| Index: tools/gn/ninja_writer.cc
|
| diff --git a/tools/gn/ninja_writer.cc b/tools/gn/ninja_writer.cc
|
| index 22a97ec4205fcaee353b25953fe134fdc0f28945..4fd5b22cffc72039b6859d512bf30719d8b3f3bc 100644
|
| --- a/tools/gn/ninja_writer.cc
|
| +++ b/tools/gn/ninja_writer.cc
|
| @@ -12,118 +12,45 @@
|
| #include "tools/gn/settings.h"
|
| #include "tools/gn/target.h"
|
|
|
| -NinjaWriter::NinjaWriter(const BuildSettings* build_settings,
|
| - Builder* builder)
|
| - : build_settings_(build_settings),
|
| - builder_(builder) {
|
| +NinjaWriter::NinjaWriter(const Builder& builder)
|
| + : builder_(builder) {
|
| }
|
|
|
| NinjaWriter::~NinjaWriter() {
|
| }
|
|
|
| // static
|
| -bool NinjaWriter::RunAndWriteFiles(const BuildSettings* build_settings,
|
| - Builder* builder,
|
| - Err* err) {
|
| - NinjaWriter writer(build_settings, builder);
|
| -
|
| - std::vector<const Settings*> all_settings;
|
| - std::vector<const Target*> default_targets;
|
| - std::vector<const Pool*> all_pools;
|
| - if (!writer.WriteToolchains(&all_settings, &default_targets, &all_pools, err))
|
| - return false;
|
| - return writer.WriteRootBuildfiles(all_settings, default_targets, all_pools,
|
| - err);
|
| -}
|
| -
|
| -// static
|
| -bool NinjaWriter::RunAndWriteToolchainFiles(
|
| +bool NinjaWriter::RunAndWriteFiles(
|
| const BuildSettings* build_settings,
|
| - Builder* builder,
|
| - std::vector<const Settings*>* all_settings,
|
| + const Builder& builder,
|
| + const PerToolchainRules& per_toolchain_rules,
|
| Err* err) {
|
| - NinjaWriter writer(build_settings, builder);
|
| - std::vector<const Target*> default_targets;
|
| - std::vector<const Pool*> all_pools;
|
| - return writer.WriteToolchains(all_settings, &default_targets, &all_pools,
|
| - err);
|
| + NinjaWriter writer(builder);
|
| +
|
| + if (!writer.WriteToolchains(per_toolchain_rules, err))
|
| + return false;
|
| + return NinjaBuildWriter::RunAndWriteFile(build_settings, builder, err);
|
| }
|
|
|
| -bool NinjaWriter::WriteToolchains(std::vector<const Settings*>* all_settings,
|
| - std::vector<const Target*>* default_targets,
|
| - std::vector<const Pool*>* all_pools,
|
| +bool NinjaWriter::WriteToolchains(const PerToolchainRules& per_toolchain_rules,
|
| Err* err) {
|
| - // Categorize all targets by toolchain.
|
| - typedef std::map<Label, std::vector<const Target*> > CategorizedMap;
|
| - CategorizedMap categorized;
|
| -
|
| - std::vector<const BuilderRecord*> all_records = builder_->GetAllRecords();
|
| - for (auto* all_record : all_records) {
|
| - if (all_record->type() == BuilderRecord::ITEM_TARGET &&
|
| - all_record->should_generate()) {
|
| - categorized[all_record->label().GetToolchainLabel()].push_back(
|
| - all_record->item()->AsTarget());
|
| - }
|
| - }
|
| - if (categorized.empty()) {
|
| + if (per_toolchain_rules.empty()) {
|
| Err(Location(), "No targets.",
|
| "I could not find any targets to write, so I'm doing nothing.")
|
| .PrintToStdout();
|
| return false;
|
| }
|
|
|
| - for (auto& i : categorized) {
|
| - // Sort targets so that they are in a deterministic order.
|
| - std::sort(i.second.begin(), i.second.end(),
|
| - [](const Target* a, const Target* b) {
|
| - return a->label() < b->label();
|
| - });
|
| - }
|
| -
|
| - Label default_label = builder_->loader()->GetDefaultToolchain();
|
| -
|
| - // Write out the toolchain buildfiles, and also accumulate the set of
|
| - // all settings and find the list of targets in the default toolchain.
|
| - UniqueVector<const Pool*> pools;
|
| - for (const auto& i : categorized) {
|
| + for (const auto& i : per_toolchain_rules) {
|
| + const Toolchain* toolchain = i.first;
|
| const Settings* settings =
|
| - builder_->loader()->GetToolchainSettings(i.first);
|
| - const Toolchain* toolchain = builder_->GetToolchain(i.first);
|
| -
|
| - all_settings->push_back(settings);
|
| -
|
| + builder_.loader()->GetToolchainSettings(toolchain->label());
|
| if (!NinjaToolchainWriter::RunAndWriteFile(settings, toolchain, i.second)) {
|
| Err(Location(),
|
| "Couldn't open toolchain buildfile(s) for writing").PrintToStdout();
|
| return false;
|
| }
|
| -
|
| - for (int j = Toolchain::TYPE_NONE + 1; j < Toolchain::TYPE_NUMTYPES; j++) {
|
| - Toolchain::ToolType tool_type = static_cast<Toolchain::ToolType>(j);
|
| - const Tool* tool = toolchain->GetTool(tool_type);
|
| - if (tool && tool->pool().ptr)
|
| - pools.push_back(tool->pool().ptr);
|
| - }
|
| }
|
|
|
| - *all_pools = pools.vector();
|
| - *default_targets = categorized[default_label];
|
| return true;
|
| }
|
| -
|
| -bool NinjaWriter::WriteRootBuildfiles(
|
| - const std::vector<const Settings*>& all_settings,
|
| - const std::vector<const Target*>& default_targets,
|
| - const std::vector<const Pool*>& all_pools,
|
| - Err* err) {
|
| - // All Settings objects should have the same default toolchain, and there
|
| - // should always be at least one settings object in the build.
|
| - CHECK(!all_settings.empty());
|
| - const Toolchain* default_toolchain =
|
| - builder_->GetToolchain(all_settings[0]->default_toolchain_label());
|
| -
|
| - // Write the root buildfile.
|
| - return NinjaBuildWriter::RunAndWriteFile(build_settings_, all_settings,
|
| - default_toolchain, default_targets,
|
| - all_pools, err);
|
| -}
|
|
|