-import os;
-import subprocess;
+import Utils
+
+def git_version_summary(have_git):
+ # Get version from GIT
+ if not have_git:
+ return ("GIT-UNKNOWN", {})
+
+ git = Utils.cmd_output('git show --pretty=format:"%h%n%ct%n%H%n%cd" --stat HEAD')
+
+ lines = git.splitlines()
+ fields = {
+ "GIT_COMMIT_ABBREV": lines[0],
+ "GIT_COMMIT_TIME": lines[1],
+ "GIT_COMMIT_FULLREV": lines[2],
+ "GIT_COMMIT_DATE": lines[3],
+ }
+
+ ret = "GIT-" + fields["GIT_COMMIT_ABBREV"]
+
+ clean = Utils.cmd_output('git diff HEAD | wc -l', silent=True)
+ if clean == "0\n":
+ fields["GIT_COMMIT_IS_CLEAN"] = "1"
+ else:
+ fields["GIT_COMMIT_IS_CLEAN"] = "0"
+ ret += "+"
+ return (ret, fields)
+
class samba_version(object):
- def __init__(self, version_dict):
+
+ def __init__(self, version_dict, have_git=False):
'''Determine the version number of samba
See VERSION for the format. Entries on that file are
self.ALPHA_RELEASE=None
self.PRE_RELEASE=None
self.RC_RELEASE=None
- self.IS_GIT_SNAPSHOT=True
+ self.IS_SNAPSHOT=True
self.RELEASE_NICKNAME=None
self.VENDOR_SUFFIX=None
self.VENDOR_PATCH=None
else:
setattr(self, a, b)
- if self.IS_GIT_SNAPSHOT is "yes":
- self.IS_GIT_SNAPSHOT=True
- elif self.IS_GIT_SNAPSHOT is "no":
- self.IS_GIT_SNAPSHOT=False
-
+ if self.IS_GIT_SNAPSHOT == "yes":
+ self.IS_SNAPSHOT=True
+ elif self.IS_GIT_SNAPSHOT == "no":
+ self.IS_SNAPSHOT=False
+ else:
+ raise Exception("Unknown value for IS_GIT_SNAPSHOT: %s" % self.IS_GIT_SNAPSHOT)
+
##
## start with "3.0.22"
##
SAMBA_VERSION_STRING += self.REVISION
if self.TP_RELEASE is not None:
self.TP_RELEASE = int(self.TP_RELEASE)
- SAMBA_VERSION_STRING += ("tp%u" % self.TP_RELEASE)
+ SAMBA_VERSION_STRING += "tp%u" % self.TP_RELEASE
if self.ALPHA_RELEASE is not None:
self.ALPHA_RELEASE = int(self.ALPHA_RELEASE)
SAMBA_VERSION_STRING += ("alpha%u" % self.ALPHA_RELEASE)
self.RC_RELEASE = int(self.RC_RELEASE)
SAMBA_VERSION_STRING += ("rc%u" % self.RC_RELEASE)
- if self.IS_GIT_SNAPSHOT:
- #Get version from GIT
- try:
- git = subprocess.Popen('git show --pretty=format:"%h%n%ct%n%H%n%cd" --stat HEAD', stdout=subprocess.PIPE, close_fds=True, shell=True)
- (output, errors) = git.communicate()
- lines = output.splitlines();
- self.GIT_COMMIT_ABBREV = lines[0]
- self.GIT_COMMIT_TIME = lines[1]
- self.GIT_COMMIT_FULLREV = lines[2]
- self.GIT_COMMIT_DATE = lines[3]
-
- SAMBA_VERSION_STRING += ("-GIT-" + self.GIT_COMMIT_ABBREV)
- except IndexError:
- SAMBA_VERSION_STRING += "-GIT-UNKNOWN"
- pass
+ if self.IS_SNAPSHOT:
+ suffix, self.vcs_fields = git_version_summary(have_git)
+ SAMBA_VERSION_STRING += "-" + suffix
+ else:
+ self.vcs_fields = {}
- self.OFFICIAL_STRING=SAMBA_VERSION_STRING
+ self.OFFICIAL_STRING = SAMBA_VERSION_STRING
if self.VENDOR_SUFFIX is not None:
SAMBA_VERSION_STRING += ("-" + self.VENDOR_SUFFIX)
self.RELEASE_NICKNAME = self.RELEASE_NICKNAME
else:
self.STRING_WITH_NICKNAME = self.STRING
-
+
def __str__(self):
string="/* Autogenerated by waf */\n"
string+="#define SAMBA_VERSION_MAJOR %u\n" % self.MAJOR
if self.RC_RELEASE is not None:
string+="#define SAMBA_VERSION_RC_RELEASE %u\n" % self.RC_RELEASE
- try:
- string+="#define SAMBA_VERSION_GIT_COMMIT_ABBREV " + self.GIT_COMMIT_ABBREV + "\n"
- string+="#define SAMBA_VERSION_GIT_COMMIT_TIME " + self.GIT_COMMIT_TIME + "\n"
- string+="#define SAMBA_VERSION_GIT_COMMIT_FULLREV " + self.GIT_COMMIT_TIME + "\n"
- string+="#define SAMBA_VERSION_GIT_COMMIT_DATE " + self.GIT_COMMIT_DATA + "\n"
- except AttributeError:
- pass
+ for name, value in self.vcs_fields.iteritems():
+ string+="#define SAMBA_VERSION_%s \"%s\"\n" % (name, value)
string+="#define SAMBA_VERSION_OFFICIAL_STRING \"" + self.OFFICIAL_STRING + "\"\n"
class samba_version_file(samba_version):
- def __init__(self, version_file):
+
+ def __init__(self, version_file, have_git=False):
'''Parse the version information from a VERSION file'''
f = open(version_file, 'r')
version_dict = {}
for line in f:
+ line = line.strip()
+ if line == '':
+ continue
+ if line.startswith("#"):
+ continue
try:
- line = line.strip()
- if line == '':
- continue
- if line.startswith("#"):
- continue
- split_line=line.split("=")
+ split_line = line.split("=")
if split_line[1] != "":
value = split_line[1].strip('"')
version_dict[split_line[0]] = value
except:
- print "Failed to parse line %s from %s" % (line, version_file)
+ print("Failed to parse line %s from %s" % (line, version_file))
raise
-
- super(samba_version_file, self).__init__(version_dict)
-
+
+ super(samba_version_file, self).__init__(version_dict, have_git=have_git)