sky_snapshot should use --snaphsot as the defualt value for
--build-output. Also, dependency collection should be done by Loader.
This commit is contained in:
@@ -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<std::string>& dependencies() const { return dependencies_; }
|
||||
private:
|
||||
std::set<std::string> 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<std::string>& 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<std::string> 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<std::string>& GetDependencies() {
|
||||
return GetFetcher().dependencies();
|
||||
return GetLoader().dependencies();
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user