• 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 "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"
15 
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.
19 //
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).
23 //
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.
27 class Settings {
28  public:
29   enum TargetOS {
30     UNKNOWN,
31     LINUX,
32     MAC,
33     WIN
34   };
35 
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);
42   ~Settings();
43 
build_settings()44   const BuildSettings* build_settings() const { return build_settings_; }
45 
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 
IsMac()61   bool IsMac() const { return target_os_ == MAC; }
IsLinux()62   bool IsLinux() const { return target_os_ == LINUX; }
IsWin()63   bool IsWin() const { return target_os_ == WIN; }
64 
target_os()65   TargetOS target_os() const { return target_os_; }
set_target_os(TargetOS t)66   void set_target_os(TargetOS t) { target_os_ = t; }
67 
toolchain_output_subdir()68   const OutputFile& toolchain_output_subdir() const {
69     return toolchain_output_subdir_;
70   }
toolchain_output_dir()71   const SourceDir& toolchain_output_dir() const {
72     return toolchain_output_dir_;
73   }
74 
75   // Directory for generated files.
toolchain_gen_dir()76   const SourceDir& toolchain_gen_dir() const {
77     return toolchain_gen_dir_;
78   }
79 
80   // The import manager caches the result of executing imported files in the
81   // context of a given settings object.
82   //
83   // See the ItemTree getter in GlobalSettings for why this doesn't return a
84   // const pointer.
import_manager()85   ImportManager& import_manager() const { return import_manager_; }
86 
base_config()87   const Scope* base_config() const { return &base_config_; }
base_config()88   Scope* base_config() { return &base_config_; }
89 
90   // Set to true when every target we encounter should be generated. False
91   // means that only targets that have a dependency from (directly or
92   // indirectly) some magic root node are actually generated. See the comments
93   // on ItemTree for more.
greedy_target_generation()94   bool greedy_target_generation() const {
95     return greedy_target_generation_;
96   }
set_greedy_target_generation(bool gtg)97   void set_greedy_target_generation(bool gtg) {
98     greedy_target_generation_ = gtg;
99   }
100 
101  private:
102   const BuildSettings* build_settings_;
103 
104   Label toolchain_label_;
105   Label default_toolchain_label_;
106 
107   TargetOS target_os_;
108 
109   mutable ImportManager import_manager_;
110 
111   // The subdirectory inside the build output for this toolchain. For the
112   // default toolchain, this will be empty (since the deafult toolchain's
113   // output directory is the same as the build directory). When nonempty, this
114   // is guaranteed to end in a slash.
115   OutputFile toolchain_output_subdir_;
116 
117   // Full source file path to the toolchain output directory.
118   SourceDir toolchain_output_dir_;
119 
120   SourceDir toolchain_gen_dir_;
121 
122   Scope base_config_;
123 
124   bool greedy_target_generation_;
125 
126   DISALLOW_COPY_AND_ASSIGN(Settings);
127 };
128 
129 #endif  // TOOLS_GN_SETTINGS_H_
130