Skip to content

Commit 3dfb90f

Browse files
committed
Checks snapshot validity using a hash of source file instead of a version string.
[email protected], [email protected] Review URL: https://codereview.chromium.org//558503002 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@40009 260f80e4-7a28-3924-810f-c04153c831b5
1 parent 6559d6e commit 3dfb90f

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

runtime/vm/version.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class Version : public AllStatic {
1616

1717
private:
1818
static const char* str_;
19+
static const char* snapshot_hash_;
1920
};
2021

2122
} // namespace dart

runtime/vm/version_in.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ const char* Version::String() {
2828

2929

3030
const char* Version::SnapshotString() {
31-
return str_;
31+
return snapshot_hash_;
3232
}
3333

34-
34+
const char* Version::snapshot_hash_ = "{{SNAPSHOT_HASH}}";
3535
const char* Version::str_ = "{{VERSION_STR}} ({{BUILD_TIME}})";
3636

3737
} // namespace dart

tools/make_version.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#
55
# This python script creates a version string in a C++ file.
66

7+
import hashlib
8+
import os
79
import sys
810
import time
911
from optparse import OptionParser
@@ -13,12 +15,41 @@ def debugLog(message):
1315
print >> sys.stderr, message
1416
sys.stderr.flush()
1517

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+
'dart.cc',
30+
'dart_api_impl.cc',
31+
'object.cc',
32+
'raw_object.cc',
33+
'raw_object_snapshot.cc',
34+
'snapshot.cc',
35+
'symbols.cc',
36+
]
37+
1638
def makeVersionString():
1739
version_string = utils.GetVersion()
1840
debugLog("Returning version string: %s " % version_string)
1941
return version_string
2042

2143

44+
def makeSnapshotHashString():
45+
vmhash = hashlib.md5()
46+
for vmfilename in VM_SNAPSHOT_FILES:
47+
vmfilepath = os.path.join(utils.DART_DIR, 'runtime', 'vm', vmfilename)
48+
with open(vmfilepath) as vmfile:
49+
vmhash.update(vmfile.read())
50+
return vmhash.hexdigest()
51+
52+
2253
def makeFile(output_file, input_file):
2354
version_cc_text = open(input_file).read()
2455
version_string = makeVersionString()
@@ -27,6 +58,9 @@ def makeFile(output_file, input_file):
2758
version_time = time.ctime(time.time())
2859
version_cc_text = version_cc_text.replace("{{BUILD_TIME}}",
2960
version_time)
61+
snapshot_hash = makeSnapshotHashString()
62+
version_cc_text = version_cc_text.replace("{{SNAPSHOT_HASH}}",
63+
snapshot_hash)
3064
open(output_file, 'w').write(version_cc_text)
3165
return True
3266

0 commit comments

Comments
 (0)