OLD | NEW |
1 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 # for details. All rights reserved. Use of this source code is governed by a | 2 # for details. All rights reserved. Use of this source code is governed by a |
3 # BSD-style license that can be found in the LICENSE file. | 3 # BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 # This file contains a set of utilities functions used by other Python-based | 5 # This file contains a set of utilities functions used by other Python-based |
6 # scripts. | 6 # scripts. |
7 | 7 |
8 import commands | 8 import commands |
9 import os | 9 import os |
10 import platform | 10 import platform |
11 import re | 11 import re |
12 import shutil | 12 import shutil |
13 import subprocess | 13 import subprocess |
14 import sys | 14 import sys |
15 import tempfile | 15 import tempfile |
16 | 16 |
17 class Version(object): | |
18 def __init__(self, channel, major, minor, patch, prerelease, | |
19 prerelease_patch): | |
20 self.channel = channel | |
21 self.major = major | |
22 self.minor = minor | |
23 self.patch = patch | |
24 self.prerelease = prerelease | |
25 self.prerelease_patch = prerelease_patch | |
26 | 17 |
27 # Try to guess the host operating system. | 18 # Try to guess the host operating system. |
28 def GuessOS(): | 19 def GuessOS(): |
29 id = platform.system() | 20 id = platform.system() |
30 if id == "Linux": | 21 if id == "Linux": |
31 return "linux" | 22 return "linux" |
32 elif id == "Darwin": | 23 elif id == "Darwin": |
33 return "macos" | 24 return "macos" |
34 elif id == "Windows" or id == "Microsoft": | 25 elif id == "Windows" or id == "Microsoft": |
35 # On Windows Vista platform.system() can return "Microsoft" with some | 26 # On Windows Vista platform.system() can return "Microsoft" with some |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 | 224 |
234 def GetBuildRoot(host_os, mode=None, arch=None, target_os=None): | 225 def GetBuildRoot(host_os, mode=None, arch=None, target_os=None): |
235 build_root = GetBuildDir(host_os, target_os) | 226 build_root = GetBuildDir(host_os, target_os) |
236 if mode: | 227 if mode: |
237 build_root = os.path.join(build_root, GetBuildConf(mode, arch)) | 228 build_root = os.path.join(build_root, GetBuildConf(mode, arch)) |
238 return build_root | 229 return build_root |
239 | 230 |
240 def GetBaseDir(): | 231 def GetBaseDir(): |
241 return BASE_DIR | 232 return BASE_DIR |
242 | 233 |
| 234 # Return the base part of the version, Major.Minor.Build.Patch, |
| 235 # without the _revision addition |
243 def GetShortVersion(): | 236 def GetShortVersion(): |
244 version = ReadVersionFile() | 237 (channel, major, minor, build, patch) = ReadVersionFile() |
245 return ('%s.%s.%s.%s.%s' % ( | 238 # TODO(kustermann/ricow): Add the channel to the version string. |
246 version.major, version.minor, version.patch, version.prerelease, | 239 return '%s.%s.%s.%s' % (major, minor, build, patch) |
247 version.prerelease_patch)) | |
248 | 240 |
249 def GetSemanticSDKVersion(): | 241 |
250 version = ReadVersionFile() | 242 def GetVersion(): |
251 if not version: | 243 version_tuple = ReadVersionFile() |
| 244 if not version_tuple: |
252 return None | 245 return None |
253 | 246 |
254 if version.channel == 'be': | 247 (channel, major, minor, build, patch) = version_tuple |
255 postfix = '-edge.%s' % GetSVNRevision() | 248 revision = GetSVNRevision() |
256 elif version.channel == 'dev': | 249 user = GetUserName() |
257 postfix = '-dev.%s.%s' % (version.prerelease, version.prerelease_patch) | 250 # We don't add username to release builds (or any builds on the bots) |
258 else: | 251 if user == 'chrome-bot': |
259 assert version.channel == 'stable' | 252 user = '' |
260 postfix = '' | |
261 | 253 |
262 return '%s.%s.%s%s' % (version.major, version.minor, version.patch, postfix) | 254 user_string = '' |
| 255 revision_string = '' |
| 256 if user: |
| 257 user_string = '_%s' % user |
| 258 if revision: |
| 259 revision_string = '_r%s' % revision |
263 | 260 |
264 def GetEclipseVersionQualifier(): | 261 # TODO(kustermann/ricow): Add the channel to the version string. |
265 def pad(number, num_digits): | 262 return ("%s.%s.%s.%s%s%s" % |
266 number_str = str(number) | 263 (major, minor, build, patch, revision_string, user_string)) |
267 return '0' * max(0, num_digits - len(number_str)) + number_str | |
268 | |
269 version = ReadVersionFile() | |
270 if version.channel == 'be': | |
271 return 'edge_%s' % pad(GetSVNRevision(), 6) | |
272 elif version.channel == 'dev': | |
273 return 'dev_%s_%s' % (pad(version.prerelease, 2), | |
274 pad(version.prerelease_patch, 2)) | |
275 else: | |
276 return 'release' | |
277 | |
278 def GetVersion(): | |
279 return GetSemanticSDKVersion() | |
280 | 264 |
281 def GetChannel(): | 265 def GetChannel(): |
282 version = ReadVersionFile() | 266 (channel, _, _, _, _) = ReadVersionFile() |
283 return version.channel | 267 return channel |
284 | 268 |
285 def GetUserName(): | 269 def GetUserName(): |
286 key = 'USER' | 270 key = 'USER' |
287 if sys.platform == 'win32': | 271 if sys.platform == 'win32': |
288 key = 'USERNAME' | 272 key = 'USERNAME' |
289 return os.environ.get(key, '') | 273 return os.environ.get(key, '') |
290 | 274 |
291 def ReadVersionFile(): | 275 def ReadVersionFile(): |
292 def match_against(pattern, content): | |
293 match = re.search(pattern, content, flags=re.MULTILINE) | |
294 if match: | |
295 return match.group(1) | |
296 return None | |
297 | |
298 version_file = os.path.join(DART_DIR, 'tools', 'VERSION') | 276 version_file = os.path.join(DART_DIR, 'tools', 'VERSION') |
299 try: | 277 try: |
300 fd = open(version_file) | 278 fd = open(version_file) |
301 content = fd.read() | 279 content = fd.read() |
302 fd.close() | 280 fd.close() |
303 except: | 281 except: |
304 print "Warning: Couldn't read VERSION file (%s)" % version_file | 282 print "Warning: Couldn't read VERSION file (%s)" % version_file |
305 return None | 283 return None |
306 | 284 channel_match = re.search( |
307 channel = match_against('^CHANNEL ([A-Za-z0-9]+)$', content) | 285 '^CHANNEL ([A-Za-z0-9]+)$', content, flags=re.MULTILINE) |
308 major = match_against('^MAJOR (\d+)$', content) | 286 major_match = re.search('^MAJOR (\d+)$', content, flags=re.MULTILINE) |
309 minor = match_against('^MINOR (\d+)$', content) | 287 minor_match = re.search('^MINOR (\d+)$', content, flags=re.MULTILINE) |
310 patch = match_against('^PATCH (\d+)$', content) | 288 build_match = re.search('^BUILD (\d+)$', content, flags=re.MULTILINE) |
311 prerelease = match_against('^PRERELEASE (\d+)$', content) | 289 patch_match = re.search('^PATCH (\d+)$', content, flags=re.MULTILINE) |
312 prerelease_patch = match_against('^PRERELEASE_PATCH (\d+)$', content) | 290 if (channel_match and |
313 | 291 major_match and |
314 if channel and major and minor and prerelease and prerelease_patch: | 292 minor_match and |
315 return Version( | 293 build_match and |
316 channel, major, minor, patch, prerelease, prerelease_patch) | 294 patch_match): |
| 295 return (channel_match.group(1), major_match.group(1), minor_match.group(1), |
| 296 build_match.group(1), patch_match.group(1)) |
317 else: | 297 else: |
318 print "Warning: VERSION file (%s) has wrong format" % version_file | 298 print "Warning: VERSION file (%s) has wrong format" % version_file |
319 return None | 299 return None |
320 | 300 |
321 def GetSVNRevision(): | 301 def GetSVNRevision(): |
322 # FIXME(kustermann): Make this work for newer SVN versions as well (where | 302 # FIXME(kustermann): Make this work for newer SVN versions as well (where |
323 # we've got only one '.svn' directory) | 303 # we've got only one '.svn' directory) |
324 custom_env = dict(os.environ) | 304 custom_env = dict(os.environ) |
325 custom_env['LC_MESSAGES'] = 'en_GB' | 305 custom_env['LC_MESSAGES'] = 'en_GB' |
326 p = subprocess.Popen(['svn', 'info'], stdout = subprocess.PIPE, | 306 p = subprocess.Popen(['svn', 'info'], stdout = subprocess.PIPE, |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
527 os.chdir(self._working_directory) | 507 os.chdir(self._working_directory) |
528 | 508 |
529 def __exit__(self, *_): | 509 def __exit__(self, *_): |
530 print "Enter directory = ", self._old_cwd | 510 print "Enter directory = ", self._old_cwd |
531 os.chdir(self._old_cwd) | 511 os.chdir(self._old_cwd) |
532 | 512 |
533 | 513 |
534 if __name__ == "__main__": | 514 if __name__ == "__main__": |
535 import sys | 515 import sys |
536 Main(sys.argv) | 516 Main(sys.argv) |
OLD | NEW |