waf: added --git-local-changes configure option
authorAndrew Tridgell <tridge@samba.org>
Tue, 16 Nov 2010 01:05:14 +0000 (12:05 +1100)
committerAndrew Tridgell <tridge@samba.org>
Tue, 16 Nov 2010 01:51:54 +0000 (01:51 +0000)
if you use --git-local-changes then the version number that waf
extracts from git will have a '+' on the end if you have local
changes, as determined by running 'git diff'.

This used to be the default, but unfortunately it is far too slow on
some systems. On a NFS build system I was using the first line of
configure took about 2 minutes.

Autobuild-User: Andrew Tridgell <tridge@samba.org>
Autobuild-Date: Tue Nov 16 01:51:54 UTC 2010 on sn-devel-104

buildtools/wafsamba/samba_patterns.py
buildtools/wafsamba/samba_version.py
buildtools/wafsamba/wscript
source3/wscript
source4/wscript

index 9693c5965ec875227dfde398b82bc6258299ad22..37ef4198a680dbd8810127dcaf47a0049b5b2d02 100644 (file)
@@ -10,9 +10,7 @@ def write_version_header(task):
     src = task.inputs[0].srcpath(task.env)
     tgt = task.outputs[0].bldpath(task.env)
 
-    have_git = 'GIT' in task.env
-
-    version = samba_version_file(src, task.env.srcdir, have_git=have_git)
+    version = samba_version_file(src, task.env.srcdir, env=task.env)
     string = str(version)
 
     f = open(tgt, 'w')
index e6a6ccf28f7bfcb77e0aa623b162fd8b2ee11b46..df715840cbfdf8878618b1935645348871ba65e2 100644 (file)
@@ -44,14 +44,18 @@ def bzr_version_summary(path):
     return (ret, fields)
 
 
-def git_version_summary(path, have_git):
+def git_version_summary(path, env=None):
     # Get version from GIT
-    if not have_git:
+    if not 'GIT' in env:
         return ("GIT-UNKNOWN", {})
 
-    git = Utils.cmd_output('git show --pretty=format:"%h%n%ct%n%H%n%cd" --stat HEAD', silent=True)
+    os.putenv('GIT_DIR', '%s/.git' % path)
+    git = Utils.cmd_output(env.GIT + ' show --pretty=format:"%h%n%ct%n%H%n%cd" --stat HEAD', silent=True)
 
     lines = git.splitlines()
