OLD | NEW |
---|---|
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/loader.h" | 8 #include "tools/gn/loader.h" |
9 #include "tools/gn/location.h" | 9 #include "tools/gn/location.h" |
10 #include "tools/gn/ninja_build_writer.h" | 10 #include "tools/gn/ninja_build_writer.h" |
11 #include "tools/gn/ninja_toolchain_writer.h" | 11 #include "tools/gn/ninja_toolchain_writer.h" |
12 #include "tools/gn/settings.h" | 12 #include "tools/gn/settings.h" |
13 #include "tools/gn/target.h" | |
13 | 14 |
14 NinjaWriter::NinjaWriter(const BuildSettings* build_settings, | 15 NinjaWriter::NinjaWriter(const BuildSettings* build_settings, |
15 Builder* builder) | 16 Builder* builder) |
16 : build_settings_(build_settings), | 17 : build_settings_(build_settings), |
17 builder_(builder) { | 18 builder_(builder) { |
18 } | 19 } |
19 | 20 |
20 NinjaWriter::~NinjaWriter() { | 21 NinjaWriter::~NinjaWriter() { |
21 } | 22 } |
22 | 23 |
23 // static | 24 // static |
24 bool NinjaWriter::RunAndWriteFiles(const BuildSettings* build_settings, | 25 bool NinjaWriter::RunAndWriteFiles(const BuildSettings* build_settings, |
25 Builder* builder, | 26 Builder* builder, |
26 Err* err) { | 27 Err* err) { |
27 NinjaWriter writer(build_settings, builder); | 28 NinjaWriter writer(build_settings, builder); |
28 | 29 |
29 std::vector<const Settings*> all_settings; | 30 std::vector<const Settings*> all_settings; |
30 std::vector<const Target*> default_targets; | 31 std::vector<const Target*> default_targets; |
31 if (!writer.WriteToolchains(&all_settings, &default_targets, err)) | 32 if (!writer.WriteToolchains(&all_settings, &default_targets, err)) |
mithro-old
2015/12/03 05:20:31
Doesn't sorting in NinjaWriter::WriteToolchains me
Zachary Forman
2015/12/03 07:27:02
Other way around - more than just WriteToolchains
| |
32 return false; | 33 return false; |
34 | |
35 // Sort the targets so that outputs have a consistent order. | |
mithro-old
2015/12/03 05:20:31
Can we get a test for this?
Zachary Forman
2015/12/03 07:27:02
I don't think so. It percolates through a stack of
| |
36 std::sort(default_targets.begin(), default_targets.end(), | |
37 [](const Target* a, const Target* b) { return *a < *b; }); | |
mithro-old
2015/12/03 05:20:31
Can you use your comparator here instead of a lamb
Zachary Forman
2015/12/03 07:27:02
Yeah, might as well. It'll be a little nicer.
| |
38 | |
33 return writer.WriteRootBuildfiles(all_settings, default_targets, err); | 39 return writer.WriteRootBuildfiles(all_settings, default_targets, err); |
34 } | 40 } |
35 | 41 |
36 // static | 42 // static |
37 bool NinjaWriter::RunAndWriteToolchainFiles( | 43 bool NinjaWriter::RunAndWriteToolchainFiles( |
38 const BuildSettings* build_settings, | 44 const BuildSettings* build_settings, |
39 Builder* builder, | 45 Builder* builder, |
40 std::vector<const Settings*>* all_settings, | 46 std::vector<const Settings*>* all_settings, |
41 Err* err) { | 47 Err* err) { |
42 NinjaWriter writer(build_settings, builder); | 48 NinjaWriter writer(build_settings, builder); |
(...skipping 20 matching lines...) Expand all Loading... | |
63 Err(Location(), "No targets.", | 69 Err(Location(), "No targets.", |
64 "I could not find any targets to write, so I'm doing nothing.") | 70 "I could not find any targets to write, so I'm doing nothing.") |
65 .PrintToStdout(); | 71 .PrintToStdout(); |
66 return false; | 72 return false; |
67 } | 73 } |
68 | 74 |
69 Label default_label = builder_->loader()->GetDefaultToolchain(); | 75 Label default_label = builder_->loader()->GetDefaultToolchain(); |
70 | 76 |
71 // Write out the toolchain buildfiles, and also accumulate the set of | 77 // Write out the toolchain buildfiles, and also accumulate the set of |
72 // all settings and find the list of targets in the default toolchain. | 78 // all settings and find the list of targets in the default toolchain. |
73 for (CategorizedMap::const_iterator i = categorized.begin(); | 79 for (CategorizedMap::iterator i = categorized.begin(); i != categorized.end(); |
74 i != categorized.end(); ++i) { | 80 ++i) { |
75 const Settings* settings = | 81 const Settings* settings = |
76 builder_->loader()->GetToolchainSettings(i->first); | 82 builder_->loader()->GetToolchainSettings(i->first); |
77 const Toolchain* toolchain = builder_->GetToolchain(i->first); | 83 const Toolchain* toolchain = builder_->GetToolchain(i->first); |
78 | 84 |
79 all_settings->push_back(settings); | 85 all_settings->push_back(settings); |
86 // Sort the toolchain's targets to ensure output is consistently ordered. | |
87 std::sort(i->second.begin(), i->second.end(), | |
mithro-old
2015/12/03 05:20:31
Same as above...
Zachary Forman
2015/12/03 07:27:02
Acknowledged
| |
88 [](const Target* a, const Target* b) { return *a < *b; }); | |
80 if (!NinjaToolchainWriter::RunAndWriteFile(settings, toolchain, | 89 if (!NinjaToolchainWriter::RunAndWriteFile(settings, toolchain, |
81 i->second)) { | 90 i->second)) { |
82 Err(Location(), | 91 Err(Location(), |
83 "Couldn't open toolchain buildfile(s) for writing").PrintToStdout(); | 92 "Couldn't open toolchain buildfile(s) for writing").PrintToStdout(); |
84 return false; | 93 return false; |
85 } | 94 } |
86 } | 95 } |
87 | 96 |
88 *default_targets = categorized[default_label]; | 97 *default_targets = categorized[default_label]; |
89 return true; | 98 return true; |
90 } | 99 } |
91 | 100 |
92 bool NinjaWriter::WriteRootBuildfiles( | 101 bool NinjaWriter::WriteRootBuildfiles( |
93 const std::vector<const Settings*>& all_settings, | 102 const std::vector<const Settings*>& all_settings, |
94 const std::vector<const Target*>& default_targets, | 103 const std::vector<const Target*>& default_targets, |
95 Err* err) { | 104 Err* err) { |
96 // All Settings objects should have the same default toolchain, and there | 105 // All Settings objects should have the same default toolchain, and there |
97 // should always be at least one settings object in the build. | 106 // should always be at least one settings object in the build. |
98 CHECK(!all_settings.empty()); | 107 CHECK(!all_settings.empty()); |
99 const Toolchain* default_toolchain = | 108 const Toolchain* default_toolchain = |
100 builder_->GetToolchain(all_settings[0]->default_toolchain_label()); | 109 builder_->GetToolchain(all_settings[0]->default_toolchain_label()); |
101 | 110 |
102 // Write the root buildfile. | 111 // Write the root buildfile. |
103 return NinjaBuildWriter::RunAndWriteFile(build_settings_, all_settings, | 112 return NinjaBuildWriter::RunAndWriteFile(build_settings_, all_settings, |
104 default_toolchain, default_targets, | 113 default_toolchain, default_targets, |
105 err); | 114 err); |
106 } | 115 } |
OLD | NEW |