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

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

Issue 265703008: Support deps for actions in GN. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « tools/gn/functions_target.cc ('k') | tools/gn/ninja_action_target_writer_unittest.cc » ('j') | 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_action_target_writer.h" 5 #include "tools/gn/ninja_action_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"
11 #include "tools/gn/target.h" 11 #include "tools/gn/target.h"
12 12
13 NinjaActionTargetWriter::NinjaActionTargetWriter(const Target* target, 13 NinjaActionTargetWriter::NinjaActionTargetWriter(const Target* target,
14 const Toolchain* toolchain, 14 const Toolchain* toolchain,
15 std::ostream& out) 15 std::ostream& out)
16 : NinjaTargetWriter(target, toolchain, out), 16 : NinjaTargetWriter(target, toolchain, out),
17 path_output_no_escaping_( 17 path_output_no_escaping_(
18 target->settings()->build_settings()->build_dir(), 18 target->settings()->build_settings()->build_dir(),
19 ESCAPE_NONE, false) { 19 ESCAPE_NONE, false) {
20 } 20 }
21 21
22 NinjaActionTargetWriter::~NinjaActionTargetWriter() { 22 NinjaActionTargetWriter::~NinjaActionTargetWriter() {
23 } 23 }
24 24
25 void NinjaActionTargetWriter::Run() { 25 void NinjaActionTargetWriter::Run() {
26 FileTemplate args_template(target_->action_values().args()); 26 FileTemplate args_template(target_->action_values().args());
27 std::string custom_rule_name = WriteRuleDefinition(args_template); 27 std::string custom_rule_name = WriteRuleDefinition(args_template);
28
29 // Collect our deps to pass as "extra hard dependencies" for input deps. This
30 // will force all of the action's dependencies to be completed before the
31 // action is run. Usually, if an action has a dependency, it will be
32 // operating on the result of that previous step, so we need to be sure to
33 // serialize these.
34 std::vector<const Target*> extra_hard_deps;
35 for (size_t i = 0; i < target_->deps().size(); i++)
36 extra_hard_deps.push_back(target_->deps()[i].ptr);
37
28 // For ACTIONs this is a bit inefficient since it creates an input dep 38 // For ACTIONs this is a bit inefficient since it creates an input dep
29 // stamp file even though we're only going to use it once. It would save a 39 // stamp file even though we're only going to use it once. It would save a
30 // build step to skip this and write the order-only deps directly on the 40 // build step to skip this and write the order-only deps directly on the
31 // build rule. This should probably be handled by WriteInputDepsStampAndGetDep 41 // build rule. This should probably be handled by WriteInputDepsStampAndGetDep
32 // automatically if we supply a count of sources (so it can optimize based on 42 // automatically if we supply a count of sources (so it can optimize based on
33 // how many times things would be duplicated). 43 // how many times things would be duplicated).
34 std::string implicit_deps = WriteInputDepsStampAndGetDep(); 44 std::string implicit_deps = WriteInputDepsStampAndGetDep(extra_hard_deps);
35 out_ << std::endl; 45 out_ << std::endl;
36 46
37 // Collects all output files for writing below. 47 // Collects all output files for writing below.
38 std::vector<OutputFile> output_files; 48 std::vector<OutputFile> output_files;
39 49
40 if (target_->output_type() == Target::ACTION_FOREACH) { 50 if (target_->output_type() == Target::ACTION_FOREACH) {
41 // Write separate build lines for each input source file. 51 // Write separate build lines for each input source file.
42 WriteSourceRules(custom_rule_name, implicit_deps, args_template, 52 WriteSourceRules(custom_rule_name, implicit_deps, args_template,
43 &output_files); 53 &output_files);
44 } else { 54 } else {
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 } 182 }
173 } 183 }
174 184
175 void NinjaActionTargetWriter::WriteStamp( 185 void NinjaActionTargetWriter::WriteStamp(
176 const std::vector<OutputFile>& output_files) { 186 const std::vector<OutputFile>& output_files) {
177 out_ << "build "; 187 out_ << "build ";
178 path_output_.WriteFile(out_, helper_.GetTargetOutputFile(target_)); 188 path_output_.WriteFile(out_, helper_.GetTargetOutputFile(target_));
179 out_ << ": " 189 out_ << ": "
180 << helper_.GetRulePrefix(target_->settings()) 190 << helper_.GetRulePrefix(target_->settings())
181 << "stamp"; 191 << "stamp";
192
193 // The action stamp depends on all output files from running the action.
182 for (size_t i = 0; i < output_files.size(); i++) { 194 for (size_t i = 0; i < output_files.size(); i++) {
183 out_ << " "; 195 out_ << " ";
184 path_output_.WriteFile(out_, output_files[i]); 196 path_output_.WriteFile(out_, output_files[i]);
185 } 197 }
198
199 // It also depends on all datadeps. These are needed at runtime and should
200 // be compiled when the action is, but don't need to be done before we run
201 // the action.
202 for (size_t i = 0; i < target_->datadeps().size(); i++) {
203 out_ << " ";
204 path_output_.WriteFile(out_,
205 helper_.GetTargetOutputFile(target_->datadeps()[i].ptr));
206 }
207
186 out_ << std::endl; 208 out_ << std::endl;
187 } 209 }
188 210
189 void NinjaActionTargetWriter::WriteOutputFilesForBuildLine( 211 void NinjaActionTargetWriter::WriteOutputFilesForBuildLine(
190 const FileTemplate& output_template, 212 const FileTemplate& output_template,
191 const SourceFile& source, 213 const SourceFile& source,
192 std::vector<OutputFile>* output_files) { 214 std::vector<OutputFile>* output_files) {
193 // If there is a depfile specified we need to list it as the first output as 215 // If there is a depfile specified we need to list it as the first output as
194 // that is what ninja will expect the depfile to refer to itself as. 216 // that is what ninja will expect the depfile to refer to itself as.
195 if (target_->action_values().has_depfile()) { 217 if (target_->action_values().has_depfile()) {
(...skipping 17 matching lines...) Expand all
213 } 235 }
214 236
215 FileTemplate NinjaActionTargetWriter::GetDepfileTemplate() const { 237 FileTemplate NinjaActionTargetWriter::GetDepfileTemplate() const {
216 std::vector<std::string> template_args; 238 std::vector<std::string> template_args;
217 std::string depfile_relative_to_build_dir = 239 std::string depfile_relative_to_build_dir =
218 RemovePrefix(target_->action_values().depfile().value(), 240 RemovePrefix(target_->action_values().depfile().value(),
219 settings_->build_settings()->build_dir().value()); 241 settings_->build_settings()->build_dir().value());
220 template_args.push_back(depfile_relative_to_build_dir); 242 template_args.push_back(depfile_relative_to_build_dir);
221 return FileTemplate(template_args); 243 return FileTemplate(template_args);
222 } 244 }
OLDNEW
« no previous file with comments | « tools/gn/functions_target.cc ('k') | tools/gn/ninja_action_target_writer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698