4 def bzr_version_summary(path):
6 from bzrlib import branch, osutils
8 return ("BZR-UNKNOWN", {})
10 from bzrlib.plugin import load_plugins
13 b = branch.Branch.open(path)
14 (revno, revid) = b.last_revision_info()
15 rev = b.repository.get_revision(revid)
18 "BZR_REVISION_ID": revid,
19 "BZR_REVNO": str(revno),
20 "COMMIT_DATE": osutils.format_date_with_offset_in_original_timezone(rev.timestamp,
22 "COMMIT_TIME": int(rev.timestamp),
23 "BZR_BRANCH": rev.properties.get("branch-nick", ""),
26 # If possible, retrieve the git sha
28 from bzrlib.plugins.git.object_store import get_object_store
31 ret = "BZR-%d" % revno
33 store = get_object_store(b.repository)
34 full_rev = store._lookup_revision_sha1(revid)
35 fields["GIT_COMMIT_ABBREV"] = full_rev[:7]
36 fields["GIT_COMMIT_FULLREV"] = full_rev
37 ret = "GIT-" + fields["GIT_COMMIT_ABBREV"]
39 clean = Utils.cmd_output('bzr diff | wc -l', silent=True)
41 fields["COMMIT_IS_CLEAN"] = "1"
43 fields["COMMIT_IS_CLEAN"] = "0"
48 def git_version_summary(path, have_git):
49 # Get version from GIT
51 return ("GIT-UNKNOWN", {})
53 git = Utils.cmd_output('GIT_DIR=%s/.git git show --pretty=format:"%h%n%ct%n%H%n%cd" --stat HEAD' % path)
55 lines = git.splitlines()
57 "GIT_COMMIT_ABBREV": lines[0],
58 "GIT_COMMIT_FULLREV": lines[2],
59 "COMMIT_TIME": lines[1],
60 "COMMIT_DATE": lines[3],
63 ret = "GIT-" + fields["GIT_COMMIT_ABBREV"]
65 clean = Utils.cmd_output('git diff HEAD | wc -l', silent=True)
67 fields["COMMIT_IS_CLEAN"] = "1"
69 fields["COMMIT_IS_CLEAN"] = "0"
74 class SambaVersion(object):
76 def __init__(self, version_dict, path, have_git=False):
77 '''Determine the version number of samba
79 See VERSION for the format. Entries on that file are
80 also accepted as dictionary entries here
88 self.ALPHA_RELEASE=None
92 self.RELEASE_NICKNAME=None
93 self.VENDOR_SUFFIX=None
94 self.VENDOR_PATCH=None
96 for a, b in version_dict.iteritems():
97 if a.startswith("SAMBA_VERSION_"):
98 setattr(self, a[14:], b)
102 if self.IS_GIT_SNAPSHOT == "yes":
103 self.IS_SNAPSHOT=True
104 elif self.IS_GIT_SNAPSHOT == "no":
105 self.IS_SNAPSHOT=False
107 raise Exception("Unknown value for IS_GIT_SNAPSHOT: %s" % self.IS_GIT_SNAPSHOT)
110 ## start with "3.0.22"
112 self.MAJOR=int(self.MAJOR)
113 self.MINOR=int(self.MINOR)
114 self.RELEASE=int(self.RELEASE)
116 SAMBA_VERSION_STRING = ("%u.%u.%u" % (self.MAJOR, self.MINOR, self.RELEASE))
119 ## maybe add "3.0.22a" or "4.0.0tp11" or "4.0.0alpha1" or "3.0.22pre1" or "3.0.22rc1"
120 ## We do not do pre or rc version on patch/letter releases
122 if self.REVISION is not None:
123 SAMBA_VERSION_STRING += self.REVISION
124 if self.TP_RELEASE is not None:
125 self.TP_RELEASE = int(self.TP_RELEASE)
126 SAMBA_VERSION_STRING += "tp%u" % self.TP_RELEASE
127 if self.ALPHA_RELEASE is not None:
128 self.ALPHA_RELEASE = int(self.ALPHA_RELEASE)
129 SAMBA_VERSION_STRING += ("alpha%u" % self.ALPHA_RELEASE)
130 if self.PRE_RELEASE is not None:
131 self.PRE_RELEASE = int(self.PRE_RELEASE)
132 SAMBA_VERSION_STRING += ("pre%u" % self.PRE_RELEASE)
133 if self.RC_RELEASE is not None:
134 self.RC_RELEASE = int(self.RC_RELEASE)
135 SAMBA_VERSION_STRING += ("rc%u" % self.RC_RELEASE)
138 if os.path.exists(os.path.join(path, ".git")):
139 suffix, self.vcs_fields = git_version_summary(path, have_git)
140 elif os.path.exists(os.path.join(path, ".bzr")):
141 suffix, self.vcs_fields = bzr_version_summary(path)
145 SAMBA_VERSION_STRING += "-" + suffix
149 self.OFFICIAL_STRING = SAMBA_VERSION_STRING
151 if self.VENDOR_SUFFIX is not None:
152 SAMBA_VERSION_STRING += ("-" + self.VENDOR_SUFFIX)
153 self.VENDOR_SUFFIX = self.VENDOR_SUFFIX
155 if self.VENDOR_PATCH is not None:
156 SAMBA_VERSION_STRING += ("-" + self.VENDOR_PATCH)
157 self.VENDOR_PATCH = self.VENDOR_PATCH
159 self.STRING = SAMBA_VERSION_STRING
161 if self.RELEASE_NICKNAME is not None:
162 self.STRING_WITH_NICKNAME += (" (" + self.RELEASE_NICKNAME + ")")
163 self.RELEASE_NICKNAME = self.RELEASE_NICKNAME
165 self.STRING_WITH_NICKNAME = self.STRING
168 string="/* Autogenerated by waf */\n"
169 string+="#define SAMBA_VERSION_MAJOR %u\n" % self.MAJOR
170 string+="#define SAMBA_VERSION_MINOR %u\n" % self.MINOR
171 string+="#define SAMBA_VERSION_RELEASE %u\n" % self.RELEASE
172 if self.REVISION is not None:
173 string+="#define SAMBA_VERSION_REVISION %u\n" % self.REVISION
175 if self.TP_RELEASE is not None:
176 string+="#define SAMBA_VERSION_TP_RELEASE %u\n" % self.TP_RELEASE
178 if self.ALPHA_RELEASE is not None:
179 string+="#define SAMBA_VERSION_ALPHA_RELEASE %u\n" % self.ALPHA_RELEASE
181 if self.PRE_RELEASE is not None:
182 string+="#define SAMBA_VERSION_PRE_RELEASE %u\n" % self.PRE_RELEASE
184 if self.RC_RELEASE is not None:
185 string+="#define SAMBA_VERSION_RC_RELEASE %u\n" % self.RC_RELEASE
187 for name, value in self.vcs_fields.iteritems():
188 string+="#define SAMBA_VERSION_%s \"%s\"\n" % (name, value)
190 string+="#define SAMBA_VERSION_OFFICIAL_STRING \"" + self.OFFICIAL_STRING + "\"\n"
192 if self.VENDOR_SUFFIX is not None:
193 string+="#define SAMBA_VERSION_VENDOR_SUFFIX " + self.VENDOR_SUFFIX + "\n"
194 if self.VENDOR_PATCH is not None:
195 string+="#define SAMBA_VERSION_VENDOR_PATCH " + self.VENDOR_PATCH + "\n"
197 if self.RELEASE_NICKNAME is not None:
198 string+="#define SAMBA_VERSION_RELEASE_NICKNAME " + self.RELEASE_NICKNAME + "\n"
200 # We need to put this #ifdef in to the headers so that vendors can override the version with a function
202 #ifdef SAMBA_VERSION_VENDOR_FUNCTION
203 # define SAMBA_VERSION_STRING SAMBA_VERSION_VENDOR_FUNCTION
204 #else /* SAMBA_VERSION_VENDOR_FUNCTION */
205 # define SAMBA_VERSION_STRING "''' + self.STRING_WITH_NICKNAME + '''"
208 string+="/* Version for mkrelease.sh: \nSAMBA_VERSION_STRING=" + self.STRING_WITH_NICKNAME + "\n */\n"
213 def samba_version_file(version_file, path, have_git=False):
214 '''Parse the version information from a VERSION file'''
216 f = open(version_file, 'r')
222 if line.startswith("#"):
225 split_line = line.split("=")
226 if split_line[1] != "":
227 value = split_line[1].strip('"')
228 version_dict[split_line[0]] = value
230 print("Failed to parse line %s from %s" % (line, version_file))
233 return SambaVersion(version_dict, path, have_git=have_git)