Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(52)

Side by Side Diff: dart/tools/utils.py

Issue 103233006: Reapply "Change SDK/DartEditor versioning scheme to semantic versions." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « dart/tools/create_windows_installer.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
17 26
18 # Try to guess the host operating system. 27 # Try to guess the host operating system.
19 def GuessOS(): 28 def GuessOS():
20 id = platform.system() 29 id = platform.system()
21 if id == "Linux": 30 if id == "Linux":
22 return "linux" 31 return "linux"
23 elif id == "Darwin": 32 elif id == "Darwin":
24 return "macos" 33 return "macos"
25 elif id == "Windows" or id == "Microsoft": 34 elif id == "Windows" or id == "Microsoft":
26 # On Windows Vista platform.system() can return "Microsoft" with some 35 # On Windows Vista platform.system() can return "Microsoft" with some
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 233
225 def GetBuildRoot(host_os, mode=None, arch=None, target_os=None): 234 def GetBuildRoot(host_os, mode=None, arch=None, target_os=None):
226 build_root = GetBuildDir(host_os, target_os) 235 build_root = GetBuildDir(host_os, target_os)
227 if mode: 236 if mode:
228 build_root = os.path.join(build_root, GetBuildConf(mode, arch)) 237 build_root = os.path.join(build_root, GetBuildConf(mode, arch))
229 return build_root 238 return build_root
230 239
231 def GetBaseDir(): 240 def GetBaseDir():
232 return BASE_DIR 241 return BASE_DIR
233 242
234 # Return the base part of the version, Major.Minor.Build.Patch,
235 # without the _revision addition
236 def GetShortVersion(): 243 def GetShortVersion():
237 (channel, major, minor, build, patch) = ReadVersionFile() 244 version = ReadVersionFile()
238 # TODO(kustermann/ricow): Add the channel to the version string. 245 return ('%s.%s.%s.%s.%s' % (
239 return '%s.%s.%s.%s' % (major, minor, build, patch) 246 version.major, version.minor, version.patch, version.prerelease,
247 version.prerelease_patch))
240 248
249 def GetSemanticSDKVersion():
250 version = ReadVersionFile()
251 if not version:
252 return None
253
254 if version.channel == 'be':
255 postfix = '-edge.%s' % GetSVNRevision()
256 elif version.channel == 'dev':
257 postfix = '-dev.%s.%s' % (version.prerelease, version.prerelease_patch)
258 else:
259 assert version.channel == 'stable'
260 postfix = ''
261
262 return '%s.%s.%s%s' % (version.major, version.minor, version.patch, postfix)
263
264 def GetEclipseVersionQualifier():
265 def pad(number, num_digits):
266 number_str = str(number)
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'
241 277
242 def GetVersion(): 278 def GetVersion():
243 version_tuple = ReadVersionFile() 279 return GetSemanticSDKVersion()
244 if not version_tuple:
245 return None
246
247 (channel, major, minor, build, patch) = version_tuple
248 revision = GetSVNRevision()
249 user = GetUserName()
250 # We don't add username to release builds (or any builds on the bots)
251 if user == 'chrome-bot':
252 user = ''
253
254 user_string = ''
255 revision_string = ''
256 if user:
257 user_string = '_%s' % user
258 if revision:
259 revision_string = '_r%s' % revision
260
261 # TODO(kustermann/ricow): Add the channel to the version string.
262 return ("%s.%s.%s.%s%s%s" %
263 (major, minor, build, patch, revision_string, user_string))
264 280
265 def GetChannel(): 281 def GetChannel():
266 (channel, _, _, _, _) = ReadVersionFile() 282 version = ReadVersionFile()
267 return channel 283 return version.channel
268 284
269 def GetUserName(): 285 def GetUserName():
270 key = 'USER' 286 key = 'USER'
271 if sys.platform == 'win32': 287 if sys.platform == 'win32':
272 key = 'USERNAME' 288 key = 'USERNAME'
273 return os.environ.get(key, '') 289 return os.environ.get(key, '')
274 290
275 def ReadVersionFile(): 291 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
276 version_file = os.path.join(DART_DIR, 'tools', 'VERSION') 298 version_file = os.path.join(DART_DIR, 'tools', 'VERSION')
277 try: 299 try:
278 fd = open(version_file) 300 fd = open(version_file)
279 content = fd.read() 301 content = fd.read()
280 fd.close() 302 fd.close()
281 except: 303 except:
282 print "Warning: Couldn't read VERSION file (%s)" % version_file 304 print "Warning: Couldn't read VERSION file (%s)" % version_file
283 return None 305 return None
284 channel_match = re.search( 306
285 '^CHANNEL ([A-Za-z0-9]+)$', content, flags=re.MULTILINE) 307 channel = match_against('^CHANNEL ([A-Za-z0-9]+)$', content)
286 major_match = re.search('^MAJOR (\d+)$', content, flags=re.MULTILINE) 308 major = match_against('^MAJOR (\d+)$', content)
287 minor_match = re.search('^MINOR (\d+)$', content, flags=re.MULTILINE) 309 minor = match_against('^MINOR (\d+)$', content)
288 build_match = re.search('^BUILD (\d+)$', content, flags=re.MULTILINE) 310 patch = match_against('^PATCH (\d+)$', content)
289 patch_match = re.search('^PATCH (\d+)$', content, flags=re.MULTILINE) 311 prerelease = match_against('^PRERELEASE (\d+)$', content)
290 if (channel_match and 312 prerelease_patch = match_against('^PRERELEASE_PATCH (\d+)$', content)
291 major_match and 313
292 minor_match and 314 if channel and major and minor and prerelease and prerelease_patch:
293 build_match and 315 return Version(
294 patch_match): 316 channel, major, minor, patch, prerelease, prerelease_patch)
295 return (channel_match.group(1), major_match.group(1), minor_match.group(1),
296 build_match.group(1), patch_match.group(1))
297 else: 317 else:
298 print "Warning: VERSION file (%s) has wrong format" % version_file 318 print "Warning: VERSION file (%s) has wrong format" % version_file
299 return None 319 return None
300 320
301 def GetSVNRevision(): 321 def GetSVNRevision():
302 # FIXME(kustermann): Make this work for newer SVN versions as well (where 322 # FIXME(kustermann): Make this work for newer SVN versions as well (where
303 # we've got only one '.svn' directory) 323 # we've got only one '.svn' directory)
304 custom_env = dict(os.environ) 324 custom_env = dict(os.environ)
305 custom_env['LC_MESSAGES'] = 'en_GB' 325 custom_env['LC_MESSAGES'] = 'en_GB'
306 p = subprocess.Popen(['svn', 'info'], stdout = subprocess.PIPE, 326 p = subprocess.Popen(['svn', 'info'], stdout = subprocess.PIPE,
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 os.chdir(self._working_directory) 527 os.chdir(self._working_directory)
508 528
509 def __exit__(self, *_): 529 def __exit__(self, *_):
510 print "Enter directory = ", self._old_cwd 530 print "Enter directory = ", self._old_cwd
511 os.chdir(self._old_cwd) 531 os.chdir(self._old_cwd)
512 532
513 533
514 if __name__ == "__main__": 534 if __name__ == "__main__":
515 import sys 535 import sys
516 Main(sys.argv) 536 Main(sys.argv)
OLDNEW
« no previous file with comments | « dart/tools/create_windows_installer.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698