4 def bzr_version_summary(path):
6 from bzrlib import branch, osutils, workingtree
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,
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 if workingtree.WorkingTree.open(path).has_changes():
40 fields["COMMIT_IS_CLEAN"] = 0
43 fields["COMMIT_IS_CLEAN"] = 1
47 def git_version_summary(path, have_git):
48 # Get version from GIT
50 return ("GIT-UNKNOWN", {})
52 git = Utils.cmd_output(env={"GIT_DIR": "%s/.git" % path}, cmd=["git", "show", '--pretty=format:%h%n%ct%n%H%n%cd', "--stat", "HEAD"])
54 lines = git.splitlines()
56 "GIT_COMMIT_ABBREV": lines[0],
57 "GIT_COMMIT_FULLREV": lines[2],
58 "COMMIT_TIME": int(lines[1]),
59 "COMMIT_DATE": lines[3],
62 ret = "GIT-" + fields["GIT_COMMIT_ABBREV"]
64 clean = Utils.cmd_output('git diff HEAD | wc -l', silent=True)
66 fields["COMMIT_IS_CLEAN"] = 1
68 fields["COMMIT_IS_CLEAN"] = 0
73 class SambaVersion(object):
75 def __init__(self, version_dict, path, have_git=False):
76 '''Determine the version number of samba
78 See VERSION for the format. Entries on that file are
79 also accepted as dictionary entries here
87 self.ALPHA_RELEASE=None
91 self.RELEASE_NICKNAME=None
92 self.VENDOR_SUFFIX=None
93 self.VENDOR_PATCH=None
95 for a, b in version_dict.iteritems():
96 if a.startswith("SAMBA_VERSION_"):
97 setattr(self, a[14:], b)
101 if self.IS_GIT_SNAPSHOT == "yes":
102 self.IS_SNAPSHOT=True
103 elif self.IS_GIT_SNAPSHOT == "no":
104 self.IS_SNAPSHOT=False
106 raise Exception("Unknown value for IS_GIT_SNAPSHOT: %s" % self.IS_GIT_SNAPSHOT)
109 ## start with "3.0.22"
111 self.MAJOR=int(self.MAJOR)
112 self.MINOR=int(self.MINOR)
113 self.RELEASE=int(self.RELEASE)
115 SAMBA_VERSION_STRING = ("%u.%u.%u" % (self.MAJOR, self.MINOR, self.RELEASE))
118 ## maybe add "3.0.22a" or "4.0.0tp11" or "4.0.0alpha1" or "3.0.22pre1" or "3.0.22rc1"
119 ## We do not do pre or rc version on patch/letter releases
121 if self.REVISION is not None:
122 SAMBA_VERSION_STRING += self.REVISION
123 if self.TP_RELEASE is not None:
124 self.TP_RELEASE = int(self.TP_RELEASE)
125 SAMBA_VERSION_STRING += "tp%u" % self.TP_RELEASE
126 if self.ALPHA_RELEASE is not None:
127 self.ALPHA_RELEASE = int(self.ALPHA_RELEASE)
128 SAMBA_VERSION_STRING += ("alpha%u" % self.ALPHA_RELEASE)
129 if self.PRE_RELEASE is not None:
130 self.PRE_RELEASE = int(self.PRE_RELEASE)
131 SAMBA_VERSION_STRING += ("pre%u" % self.PRE_RELEASE)
132 if self.RC_RELEASE is not None:
133 self.RC_RELEASE = int(self.RC_RELEASE)
134 SAMBA_VERSION_STRING += ("rc%u" % self.RC_RELEASE)
137 if os.path.exists(os.path.join(path, ".git")):
138 suffix, self.vcs_fields = git_version_summary(path, have_git)
139 elif os.path.exists(os.path.join(path, ".bzr")):
140 suffix, self.vcs_fields = bzr_version_summary(path)
144 SAMBA_VERSION_STRING += "-" + suffix
148 self.OFFICIAL_STRING = SAMBA_VERSION_STRING
150 if self.VENDOR_SUFFIX is not None:
151 SAMBA_VERSION_STRING += ("-" + self.VENDOR_SUFFIX)
152 self.VENDOR_SUFFIX = self.VENDOR_SUFFIX
154 if self.VENDOR_PATCH is not None:
155 SAMBA_VERSION_STRING += ("-" + self.VENDOR_PATCH)
156 self.VENDOR_PATCH = self.VENDOR_PATCH
158 self.STRING = SAMBA_VERSION_STRING
160 if self.RELEASE_NICKNAME is not None:
161 self.STRING_WITH_NICKNAME += (" (" + self.RELEASE_NICKNAME + ")")
162 self.RELEASE_NICKNAME = self.RELEASE_NICKNAME
164 self.STRING_WITH_NICKNAME = self.STRING
167 string="/* Autogenerated by waf */\n"
168 string+="#define SAMBA_VERSION_MAJOR %u\n" % self.MAJOR
169 string+="#define SAMBA_VERSION_MINOR %u\n" % self.MINOR
170 string+="#define SAMBA_VERSION_RELEASE %u\n" % self.RELEASE
171 if self.REVISION is not None:
172 string+="#define SAMBA_VERSION_REVISION %u\n" % self.REVISION
174 if self.TP_RELEASE is not None:
175 string+="#define SAMBA_VERSION_TP_RELEASE %u\n" % self.TP_RELEASE
177 if self.ALPHA_RELEASE is not None:
178 string+="#define SAMBA_VERSION_ALPHA_RELEASE %u\n" % self.ALPHA_RELEASE
180 if self.PRE_RELEASE is not None:
181 string+="#define SAMBA_VERSION_PRE_RELEASE %u\n" % self.PRE_RELEASE
183 if self.RC_RELEASE is not None:
184 string+="#define SAMBA_VERSION_RC_RELEASE %u\n" % self.RC_RELEASE
186 for name in sorted(self.vcs_fields.keys()):
187 string+="#define SAMBA_VERSION_%s " % name
188 value = self.vcs_fields[name]
189 if isinstance(value, basestring):
190 string += "\"%s\"" % value
191 elif type(value) is int:
192 string += "%d" % value
194 raise Exception("Unknown type for %s: %r" % (name, value))
197 string+="#define SAMBA_VERSION_OFFICIAL_STRING \"" + self.OFFICIAL_STRING + "\"\n"
199 if self.VENDOR_SUFFIX is not None:
200 string+="#define SAMBA_VERSION_VENDOR_SUFFIX " + self.VENDOR_SUFFIX + "\n"
201 if self.VENDOR_PATCH is not None:
202 string+="#define SAMBA_VERSION_VENDOR_PATCH " + self.VENDOR_PATCH + "\n"
204 if self.RELEASE_NICKNAME is not None:
205 string+="#define SAMBA_VERSION_RELEASE_NICKNAME " + self.RELEASE_NICKNAME + "\n"
207 # We need to put this #ifdef in to the headers so that vendors can override the version with a function
209 #ifdef SAMBA_VERSION_VENDOR_FUNCTION
210 # define SAMBA_VERSION_STRING SAMBA_VERSION_VENDOR_FUNCTION
211 #else /* SAMBA_VERSION_VENDOR_FUNCTION */
212 # define SAMBA_VERSION_STRING "''' + self.STRING_WITH_NICKNAME + '''"
215 string+="/* Version for mkrelease.sh: \nSAMBA_VERSION_STRING=" + self.STRING_WITH_NICKNAME + "\n */\n"
220 def samba_version_file(version_file, path, have_git=False):
221 '''Parse the version information from a VERSION file'''
223 f = open(version_file, 'r')
229 if line.startswith("#"):
232 split_line = line.split("=")
233 if split_line[1] != "":
234 value = split_line[1].strip('"')
235 version_dict[split_line[0]] = value
237 print("Failed to parse line %s from %s" % (line, version_file))
240 return SambaVersion(version_dict, path, have_git=have_git)