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. 37 // 38 // The output_subdir_name is the name we should use for the subdirectory in 39 // the build output directory for this toolchain's outputs. The default 40 // toolchain would use an empty string (it goes in the root build dir). 41 // Otherwise, it must end in a slash. 42 Settings(const BuildSettings* build_settings, 43 const std::string& output_subdir_name); 44 ~Settings(); 45 build_settings()46 const BuildSettings* build_settings() const { return build_settings_; } 47 toolchain_label()48 const Label& toolchain_label() const { return toolchain_label_; } set_toolchain_label(const Label & l)49 void set_toolchain_label(const Label& l) { toolchain_label_ = l; } 50 default_toolchain_label()51 const Label& default_toolchain_label() const { 52 return default_toolchain_label_; 53 } set_default_toolchain_label(const Label & default_label)54 void set_default_toolchain_label(const Label& default_label) { 55 default_toolchain_label_ = default_label; 56 } 57 58 // Indicates if this corresponds to the default toolchain. is_default()59 bool is_default() const { 60 return toolchain_label_ == default_toolchain_label_; 61 } 62 IsMac()63 bool IsMac() const { return target_os_ == MAC; } IsLinux()64 bool IsLinux() const { return target_os_ == LINUX; } IsWin()65 bool IsWin() const { return target_os_ == WIN; } 66 target_os()67 TargetOS target_os() const { return target_os_; } set_target_os(TargetOS t)68 void set_target_os(TargetOS t) { target_os_ = t; } 69 toolchain_output_subdir()70 const OutputFile& toolchain_output_subdir() const { 71 return toolchain_output_subdir_; 72 } toolchain_output_dir()73 const SourceDir& toolchain_output_dir() const { 74 return toolchain_output_dir_; 75 } 76 77 // Directory for generated files. toolchain_gen_dir()78 const SourceDir& toolchain_gen_dir() const { 79 return toolchain_gen_dir_; 80 } 81 82 // The import manager caches the result of executing imported files in the 83 // context of a given settings object. 84 // 85 // See the ItemTree getter in GlobalSettings for why this doesn't return a 86 // const pointer. import_manager()87 ImportManager& import_manager() const { return import_manager_; } 88 base_config()89 const Scope* base_config() const { return &base_config_; } base_config()90 Scope* base_config() { return &base_config_; } 91 92 // Set to true when every target we encounter should be generated. False 93 // means that only targets that have a dependency from (directly or 94 // indirectly) some magic root node are actually generated. See the comments 95 // on ItemTree for more. greedy_target_generation()96 bool greedy_target_generation() const { 97 return greedy_target_generation_; 98 } set_greedy_target_generation(bool gtg)99 void set_greedy_target_generation(bool gtg) { 100 greedy_target_generation_ = gtg; 101 } 102 103 private: 104 const BuildSettings* build_settings_; 105 106 Label toolchain_label_; 107 Label default_toolchain_label_; 108 109 TargetOS target_os_; 110 111 mutable ImportManager import_manager_; 112 113 // The subdirectory inside the build output for this toolchain. For the 114 // default toolchain, this will be empty (since the deafult toolchain's 115 // output directory is the same as the build directory). When nonempty, this 116 // is guaranteed to end in a slash. 117 OutputFile toolchain_output_subdir_; 118 119 // Full source file path to the toolchain output directory. 120 SourceDir toolchain_output_dir_; 121 122 SourceDir toolchain_gen_dir_; 123 124 Scope base_config_; 125 126 bool greedy_target_generation_; 127 128 DISALLOW_COPY_AND_ASSIGN(Settings); 129 }; 130 131 #endif // TOOLS_GN_SETTINGS_H_ 132