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