Merge pull request #2478 from alhaad/depfile_support
Depfile support for sky_snaphot.
This commit is contained in:
@@ -15,16 +15,6 @@
|
||||
|
||||
namespace {
|
||||
|
||||
std::string 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);
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
base::FilePath SimplifyPath(const base::FilePath& path) {
|
||||
std::vector<base::FilePath::StringType> components;
|
||||
path.GetComponents(&components);
|
||||
@@ -46,12 +36,16 @@ 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);
|
||||
@@ -79,6 +73,17 @@ 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(Fetch(StringFromDart(url)));
|
||||
Dart_Handle result = Dart_LoadLibrary(url, source, 0, 0);
|
||||
@@ -128,5 +133,10 @@ Dart_Handle HandleLibraryTag(Dart_LibraryTag tag,
|
||||
|
||||
void LoadScript(const std::string& url) {
|
||||
LogIfError(
|
||||
Dart_LoadScript(StringToDart(url), StringToDart(Fetch(url)), 0, 0));
|
||||
Dart_LoadScript(StringToDart(url), StringToDart(GetLoader().Fetch(url)),
|
||||
0, 0));
|
||||
}
|
||||
|
||||
const std::set<std::string>& GetDependencies() {
|
||||
return GetLoader().dependencies();
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#ifndef SKY_TOOLS_SKY_SNAPSHOT_LOADER_H_
|
||||
#define SKY_TOOLS_SKY_SNAPSHOT_LOADER_H_
|
||||
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
||||
#include "dart/runtime/include/dart_api.h"
|
||||
@@ -13,5 +14,6 @@ Dart_Handle HandleLibraryTag(Dart_LibraryTag tag,
|
||||
Dart_Handle library,
|
||||
Dart_Handle url);
|
||||
void LoadScript(const std::string& url);
|
||||
const std::set<std::string>& GetDependencies();
|
||||
|
||||
#endif // SKY_TOOLS_SKY_SNAPSHOT_LOADER_H_
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
void Usage() {
|
||||
std::cerr << "Usage: sky_snapshot"
|
||||
<< " --" << switches::kPackageRoot << " --" << switches::kSnapshot
|
||||
<< " --" << switches::kDepfile << " --" << switches::kBuildOutput
|
||||
<< " <lib/main.dart>" << std::endl;
|
||||
}
|
||||
|
||||
@@ -33,6 +34,21 @@ void WriteSnapshot(base::FilePath path) {
|
||||
size);
|
||||
}
|
||||
|
||||
void WriteDependencies(base::FilePath path,
|
||||
const std::string& build_output,
|
||||
const std::set<std::string>& deps) {
|
||||
base::FilePath current_directory;
|
||||
CHECK(base::GetCurrentDirectory(¤t_directory));
|
||||
std::string output = build_output + ":";
|
||||
for (const auto& i : deps) {
|
||||
output += " ";
|
||||
output += current_directory.Append(i).MaybeAsASCII();
|
||||
}
|
||||
const char* data = output.c_str();
|
||||
const intptr_t data_length = output.size();
|
||||
CHECK_EQ(base::WriteFile(path, data, data_length), data_length);
|
||||
}
|
||||
|
||||
int main(int argc, const char* argv[]) {
|
||||
base::AtExitManager exit_manager;
|
||||
base::EnableTerminationOnHeapCorruption();
|
||||
@@ -63,5 +79,14 @@ int main(int argc, const char* argv[]) {
|
||||
CHECK(command_line.HasSwitch(switches::kSnapshot)) << "Need --snapshot";
|
||||
WriteSnapshot(command_line.GetSwitchValuePath(switches::kSnapshot));
|
||||
|
||||
if (command_line.HasSwitch(switches::kDepfile)) {
|
||||
auto build_output = command_line.HasSwitch(switches::kBuildOutput) ?
|
||||
command_line.GetSwitchValueASCII(switches::kBuildOutput) :
|
||||
command_line.GetSwitchValueASCII(switches::kSnapshot);
|
||||
WriteDependencies(command_line.GetSwitchValuePath(switches::kDepfile),
|
||||
build_output,
|
||||
GetDependencies());
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
|
||||
namespace switches {
|
||||
|
||||
const char kBuildOutput[] = "build-output";
|
||||
const char kDepfile[] = "depfile";
|
||||
const char kHelp[] = "help";
|
||||
const char kPackageRoot[] = "package-root";
|
||||
const char kSnapshot[] = "snapshot";
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
|
||||
namespace switches {
|
||||
|
||||
extern const char kBuildOutput[];
|
||||
extern const char kDepfile[];
|
||||
extern const char kHelp[];
|
||||
extern const char kPackageRoot[];
|
||||
extern const char kSnapshot[];
|
||||
|
||||
Reference in New Issue
Block a user