[libvirt] [PATCH v2] maint: prohibit empty first lines

Based on discussion with Eric: https://www.redhat.com/archives/libvir-list/2014-March/msg01001.html Signed-off-by: Martin Kletzander <mkletzan@redhat.com> --- v2: - rebase on current master and s/FILENAME:1:/FILENAME ":1:"/ cfg.mk | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cfg.mk b/cfg.mk index 675af21..80440b5 100644 --- a/cfg.mk +++ b/cfg.mk @@ -938,6 +938,13 @@ sc_require_locale_h: fi; \ done; +sc_prohibit_empty_first_line: + @awk 'BEGIN { fail=0; } \ + FNR == 1 { if ($$0 == "") { print FILENAME ":1:"; fail=1; } } \ + END { if (fail == 1) { \ + print "$(ME): Prohibited empty first line" > "/dev/stderr"; \ + } exit fail; }' $$($(VC_LIST_EXCEPT) | grep '\.[ch]$$'); + # We don't use this feature of maint.mk. prev_version_file = /dev/null -- 2.0.0

On 04.06.2014 15:01, Martin Kletzander wrote:
Based on discussion with Eric:
https://www.redhat.com/archives/libvir-list/2014-March/msg01001.html
Signed-off-by: Martin Kletzander <mkletzan@redhat.com> --- v2: - rebase on current master and s/FILENAME:1:/FILENAME ":1:"/
cfg.mk | 7 +++++++ 1 file changed, 7 insertions(+)
diff --git a/cfg.mk b/cfg.mk index 675af21..80440b5 100644 --- a/cfg.mk +++ b/cfg.mk @@ -938,6 +938,13 @@ sc_require_locale_h: fi; \ done;
+sc_prohibit_empty_first_line: + @awk 'BEGIN { fail=0; } \ + FNR == 1 { if ($$0 == "") { print FILENAME ":1:"; fail=1; } } \ + END { if (fail == 1) { \ + print "$(ME): Prohibited empty first line" > "/dev/stderr"; \ + } exit fail; }' $$($(VC_LIST_EXCEPT) | grep '\.[ch]$$');
Maybe we can check the whole VC_LIST, there are only a few files that start with an empty line (typically README.txt) and those can have an exception. But there are some that shouldn't start with an empty line, e.g.: docs/generic.css:1: src/locking/lockd.conf:1: src/locking/sanlock.conf:1: and some testdata under tests/nodeinfodata/linux-test3/node/node*/meminfo. These in particular should be plain copy of their origins in sysfs which at least on my system doesn't start with an empty line: # head -n1 /sys/devices/system/node/node0/meminfo Node 0 MemTotal: 4004132 kB But your version is good too. ACK whether you decide to change it the way I'm suggesting or not. Michal

On 06/04/2014 07:01 AM, Martin Kletzander wrote:
Based on discussion with Eric:
https://www.redhat.com/archives/libvir-list/2014-March/msg01001.html
Signed-off-by: Martin Kletzander <mkletzan@redhat.com> --- v2: - rebase on current master and s/FILENAME:1:/FILENAME ":1:"/
cfg.mk | 7 +++++++ 1 file changed, 7 insertions(+)
The existing sc_prohibit_empty_lines_at_EOF in maint.mk does a similar check but using perl instead of awk. But that shouldn't matter.
diff --git a/cfg.mk b/cfg.mk index 675af21..80440b5 100644 --- a/cfg.mk +++ b/cfg.mk @@ -938,6 +938,13 @@ sc_require_locale_h: fi; \ done;
+sc_prohibit_empty_first_line: + @awk 'BEGIN { fail=0; } \ + FNR == 1 { if ($$0 == "") { print FILENAME ":1:"; fail=1; } } \
why is this to stdout...
+ END { if (fail == 1) { \ + print "$(ME): Prohibited empty first line" > "/dev/stderr"; \
...but this to stderr?
+ } exit fail; }' $$($(VC_LIST_EXCEPT) | grep '\.[ch]$$');
I'd use ALL of VC_LIST_EXCEPT (not just the .c and .h files). But in general it looks like it does the right thing. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

On Wed, Jun 04, 2014 at 10:14:24AM -0600, Eric Blake wrote:
On 06/04/2014 07:01 AM, Martin Kletzander wrote:
Based on discussion with Eric:
https://www.redhat.com/archives/libvir-list/2014-March/msg01001.html
Signed-off-by: Martin Kletzander <mkletzan@redhat.com> --- v2: - rebase on current master and s/FILENAME:1:/FILENAME ":1:"/
cfg.mk | 7 +++++++ 1 file changed, 7 insertions(+)
The existing sc_prohibit_empty_lines_at_EOF in maint.mk does a similar check but using perl instead of awk. But that shouldn't matter.
Yeah, but that is taken from gnulib, isn't it? Do you suggest proposing this fix there?
diff --git a/cfg.mk b/cfg.mk index 675af21..80440b5 100644 --- a/cfg.mk +++ b/cfg.mk @@ -938,6 +938,13 @@ sc_require_locale_h: fi; \ done;
+sc_prohibit_empty_first_line: + @awk 'BEGIN { fail=0; } \ + FNR == 1 { if ($$0 == "") { print FILENAME ":1:"; fail=1; } } \
why is this to stdout...
I wanted to simulate the behaviour of other syntax-check rules that use grep without output redirection. No problem of making this go to stderr, though.
+ END { if (fail == 1) { \ + print "$(ME): Prohibited empty first line" > "/dev/stderr"; \
...but this to stderr?
+ } exit fail; }' $$($(VC_LIST_EXCEPT) | grep '\.[ch]$$');
I'd use ALL of VC_LIST_EXCEPT (not just the .c and .h files). But in general it looks like it does the right thing.
Michal had a good point of those other files. I'll remove the grep, add necessary files into except rule and fix all the other non-.[ch] ones. Thanks for the reviews Martin
participants (3)
-
Eric Blake
-
Martin Kletzander
-
Michal Privoznik