nobs git describe watermarking support

Issue #135 resolved
Dan Bonachea created an issue

With pull request #25 merged, users can now use ident to query UPC++ version info from any UPC++ executable. This will soon also include a git hash for automated nightly builds.

An additional enhancement would be for nobs to embed the git hash for manual build/installs from a UPC++ git clone.

All that's needed to make this work is for nobs to notice the presence of a .git directory and add the equivalent of:

-DUPCXX_GIT_VERSION=<output of git describe>

to the library compile line. The code needs to be "defensive" and make no change in any of the following situations:

  1. .git directory missing (eg as in a source tarball)
  2. git command is not in the PATH (eg the source dir is a git clone on a network drive and this node does not have git)
  3. git command exits with an error for some reason

John provided the preliminary patch below, which lacks the necessary defensiveness:

diff --git a/nobsrule.py b/nobsrule.py
index 0a3fbe9..935fa8a 100644
--- a/nobsrule.py
+++ b/nobsrule.py
@@ -334,6 +334,16 @@ def comp_version(cxt, src):
 def upcxx_assert_enabled(cxt):
   return bool(env('ASSERT', False))

+def git_describe():
+  import subprocess as subp
+  p = subp.Popen(['git','describe'], stdout=subp.PIPE)
+  id, _ = p.communicate()
+  id = id.strip()
+  global git_describe
+  
+  git_describe = lambda:id
+  return id
+
 @rule(path_arg='src')
 @coroutine
 def comp_lang_pp(cxt, src, libset):
@@ -342,8 +352,10 @@ def comp_lang_pp(cxt, src, libset):
   """
   comp = yield cxt.comp_lang(src)
   ivt = yield cxt.include_vdirs_tree(src)
+  
   yield (
     comp + 
+    ['-DUPCXX_GIT_VERSION='+git_describe()] +
     ['-D_GNU_SOURCE=1'] + # Required for full latest POSIX on some systems
     ['-I'+ivt] +
     libset_ppflags(libset)

Comments (3)

  1. Log in to comment