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

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

Issue 505353002: Reduce input dependencies in GN. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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 | « tools/gn/ninja_action_target_writer.h ('k') | tools/gn/ninja_binary_target_writer.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/settings.h" 9 #include "tools/gn/settings.h"
10 #include "tools/gn/string_utils.h" 10 #include "tools/gn/string_utils.h"
(...skipping 22 matching lines...) Expand all
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 (size_t i = 0; i < target_->deps().size(); i++)
35 extra_hard_deps.push_back(target_->deps()[i].ptr); 35 extra_hard_deps.push_back(target_->deps()[i].ptr);
36 36
37 // For ACTIONs this is a bit inefficient since it creates an input dep 37 // 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 38 // 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 39 // build step to skip this and write the order-only deps directly on the
40 // build rule. This should probably be handled by WriteInputDepsStampAndGetDep 40 // build rule. This should probably be handled by WriteInputDepsStampAndGetDep
41 // automatically if we supply a count of sources (so it can optimize based on 41 // automatically if we supply a count of sources (so it can optimize based on
42 // how many times things would be duplicated). 42 // how many times things would be duplicated).
43 std::string implicit_deps = WriteInputDepsStampAndGetDep(extra_hard_deps); 43 OutputFile input_dep = WriteInputDepsStampAndGetDep(extra_hard_deps);
44 out_ << std::endl; 44 out_ << std::endl;
45 45
46 // Collects all output files for writing below. 46 // Collects all output files for writing below.
47 std::vector<OutputFile> output_files; 47 std::vector<OutputFile> output_files;
48 48
49 if (target_->output_type() == Target::ACTION_FOREACH) { 49 if (target_->output_type() == Target::ACTION_FOREACH) {
50 // Write separate build lines for each input source file. 50 // Write separate build lines for each input source file.
51 WriteSourceRules(custom_rule_name, implicit_deps, &output_files); 51 WriteSourceRules(custom_rule_name, input_dep, &output_files);
52 } else { 52 } else {
53 DCHECK(target_->output_type() == Target::ACTION); 53 DCHECK(target_->output_type() == Target::ACTION);
54 54
55 // Write a rule that invokes the script once with the outputs as outputs, 55 // Write a rule that invokes the script once with the outputs as outputs,
56 // and the data as inputs. It does not depend on the sources. 56 // and the data as inputs. It does not depend on the sources.
57 out_ << "build"; 57 out_ << "build";
58 SubstitutionWriter::GetListAsOutputFiles( 58 SubstitutionWriter::GetListAsOutputFiles(
59 settings_, target_->action_values().outputs(), &output_files); 59 settings_, target_->action_values().outputs(), &output_files);
60 path_output_.WriteFiles(out_, output_files); 60 path_output_.WriteFiles(out_, output_files);
61 61
62 out_ << ": " << custom_rule_name << implicit_deps << std::endl; 62 out_ << ": " << custom_rule_name;
63 if (!input_dep.value().empty()) {
64 // As in WriteSourceRules, we want to force this target to rebuild any
65 // time any of its dependencies change.
66 out_ << " | ";
67 path_output_.WriteFile(out_, input_dep);
68 }
69 out_ << std::endl;
63 if (target_->action_values().has_depfile()) { 70 if (target_->action_values().has_depfile()) {
64 out_ << " depfile = "; 71 out_ << " depfile = ";
65 WriteDepfile(SourceFile()); 72 WriteDepfile(SourceFile());
66 out_ << std::endl; 73 out_ << std::endl;
67 } 74 }
68 } 75 }
69 out_ << std::endl; 76 out_ << std::endl;
70 77
71 // Write the stamp, which also depends on all datadeps. These are needed at 78 // Write the stamp, which also depends on all datadeps. These are needed at
72 // runtime and should be compiled when the action is, but don't need to be 79 // runtime and should be compiled when the action is, but don't need to be
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 out_ << std::endl; 144 out_ << std::endl;
138 out_ << " description = ACTION " << target_label << std::endl; 145 out_ << " description = ACTION " << target_label << std::endl;
139 out_ << " restat = 1" << std::endl; 146 out_ << " restat = 1" << std::endl;
140 } 147 }
141 148
142 return custom_rule_name; 149 return custom_rule_name;
143 } 150 }
144 151
145 void NinjaActionTargetWriter::WriteSourceRules( 152 void NinjaActionTargetWriter::WriteSourceRules(
146 const std::string& custom_rule_name, 153 const std::string& custom_rule_name,
147 const std::string& implicit_deps, 154 const OutputFile& input_dep,
148 std::vector<OutputFile>* output_files) { 155 std::vector<OutputFile>* output_files) {
149 EscapeOptions args_escape_options; 156 EscapeOptions args_escape_options;
150 args_escape_options.mode = ESCAPE_NINJA_COMMAND; 157 args_escape_options.mode = ESCAPE_NINJA_COMMAND;
151 // We're writing the substitution values, these should not be quoted since 158 // We're writing the substitution values, these should not be quoted since
152 // they will get pasted into the real command line. 159 // they will get pasted into the real command line.
153 args_escape_options.inhibit_quoting = true; 160 args_escape_options.inhibit_quoting = true;
154 161
155 const std::vector<SubstitutionType>& args_substitutions_used = 162 const std::vector<SubstitutionType>& args_substitutions_used =
156 target_->action_values().args().required_types(); 163 target_->action_values().args().required_types();
157 164
158 const Target::FileList& sources = target_->sources(); 165 const Target::FileList& sources = target_->sources();
159 for (size_t i = 0; i < sources.size(); i++) { 166 for (size_t i = 0; i < sources.size(); i++) {
160 out_ << "build"; 167 out_ << "build";
161 WriteOutputFilesForBuildLine(sources[i], output_files); 168 WriteOutputFilesForBuildLine(sources[i], output_files);
162 169
163 out_ << ": " << custom_rule_name << " "; 170 out_ << ": " << custom_rule_name << " ";
164 path_output_.WriteFile(out_, sources[i]); 171 path_output_.WriteFile(out_, sources[i]);
165 out_ << implicit_deps << std::endl; 172 if (!input_dep.value().empty()) {
173 // Using "|" for the dependencies forces all implicit dependencies to be
174 // fully up-to-date before running the action, and will re-run this
175 // action if any input dependencies change. This is important because
176 // this action may consume the outputs of previous steps.
177 out_ << " | ";
178 path_output_.WriteFile(out_, input_dep);
179 }
180 out_ << std::endl;
166 181
167 // Windows needs a unique ID for the response file. 182 // Windows needs a unique ID for the response file.
168 if (target_->settings()->IsWin()) 183 if (target_->settings()->IsWin())
169 out_ << " unique_name = " << i << std::endl; 184 out_ << " unique_name = " << i << std::endl;
170 185
171 SubstitutionWriter::WriteNinjaVariablesForSource( 186 SubstitutionWriter::WriteNinjaVariablesForSource(
172 settings_, sources[i], args_substitutions_used, 187 settings_, sources[i], args_substitutions_used,
173 args_escape_options, out_); 188 args_escape_options, out_);
174 189
175 if (target_->action_values().has_depfile()) { 190 if (target_->action_values().has_depfile()) {
(...skipping 16 matching lines...) Expand all
192 out_ << " "; 207 out_ << " ";
193 path_output_.WriteFile(out_, (*output_files)[i]); 208 path_output_.WriteFile(out_, (*output_files)[i]);
194 } 209 }
195 } 210 }
196 211
197 void NinjaActionTargetWriter::WriteDepfile(const SourceFile& source) { 212 void NinjaActionTargetWriter::WriteDepfile(const SourceFile& source) {
198 path_output_.WriteFile(out_, 213 path_output_.WriteFile(out_,
199 SubstitutionWriter::ApplyPatternToSourceAsOutputFile( 214 SubstitutionWriter::ApplyPatternToSourceAsOutputFile(
200 settings_, target_->action_values().depfile(), source)); 215 settings_, target_->action_values().depfile(), source));
201 } 216 }
OLDNEW
« no previous file with comments | « tools/gn/ninja_action_target_writer.h ('k') | tools/gn/ninja_binary_target_writer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698