+    if not lines or len(lines) < 4:
+        return ("GIT-UNKNOWN", {})
+
     fields = {
             "GIT_COMMIT_ABBREV": lines[0],
             "GIT_COMMIT_FULLREV": lines[2],
@@ -61,18 +65,20 @@ def git_version_summary(path, have_git):
 
     ret = "GIT-" + fields["GIT_COMMIT_ABBREV"]
 
-    clean = Utils.cmd_output('git diff HEAD | wc -l', silent=True)
-    if clean == "0\n":
-        fields["COMMIT_IS_CLEAN"] = 1
-    else:
-        fields["COMMIT_IS_CLEAN"] = 0
-        ret += "+"
+    if env.GIT_LOCAL_CHANGES:
+        clean = Utils.cmd_output('git diff HEAD | wc -l', silent=True).strip()
+        if clean == "0":
+            fields["COMMIT_IS_CLEAN"] = 1
+        else:
+            fields["COMMIT_IS_CLEAN"] = 0
+            ret += "+"
+
     return (ret, fields)
 
 
 class SambaVersion(object):
 
-    def __init__(self, version_dict, path, have_git=False):
+    def __init__(self, version_dict, path, env=None):
         '''Determine the version number of samba
 
 See VERSION for the format.  Entries on that file are 
@@ -135,7 +141,7 @@ also accepted as dictionary entries here
 
         if self.IS_SNAPSHOT:
             if os.path.exists(os.path.join(path, ".git")):
-                suffix, self.vcs_fields = git_version_summary(path, have_git)
+                suffix, self.vcs_fields = git_version_summary(path, env=env)
             elif os.path.exists(os.path.join(path, ".bzr")):
                 suffix, self.vcs_fields = bzr_version_summary(path)
             else:
@@ -217,7 +223,7 @@ also accepted as dictionary entries here
         return string
 
 
-def samba_version_file(version_file, path, have_git=False):
+def samba_version_file(version_file, path, env=None):
     '''Parse the version information from a VERSION file'''
 
     f = open(version_file, 'r')
@@ -237,4 +243,4 @@ def samba_version_file(version_file, path, have_git=False):
             print("Failed to parse line %s from %s" % (line, version_file))
             raise
 
-    return SambaVersion(version_dict, path, have_git=have_git)
+    return SambaVersion(version_dict, path, env=env)
index 6913f63c91727d67f024c3464f7797e8a80c2650..0d91237d482894a2a2c3f4b4d3f37216f3163301 100644 (file)
@@ -96,6 +96,9 @@ def set_options(opt):
     gr.add_option('--pedantic',
                   help=("Enable even more compiler warnings"),
                   action='store_true', dest='pedantic', default=False)
+    gr.add_option('--git-local-changes',
+                  help=("mark version with + if local git changes"),
+                  action='store_true', dest='GIT_LOCAL_CHANGES', default=False)
 
     gr.add_option('--abi-check',
                   help=("Check ABI signatures for libraries"),
@@ -244,6 +247,8 @@ def configure(conf):
     except:
         conf.env.ABI_CHECK = False
 
+    conf.env.GIT_LOCAL_CHANGES = Options.options.GIT_LOCAL_CHANGES
+
     conf.CHECK_COMMAND(['uname', '-a'],
                        msg='Checking build system',
                        define='BUILD_SYSTEM',
index 1164ff1d702a27ef9dfa9f440cb3610d781257c4..510bed574941702f99ff5432b80624814a9dd3e5 100644 (file)
@@ -14,14 +14,14 @@ import build.charset
 import samba_utils
 import samba3
 
-def load_version(have_git=False):
+def load_version(env=None):
     '''load samba versions either from ./VERSION or git
     return a version object for detailed breakdown'''
     import samba_utils, Utils
-    if not have_git:
+    if not env:
         env = samba_utils.LOAD_ENVIRONMENT()
-        have_git = 'GIT' in env
-    version = wafsamba.samba_version_file("./VERSION", "..", have_git=have_git)
+
+    version = wafsamba.samba_version_file("./VERSION", "..", env=env)
     Utils.g_module.VERSION = version.STRING
     return version
 
@@ -67,7 +67,7 @@ def set_options(opt):
 def configure(conf):
     from samba_utils import TO_LIST
 
-    version = load_version(have_git=True)
+    version = load_version(env=conf.env)
 
     conf.DEFINE('CONFIG_H_IS_FROM_SAMBA', 1)
     conf.DEFINE('_SAMBA_BUILD_', version.MAJOR, add_to_cflags=True)
index bf4ccbdfcaedde954f280ca0049cd2e4205dc78d..80916f5579ddc88a5617349934fab650242317a2 100644 (file)
@@ -11,14 +11,14 @@ sys.path.insert(0, srcdir+"/buildtools/wafsamba")
 import wafsamba, Options, samba_dist, Scripting, Utils
 
 
-def load_version(have_git=False):
+def load_version(env=None):
     '''load samba versions either from ./VERSION or git
     return a version object for detailed breakdown'''
     import samba_utils, Utils
-    if not have_git:
+    if not env:
         env = samba_utils.LOAD_ENVIRONMENT()
-        have_git = 'GIT' in env
-    version = wafsamba.samba_version_file("./VERSION", "..", have_git=have_git)
+
+    version = wafsamba.samba_version_file("./VERSION", "..", env)
     Utils.g_module.VERSION = version.STRING
     return version
 
@@ -61,7 +61,7 @@ def set_options(opt):
 
 
 def configure(conf):
-    version = load_version(have_git=True)
+    version = load_version(env=conf.env)
 
     conf.DEFINE('CONFIG_H_IS_FROM_SAMBA', 1)
     conf.DEFINE('_SAMBA_BUILD_', version.MAJOR, add_to_cflags=True)
@@ -150,7 +150,7 @@ def ctags(ctx):
 # of commands in --help
 def build(bld):
     '''build all targets'''
-    load_version()
+    load_version(env=bld.env)
     pass
 
 
@@ -176,12 +176,12 @@ def wafdocs(ctx):
 
 def dist():
     '''makes a tarball for distribution'''
-    load_version()
+    load_version(env=None)
     samba_dist.dist()
 
 def distcheck():
     '''test that distribution tarball builds and installs'''
-    load_version()
+    load_version(env=None)
     import Scripting
     d = Scripting.distcheck
     d(subdir='source4')