mirror of
https://github.com/dart-lang/sdk
synced 2024-09-05 16:41:07 +00:00
Prefix scripts from core builtin libraries so the URIs are unique.
After https://dart-review.googlesource.com/c/sdk/+/7588 we ended up with two crypto.dart files in the core prebuilt libraries(io and _http), which caused problem with coverage tool that relied on the fact that script uris can uniquely identify files. https://github.com/dart-lang/coverage/issues/194 was filed to handle non-unique uris. This CL ensures that core builtin libraries URIs stays unique by prefixing them with 'dart:' library prefix. This makes core builtin libraries scripts have names similarly structured to script names for other core libraries. Bug: Change-Id: I79960f4f24e6e958836df866365355584c28df27 Reviewed-on: https://dart-review.googlesource.com/11140 Commit-Queue: Alexander Aprelev <aam@google.com> Reviewed-by: Ryan Macnak <rmacnak@google.com>
This commit is contained in:
parent
2d30c30f71
commit
d822bdb797
|
@ -10,6 +10,10 @@
|
|||
#include "bin/dartutils.h"
|
||||
#include "bin/platform.h"
|
||||
|
||||
#include "vm/dart_api_impl.h"
|
||||
#include "vm/object.h"
|
||||
#include "vm/object_store.h"
|
||||
|
||||
namespace dart {
|
||||
namespace bin {
|
||||
|
||||
|
@ -53,9 +57,11 @@ static void LoadPatchFiles(Dart_Handle library,
|
|||
reinterpret_cast<const uint8_t*>(source), strlen(source));
|
||||
|
||||
// Prepend the patch library URI to form a unique script URI for the patch.
|
||||
intptr_t len = snprintf(NULL, 0, "%s/%s", patch_uri, patch_files[j]);
|
||||
const char* unprefixed_patch_file = strchr(patch_files[j], '/') + 1;
|
||||
intptr_t len = snprintf(NULL, 0, "%s/%s", patch_uri, unprefixed_patch_file);
|
||||
char* patch_filename = DartUtils::ScopedCString(len + 1);
|
||||
snprintf(patch_filename, len + 1, "%s/%s", patch_uri, patch_files[j]);
|
||||
snprintf(patch_filename, len + 1, "%s/%s", patch_uri,
|
||||
unprefixed_patch_file);
|
||||
Dart_Handle patch_file_uri = DartUtils::NewString(patch_filename);
|
||||
|
||||
DART_CHECK_VALID(Dart_LibraryLoadPatch(library, patch_file_uri, patch_src));
|
||||
|
|
|
@ -653,9 +653,16 @@ static Dart_Handle CreateSnapshotLibraryTagHandler(Dart_LibraryTag tag,
|
|||
if (libraryBuiltinId != Builtin::kInvalidLibrary) {
|
||||
// Special case for parting sources of a builtin library.
|
||||
if (tag == Dart_kSourceTag) {
|
||||
return Dart_LoadSource(library, url, Dart_Null(),
|
||||
Builtin::PartSource(libraryBuiltinId, url_string),
|
||||
0, 0);
|
||||
intptr_t len = snprintf(NULL, 0, "%s/%s", library_url_string, url_string);
|
||||
char* patch_filename = reinterpret_cast<char*>(malloc(len + 1));
|
||||
snprintf(patch_filename, len + 1, "%s/%s", library_url_string,
|
||||
url_string);
|
||||
Dart_Handle prefixed_url = Dart_NewStringFromCString(patch_filename);
|
||||
Dart_Handle result = Dart_LoadSource(
|
||||
library, prefixed_url, Dart_Null(),
|
||||
Builtin::PartSource(libraryBuiltinId, patch_filename), 0, 0);
|
||||
free(patch_filename);
|
||||
return result;
|
||||
}
|
||||
ASSERT(tag == Dart_kImportTag);
|
||||
return DartUtils::NewError("Unable to import '%s' ", url_string);
|
||||
|
|
|
@ -845,9 +845,11 @@ Dart_Handle Loader::DartColonLibraryTagHandler(Dart_LibraryTag tag,
|
|||
char* part_uri = reinterpret_cast<char*>(malloc(len + 1));
|
||||
snprintf(part_uri, len + 1, "%s/%s", library_url_string, url_string);
|
||||
Dart_Handle part_uri_obj = DartUtils::NewString(part_uri);
|
||||
Dart_Handle result =
|
||||
Dart_LoadSource(library, part_uri_obj, Dart_Null(),
|
||||
Builtin::PartSource(id, part_uri), 0, 0);
|
||||
free(part_uri);
|
||||
return Dart_LoadSource(library, part_uri_obj, Dart_Null(),
|
||||
Builtin::PartSource(id, url_string), 0, 0);
|
||||
return result;
|
||||
}
|
||||
// All cases should have been handled above.
|
||||
UNREACHABLE();
|
||||
|
|
|
@ -64,7 +64,7 @@ def makeFile(output_file, input_cc_file, include, var_name, lib_name, in_files):
|
|||
if (main_file_found):
|
||||
continue
|
||||
part_index.append(' "' +
|
||||
os.path.basename(string_file).replace('\\', '\\\\') + '",\n')
|
||||
lib_name + "/" + os.path.basename(string_file).replace('\\', '\\\\') + '",\n')
|
||||
part_index.append(' source_array_' + str(file_count) + ',\n\n')
|
||||
bootstrap_cc_text = bootstrap_cc_text.replace("{{LIBRARY_SOURCE_MAP}}", '')
|
||||
bootstrap_cc_text = bootstrap_cc_text.replace("{{PART_SOURCE_MAP}}",
|
||||
|
|
|
@ -79,7 +79,8 @@ static RawString* GetLibrarySourceByIndex(intptr_t index,
|
|||
return String::FromUTF8(utf8_array, file_length);
|
||||
}
|
||||
|
||||
static RawString* GetLibrarySource(const Library& lib,
|
||||
static RawString* GetLibrarySource(Zone* zone,
|
||||
const Library& lib,
|
||||
const String& uri,
|
||||
bool patch) {
|
||||
// First check if this is a valid bootstrap library and find its index in
|
||||
|
@ -95,7 +96,13 @@ static RawString* GetLibrarySource(const Library& lib,
|
|||
return String::null(); // The library is not a bootstrap library.
|
||||
}
|
||||
|
||||
return GetLibrarySourceByIndex(index, uri, patch);
|
||||
const Array& strings = Array::Handle(zone, Array::New(3));
|
||||
strings.SetAt(0, lib_uri);
|
||||
strings.SetAt(1, Symbols::Slash());
|
||||
strings.SetAt(2, uri);
|
||||
const String& part_uri = String::Handle(zone, String::ConcatAll(strings));
|
||||
|
||||
return GetLibrarySourceByIndex(index, part_uri, patch);
|
||||
}
|
||||
|
||||
static RawError* Compile(const Library& library, const Script& script) {
|
||||
|
@ -122,7 +129,7 @@ static Dart_Handle LoadPartSource(Thread* thread,
|
|||
const String& uri) {
|
||||
Zone* zone = thread->zone();
|
||||
const String& part_source =
|
||||
String::Handle(zone, GetLibrarySource(lib, uri, false));
|
||||
String::Handle(zone, GetLibrarySource(zone, lib, uri, false));
|
||||
const String& lib_uri = String::Handle(zone, lib.url());
|
||||
if (part_source.IsNull()) {
|
||||
return Api::NewError("Unable to read part file '%s' of library '%s'",
|
||||
|
|
Loading…
Reference in a new issue