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

Side by Side Diff: tools/gn/ninja_target_writer.cc

Issue 1420043004: [GN] Allow spaces in output names and other substitutions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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 | « tools/gn/ninja_target_writer.h ('k') | 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 Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "tools/gn/ninja_target_writer.h" 5 #include "tools/gn/ninja_target_writer.h"
6 6
7 #include <sstream> 7 #include <sstream>
8 8
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
11 #include "tools/gn/err.h" 11 #include "tools/gn/err.h"
12 #include "tools/gn/escape.h"
12 #include "tools/gn/filesystem_utils.h" 13 #include "tools/gn/filesystem_utils.h"
13 #include "tools/gn/ninja_action_target_writer.h" 14 #include "tools/gn/ninja_action_target_writer.h"
14 #include "tools/gn/ninja_binary_target_writer.h" 15 #include "tools/gn/ninja_binary_target_writer.h"
15 #include "tools/gn/ninja_copy_target_writer.h" 16 #include "tools/gn/ninja_copy_target_writer.h"
16 #include "tools/gn/ninja_group_target_writer.h" 17 #include "tools/gn/ninja_group_target_writer.h"
17 #include "tools/gn/ninja_utils.h" 18 #include "tools/gn/ninja_utils.h"
18 #include "tools/gn/output_file.h" 19 #include "tools/gn/output_file.h"
19 #include "tools/gn/scheduler.h" 20 #include "tools/gn/scheduler.h"
20 #include "tools/gn/string_utils.h" 21 #include "tools/gn/string_utils.h"
21 #include "tools/gn/substitution_type.h"
22 #include "tools/gn/substitution_writer.h" 22 #include "tools/gn/substitution_writer.h"
23 #include "tools/gn/target.h" 23 #include "tools/gn/target.h"
24 #include "tools/gn/trace.h" 24 #include "tools/gn/trace.h"
25 25
26 NinjaTargetWriter::NinjaTargetWriter(const Target* target, 26 NinjaTargetWriter::NinjaTargetWriter(const Target* target,
27 std::ostream& out) 27 std::ostream& out)
28 : settings_(target->settings()), 28 : settings_(target->settings()),
29 target_(target), 29 target_(target),
30 out_(out), 30 out_(out),
31 path_output_(settings_->build_settings()->build_dir(), 31 path_output_(settings_->build_settings()->build_dir(),
(...skipping 13 matching lines...) Expand all
45 trace.SetToolchain(settings->toolchain_label()); 45 trace.SetToolchain(settings->toolchain_label());
46 46
47 base::FilePath ninja_file(settings->build_settings()->GetFullPath( 47 base::FilePath ninja_file(settings->build_settings()->GetFullPath(
48 GetNinjaFileForTarget(target))); 48 GetNinjaFileForTarget(target)));
49 49
50 if (g_scheduler->verbose_logging()) 50 if (g_scheduler->verbose_logging())
51 g_scheduler->Log("Writing", FilePathToUTF8(ninja_file)); 51 g_scheduler->Log("Writing", FilePathToUTF8(ninja_file));
52 52
53 base::CreateDirectory(ninja_file.DirName()); 53 base::CreateDirectory(ninja_file.DirName());
54 54
55 // It's rediculously faster to write to a string and then write that to 55 // It's ridiculously faster to write to a string and then write that to
56 // disk in one operation than to use an fstream here. 56 // disk in one operation than to use an fstream here.
57 std::stringstream file; 57 std::stringstream file;
58 58
59 // Call out to the correct sub-type of writer. 59 // Call out to the correct sub-type of writer.
60 if (target->output_type() == Target::COPY_FILES) { 60 if (target->output_type() == Target::COPY_FILES) {
61 NinjaCopyTargetWriter writer(target, file); 61 NinjaCopyTargetWriter writer(target, file);
62 writer.Run(); 62 writer.Run();
63 } else if (target->output_type() == Target::ACTION || 63 } else if (target->output_type() == Target::ACTION ||
64 target->output_type() == Target::ACTION_FOREACH) { 64 target->output_type() == Target::ACTION_FOREACH) {
65 NinjaActionTargetWriter writer(target, file); 65 NinjaActionTargetWriter writer(target, file);
(...skipping 10 matching lines...) Expand all
76 writer.Run(); 76 writer.Run();
77 } else { 77 } else {
78 CHECK(0) << "Output type of target not handled."; 78 CHECK(0) << "Output type of target not handled.";
79 } 79 }
80 80
81 std::string contents = file.str(); 81 std::string contents = file.str();
82 base::WriteFile(ninja_file, contents.c_str(), 82 base::WriteFile(ninja_file, contents.c_str(),
83 static_cast<int>(contents.size())); 83 static_cast<int>(contents.size()));
84 } 84 }
85 85
86 void NinjaTargetWriter::WriteEscapedSubstitution(SubstitutionType type) {
87 EscapeOptions opts;
88 opts.mode = ESCAPE_NINJA;
89
90 out_ << kSubstitutionNinjaNames[type] << " = ";
91 EscapeStringToStream(out_,
92 SubstitutionWriter::GetTargetSubstitution(target_, type),
93 opts);
94 out_ << std::endl;
95 }
96
86 void NinjaTargetWriter::WriteSharedVars(const SubstitutionBits& bits) { 97 void NinjaTargetWriter::WriteSharedVars(const SubstitutionBits& bits) {
87 bool written_anything = false; 98 bool written_anything = false;
88 99
89 // Target label. 100 // Target label.
90 if (bits.used[SUBSTITUTION_LABEL]) { 101 if (bits.used[SUBSTITUTION_LABEL]) {
91 out_ << kSubstitutionNinjaNames[SUBSTITUTION_LABEL] << " = " 102 WriteEscapedSubstitution(SUBSTITUTION_LABEL);
92 << SubstitutionWriter::GetTargetSubstitution(
93 target_, SUBSTITUTION_LABEL)
94 << std::endl;
95 written_anything = true; 103 written_anything = true;
96 } 104 }
97 105
98 // Root gen dir. 106 // Root gen dir.
99 if (bits.used[SUBSTITUTION_ROOT_GEN_DIR]) { 107 if (bits.used[SUBSTITUTION_ROOT_GEN_DIR]) {
100 out_ << kSubstitutionNinjaNames[SUBSTITUTION_ROOT_GEN_DIR] << " = " 108 WriteEscapedSubstitution(SUBSTITUTION_ROOT_GEN_DIR);
101 << SubstitutionWriter::GetTargetSubstitution(
102 target_, SUBSTITUTION_ROOT_GEN_DIR)
103 << std::endl;
104 written_anything = true; 109 written_anything = true;
105 } 110 }
106 111
107 // Root out dir. 112 // Root out dir.
108 if (bits.used[SUBSTITUTION_ROOT_OUT_DIR]) { 113 if (bits.used[SUBSTITUTION_ROOT_OUT_DIR]) {
109 out_ << kSubstitutionNinjaNames[SUBSTITUTION_ROOT_OUT_DIR] << " = " 114 WriteEscapedSubstitution(SUBSTITUTION_ROOT_OUT_DIR);
110 << SubstitutionWriter::GetTargetSubstitution(
111 target_, SUBSTITUTION_ROOT_OUT_DIR)
112 << std::endl;
113 written_anything = true; 115 written_anything = true;
114 } 116 }
115 117
116 // Target gen dir. 118 // Target gen dir.
117 if (bits.used[SUBSTITUTION_TARGET_GEN_DIR]) { 119 if (bits.used[SUBSTITUTION_TARGET_GEN_DIR]) {
118 out_ << kSubstitutionNinjaNames[SUBSTITUTION_TARGET_GEN_DIR] << " = " 120 WriteEscapedSubstitution(SUBSTITUTION_TARGET_GEN_DIR);
119 << SubstitutionWriter::GetTargetSubstitution(
120 target_, SUBSTITUTION_TARGET_GEN_DIR)
121 << std::endl;
122 written_anything = true; 121 written_anything = true;
123 } 122 }
124 123
125 // Target out dir. 124 // Target out dir.
126 if (bits.used[SUBSTITUTION_TARGET_OUT_DIR]) { 125 if (bits.used[SUBSTITUTION_TARGET_OUT_DIR]) {
127 out_ << kSubstitutionNinjaNames[SUBSTITUTION_TARGET_OUT_DIR] << " = " 126 WriteEscapedSubstitution(SUBSTITUTION_TARGET_OUT_DIR);
128 << SubstitutionWriter::GetTargetSubstitution(
129 target_, SUBSTITUTION_TARGET_OUT_DIR)
130 << std::endl;
131 written_anything = true; 127 written_anything = true;
132 } 128 }
133 129
134 // Target output name. 130 // Target output name.
135 if (bits.used[SUBSTITUTION_TARGET_OUTPUT_NAME]) { 131 if (bits.used[SUBSTITUTION_TARGET_OUTPUT_NAME]) {
136 out_ << kSubstitutionNinjaNames[SUBSTITUTION_TARGET_OUTPUT_NAME] << " = " 132 WriteEscapedSubstitution(SUBSTITUTION_TARGET_OUTPUT_NAME);
137 << SubstitutionWriter::GetTargetSubstitution(
138 target_, SUBSTITUTION_TARGET_OUTPUT_NAME)
139 << std::endl;
140 written_anything = true; 133 written_anything = true;
141 } 134 }
142 135
143 // If we wrote any vars, separate them from the rest of the file that follows 136 // If we wrote any vars, separate them from the rest of the file that follows
144 // with a blank line. 137 // with a blank line.
145 if (written_anything) 138 if (written_anything)
146 out_ << std::endl; 139 out_ << std::endl;
147 } 140 }
148 141
149 OutputFile NinjaTargetWriter::WriteInputDepsStampAndGetDep( 142 OutputFile NinjaTargetWriter::WriteInputDepsStampAndGetDep(
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 << GetNinjaRulePrefixForToolchain(settings_) 249 << GetNinjaRulePrefixForToolchain(settings_)
257 << Toolchain::ToolTypeToName(Toolchain::TYPE_STAMP); 250 << Toolchain::ToolTypeToName(Toolchain::TYPE_STAMP);
258 path_output_.WriteFiles(out_, files); 251 path_output_.WriteFiles(out_, files);
259 252
260 if (!order_only_deps.empty()) { 253 if (!order_only_deps.empty()) {
261 out_ << " ||"; 254 out_ << " ||";
262 path_output_.WriteFiles(out_, order_only_deps); 255 path_output_.WriteFiles(out_, order_only_deps);
263 } 256 }
264 out_ << std::endl; 257 out_ << std::endl;
265 } 258 }
OLDNEW
« no previous file with comments | « tools/gn/ninja_target_writer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698