Skip to content

Commit d822bdb

Browse files
aamcommit-bot@chromium.org
authored andcommitted
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 <[email protected]> Reviewed-by: Ryan Macnak <[email protected]>
1 parent 2d30c30 commit d822bdb

File tree

5 files changed

+33
-11
lines changed

5 files changed

+33
-11
lines changed

runtime/bin/builtin.cc

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
#include "bin/dartutils.h"
1111
#include "bin/platform.h"
1212

13+
#include "vm/dart_api_impl.h"
14+
#include "vm/object.h"
15+
#include "vm/object_store.h"
16+
1317
namespace dart {
1418
namespace bin {
1519

@@ -53,9 +57,11 @@ static void LoadPatchFiles(Dart_Handle library,
5357
reinterpret_cast<const uint8_t*>(source), strlen(source));
5458

5559
// Prepend the patch library URI to form a unique script URI for the patch.
56-
intptr_t len = snprintf(NULL, 0, "%s/%s", patch_uri, patch_files[j]);
60+
const char* unprefixed_patch_file = strchr(patch_files[j], '/') + 1;
61+
intptr_t len = snprintf(NULL, 0, "%s/%s", patch_uri, unprefixed_patch_file);
5762
char* patch_filename = DartUtils::ScopedCString(len + 1);
58-
snprintf(patch_filename, len + 1, "%s/%s", patch_uri, patch_files[j]);
63+
snprintf(patch_filename, len + 1, "%s/%s", patch_uri,
64+
unprefixed_patch_file);
5965
Dart_Handle patch_file_uri = DartUtils::NewString(patch_filename);
6066

6167
DART_CHECK_VALID(Dart_LibraryLoadPatch(library, patch_file_uri, patch_src));

runtime/bin/gen_snapshot.cc

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -653,9 +653,16 @@ static Dart_Handle CreateSnapshotLibraryTagHandler(Dart_LibraryTag tag,
653653
if (libraryBuiltinId != Builtin::kInvalidLibrary) {
654654
// Special case for parting sources of a builtin library.
655655
if (tag == Dart_kSourceTag) {
656-
return Dart_LoadSource(library, url, Dart_Null(),
657-
Builtin::PartSource(libraryBuiltinId, url_string),
658-
0, 0);
656+
intptr_t len = snprintf(NULL, 0, "%s/%s", library_url_string, url_string);
657+
char* patch_filename = reinterpret_cast<char*>(malloc(len + 1));
658+
snprintf(patch_filename, len + 1, "%s/%s", library_url_string,
659+
url_string);
660+
Dart_Handle prefixed_url = Dart_NewStringFromCString(patch_filename);
661+
Dart_Handle result = Dart_LoadSource(
662+
library, prefixed_url, Dart_Null(),
663+
Builtin::PartSource(libraryBuiltinId, patch_filename), 0, 0);
664+
free(patch_filename);
665+
return result;
659666
}
660667
ASSERT(tag == Dart_kImportTag);
661668
return DartUtils::NewError("Unable to import '%s' ", url_string);

runtime/bin/loader.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -845,9 +845,11 @@ Dart_Handle Loader::DartColonLibraryTagHandler(Dart_LibraryTag tag,
845845
char* part_uri = reinterpret_cast<char*>(malloc(len + 1));
846846
snprintf(part_uri, len + 1, "%s/%s", library_url_string, url_string);
847847
Dart_Handle part_uri_obj = DartUtils::NewString(part_uri);
848+
Dart_Handle result =
849+
Dart_LoadSource(library, part_uri_obj, Dart_Null(),
850+
Builtin::PartSource(id, part_uri), 0, 0);
848851
free(part_uri);
849-
return Dart_LoadSource(library, part_uri_obj, Dart_Null(),
850-
Builtin::PartSource(id, url_string), 0, 0);
852+
return result;
851853
}
852854
// All cases should have been handled above.
853855
UNREACHABLE();

runtime/tools/gen_library_src_paths.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def makeFile(output_file, input_cc_file, include, var_name, lib_name, in_files):
6464
if (main_file_found):
6565
continue
6666
part_index.append(' "' +
67-
os.path.basename(string_file).replace('\\', '\\\\') + '",\n')
67+
lib_name + "/" + os.path.basename(string_file).replace('\\', '\\\\') + '",\n')
6868
part_index.append(' source_array_' + str(file_count) + ',\n\n')
6969
bootstrap_cc_text = bootstrap_cc_text.replace("{{LIBRARY_SOURCE_MAP}}", '')
7070
bootstrap_cc_text = bootstrap_cc_text.replace("{{PART_SOURCE_MAP}}",

runtime/vm/bootstrap.cc

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ static RawString* GetLibrarySourceByIndex(intptr_t index,
7979
return String::FromUTF8(utf8_array, file_length);
8080
}
8181

82-
static RawString* GetLibrarySource(const Library& lib,
82+
static RawString* GetLibrarySource(Zone* zone,
83+
const Library& lib,
8384
const String& uri,
8485
bool patch) {
8586
// First check if this is a valid bootstrap library and find its index in
@@ -95,7 +96,13 @@ static RawString* GetLibrarySource(const Library& lib,
9596
return String::null(); // The library is not a bootstrap library.
9697
}
9798

98-
return GetLibrarySourceByIndex(index, uri, patch);
99+
const Array& strings = Array::Handle(zone, Array::New(3));
100+
strings.SetAt(0, lib_uri);
101+
strings.SetAt(1, Symbols::Slash());
102+
strings.SetAt(2, uri);
103+
const String& part_uri = String::Handle(zone, String::ConcatAll(strings));
104+
105+
return GetLibrarySourceByIndex(index, part_uri, patch);
99106
}
100107

101108
static RawError* Compile(const Library& library, const Script& script) {
@@ -122,7 +129,7 @@ static Dart_Handle LoadPartSource(Thread* thread,
122129
const String& uri) {
123130
Zone* zone = thread->zone();
124131
const String& part_source =
125-
String::Handle(zone, GetLibrarySource(lib, uri, false));
132+
String::Handle(zone, GetLibrarySource(zone, lib, uri, false));
126133
const String& lib_uri = String::Handle(zone, lib.url());
127134
if (part_source.IsNull()) {
128135
return Api::NewError("Unable to read part file '%s' of library '%s'",

0 commit comments

Comments
 (0)