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

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

Issue 1494883002: GN: Makes GN output deterministic (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Moves sort into ninja_toolchain_writer.cc for consistency 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
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_writer.h" 5 #include "tools/gn/ninja_writer.h"
6 6
7 #include "tools/gn/builder.h" 7 #include "tools/gn/builder.h"
8 #include "tools/gn/dereference_comparator.h"
8 #include "tools/gn/loader.h" 9 #include "tools/gn/loader.h"
9 #include "tools/gn/location.h" 10 #include "tools/gn/location.h"
10 #include "tools/gn/ninja_build_writer.h" 11 #include "tools/gn/ninja_build_writer.h"
11 #include "tools/gn/ninja_toolchain_writer.h" 12 #include "tools/gn/ninja_toolchain_writer.h"
12 #include "tools/gn/settings.h" 13 #include "tools/gn/settings.h"
14 #include "tools/gn/target.h"
13 15
14 NinjaWriter::NinjaWriter(const BuildSettings* build_settings, 16 NinjaWriter::NinjaWriter(const BuildSettings* build_settings,
15 Builder* builder) 17 Builder* builder)
16 : build_settings_(build_settings), 18 : build_settings_(build_settings),
17 builder_(builder) { 19 builder_(builder) {
18 } 20 }
19 21
20 NinjaWriter::~NinjaWriter() { 22 NinjaWriter::~NinjaWriter() {
21 } 23 }
22 24
23 // static 25 // static
24 bool NinjaWriter::RunAndWriteFiles(const BuildSettings* build_settings, 26 bool NinjaWriter::RunAndWriteFiles(const BuildSettings* build_settings,
25 Builder* builder, 27 Builder* builder,
26 Err* err) { 28 Err* err) {
27 NinjaWriter writer(build_settings, builder); 29 NinjaWriter writer(build_settings, builder);
28 30
29 std::vector<const Settings*> all_settings; 31 std::vector<const Settings*> all_settings;
30 std::vector<const Target*> default_targets; 32 std::vector<const Target*> default_targets;
31 if (!writer.WriteToolchains(&all_settings, &default_targets, err)) 33 if (!writer.WriteToolchains(&all_settings, &default_targets, err))
32 return false; 34 return false;
35
36 // Sort the targets so that outputs have a consistent order.
37 std::sort(default_targets.begin(), default_targets.end(),
38 DereferenceComparator<Target>());
39
33 return writer.WriteRootBuildfiles(all_settings, default_targets, err); 40 return writer.WriteRootBuildfiles(all_settings, default_targets, err);
34 } 41 }
35 42
36 // static 43 // static
37 bool NinjaWriter::RunAndWriteToolchainFiles( 44 bool NinjaWriter::RunAndWriteToolchainFiles(
38 const BuildSettings* build_settings, 45 const BuildSettings* build_settings,
39 Builder* builder, 46 Builder* builder,
40 std::vector<const Settings*>* all_settings, 47 std::vector<const Settings*>* all_settings,
41 Err* err) { 48 Err* err) {
42 NinjaWriter writer(build_settings, builder); 49 NinjaWriter writer(build_settings, builder);
(...skipping 20 matching lines...) Expand all
63 Err(Location(), "No targets.", 70 Err(Location(), "No targets.",
64 "I could not find any targets to write, so I'm doing nothing.") 71 "I could not find any targets to write, so I'm doing nothing.")
65 .PrintToStdout(); 72 .PrintToStdout();
66 return false; 73 return false;
67 } 74 }
68 75
69 Label default_label = builder_->loader()->GetDefaultToolchain(); 76 Label default_label = builder_->loader()->GetDefaultToolchain();
70 77
71 // Write out the toolchain buildfiles, and also accumulate the set of 78 // Write out the toolchain buildfiles, and also accumulate the set of
72 // all settings and find the list of targets in the default toolchain. 79 // all settings and find the list of targets in the default toolchain.
73 for (CategorizedMap::const_iterator i = categorized.begin(); 80 for (CategorizedMap::iterator i = categorized.begin(); i != categorized.end();
74 i != categorized.end(); ++i) { 81 ++i) {
75 const Settings* settings = 82 const Settings* settings =
76 builder_->loader()->GetToolchainSettings(i->first); 83 builder_->loader()->GetToolchainSettings(i->first);
77 const Toolchain* toolchain = builder_->GetToolchain(i->first); 84 const Toolchain* toolchain = builder_->GetToolchain(i->first);
78 85
79 all_settings->push_back(settings); 86 all_settings->push_back(settings);
87
80 if (!NinjaToolchainWriter::RunAndWriteFile(settings, toolchain, 88 if (!NinjaToolchainWriter::RunAndWriteFile(settings, toolchain,
81 i->second)) { 89 i->second)) {
82 Err(Location(), 90 Err(Location(),
83 "Couldn't open toolchain buildfile(s) for writing").PrintToStdout(); 91 "Couldn't open toolchain buildfile(s) for writing").PrintToStdout();
84 return false; 92 return false;
85 } 93 }
86 } 94 }
87 95
88 *default_targets = categorized[default_label]; 96 *default_targets = categorized[default_label];
89 return true; 97 return true;
90 } 98 }
91 99
92 bool NinjaWriter::WriteRootBuildfiles( 100 bool NinjaWriter::WriteRootBuildfiles(
93 const std::vector<const Settings*>& all_settings, 101 const std::vector<const Settings*>& all_settings,
94 const std::vector<const Target*>& default_targets, 102 const std::vector<const Target*>& default_targets,
95 Err* err) { 103 Err* err) {
96 // All Settings objects should have the same default toolchain, and there 104 // All Settings objects should have the same default toolchain, and there
97 // should always be at least one settings object in the build. 105 // should always be at least one settings object in the build.
98 CHECK(!all_settings.empty()); 106 CHECK(!all_settings.empty());
99 const Toolchain* default_toolchain = 107 const Toolchain* default_toolchain =
100 builder_->GetToolchain(all_settings[0]->default_toolchain_label()); 108 builder_->GetToolchain(all_settings[0]->default_toolchain_label());
101 109
102 // Write the root buildfile. 110 // Write the root buildfile.
103 return NinjaBuildWriter::RunAndWriteFile(build_settings_, all_settings, 111 return NinjaBuildWriter::RunAndWriteFile(build_settings_, all_settings,
104 default_toolchain, default_targets, 112 default_toolchain, default_targets,
105 err); 113 err);
106 } 114 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698