Thread (13 messages) 13 messages, 2 authors, 2016-06-15

Re: [GUILT 1/5] Fix generation of Documentation/usage-%.txt.

flat view

From: Per Cederqvist <hidden>
Date: 2016-06-15 23:03:40

On Fri, Jan 23, 2015 at 3:21 PM, Jeff Sipek [off-list ref] wrote:
On Fri, Jan 23, 2015 at 02:24:55PM +0100, Per Cederqvist wrote:
quoted
The old rule worked, most of the time, but had several issues:

 - It depended on the corresponding guilt-*.txt file, but the usage.sh
   script actually reads ../guilt-foo.

 - Actually, each usage-%.txt depended on all guilt-*.txt files, so
   make had to do more work than necessary if a single file was
   altered.

 - The construct broke parallel make, which would spawn several
   usage.sh at once.  This leads to unnecessary work, and could
   potentially result in broken usage files if the "echo some_string >
   some_file" construct used by usage.sh isn't atomic.

Fixed by letting the usage.sh script update a single file, and writing
a proper implicit make rule.  This makes parallel make work a lot
better.
Nice!
quoted
There is a small downside, though, as usage.sh will now be run once
for each command (if everything is regenerated).  I think it is worth
to pay that price to get the correctness.  This command is still very
fast compared to the docbook processing.
Given how much simple usage.sh got, I'm thinking it might be worth it to
just remove it, and just shove the rule into the makefile itself.

Ok, I tried to write it.  I came up with the following.  (Note: I have *not*
tested it.)  It's not *that* ugly.

usage-guilt-%.txt: ../guilt-% usage.sh
        echo "'$(basename $<)' `sed -n -e '/^USAGE=/{s/USAGE="//; s/"$//; p; q}' $<`" > $@

What do you think?  Too opaque?  Your change looks good.
Too opaque, and not tested enough. It doesn't work, since make will
handle all $.  You need to write $$ instead of $ in at least one of the
places.  I would stick with usage.sh, as getting the quoting right when
you have make, shell, subshells, and sed all at the same time is just
too painful.

But it is of course up to you. You are the maintainer. :-)

    /ceder
Jeff.
quoted
Signed-off-by: Per Cederqvist <redacted>
---
 Documentation/Makefile | 4 ++--
 Documentation/usage.sh | 8 +++-----
 2 files changed, 5 insertions(+), 7 deletions(-)
diff --git a/Documentation/Makefile b/Documentation/Makefile
index b6c3285..ec3c9e8 100644
--- a/Documentation/Makefile
+++ b/Documentation/Makefile
@@ -66,8 +66,8 @@ clean:
      rm -f usage-*.txt
      rm -f version.txt

-usage-%.txt: $(MAN1_TXT) usage.sh
-     sh ./usage.sh
+usage-guilt-%.txt: ../guilt-% usage.sh
+     sh ./usage.sh $<

 %.html : %.txt footer.txt version.txt
      $(ASCIIDOC) -b xhtml11 -d manpage -f asciidoc.conf $(ASCIIDOC_EXTRA) $<
diff --git a/Documentation/usage.sh b/Documentation/usage.sh
index 20fdca4..629f546 100644
--- a/Documentation/usage.sh
+++ b/Documentation/usage.sh
@@ -1,7 +1,5 @@
 #!/bin/sh

-for i in `ls ../guilt-*`; do
-     name=$(basename $i)
-     u=$(grep USAGE $i |  sed 's/USAGE="//' | sed 's/"$//')
-     echo "'$name' $u"  > usage-$name.txt
-done
+name=$(basename $1)
+u=$(grep USAGE $1 |  sed 's/USAGE="//' | sed 's/"$//')
+echo "'$name' $u"  > usage-$name.txt
--
2.1.0
--
The reasonable man adapts himself to the world; the unreasonable one
persists in trying to adapt the world to himself. Therefore all progress
depends on the unreasonable man.
                - George Bernard Shaw
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help