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

Side by Side Diff: runtime/bin/gen_snapshot.cc

Issue 2966903003: [gen_snapshot] Escape spaces when generating depfiles. (Closed)
Patch Set: Created 3 years, 5 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 698 matching lines...) Expand 10 before | Expand all | Expand 10 after
709 if (DartUtils::IsDartBuiltinLibURL(url)) { 709 if (DartUtils::IsDartBuiltinLibURL(url)) {
710 return Builtin::kBuiltinLibrary; 710 return Builtin::kBuiltinLibrary;
711 } 711 }
712 if (DartUtils::IsDartIOLibURL(url)) { 712 if (DartUtils::IsDartIOLibURL(url)) {
713 return Builtin::kIOLibrary; 713 return Builtin::kIOLibrary;
714 } 714 }
715 return Builtin::kInvalidLibrary; 715 return Builtin::kInvalidLibrary;
716 } 716 }
717 717
718 718
719 static bool WriteDependencies(const char* target, 719 // Generates a depfile like gcc -M -MF. Must be consumable by Ninja.
720 File* file, 720 class DependenciesFileWriter : public ValueObject {
721 MallocGrowableArray<char*>* dependencies) { 721 public:
722 bool success = true; 722 DependenciesFileWriter() : dependencies_(NULL), file_(NULL), success_(true) {}
723 success &= file->Print("%s: ", target);
724 723
725 if (snapshot_kind == kScript) { 724 void WriteDependencies(MallocGrowableArray<char*>* dependencies) {
726 if (vm_snapshot_data_filename != NULL) { 725 dependencies_ = dependencies;
727 success &= file->Print("%s ", vm_snapshot_data_filename);
728 }
729 if (vm_snapshot_instructions_filename != NULL) {
730 success &= file->Print("%s ", vm_snapshot_instructions_filename);
731 }
732 if (isolate_snapshot_data_filename != NULL) {
733 success &= file->Print("%s ", isolate_snapshot_data_filename);
734 }
735 if (isolate_snapshot_instructions_filename != NULL) {
736 success &= file->Print("%s ", isolate_snapshot_instructions_filename);
737 }
738 }
739 726
740 for (intptr_t i = 0; i < dependencies->length(); i++) { 727 file_ = File::Open(dependencies_filename, File::kWriteTruncate);
741 success &= file->Print("%s ", dependencies->At(i)); 728 if (file_ == NULL) {
742 }
743
744 success &= file->Print("\n");
745 return success;
746 }
747
748
749 static void CreateAndWriteDependenciesFile() {
750 IsolateData* isolate_data =
751 reinterpret_cast<IsolateData*>(Dart_CurrentIsolateData());
752 MallocGrowableArray<char*>* dependencies = isolate_data->dependencies();
753 if (dependencies == NULL) {
754 return;
755 }
756
757 Loader::ResolveDependenciesAsFilePaths();
758
759 ASSERT((dependencies_filename != NULL) || print_dependencies);
760 if (dependencies_filename != NULL) {
761 bool success = true;
762 File* file = File::Open(dependencies_filename, File::kWriteTruncate);
763 if (file == NULL) {
764 Log::PrintErr("Error: Unable to open dependencies file: %s\n\n", 729 Log::PrintErr("Error: Unable to open dependencies file: %s\n\n",
765 dependencies_filename); 730 dependencies_filename);
766 exit(kErrorExitCode); 731 exit(kErrorExitCode);
767 } 732 }
768 733
769 // Write dependencies for one of the output files. 734 // Write dependencies for one of the output files.
770 // TODO(https://github.com/ninja-build/ninja/issues/1184): Do this for all 735 // TODO(https://github.com/ninja-build/ninja/issues/1184): Do this for all
771 // output files. 736 // output files.
772 switch (snapshot_kind) { 737 switch (snapshot_kind) {
773 case kCore: 738 case kCore:
774 success &= 739 WriteDependenciesWithTarget(vm_snapshot_data_filename);
775 WriteDependencies(vm_snapshot_data_filename, file, dependencies); 740 // WriteDependenciesWithTarget(isolate_snapshot_data_filename);
776 // success &= WriteDependencies(isolate_snapshot_data_filename, file,
777 // dependencies);
778 break; 741 break;
779 case kScript: 742 case kScript:
780 success &= 743 WriteDependenciesWithTarget(script_snapshot_filename);
781 WriteDependencies(script_snapshot_filename, file, dependencies);
782 break; 744 break;
783 case kAppAOTAssembly: 745 case kAppAOTAssembly:
784 success &= WriteDependencies(assembly_filename, file, dependencies); 746 WriteDependenciesWithTarget(assembly_filename);
785 break; 747 break;
786 case kCoreJIT: 748 case kCoreJIT:
787 case kAppAOTBlobs: 749 case kAppAOTBlobs:
788 success &= 750 WriteDependenciesWithTarget(vm_snapshot_data_filename);
789 WriteDependencies(vm_snapshot_data_filename, file, dependencies); 751 // WriteDependenciesWithTarget(vm_snapshot_instructions_filename);
790 // success &= WriteDependencies(vm_snapshot_instructions_filename, file, 752 // WriteDependenciesWithTarget(isolate_snapshot_data_filename);
791 // dependencies); 753 // WriteDependenciesWithTarget(isolate_snapshot_instructions_filename);
792 // success &= WriteDependencies(isolate_snapshot_data_filename, file,
793 // dependencies);
794 // success &= WriteDependencies(isolate_snapshot_instructions_filename,
795 // file, dependencies);
796 break; 754 break;
797 } 755 }
798 756
799 if (!success) { 757 if (!success_) {
800 Log::PrintErr("Error: Unable to write dependencies file: %s\n\n", 758 Log::PrintErr("Error: Unable to write dependencies file: %s\n\n",
801 dependencies_filename); 759 dependencies_filename);
802 exit(kErrorExitCode); 760 exit(kErrorExitCode);
803 } 761 }
804 file->Release(); 762 file_->Release();
763 }
764
765 private:
766 void WriteDependenciesWithTarget(const char* target) {
767 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
768 Write(": ");
769
770 if (snapshot_kind == kScript) {
771 if (vm_snapshot_data_filename != NULL) {
772 WritePath(vm_snapshot_data_filename);
773 }
774 if (vm_snapshot_instructions_filename != NULL) {
775 WritePath(vm_snapshot_instructions_filename);
776 }
777 if (isolate_snapshot_data_filename != NULL) {
778 WritePath(isolate_snapshot_data_filename);
779 }
780 if (isolate_snapshot_instructions_filename != NULL) {
781 WritePath(isolate_snapshot_instructions_filename);
782 }
783 }
784
785 for (intptr_t i = 0; i < dependencies_->length(); i++) {
786 WritePath(dependencies_->At(i));
787 }
788
789 Write("\n");
790 }
791
792 char* EscapePath(const char* path) {
793 char* escaped_path = reinterpret_cast<char*>(malloc(strlen(path) * 2 + 1));
794 const char* read_cursor = path;
795 char* write_cursor = escaped_path;
796 while (*read_cursor != '\0') {
797 if ((*read_cursor == ' ') || (*read_cursor == '\\')) {
798 *write_cursor++ = '\\';
799 }
800 *write_cursor++ = *read_cursor++;
801 }
802 *write_cursor = '\0';
803 return escaped_path;
804 }
805
806 void WritePath(const char* path) {
807 char* escaped_path = EscapePath(path);
808 success_ &= file_->Print("%s ", escaped_path);
809 free(escaped_path);
810 }
811
812 void Write(const char* string) { success_ &= file_->Print("%s", string); }
813
814 MallocGrowableArray<char*>* dependencies_;
815 File* file_;
816 bool success_;
817 };
818
819
820 static void CreateAndWriteDependenciesFile() {
821 IsolateData* isolate_data =
822 reinterpret_cast<IsolateData*>(Dart_CurrentIsolateData());
823 MallocGrowableArray<char*>* dependencies = isolate_data->dependencies();
824 if (dependencies == NULL) {
825 return;
826 }
827
828 Loader::ResolveDependenciesAsFilePaths();
829
830 ASSERT((dependencies_filename != NULL) || print_dependencies);
831 if (dependencies_filename != NULL) {
832 DependenciesFileWriter writer;
833 writer.WriteDependencies(dependencies);
805 } 834 }
806 835
807 if (print_dependencies) { 836 if (print_dependencies) {
808 Log::Print("%s\n", vm_snapshot_data_filename); 837 Log::Print("%s\n", vm_snapshot_data_filename);
809 if (snapshot_kind == kScript) { 838 if (snapshot_kind == kScript) {
810 if (vm_snapshot_data_filename != NULL) { 839 if (vm_snapshot_data_filename != NULL) {
811 Log::Print("%s\n", vm_snapshot_data_filename); 840 Log::Print("%s\n", vm_snapshot_data_filename);
812 } 841 }
813 if (vm_snapshot_instructions_filename != NULL) { 842 if (vm_snapshot_instructions_filename != NULL) {
814 Log::Print("%s\n", vm_snapshot_instructions_filename); 843 Log::Print("%s\n", vm_snapshot_instructions_filename);
(...skipping 1053 matching lines...) Expand 10 before | Expand all | Expand 10 after
1868 delete mapped_isolate_snapshot_instructions; 1897 delete mapped_isolate_snapshot_instructions;
1869 return 0; 1898 return 0;
1870 } 1899 }
1871 1900
1872 } // namespace bin 1901 } // namespace bin
1873 } // namespace dart 1902 } // namespace dart
1874 1903
1875 int main(int argc, char** argv) { 1904 int main(int argc, char** argv) {
1876 return dart::bin::main(argc, argv); 1905 return dart::bin::main(argc, argv);
1877 } 1906 }
OLDNEW
« 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