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

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

Issue 350743004: Allow dependencies of toolchains in GN. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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/ninja_copy_target_writer_unittest.cc ('k') | tools/gn/ninja_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_target_writer.h" 5 #include "tools/gn/ninja_target_writer.h"
6 6
7 #include <fstream> 7 #include <fstream>
8 #include <sstream> 8 #include <sstream>
9 9
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 79
80 std::string contents = file.str(); 80 std::string contents = file.str();
81 base::WriteFile(ninja_file, contents.c_str(), 81 base::WriteFile(ninja_file, contents.c_str(),
82 static_cast<int>(contents.size())); 82 static_cast<int>(contents.size()));
83 } 83 }
84 84
85 std::string NinjaTargetWriter::WriteInputDepsStampAndGetDep( 85 std::string NinjaTargetWriter::WriteInputDepsStampAndGetDep(
86 const std::vector<const Target*>& extra_hard_deps) const { 86 const std::vector<const Target*>& extra_hard_deps) const {
87 // For an action (where we run a script only once) the sources are the same 87 // For an action (where we run a script only once) the sources are the same
88 // as the source prereqs. 88 // as the source prereqs.
89 bool list_sources_as_input_deps = target_->output_type() == Target::ACTION; 89 bool list_sources_as_input_deps = (target_->output_type() == Target::ACTION);
90 90
91 // Actions get implicit dependencies on the script itself. 91 // Actions get implicit dependencies on the script itself.
92 bool add_script_source_as_dep = target_->output_type() == Target::ACTION || 92 bool add_script_source_as_dep =
93 target_->output_type() == Target::ACTION_FOREACH; 93 (target_->output_type() == Target::ACTION) ||
94 (target_->output_type() == Target::ACTION_FOREACH);
94 95
95 if (!add_script_source_as_dep && 96 if (!add_script_source_as_dep &&
96 extra_hard_deps.empty() && 97 extra_hard_deps.empty() &&
97 target_->inputs().empty() && 98 target_->inputs().empty() &&
98 target_->recursive_hard_deps().empty() && 99 target_->recursive_hard_deps().empty() &&
99 (!list_sources_as_input_deps || target_->sources().empty())) 100 (!list_sources_as_input_deps || target_->sources().empty()) &&
101 toolchain_->deps().empty())
100 return std::string(); // No input/hard deps. 102 return std::string(); // No input/hard deps.
101 103
102 // One potential optimization is if there are few input dependencies (or 104 // One potential optimization is if there are few input dependencies (or
103 // potentially few sources that depend on these) it's better to just write 105 // potentially few sources that depend on these) it's better to just write
104 // all hard deps on each sources line than have this intermediate stamp. We 106 // all hard deps on each sources line than have this intermediate stamp. We
105 // do the stamp file because duplicating all the order-only deps for each 107 // do the stamp file because duplicating all the order-only deps for each
106 // source file can really explode the ninja file but this won't be the most 108 // source file can really explode the ninja file but this won't be the most
107 // optimal thing in all cases. 109 // optimal thing in all cases.
108 110
109 OutputFile input_stamp_file = helper_.GetTargetOutputDir(target_); 111 OutputFile input_stamp_file = helper_.GetTargetOutputDir(target_);
(...skipping 28 matching lines...) Expand all
138 } 140 }
139 141
140 // Add on any hard deps that are direct or indirect dependencies. 142 // Add on any hard deps that are direct or indirect dependencies.
141 const std::set<const Target*>& hard_deps = target_->recursive_hard_deps(); 143 const std::set<const Target*>& hard_deps = target_->recursive_hard_deps();
142 for (std::set<const Target*>::const_iterator i = hard_deps.begin(); 144 for (std::set<const Target*>::const_iterator i = hard_deps.begin();
143 i != hard_deps.end(); ++i) { 145 i != hard_deps.end(); ++i) {
144 out_ << " "; 146 out_ << " ";
145 path_output_.WriteFile(out_, helper_.GetTargetOutputFile(*i)); 147 path_output_.WriteFile(out_, helper_.GetTargetOutputFile(*i));
146 } 148 }
147 149
150 // Toolchain dependencies. These must be resolved before doing anything.
151 // This just writs all toolchain deps for simplicity. If we find that
152 // toolchains often have more than one dependency, we could consider writing
153 // a toolchain-specific stamp file and only include the stamp here.
154 const LabelTargetVector& toolchain_deps = toolchain_->deps();
155 for (size_t i = 0; i < toolchain_deps.size(); i++) {
156 out_ << " ";
157 path_output_.WriteFile(out_,
158 helper_.GetTargetOutputFile(toolchain_deps[i].ptr));
159 }
160
148 // Extra hard deps passed in. 161 // Extra hard deps passed in.
149 for (size_t i = 0; i < extra_hard_deps.size(); i++) { 162 for (size_t i = 0; i < extra_hard_deps.size(); i++) {
150 out_ << " "; 163 out_ << " ";
151 path_output_.WriteFile(out_, 164 path_output_.WriteFile(out_,
152 helper_.GetTargetOutputFile(extra_hard_deps[i])); 165 helper_.GetTargetOutputFile(extra_hard_deps[i]));
153 } 166 }
154 167
155 out_ << "\n"; 168 out_ << "\n";
156 return " | " + stamp_file_string; 169 return " | " + stamp_file_string;
157 } 170 }
158 171
159 FileTemplate NinjaTargetWriter::GetOutputTemplate() const { 172 FileTemplate NinjaTargetWriter::GetOutputTemplate() const {
160 const Target::FileList& outputs = target_->action_values().outputs(); 173 const Target::FileList& outputs = target_->action_values().outputs();
161 std::vector<std::string> output_template_args; 174 std::vector<std::string> output_template_args;
162 for (size_t i = 0; i < outputs.size(); i++) { 175 for (size_t i = 0; i < outputs.size(); i++) {
163 // All outputs should be in the output dir. 176 // All outputs should be in the output dir.
164 output_template_args.push_back( 177 output_template_args.push_back(
165 RemovePrefix(outputs[i].value(), 178 RemovePrefix(outputs[i].value(),
166 settings_->build_settings()->build_dir().value())); 179 settings_->build_settings()->build_dir().value()));
167 } 180 }
168 return FileTemplate(target_->settings(), output_template_args); 181 return FileTemplate(target_->settings(), output_template_args);
169 } 182 }
OLDNEW
« no previous file with comments | « tools/gn/ninja_copy_target_writer_unittest.cc ('k') | tools/gn/ninja_target_writer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698