[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [bug-cppi] extension of cppi to cover spec files?
From: |
Eric Blake |
Subject: |
Re: [bug-cppi] extension of cppi to cover spec files? |
Date: |
Thu, 17 Jan 2013 17:17:31 -0700 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130110 Thunderbird/17.0.2 |
On 01/10/2013 11:03 AM, Jim Meyering wrote:
> Eric Blake wrote:
>> On the libvirt list, there was a thread[1] that mentioned that in a .rpm
>> file, writing:
>>
>> %if %{condition1}
>> %define foo 0
>> %else
>> %define foo 1
>> %if %{condition2}
>> %define bar 1
>> %endif
>> %endif
>>
>> is more legible than when everything is flush to the left column.
> Hi Eric,
>
> I agree that using indentation makes that easier to read.
>
> Though note that the current code is merely a lexer of a small subset
> of C syntax, but since RPM spec files are subject to different syntax
> rules, there may be unbalanced comment delimiters, unmatched quotes, etc.
Here's how I solved it in libvirt: rewrite the spec file into a C file
for the duration of the cppi run, while making the output still point to
the original file name (in the style of another cfg.mk syntax check):
# Enforce similar spec file indentation style, by running cppi on a
# (comment-only) C file that mirrors the same layout as the spec file.
sc_spec_indentation:
@if cppi --version >/dev/null 2>&1; then \
for f in $$($(VC_LIST_EXCEPT) | grep '\.spec\.in$$'); do\
sed -e 's|#|// #|; s|%ifn*\(arch\)* |#if a // |' \
-e 's/%\(else\|endif\|define\)/#\1/' \
-e 's/^\( *\)#/#\1/; s|^\([^#/]\)|// \1|' $$f \
| cppi -a -c 2>&1 | sed "s|standard input|$$f|" >&2 \
|| { echo '$(ME): incorrect preprocessor indentation' 1>&2;\
exit 1; }; \
done \
else \
echo '$(ME): skipping test $@: cppi not installed' 1>&2;\
fi
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature