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