Chromium Code Reviews| Index: runtime/bin/main.cc |
| diff --git a/runtime/bin/main.cc b/runtime/bin/main.cc |
| index f8ef12f0fc5fb1b1bcb469e9aa8ce66bc4119806..d3e078e21b0d87783515b2b9fb53842bae3470ec 100644 |
| --- a/runtime/bin/main.cc |
| +++ b/runtime/bin/main.cc |
| @@ -70,6 +70,12 @@ static bool has_gen_precompiled_snapshot = false; |
| static bool has_run_precompiled_snapshot = false; |
| +// Value of the --gen/run_precompiled_snapshot flag. |
| +// (This pointer points into an argv buffer and does not need to be |
| +// free'd.) |
| +static const char* precompiled_snapshot_directory = NULL; |
| + |
| + |
| // Global flag that is used to indicate that we want to compile everything in |
| // the same way as precompilation before main, then continue running in the |
| // same process. |
| @@ -303,16 +309,18 @@ static bool ProcessCompileAllOption(const char* arg, |
| static bool ProcessGenPrecompiledSnapshotOption( |
| const char* arg, |
| CommandLineOptions* vm_options) { |
| - ASSERT(arg != NULL); |
| - if (*arg != '\0') { |
| - return false; |
| - } |
| // Ensure that we are not already running using a full snapshot. |
| if (isolate_snapshot_buffer != NULL) { |
| Log::PrintErr("Precompiled snapshots must be generated with" |
| " dart_no_snapshot.\n"); |
| return false; |
| } |
| + ASSERT(arg != NULL); |
| + precompiled_snapshot_directory = arg; |
| + if ((precompiled_snapshot_directory[0] == '=') || |
| + (precompiled_snapshot_directory[0] == ':')) { |
| + precompiled_snapshot_directory = &precompiled_snapshot_directory[1]; |
| + } |
| has_gen_precompiled_snapshot = true; |
| vm_options->AddArgument("--precompilation"); |
| return true; |
| @@ -323,8 +331,10 @@ static bool ProcessRunPrecompiledSnapshotOption( |
| const char* arg, |
| CommandLineOptions* vm_options) { |
| ASSERT(arg != NULL); |
| - if (*arg != '\0') { |
| - return false; |
| + precompiled_snapshot_directory = arg; |
| + if ((precompiled_snapshot_directory[0] == '=') || |
| + (precompiled_snapshot_directory[0] == ':')) { |
| + precompiled_snapshot_directory = &precompiled_snapshot_directory[1]; |
| } |
| has_run_precompiled_snapshot = true; |
| vm_options->AddArgument("--precompilation"); |
| @@ -1010,32 +1020,57 @@ static void ServiceStreamCancelCallback(const char* stream_id) { |
| } |
| -static void WriteSnapshotFile(const char* filename, |
| - const uint8_t* buffer, |
| - const intptr_t size) { |
| - File* file = File::Open(filename, File::kWriteTruncate); |
| +static void WritePrecompiledSnapshotFile(const char* filename, |
| + const uint8_t* buffer, |
| + const intptr_t size) { |
| + const char* qualified_filename; |
| + if (strlen(precompiled_snapshot_directory) > 0) { |
| + intptr_t len = snprintf(NULL, 0, "%s/%s", |
| + precompiled_snapshot_directory, filename); |
| + char* concat = reinterpret_cast<char*>(alloca(len + 1)); |
|
Florian Schneider
2015/12/17 12:53:25
I would avoid alloca - it is not standard C++, and
rmacnak
2015/12/17 19:20:51
Done.
|
| + snprintf(concat, len + 1, "%s/%s", |
| + precompiled_snapshot_directory, filename); |
| + qualified_filename = concat; |
| + } else { |
| + qualified_filename = filename; |
| + } |
| + |
| + File* file = File::Open(qualified_filename, File::kWriteTruncate); |
| ASSERT(file != NULL); |
| if (!file->WriteFully(buffer, size)) { |
| ErrorExit(kErrorExitCode, |
| "Unable to open file %s for writing snapshot\n", |
| - filename); |
| + qualified_filename); |
| } |
| delete file; |
| } |
| -static void ReadSnapshotFile(const char* filename, |
| - const uint8_t** buffer) { |
| - void* file = DartUtils::OpenFile(filename, false); |
| +static void ReadPrecompiledSnapshotFile(const char* filename, |
| + const uint8_t** buffer) { |
| + const char* qualified_filename; |
| + if (strlen(precompiled_snapshot_directory) > 0) { |
| + intptr_t len = snprintf(NULL, 0, "%s/%s", |
| + precompiled_snapshot_directory, filename); |
| + char* concat = reinterpret_cast<char*>(alloca(len + 1)); |
|
Florian Schneider
2015/12/17 12:53:25
Same here. Maybe something like this:
char* conca
rmacnak
2015/12/17 19:20:51
Done.
|
| + snprintf(concat, len + 1, "%s/%s", |
| + precompiled_snapshot_directory, filename); |
| + qualified_filename = concat; |
| + } else { |
| + qualified_filename = filename; |
| + } |
| + |
| + void* file = DartUtils::OpenFile(qualified_filename, false); |
| if (file == NULL) { |
| ErrorExit(kErrorExitCode, |
| - "Error: Unable to open file %s for reading snapshot\n", filename); |
| + "Error: Unable to open file %s for reading snapshot\n", |
| + qualified_filename); |
| } |
| intptr_t len = -1; |
| DartUtils::ReadFile(buffer, &len, file); |
| if (*buffer == NULL || len == -1) { |
| ErrorExit(kErrorExitCode, |
| - "Error: Unable to read snapshot file %s\n", filename); |
| + "Error: Unable to read snapshot file %s\n", qualified_filename); |
| } |
| DartUtils::CloseFile(file); |
| } |
| @@ -1216,15 +1251,15 @@ bool RunMainIsolate(const char* script_name, |
| &instructions_buffer, |
| &instructions_size); |
| CHECK_RESULT(result); |
| - WriteSnapshotFile(kPrecompiledVmIsolateName, |
| - vm_isolate_buffer, |
| - vm_isolate_size); |
| - WriteSnapshotFile(kPrecompiledIsolateName, |
| - isolate_buffer, |
| - isolate_size); |
| - WriteSnapshotFile(kPrecompiledInstructionsName, |
| - instructions_buffer, |
| - instructions_size); |
| + WritePrecompiledSnapshotFile(kPrecompiledVmIsolateName, |
| + vm_isolate_buffer, |
| + vm_isolate_size); |
| + WritePrecompiledSnapshotFile(kPrecompiledIsolateName, |
| + isolate_buffer, |
| + isolate_size); |
| + WritePrecompiledSnapshotFile(kPrecompiledInstructionsName, |
| + instructions_buffer, |
| + instructions_size); |
| } else { |
| if (has_compile_all) { |
| result = Dart_CompileAll(); |
| @@ -1354,8 +1389,10 @@ void main(int argc, char** argv) { |
| if (has_run_precompiled_snapshot) { |
| instructions_snapshot = reinterpret_cast<const uint8_t*>( |
| LoadLibrarySymbol(kPrecompiledLibraryName, kPrecompiledSymbolName)); |
| - ReadSnapshotFile(kPrecompiledVmIsolateName, &vm_isolate_snapshot_buffer); |
| - ReadSnapshotFile(kPrecompiledIsolateName, &isolate_snapshot_buffer); |
| + ReadPrecompiledSnapshotFile(kPrecompiledVmIsolateName, |
| + &vm_isolate_snapshot_buffer); |
| + ReadPrecompiledSnapshotFile(kPrecompiledIsolateName, |
| + &isolate_snapshot_buffer); |
| } |
| // Initialize the Dart VM. |