| OLD | NEW |
| 1 # Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 # Copyright (c) 2011, 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 python script creates a version string in a C++ file. | 5 # This python script creates a version string in a C++ file. |
| 6 | 6 |
| 7 import os | 7 import os |
| 8 import sys | 8 import sys |
| 9 import subprocess | 9 import subprocess |
| 10 import platform | 10 import platform |
| 11 import getpass | 11 import getpass |
| 12 from os.path import join | 12 from os.path import join |
| 13 import time | 13 import time |
| 14 from optparse import OptionParser | 14 from optparse import OptionParser |
| 15 | 15 |
| 16 def debugLog(message): | 16 def debugLog(message): |
| 17 print >> sys.stderr, message | 17 print >> sys.stderr, message |
| 18 sys.stderr.flush() | 18 sys.stderr.flush() |
| 19 | 19 |
| 20 | 20 |
| 21 def getVersionPart(version_file, part): | 21 def getVersionPart(version_file, part): |
| 22 command = ['awk', '$1 == "%s" {print $2}' % (part), version_file] | 22 command = ['awk', '$1 == "%s" {print $2}' % (part), version_file] |
| 23 debugLog("Getting version part: %s Running command %s" % (part, command)) | |
| 24 proc = subprocess.Popen(command, | 23 proc = subprocess.Popen(command, |
| 25 stdout=subprocess.PIPE, | 24 stdout=subprocess.PIPE, |
| 26 stderr=subprocess.STDOUT) | 25 stderr=subprocess.STDOUT) |
| 27 result = proc.communicate()[0].split('\n')[0] | 26 result = proc.communicate()[0].split('\n')[0] |
| 28 debugLog("Got result: %s" % result) | |
| 29 return result | 27 return result |
| 30 | 28 |
| 31 def getRevision(): | 29 def getRevision(): |
| 32 debugLog("Getting revision") | |
| 33 is_svn = True | 30 is_svn = True |
| 34 if os.path.exists('.svn'): | 31 if os.path.exists('.svn'): |
| 35 debugLog("Using svn to get revision") | |
| 36 cmd = ['svn', 'info'] | 32 cmd = ['svn', 'info'] |
| 37 else: | 33 else: |
| 38 git_proc = subprocess.Popen( | 34 git_proc = subprocess.Popen( |
| 39 ['git', 'branch', '-r'], | 35 ['git', 'branch', '-r'], |
| 40 stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | 36 stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
| 41 if 'git-svn' in git_proc.communicate()[0]: | 37 if 'git-svn' in git_proc.communicate()[0]: |
| 42 debugLog("Using git svn to get revision") | |
| 43 cmd = ['git', 'svn', 'info'] | 38 cmd = ['git', 'svn', 'info'] |
| 44 else: | 39 else: |
| 45 # Cannot get revision because we are not in svn or | 40 # Cannot get revision because we are not in svn or |
| 46 # git svn checkout. | 41 # git svn checkout. |
| 47 debugLog("Could not get revision: not an svn or git-svn checkout?") | |
| 48 return '' | 42 return '' |
| 49 debugLog("Running command to get revision: %s" % cmd) | |
| 50 proc = subprocess.Popen(cmd, | 43 proc = subprocess.Popen(cmd, |
| 51 stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | 44 stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
| 52 revision = proc.communicate()[0].split('\n')[4].split(' ')[1] | 45 revision = proc.communicate()[0].split('\n')[4].split(' ')[1] |
| 53 debugLog("Got revision: %s" % revision) | |
| 54 return revision | 46 return revision |
| 55 | 47 |
| 56 def makeVersionString(version_file): | 48 def makeVersionString(version_file): |
| 57 id = platform.system() | 49 id = platform.system() |
| 58 if id == 'Windows' or id == 'Microsoft': | 50 if id == 'Windows' or id == 'Microsoft': |
| 59 return '0.0.0.0' | 51 return '0.0.0.0' |
| 60 major = getVersionPart(version_file, 'MAJOR') | 52 major = getVersionPart(version_file, 'MAJOR') |
| 61 minor = getVersionPart(version_file, 'MINOR') | 53 minor = getVersionPart(version_file, 'MINOR') |
| 62 build = getVersionPart(version_file, 'BUILD') | 54 build = getVersionPart(version_file, 'BUILD') |
| 63 patch = getVersionPart(version_file, 'PATCH') | 55 patch = getVersionPart(version_file, 'PATCH') |
| 64 revision = getRevision() | 56 revision = getRevision() |
| 65 user = getpass.getuser() | 57 user = getpass.getuser() |
| 66 version_string = '%s.%s.%s.%s_%s_%s' % (major, | 58 version_string = '%s.%s.%s.%s_%s_%s' % (major, |
| 67 minor, | 59 minor, |
| 68 build, | 60 build, |
| 69 patch, | 61 patch, |
| 70 revision, | 62 revision, |
| 71 user) | 63 user) |
| 72 debugLog("Returning version string: %s " % version_string) | 64 debugLog("Returning version string: %s " % version_string) |
| 73 return version_string | 65 return version_string |
| 74 | 66 |
| 75 def makeFile(output_file, input_file, version_file): | 67 def makeFile(output_file, input_file, version_file): |
| 76 debugLog("Making version file") | |
| 77 version_cc_text = open(input_file).read() | 68 version_cc_text = open(input_file).read() |
| 78 version_string = makeVersionString(version_file) | 69 version_string = makeVersionString(version_file) |
| 79 debugLog("Writing version to version_cc file: %s" % version_string) | |
| 80 version_cc_text = version_cc_text.replace("{{VERSION_STR}}", | 70 version_cc_text = version_cc_text.replace("{{VERSION_STR}}", |
| 81 version_string) | 71 version_string) |
| 82 version_time = time.ctime(time.time()) | 72 version_time = time.ctime(time.time()) |
| 83 debugLog("Writing time to version_cc file: %s" % version_time) | |
| 84 version_cc_text = version_cc_text.replace("{{BUILD_TIME}}", | 73 version_cc_text = version_cc_text.replace("{{BUILD_TIME}}", |
| 85 version_time) | 74 version_time) |
| 86 open(output_file, 'w').write(version_cc_text) | 75 open(output_file, 'w').write(version_cc_text) |
| 87 return True | 76 return True |
| 88 | 77 |
| 89 | 78 |
| 90 def main(args): | 79 def main(args): |
| 91 try: | 80 try: |
| 92 # Parse input. | 81 # Parse input. |
| 93 parser = OptionParser() | 82 parser = OptionParser() |
| (...skipping 25 matching lines...) Expand all Loading... |
| 119 return -1 | 108 return -1 |
| 120 | 109 |
| 121 return 0 | 110 return 0 |
| 122 except Exception, inst: | 111 except Exception, inst: |
| 123 sys.stderr.write('make_version.py exception\n') | 112 sys.stderr.write('make_version.py exception\n') |
| 124 sys.stderr.write(str(inst)) | 113 sys.stderr.write(str(inst)) |
| 125 sys.stderr.write('\n') | 114 sys.stderr.write('\n') |
| 126 return -1 | 115 return -1 |
| 127 | 116 |
| 128 if __name__ == '__main__': | 117 if __name__ == '__main__': |
| 129 debugLog('starting make_version.py') | |
| 130 exit_code = main(sys.argv) | 118 exit_code = main(sys.argv) |
| 131 debugLog('exiting make_version.py (exit code: %s)' % exit_code) | |
| 132 sys.exit(exit_code) | 119 sys.exit(exit_code) |
| OLD | NEW |