Add --print-deps mode to sky_snapshot (flutter/engine#2903)
This commit is contained in:
2
DEPS
2
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',
|
||||
|
||||
@@ -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<char> snapshot_blob = CreateSnapshot();
|
||||
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<char> 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 (!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;
|
||||
|
||||
Reference in New Issue
Block a user