blob: 8b69a3fc73536a7eaaf258b6d5a1220652bcc9d6 [file] [log] [blame]
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "tools/gn/ninja_writer.h"
#include "tools/gn/location.h"
#include "tools/gn/ninja_build_writer.h"
#include "tools/gn/ninja_toolchain_writer.h"
NinjaWriter::NinjaWriter(const BuildSettings* build_settings)
: build_settings_(build_settings) {
NinjaWriter::~NinjaWriter() {
// static
bool NinjaWriter::RunAndWriteFiles(const BuildSettings* build_settings) {
NinjaWriter writer(build_settings);
return writer.WriteRootBuildfiles();
bool NinjaWriter::WriteRootBuildfiles() {
// Categorize all targets by toolchain.
typedef std::map<Label, std::vector<const Target*> > CategorizedMap;
CategorizedMap categorized;
std::vector<const Target*> all_targets;
for (size_t i = 0; i < all_targets.size(); i++) {
Label default_label =
// Write out the toolchain buildfiles, and also accumulate the set of
// all settings and find the list of targets in the default toolchain.
std::vector<const Settings*> all_settings;
const std::vector<const Target*>* default_targets = NULL;
for (CategorizedMap::const_iterator i = categorized.begin();
i != categorized.end(); ++i) {
const Settings* settings;
base::AutoLock lock(build_settings_->item_tree().lock());
Err ignored;
settings =
LocationRange(), i->first, &ignored);
if (i->first == default_label)
default_targets = &i->second;
if (!NinjaToolchainWriter::RunAndWriteFile(settings, i->second))
return false;
// Write the root buildfile.
return NinjaBuildWriter::RunAndWriteFile(build_settings_, all_settings,