diff --git a/runtime/bin/BUILD.gn b/runtime/bin/BUILD.gn index d5e5897d553..be0893506f2 100644 --- a/runtime/bin/BUILD.gn +++ b/runtime/bin/BUILD.gn @@ -1031,7 +1031,6 @@ source_set("run_vm_tests_set") { # The VM sources are already included in libdart, so we just want to add in # the tests here. - platform_tests = rebase_path(platform_sources_tests, ".", "../platform") vm_tests = rebase_path(vm_sources_tests, ".", "../vm") compiler_tests = rebase_path(compiler_sources_tests, ".", "../vm/compiler") heap_tests = rebase_path(heap_sources_tests, ".", "../vm/heap") @@ -1052,7 +1051,7 @@ source_set("run_vm_tests_set") { "vmservice_impl.cc", "vmservice_impl.h", ] + builtin_impl_tests + vm_tests + compiler_tests + heap_tests + - io_impl_tests + platform_tests + io_impl_tests } executable("run_vm_tests") { diff --git a/runtime/bin/builtin_impl_sources.gni b/runtime/bin/builtin_impl_sources.gni index 0db1b7655bc..6e4b6519b54 100644 --- a/runtime/bin/builtin_impl_sources.gni +++ b/runtime/bin/builtin_impl_sources.gni @@ -51,6 +51,8 @@ builtin_impl_sources = [ "thread_macos.h", "thread_win.cc", "thread_win.h", + "uri.cc", + "uri.h", "utils.cc", "utils.h", "utils_fuchsia.cc", @@ -69,4 +71,5 @@ builtin_impl_tests = [ "priority_heap_test.cc", "snapshot_utils_test.cc", "test_utils.cc", + "uri_test.cc", ] diff --git a/runtime/bin/loader.cc b/runtime/bin/loader.cc index 0055a7c888b..dbd60699bd9 100644 --- a/runtime/bin/loader.cc +++ b/runtime/bin/loader.cc @@ -4,18 +4,11 @@ #include "bin/loader.h" -#include "bin/builtin.h" #include "bin/dartutils.h" #include "bin/dfe.h" #include "bin/error_exit.h" -#include "bin/file.h" -#include "bin/gzip.h" -#include "bin/lockers.h" #include "bin/snapshot_utils.h" -#include "bin/utils.h" -#include "include/dart_tools_api.h" -#include "platform/growable_array.h" -#include "platform/uri.h" +#include "bin/uri.h" #include "platform/utils.h" namespace dart { diff --git a/runtime/bin/native_assets_api_impl.cc b/runtime/bin/native_assets_api_impl.cc index ab86e14468a..e783d56b2b5 100644 --- a/runtime/bin/native_assets_api_impl.cc +++ b/runtime/bin/native_assets_api_impl.cc @@ -20,7 +20,7 @@ #endif #include "bin/file.h" -#include "platform/uri.h" +#include "bin/uri.h" namespace dart { namespace bin { diff --git a/runtime/platform/uri.cc b/runtime/bin/uri.cc similarity index 99% rename from runtime/platform/uri.cc rename to runtime/bin/uri.cc index bc52efafeef..b0a1270c4ee 100644 --- a/runtime/platform/uri.cc +++ b/runtime/bin/uri.cc @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -#include "platform/uri.h" +#include "bin/uri.h" #include #include diff --git a/runtime/platform/uri.h b/runtime/bin/uri.h similarity index 89% rename from runtime/platform/uri.h rename to runtime/bin/uri.h index 8201b702218..65483acee8a 100644 --- a/runtime/platform/uri.h +++ b/runtime/bin/uri.h @@ -2,8 +2,8 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -#ifndef RUNTIME_PLATFORM_URI_H_ -#define RUNTIME_PLATFORM_URI_H_ +#ifndef RUNTIME_BIN_URI_H_ +#define RUNTIME_BIN_URI_H_ #include #include "platform/utils.h" @@ -33,4 +33,4 @@ CStringUniquePtr ResolveUri(const char* ref_uri, const char* base_uri); } // namespace dart -#endif // RUNTIME_PLATFORM_URI_H_ +#endif // RUNTIME_BIN_URI_H_ diff --git a/runtime/platform/uri_test.cc b/runtime/bin/uri_test.cc similarity index 99% rename from runtime/platform/uri_test.cc rename to runtime/bin/uri_test.cc index a2089bd5955..e324de6c8da 100644 --- a/runtime/platform/uri_test.cc +++ b/runtime/bin/uri_test.cc @@ -4,7 +4,7 @@ #include "vm/unit_test.h" -#include "platform/uri.h" +#include "bin/uri.h" #include "platform/utils.h" namespace dart { diff --git a/runtime/lib/ffi_dynamic_library.cc b/runtime/lib/ffi_dynamic_library.cc index e17a9bf9e9e..8f6eabe868b 100644 --- a/runtime/lib/ffi_dynamic_library.cc +++ b/runtime/lib/ffi_dynamic_library.cc @@ -14,7 +14,6 @@ #include #endif -#include "platform/uri.h" #include "vm/bootstrap_natives.h" #include "vm/dart_api_impl.h" #include "vm/exceptions.h" @@ -281,54 +280,6 @@ static void* FfiResolveWithFfiNativeResolver(Thread* const thread, return result; } -#if defined(DART_TARGET_OS_WINDOWS) -// Replaces back slashes with forward slashes in place. -static void ReplaceBackSlashes(char* cstr) { - const intptr_t length = strlen(cstr); - for (int i = 0; i < length; i++) { - cstr[i] = cstr[i] == '\\' ? '/' : cstr[i]; - } -} -#endif - -const char* file_schema = "file://"; -const int file_schema_length = 7; - -// Get a file path with only forward slashes from the script path. -static StringPtr GetPlatformScriptPath(Thread* thread) { - IsolateGroupSource* const source = thread->isolate_group()->source(); - -#if defined(DART_TARGET_OS_WINDOWS) - // Isolate.spawnUri sets a `source` including the file schema. - // And on Windows we get an extra forward slash in that case. - const char* file_schema_slash = "file:///"; - const int file_schema_slash_length = 8; - const char* path = source->script_uri; - if (strlen(source->script_uri) > file_schema_slash_length && - strncmp(source->script_uri, file_schema_slash, - file_schema_slash_length) == 0) { - path = (source->script_uri + file_schema_slash_length); - } - - // Replace backward slashes with forward slashes. - const intptr_t len = strlen(path); - char* path_copy = reinterpret_cast(malloc(len + 1)); - snprintf(path_copy, len + 1, "%s", path); - ReplaceBackSlashes(path_copy); - const auto& result = String::Handle(String::New(path_copy)); - free(path_copy); - return result.ptr(); -#else - // Isolate.spawnUri sets a `source` including the file schema. - if (strlen(source->script_uri) > file_schema_length && - strncmp(source->script_uri, file_schema, file_schema_length) == 0) { - const char* path = (source->script_uri + file_schema_length); - return String::New(path); - } - return String::New(source->script_uri); -#endif -} - // Array::null if asset is not in mapping or no mapping. static ArrayPtr GetAssetLocation(Thread* const thread, const String& asset) { Zone* const zone = thread->zone(); @@ -377,77 +328,6 @@ static char* AvailableAssetsToCString(Thread* const thread) { return buffer.buffer(); } -// Fall back to old implementation temporarily to ease the roll into flutter. -// TODO(https://dartbug.com/55523): Remove fallback and throw errors that -// native assets API is not initialized. -static void* FfiResolveAssetFallback(Thread* const thread, - const String& asset_type, - const String& path, - const String& symbol, - char** error) { - Zone* const zone = thread->zone(); - void* handle = nullptr; - if (asset_type.Equals(Symbols::absolute())) { - handle = LoadDynamicLibrary(path.ToCString(), error); - } else if (asset_type.Equals(Symbols::relative())) { - const auto& platform_script_uri = String::Handle( - zone, - String::NewFormatted( - "%s%s", file_schema, - String::Handle(zone, GetPlatformScriptPath(thread)).ToCString())); - char* path_cstr = path.ToMallocCString(); -#if defined(DART_TARGET_OS_WINDOWS) - ReplaceBackSlashes(path_cstr); -#endif - CStringUniquePtr target_uri = - ResolveUri(path_cstr, platform_script_uri.ToCString()); - free(path_cstr); - if (!target_uri) { - *error = OS::SCreate( - /*use malloc*/ nullptr, - "Failed to resolve '%s' relative to " - "'%s'.", - path.ToCString(), platform_script_uri.ToCString()); - } else { - const char* target_path = target_uri.get() + file_schema_length; - handle = LoadDynamicLibrary(target_path, error); - } - } else if (asset_type.Equals(Symbols::system())) { - handle = LoadDynamicLibrary(path.ToCString(), error); - } else if (asset_type.Equals(Symbols::process())) { -#if defined(DART_HOST_OS_LINUX) || defined(DART_HOST_OS_MACOS) || \ - defined(DART_HOST_OS_ANDROID) || defined(DART_HOST_OS_FUCHSIA) - handle = RTLD_DEFAULT; -#else - handle = kWindowsDynamicLibraryProcessPtr; -#endif - } else if (asset_type.Equals(Symbols::executable())) { - handle = LoadDynamicLibrary(nullptr, error); - } else { - UNREACHABLE(); - } - if (*error != nullptr) { - char* inner_error = *error; - *error = OS::SCreate(/*use malloc*/ nullptr, - "Failed to load dynamic library '%s': %s", - path.ToCString(), inner_error); - free(inner_error); - } else { - void* const result = ResolveSymbol(handle, symbol.ToCString(), error); - if (*error != nullptr) { - char* inner_error = *error; - *error = OS::SCreate(/*use malloc*/ nullptr, - "Failed to lookup symbol '%s': %s", - symbol.ToCString(), inner_error); - free(inner_error); - } else { - return result; - } - } - ASSERT(*error != nullptr); - return nullptr; -} - // If an error occurs populates |error| with an error message // (caller must free this message when it is no longer needed). // @@ -476,32 +356,42 @@ static void* FfiResolveAsset(Thread* const thread, void* handle; if (asset_type.Equals(Symbols::absolute())) { if (native_assets_api->dlopen_absolute == nullptr) { - return FfiResolveAssetFallback(thread, asset_type, path, symbol, error); + *error = OS::SCreate(/*use malloc*/ nullptr, + "NativeAssetsApi::dlopen_absolute not set."); + return nullptr; } NoActiveIsolateScope no_active_isolate_scope; handle = native_assets_api->dlopen_absolute(path_cstr, error); } else if (asset_type.Equals(Symbols::relative())) { if (native_assets_api->dlopen_relative == nullptr) { - return FfiResolveAssetFallback(thread, asset_type, path, symbol, error); + *error = OS::SCreate(/*use malloc*/ nullptr, + "NativeAssetsApi::dlopen_relative not set."); + return nullptr; } NoActiveIsolateScope no_active_isolate_scope; handle = native_assets_api->dlopen_relative(path_cstr, error); } else if (asset_type.Equals(Symbols::system())) { if (native_assets_api->dlopen_system == nullptr) { - return FfiResolveAssetFallback(thread, asset_type, path, symbol, error); + *error = OS::SCreate(/*use malloc*/ nullptr, + "NativeAssetsApi::dlopen_system not set."); + return nullptr; } NoActiveIsolateScope no_active_isolate_scope; handle = native_assets_api->dlopen_system(path_cstr, error); } else if (asset_type.Equals(Symbols::executable())) { if (native_assets_api->dlopen_executable == nullptr) { - return FfiResolveAssetFallback(thread, asset_type, path, symbol, error); + *error = OS::SCreate(/*use malloc*/ nullptr, + "NativeAssetsApi::dlopen_executable not set."); + return nullptr; } NoActiveIsolateScope no_active_isolate_scope; handle = native_assets_api->dlopen_executable(error); } else { RELEASE_ASSERT(asset_type.Equals(Symbols::process())); if (native_assets_api->dlopen_process == nullptr) { - return FfiResolveAssetFallback(thread, asset_type, path, symbol, error); + *error = OS::SCreate(/*use malloc*/ nullptr, + "NativeAssetsApi::dlopen_process not set."); + return nullptr; } NoActiveIsolateScope no_active_isolate_scope; handle = native_assets_api->dlopen_process(error); @@ -511,7 +401,9 @@ static void* FfiResolveAsset(Thread* const thread, return nullptr; } if (native_assets_api->dlsym == nullptr) { - return FfiResolveAssetFallback(thread, asset_type, path, symbol, error); + *error = + OS::SCreate(/*use malloc*/ nullptr, "NativeAssetsApi::dlsym not set."); + return nullptr; } void* const result = native_assets_api->dlsym(handle, symbol.ToCString(), error); diff --git a/runtime/platform/platform_sources.gni b/runtime/platform/platform_sources.gni index db926b1ba79..e300478c7ea 100644 --- a/runtime/platform/platform_sources.gni +++ b/runtime/platform/platform_sources.gni @@ -35,8 +35,6 @@ platform_sources = [ "unwinding_records.cc", "unwinding_records.h", "unwinding_records_win.cc", - "uri.cc", - "uri.h", "utils.cc", "utils.h", "utils_android.cc", @@ -45,5 +43,3 @@ platform_sources = [ "utils_macos.cc", "utils_win.cc", ] - -platform_sources_tests = [ "uri_test.cc" ] diff --git a/runtime/vm/unit_test.cc b/runtime/vm/unit_test.cc index dcbf8a9dc30..d83f5876340 100644 --- a/runtime/vm/unit_test.cc +++ b/runtime/vm/unit_test.cc @@ -9,9 +9,9 @@ #include "bin/builtin.h" #include "bin/dartutils.h" #include "bin/isolate_data.h" +#include "bin/uri.h" #include "platform/globals.h" -#include "platform/uri.h" #include "vm/compiler/assembler/assembler.h" #include "vm/compiler/assembler/disassembler.h"