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

Side by Side Diff: tools/utils.py

Issue 1153033007: Add python based VERSION file generation for sdk bots (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: fix spelling Created 5 years, 6 months 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
« no previous file with comments | « tools/bots/dart_sdk.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 datetime
10 import json
9 import os 11 import os
10 import platform 12 import platform
11 import re 13 import re
12 import shutil 14 import shutil
13 import subprocess 15 import subprocess
14 import tempfile 16 import tempfile
15 import sys 17 import sys
16 18
17 class Version(object): 19 class Version(object):
18 def __init__(self, channel, major, minor, patch, prerelease, 20 def __init__(self, channel, major, minor, patch, prerelease,
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 return 'edge_%s' % pad(GetSVNRevision(), 6) 313 return 'edge_%s' % pad(GetSVNRevision(), 6)
312 elif version.channel == 'dev': 314 elif version.channel == 'dev':
313 return 'dev_%s_%s' % (pad(version.prerelease, 2), 315 return 'dev_%s_%s' % (pad(version.prerelease, 2),
314 pad(version.prerelease_patch, 2)) 316 pad(version.prerelease_patch, 2))
315 else: 317 else:
316 return 'release' 318 return 'release'
317 319
318 def GetVersion(): 320 def GetVersion():
319 return GetSemanticSDKVersion() 321 return GetSemanticSDKVersion()
320 322
323
324 # The editor used to produce the VERSION file put on gcs. We now produce this
325 # in the bots archiving the sdk.
326 # The content looks like this:
327 #{
328 # "date": "2015-05-28",
329 # "version": "1.11.0-edge.131653",
330 # "revision": "535394c2657ede445142d8a92486d3899bbf49b5"
331 #}
332 def GetVersionFileContent():
333 result = {"date": str(datetime.date.today()),
334 "version": GetVersion(),
335 "revision": GetGitRevision()}
336 return json.dumps(result, indent=2)
337
321 def GetChannel(): 338 def GetChannel():
322 version = ReadVersionFile() 339 version = ReadVersionFile()
323 return version.channel 340 return version.channel
324 341
325 def GetUserName(): 342 def GetUserName():
326 key = 'USER' 343 key = 'USER'
327 if sys.platform == 'win32': 344 if sys.platform == 'win32':
328 key = 'USERNAME' 345 key = 'USERNAME'
329 return os.environ.get(key, '') 346 return os.environ.get(key, '')
330 347
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 # we use the version number instead for archiving purposes. 398 # we use the version number instead for archiving purposes.
382 # The number on master is the count of commits on the master branch. 399 # The number on master is the count of commits on the master branch.
383 def GetArchiveVersion(): 400 def GetArchiveVersion():
384 version = ReadVersionFile() 401 version = ReadVersionFile()
385 if not version: 402 if not version:
386 raise 'Could not get the archive version, parsing the version file failed' 403 raise 'Could not get the archive version, parsing the version file failed'
387 if version.channel == 'be': 404 if version.channel == 'be':
388 return GetGitNumber() 405 return GetGitNumber()
389 return GetSemanticSDKVersion() 406 return GetSemanticSDKVersion()
390 407
408
409 def GetGitRevision():
410 p = subprocess.Popen(['git', 'log', '-n', '1', '--pretty=format:%H'],
411 stdout = subprocess.PIPE,
412 stderr = subprocess.STDOUT, shell=IsWindows(),
413 cwd = DART_DIR)
414 output, _ = p.communicate()
415 # We expect a full git hash
416 if len(output) != 40:
417 print "Warning: could not parse git commit, output was %s" % output
418 return None
419 return output
420
391 # To eliminate clashing with older archived builds on bleding edge we add 421 # To eliminate clashing with older archived builds on bleding edge we add
392 # a base number bigger the largest svn revision (this also gives us an easy 422 # a base number bigger the largest svn revision (this also gives us an easy
393 # way of seeing if an archive comes from git based or svn based commits). 423 # way of seeing if an archive comes from git based or svn based commits).
394 GIT_NUMBER_BASE = 100000 424 GIT_NUMBER_BASE = 100000
395 def GetGitNumber(): 425 def GetGitNumber():
396 p = subprocess.Popen(['git', 'rev-list', 'HEAD', '--count'], 426 p = subprocess.Popen(['git', 'rev-list', 'HEAD', '--count'],
397 stdout = subprocess.PIPE, 427 stdout = subprocess.PIPE,
398 stderr = subprocess.STDOUT, shell=IsWindows(), 428 stderr = subprocess.STDOUT, shell=IsWindows(),
399 cwd = DART_DIR) 429 cwd = DART_DIR)
400 output, _ = p.communicate() 430 output, _ = p.communicate()
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 except OSError, e: 530 except OSError, e:
501 PrintError("os.unlink() " + str(e)) 531 PrintError("os.unlink() " + str(e))
502 532
503 533
504 def Main(): 534 def Main():
505 print "GuessOS() -> ", GuessOS() 535 print "GuessOS() -> ", GuessOS()
506 print "GuessArchitecture() -> ", GuessArchitecture() 536 print "GuessArchitecture() -> ", GuessArchitecture()
507 print "GuessCpus() -> ", GuessCpus() 537 print "GuessCpus() -> ", GuessCpus()
508 print "IsWindows() -> ", IsWindows() 538 print "IsWindows() -> ", IsWindows()
509 print "GuessVisualStudioPath() -> ", GuessVisualStudioPath() 539 print "GuessVisualStudioPath() -> ", GuessVisualStudioPath()
510 540 print "GetGitRevision() -> ", GetGitRevision()
541 print "GetVersionFileContent() -> ", GetVersionFileContent()
511 542
512 class Error(Exception): 543 class Error(Exception):
513 pass 544 pass
514 545
515 546
516 class ToolError(Exception): 547 class ToolError(Exception):
517 """Deprecated exception, use Error instead.""" 548 """Deprecated exception, use Error instead."""
518 549
519 def __init__(self, value): 550 def __init__(self, value):
520 self.value = value 551 self.value = value
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 os.chdir(self._working_directory) 632 os.chdir(self._working_directory)
602 633
603 def __exit__(self, *_): 634 def __exit__(self, *_):
604 print "Enter directory = ", self._old_cwd 635 print "Enter directory = ", self._old_cwd
605 os.chdir(self._old_cwd) 636 os.chdir(self._old_cwd)
606 637
607 638
608 if __name__ == "__main__": 639 if __name__ == "__main__":
609 import sys 640 import sys
610 Main() 641 Main()
OLDNEW
« no previous file with comments | « tools/bots/dart_sdk.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698