| 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 hashlib | 7 import hashlib |
| 8 import os | 8 import os |
| 9 import sys | 9 import sys |
| 10 import time | 10 import time |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 # Source files. | 28 # Source files. |
| 29 'dart.cc', | 29 'dart.cc', |
| 30 'dart_api_impl.cc', | 30 'dart_api_impl.cc', |
| 31 'object.cc', | 31 'object.cc', |
| 32 'raw_object.cc', | 32 'raw_object.cc', |
| 33 'raw_object_snapshot.cc', | 33 'raw_object_snapshot.cc', |
| 34 'snapshot.cc', | 34 'snapshot.cc', |
| 35 'symbols.cc', | 35 'symbols.cc', |
| 36 ] | 36 ] |
| 37 | 37 |
| 38 def makeVersionString(quiet): | 38 def makeVersionString(quiet, no_svn): |
| 39 version_string = utils.GetVersion() | 39 version_string = utils.GetSemanticSDKVersion(ignore_svn_revision=no_svn) |
| 40 if not quiet: | 40 if not quiet: |
| 41 debugLog("Returning version string: %s " % version_string) | 41 debugLog("Returning version string: %s " % version_string) |
| 42 return version_string | 42 return version_string |
| 43 | 43 |
| 44 | 44 |
| 45 def makeSnapshotHashString(): | 45 def makeSnapshotHashString(): |
| 46 vmhash = hashlib.md5() | 46 vmhash = hashlib.md5() |
| 47 for vmfilename in VM_SNAPSHOT_FILES: | 47 for vmfilename in VM_SNAPSHOT_FILES: |
| 48 vmfilepath = os.path.join(utils.DART_DIR, 'runtime', 'vm', vmfilename) | 48 vmfilepath = os.path.join(utils.DART_DIR, 'runtime', 'vm', vmfilename) |
| 49 with open(vmfilepath) as vmfile: | 49 with open(vmfilepath) as vmfile: |
| 50 vmhash.update(vmfile.read()) | 50 vmhash.update(vmfile.read()) |
| 51 return vmhash.hexdigest() | 51 return vmhash.hexdigest() |
| 52 | 52 |
| 53 | 53 |
| 54 def makeFile(quiet, output_file, input_file): | 54 def makeFile(quiet, output_file, input_file, ignore_svn_revision): |
| 55 version_cc_text = open(input_file).read() | 55 version_cc_text = open(input_file).read() |
| 56 version_string = makeVersionString(quiet) | 56 version_string = makeVersionString(quiet, ignore_svn_revision) |
| 57 version_cc_text = version_cc_text.replace("{{VERSION_STR}}", | 57 version_cc_text = version_cc_text.replace("{{VERSION_STR}}", |
| 58 version_string) | 58 version_string) |
| 59 version_time = time.ctime(time.time()) | 59 version_time = time.ctime(time.time()) |
| 60 version_cc_text = version_cc_text.replace("{{BUILD_TIME}}", | 60 version_cc_text = version_cc_text.replace("{{BUILD_TIME}}", |
| 61 version_time) | 61 version_time) |
| 62 snapshot_hash = makeSnapshotHashString() | 62 snapshot_hash = makeSnapshotHashString() |
| 63 version_cc_text = version_cc_text.replace("{{SNAPSHOT_HASH}}", | 63 version_cc_text = version_cc_text.replace("{{SNAPSHOT_HASH}}", |
| 64 snapshot_hash) | 64 snapshot_hash) |
| 65 open(output_file, 'w').write(version_cc_text) | 65 open(output_file, 'w').write(version_cc_text) |
| 66 return True | 66 return True |
| 67 | 67 |
| 68 | 68 |
| 69 def main(args): | 69 def main(args): |
| 70 try: | 70 try: |
| 71 # Parse input. | 71 # Parse input. |
| 72 parser = OptionParser() | 72 parser = OptionParser() |
| 73 parser.add_option("-q", "--quiet", | 73 parser.add_option("-q", "--quiet", |
| 74 action="store_true", default=False, | 74 action="store_true", default=False, |
| 75 help="disable console output") | 75 help="disable console output") |
| 76 parser.add_option("--ignore_svn_revision", |
| 77 action="store_true", default=False, |
| 78 help="Don't try to determine svn revision") |
| 76 parser.add_option("--output", | 79 parser.add_option("--output", |
| 77 action="store", type="string", | 80 action="store", type="string", |
| 78 help="output file name") | 81 help="output file name") |
| 79 parser.add_option("--input", | 82 parser.add_option("--input", |
| 80 action="store", type="string", | 83 action="store", type="string", |
| 81 help="input template file") | 84 help="input template file") |
| 82 | 85 |
| 83 (options, args) = parser.parse_args() | 86 (options, args) = parser.parse_args() |
| 84 if not options.output: | 87 if not options.output: |
| 85 sys.stderr.write('--output not specified\n') | 88 sys.stderr.write('--output not specified\n') |
| 86 return -1 | 89 return -1 |
| 87 if not len(options.input): | 90 if not len(options.input): |
| 88 sys.stderr.write('--input not specified\n') | 91 sys.stderr.write('--input not specified\n') |
| 89 return -1 | 92 return -1 |
| 90 | 93 |
| 91 files = [] | 94 files = [] |
| 92 for arg in args: | 95 for arg in args: |
| 93 files.append(arg) | 96 files.append(arg) |
| 94 | 97 |
| 95 if not makeFile(options.quiet, options.output, options.input): | 98 if not makeFile(options.quiet, options.output, options.input, |
| 99 options.ignore_svn_revision): |
| 96 return -1 | 100 return -1 |
| 97 | 101 |
| 98 return 0 | 102 return 0 |
| 99 except Exception, inst: | 103 except Exception, inst: |
| 100 sys.stderr.write('make_version.py exception\n') | 104 sys.stderr.write('make_version.py exception\n') |
| 101 sys.stderr.write(str(inst)) | 105 sys.stderr.write(str(inst)) |
| 102 sys.stderr.write('\n') | 106 sys.stderr.write('\n') |
| 103 return -1 | 107 return -1 |
| 104 | 108 |
| 105 if __name__ == '__main__': | 109 if __name__ == '__main__': |
| 106 exit_code = main(sys.argv) | 110 exit_code = main(sys.argv) |
| 107 sys.exit(exit_code) | 111 sys.exit(exit_code) |
| OLD | NEW |