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