| 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): |
| 17 print >> sys.stderr, message |
| 18 sys.stderr.flush() |
| 19 |
| 20 |
| 16 def getVersionPart(version_file, part): | 21 def getVersionPart(version_file, part): |
| 17 command = ['awk', '$1 == "%s" {print $2}' % (part), version_file] | 22 command = ['awk', '$1 == "%s" {print $2}' % (part), version_file] |
| 18 print "Getting version part: %s Running command %s" % (part, command) | 23 debugLog("Getting version part: %s Running command %s" % (part, command)) |
| 19 proc = subprocess.Popen(command, | 24 proc = subprocess.Popen(command, |
| 20 stdout=subprocess.PIPE, | 25 stdout=subprocess.PIPE, |
| 21 stderr=subprocess.STDOUT) | 26 stderr=subprocess.STDOUT) |
| 22 result = proc.communicate()[0].split('\n')[0] | 27 result = proc.communicate()[0].split('\n')[0] |
| 23 print "Got result: %s" % result | 28 debugLog("Got result: %s" % result) |
| 24 return result | 29 return result |
| 25 | 30 |
| 26 def getRevision(): | 31 def getRevision(): |
| 27 print "Getting revision" | 32 debugLog("Getting revision") |
| 28 is_svn = True | 33 is_svn = True |
| 29 if os.path.exists('.svn'): | 34 if os.path.exists('.svn'): |
| 30 print "Using svn to get revision" | 35 debugLog("Using svn to get revision") |
| 31 cmd = ['svn', 'info'] | 36 cmd = ['svn', 'info'] |
| 32 else: | 37 else: |
| 33 print "Using git svn to get revision" | 38 debugLog("Using git svn to get revision") |
| 34 cmd = ['git', 'svn', 'info'] | 39 cmd = ['git', 'svn', 'info'] |
| 35 try: | 40 try: |
| 36 print "Running command to get revision: %s" % cmd | 41 debugLog("Running command to get revision: %s" % cmd) |
| 37 proc = subprocess.Popen(cmd, | 42 proc = subprocess.Popen(cmd, |
| 38 stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | 43 stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
| 39 revision = proc.communicate()[0].split('\n')[4].split(' ')[1] | 44 revision = proc.communicate()[0].split('\n')[4].split(' ')[1] |
| 40 print "Got revision: %s" % revision | 45 debugLog("Got revision: %s" % revision) |
| 41 return revision | 46 return revision |
| 42 except Exception: | 47 except Exception: |
| 43 # If we can't get any revision info (due to lack of tooling) return ''. | 48 # If we can't get any revision info (due to lack of tooling) return ''. |
| 44 return '' | 49 return '' |
| 45 | 50 |
| 46 | 51 |
| 47 def makeVersionString(version_file): | 52 def makeVersionString(version_file): |
| 48 id = platform.system() | 53 id = platform.system() |
| 49 if id == 'Windows' or id == 'Microsoft': | 54 if id == 'Windows' or id == 'Microsoft': |
| 50 return '0.0.0.0' | 55 return '0.0.0.0' |
| 51 major = getVersionPart(version_file, 'MAJOR') | 56 major = getVersionPart(version_file, 'MAJOR') |
| 52 minor = getVersionPart(version_file, 'MINOR') | 57 minor = getVersionPart(version_file, 'MINOR') |
| 53 build = getVersionPart(version_file, 'BUILD') | 58 build = getVersionPart(version_file, 'BUILD') |
| 54 patch = getVersionPart(version_file, 'PATCH') | 59 patch = getVersionPart(version_file, 'PATCH') |
| 55 revision = getRevision() | 60 revision = getRevision() |
| 56 user = getpass.getuser() | 61 user = getpass.getuser() |
| 57 version_string = '%s.%s.%s.%s_%s_%s' % (major, | 62 version_string = '%s.%s.%s.%s_%s_%s' % (major, |
| 58 minor, | 63 minor, |
| 59 build, | 64 build, |
| 60 patch, | 65 patch, |
| 61 revision, | 66 revision, |
| 62 user) | 67 user) |
| 63 print "Returning version string: %s " % version_string | 68 debugLog("Returning version string: %s " % version_string) |
| 64 return version_string | 69 return version_string |
| 65 | 70 |
| 66 def makeFile(output_file, input_file, version_file): | 71 def makeFile(output_file, input_file, version_file): |
| 67 print "Making version file" | 72 debugLog("Making version file") |
| 68 version_cc_text = open(input_file).read() | 73 version_cc_text = open(input_file).read() |
| 69 version_string = makeVersionString(version_file) | 74 version_string = makeVersionString(version_file) |
| 70 print "Writing version to version_cc file: %s" % version_string | 75 debugLog("Writing version to version_cc file: %s" % version_string) |
| 71 version_cc_text = version_cc_text.replace("{{VERSION_STR}}", | 76 version_cc_text = version_cc_text.replace("{{VERSION_STR}}", |
| 72 version_string) | 77 version_string) |
| 73 version_time = time.ctime(time.time()) | 78 version_time = time.ctime(time.time()) |
| 74 print "Writing time to version_cc file: %s" % version_time | 79 debugLog("Writing time to version_cc file: %s" % version_time) |
| 75 version_cc_text = version_cc_text.replace("{{BUILD_TIME}}", | 80 version_cc_text = version_cc_text.replace("{{BUILD_TIME}}", |
| 76 version_time) | 81 version_time) |
| 77 open(output_file, 'w').write(version_cc_text) | 82 open(output_file, 'w').write(version_cc_text) |
| 78 return True | 83 return True |
| 79 | 84 |
| 80 | 85 |
| 81 def main(args): | 86 def main(args): |
| 82 try: | 87 try: |
| 83 # Parse input. | 88 # Parse input. |
| 84 parser = OptionParser() | 89 parser = OptionParser() |
| (...skipping 25 matching lines...) Expand all Loading... |
| 110 return -1 | 115 return -1 |
| 111 | 116 |
| 112 return 0 | 117 return 0 |
| 113 except Exception, inst: | 118 except Exception, inst: |
| 114 sys.stderr.write('make_version.py exception\n') | 119 sys.stderr.write('make_version.py exception\n') |
| 115 sys.stderr.write(str(inst)) | 120 sys.stderr.write(str(inst)) |
| 116 sys.stderr.write('\n') | 121 sys.stderr.write('\n') |
| 117 return -1 | 122 return -1 |
| 118 | 123 |
| 119 if __name__ == '__main__': | 124 if __name__ == '__main__': |
| 120 sys.stderr.write('starting make_version.py\n') | 125 debugLog('starting make_version.py') |
| 121 sys.stderr.flush() | |
| 122 exit_code = main(sys.argv) | 126 exit_code = main(sys.argv) |
| 123 sys.stderr.write('exiting make_version.py (exit code: %s)\n' % exit_code) | 127 debugLog('exiting make_version.py (exit code: %s)' % exit_code) |
| 124 sys.stderr.flush() | |
| 125 sys.exit(exit_code) | 128 sys.exit(exit_code) |
| OLD | NEW |