[libvirt] [PATCH 05/10] syntax-check: Don't include duplicate header
Eric Blake
eblake at redhat.com
Wed Apr 17 03:41:46 UTC 2013
On 04/16/2013 07:41 AM, Osier Yang wrote:
> Except gnulib...
> ---
> cfg.mk | 22 ++++++++++++++++++++++
> 1 file changed, 22 insertions(+)
>
> diff --git a/cfg.mk b/cfg.mk
> index e60c4e3..71f7ee4 100644
> --- a/cfg.mk
> +++ b/cfg.mk
> @@ -722,6 +722,28 @@ sc_prohibit_exit_in_tests:
> halt='use return, not exit(), in tests' \
> $(_sc_search_regexp)
>
> +# Don't include duplicate header in the source (either *.c or *.h)
> +sc_prohibit_duplicate_header:
> + @for i in $$($(VC_LIST_EXCEPT) | grep '\.[ch]$$'); do \
You also cleaned up .x files, so use [chx] instead of [ch].
> + awk 'BEGIN { \
> + FS=" "; \
I don't think you need to set FS, if you use my match/substr change.
> + fail=0; \
> + } \
> + /^# *include.*\.h[">]$$/ { \
> + arr[$$NF]++; \
> + } \
Here's where my comments on patch 1 should be incorporated:
/# *include/ { \
match($0, /[<"][^>"]*[">]/) \
arr[substr($0, RMATCH + 1, RLENGTH - 2)]++ \
}
> + END { \
> + for (key in arr) { \
> + if (arr[key] > 1) { \
> + fail=1; \
> + printf("%d %s are included\n", arr[key], key); \
> + } \
> + } \
> + if (fail == 1) \
> + exit 1; \
> + }' $$i || { echo "Duplicate header(s) in $$i"; exit 1; }; \
This exits on first failure, instead of collecting all failures in one
go. It also misses the prefix $(ME): used in other error messages, and
should be sent to stderr. I would do:
@fail=0; for i in ...
awk '{
...
if (fail == 1) {
printf("duplicate header(s) in " FILENAME
}
}' $$i || fail=1
done; if test $$fail = 1; then
{ echo "$(ME): avoid duplicate headers" >&2; exit 1; }
fi
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 621 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20130416/b817aacc/attachment-0001.sig>
More information about the libvir-list
mailing list