Skip to content

Commit

Permalink
Prefix scripts from core builtin libraries so the URIs are unique.
Browse files Browse the repository at this point in the history
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. dart-lang/coverage#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>
  • Loading branch information
aam authored and commit-bot@chromium.org committed Oct 5, 2017
1 parent 2d30c30 commit d822bdb
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 11 deletions.
10 changes: 8 additions & 2 deletions runtime/bin/builtin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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));
Expand Down
13 changes: 10 additions & 3 deletions runtime/bin/gen_snapshot.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 4 additions & 2 deletions runtime/bin/loader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion runtime/tools/gen_library_src_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}}",
Expand Down
13 changes: 10 additions & 3 deletions runtime/vm/bootstrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand All @@ -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'",
Expand Down

0 comments on commit d822bdb

Please sign in to comment.