Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(386)

Unified Diff: runtime/bin/gen_snapshot.cc

Issue 2966903003: [gen_snapshot] Escape spaces when generating depfiles. (Closed)
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/gen_snapshot.cc
diff --git a/runtime/bin/gen_snapshot.cc b/runtime/bin/gen_snapshot.cc
index aca6e2388d0117b88cf60c969c02f45118ad0e0a..39734f559f728f50f1d7092f54725d83f88c1fc6 100644
--- a/runtime/bin/gen_snapshot.cc
+++ b/runtime/bin/gen_snapshot.cc
@@ -716,51 +716,16 @@ static Builtin::BuiltinLibraryId BuiltinId(const char* url) {
}
-static bool WriteDependencies(const char* target,
- File* file,
- MallocGrowableArray<char*>* dependencies) {
- bool success = true;
- success &= file->Print("%s: ", target);
-
- if (snapshot_kind == kScript) {
- if (vm_snapshot_data_filename != NULL) {
- success &= file->Print("%s ", vm_snapshot_data_filename);
- }
- if (vm_snapshot_instructions_filename != NULL) {
- success &= file->Print("%s ", vm_snapshot_instructions_filename);
- }
- if (isolate_snapshot_data_filename != NULL) {
- success &= file->Print("%s ", isolate_snapshot_data_filename);
- }
- if (isolate_snapshot_instructions_filename != NULL) {
- success &= file->Print("%s ", isolate_snapshot_instructions_filename);
- }
- }
-
- for (intptr_t i = 0; i < dependencies->length(); i++) {
- success &= file->Print("%s ", dependencies->At(i));
- }
-
- success &= file->Print("\n");
- return success;
-}
-
-
-static void CreateAndWriteDependenciesFile() {
- IsolateData* isolate_data =
- reinterpret_cast<IsolateData*>(Dart_CurrentIsolateData());
- MallocGrowableArray<char*>* dependencies = isolate_data->dependencies();
- if (dependencies == NULL) {
- return;
- }
+// Generates a depfile like gcc -M -MF. Must be consumable by Ninja.
+class DependenciesFileWriter : public ValueObject {
+ public:
+ DependenciesFileWriter() : dependencies_(NULL), file_(NULL), success_(true) {}
- Loader::ResolveDependenciesAsFilePaths();
+ void WriteDependencies(MallocGrowableArray<char*>* dependencies) {
+ dependencies_ = dependencies;
- ASSERT((dependencies_filename != NULL) || print_dependencies);
- if (dependencies_filename != NULL) {
- bool success = true;
- File* file = File::Open(dependencies_filename, File::kWriteTruncate);
- if (file == NULL) {
+ file_ = File::Open(dependencies_filename, File::kWriteTruncate);
+ if (file_ == NULL) {
Log::PrintErr("Error: Unable to open dependencies file: %s\n\n",
dependencies_filename);
exit(kErrorExitCode);
@@ -771,37 +736,101 @@ static void CreateAndWriteDependenciesFile() {
// output files.
switch (snapshot_kind) {
case kCore:
- success &=
- WriteDependencies(vm_snapshot_data_filename, file, dependencies);
- // success &= WriteDependencies(isolate_snapshot_data_filename, file,
- // dependencies);
+ WriteDependenciesWithTarget(vm_snapshot_data_filename);
+ // WriteDependenciesWithTarget(isolate_snapshot_data_filename);
break;
case kScript:
- success &=
- WriteDependencies(script_snapshot_filename, file, dependencies);
+ WriteDependenciesWithTarget(script_snapshot_filename);
break;
case kAppAOTAssembly:
- success &= WriteDependencies(assembly_filename, file, dependencies);
+ WriteDependenciesWithTarget(assembly_filename);
break;
case kCoreJIT:
case kAppAOTBlobs:
- success &=
- WriteDependencies(vm_snapshot_data_filename, file, dependencies);
- // success &= WriteDependencies(vm_snapshot_instructions_filename, file,
- // dependencies);
- // success &= WriteDependencies(isolate_snapshot_data_filename, file,
- // dependencies);
- // success &= WriteDependencies(isolate_snapshot_instructions_filename,
- // file, dependencies);
+ WriteDependenciesWithTarget(vm_snapshot_data_filename);
+ // WriteDependenciesWithTarget(vm_snapshot_instructions_filename);
+ // WriteDependenciesWithTarget(isolate_snapshot_data_filename);
+ // WriteDependenciesWithTarget(isolate_snapshot_instructions_filename);
break;
}
- if (!success) {
+ if (!success_) {
Log::PrintErr("Error: Unable to write dependencies file: %s\n\n",
dependencies_filename);
exit(kErrorExitCode);
}
- file->Release();
+ file_->Release();
+ }
+
+ private:
+ void WriteDependenciesWithTarget(const char* target) {
+ WritePath(target);
Chris Bracken 2017/07/01 00:47:54 It looks like we've just got one string for the ta
rmacnak 2017/07/05 16:51:04 Since all four files are generated by the same act
+ Write(": ");
+
+ if (snapshot_kind == kScript) {
+ if (vm_snapshot_data_filename != NULL) {
+ WritePath(vm_snapshot_data_filename);
+ }
+ if (vm_snapshot_instructions_filename != NULL) {
+ WritePath(vm_snapshot_instructions_filename);
+ }
+ if (isolate_snapshot_data_filename != NULL) {
+ WritePath(isolate_snapshot_data_filename);
+ }
+ if (isolate_snapshot_instructions_filename != NULL) {
+ WritePath(isolate_snapshot_instructions_filename);
+ }
+ }
+
+ for (intptr_t i = 0; i < dependencies_->length(); i++) {
+ WritePath(dependencies_->At(i));
+ }
+
+ Write("\n");
+ }
+
+ char* EscapePath(const char* path) {
+ char* escaped_path = reinterpret_cast<char*>(malloc(strlen(path) * 2 + 1));
+ const char* read_cursor = path;
+ char* write_cursor = escaped_path;
+ while (*read_cursor != '\0') {
+ if ((*read_cursor == ' ') || (*read_cursor == '\\')) {
+ *write_cursor++ = '\\';
+ }
+ *write_cursor++ = *read_cursor++;
+ }
+ *write_cursor = '\0';
+ return escaped_path;
+ }
+
+ void WritePath(const char* path) {
+ char* escaped_path = EscapePath(path);
+ success_ &= file_->Print("%s ", escaped_path);
+ free(escaped_path);
+ }
+
+ void Write(const char* string) { success_ &= file_->Print("%s", string); }
+
+ MallocGrowableArray<char*>* dependencies_;
+ File* file_;
+ bool success_;
+};
+
+
+static void CreateAndWriteDependenciesFile() {
+ IsolateData* isolate_data =
+ reinterpret_cast<IsolateData*>(Dart_CurrentIsolateData());
+ MallocGrowableArray<char*>* dependencies = isolate_data->dependencies();
+ if (dependencies == NULL) {
+ return;
+ }
+
+ Loader::ResolveDependenciesAsFilePaths();
+
+ ASSERT((dependencies_filename != NULL) || print_dependencies);
+ if (dependencies_filename != NULL) {
+ DependenciesFileWriter writer;
+ writer.WriteDependencies(dependencies);
}
if (print_dependencies) {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698