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 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 all_record->item()->AsTarget()); | 60 all_record->item()->AsTarget()); |
60 } | 61 } |
61 } | 62 } |
62 if (categorized.empty()) { | 63 if (categorized.empty()) { |
63 Err(Location(), "No targets.", | 64 Err(Location(), "No targets.", |
64 "I could not find any targets to write, so I'm doing nothing.") | 65 "I could not find any targets to write, so I'm doing nothing.") |
65 .PrintToStdout(); | 66 .PrintToStdout(); |
66 return false; | 67 return false; |
67 } | 68 } |
68 | 69 |
| 70 for (auto& i : categorized) { |
| 71 // Sort targets so that they are in a deterministic order. |
| 72 std::sort(i.second.begin(), i.second.end(), |
| 73 [](const Target* a, const Target* b) { |
| 74 return a->label() < b->label(); |
| 75 }); |
| 76 } |
| 77 |
69 Label default_label = builder_->loader()->GetDefaultToolchain(); | 78 Label default_label = builder_->loader()->GetDefaultToolchain(); |
70 | 79 |
71 // Write out the toolchain buildfiles, and also accumulate the set of | 80 // Write out the toolchain buildfiles, and also accumulate the set of |
72 // all settings and find the list of targets in the default toolchain. | 81 // all settings and find the list of targets in the default toolchain. |
73 for (CategorizedMap::const_iterator i = categorized.begin(); | 82 for (const auto& i : categorized) { |
74 i != categorized.end(); ++i) { | |
75 const Settings* settings = | 83 const Settings* settings = |
76 builder_->loader()->GetToolchainSettings(i->first); | 84 builder_->loader()->GetToolchainSettings(i.first); |
77 const Toolchain* toolchain = builder_->GetToolchain(i->first); | 85 const Toolchain* toolchain = builder_->GetToolchain(i.first); |
78 | 86 |
79 all_settings->push_back(settings); | 87 all_settings->push_back(settings); |
80 if (!NinjaToolchainWriter::RunAndWriteFile(settings, toolchain, | 88 |
81 i->second)) { | 89 if (!NinjaToolchainWriter::RunAndWriteFile(settings, toolchain, 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 } |
OLD | NEW |