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

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

Issue 561273003: Add public deps to GN (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merge 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/header_checker_unittest.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/deps_iterator.h"
8 #include "tools/gn/err.h" 9 #include "tools/gn/err.h"
9 #include "tools/gn/settings.h" 10 #include "tools/gn/settings.h"
10 #include "tools/gn/string_utils.h" 11 #include "tools/gn/string_utils.h"
11 #include "tools/gn/substitution_writer.h" 12 #include "tools/gn/substitution_writer.h"
12 #include "tools/gn/target.h" 13 #include "tools/gn/target.h"
13 14
14 NinjaActionTargetWriter::NinjaActionTargetWriter(const Target* target, 15 NinjaActionTargetWriter::NinjaActionTargetWriter(const Target* target,
15 std::ostream& out) 16 std::ostream& out)
16 : NinjaTargetWriter(target, out), 17 : NinjaTargetWriter(target, out),
17 path_output_no_escaping_( 18 path_output_no_escaping_(
18 target->settings()->build_settings()->build_dir(), 19 target->settings()->build_settings()->build_dir(),
19 ESCAPE_NONE) { 20 ESCAPE_NONE) {
20 } 21 }
21 22
22 NinjaActionTargetWriter::~NinjaActionTargetWriter() { 23 NinjaActionTargetWriter::~NinjaActionTargetWriter() {
23 } 24 }
24 25
25 void NinjaActionTargetWriter::Run() { 26 void NinjaActionTargetWriter::Run() {
26 std::string custom_rule_name = WriteRuleDefinition(); 27 std::string custom_rule_name = WriteRuleDefinition();
27 28
28 // Collect our deps to pass as "extra hard dependencies" for input deps. This 29 // 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 30 // 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 31 // 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 32 // operating on the result of that previous step, so we need to be sure to
32 // serialize these. 33 // serialize these.
33 std::vector<const Target*> extra_hard_deps; 34 std::vector<const Target*> extra_hard_deps;
34 for (size_t i = 0; i < target_->deps().size(); i++) 35 for (DepsIterator iter(target_, DepsIterator::LINKED_ONLY);
35 extra_hard_deps.push_back(target_->deps()[i].ptr); 36 !iter.done(); iter.Advance())
37 extra_hard_deps.push_back(iter.target());
36 38
37 // For ACTIONs this is a bit inefficient since it creates an input dep 39 // 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 40 // 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 41 // build step to skip this and write the order-only deps directly on the
40 // build rule. This should probably be handled by WriteInputDepsStampAndGetDep 42 // build rule. This should probably be handled by WriteInputDepsStampAndGetDep
41 // automatically if we supply a count of sources (so it can optimize based on 43 // automatically if we supply a count of sources (so it can optimize based on
42 // how many times things would be duplicated). 44 // how many times things would be duplicated).
43 OutputFile input_dep = WriteInputDepsStampAndGetDep(extra_hard_deps); 45 OutputFile input_dep = WriteInputDepsStampAndGetDep(extra_hard_deps);
44 out_ << std::endl; 46 out_ << std::endl;
45 47
(...skipping 22 matching lines...) Expand all
68 } 70 }
69 out_ << std::endl; 71 out_ << std::endl;
70 if (target_->action_values().has_depfile()) { 72 if (target_->action_values().has_depfile()) {
71 out_ << " depfile = "; 73 out_ << " depfile = ";
72 WriteDepfile(SourceFile()); 74 WriteDepfile(SourceFile());
73 out_ << std::endl; 75 out_ << std::endl;
74 } 76 }
75 } 77 }
76 out_ << std::endl; 78 out_ << std::endl;
77 79
78 // Write the stamp, which also depends on all datadeps. These are needed at 80 // 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 81 // runtime and should be compiled when the action is, but don't need to be
80 // done before we run the action. 82 // done before we run the action.
81 std::vector<OutputFile> data_outs; 83 std::vector<OutputFile> data_outs;
82 for (size_t i = 0; i < target_->datadeps().size(); i++) 84 for (size_t i = 0; i < target_->data_deps().size(); i++)
83 data_outs.push_back(target_->datadeps()[i].ptr->dependency_output_file()); 85 data_outs.push_back(target_->data_deps()[i].ptr->dependency_output_file());
84 WriteStampForTarget(output_files, data_outs); 86 WriteStampForTarget(output_files, data_outs);
85 } 87 }
86 88
87 std::string NinjaActionTargetWriter::WriteRuleDefinition() { 89 std::string NinjaActionTargetWriter::WriteRuleDefinition() {
88 // Make a unique name for this rule. 90 // Make a unique name for this rule.
89 // 91 //
90 // Use a unique name for the response file when there are multiple build 92 // 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, 93 // 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. 94 // there will be only one invocation so we can use a simple name.
93 std::string target_label = target_->label().GetUserVisibleName(true); 95 std::string target_label = target_->label().GetUserVisibleName(true);
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 out_ << " "; 209 out_ << " ";
208 path_output_.WriteFile(out_, (*output_files)[i]); 210 path_output_.WriteFile(out_, (*output_files)[i]);
209 } 211 }
210 } 212 }
211 213
212 void NinjaActionTargetWriter::WriteDepfile(const SourceFile& source) { 214 void NinjaActionTargetWriter::WriteDepfile(const SourceFile& source) {
213 path_output_.WriteFile(out_, 215 path_output_.WriteFile(out_,
214 SubstitutionWriter::ApplyPatternToSourceAsOutputFile( 216 SubstitutionWriter::ApplyPatternToSourceAsOutputFile(
215 settings_, target_->action_values().depfile(), source)); 217 settings_, target_->action_values().depfile(), source));
216 } 218 }
OLDNEW
« no previous file with comments | « tools/gn/header_checker_unittest.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