diff --git a/runtime/lib/date_patch.dart b/runtime/lib/date_patch.dart index b1f2f8dde6c..f959723bd9d 100644 --- a/runtime/lib/date_patch.dart +++ b/runtime/lib/date_patch.dart @@ -5,6 +5,19 @@ // VM implementation of DateTime. patch class DateTime { + // Natives. + // The natives have been moved up here to work around Issue 10401. + static int _getCurrentMs() native "DateNatives_currentTimeMillis"; + + static String _timeZoneNameForClampedSeconds(int secondsSinceEpoch) + native "DateNatives_timeZoneName"; + + static int _timeZoneOffsetInSecondsForClampedSeconds(int secondsSinceEpoch) + native "DateNatives_timeZoneOffsetInSeconds"; + + static int _localTimeZoneAdjustmentInSeconds() + native "DateNatives_localTimeZoneAdjustmentInSeconds"; + /* patch */ DateTime._internal(int year, int month, int day, @@ -310,16 +323,4 @@ patch class DateTime { int equivalentSeconds = _equivalentSeconds(millisecondsSinceEpoch); return _timeZoneNameForClampedSeconds(equivalentSeconds); } - - // Natives - static int _getCurrentMs() native "DateNatives_currentTimeMillis"; - - static String _timeZoneNameForClampedSeconds(int secondsSinceEpoch) - native "DateNatives_timeZoneName"; - - static int _timeZoneOffsetInSecondsForClampedSeconds(int secondsSinceEpoch) - native "DateNatives_timeZoneOffsetInSeconds"; - - static int _localTimeZoneAdjustmentInSeconds() - native "DateNatives_localTimeZoneAdjustmentInSeconds"; } diff --git a/runtime/tools/gen_library_src_paths.py b/runtime/tools/gen_library_src_paths.py index 2cb082bb998..27512150115 100644 --- a/runtime/tools/gen_library_src_paths.py +++ b/runtime/tools/gen_library_src_paths.py @@ -38,6 +38,7 @@ def makeFile(output_file, input_cc_file, include, var_name, lib_name, in_files): os.path.basename(string_file).replace('\\', '\\\\') + '", ') part_index.append('"' + os.path.abspath(string_file).replace('\\', '\\\\') + '", \n') + bootstrap_cc_text = bootstrap_cc_text.replace("{{LIBRARY_SOURCE_MAP}}", '') bootstrap_cc_text = bootstrap_cc_text.replace("{{PART_SOURCE_MAP}}", ''.join(part_index)) open(output_file, 'w').write(bootstrap_cc_text) diff --git a/runtime/vm/bootstrap.cc b/runtime/vm/bootstrap.cc index 01008aacba5..06a08c9b386 100644 --- a/runtime/vm/bootstrap.cc +++ b/runtime/vm/bootstrap.cc @@ -27,7 +27,7 @@ typedef struct { const char* uri_; const char** source_paths_; const char* patch_uri_; - const char* patch_source_; + const char** patch_paths_; } bootstrap_lib_props; @@ -35,19 +35,19 @@ static bootstrap_lib_props bootstrap_libraries[] = { INIT_LIBRARY(ObjectStore::kCore, core, Bootstrap::corelib_source_paths_, - Bootstrap::corelib_patch_), + Bootstrap::corelib_patch_paths_), INIT_LIBRARY(ObjectStore::kAsync, async, Bootstrap::async_source_paths_, - Bootstrap::async_patch_), + Bootstrap::async_patch_paths_), INIT_LIBRARY(ObjectStore::kCollection, collection, Bootstrap::collection_source_paths_, - Bootstrap::collection_patch_), + Bootstrap::collection_patch_paths_), INIT_LIBRARY(ObjectStore::kCollectionDev, _collection-dev, Bootstrap::collection_dev_source_paths_, - Bootstrap::collection_dev_patch_), + Bootstrap::collection_dev_patch_paths_), INIT_LIBRARY(ObjectStore::kCrypto, crypto, Bootstrap::crypto_source_paths_, @@ -55,23 +55,23 @@ static bootstrap_lib_props bootstrap_libraries[] = { INIT_LIBRARY(ObjectStore::kIsolate, isolate, Bootstrap::isolate_source_paths_, - Bootstrap::isolate_patch_), + Bootstrap::isolate_patch_paths_), INIT_LIBRARY(ObjectStore::kJson, json, Bootstrap::json_source_paths_, - Bootstrap::json_patch_), + Bootstrap::json_patch_paths_), INIT_LIBRARY(ObjectStore::kMath, math, Bootstrap::math_source_paths_, - Bootstrap::math_patch_), + Bootstrap::math_patch_paths_), INIT_LIBRARY(ObjectStore::kMirrors, mirrors, Bootstrap::mirrors_source_paths_, - Bootstrap::mirrors_patch_), + Bootstrap::mirrors_patch_paths_), INIT_LIBRARY(ObjectStore::kTypedData, typed_data, Bootstrap::typed_data_source_paths_, - Bootstrap::typed_data_patch_), + Bootstrap::typed_data_patch_paths_), INIT_LIBRARY(ObjectStore::kUtf, utf, Bootstrap::utf_source_paths_, @@ -102,15 +102,10 @@ static RawString* GetLibrarySource(const Library& lib, return String::null(); // Library is not a boot strap library. } - if (patch) { - // TODO(asiva): Replace with actual read of the source file. - const char* source = bootstrap_libraries[index].patch_source_; - ASSERT(source != NULL); - return String::New(source, Heap::kOld); - } - // Try to read the source using the path specified for the uri. - const char** source_paths = bootstrap_libraries[index].source_paths_; + const char** source_paths = patch ? + bootstrap_libraries[index].patch_paths_ : + bootstrap_libraries[index].source_paths_; if (source_paths == NULL) { return String::null(); // No path mapping information exists for library. } @@ -234,6 +229,41 @@ static Dart_Handle BootstrapLibraryTagHandler(Dart_LibraryTag tag, } +static RawError* LoadPatchFiles(Isolate* isolate, + const Library& lib, + const String& patch_uri, + const char** patch_files) { + String& patch_file_uri = String::Handle(isolate); + String& source = String::Handle(isolate); + Script& script = Script::Handle(isolate); + Error& error = Error::Handle(isolate); + const Array& strings = Array::Handle(isolate, Array::New(3)); + strings.SetAt(0, patch_uri); + strings.SetAt(1, Symbols::Slash()); + intptr_t j = 0; + while (patch_files[j] != NULL) { + patch_file_uri = String::New(patch_files[j]); + source = GetLibrarySource(lib, patch_file_uri, true); + if (source.IsNull()) { + return Api::UnwrapErrorHandle( + isolate, + Api::NewError("Unable to find dart patch source for %s", + patch_file_uri.ToCString())).raw(); + } + // Prepend the patch library URI to form a unique script URI for the patch. + strings.SetAt(2, patch_file_uri); + patch_file_uri = String::ConcatAll(strings); + script = Script::New(patch_file_uri, source, RawScript::kPatchTag); + error = lib.Patch(script); + if (!error.IsNull()) { + return error.raw(); + } + j += 2; + } + return Error::null(); +} + + RawError* Bootstrap::LoadandCompileScripts() { Isolate* isolate = Isolate::Current(); String& uri = String::Handle(); @@ -266,7 +296,7 @@ RawError* Bootstrap::LoadandCompileScripts() { i = i + 1; } - // Load and compile bootstrap libraries. + // Load, compile and patch bootstrap libraries. i = 0; while (bootstrap_libraries[i].index_ != ObjectStore::kNone) { uri = Symbols::New(bootstrap_libraries[i].uri_); @@ -285,18 +315,12 @@ RawError* Bootstrap::LoadandCompileScripts() { break; } // If a patch exists, load and patch the script. - if (bootstrap_libraries[i].patch_source_ != NULL) { - patch_uri = String::New(bootstrap_libraries[i].patch_uri_, - Heap::kOld); - source = GetLibrarySource(lib, uri, true); - if (source.IsNull()) { - error ^= Api::UnwrapErrorHandle( - isolate, Api::NewError("Unable to find dart patch source for %s", - uri.ToCString())).raw(); - break; - } - script = Script::New(patch_uri, source, RawScript::kPatchTag); - error = lib.Patch(script); + if (bootstrap_libraries[i].patch_paths_ != NULL) { + patch_uri = Symbols::New(bootstrap_libraries[i].patch_uri_); + error = LoadPatchFiles(isolate, + lib, + patch_uri, + bootstrap_libraries[i].patch_paths_); if (!error.IsNull()) { break; } diff --git a/runtime/vm/bootstrap.h b/runtime/vm/bootstrap.h index 8c3ae55ff36..d87354149bd 100644 --- a/runtime/vm/bootstrap.h +++ b/runtime/vm/bootstrap.h @@ -31,16 +31,16 @@ class Bootstrap : public AllStatic { static const char* uri_source_paths_[]; static const char* utf_source_paths_[]; - // Patch sources for libaries (concatenated source). - static const char async_patch_[]; - static const char corelib_patch_[]; - static const char collection_patch_[]; - static const char collection_dev_patch_[]; - static const char isolate_patch_[]; - static const char json_patch_[]; - static const char math_patch_[]; - static const char mirrors_patch_[]; - static const char typed_data_patch_[]; + // Source path mapping for patch URI and 'parts'. + static const char* async_patch_paths_[]; + static const char* corelib_patch_paths_[]; + static const char* collection_patch_paths_[]; + static const char* collection_dev_patch_paths_[]; + static const char* isolate_patch_paths_[]; + static const char* json_patch_paths_[]; + static const char* math_patch_paths_[]; + static const char* mirrors_patch_paths_[]; + static const char* typed_data_patch_paths_[]; }; } // namespace dart diff --git a/runtime/vm/vm.gypi b/runtime/vm/vm.gypi index a9fd7c22a5e..9e073d1b458 100644 --- a/runtime/vm/vm.gypi +++ b/runtime/vm/vm.gypi @@ -274,8 +274,8 @@ { 'action_name': 'generate_corelib_patch_cc', 'inputs': [ - '../tools/create_string_literal.py', - '<(builtin_in_cc_file)', + '../tools/gen_library_src_paths.py', + '<(libgen_in_cc_file)', '<@(_sources)', ], 'outputs': [ @@ -283,11 +283,12 @@ ], 'action': [ 'python', - 'tools/create_string_literal.py', + 'tools/gen_library_src_paths.py', '--output', '<(corelib_patch_cc_file)', - '--input_cc', '<(builtin_in_cc_file)', + '--input_cc', '<(libgen_in_cc_file)', '--include', 'vm/bootstrap.h', - '--var_name', 'dart::Bootstrap::corelib_patch_', + '--var_name', 'dart::Bootstrap::corelib_patch_paths_', + '--library_name', 'dart:corelib', '<@(_sources)', ], 'message': 'Generating ''<(corelib_patch_cc_file)'' file.' @@ -353,8 +354,8 @@ { 'action_name': 'generate_collection_dev_patch_cc', 'inputs': [ - '../tools/create_string_literal.py', - '<(builtin_in_cc_file)', + '../tools/gen_library_src_paths.py', + '<(libgen_in_cc_file)', '<@(_sources)', ], 'outputs': [ @@ -362,11 +363,12 @@ ], 'action': [ 'python', - 'tools/create_string_literal.py', + 'tools/gen_library_src_paths.py', '--output', '<(collection_dev_patch_cc_file)', - '--input_cc', '<(builtin_in_cc_file)', + '--input_cc', '<(libgen_in_cc_file)', '--include', 'vm/bootstrap.h', - '--var_name', 'dart::Bootstrap::collection_dev_patch_', + '--var_name', 'dart::Bootstrap::collection_dev_patch_paths_', + '--library_name', 'dart:_collection-dev', '<@(_sources)', ], 'message': 'Generating ''<(collection_dev_patch_cc_file)'' file.' @@ -505,8 +507,8 @@ { 'action_name': 'generate_math_patch_cc', 'inputs': [ - '../tools/create_string_literal.py', - '<(builtin_in_cc_file)', + '../tools/gen_library_src_paths.py', + '<(libgen_in_cc_file)', '<@(_sources)', ], 'outputs': [ @@ -514,11 +516,12 @@ ], 'action': [ 'python', - 'tools/create_string_literal.py', + 'tools/gen_library_src_paths.py', '--output', '<(math_patch_cc_file)', - '--input_cc', '<(builtin_in_cc_file)', + '--input_cc', '<(libgen_in_cc_file)', '--include', 'vm/bootstrap.h', - '--var_name', 'dart::Bootstrap::math_patch_', + '--var_name', 'dart::Bootstrap::math_patch_paths_', + '--library_name', 'dart:math', '<@(_sources)', ], 'message': 'Generating ''<(math_patch_cc_file)'' file.' @@ -584,8 +587,8 @@ { 'action_name': 'generate_mirrors_patch_cc', 'inputs': [ - '../tools/create_string_literal.py', - '<(builtin_in_cc_file)', + '../tools/gen_library_src_paths.py', + '<(libgen_in_cc_file)', '<@(_sources)', ], 'outputs': [ @@ -593,11 +596,12 @@ ], 'action': [ 'python', - 'tools/create_string_literal.py', + 'tools/gen_library_src_paths.py', '--output', '<(mirrors_patch_cc_file)', - '--input_cc', '<(builtin_in_cc_file)', + '--input_cc', '<(libgen_in_cc_file)', '--include', 'vm/bootstrap.h', - '--var_name', 'dart::Bootstrap::mirrors_patch_', + '--var_name', 'dart::Bootstrap::mirrors_patch_paths_', + '--library_name', 'dart:mirrors', '<@(_sources)', ], 'message': 'Generating ''<(mirrors_patch_cc_file)'' file.' @@ -663,8 +667,8 @@ { 'action_name': 'generate_async_patch_cc', 'inputs': [ - '../tools/create_string_literal.py', - '<(builtin_in_cc_file)', + '../tools/gen_library_src_paths.py', + '<(libgen_in_cc_file)', '<@(_sources)', ], 'outputs': [ @@ -672,11 +676,12 @@ ], 'action': [ 'python', - 'tools/create_string_literal.py', + 'tools/gen_library_src_paths.py', '--output', '<(async_patch_cc_file)', - '--input_cc', '<(builtin_in_cc_file)', + '--input_cc', '<(libgen_in_cc_file)', '--include', 'vm/bootstrap.h', - '--var_name', 'dart::Bootstrap::async_patch_', + '--var_name', 'dart::Bootstrap::async_patch_paths_', + '--library_name', 'dart:async', '<@(_sources)', ], 'message': 'Generating ''<(async_patch_cc_file)'' file.' @@ -702,8 +707,8 @@ { 'action_name': 'generate_collection_patch_cc', 'inputs': [ - '../tools/create_string_literal.py', - '<(builtin_in_cc_file)', + '../tools/gen_library_src_paths.py', + '<(libgen_in_cc_file)', '<@(_sources)', ], 'outputs': [ @@ -711,11 +716,12 @@ ], 'action': [ 'python', - 'tools/create_string_literal.py', + 'tools/gen_library_src_paths.py', '--output', '<(collection_patch_cc_file)', - '--input_cc', '<(builtin_in_cc_file)', + '--input_cc', '<(libgen_in_cc_file)', '--include', 'vm/bootstrap.h', - '--var_name', 'dart::Bootstrap::collection_patch_', + '--var_name', 'dart::Bootstrap::collection_patch_paths_', + '--library_name', 'dart:collection', '<@(_sources)', ], 'message': 'Generating ''<(collection_patch_cc_file)'' file.' @@ -741,8 +747,8 @@ { 'action_name': 'generate_isolate_patch_cc', 'inputs': [ - '../tools/create_string_literal.py', - '<(builtin_in_cc_file)', + '../tools/gen_library_src_paths.py', + '<(libgen_in_cc_file)', '<@(_sources)', ], 'outputs': [ @@ -750,11 +756,12 @@ ], 'action': [ 'python', - 'tools/create_string_literal.py', + 'tools/gen_library_src_paths.py', '--output', '<(isolate_patch_cc_file)', - '--input_cc', '<(builtin_in_cc_file)', + '--input_cc', '<(libgen_in_cc_file)', '--include', 'vm/bootstrap.h', - '--var_name', 'dart::Bootstrap::isolate_patch_', + '--var_name', 'dart::Bootstrap::isolate_patch_paths_', + '--library_name', 'dart:isolate', '<@(_sources)', ], 'message': 'Generating ''<(isolate_patch_cc_file)'' file.' @@ -813,8 +820,8 @@ { 'action_name': 'generate_json_patch_cc', 'inputs': [ - '../tools/create_string_literal.py', - '<(builtin_in_cc_file)', + '../tools/gen_library_src_paths.py', + '<(libgen_in_cc_file)', '<@(_sources)', ], 'outputs': [ @@ -822,11 +829,12 @@ ], 'action': [ 'python', - 'tools/create_string_literal.py', + 'tools/gen_library_src_paths.py', '--output', '<(json_patch_cc_file)', - '--input_cc', '<(builtin_in_cc_file)', + '--input_cc', '<(libgen_in_cc_file)', '--include', 'vm/bootstrap.h', - '--var_name', 'dart::Bootstrap::json_patch_', + '--var_name', 'dart::Bootstrap::json_patch_paths_', + '--library_name', 'dart:json', '<@(_sources)', ], 'message': 'Generating ''<(json_patch_cc_file)'' file.' @@ -892,8 +900,8 @@ { 'action_name': 'generate_typed_data_patch_cc', 'inputs': [ - '../tools/create_string_literal.py', - '<(builtin_in_cc_file)', + '../tools/gen_library_src_paths.py', + '<(libgen_in_cc_file)', '<@(_sources)', ], 'outputs': [ @@ -901,11 +909,12 @@ ], 'action': [ 'python', - 'tools/create_string_literal.py', + 'tools/gen_library_src_paths.py', '--output', '<(typed_data_patch_cc_file)', - '--input_cc', '<(builtin_in_cc_file)', + '--input_cc', '<(libgen_in_cc_file)', '--include', 'vm/bootstrap.h', - '--var_name', 'dart::Bootstrap::typed_data_patch_', + '--var_name', 'dart::Bootstrap::typed_data_patch_paths_', + '--library_name', 'dart:typed_data', '<@(_sources)', ], 'message': 'Generating ''<(typed_data_patch_cc_file)'' file.'