From b7fa647d2200e4617af7f493bf0b560303b226dc Mon Sep 17 00:00:00 2001 From: John McCutchan Date: Tue, 22 Nov 2016 07:50:34 -0800 Subject: [PATCH] Add --compile-all to sky_snapshot (flutter/engine#3251) --- engine/src/flutter/snapshotter/main.cc | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/engine/src/flutter/snapshotter/main.cc b/engine/src/flutter/snapshotter/main.cc index 4439951044..ba2a49e11e 100644 --- a/engine/src/flutter/snapshotter/main.cc +++ b/engine/src/flutter/snapshotter/main.cc @@ -9,6 +9,7 @@ #include #include "dart/runtime/include/dart_api.h" +#include "dart/runtime/include/dart_native_api.h" #include "lib/ftl/arraysize.h" #include "lib/ftl/command_line.h" #include "lib/ftl/files/directory.h" @@ -36,6 +37,7 @@ 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 @@ -206,6 +208,28 @@ int CreateSnapshot(const ftl::CommandLine& command_line) { 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; + } + + 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; + } + } + if (print_deps_mode) { if (Dart_IsError(load_result)) { // Loading / parsing the source resulted in an error. Report the error