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
3 // found in the LICENSE file.
5 #ifndef TOOLS_GN_SETTINGS_H_
6 #define TOOLS_GN_SETTINGS_H_
8 #include "base/files/file_path.h"
9 #include "tools/gn/build_settings.h"
10 #include "tools/gn/import_manager.h"
11 #include "tools/gn/output_file.h"
12 #include "tools/gn/scope.h"
13 #include "tools/gn/source_dir.h"
14 #include "tools/gn/toolchain.h"
16 // Holds the settings for one toolchain invocation. There will be one
17 // Settings object for each toolchain type, each referring to the same
18 // BuildSettings object for shared stuff.
20 // The Settings object is const once it is constructed, which allows us to
21 // use it from multiple threads during target generation without locking (which
22 // is important, because it gets used a lot).
24 // The Toolchain object holds the set of stuff that is set by the toolchain
25 // declaration, which obviously needs to be set later when we actually parse
26 // the file with the toolchain declaration in it.
36 // Constructs a toolchain settings. The output_subdir_name is the name we
37 // should use for the subdirectory in the build output directory for this
38 // toolchain's outputs. It should have no slashes in it. The default
39 // toolchain should use an empty string.
40 Settings(const BuildSettings* build_settings,
41 const std::string& output_subdir_name);
44 const BuildSettings* build_settings() const { return build_settings_; }
46 const Label& toolchain_label() const { return toolchain_label_; }
47 void set_toolchain_label(const Label& l) { toolchain_label_ = l; }
49 // Indicates if this corresponds to the default toolchain.
50 bool is_default() const { return is_default_; }
51 void set_is_default(bool id) { is_default_ = id; }
53 bool IsMac() const { return target_os_ == MAC; }
54 bool IsLinux() const { return target_os_ == LINUX; }
55 bool IsWin() const { return target_os_ == WIN; }
57 TargetOS target_os() const { return target_os_; }
58 void set_target_os(TargetOS t) { target_os_ = t; }
60 const OutputFile& toolchain_output_subdir() const {
61 return toolchain_output_subdir_;
63 const SourceDir& toolchain_output_dir() const {
64 return toolchain_output_dir_;
67 // Directory for generated files.
68 const SourceDir& toolchain_gen_dir() const {
69 return toolchain_gen_dir_;
72 // The import manager caches the result of executing imported files in the
73 // context of a given settings object.
75 // See the ItemTree getter in GlobalSettings for why this doesn't return a
77 ImportManager& import_manager() const { return import_manager_; }
79 const Scope* base_config() const { return &base_config_; }
80 Scope* base_config() { return &base_config_; }
82 // Set to true when every target we encounter should be generated. False
83 // means that only targets that have a dependency from (directly or
84 // indirectly) some magic root node are actually generated. See the comments
85 // on ItemTree for more.
86 bool greedy_target_generation() const {
87 return greedy_target_generation_;
89 void set_greedy_target_generation(bool gtg) {
90 greedy_target_generation_ = gtg;
94 const BuildSettings* build_settings_;
96 Label toolchain_label_;
101 mutable ImportManager import_manager_;
103 // The subdirectory inside the build output for this toolchain. For the
104 // default toolchain, this will be empty (since the deafult toolchain's
105 // output directory is the same as the build directory). When nonempty, this
106 // is guaranteed to end in a slash.
107 OutputFile toolchain_output_subdir_;
109 // Full source file path to the toolchain output directory.
110 SourceDir toolchain_output_dir_;
112 SourceDir toolchain_gen_dir_;
116 bool greedy_target_generation_;
118 DISALLOW_COPY_AND_ASSIGN(Settings);
121 #endif // TOOLS_GN_SETTINGS_H_