diff --git a/DEPS b/DEPS index afa19d29a4498a8fdb10ef9a7a6738ebae46e80b..58e8f4c09becc792fd7d5e587b0cb990d4ec3998 100644 --- a/DEPS +++ b/DEPS @@ -55,7 +55,7 @@ deps = { Var('fuchsia_git') + '/ftl' + '@' + '0bb3a02301c8a88b494e58c6636fa509525adaa8', 'src/lib/tonic': - Var('fuchsia_git') + '/tonic' + '@' + '25b9fe6c5dfb0925794e754b7dc80d9c320e5082', + Var('fuchsia_git') + '/tonic' + '@' + '8e0776dc4aa1c7fab21b742279ef90527c59b216', 'src/third_party/gtest': Var('fuchsia_git') + '/third_party/gtest' + '@' + 'c00f82917331efbbd27124b537e4ccc915a02b72', diff --git a/snapshotter/main.cc b/snapshotter/main.cc index 3f95be7352ad02c5d71e81e2cca02a5e7aae2664..89ca0d0bf0da8063b5fa3fba14552ea07a8eda21 100644 --- a/snapshotter/main.cc +++ b/snapshotter/main.cc @@ -35,6 +35,7 @@ constexpr char kPackages[] = "packages"; constexpr char kSnapshot[] = "snapshot"; constexpr char kDepfile[] = "depfile"; constexpr char kBuildOutput[] = "build-output"; +constexpr char kPrintDeps[] = "print-deps"; const char* kDartArgs[] = { // clang-format off @@ -181,20 +182,21 @@ int CreateSnapshot(const ftl::CommandLine& command_line) { } std::string main_dart = args[0]; - + const bool print_deps_mode = command_line.HasOption(kPrintDeps, nullptr); std::string snapshot; - if (!command_line.GetOptionValue(kSnapshot, &snapshot)) { - std::cerr << "error: Need --" << kSnapshot << "." << std::endl; - return 1; - } - std::string depfile; std::string build_output; - 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; + 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(); @@ -212,20 +214,30 @@ int CreateSnapshot(const ftl::CommandLine& command_line) { DART_CHECK_VALID(Dart_LoadScript(ToDart(main_dart), Dart_Null(), ToDart(loader.Fetch(main_dart)), 0, 0)); - 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 (print_deps_mode) { + // The script has been loaded, print out the minimal dependencies to run. + for (const auto& dep : loader.url_dependencies()) { + std::string file = dep; + FTL_DCHECK(!file.empty()); + std::cout << file << "\n"; + } + } else { + // 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; + if (!depfile.empty() && + !WriteDepfile(depfile, build_output, loader.dependencies())) { + std::cerr << "error: Failed to write depfile to '" << depfile << "'." + << std::endl; + return 1; + } } return 0;