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
_sha
1(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
, env
=None):
48 # Get version from GIT
50 return ("GIT-UNKNOWN", {})
52 os
.putenv('GIT_DIR', '%s/.git' % path
)
53 git
= Utils
.cmd_output(env
.GIT
+ ' show --pretty=format:"%h%n%ct%n%H%n%cd" --stat HEAD', silent
=True)
55 lines
= git
.splitlines()
56 if not lines
or len(lines
) < 4:
57 return ("GIT-UNKNOWN", {})
60 "GIT_COMMIT_ABBREV": lines
[0],
61 "GIT_COMMIT_FULLREV": lines
[2],
62 "COMMIT_TIME": int(lines
[1]),
63 "COMMIT_DATE": lines
[3],
66 ret
= "GIT-" + fields
["GIT_COMMIT_ABBREV"]
68 if env
.GIT_LOCAL_CHANGES
:
69 clean
= Utils
.cmd_output('git diff HEAD | wc -l', silent
=True).strip()
71 fields
["COMMIT_IS_CLEAN"] = 1
73 fields
["COMMIT_IS_CLEAN"] = 0
79 class SambaVersion(object):
81 def __init__(self
, version_dict
, path
, env
=None):
82 '''Determine the version number of samba
84 See VERSION for the format. Entries on that file are
85 also accepted as dictionary entries here
93 self
.ALPHA_RELEASE
=None
97 self
.RELEASE_NICKNAME
=None
98 self
.VENDOR_SUFFIX
=None
99 self
.VENDOR_PATCH
=None
101 for a
, b
in version_dict
.iteritems():
102 if a
.startswith("SAMBA_VERSION_"):
103 setattr(self
, a
[14:], b
)
107 if self
.IS_GIT_SNAPSHOT
== "yes":
108 self
.IS_SNAPSHOT
=True
109 elif self
.IS_GIT_SNAPSHOT
== "no":
110 self
.IS_SNAPSHOT
=False
112 raise Exception("Unknown value for IS_GIT_SNAPSHOT: %s" % self
.IS_GIT_SNAPSHOT
)
115 ## start with "3.0.22"
117 self
.MAJOR
=int(self
.MAJOR
)
118 self
.MINOR
=int(self
.MINOR
)
119 self
.RELEASE
=int(self
.RELEASE
)
121 SAMBA_VERSION_STRING
= ("%u.%u.%u" % (self
.MAJOR
, self
.MINOR
, self
.RELEASE
))
124 ## maybe add "3.0.22a" or "4.0.0tp11" or "4.0.0alpha1" or "3.0.22pre1" or "3.0.22rc1"
125 ## We do not do pre or rc version on patch/letter releases
127 if self
.REVISION
is not None:
128 SAMBA_VERSION_STRING
+= self
.REVISION
129 if self
.TP_RELEASE
is not None:
130 self
.TP_RELEASE
= int(self
.TP_RELEASE
)
131 SAMBA_VERSION_STRING
+= "tp%u" % self
.TP_RELEASE
132 if self
.ALPHA_RELEASE
is not None:
133 self
.ALPHA_RELEASE
= int(self
.ALPHA_RELEASE
)
134 SAMBA_VERSION_STRING
+= ("alpha%u" % self
.ALPHA_RELEASE
)
135 if self
.PRE_RELEASE
is not None:
136 self
.PRE_RELEASE
= int(self
.PRE_RELEASE
)
137 SAMBA_VERSION_STRING
+= ("pre%u" % self
.PRE_RELEASE
)
138 if self
.RC_RELEASE
is not None:
139 self
.RC_RELEASE
= int(self
.RC_RELEASE
)
140 SAMBA_VERSION_STRING
+= ("rc%u" % self
.RC_RELEASE
)
143 if os
.path
.exists(os
.path
.join(path
, ".git")):
144 suffix
, self
.vcs_fields
= git_version_summary(path
, env
=env
)
145 elif os
.path
.exists(os
.path
.join(path
, ".bzr")):
146 suffix
, self
.vcs_fields
= bzr_version_summary(path
)
150 SAMBA_VERSION_STRING
+= "-" + suffix
154 self
.OFFICIAL_STRING
= SAMBA_VERSION_STRING
156 if self
.VENDOR_SUFFIX
is not None:
157 SAMBA_VERSION_STRING
+= ("-" + self
.VENDOR_SUFFIX
)
158 self
.VENDOR_SUFFIX
= self
.VENDOR_SUFFIX
160 if self
.VENDOR_PATCH
is not None:
161 SAMBA_VERSION_STRING
+= ("-" + self
.VENDOR_PATCH
)
162 self
.VENDOR_PATCH
= self
.VENDOR_PATCH
164 self
.STRING
= SAMBA_VERSION_STRING
166 if self
.RELEASE_NICKNAME
is not None:
167 self
.STRING_WITH_NICKNAME
+= (" (" + self
.RELEASE_NICKNAME
+ ")")
168 self
.RELEASE_NICKNAME
= self
.RELEASE_NICKNAME
170 self
.STRING_WITH_NICKNAME
= self
.STRING
173 string
="/* Autogenerated by waf */\n"
174 string
+="#define SAMBA_VERSION_MAJOR %u\n" % self
.MAJOR
175 string
+="#define SAMBA_VERSION_MINOR %u\n" % self
.MINOR
176 string
+="#define SAMBA_VERSION_RELEASE %u\n" % self
.RELEASE
177 if self
.REVISION
is not None:
178 string
+="#define SAMBA_VERSION_REVISION %u\n" % self
.REVISION
180 if self
.TP_RELEASE
is not None:
181 string
+="#define SAMBA_VERSION_TP_RELEASE %u\n" % self
.TP_RELEASE
183 if self
.ALPHA_RELEASE
is not None:
184 string
+="#define SAMBA_VERSION_ALPHA_RELEASE %u\n" % self
.ALPHA_RELEASE
186 if self
.PRE_RELEASE
is not None:
187 string
+="#define SAMBA_VERSION_PRE_RELEASE %u\n" % self
.PRE_RELEASE
189 if self
.RC_RELEASE
is not None:
190 string
+="#define SAMBA_VERSION_RC_RELEASE %u\n" % self
.RC_RELEASE
192 for name
in sorted(self
.vcs_fields
.keys()):
193 string
+="#define SAMBA_VERSION_%s " % name
194 value
= self
.vcs_fields
[name
]
195 if isinstance(value
, basestring
):
196 string
+= "\"%s\"" % value
197 elif type(value
) is int:
198 string
+= "%d" % value
200 raise Exception("Unknown type for %s: %r" % (name
, value
))
203 string
+="#define SAMBA_VERSION_OFFICIAL_STRING \"" + self
.OFFICIAL_STRING
+ "\"\n"
205 if self
.VENDOR_SUFFIX
is not None:
206 string
+="#define SAMBA_VERSION_VENDOR_SUFFIX " + self
.VENDOR_SUFFIX
+ "\n"
207 if self
.VENDOR_PATCH
is not None:
208 string
+="#define SAMBA_VERSION_VENDOR_PATCH " + self
.VENDOR_PATCH
+ "\n"
210 if self
.RELEASE_NICKNAME
is not None:
211 string
+="#define SAMBA_VERSION_RELEASE_NICKNAME " + self
.RELEASE_NICKNAME
+ "\n"
213 # We need to put this #ifdef in to the headers so that vendors can override the version with a function
215 #ifdef SAMBA_VERSION_VENDOR_FUNCTION
216 # define SAMBA_VERSION_STRING SAMBA_VERSION_VENDOR_FUNCTION
217 #else /* SAMBA_VERSION_VENDOR_FUNCTION */
218 # define SAMBA_VERSION_STRING "''' + self
.STRING_WITH_NICKNAME
+ '''"
221 string
+="/* Version for mkrelease.sh: \nSAMBA_VERSION_STRING=" + self
.STRING_WITH_NICKNAME
+ "\n */\n"
226 def samba_version_file(version_file
, path
, env
=None):
227 '''Parse the version information from a VERSION file'''
229 f
= open(version_file
, 'r')
235 if line
.startswith("#"):
238 split_line
= line
.split("=")
239 if split_line
[1] != "":
240 value
= split_line
[1].strip('"')
241 version_dict
[split_line
[0]] = value
243 print("Failed to parse line %s from %s" % (line
, version_file
))
246 return SambaVersion(version_dict
, path
, env
=env
)