5 def bzr_version_summary(path
):
7 from bzrlib
import branch
, osutils
, workingtree
9 return ("BZR-UNKNOWN", {})
11 from bzrlib
.plugin
import load_plugins
14 b
= branch
.Branch
.open(path
)
15 (revno
, revid
) = b
.last_revision_info()
16 rev
= b
.repository
.get_revision(revid
)
19 "BZR_REVISION_ID": revid
,
21 "COMMIT_DATE": osutils
.format_date_with_offset_in_original_timezone(rev
.timestamp
,
23 "COMMIT_TIME": int(rev
.timestamp
),
24 "BZR_BRANCH": rev
.properties
.get("branch-nick", ""),
27 # If possible, retrieve the git sha
29 from bzrlib
.plugins
.git
.object_store
import get_object_store
32 ret
= "BZR-%d" % revno
34 store
= get_object_store(b
.repository
)
35 full_rev
= store
._lookup
_revision
_sha
1(revid
)
36 fields
["GIT_COMMIT_ABBREV"] = full_rev
[:7]
37 fields
["GIT_COMMIT_FULLREV"] = full_rev
38 ret
= "GIT-" + fields
["GIT_COMMIT_ABBREV"]
40 if workingtree
.WorkingTree
.open(path
).has_changes():
41 fields
["COMMIT_IS_CLEAN"] = 0
44 fields
["COMMIT_IS_CLEAN"] = 1
48 def git_version_summary(path
, env
=None):
49 # Get version from GIT
51 return ("GIT-UNKNOWN", {})
53 environ
= dict(os
.environ
)
54 environ
["GIT_DIR"] = '%s/.git' % path
55 environ
["GIT_WORK_TREE"] = path
56 git
= Utils
.cmd_output(env
.GIT
+ ' show --pretty=format:"%h%n%ct%n%H%n%cd" --stat HEAD', silent
=True, env
=environ
)
58 lines
= git
.splitlines()
59 if not lines
or len(lines
) < 4:
60 return ("GIT-UNKNOWN", {})
63 "GIT_COMMIT_ABBREV": lines
[0],
64 "GIT_COMMIT_FULLREV": lines
[2],
65 "COMMIT_TIME": int(lines
[1]),
66 "COMMIT_DATE": lines
[3],
69 ret
= "GIT-" + fields
["GIT_COMMIT_ABBREV"]
71 if env
.GIT_LOCAL_CHANGES
:
72 clean
= Utils
.cmd_output('git diff HEAD | wc -l', silent
=True).strip()
74 fields
["COMMIT_IS_CLEAN"] = 1
76 fields
["COMMIT_IS_CLEAN"] = 0
82 class SambaVersion(object):
84 def __init__(self
, version_dict
, path
, env
=None):
85 '''Determine the version number of samba
87 See VERSION for the format. Entries on that file are
88 also accepted as dictionary entries here
96 self
.ALPHA_RELEASE
=None
100 self
.RELEASE_NICKNAME
=None
101 self
.VENDOR_SUFFIX
=None
102 self
.VENDOR_PATCH
=None
104 for a
, b
in version_dict
.iteritems():
105 if a
.startswith("SAMBA_VERSION_"):
106 setattr(self
, a
[14:], b
)
110 if self
.IS_GIT_SNAPSHOT
== "yes":
111 self
.IS_SNAPSHOT
=True
112 elif self
.IS_GIT_SNAPSHOT
== "no":
113 self
.IS_SNAPSHOT
=False
115 raise Exception("Unknown value for IS_GIT_SNAPSHOT: %s" % self
.IS_GIT_SNAPSHOT
)
118 ## start with "3.0.22"
120 self
.MAJOR
=int(self
.MAJOR
)
121 self
.MINOR
=int(self
.MINOR
)
122 self
.RELEASE
=int(self
.RELEASE
)
124 SAMBA_VERSION_STRING
= ("%u.%u.%u" % (self
.MAJOR
, self
.MINOR
, self
.RELEASE
))
127 ## maybe add "3.0.22a" or "4.0.0tp11" or "4.0.0alpha1" or "3.0.22pre1" or "3.0.22rc1"
128 ## We do not do pre or rc version on patch/letter releases
130 if self
.REVISION
is not None:
131 SAMBA_VERSION_STRING
+= self
.REVISION
132 if self
.TP_RELEASE
is not None:
133 self
.TP_RELEASE
= int(self
.TP_RELEASE
)
134 SAMBA_VERSION_STRING
+= "tp%u" % self
.TP_RELEASE
135 if self
.ALPHA_RELEASE
is not None:
136 self
.ALPHA_RELEASE
= int(self
.ALPHA_RELEASE
)
137 SAMBA_VERSION_STRING
+= ("alpha%u" % self
.ALPHA_RELEASE
)
138 if self
.PRE_RELEASE
is not None:
139 self
.PRE_RELEASE
= int(self
.PRE_RELEASE
)
140 SAMBA_VERSION_STRING
+= ("pre%u" % self
.PRE_RELEASE
)
141 if self
.RC_RELEASE
is not None:
142 self
.RC_RELEASE
= int(self
.RC_RELEASE
)
143 SAMBA_VERSION_STRING
+= ("rc%u" % self
.RC_RELEASE
)
146 if os
.path
.exists(os
.path
.join(path
, ".git")):
147 suffix
, self
.vcs_fields
= git_version_summary(path
, env
=env
)
148 elif os
.path
.exists(os
.path
.join(path
, ".bzr")):
149 suffix
, self
.vcs_fields
= bzr_version_summary(path
)
153 SAMBA_VERSION_STRING
+= "-" + suffix
157 self
.OFFICIAL_STRING
= SAMBA_VERSION_STRING
159 if self
.VENDOR_SUFFIX
is not None:
160 SAMBA_VERSION_STRING
+= ("-" + self
.VENDOR_SUFFIX
)
161 self
.VENDOR_SUFFIX
= self
.VENDOR_SUFFIX
163 if self
.VENDOR_PATCH
is not None:
164 SAMBA_VERSION_STRING
+= ("-" + self
.VENDOR_PATCH
)
165 self
.VENDOR_PATCH
= self
.VENDOR_PATCH
167 self
.STRING
= SAMBA_VERSION_STRING
169 if self
.RELEASE_NICKNAME
is not None:
170 self
.STRING_WITH_NICKNAME
+= (" (" + self
.RELEASE_NICKNAME
+ ")")
171 self
.RELEASE_NICKNAME
= self
.RELEASE_NICKNAME
173 self
.STRING_WITH_NICKNAME
= self
.STRING
176 string
="/* Autogenerated by waf */\n"
177 string
+="#define SAMBA_VERSION_MAJOR %u\n" % self
.MAJOR
178 string
+="#define SAMBA_VERSION_MINOR %u\n" % self
.MINOR
179 string
+="#define SAMBA_VERSION_RELEASE %u\n" % self
.RELEASE
180 if self
.REVISION
is not None:
181 string
+="#define SAMBA_VERSION_REVISION %u\n" % self
.REVISION
183 if self
.TP_RELEASE
is not None:
184 string
+="#define SAMBA_VERSION_TP_RELEASE %u\n" % self
.TP_RELEASE
186 if self
.ALPHA_RELEASE
is not None:
187 string
+="#define SAMBA_VERSION_ALPHA_RELEASE %u\n" % self
.ALPHA_RELEASE
189 if self
.PRE_RELEASE
is not None:
190 string
+="#define SAMBA_VERSION_PRE_RELEASE %u\n" % self
.PRE_RELEASE
192 if self
.RC_RELEASE
is not None:
193 string
+="#define SAMBA_VERSION_RC_RELEASE %u\n" % self
.RC_RELEASE
195 for name
in sorted(self
.vcs_fields
.keys()):
196 string
+="#define SAMBA_VERSION_%s " % name
197 value
= self
.vcs_fields
[name
]
198 if isinstance(value
, basestring
):
199 string
+= "\"%s\"" % value
200 elif type(value
) is int:
201 string
+= "%d" % value
203 raise Exception("Unknown type for %s: %r" % (name
, value
))
206 string
+="#define SAMBA_VERSION_OFFICIAL_STRING \"" + self
.OFFICIAL_STRING
+ "\"\n"
208 if self
.VENDOR_SUFFIX
is not None:
209 string
+="#define SAMBA_VERSION_VENDOR_SUFFIX " + self
.VENDOR_SUFFIX
+ "\n"
210 if self
.VENDOR_PATCH
is not None:
211 string
+="#define SAMBA_VERSION_VENDOR_PATCH " + self
.VENDOR_PATCH
+ "\n"
213 if self
.RELEASE_NICKNAME
is not None:
214 string
+="#define SAMBA_VERSION_RELEASE_NICKNAME " + self
.RELEASE_NICKNAME
+ "\n"
216 # We need to put this #ifdef in to the headers so that vendors can override the version with a function
218 #ifdef SAMBA_VERSION_VENDOR_FUNCTION
219 # define SAMBA_VERSION_STRING SAMBA_VERSION_VENDOR_FUNCTION
220 #else /* SAMBA_VERSION_VENDOR_FUNCTION */
221 # define SAMBA_VERSION_STRING "''' + self
.STRING_WITH_NICKNAME
+ '''"
224 string
+="/* Version for mkrelease.sh: \nSAMBA_VERSION_STRING=" + self
.STRING_WITH_NICKNAME
+ "\n */\n"
229 def samba_version_file(version_file
, path
, env
=None):
230 '''Parse the version information from a VERSION file'''
232 f
= open(version_file
, 'r')
238 if line
.startswith("#"):
241 split_line
= line
.split("=")
242 if split_line
[1] != "":
243 value
= split_line
[1].strip('"')
244 version_dict
[split_line
[0]] = value
246 print("Failed to parse line %s from %s" % (line
, version_file
))
249 return SambaVersion(version_dict
, path
, env
=env
)
253 def load_version(env
=None):
254 '''load samba versions either from ./VERSION or git
255 return a version object for detailed breakdown'''
257 env
= samba_utils
.LOAD_ENVIRONMENT()
259 version
= samba_version_file("./VERSION", "..", env
)
260 Utils
.g_module
.VERSION
= version
.STRING