OLD | NEW |
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/settings.h" | 9 #include "tools/gn/settings.h" |
10 #include "tools/gn/string_utils.h" | 10 #include "tools/gn/string_utils.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 | 24 |
25 void NinjaActionTargetWriter::Run() { | 25 void NinjaActionTargetWriter::Run() { |
26 std::string custom_rule_name = WriteRuleDefinition(); | 26 std::string custom_rule_name = WriteRuleDefinition(); |
27 | 27 |
28 // Collect our deps to pass as "extra hard dependencies" for input deps. This | 28 // Collect our deps to pass as "extra hard dependencies" for input deps. This |
29 // will force all of the action's dependencies to be completed before the | 29 // will force all of the action's dependencies to be completed before the |
30 // action is run. Usually, if an action has a dependency, it will be | 30 // action is run. Usually, if an action has a dependency, it will be |
31 // operating on the result of that previous step, so we need to be sure to | 31 // operating on the result of that previous step, so we need to be sure to |
32 // serialize these. | 32 // serialize these. |
33 std::vector<const Target*> extra_hard_deps; | 33 std::vector<const Target*> extra_hard_deps; |
34 for (size_t i = 0; i < target_->deps().size(); i++) | 34 for (DepsIterator iter(target_, DepsIterator::LINKED_ONLY); |
35 extra_hard_deps.push_back(target_->deps()[i].ptr); | 35 !iter.done(); iter.Advance()) |
| 36 extra_hard_deps.push_back(iter.target()); |
36 | 37 |
37 // 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 |
38 // 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 |
39 // 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 |
40 // build rule. This should probably be handled by WriteInputDepsStampAndGetDep | 41 // build rule. This should probably be handled by WriteInputDepsStampAndGetDep |
41 // 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 |
42 // how many times things would be duplicated). | 43 // how many times things would be duplicated). |
43 OutputFile input_dep = WriteInputDepsStampAndGetDep(extra_hard_deps); | 44 OutputFile input_dep = WriteInputDepsStampAndGetDep(extra_hard_deps); |
44 out_ << std::endl; | 45 out_ << std::endl; |
45 | 46 |
(...skipping 22 matching lines...) Expand all Loading... |
68 } | 69 } |
69 out_ << std::endl; | 70 out_ << std::endl; |
70 if (target_->action_values().has_depfile()) { | 71 if (target_->action_values().has_depfile()) { |
71 out_ << " depfile = "; | 72 out_ << " depfile = "; |
72 WriteDepfile(SourceFile()); | 73 WriteDepfile(SourceFile()); |
73 out_ << std::endl; | 74 out_ << std::endl; |
74 } | 75 } |
75 } | 76 } |
76 out_ << std::endl; | 77 out_ << std::endl; |
77 | 78 |
78 // Write the stamp, which also depends on all datadeps. These are needed at | 79 // Write the stamp, which also depends on all data deps. These are needed at |
79 // runtime and should be compiled when the action is, but don't need to be | 80 // runtime and should be compiled when the action is, but don't need to be |
80 // done before we run the action. | 81 // done before we run the action. |
81 std::vector<OutputFile> data_outs; | 82 std::vector<OutputFile> data_outs; |
82 for (size_t i = 0; i < target_->datadeps().size(); i++) | 83 for (size_t i = 0; i < target_->data_deps().size(); i++) |
83 data_outs.push_back(target_->datadeps()[i].ptr->dependency_output_file()); | 84 data_outs.push_back(target_->data_deps()[i].ptr->dependency_output_file()); |
84 WriteStampForTarget(output_files, data_outs); | 85 WriteStampForTarget(output_files, data_outs); |
85 } | 86 } |
86 | 87 |
87 std::string NinjaActionTargetWriter::WriteRuleDefinition() { | 88 std::string NinjaActionTargetWriter::WriteRuleDefinition() { |
88 // Make a unique name for this rule. | 89 // Make a unique name for this rule. |
89 // | 90 // |
90 // Use a unique name for the response file when there are multiple build | 91 // Use a unique name for the response file when there are multiple build |
91 // steps so that they don't stomp on each other. When there are no sources, | 92 // steps so that they don't stomp on each other. When there are no sources, |
92 // there will be only one invocation so we can use a simple name. | 93 // there will be only one invocation so we can use a simple name. |
93 std::string target_label = target_->label().GetUserVisibleName(true); | 94 std::string target_label = target_->label().GetUserVisibleName(true); |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 out_ << " "; | 208 out_ << " "; |
208 path_output_.WriteFile(out_, (*output_files)[i]); | 209 path_output_.WriteFile(out_, (*output_files)[i]); |
209 } | 210 } |
210 } | 211 } |
211 | 212 |
212 void NinjaActionTargetWriter::WriteDepfile(const SourceFile& source) { | 213 void NinjaActionTargetWriter::WriteDepfile(const SourceFile& source) { |
213 path_output_.WriteFile(out_, | 214 path_output_.WriteFile(out_, |
214 SubstitutionWriter::ApplyPatternToSourceAsOutputFile( | 215 SubstitutionWriter::ApplyPatternToSourceAsOutputFile( |
215 settings_, target_->action_values().depfile(), source)); | 216 settings_, target_->action_values().depfile(), source)); |
216 } | 217 } |
OLD | NEW |