6 def git_version_summary(path
, env
=None):
8 if not 'GIT' in env
and os
.path
.exists("/usr/bin/git"):
9 # this is useful when doing make dist without configuring
10 env
.GIT
= "/usr/bin/git"
13 return ("GIT-UNKNOWN", {})
15 environ
= dict(os
.environ
)
16 environ
["GIT_DIR"] = '%s/.git' % path
17 environ
["GIT_WORK_TREE"] = path
18 git
= Utils
.cmd_output(env
.GIT
+ ' show --pretty=format:"%h%n%ct%n%H%n%cd" --stat HEAD', silent
=True, env
=environ
)
20 lines
= git
.splitlines()
21 if not lines
or len(lines
) < 4:
22 return ("GIT-UNKNOWN", {})
25 "GIT_COMMIT_ABBREV": lines
[0],
26 "GIT_COMMIT_FULLREV": lines
[2],
27 "COMMIT_TIME": int(lines
[1]),
28 "COMMIT_DATE": lines
[3],
31 ret
= "GIT-" + fields
["GIT_COMMIT_ABBREV"]
33 if env
.GIT_LOCAL_CHANGES
:
34 clean
= Utils
.cmd_output('%s diff HEAD | wc -l' % env
.GIT
, silent
=True).strip()
36 fields
["COMMIT_IS_CLEAN"] = 1
38 fields
["COMMIT_IS_CLEAN"] = 0
44 def distversion_version_summary(path
):
45 #get version from .distversion file
46 f
= open(path
+ '/.distversion', 'r')
54 if line
.startswith("#"):
57 split_line
= line
.split("=")
58 if split_line
[1] != "":
66 print("Failed to parse line %s from .distversion file." % (line
))
70 if "COMMIT_TIME" in fields
:
71 fields
["COMMIT_TIME"] = int(fields
["COMMIT_TIME"])
74 return ("UNKNOWN", fields
)
76 return (suffix
, fields
)
79 class SambaVersion(object):
81 def __init__(self
, version_dict
, path
, env
=None, is_install
=True):
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
94 self
.BETA_RELEASE
=None
98 self
.RELEASE_NICKNAME
=None
99 self
.VENDOR_SUFFIX
=None
100 self
.VENDOR_PATCH
=None
102 for a
, b
in version_dict
.iteritems():
103 if a
.startswith("SAMBA_VERSION_"):
104 setattr(self
, a
[14:], b
)
108 if self
.IS_GIT_SNAPSHOT
== "yes":
109 self
.IS_SNAPSHOT
=True
110 elif self
.IS_GIT_SNAPSHOT
== "no":
111 self
.IS_SNAPSHOT
=False
113 raise Exception("Unknown value for IS_GIT_SNAPSHOT: %s" % self
.IS_GIT_SNAPSHOT
)
116 ## start with "3.0.22"
118 self
.MAJOR
=int(self
.MAJOR
)
119 self
.MINOR
=int(self
.MINOR
)
120 self
.RELEASE
=int(self
.RELEASE
)
122 SAMBA_VERSION_STRING
= ("%u.%u.%u" % (self
.MAJOR
, self
.MINOR
, self
.RELEASE
))
125 ## maybe add "3.0.22a" or "4.0.0tp11" or "4.0.0alpha1" or "4.0.0beta1" or "3.0.22pre1" or "3.0.22rc1"
126 ## We do not do pre or rc version on patch/letter releases
128 if self
.REVISION
is not None:
129 SAMBA_VERSION_STRING
+= self
.REVISION
130 if self
.TP_RELEASE
is not None:
131 self
.TP_RELEASE
= int(self
.TP_RELEASE
)
132 SAMBA_VERSION_STRING
+= "tp%u" % self
.TP_RELEASE
133 if self
.ALPHA_RELEASE
is not None:
134 self
.ALPHA_RELEASE
= int(self
.ALPHA_RELEASE
)
135 SAMBA_VERSION_STRING
+= ("alpha%u" % self
.ALPHA_RELEASE
)
136 if self
.BETA_RELEASE
is not None:
137 self
.BETA_RELEASE
= int(self
.BETA_RELEASE
)
138 SAMBA_VERSION_STRING
+= ("beta%u" % self
.BETA_RELEASE
)
139 if self
.PRE_RELEASE
is not None:
140 self
.PRE_RELEASE
= int(self
.PRE_RELEASE
)
141 SAMBA_VERSION_STRING
+= ("pre%u" % self
.PRE_RELEASE
)
142 if self
.RC_RELEASE
is not None:
143 self
.RC_RELEASE
= int(self
.RC_RELEASE
)
144 SAMBA_VERSION_STRING
+= ("rc%u" % self
.RC_RELEASE
)
148 suffix
= "DEVELOPERBUILD"
150 elif os
.path
.exists(os
.path
.join(path
, ".git")):
151 suffix
, self
.vcs_fields
= git_version_summary(path
, env
=env
)
152 elif os
.path
.exists(os
.path
.join(path
, ".distversion")):
153 suffix
, self
.vcs_fields
= distversion_version_summary(path
)
157 self
.vcs_fields
["SUFFIX"] = suffix
158 SAMBA_VERSION_STRING
+= "-" + suffix
162 self
.OFFICIAL_STRING
= SAMBA_VERSION_STRING
164 if self
.VENDOR_SUFFIX
is not None:
165 SAMBA_VERSION_STRING
+= ("-" + self
.VENDOR_SUFFIX
)
166 self
.VENDOR_SUFFIX
= self
.VENDOR_SUFFIX
168 if self
.VENDOR_PATCH
is not None:
169 SAMBA_VERSION_STRING
+= ("-" + self
.VENDOR_PATCH
)
170 self
.VENDOR_PATCH
= self
.VENDOR_PATCH
172 self
.STRING
= SAMBA_VERSION_STRING
174 if self
.RELEASE_NICKNAME
is not None:
175 self
.STRING_WITH_NICKNAME
= "%s (%s)" % (self
.STRING
, self
.RELEASE_NICKNAME
)
177 self
.STRING_WITH_NICKNAME
= self
.STRING
180 string
="/* Autogenerated by waf */\n"
181 string
+="#define SAMBA_VERSION_MAJOR %u\n" % self
.MAJOR
182 string
+="#define SAMBA_VERSION_MINOR %u\n" % self
.MINOR
183 string
+="#define SAMBA_VERSION_RELEASE %u\n" % self
.RELEASE
184 if self
.REVISION
is not None:
185 string
+="#define SAMBA_VERSION_REVISION %u\n" % self
.REVISION
187 if self
.TP_RELEASE
is not None:
188 string
+="#define SAMBA_VERSION_TP_RELEASE %u\n" % self
.TP_RELEASE
190 if self
.ALPHA_RELEASE
is not None:
191 string
+="#define SAMBA_VERSION_ALPHA_RELEASE %u\n" % self
.ALPHA_RELEASE
193 if self
.BETA_RELEASE
is not None:
194 string
+="#define SAMBA_VERSION_BETA_RELEASE %u\n" % self
.BETA_RELEASE
196 if self
.PRE_RELEASE
is not None:
197 string
+="#define SAMBA_VERSION_PRE_RELEASE %u\n" % self
.PRE_RELEASE
199 if self
.RC_RELEASE
is not None:
200 string
+="#define SAMBA_VERSION_RC_RELEASE %u\n" % self
.RC_RELEASE
202 for name
in sorted(self
.vcs_fields
.keys()):
203 string
+="#define SAMBA_VERSION_%s " % name
204 value
= self
.vcs_fields
[name
]
205 if isinstance(value
, basestring
):
206 string
+= "\"%s\"" % value
207 elif type(value
) is int:
208 string
+= "%d" % value
210 raise Exception("Unknown type for %s: %r" % (name
, value
))
213 string
+="#define SAMBA_VERSION_OFFICIAL_STRING \"" + self
.OFFICIAL_STRING
+ "\"\n"
215 if self
.VENDOR_SUFFIX
is not None:
216 string
+="#define SAMBA_VERSION_VENDOR_SUFFIX " + self
.VENDOR_SUFFIX
+ "\n"
217 if self
.VENDOR_PATCH
is not None:
218 string
+="#define SAMBA_VERSION_VENDOR_PATCH " + self
.VENDOR_PATCH
+ "\n"
220 if self
.RELEASE_NICKNAME
is not None:
221 string
+="#define SAMBA_VERSION_RELEASE_NICKNAME " + self
.RELEASE_NICKNAME
+ "\n"
223 # We need to put this #ifdef in to the headers so that vendors can override the version with a function
225 #ifdef SAMBA_VERSION_VENDOR_FUNCTION
226 # define SAMBA_VERSION_STRING SAMBA_VERSION_VENDOR_FUNCTION
227 #else /* SAMBA_VERSION_VENDOR_FUNCTION */
228 # define SAMBA_VERSION_STRING "''' + self
.STRING_WITH_NICKNAME
+ '''"
231 string
+="/* Version for mkrelease.sh: \nSAMBA_VERSION_STRING=" + self
.STRING_WITH_NICKNAME
+ "\n */\n"
236 def samba_version_file(version_file
, path
, env
=None, is_install
=True):
237 '''Parse the version information from a VERSION file'''
239 f
= open(version_file
, 'r')
245 if line
.startswith("#"):
248 split_line
= line
.split("=")
249 if split_line
[1] != "":
250 value
= split_line
[1].strip('"')
251 version_dict
[split_line
[0]] = value
253 print("Failed to parse line %s from %s" % (line
, version_file
))
256 return SambaVersion(version_dict
, path
, env
=env
, is_install
=is_install
)
260 def load_version(env
=None, is_install
=True):
261 '''load samba versions either from ./VERSION or git
262 return a version object for detailed breakdown'''
264 env
= samba_utils
.LOAD_ENVIRONMENT()
266 version
= samba_version_file("./VERSION", ".", env
, is_install
=is_install
)
267 Utils
.g_module
.VERSION
= version
.STRING