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

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

Issue 55633002: GN: Add ability to specify a depfile for custom targets. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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 | Annotate | Revision Log
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_script_target_writer.h" 5 #include "tools/gn/ninja_script_target_writer.h"
6 6
7 #include "base/strings/string_util.h" 7 #include "base/strings/string_util.h"
8 #include "tools/gn/err.h" 8 #include "tools/gn/err.h"
9 #include "tools/gn/file_template.h" 9 #include "tools/gn/file_template.h"
10 #include "tools/gn/string_utils.h" 10 #include "tools/gn/string_utils.h"
(...skipping 18 matching lines...) Expand all
29 // Collects all output files for writing below. 29 // Collects all output files for writing below.
30 std::vector<OutputFile> output_files; 30 std::vector<OutputFile> output_files;
31 31
32 if (has_sources()) { 32 if (has_sources()) {
33 // Write separate build lines for each input source file. 33 // Write separate build lines for each input source file.
34 WriteSourceRules(custom_rule_name, implicit_deps, args_template, 34 WriteSourceRules(custom_rule_name, implicit_deps, args_template,
35 &output_files); 35 &output_files);
36 } else { 36 } else {
37 // No sources, write a rule that invokes the script once with the 37 // No sources, write a rule that invokes the script once with the
38 // outputs as outputs, and the data as inputs. 38 // outputs as outputs, and the data as inputs.
39 out_ << "build"; 39 out_ << "build ";
brettw 2013/11/04 05:22:14 I've been standardizing on the guy who's appending
koz (OOO until 15th September) 2013/11/06 07:29:11 Done.
40 if (target_->script_values().has_depfile())
41 WriteDepfile(SourceFile());
40 const Target::FileList& outputs = target_->script_values().outputs(); 42 const Target::FileList& outputs = target_->script_values().outputs();
41 for (size_t i = 0; i < outputs.size(); i++) { 43 for (size_t i = 0; i < outputs.size(); i++) {
42 OutputFile output_path( 44 OutputFile output_path(
43 RemovePrefix(outputs[i].value(), 45 RemovePrefix(outputs[i].value(),
44 settings_->build_settings()->build_dir().value())); 46 settings_->build_settings()->build_dir().value()));
45 output_files.push_back(output_path); 47 output_files.push_back(output_path);
46 out_ << " "; 48 out_ << " ";
47 path_output_.WriteFile(out_, output_path); 49 path_output_.WriteFile(out_, output_path);
48 } 50 }
49 out_ << ": " << custom_rule_name << implicit_deps << std::endl; 51 out_ << ": " << custom_rule_name << implicit_deps << std::endl;
52 if (target_->script_values().has_depfile()) {
53 out_ << " depfile = ";
54 WriteDepfile(SourceFile());
55 out_ << std::endl;
56 }
50 } 57 }
51 out_ << std::endl; 58 out_ << std::endl;
52 59
53 WriteStamp(output_files); 60 WriteStamp(output_files);
54 } 61 }
55 62
56 std::string NinjaScriptTargetWriter::WriteRuleDefinition( 63 std::string NinjaScriptTargetWriter::WriteRuleDefinition(
57 const FileTemplate& args_template) { 64 const FileTemplate& args_template) {
58 // Make a unique name for this rule. 65 // Make a unique name for this rule.
59 // 66 //
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 out_ << ": " << custom_rule_name << " "; 144 out_ << ": " << custom_rule_name << " ";
138 path_output_.WriteFile(out_, sources[i]); 145 path_output_.WriteFile(out_, sources[i]);
139 out_ << implicit_deps << std::endl; 146 out_ << implicit_deps << std::endl;
140 147
141 // Windows needs a unique ID for the response file. 148 // Windows needs a unique ID for the response file.
142 if (target_->settings()->IsWin()) 149 if (target_->settings()->IsWin())
143 out_ << " unique_name = " << i << std::endl; 150 out_ << " unique_name = " << i << std::endl;
144 151
145 if (args_template.has_substitutions()) 152 if (args_template.has_substitutions())
146 WriteArgsSubstitutions(sources[i], args_template); 153 WriteArgsSubstitutions(sources[i], args_template);
154
155 if (target_->script_values().has_depfile()) {
156 out_ << " depfile = ";
157 WriteDepfile(sources[i]);
158 out_ << std::endl;
159 }
147 } 160 }
148 } 161 }
149 162
150 void NinjaScriptTargetWriter::WriteStamp( 163 void NinjaScriptTargetWriter::WriteStamp(
151 const std::vector<OutputFile>& output_files) { 164 const std::vector<OutputFile>& output_files) {
152 out_ << "build "; 165 out_ << "build ";
153 path_output_.WriteFile(out_, helper_.GetTargetOutputFile(target_)); 166 path_output_.WriteFile(out_, helper_.GetTargetOutputFile(target_));
154 out_ << ": " 167 out_ << ": "
155 << helper_.GetRulePrefix(target_->settings()->toolchain()) 168 << helper_.GetRulePrefix(target_->settings()->toolchain())
156 << "stamp"; 169 << "stamp";
157 for (size_t i = 0; i < output_files.size(); i++) { 170 for (size_t i = 0; i < output_files.size(); i++) {
158 out_ << " "; 171 out_ << " ";
159 path_output_.WriteFile(out_, output_files[i]); 172 path_output_.WriteFile(out_, output_files[i]);
160 } 173 }
161 out_ << std::endl; 174 out_ << std::endl;
162 } 175 }
163 176
164 void NinjaScriptTargetWriter::WriteOutputFilesForBuildLine( 177 void NinjaScriptTargetWriter::WriteOutputFilesForBuildLine(
165 const FileTemplate& output_template, 178 const FileTemplate& output_template,
166 const SourceFile& source, 179 const SourceFile& source,
167 std::vector<OutputFile>* output_files) { 180 std::vector<OutputFile>* output_files) {
181 // If there is a depfile specified we need to list it as the first output as
182 // that is what ninja will expect the depfile to refer to itself as.
183 if (target_->script_values().has_depfile()) {
184 out_ << " ";
185 WriteDepfile(source);
186 }
168 std::vector<std::string> output_template_result; 187 std::vector<std::string> output_template_result;
169 output_template.ApplyString(source.value(), &output_template_result); 188 output_template.ApplyString(source.value(), &output_template_result);
170 for (size_t out_i = 0; out_i < output_template_result.size(); out_i++) { 189 for (size_t out_i = 0; out_i < output_template_result.size(); out_i++) {
171 OutputFile output_path(output_template_result[out_i]); 190 OutputFile output_path(output_template_result[out_i]);
172 output_files->push_back(output_path); 191 output_files->push_back(output_path);
173 out_ << " "; 192 out_ << " ";
174 path_output_.WriteFile(out_, output_path); 193 path_output_.WriteFile(out_, output_path);
175 } 194 }
176 } 195 }
196
197 void NinjaScriptTargetWriter::WriteDepfile(const SourceFile& source) {
198 std::vector<std::string> result;
199 GetDepfileTemplate().ApplyString(source.value(), &result);
200 path_output_.WriteFile(out_, OutputFile(result[0]));
201 }
202
203 FileTemplate NinjaScriptTargetWriter::GetDepfileTemplate() const {
204 std::vector<std::string> template_args;
205 std::string depfile_relative_to_build_dir =
206 RemovePrefix(target_->script_values().depfile().value(),
207 settings_->build_settings()->build_dir().value());
208 template_args.push_back(depfile_relative_to_build_dir);
209 return FileTemplate(template_args);
210 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698