• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #ifndef TOOLS_GN_SETTINGS_H_
6 #define TOOLS_GN_SETTINGS_H_
7 
8 #include "base/files/file_path.h"
9 #include "base/macros.h"
10 #include "gn/import_manager.h"
11 #include "gn/output_file.h"
12 #include "gn/scope.h"
13 #include "gn/source_dir.h"
14 #include "gn/toolchain.h"
15 
16 class BuildSettings;
17 
18 // Holds the settings for one toolchain invocation. There will be one
19 // Settings object for each toolchain type, each referring to the same
20 // BuildSettings object for shared stuff.
21 //
22 // The Settings object is const once it is constructed, which allows us to
23 // use it from multiple threads during target generation without locking (which
24 // is important, because it gets used a lot).
25 //
26 // The Toolchain object holds the set of stuff that is set by the toolchain
27 // declaration, which obviously needs to be set later when we actually parse
28 // the file with the toolchain declaration in it.
29 class Settings {
30  public:
31   // Constructs a toolchain settings.
32   //
33   // The output_subdir_name is the name we should use for the subdirectory in
34   // the build output directory for this toolchain's outputs. The default
35   // toolchain would use an empty string (it goes in the root build dir).
36   // Otherwise, it must end in a slash.
37   Settings(const BuildSettings* build_settings,
38            const std::string& output_subdir_name);
39 
build_settings()40   const BuildSettings* build_settings() const { return build_settings_; }
41 
42   // The actual Toolchain object pointer is not available on the settings
43   // object because it might not be resolved yet. Code running after the
44   // load is complete can ask the Builder for the Toolchain corresponding to
45   // this label.
toolchain_label()46   const Label& toolchain_label() const { return toolchain_label_; }
set_toolchain_label(const Label & l)47   void set_toolchain_label(const Label& l) { toolchain_label_ = l; }
48 
default_toolchain_label()49   const Label& default_toolchain_label() const {
50     return default_toolchain_label_;
51   }
set_default_toolchain_label(const Label & default_label)52   void set_default_toolchain_label(const Label& default_label) {
53     default_toolchain_label_ = default_label;
54   }
55 
56   // Indicates if this corresponds to the default toolchain.
is_default()57   bool is_default() const {
58     return toolchain_label_ == default_toolchain_label_;
59   }
60 
toolchain_output_subdir()61   const OutputFile& toolchain_output_subdir() const {
62     return toolchain_output_subdir_;
63   }
toolchain_output_dir()64   const SourceDir& toolchain_output_dir() const {
65     return toolchain_output_dir_;
66   }
67 
68   // Directory for generated files.
toolchain_gen_dir()69   const SourceDir& toolchain_gen_dir() const { return toolchain_gen_dir_; }
70 
71   // The import manager caches the result of executing imported files in the
72   // context of a given settings object.
73   //
74   // See the ItemTree getter in GlobalSettings for why this doesn't return a
75   // const pointer.
import_manager()76   ImportManager& import_manager() const { return import_manager_; }
77 
base_config()78   const Scope* base_config() const { return &base_config_; }
base_config()79   Scope* base_config() { return &base_config_; }
80 
81   // Set to true when every target we encounter should be generated. False
82   // means that only targets that have a dependency from (directly or
83   // indirectly) some magic root node are actually generated. See the comments
84   // on ItemTree for more.
greedy_target_generation()85   bool greedy_target_generation() const { return greedy_target_generation_; }
set_greedy_target_generation(bool gtg)86   void set_greedy_target_generation(bool gtg) {
87     greedy_target_generation_ = gtg;
88   }
89 
90  private:
91   const BuildSettings* build_settings_;
92 
93   Label toolchain_label_;
94   Label default_toolchain_label_;
95 
96   mutable ImportManager import_manager_;
97 
98   // The subdirectory inside the build output for this toolchain. For the
99   // default toolchain, this will be empty (since the deafult toolchain's
100   // output directory is the same as the build directory). When nonempty, this
101   // is guaranteed to end in a slash.
102   OutputFile toolchain_output_subdir_;
103 
104   // Full source file path to the toolchain output directory.
105   SourceDir toolchain_output_dir_;
106 
107   SourceDir toolchain_gen_dir_;
108 
109   Scope base_config_;
110 
111   bool greedy_target_generation_ = false;
112 
113   DISALLOW_COPY_AND_ASSIGN(Settings);
114 };
115 
116 #endif  // TOOLS_GN_SETTINGS_H_
117