diff --git a/runtime/vm/version.h b/runtime/vm/version.h index 0ced9b3ca6c..45afcb5964a 100644 --- a/runtime/vm/version.h +++ b/runtime/vm/version.h @@ -16,6 +16,7 @@ class Version : public AllStatic { private: static const char* str_; + static const char* snapshot_hash_; }; } // namespace dart diff --git a/runtime/vm/version_in.cc b/runtime/vm/version_in.cc index 9f515d9e56c..34d7fc67637 100644 --- a/runtime/vm/version_in.cc +++ b/runtime/vm/version_in.cc @@ -28,10 +28,10 @@ const char* Version::String() { const char* Version::SnapshotString() { - return str_; + return snapshot_hash_; } - +const char* Version::snapshot_hash_ = "{{SNAPSHOT_HASH}}"; const char* Version::str_ = "{{VERSION_STR}} ({{BUILD_TIME}})"; } // namespace dart diff --git a/tools/make_version.py b/tools/make_version.py index 54ce6752245..80ac418bf23 100644 --- a/tools/make_version.py +++ b/tools/make_version.py @@ -4,6 +4,8 @@ # # This python script creates a version string in a C++ file. +import hashlib +import os import sys import time from optparse import OptionParser @@ -13,12 +15,41 @@ def debugLog(message): print >> sys.stderr, message sys.stderr.flush() +# When these files change, snapshots created by the VM are potentially no longer +# backwards-compatible. +VM_SNAPSHOT_FILES=[ + # Header files. + 'datastream.h', + 'object.h', + 'raw_object.h', + 'snapshot.h', + 'snapshot_ids.h', + 'symbols.h', + # Source files. + 'dart.cc', + 'dart_api_impl.cc', + 'object.cc', + 'raw_object.cc', + 'raw_object_snapshot.cc', + 'snapshot.cc', + 'symbols.cc', +] + def makeVersionString(): version_string = utils.GetVersion() debugLog("Returning version string: %s " % version_string) return version_string +def makeSnapshotHashString(): + vmhash = hashlib.md5() + for vmfilename in VM_SNAPSHOT_FILES: + vmfilepath = os.path.join(utils.DART_DIR, 'runtime', 'vm', vmfilename) + with open(vmfilepath) as vmfile: + vmhash.update(vmfile.read()) + return vmhash.hexdigest() + + def makeFile(output_file, input_file): version_cc_text = open(input_file).read() version_string = makeVersionString() @@ -27,6 +58,9 @@ def makeFile(output_file, input_file): version_time = time.ctime(time.time()) version_cc_text = version_cc_text.replace("{{BUILD_TIME}}", version_time) + snapshot_hash = makeSnapshotHashString() + version_cc_text = version_cc_text.replace("{{SNAPSHOT_HASH}}", + snapshot_hash) open(output_file, 'w').write(version_cc_text) return True