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 Toolchain* toolchain, 42 const std::string& output_subdir_name); 43 ~Settings(); 44 45 const BuildSettings* build_settings() const { return build_settings_; } 46 47 // Danger: this must only be used for getting the toolchain label until the 48 // toolchain has been resolved. Otherwise, it will be modified on an 49 // arbitrary thread when the toolchain invocation is found. Generally, you 50 // will only read this from the target generation where we know everything 51 // has been resolved and won't change. 52 const Toolchain* toolchain() const { return toolchain_; } 53 54 bool IsMac() const { return target_os_ == MAC; } 55 bool IsLinux() const { return target_os_ == LINUX; } 56 bool IsWin() const { return target_os_ == WIN; } 57 58 TargetOS target_os() const { return target_os_; } 59 void set_target_os(TargetOS t) { target_os_ = t; } 60 61 const OutputFile& toolchain_output_subdir() const { 62 return toolchain_output_subdir_; 63 } 64 const SourceDir& toolchain_output_dir() const { 65 return toolchain_output_dir_; 66 } 67 68 // Directory for generated files. 69 const SourceDir& toolchain_gen_dir() const { 70 return toolchain_gen_dir_; 71 } 72 73 // The import manager caches the result of executing imported files in the 74 // context of a given settings object. 75 // 76 // See the ItemTree getter in GlobalSettings for why this doesn't return a 77 // const pointer. 78 ImportManager& import_manager() const { return import_manager_; } 79 80 const Scope* base_config() const { return &base_config_; } 81 Scope* base_config() { return &base_config_; } 82 83 // Set to true when every target we encounter should be generated. False 84 // means that only targets that have a dependency from (directly or 85 // indirectly) some magic root node are actually generated. See the comments 86 // on ItemTree for more. 87 bool greedy_target_generation() const { 88 return greedy_target_generation_; 89 } 90 void set_greedy_target_generation(bool gtg) { 91 greedy_target_generation_ = gtg; 92 } 93 94 private: 95 const BuildSettings* build_settings_; 96 97 const Toolchain* toolchain_; 98 99 TargetOS target_os_; 100 101 mutable ImportManager import_manager_; 102 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_; 108 109 // Full source file path to the toolchain output directory. 110 SourceDir toolchain_output_dir_; 111 112 SourceDir toolchain_gen_dir_; 113 114 Scope base_config_; 115 116 bool greedy_target_generation_; 117 118 DISALLOW_COPY_AND_ASSIGN(Settings); 119 }; 120 121 #endif // TOOLS_GN_SETTINGS_H_ 122