| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 // Generate a snapshot file after loading all the scripts specified on the | 5 // Generate a snapshot file after loading all the scripts specified on the |
| 6 // command line. | 6 // command line. |
| 7 | 7 |
| 8 #include <stdio.h> | 8 #include <stdio.h> |
| 9 #include <stdlib.h> | 9 #include <stdlib.h> |
| 10 #include <string.h> | 10 #include <string.h> |
| (...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 439 "Obfuscation can only be enabled when building AOT snapshot.\n\n"); | 439 "Obfuscation can only be enabled when building AOT snapshot.\n\n"); |
| 440 return -1; | 440 return -1; |
| 441 } | 441 } |
| 442 | 442 |
| 443 return 0; | 443 return 0; |
| 444 } | 444 } |
| 445 | 445 |
| 446 static void WriteFile(const char* filename, | 446 static void WriteFile(const char* filename, |
| 447 const uint8_t* buffer, | 447 const uint8_t* buffer, |
| 448 const intptr_t size) { | 448 const intptr_t size) { |
| 449 File* file = File::Open(filename, File::kWriteTruncate); | 449 File* file = File::Open(NULL, filename, File::kWriteTruncate); |
| 450 if (file == NULL) { | 450 if (file == NULL) { |
| 451 Log::PrintErr("Error: Unable to write snapshot file: %s\n\n", filename); | 451 Log::PrintErr("Error: Unable to write snapshot file: %s\n\n", filename); |
| 452 Dart_ExitScope(); | 452 Dart_ExitScope(); |
| 453 Dart_ShutdownIsolate(); | 453 Dart_ShutdownIsolate(); |
| 454 exit(kErrorExitCode); | 454 exit(kErrorExitCode); |
| 455 } | 455 } |
| 456 if (!file->WriteFully(buffer, size)) { | 456 if (!file->WriteFully(buffer, size)) { |
| 457 Log::PrintErr("Error: Unable to write snapshot file: %s\n\n", filename); | 457 Log::PrintErr("Error: Unable to write snapshot file: %s\n\n", filename); |
| 458 Dart_ExitScope(); | 458 Dart_ExitScope(); |
| 459 Dart_ShutdownIsolate(); | 459 Dart_ShutdownIsolate(); |
| 460 exit(kErrorExitCode); | 460 exit(kErrorExitCode); |
| 461 } | 461 } |
| 462 file->Release(); | 462 file->Release(); |
| 463 } | 463 } |
| 464 | 464 |
| 465 static void ReadFile(const char* filename, uint8_t** buffer, intptr_t* size) { | 465 static void ReadFile(const char* filename, uint8_t** buffer, intptr_t* size) { |
| 466 File* file = File::Open(filename, File::kRead); | 466 File* file = File::Open(NULL, filename, File::kRead); |
| 467 if (file == NULL) { | 467 if (file == NULL) { |
| 468 Log::PrintErr("Unable to open file %s\n", filename); | 468 Log::PrintErr("Unable to open file %s\n", filename); |
| 469 Dart_ExitScope(); | 469 Dart_ExitScope(); |
| 470 Dart_ShutdownIsolate(); | 470 Dart_ShutdownIsolate(); |
| 471 exit(kErrorExitCode); | 471 exit(kErrorExitCode); |
| 472 } | 472 } |
| 473 *size = file->Length(); | 473 *size = file->Length(); |
| 474 *buffer = reinterpret_cast<uint8_t*>(malloc(*size)); | 474 *buffer = reinterpret_cast<uint8_t*>(malloc(*size)); |
| 475 if (!file->ReadFully(*buffer, *size)) { | 475 if (!file->ReadFully(*buffer, *size)) { |
| 476 Log::PrintErr("Unable to read file %s\n", filename); | 476 Log::PrintErr("Unable to read file %s\n", filename); |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 605 } | 605 } |
| 606 | 606 |
| 607 // Generates a depfile like gcc -M -MF. Must be consumable by Ninja. | 607 // Generates a depfile like gcc -M -MF. Must be consumable by Ninja. |
| 608 class DependenciesFileWriter : public ValueObject { | 608 class DependenciesFileWriter : public ValueObject { |
| 609 public: | 609 public: |
| 610 DependenciesFileWriter() : dependencies_(NULL), file_(NULL), success_(true) {} | 610 DependenciesFileWriter() : dependencies_(NULL), file_(NULL), success_(true) {} |
| 611 | 611 |
| 612 void WriteDependencies(MallocGrowableArray<char*>* dependencies) { | 612 void WriteDependencies(MallocGrowableArray<char*>* dependencies) { |
| 613 dependencies_ = dependencies; | 613 dependencies_ = dependencies; |
| 614 | 614 |
| 615 file_ = File::Open(dependencies_filename, File::kWriteTruncate); | 615 file_ = File::Open(NULL, dependencies_filename, File::kWriteTruncate); |
| 616 if (file_ == NULL) { | 616 if (file_ == NULL) { |
| 617 Log::PrintErr("Error: Unable to open dependencies file: %s\n\n", | 617 Log::PrintErr("Error: Unable to open dependencies file: %s\n\n", |
| 618 dependencies_filename); | 618 dependencies_filename); |
| 619 exit(kErrorExitCode); | 619 exit(kErrorExitCode); |
| 620 } | 620 } |
| 621 | 621 |
| 622 // Write dependencies for one of the output files. | 622 // Write dependencies for one of the output files. |
| 623 // TODO(https://github.com/ninja-build/ninja/issues/1184): Do this for all | 623 // TODO(https://github.com/ninja-build/ninja/issues/1184): Do this for all |
| 624 // output files. | 624 // output files. |
| 625 switch (snapshot_kind) { | 625 switch (snapshot_kind) { |
| (...skipping 856 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1482 return NULL; | 1482 return NULL; |
| 1483 } | 1483 } |
| 1484 Dart_ExitScope(); | 1484 Dart_ExitScope(); |
| 1485 Dart_ExitIsolate(); | 1485 Dart_ExitIsolate(); |
| 1486 return isolate; | 1486 return isolate; |
| 1487 } | 1487 } |
| 1488 | 1488 |
| 1489 static MappedMemory* MapFile(const char* filename, | 1489 static MappedMemory* MapFile(const char* filename, |
| 1490 File::MapType type, | 1490 File::MapType type, |
| 1491 const uint8_t** buffer) { | 1491 const uint8_t** buffer) { |
| 1492 File* file = File::Open(filename, File::kRead); | 1492 File* file = File::Open(NULL, filename, File::kRead); |
| 1493 if (file == NULL) { | 1493 if (file == NULL) { |
| 1494 Log::PrintErr("Failed to open: %s\n", filename); | 1494 Log::PrintErr("Failed to open: %s\n", filename); |
| 1495 exit(kErrorExitCode); | 1495 exit(kErrorExitCode); |
| 1496 } | 1496 } |
| 1497 intptr_t length = file->Length(); | 1497 intptr_t length = file->Length(); |
| 1498 if (length == 0) { | 1498 if (length == 0) { |
| 1499 // Can't map an empty file. | 1499 // Can't map an empty file. |
| 1500 *buffer = NULL; | 1500 *buffer = NULL; |
| 1501 return NULL; | 1501 return NULL; |
| 1502 } | 1502 } |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1789 delete mapped_isolate_snapshot_instructions; | 1789 delete mapped_isolate_snapshot_instructions; |
| 1790 return 0; | 1790 return 0; |
| 1791 } | 1791 } |
| 1792 | 1792 |
| 1793 } // namespace bin | 1793 } // namespace bin |
| 1794 } // namespace dart | 1794 } // namespace dart |
| 1795 | 1795 |
| 1796 int main(int argc, char** argv) { | 1796 int main(int argc, char** argv) { |
| 1797 return dart::bin::main(argc, argv); | 1797 return dart::bin::main(argc, argv); |
| 1798 } | 1798 } |
| OLD | NEW |