mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Bug fixes for sky_snapshot --compile-all mode (flutter/engine#3255)
This commit is contained in:
parent
9a9a43d2d6
commit
f5d89a6a7a
2
DEPS
2
DEPS
@ -27,7 +27,7 @@ vars = {
|
||||
|
||||
# Note: When updating the Dart revision, ensure that all entries that are
|
||||
# dependencies of dart are also updated
|
||||
'dart_revision': 'deafdbf978d1128dde83b9779bdae6633d484d96',
|
||||
'dart_revision': 'ed47486f6003eea8c6012d4ee1ea604c3dcd41f0',
|
||||
'dart_boringssl_gen_revision': '62c20247d582444cb2804f9ea4e3abaa6e47f6a5',
|
||||
'dart_boringssl_revision': '8d343b44bbab829d1a28fdef650ca95f7db4412e',
|
||||
'dart_observatory_packages_revision': '26aad88f1c1915d39bbcbff3cad589e2402fdcf1',
|
||||
|
||||
@ -10,6 +10,7 @@
|
||||
|
||||
#include "dart/runtime/include/dart_api.h"
|
||||
#include "dart/runtime/include/dart_native_api.h"
|
||||
#include "dart/runtime/include/dart_tools_api.h"
|
||||
#include "lib/ftl/arraysize.h"
|
||||
#include "lib/ftl/command_line.h"
|
||||
#include "lib/ftl/files/directory.h"
|
||||
@ -121,6 +122,49 @@ Dart_Handle HandleLibraryTag(Dart_LibraryTag tag,
|
||||
return GetLoader().HandleLibraryTag(tag, library, url);
|
||||
}
|
||||
|
||||
static const char StubNativeFunctionName[] = "StubNativeFunction";
|
||||
|
||||
void StubNativeFunction(Dart_NativeArguments arguments) {
|
||||
// This is a stub function for the resolver
|
||||
Dart_SetReturnValue(
|
||||
arguments, Dart_NewApiError("<EMBEDDER DID NOT SETUP NATIVE RESOLVER>"));
|
||||
}
|
||||
|
||||
static Dart_NativeFunction StubNativeLookup(Dart_Handle name,
|
||||
int argument_count,
|
||||
bool* auto_setup_scope) {
|
||||
return &StubNativeFunction;
|
||||
}
|
||||
|
||||
static const uint8_t* StubNativeSymbol(Dart_NativeFunction nf) {
|
||||
return reinterpret_cast<const uint8_t*>(StubNativeFunctionName);
|
||||
}
|
||||
|
||||
// Registers a dummy native symbol resolver on all loaded libraries that do not
|
||||
// already have a native symbol resolver. This is necessary because
|
||||
// `--compile-all` will try and resolve all native functions. The function
|
||||
// returned by the dummy native symbol resolver will never be invoked.
|
||||
static void SetupStubNativeResolvers() {
|
||||
Dart_Handle library_ids = Dart_GetLibraryIds();
|
||||
intptr_t library_ids_length;
|
||||
DART_CHECK_VALID(Dart_ListLength(library_ids, &library_ids_length));
|
||||
for (intptr_t i = 0; i < library_ids_length; i++) {
|
||||
Dart_Handle library_id_handle = Dart_ListGetAt(library_ids, i);
|
||||
DART_CHECK_VALID(library_id_handle);
|
||||
int64_t library_id;
|
||||
Dart_IntegerToInt64(library_id_handle, &library_id);
|
||||
Dart_Handle library = Dart_GetLibraryFromId(library_id);
|
||||
DART_CHECK_VALID(library);
|
||||
Dart_NativeEntryResolver old_resolver = NULL;
|
||||
DART_CHECK_VALID(Dart_GetNativeResolver(library, &old_resolver));
|
||||
if (old_resolver == NULL) {
|
||||
Dart_Handle result =
|
||||
Dart_SetNativeResolver(library, &StubNativeLookup, &StubNativeSymbol);
|
||||
DART_CHECK_VALID(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<char> CreateSnapshot() {
|
||||
uint8_t* buffer = nullptr;
|
||||
intptr_t size = 0;
|
||||
@ -216,19 +260,7 @@ int CreateSnapshot(const ftl::CommandLine& command_line) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
const bool compile_all_mode = command_line.HasOption(kCompileAll, nullptr);
|
||||
if (compile_all_mode) {
|
||||
// Compile all the code loaded into the isolate. This will eagerly detect
|
||||
// syntax errors.
|
||||
Dart_Handle compile_all_results = Dart_CompileAll();
|
||||
if (Dart_IsError(compile_all_results)) {
|
||||
std::cerr << "error: Compilation errors detected:"
|
||||
<< std::endl
|
||||
<< Dart_GetError(compile_all_results)
|
||||
<< std::endl;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
SetupStubNativeResolvers();
|
||||
|
||||
if (print_deps_mode) {
|
||||
if (Dart_IsError(load_result)) {
|
||||
@ -263,6 +295,22 @@ int CreateSnapshot(const ftl::CommandLine& command_line) {
|
||||
<< std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Run compile-all *after* generating the snapshot to avoid adding
|
||||
// unnecessary compilation related artifacts to the snapshot.
|
||||
const bool compile_all_mode = command_line.HasOption(kCompileAll, nullptr);
|
||||
if (compile_all_mode) {
|
||||
// Compile all the code loaded into the isolate. This will eagerly detect
|
||||
// syntax errors.
|
||||
Dart_Handle compile_all_results = Dart_CompileAll();
|
||||
if (Dart_IsError(compile_all_results)) {
|
||||
std::cerr << "error: Compilation errors detected:"
|
||||
<< std::endl
|
||||
<< Dart_GetError(compile_all_results)
|
||||
<< std::endl;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user