update-waf.sh: make mktemp happy by including anything Xes.
[samba.git] / buildtools / wafsamba / samba_version.py
index df715840cbfdf8878618b1935645348871ba65e2..9dae23a908429865af98655755a54ef733e55258 100644 (file)
@@ -1,12 +1,18 @@
 import os
 import Utils
+import samba_utils
+import sys
 
 def bzr_version_summary(path):
     try:
-        from bzrlib import branch, osutils, workingtree
+        import bzrlib
     except ImportError:
         return ("BZR-UNKNOWN", {})
 
+    import bzrlib.ui
+    bzrlib.ui.ui_factory = bzrlib.ui.make_ui_for_terminal(
+        sys.stdin, sys.stdout, sys.stderr)
+    from bzrlib import branch, osutils, workingtree
     from bzrlib.plugin import load_plugins
     load_plugins()
 
@@ -31,7 +37,11 @@ def bzr_version_summary(path):
         ret = "BZR-%d" % revno
     else:
         store = get_object_store(b.repository)
-        full_rev = store._lookup_revision_sha1(revid)
+        store.lock_read()
+        try:
+            full_rev = store._lookup_revision_sha1(revid)
+        finally:
+            store.unlock()
         fields["GIT_COMMIT_ABBREV"] = full_rev[:7]
         fields["GIT_COMMIT_FULLREV"] = full_rev
         ret = "GIT-" + fields["GIT_COMMIT_ABBREV"]
@@ -46,11 +56,17 @@ def bzr_version_summary(path):
 
 def git_version_summary(path, env=None):
     # Get version from GIT
+    if not 'GIT' in env and os.path.exists("/usr/bin/git"):
+        # this is useful when doing make dist without configuring
+        env.GIT = "/usr/bin/git"
+
     if not 'GIT' in env:
         return ("GIT-UNKNOWN", {})
 
-    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)
+    environ = dict(os.environ)
+    environ["GIT_DIR"] = '%s/.git' % path
+    environ["GIT_WORK_TREE"] = path
+    git = Utils.cmd_output(env.GIT + ' show --pretty=format:"%h%n%ct%n%H%n%cd" --stat HEAD', silent=True, env=environ)
 
     lines = git.splitlines()
     if not lines or len(lines) < 4:
@@ -66,7 +82,7 @@ def git_version_summary(path, env=None):
     ret = "GIT-" + fields["GIT_COMMIT_ABBREV"]
 
     if env.GIT_LOCAL_CHANGES:
-        clean = Utils.cmd_output('git diff HEAD | wc -l', silent=True).strip()
+        clean = Utils.cmd_output('%s diff HEAD | wc -l' % env.GIT, silent=True).strip()
         if clean == "0":
             fields["COMMIT_IS_CLEAN"] = 1
         else:
@@ -78,7 +94,7 @@ def git_version_summary(path, env=None):
 
 class SambaVersion(object):
 
-    def __init__(self, version_dict, path, env=None):
+    def __init__(self, version_dict, path, env=None, is_install=True):
         '''Determine the version number of samba
 
 See VERSION for the format.  Entries on that file are 
@@ -91,6 +107,7 @@ also accepted as dictionary entries here
         self.REVISION=None
         self.TP_RELEASE=None
         self.ALPHA_RELEASE=None
+        self.BETA_RELEASE=None
         self.PRE_RELEASE=None
         self.RC_RELEASE=None
         self.IS_SNAPSHOT=True
@@ -121,7 +138,7 @@ also accepted as dictionary entries here
         SAMBA_VERSION_STRING = ("%u.%u.%u" % (self.MAJOR, self.MINOR, self.RELEASE))
 
 ##
-## maybe add "3.0.22a" or "4.0.0tp11" or "4.0.0alpha1" or "3.0.22pre1" or "3.0.22rc1"
+## maybe add "3.0.22a" or "4.0.0tp11" or "4.0.0alpha1" or "4.0.0beta1" or "3.0.22pre1" or "3.0.22rc1"
 ## We do not do pre or rc version on patch/letter releases
 ##
         if self.REVISION is not None:
@@ -132,6 +149,9 @@ also accepted as dictionary entries here
         if self.ALPHA_RELEASE is not None:
             self.ALPHA_RELEASE = int(self.ALPHA_RELEASE)
             SAMBA_VERSION_STRING += ("alpha%u" % self.ALPHA_RELEASE)
+        if self.BETA_RELEASE is not None:
+            self.BETA_RELEASE = int(self.BETA_RELEASE)
+            SAMBA_VERSION_STRING += ("beta%u" % self.BETA_RELEASE)
         if self.PRE_RELEASE is not None:
             self.PRE_RELEASE = int(self.PRE_RELEASE)
             SAMBA_VERSION_STRING += ("pre%u" % self.PRE_RELEASE)
@@ -140,7 +160,10 @@ also accepted as dictionary entries here
             SAMBA_VERSION_STRING += ("rc%u" % self.RC_RELEASE)
 
         if self.IS_SNAPSHOT:
-            if os.path.exists(os.path.join(path, ".git")):
+            if not is_install:
+                suffix = "DEVELOPERBUILD"
+                self.vcs_fields = {}
+            elif os.path.exists(os.path.join(path, ".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)
@@ -164,8 +187,7 @@ also accepted as dictionary entries here
         self.STRING = SAMBA_VERSION_STRING
 
         if self.RELEASE_NICKNAME is not None:
-            self.STRING_WITH_NICKNAME += (" (" + self.RELEASE_NICKNAME + ")")
-            self.RELEASE_NICKNAME = self.RELEASE_NICKNAME
+            self.STRING_WITH_NICKNAME = "%s (%s)" % (self.STRING, self.RELEASE_NICKNAME)
         else:
             self.STRING_WITH_NICKNAME = self.STRING
 
@@ -183,6 +205,9 @@ also accepted as dictionary entries here
         if self.ALPHA_RELEASE is not None:
             string+="#define SAMBA_VERSION_ALPHA_RELEASE %u\n" % self.ALPHA_RELEASE
 
+        if self.BETA_RELEASE is not None:
+            string+="#define SAMBA_VERSION_BETA_RELEASE %u\n" % self.BETA_RELEASE
+
         if self.PRE_RELEASE is not None:
             string+="#define SAMBA_VERSION_PRE_RELEASE %u\n" % self.PRE_RELEASE
 
@@ -223,7 +248,7 @@ also accepted as dictionary entries here
         return string
 
 
-def samba_version_file(version_file, path, env=None):
+def samba_version_file(version_file, path, env=None, is_install=True):
     '''Parse the version information from a VERSION file'''
 
     f = open(version_file, 'r')
@@ -243,4 +268,16 @@ def samba_version_file(version_file, path, env=None):
             print("Failed to parse line %s from %s" % (line, version_file))
             raise
 
-    return SambaVersion(version_dict, path, env=env)
+    return SambaVersion(version_dict, path, env=env, is_install=is_install)
+
+
+
+def load_version(env=None, is_install=True):
+    '''load samba versions either from ./VERSION or git
+    return a version object for detailed breakdown'''
+    if not env:
+        env = samba_utils.LOAD_ENVIRONMENT()
+
+    version = samba_version_file("./VERSION", ".", env, is_install=is_install)
+    Utils.g_module.VERSION = version.STRING
+    return version