spec: indent %if to make it easier to see conditions

Nested conditionals are hard to read if they are not indented.
We can't add arbitrary whitespace to everything in spec files,
but we CAN add spaces before %if and %define.  Use this trick,
plus a fancy sed script that rewrites a spec file into a C
file, so we can use cppi to keep our spec file nice.

For reference, the sed script converts code like:

|# RHEL-5 builds are client-only for s390, ppc
|%if 0%{?rhel} == 5
|    %ifnarch %{ix86} x86_64 ia64
|        %define client_only        1
|    %endif
|%endif

into the following for cppi:

|// # RHEL-5 builds are client-only for s390, ppc
|#if a // 0%{?rhel} == 5
|# if a // %{ix86} x86_64 ia64
|#  define client_only        1
|# endif
|#endif

and errors from 'make syntax-check' look like:
spec_indentation
cppi: mingw-libvirt.spec.in: line 130: not properly indented
maint.mk: incorrect preprocessor indentation

* libvirt.spec.in: Add some indentation to make it easier to follow
various conditionals.
* mingw-libvirt-spec.in: Likewise.
* cfg.mk (sc_spec_indentation): New syntax check to enforce it.
This commit is contained in:
Eric Blake 2013-01-09 13:50:03 -07:00
parent 790f912b46
commit c8f79c9b29
3 changed files with 452 additions and 437 deletions

19
cfg.mk
View File

@ -1,5 +1,5 @@
# Customize Makefile.maint. -*- makefile -*- # Customize Makefile.maint. -*- makefile -*-
# Copyright (C) 2008-2012 Red Hat, Inc. # Copyright (C) 2008-2013 Red Hat, Inc.
# Copyright (C) 2003-2008 Free Software Foundation, Inc. # Copyright (C) 2003-2008 Free Software Foundation, Inc.
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
@ -623,6 +623,23 @@ sc_preprocessor_indentation:
echo '$(ME): skipping test $@: cppi not installed' 1>&2; \ echo '$(ME): skipping test $@: cppi not installed' 1>&2; \
fi fi
# 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\1\1#/#\1/' \
-e 's|^\( *[^#/ ]\)|// \1|; s|^\( */[^/]\)|// \1|' $$f \
| cppi -a -c 2>&1 | sed "s|standard input|$$f|"; \
done | { if grep . >&2; then false; else :; fi; } \
|| { echo '$(ME): incorrect preprocessor indentation' 1>&2; \
exit 1; }; \
else \
echo '$(ME): skipping test $@: cppi not installed' 1>&2; \
fi
sc_copyright_format: sc_copyright_format:
@require='Copyright .*Red 'Hat', Inc\.' \ @require='Copyright .*Red 'Hat', Inc\.' \
containing='Copyright .*Red 'Hat \ containing='Copyright .*Red 'Hat \

File diff suppressed because it is too large Load Diff

View File

@ -17,9 +17,9 @@
# RHEL ships ESX but not PowerHypervisor, HyperV, or libxenserver (xenapi) # RHEL ships ESX but not PowerHypervisor, HyperV, or libxenserver (xenapi)
%if 0%{?rhel} %if 0%{?rhel}
%define with_phyp 0 %define with_phyp 0
%define with_xenapi 0 %define with_xenapi 0
%define with_hyperv 0 %define with_hyperv 0
%endif %endif
Name: mingw-libvirt Name: mingw-libvirt
@ -111,23 +111,23 @@ MinGW Windows libvirt virtualization library, static version.
%build %build
%if ! %{with_phyp} %if ! %{with_phyp}
%define _without_phyp --without-phyp %define _without_phyp --without-phyp
%endif %endif
%if ! %{with_esx} %if ! %{with_esx}
%define _without_esx --without-esx %define _without_esx --without-esx
%endif %endif
%if ! %{with_hyperv} %if ! %{with_hyperv}
%define _without_hyperv --without-hyperv %define _without_hyperv --without-hyperv
%endif %endif
%if ! %{with_xenapi} %if ! %{with_xenapi}
%define _without_xenapi --without-xenapi %define _without_xenapi --without-xenapi
%endif %endif
%if ! %{with_parallels} %if ! %{with_parallels}
%define _without_parallels --without-parallels %define _without_parallels --without-parallels
%endif %endif
%if 0%{?enable_autotools} %if 0%{?enable_autotools}