[Git][NTPsec/ntpsec][master] build: make waf configure work on shallow git clones

Eric S. Raymond (@esr) gitlab at mg.gitlab.com
Sun Mar 27 22:28:08 UTC 2022



Eric S. Raymond pushed to branch master at NTPsec / ntpsec


Commits:
5b934c94 by James Browning at 2022-03-27T22:21:22+00:00
build: make waf configure work on shallow git clones

`[tag-7-]gdeadbeef[-dirty]` covers 4 common outputs of `git describe`
with passed options. `tag` and `7` if present represent the latest
tag and the number of commits since. `-dirty` indicates that there are
uncommitted changes in the tree. The shallow clone lacks the first two
which broke the configure step. Distro packagers usually add patches.

the fifth possibility is a broken tree, which cause `git` to explode and
keep spreading the joy.

STR:
1. `git clone https://gitlab.com/NTPsec/ntpsec`
2. `cd ntpsec`
3. `./waf configure`
ER: configure should complete successfully
AR: configure fails with...
```
Checking for program 'git'                : /usr/bin/git
Command ['/usr/bin/git', 'describe', '--dirty'] returned 128
```

- - - - -


1 changed file:

- wscript


Changes:

=====================================
wscript
=====================================
@@ -177,9 +177,21 @@ def configure(ctx):
     if build_desc:
         build_desc = ' ' + build_desc
     if ctx.env.BIN_GIT:
-        cmd = ctx.env.BIN_GIT + shlex.split("describe --dirty")
-        git_short_hash = ctx.cmd_and_log(cmd).strip()
-        git_short_hash = '-'.join(git_short_hash.split('-')[1:])
+        # 'tag', '7', and 'deadbeef' are fill ins for
+        # a previous tag (always dropped), commits since that tag,
+        # the short commit hash. I can see 5 'git describe' outputs
+        # buildbots and prepush should get: tag-7-gdeadbeef
+        # working developers should get: tag-7-gdeadbeef-dirty
+        # patched shallow builders should get: gdeadbeef-dirty
+        # other shallow builder should get: gdeadbeef
+        # the thorium poisoned get errors and burst into flame
+        # 1-2 tokens gets appended verbatim
+        # 3-4 gets the first token dropped and the rest added
+        # I have never seen 5+ tokens, we should be safe
+        cmd = ctx.env.BIN_GIT + shlex.split("describe --tags --dirty --always")
+        git_short_hash = ctx.cmd_and_log(cmd).strip().split('-')
+        clip = 1 if len(git_short_hash) > 2 else 0
+        git_short_hash = '-'.join(git_short_hash[clip:])
 
         ctx.env.NTPSEC_VERSION = "%s+" % ntpsec_release
         ctx.env.NTPSEC_VERSION_EXTENDED = ("%s+%s%s" %
@@ -1055,7 +1067,7 @@ def build(ctx):
         target3 = bldnode.ant_glob('*ntpc*')
         for _ in target3:
             ctx.exec_command("rm -f %s" % _.abspath())
-        # Finish purging ntp.ntpc 
+        # Finish purging ntp.ntpc
         ctx.add_group()
 
     if ctx.env.REFCLOCK_GENERIC or ctx.env.REFCLOCK_TRIMBLE:



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/-/commit/5b934c9400a49c970e0fdb3b2e0557ffa1ed2e47

-- 
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/-/commit/5b934c9400a49c970e0fdb3b2e0557ffa1ed2e47
You're receiving this email because of your account on gitlab.com.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20220327/de27af44/attachment-0001.htm>


More information about the vc mailing list