From cd417b0519153a3c8b232ab321683341a0efdb3a Mon Sep 17 00:00:00 2001 From: Michael Goderbauer Date: Tue, 14 Mar 2017 10:24:17 -0700 Subject: [PATCH] Remove sky_snapshot sources (#3471) * Remove sky_snapshot sources * update licenses --- BUILD.gn | 2 - build/flutter_app.gni | 22 +- build/snapshot.py | 22 +- sky/BUILD.gn | 4 - snapshotter/BUILD.gn | 30 --- snapshotter/main.cc | 330 ------------------------ travis/licenses_golden/licenses_flutter | 1 - 7 files changed, 28 insertions(+), 383 deletions(-) delete mode 100644 snapshotter/BUILD.gn delete mode 100644 snapshotter/main.cc diff --git a/BUILD.gn b/BUILD.gn index 15976b5b233..9b97483e05d 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -15,8 +15,6 @@ group("flutter") { "//flutter/examples", "//flutter/flow", "//flutter/runtime", - "//flutter/snapshotter", - "//flutter/snapshotter($host_toolchain)", ] } diff --git a/build/flutter_app.gni b/build/flutter_app.gni index 46306c98f04..8f1af0ec0bb 100644 --- a/build/flutter_app.gni +++ b/build/flutter_app.gni @@ -58,9 +58,14 @@ template("flutter_app") { bundle_name = "${target_name}.flx" } - flutter_snapshot_label = "//flutter/snapshotter($host_toolchain)" + flutter_snapshot_label = "//dart/runtime/bin:gen_snapshot($host_toolchain)" flutter_snapshot_dir = get_label_info(flutter_snapshot_label, "root_out_dir") - flutter_snapshot = "$flutter_snapshot_dir/sky_snapshot" + flutter_snapshot = "$flutter_snapshot_dir/gen_snapshot" + + flutter_core_snapshot_label = "//flutter/lib/snapshot:generate_snapshot_bin" + flutter_core_snapshot_gen_dir = get_label_info(flutter_core_snapshot_label, "target_gen_dir") + flutter_core_snapshot_vm_data = "$flutter_core_snapshot_gen_dir/vm_isolate_snapshot.bin" + flutter_core_snapshot_isolate_data = "$flutter_core_snapshot_gen_dir/isolate_snapshot.bin" dart_binary_label = "//dart/runtime/bin:dart($host_toolchain)" dart_binary_dir = get_label_info(dart_binary_label, "root_out_dir") @@ -102,23 +107,26 @@ template("flutter_app") { args = [ "--snapshotter-path", rebase_path(flutter_snapshot), - "--app-dir", - rebase_path("."), + "--vm-snapshot-data", + rebase_path(flutter_core_snapshot_vm_data), + "--isolate-snapshot-data", + rebase_path(flutter_core_snapshot_isolate_data), "--main-dart", rebase_path(main_dart), "--packages", rebase_path(dot_packages), "--snapshot", - rebase_path(snapshot_path), + rebase_path(snapshot_path, root_build_dir), "--depfile", rebase_path(depfile_path), - "--build-output", - rebase_path(snapshot_path, root_build_dir), + "--root-build-dir", + rebase_path(root_build_dir), ] deps = [ ":$dart_package_name", flutter_snapshot_label, + flutter_core_snapshot_label, ] if (defined(invoker.deps)) { diff --git a/build/snapshot.py b/build/snapshot.py index 9b47a850b35..30601090ebe 100755 --- a/build/snapshot.py +++ b/build/snapshot.py @@ -14,29 +14,33 @@ def main(): parser.add_argument('--snapshotter-path', type=str, required=True, help='The Flutter snapshotter') - parser.add_argument('--app-dir', type=str, required=True, - help='The root of the app') + parser.add_argument('--vm-snapshot-data', type=str, required=True, + help='Path to vm_isolate_snapshot.bin') + parser.add_argument('--isolate-snapshot-data', type=str, required=True, + help='Path to isolate_snapshot.bin') parser.add_argument('--main-dart', type=str, required=True, help='The main.dart file to use') parser.add_argument('--packages', type=str, required=True, help='The package map to use') parser.add_argument('--snapshot', type=str, required=True, - help='Path to application snapshot') + help='Where to output application snapshot') parser.add_argument('--depfile', type=str, required=True, help='Where to output dependency information') - parser.add_argument('--build-output', type=str, required=True, - help='Target name used in the depfile') + parser.add_argument('--root-build-dir', type=str, required=True, + help='The root build dir for --depfile and --snapshot') args = parser.parse_args() result = subprocess.call([ args.snapshotter_path, + '--snapshot_kind=script', + '--vm_snapshot_data=%s' % args.vm_snapshot_data, + '--isolate_snapshot_data=%s' % args.isolate_snapshot_data, '--packages=%s' % args.packages, - '--snapshot=%s' % args.snapshot, - '--depfile=%s' % args.depfile, - '--build-output=%s' % args.build_output, + '--script_snapshot=%s' % args.snapshot, + '--dependencies=%s' % args.depfile, args.main_dart, - ], cwd=args.app_dir) + ], cwd=args.root_build_dir) return result diff --git a/sky/BUILD.gn b/sky/BUILD.gn index c57fa16df2b..c78c168f3ac 100644 --- a/sky/BUILD.gn +++ b/sky/BUILD.gn @@ -14,8 +14,4 @@ group("sky") { if (!is_fuchsia) { deps += [ "//flutter/shell" ] } - - if (dart_host_toolchain == host_toolchain) { - deps += [ "//flutter/snapshotter($dart_host_toolchain)" ] - } } diff --git a/snapshotter/BUILD.gn b/snapshotter/BUILD.gn deleted file mode 100644 index 815e4eff530..00000000000 --- a/snapshotter/BUILD.gn +++ /dev/null @@ -1,30 +0,0 @@ -# Copyright 2014 The Chromium Authors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -executable("snapshotter") { - output_name = "sky_snapshot" - - sources = [ - "main.cc", - ] - - deps = [ - "//dart/runtime:libdart", - "//dart/runtime/vm:libdart_platform", - "//flutter/lib/snapshot", - "//lib/ftl", - "//lib/tonic/converter", - "//lib/tonic/file_loader", - ] - - if (!is_ios && !is_mac && !is_fuchsia) { - ldflags = [ - # libgcc_s is not a DT_NEEDED library; it normally gets loaded implicitly. - # This flag ensures that rpath is referenced when searching for - # the so, which in turn gets the resulting sky_snapshot binary - # closer to being able to run in Google's production environment. - "-lgcc_s", - ] - } -} diff --git a/snapshotter/main.cc b/snapshotter/main.cc deleted file mode 100644 index 2ace6655a1e..00000000000 --- a/snapshotter/main.cc +++ /dev/null @@ -1,330 +0,0 @@ -// Copyright 2016 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include - -#include -#include -#include - -#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" -#include "lib/ftl/files/eintr_wrapper.h" -#include "lib/ftl/files/file_descriptor.h" -#include "lib/ftl/files/file.h" -#include "lib/ftl/files/symlink.h" -#include "lib/ftl/files/unique_fd.h" -#include "lib/ftl/logging.h" -#include "lib/tonic/converter/dart_converter.h" -#include "lib/tonic/file_loader/file_loader.h" - -extern "C" { -extern const uint8_t kDartVmSnapshotData[]; -extern const uint8_t kDartVmSnapshotInstructions[]; -extern const uint8_t kDartIsolateSnapshotData[]; -extern const uint8_t kDartIsolateSnapshotInstructions[]; -} - -namespace { - -using tonic::ToDart; - -constexpr char kHelp[] = "help"; -constexpr char kPackages[] = "packages"; -constexpr char kSnapshot[] = "snapshot"; -constexpr char kDepfile[] = "depfile"; -constexpr char kBuildOutput[] = "build-output"; -constexpr char kPrintDeps[] = "print-deps"; -constexpr char kCompileAll[] = "compile-all"; - -const char* kDartArgs[] = { - // clang-format off - "--enable_mirrors=false", - "--load_deferred_eagerly=true", - "--conditional_directives", - // TODO(chinmaygarde): The experimental interpreter for iOS device targets - // does not support all these flags. The build process uses its own version - // of this snapshotter. Till support for all these flags is added, make - // sure the snapshotter does not error out on unrecognized flags. - "--ignore-unrecognized-flags", - // clang-format on -}; - -void Usage() { - std::cerr - << "Usage: sky_snapshot [] " << std::endl - << std::endl - << "Global options:" << std::endl - << " --packages= Where to find a .package spec" << std::endl - << " file." << std::endl - << std::endl - << "To create a script snapshot of :" << std::endl - << " --snapshot= Where to write the snapshot to." << std::endl - << " --depfile= (optional) Where to write the" << std::endl - << " dependecy file to, which lists" << std::endl - << " all transitive imports of the" << std::endl - << " generated snapshot as sources" << std::endl - << " in the style of a Makefile." << std::endl - << " --build-output= (required with --depfile)" << std::endl - << " Determines target name used in" << std::endl - << " dependency file." << std::endl - << " --compile-all Compile all code loaded" << std::endl - << " into the isolate to eagerly" << std::endl - << " detect syntax errors." << std::endl - << std::endl - << "To print dependencies of to stdout:" << std::endl - << " --print-deps Prints all transitive imports" << std::endl - << " as sources to stdout (no" << std::endl - << " snapshot will be created)." << std::endl; -} - -class DartScope { - public: - DartScope(Dart_Isolate isolate) { - Dart_EnterIsolate(isolate); - Dart_EnterScope(); - } - - ~DartScope() { - Dart_ExitScope(); - Dart_ExitIsolate(); - } -}; - -void InitDartVM() { - FTL_CHECK(Dart_SetVMFlags(arraysize(kDartArgs), kDartArgs)); - Dart_InitializeParams params = {}; - params.version = DART_INITIALIZE_PARAMS_CURRENT_VERSION; - params.vm_snapshot_data = kDartVmSnapshotData; - params.vm_snapshot_instructions = kDartVmSnapshotInstructions; - char* error = Dart_Initialize(¶ms); - if (error) - FTL_LOG(FATAL) << error; -} - -Dart_Isolate CreateDartIsolate() { - char* error = nullptr; - Dart_Isolate isolate = - Dart_CreateIsolate("dart:snapshot", "main", kDartIsolateSnapshotData, - kDartIsolateSnapshotInstructions, - nullptr, nullptr, &error); - FTL_CHECK(isolate) << error; - Dart_ExitIsolate(); - return isolate; -} - -tonic::FileLoader* g_loader = nullptr; - -tonic::FileLoader& GetLoader() { - if (!g_loader) - g_loader = new tonic::FileLoader(); - return *g_loader; -} - -Dart_Handle HandleLibraryTag(Dart_LibraryTag tag, - Dart_Handle library, - Dart_Handle url) { - 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("")); -} - -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(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 libraries = Dart_GetLoadedLibraries(); - DART_CHECK_VALID(libraries); - intptr_t libraries_length; - DART_CHECK_VALID(Dart_ListLength(libraries, &libraries_length)); - for (intptr_t i = 0; i < libraries_length; i++) { - Dart_Handle library = Dart_ListGetAt(libraries, i); - 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 CreateSnapshot() { - uint8_t* buffer = nullptr; - intptr_t size = 0; - DART_CHECK_VALID(Dart_CreateScriptSnapshot(&buffer, &size)); - const char* begin = reinterpret_cast(buffer); - return std::vector(begin, begin + size); -} - -bool WriteDepfile(const std::string& path, - const std::string& build_output, - const std::set& deps) { - std::string current_directory = files::GetCurrentDirectory(); - std::string output = build_output + ":"; - for (const auto& dep : deps) { - std::string file = dep; - FTL_DCHECK(!file.empty()); - if (file[0] != '/') - file = current_directory + "/" + file; - - std::string resolved_file; - if (files::ReadSymbolicLink(file, &resolved_file)) { - output += " " + resolved_file; - } else { - output += " " + file; - } - } - return files::WriteFile(path, output.data(), output.size()); -} - -int CreateSnapshot(const ftl::CommandLine& command_line) { - if (command_line.HasOption(kHelp, nullptr)) { - Usage(); - return 0; - } - - if (command_line.positional_args().empty()) { - Usage(); - return 1; - } - - std::string packages; - if (!command_line.GetOptionValue(kPackages, &packages)) { - std::cerr << "error: Need --" << kPackages << std::endl; - return 1; - } - - std::vector args = command_line.positional_args(); - if (args.size() != 1) { - std::cerr << "error: Need one position argument. Got " << args.size() << "." - << std::endl; - return 1; - } - - std::string main_dart = args[0]; - const bool print_deps_mode = command_line.HasOption(kPrintDeps, nullptr); - std::string snapshot; - std::string depfile; - std::string build_output; - if (!print_deps_mode) { - if (!command_line.GetOptionValue(kSnapshot, &snapshot)) { - std::cerr << "error: Need --" << kSnapshot << "." << std::endl; - return 1; - } - if (command_line.GetOptionValue(kDepfile, &depfile) && - !command_line.GetOptionValue(kBuildOutput, &build_output)) { - std::cerr << "error: Need --" << kBuildOutput << " if --" << kDepfile - << " is specified." << std::endl; - return 1; - } - } - - InitDartVM(); - - tonic::FileLoader& loader = GetLoader(); - if (!loader.LoadPackagesMap(packages)) - return 1; - - Dart_Isolate isolate = CreateDartIsolate(); - FTL_CHECK(isolate) << "Failed to create isolate."; - - DartScope scope(isolate); - - DART_CHECK_VALID(Dart_SetLibraryTagHandler(HandleLibraryTag)); - Dart_Handle load_result = - Dart_LoadScript(ToDart(main_dart), Dart_Null(), - ToDart(loader.Fetch(main_dart)), 0, 0); - - if (Dart_IsError(load_result)) { - std::cerr << "error: Failed to load main script:" - << std::endl - << Dart_GetError(load_result) - << std::endl; - return 1; - } - - SetupStubNativeResolvers(); - - if (print_deps_mode) { - if (Dart_IsError(load_result)) { - // Loading / parsing the source resulted in an error. Report the error - // to stderr and exit. - std::cerr << Dart_GetError(load_result) << std::endl; - return 1; - } - // The script has been loaded, print out the minimal dependencies to run. - for (const auto& dep : loader.dependencies()) { - std::string file = dep; - FTL_DCHECK(!file.empty()); - std::cout << file << "\n"; - } - } else { - DART_CHECK_VALID(load_result); - DART_CHECK_VALID(Dart_FinalizeLoading(false)); - - // The script has been loaded, generate a snapshot. - std::vector snapshot_blob = CreateSnapshot(); - - if (!snapshot.empty() && - !files::WriteFile(snapshot, snapshot_blob.data(), snapshot_blob.size())) { - std::cerr << "error: Failed to write snapshot to '" << snapshot << "'." - << std::endl; - return 1; - } - - if (!depfile.empty() && - !WriteDepfile(depfile, build_output, loader.dependencies())) { - std::cerr << "error: Failed to write depfile to '" << depfile << "'." - << 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; -} - -} // namespace - -int main(int argc, const char* argv[]) { - return CreateSnapshot(ftl::CommandLineFromArgcArgv(argc, argv)); -} diff --git a/travis/licenses_golden/licenses_flutter b/travis/licenses_golden/licenses_flutter index fcf5307142c..6b8764f5d81 100644 --- a/travis/licenses_golden/licenses_flutter +++ b/travis/licenses_golden/licenses_flutter @@ -1829,7 +1829,6 @@ FILE: ../../../flutter/sky/engine/platform/fonts/fuchsia/FontCacheFuchsia.cpp FILE: ../../../flutter/sky/engine/platform/fonts/fuchsia/FontCacheFuchsia.h FILE: ../../../flutter/sky/engine/platform/text/TextBox.h FILE: ../../../flutter/sky/packages/flutter_services/lib/empty.dart -FILE: ../../../flutter/snapshotter/main.cc FILE: ../../../flutter/synchronization/debug_thread_checker.h FILE: ../../../flutter/synchronization/pipeline.cc FILE: ../../../flutter/synchronization/pipeline.h