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

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

Issue 1494883002: GN: Makes GN output deterministic (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Code delousing Created 5 years 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_build_writer.cc ('k') | tools/gn/ninja_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_target_writer.h" 5 #include "tools/gn/ninja_target_writer.h"
6 6
7 #include <sstream> 7 #include <sstream>
8 8
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 path_output_.WriteFile(out_, input); 200 path_output_.WriteFile(out_, input);
201 } 201 }
202 if (list_sources_as_input_deps) { 202 if (list_sources_as_input_deps) {
203 for (const auto& source : target_->sources()) { 203 for (const auto& source : target_->sources()) {
204 out_ << " "; 204 out_ << " ";
205 path_output_.WriteFile(out_, source); 205 path_output_.WriteFile(out_, source);
206 } 206 }
207 } 207 }
208 208
209 // The different souces of input deps may duplicate some targets, so uniquify 209 // The different souces of input deps may duplicate some targets, so uniquify
210 // them (ordering doesn't matter for this case). 210 // them. These are sorted so the generated files are deterministic.
211 std::set<const Target*> unique_deps; 211 std::vector<const Target*> sorted_deps;
212 212
213 // Hard dependencies that are direct or indirect dependencies. 213 // Hard dependencies that are direct or indirect dependencies.
214 const std::set<const Target*>& hard_deps = target_->recursive_hard_deps(); 214 // These are large (up to 100s), hence why we check other
215 for (const auto& dep : hard_deps) 215 const std::set<const Target*>& hard_deps(target_->recursive_hard_deps());
216 unique_deps.insert(dep);
217 216
218 // Extra hard dependencies passed in. 217 // Extra hard dependencies passed in. Note that these are usually empty/small.
219 unique_deps.insert(extra_hard_deps.begin(), extra_hard_deps.end()); 218 for (const Target* target : extra_hard_deps) {
219 if (!hard_deps.count(target))
220 sorted_deps.push_back(target);
221 }
220 222
221 // Toolchain dependencies. These must be resolved before doing anything. 223 // Toolchain dependencies. These must be resolved before doing anything.
222 // This just writs all toolchain deps for simplicity. If we find that 224 // This just writes all toolchain deps for simplicity. If we find that
223 // toolchains often have more than one dependency, we could consider writing 225 // toolchains often have more than one dependency, we could consider writing
224 // a toolchain-specific stamp file and only include the stamp here. 226 // a toolchain-specific stamp file and only include the stamp here.
227 // Note that these are usually empty/small.
225 const LabelTargetVector& toolchain_deps = target_->toolchain()->deps(); 228 const LabelTargetVector& toolchain_deps = target_->toolchain()->deps();
226 for (const auto& toolchain_dep : toolchain_deps) 229 for (const auto& toolchain_dep : toolchain_deps) {
227 unique_deps.insert(toolchain_dep.ptr); 230 // This could theoretically duplicate dependencies already in the list,
231 // but shouldn't happen in practice, is inconvenient to check for,
232 // and only results in harmless redundant dependencies listed.
233 if (!hard_deps.count(toolchain_dep.ptr))
234 sorted_deps.push_back(toolchain_dep.ptr);
235 }
228 236
229 for (const auto& dep : unique_deps) { 237 for (const Target* target : hard_deps) {
238 sorted_deps.push_back(target);
239 }
240
241 std::sort(
242 sorted_deps.begin(), sorted_deps.end(),
243 [](const Target* a, const Target* b) { return a->label() < b->label(); });
244
245 for (const auto& dep : sorted_deps) {
230 DCHECK(!dep->dependency_output_file().value().empty()); 246 DCHECK(!dep->dependency_output_file().value().empty());
231 out_ << " "; 247 out_ << " ";
232 path_output_.WriteFile(out_, dep->dependency_output_file()); 248 path_output_.WriteFile(out_, dep->dependency_output_file());
233 } 249 }
234 250
235 out_ << "\n"; 251 out_ << "\n";
236 return input_stamp_file; 252 return input_stamp_file;
237 } 253 }
238 254
239 void NinjaTargetWriter::WriteStampForTarget( 255 void NinjaTargetWriter::WriteStampForTarget(
(...skipping 15 matching lines...) Expand all
255 << GetNinjaRulePrefixForToolchain(settings_) 271 << GetNinjaRulePrefixForToolchain(settings_)
256 << Toolchain::ToolTypeToName(Toolchain::TYPE_STAMP); 272 << Toolchain::ToolTypeToName(Toolchain::TYPE_STAMP);
257 path_output_.WriteFiles(out_, files); 273 path_output_.WriteFiles(out_, files);
258 274
259 if (!order_only_deps.empty()) { 275 if (!order_only_deps.empty()) {
260 out_ << " ||"; 276 out_ << " ||";
261 path_output_.WriteFiles(out_, order_only_deps); 277 path_output_.WriteFiles(out_, order_only_deps);
262 } 278 }
263 out_ << std::endl; 279 out_ << std::endl;
264 } 280 }
OLDNEW
« no previous file with comments | « tools/gn/ninja_build_writer.cc ('k') | tools/gn/ninja_writer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698