[email protected] | 0dfcae7 | 2014-08-19 22:52:16 | [diff] [blame] | 1 | // Copyright 2014 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_TOOL_H_ |
| 6 | #define TOOLS_GN_TOOL_H_ |
| 7 | |
| 8 | #include <string> |
| 9 | |
[email protected] | 0dfcae7 | 2014-08-19 22:52:16 | [diff] [blame] | 10 | #include "base/logging.h" |
tfarina | f51a763e | 2015-08-10 00:55:38 | [diff] [blame] | 11 | #include "base/macros.h" |
[email protected] | 0dfcae7 | 2014-08-19 22:52:16 | [diff] [blame] | 12 | #include "tools/gn/substitution_list.h" |
| 13 | #include "tools/gn/substitution_pattern.h" |
| 14 | |
| 15 | class Tool { |
| 16 | public: |
| 17 | enum DepsFormat { |
| 18 | DEPS_GCC = 0, |
| 19 | DEPS_MSVC = 1 |
| 20 | }; |
| 21 | |
brettw | 3dab5fe | 2015-06-29 23:00:15 | [diff] [blame] | 22 | enum PrecompiledHeaderType { |
| 23 | PCH_NONE = 0, |
andybons | 1ae777a | 2015-09-17 22:24:32 | [diff] [blame^] | 24 | PCH_GCC = 1, |
| 25 | PCH_MSVC = 2 |
brettw | 3dab5fe | 2015-06-29 23:00:15 | [diff] [blame] | 26 | }; |
| 27 | |
[email protected] | 0dfcae7 | 2014-08-19 22:52:16 | [diff] [blame] | 28 | Tool(); |
| 29 | ~Tool(); |
| 30 | |
| 31 | // Getters/setters ---------------------------------------------------------- |
| 32 | // |
| 33 | // After the tool has had its attributes set, the caller must call |
| 34 | // SetComplete(), at which point no other changes can be made. |
| 35 | |
| 36 | // Command to run. |
| 37 | const SubstitutionPattern& command() const { |
| 38 | return command_; |
| 39 | } |
| 40 | void set_command(const SubstitutionPattern& cmd) { |
| 41 | DCHECK(!complete_); |
| 42 | command_ = cmd; |
| 43 | } |
| 44 | |
| 45 | // Should include a leading "." if nonempty. |
| 46 | const std::string& default_output_extension() const { |
| 47 | return default_output_extension_; |
| 48 | } |
| 49 | void set_default_output_extension(const std::string& ext) { |
| 50 | DCHECK(!complete_); |
| 51 | DCHECK(ext.empty() || ext[0] == '.'); |
| 52 | default_output_extension_ = ext; |
| 53 | } |
| 54 | |
| 55 | // Dependency file (if supported). |
| 56 | const SubstitutionPattern& depfile() const { |
| 57 | return depfile_; |
| 58 | } |
| 59 | void set_depfile(const SubstitutionPattern& df) { |
| 60 | DCHECK(!complete_); |
| 61 | depfile_ = df; |
| 62 | } |
| 63 | |
| 64 | DepsFormat depsformat() const { |
| 65 | return depsformat_; |
| 66 | } |
| 67 | void set_depsformat(DepsFormat f) { |
| 68 | DCHECK(!complete_); |
| 69 | depsformat_ = f; |
| 70 | } |
| 71 | |
brettw | 3dab5fe | 2015-06-29 23:00:15 | [diff] [blame] | 72 | PrecompiledHeaderType precompiled_header_type() const { |
| 73 | return precompiled_header_type_; |
| 74 | } |
| 75 | void set_precompiled_header_type(PrecompiledHeaderType pch_type) { |
| 76 | precompiled_header_type_ = pch_type; |
| 77 | } |
| 78 | |
[email protected] | 0dfcae7 | 2014-08-19 22:52:16 | [diff] [blame] | 79 | const SubstitutionPattern& description() const { |
| 80 | return description_; |
| 81 | } |
| 82 | void set_description(const SubstitutionPattern& desc) { |
| 83 | DCHECK(!complete_); |
| 84 | description_ = desc; |
| 85 | } |
| 86 | |
| 87 | const std::string& lib_switch() const { |
| 88 | return lib_switch_; |
| 89 | } |
| 90 | void set_lib_switch(const std::string& s) { |
| 91 | DCHECK(!complete_); |
| 92 | lib_switch_ = s; |
| 93 | } |
| 94 | |
| 95 | const std::string& lib_dir_switch() const { |
| 96 | return lib_dir_switch_; |
| 97 | } |
| 98 | void set_lib_dir_switch(const std::string& s) { |
| 99 | DCHECK(!complete_); |
| 100 | lib_dir_switch_ = s; |
| 101 | } |
| 102 | |
| 103 | const SubstitutionList& outputs() const { |
| 104 | return outputs_; |
| 105 | } |
| 106 | void set_outputs(const SubstitutionList& out) { |
| 107 | DCHECK(!complete_); |
| 108 | outputs_ = out; |
| 109 | } |
| 110 | |
| 111 | // Should match files in the outputs() if nonempty. |
| 112 | const SubstitutionPattern& link_output() const { |
| 113 | return link_output_; |
| 114 | } |
| 115 | void set_link_output(const SubstitutionPattern& link_out) { |
| 116 | DCHECK(!complete_); |
| 117 | link_output_ = link_out; |
| 118 | } |
| 119 | |
| 120 | const SubstitutionPattern& depend_output() const { |
| 121 | return depend_output_; |
| 122 | } |
| 123 | void set_depend_output(const SubstitutionPattern& dep_out) { |
| 124 | DCHECK(!complete_); |
| 125 | depend_output_ = dep_out; |
| 126 | } |
| 127 | |
| 128 | const std::string& output_prefix() const { |
| 129 | return output_prefix_; |
| 130 | } |
| 131 | void set_output_prefix(const std::string& s) { |
| 132 | DCHECK(!complete_); |
| 133 | output_prefix_ = s; |
| 134 | } |
| 135 | |
[email protected] | 0dfcae7 | 2014-08-19 22:52:16 | [diff] [blame] | 136 | bool restat() const { |
| 137 | return restat_; |
| 138 | } |
| 139 | void set_restat(bool r) { |
| 140 | DCHECK(!complete_); |
| 141 | restat_ = r; |
| 142 | } |
| 143 | |
| 144 | const SubstitutionPattern& rspfile() const { |
| 145 | return rspfile_; |
| 146 | } |
| 147 | void set_rspfile(const SubstitutionPattern& rsp) { |
| 148 | DCHECK(!complete_); |
| 149 | rspfile_ = rsp; |
| 150 | } |
| 151 | |
| 152 | const SubstitutionPattern& rspfile_content() const { |
| 153 | return rspfile_content_; |
| 154 | } |
| 155 | void set_rspfile_content(const SubstitutionPattern& content) { |
| 156 | DCHECK(!complete_); |
| 157 | rspfile_content_ = content; |
| 158 | } |
| 159 | |
| 160 | // Other functions ---------------------------------------------------------- |
| 161 | |
| 162 | // Called when the toolchain is saving this tool, after everything is filled |
| 163 | // in. |
| 164 | void SetComplete(); |
| 165 | |
| 166 | // Returns true if this tool has separate outputs for dependency tracking |
| 167 | // and linking. |
| 168 | bool has_separate_solink_files() const { |
| 169 | return !link_output_.empty() || !depend_output_.empty(); |
| 170 | } |
| 171 | |
| 172 | // Substitutions required by this tool. |
| 173 | const SubstitutionBits& substitution_bits() const { |
| 174 | DCHECK(complete_); |
| 175 | return substitution_bits_; |
| 176 | } |
| 177 | |
tfarina | 0cac060b | 2015-04-01 12:29:20 | [diff] [blame] | 178 | private: |
[email protected] | 0dfcae7 | 2014-08-19 22:52:16 | [diff] [blame] | 179 | SubstitutionPattern command_; |
| 180 | std::string default_output_extension_; |
| 181 | SubstitutionPattern depfile_; |
| 182 | DepsFormat depsformat_; |
brettw | 3dab5fe | 2015-06-29 23:00:15 | [diff] [blame] | 183 | PrecompiledHeaderType precompiled_header_type_; |
[email protected] | 0dfcae7 | 2014-08-19 22:52:16 | [diff] [blame] | 184 | SubstitutionPattern description_; |
| 185 | std::string lib_switch_; |
| 186 | std::string lib_dir_switch_; |
| 187 | SubstitutionList outputs_; |
| 188 | SubstitutionPattern link_output_; |
| 189 | SubstitutionPattern depend_output_; |
| 190 | std::string output_prefix_; |
[email protected] | 0dfcae7 | 2014-08-19 22:52:16 | [diff] [blame] | 191 | bool restat_; |
| 192 | SubstitutionPattern rspfile_; |
| 193 | SubstitutionPattern rspfile_content_; |
| 194 | |
| 195 | bool complete_; |
| 196 | |
| 197 | SubstitutionBits substitution_bits_; |
| 198 | |
| 199 | DISALLOW_COPY_AND_ASSIGN(Tool); |
| 200 | }; |
| 201 | |
| 202 | #endif // TOOLS_GN_TOOL_H_ |