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