blob: 93a1ae6b41299919cf748d06f965f983e86499d7 [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 "base/files/file_path.h"
#include "tools/gn/build_settings.h"
#include "tools/gn/import_manager.h"
#include "tools/gn/output_file.h"
#include "tools/gn/scope.h"
#include "tools/gn/source_dir.h"
#include "tools/gn/toolchain.h"
// Holds the settings for one toolchain invocation. There will be one
// Settings object for each toolchain type, each referring to the same
// BuildSettings object for shared stuff.
// The Settings object is const once it is constructed, which allows us to
// use it from multiple threads during target generation without locking (which
// is important, because it gets used a lot).
// The Toolchain object holds the set of stuff that is set by the toolchain
// declaration, which obviously needs to be set later when we actually parse
// the file with the toolchain declaration in it.
class Settings {
enum TargetOS {
// Constructs a toolchain settings. The output_subdir_name is the name we
// should use for the subdirectory in the build output directory for this
// toolchain's outputs. It should have no slashes in it. The default
// toolchain should use an empty string.
Settings(const BuildSettings* build_settings,
const Toolchain* toolchain,
const std::string& output_subdir_name);
const BuildSettings* build_settings() const { return build_settings_; }
// Danger: this must only be used for getting the toolchain label until the
// toolchain has been resolved. Otherwise, it will be modified on an
// arbitrary thread when the toolchain invocation is found. Generally, you
// will only read this from the target generation where we know everything
// has been resolved and won't change.
const Toolchain* toolchain() const { return toolchain_; }
bool IsMac() const { return target_os_ == MAC; }
bool IsWin() const { return target_os_ == WIN; }
TargetOS target_os() const { return target_os_; }
void set_target_os(TargetOS t) { target_os_ = t; }
const OutputFile& toolchain_output_subdir() const {
return toolchain_output_subdir_;
const SourceDir& toolchain_output_dir() const {
return toolchain_output_dir_;
// Directory for generated files.
const SourceDir& toolchain_gen_dir() const {
return toolchain_gen_dir_;
// The import manager caches the result of executing imported files in the
// context of a given settings object.
// See the ItemTree getter in GlobalSettings for why this doesn't return a
// const pointer.
ImportManager& import_manager() const { return import_manager_; }
const Scope* base_config() const { return &base_config_; }
Scope* base_config() { return &base_config_; }
const BuildSettings* build_settings_;
const Toolchain* toolchain_;
TargetOS target_os_;
mutable ImportManager import_manager_;
// The subdirectory inside the build output for this toolchain. For the
// default toolchain, this will be empty (since the deafult toolchain's
// output directory is the same as the build directory). When nonempty, this
// is guaranteed to end in a slash.
OutputFile toolchain_output_subdir_;
// Full source file path to the toolchain output directory.
SourceDir toolchain_output_dir_;
SourceDir toolchain_gen_dir_;
Scope base_config_;