Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 # BSD-style license that can be found in the LICENSE file. | |
| 4 # | |
| 5 # This python script creates a version string in a C++ file. | |
| 6 | |
| 7 import os | |
| 8 import pwd | |
| 9 import sys | |
| 10 import subprocess | |
| 11 from os.path import join | |
| 12 import time | |
| 13 from optparse import OptionParser | |
| 14 | |
| 15 def getVersionPart(version_file, part): | |
| 16 proc = subprocess.Popen(['awk', | |
|
ricow1
2012/10/11 07:35:24
this will not work on windows
| |
| 17 '$1 == "%s" {print $2}' % (part), | |
| 18 version_file], | |
| 19 stdout=subprocess.PIPE, | |
| 20 stderr=subprocess.STDOUT) | |
| 21 return proc.communicate()[0].split('\n')[0] | |
| 22 | |
| 23 def getRevision(): | |
| 24 is_svn = True | |
| 25 if os.path.exists('.svn'): | |
| 26 cmd = ['svn', 'info'] | |
| 27 else: | |
| 28 cmd = ['git', 'svn', 'info'] | |
| 29 proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | |
| 30 return proc.communicate()[0].split('\n')[4].split(' ')[1] | |
| 31 | |
| 32 def makeVersionString(version_file): | |
| 33 major = getVersionPart(version_file, 'MAJOR') | |
|
ricow1
2012/10/11 07:35:24
maybe we should just make this call "tools/testsin
| |
| 34 minor = getVersionPart(version_file, 'MINOR') | |
| 35 build = getVersionPart(version_file, 'BUILD') | |
| 36 patch = getVersionPart(version_file, 'PATCH') | |
| 37 revision = getRevision() | |
| 38 user = pwd.getpwuid(os.getuid())[0] | |
| 39 return '%s.%s.%s.%s_%s_%s' % (major, minor, build, patch, revision, user) | |
| 40 | |
| 41 def makeFile(output_file, input_file, version_file): | |
| 42 version_cc_text = open(input_file).read() | |
| 43 version_cc_text = version_cc_text.replace("{{VERSION_STR}}", | |
| 44 makeVersionString(version_file)) | |
| 45 version_cc_text = version_cc_text.replace("{{BUILD_TIME}}", | |
| 46 time.ctime(time.time())) | |
| 47 open(output_file, 'w').write(version_cc_text) | |
| 48 return True | |
| 49 | |
| 50 | |
| 51 def main(args): | |
| 52 try: | |
| 53 # Parse input. | |
| 54 parser = OptionParser() | |
| 55 parser.add_option("--output", | |
| 56 action="store", type="string", | |
| 57 help="output file name") | |
| 58 parser.add_option("--input", | |
| 59 action="store", type="string", | |
| 60 help="input template file") | |
| 61 parser.add_option("--version", | |
| 62 action="store", type="string", | |
| 63 help="version file") | |
| 64 | |
| 65 (options, args) = parser.parse_args() | |
| 66 if not options.output: | |
| 67 sys.stderr.write('--output not specified\n') | |
| 68 return -1 | |
| 69 if not len(options.input): | |
| 70 sys.stderr.write('--input not specified\n') | |
| 71 return -1 | |
| 72 | |
| 73 files = [ ] | |
| 74 for arg in args: | |
| 75 files.append(arg) | |
| 76 | |
| 77 if not makeFile(options.output, | |
| 78 options.input, | |
| 79 options.version): | |
| 80 return -1 | |
| 81 | |
| 82 return 0 | |
| 83 except Exception, inst: | |
| 84 sys.stderr.write('make_version.py exception\n') | |
| 85 sys.stderr.write(str(inst)) | |
| 86 sys.stderr.write('\n') | |
| 87 return -1 | |
| 88 | |
| 89 if __name__ == '__main__': | |
| 90 sys.exit(main(sys.argv)) | |
| OLD | NEW |