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 | |
8 import os | |
7 import sys | 9 import sys |
8 import time | 10 import time |
9 from optparse import OptionParser | 11 from optparse import OptionParser |
10 import utils | 12 import utils |
11 | 13 |
12 def debugLog(message): | 14 def debugLog(message): |
13 print >> sys.stderr, message | 15 print >> sys.stderr, message |
14 sys.stderr.flush() | 16 sys.stderr.flush() |
15 | 17 |
18 # When these files change, snapshots created by the VM are potentially no longer | |
19 # backwards-compatible. | |
20 VM_SNAPSHOT_FILES=[ | |
21 # Header files. | |
22 'datastream.h', | |
23 'object.h', | |
24 'raw_object.h', | |
25 'snapshot.h', | |
26 'snapshot_ids.h', | |
27 'symbols.h', | |
28 # Source files. | |
29 'object.cc', | |
30 'raw_object.cc', | |
31 'raw_object_snapshot.cc', | |
32 'snapshot.cc', | |
33 'symbols.cc', | |
siva
2014/09/08 23:47:45
I think we should also include dart_api_impl.cc it
zra
2014/09/09 01:43:03
Done.
| |
34 ] | |
35 | |
16 def makeVersionString(): | 36 def makeVersionString(): |
17 version_string = utils.GetVersion() | 37 version_string = utils.GetVersion() |
18 debugLog("Returning version string: %s " % version_string) | 38 debugLog("Returning version string: %s " % version_string) |
19 return version_string | 39 return version_string |
20 | 40 |
21 | 41 |
42 def makeSnapshotHashString(): | |
43 vmhash = hashlib.md5() | |
Ivan Posva
2014/09/09 00:08:03
Anything better than MD5? Should we even care?
zra
2014/09/09 01:43:03
Since the hash is not being used for any security
| |
44 for vmfilename in VM_SNAPSHOT_FILES: | |
45 vmfilepath = os.path.join(utils.DART_DIR, 'runtime', 'vm', vmfilename) | |
46 with open(vmfilepath) as vmfile: | |
47 vmhash.update(vmfile.read()) | |
48 return vmhash.hexdigest() | |
49 | |
50 | |
22 def makeFile(output_file, input_file): | 51 def makeFile(output_file, input_file): |
23 version_cc_text = open(input_file).read() | 52 version_cc_text = open(input_file).read() |
24 version_string = makeVersionString() | 53 version_string = makeVersionString() |
25 version_cc_text = version_cc_text.replace("{{VERSION_STR}}", | 54 version_cc_text = version_cc_text.replace("{{VERSION_STR}}", |
26 version_string) | 55 version_string) |
27 version_time = time.ctime(time.time()) | 56 version_time = time.ctime(time.time()) |
28 version_cc_text = version_cc_text.replace("{{BUILD_TIME}}", | 57 version_cc_text = version_cc_text.replace("{{BUILD_TIME}}", |
29 version_time) | 58 version_time) |
59 snapshot_hash = makeSnapshotHashString() | |
60 version_cc_text = version_cc_text.replace("{{SNAPSHOT_HASH}}", | |
61 snapshot_hash) | |
30 open(output_file, 'w').write(version_cc_text) | 62 open(output_file, 'w').write(version_cc_text) |
31 return True | 63 return True |
32 | 64 |
33 | 65 |
34 def main(args): | 66 def main(args): |
35 try: | 67 try: |
36 # Parse input. | 68 # Parse input. |
37 parser = OptionParser() | 69 parser = OptionParser() |
38 parser.add_option("--output", | 70 parser.add_option("--output", |
39 action="store", type="string", | 71 action="store", type="string", |
(...skipping 20 matching lines...) Expand all Loading... | |
60 return 0 | 92 return 0 |
61 except Exception, inst: | 93 except Exception, inst: |
62 sys.stderr.write('make_version.py exception\n') | 94 sys.stderr.write('make_version.py exception\n') |
63 sys.stderr.write(str(inst)) | 95 sys.stderr.write(str(inst)) |
64 sys.stderr.write('\n') | 96 sys.stderr.write('\n') |
65 return -1 | 97 return -1 |
66 | 98 |
67 if __name__ == '__main__': | 99 if __name__ == '__main__': |
68 exit_code = main(sys.argv) | 100 exit_code = main(sys.argv) |
69 sys.exit(exit_code) | 101 sys.exit(exit_code) |
OLD | NEW |