From ee5c415bebbcba13b789ac734bbfce4266b7d302 Mon Sep 17 00:00:00 2001 From: Alhaad Gokhale Date: Tue, 8 Mar 2016 21:56:44 -0800 Subject: [PATCH] sky_snapshot should use --snaphsot as the defualt value for --build-output. Also, dependency collection should be done by Loader. --- .../flutter/sky/tools/sky_snapshot/loader.cc | 51 +++++++------------ .../flutter/sky/tools/sky_snapshot/main.cc | 7 +-- 2 files changed, 23 insertions(+), 35 deletions(-) diff --git a/engine/src/flutter/sky/tools/sky_snapshot/loader.cc b/engine/src/flutter/sky/tools/sky_snapshot/loader.cc index 0c3c38fa01..ba19fa67c8 100644 --- a/engine/src/flutter/sky/tools/sky_snapshot/loader.cc +++ b/engine/src/flutter/sky/tools/sky_snapshot/loader.cc @@ -32,44 +32,20 @@ base::FilePath SimplifyPath(const base::FilePath& path) { return result; } -class Fetcher { - public: - std::string Fetch(const std::string& url); - const std::set& dependencies() const { return dependencies_; } - private: - std::set dependencies_; -}; - -std::string Fetcher::Fetch(const std::string& url) { - base::FilePath path(url); - std::string source; - if (!base::ReadFileToString(path, &source)) { - fprintf(stderr, "error: Unable to find Dart library '%s'.\n", url.c_str()); - exit(1); - } - dependencies_.insert(url); - return source; -} - -Fetcher* g_fetcher = nullptr; - -Fetcher& GetFetcher() { - if (!g_fetcher) { - g_fetcher = new Fetcher(); - } - return *g_fetcher; -} - class Loader { public: Loader(const base::FilePath& package_root); + const std::set& dependencies() const { return dependencies_; } + std::string CanonicalizePackageURL(std::string url); Dart_Handle CanonicalizeURL(Dart_Handle library, Dart_Handle url); + std::string Fetch(const std::string& url); Dart_Handle Import(Dart_Handle url); Dart_Handle Source(Dart_Handle library, Dart_Handle url); private: + std::set dependencies_; base::FilePath package_root_; DISALLOW_COPY_AND_ASSIGN(Loader); @@ -97,15 +73,26 @@ Dart_Handle Loader::CanonicalizeURL(Dart_Handle library, Dart_Handle url) { return StringToDart(normalized_path.AsUTF8Unsafe()); } +std::string Loader::Fetch(const std::string& url) { + base::FilePath path(url); + std::string source; + if (!base::ReadFileToString(path, &source)) { + fprintf(stderr, "error: Unable to find Dart library '%s'.\n", url.c_str()); + exit(1); + } + dependencies_.insert(url); + return source; +} + Dart_Handle Loader::Import(Dart_Handle url) { - Dart_Handle source = StringToDart(GetFetcher().Fetch(StringFromDart(url))); + Dart_Handle source = StringToDart(Fetch(StringFromDart(url))); Dart_Handle result = Dart_LoadLibrary(url, source, 0, 0); LogIfError(result); return result; } Dart_Handle Loader::Source(Dart_Handle library, Dart_Handle url) { - Dart_Handle source = StringToDart(GetFetcher().Fetch(StringFromDart(url))); + Dart_Handle source = StringToDart(Fetch(StringFromDart(url))); Dart_Handle result = Dart_LoadSource(library, url, source, 0, 0); LogIfError(result); return result; @@ -146,10 +133,10 @@ Dart_Handle HandleLibraryTag(Dart_LibraryTag tag, void LoadScript(const std::string& url) { LogIfError( - Dart_LoadScript(StringToDart(url), StringToDart(GetFetcher().Fetch(url)), + Dart_LoadScript(StringToDart(url), StringToDart(GetLoader().Fetch(url)), 0, 0)); } const std::set& GetDependencies() { - return GetFetcher().dependencies(); + return GetLoader().dependencies(); } diff --git a/engine/src/flutter/sky/tools/sky_snapshot/main.cc b/engine/src/flutter/sky/tools/sky_snapshot/main.cc index 53392bc268..4566217d53 100644 --- a/engine/src/flutter/sky/tools/sky_snapshot/main.cc +++ b/engine/src/flutter/sky/tools/sky_snapshot/main.cc @@ -80,10 +80,11 @@ int main(int argc, const char* argv[]) { WriteSnapshot(command_line.GetSwitchValuePath(switches::kSnapshot)); if (command_line.HasSwitch(switches::kDepfile)) { - CHECK(command_line.HasSwitch(switches::kBuildOutput)) << - "Need --build-output with --depfile"; + auto build_output = command_line.HasSwitch(switches::kBuildOutput) ? + command_line.GetSwitchValueASCII(switches::kBuildOutput) : + command_line.GetSwitchValueASCII(switches::kSnapshot); WriteDependencies(command_line.GetSwitchValuePath(switches::kDepfile), - command_line.GetSwitchValueASCII(switches::kBuildOutput), + build_output, GetDependencies()); }