blob: f44af2e59f46c71d12e392e87ece8b1f6e01502e [file] [log] [blame]
[email protected]0dfcae72014-08-19 22:52:161// 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]0dfcae72014-08-19 22:52:1610#include "base/logging.h"
tfarinaf51a763e2015-08-10 00:55:3811#include "base/macros.h"
sdefresne40451c52016-06-04 12:37:2912#include "tools/gn/label.h"
13#include "tools/gn/label_ptr.h"
[email protected]0dfcae72014-08-19 22:52:1614#include "tools/gn/substitution_list.h"
15#include "tools/gn/substitution_pattern.h"
16
brettw15e0e74f2016-07-26 18:00:2417class ParseNode;
sdefresne40451c52016-06-04 12:37:2918class Pool;
19
[email protected]0dfcae72014-08-19 22:52:1620class Tool {
21 public:
22 enum DepsFormat {
23 DEPS_GCC = 0,
24 DEPS_MSVC = 1
25 };
26
brettw3dab5fe2015-06-29 23:00:1527 enum PrecompiledHeaderType {
28 PCH_NONE = 0,
andybons1ae777a2015-09-17 22:24:3229 PCH_GCC = 1,
30 PCH_MSVC = 2
brettw3dab5fe2015-06-29 23:00:1531 };
32
[email protected]0dfcae72014-08-19 22:52:1633 Tool();
34 ~Tool();
35
brettw15e0e74f2016-07-26 18:00:2436 const ParseNode* defined_from() const { return defined_from_; }
37 void set_defined_from(const ParseNode* df) { defined_from_ = df; }
38
[email protected]0dfcae72014-08-19 22:52:1639 // 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 }
brettw15e0e74f2016-07-26 18:00:2448 void set_command(SubstitutionPattern cmd) {
[email protected]0dfcae72014-08-19 22:52:1649 DCHECK(!complete_);
brettw15e0e74f2016-07-26 18:00:2450 command_ = std::move(cmd);
[email protected]0dfcae72014-08-19 22:52:1651 }
52
53 // Should include a leading "." if nonempty.
54 const std::string& default_output_extension() const {
55 return default_output_extension_;
56 }
brettw15e0e74f2016-07-26 18:00:2457 void set_default_output_extension(std::string ext) {
[email protected]0dfcae72014-08-19 22:52:1658 DCHECK(!complete_);
59 DCHECK(ext.empty() || ext[0] == '.');
brettw15e0e74f2016-07-26 18:00:2460 default_output_extension_ = std::move(ext);
[email protected]0dfcae72014-08-19 22:52:1661 }
62
brettwf2eba7f2016-04-14 18:14:4563 const SubstitutionPattern& default_output_dir() const {
64 return default_output_dir_;
65 }
brettw15e0e74f2016-07-26 18:00:2466 void set_default_output_dir(SubstitutionPattern dir) {
brettwf2eba7f2016-04-14 18:14:4567 DCHECK(!complete_);
brettw15e0e74f2016-07-26 18:00:2468 default_output_dir_ = std::move(dir);
brettwf2eba7f2016-04-14 18:14:4569 }
70
[email protected]0dfcae72014-08-19 22:52:1671 // Dependency file (if supported).
72 const SubstitutionPattern& depfile() const {
73 return depfile_;
74 }
brettw15e0e74f2016-07-26 18:00:2475 void set_depfile(SubstitutionPattern df) {
[email protected]0dfcae72014-08-19 22:52:1676 DCHECK(!complete_);
brettw15e0e74f2016-07-26 18:00:2477 depfile_ = std::move(df);
[email protected]0dfcae72014-08-19 22:52:1678 }
79
80 DepsFormat depsformat() const {
81 return depsformat_;
82 }
83 void set_depsformat(DepsFormat f) {
84 DCHECK(!complete_);
85 depsformat_ = f;
86 }
87
brettw3dab5fe2015-06-29 23:00:1588 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]0dfcae72014-08-19 22:52:1695 const SubstitutionPattern& description() const {
96 return description_;
97 }
brettw15e0e74f2016-07-26 18:00:2498 void set_description(SubstitutionPattern desc) {
[email protected]0dfcae72014-08-19 22:52:1699 DCHECK(!complete_);
brettw15e0e74f2016-07-26 18:00:24100 description_ = std::move(desc);
[email protected]0dfcae72014-08-19 22:52:16101 }
102
103 const std::string& lib_switch() const {
104 return lib_switch_;
105 }
brettw15e0e74f2016-07-26 18:00:24106 void set_lib_switch(std::string s) {
[email protected]0dfcae72014-08-19 22:52:16107 DCHECK(!complete_);
brettw15e0e74f2016-07-26 18:00:24108 lib_switch_ = std::move(s);
[email protected]0dfcae72014-08-19 22:52:16109 }
110
111 const std::string& lib_dir_switch() const {
112 return lib_dir_switch_;
113 }
brettw15e0e74f2016-07-26 18:00:24114 void set_lib_dir_switch(std::string s) {
[email protected]0dfcae72014-08-19 22:52:16115 DCHECK(!complete_);
brettw15e0e74f2016-07-26 18:00:24116 lib_dir_switch_ = std::move(s);
[email protected]0dfcae72014-08-19 22:52:16117 }
118
119 const SubstitutionList& outputs() const {
120 return outputs_;
121 }
brettw15e0e74f2016-07-26 18:00:24122 void set_outputs(SubstitutionList out) {
[email protected]0dfcae72014-08-19 22:52:16123 DCHECK(!complete_);
brettw15e0e74f2016-07-26 18:00:24124 outputs_ = std::move(out);
[email protected]0dfcae72014-08-19 22:52:16125 }
126
127 // Should match files in the outputs() if nonempty.
128 const SubstitutionPattern& link_output() const {
129 return link_output_;
130 }
brettw15e0e74f2016-07-26 18:00:24131 void set_link_output(SubstitutionPattern link_out) {
[email protected]0dfcae72014-08-19 22:52:16132 DCHECK(!complete_);
brettw15e0e74f2016-07-26 18:00:24133 link_output_ = std::move(link_out);
[email protected]0dfcae72014-08-19 22:52:16134 }
135
136 const SubstitutionPattern& depend_output() const {
137 return depend_output_;
138 }
brettw15e0e74f2016-07-26 18:00:24139 void set_depend_output(SubstitutionPattern dep_out) {
[email protected]0dfcae72014-08-19 22:52:16140 DCHECK(!complete_);
brettw15e0e74f2016-07-26 18:00:24141 depend_output_ = std::move(dep_out);
[email protected]0dfcae72014-08-19 22:52:16142 }
143
brettw15e0e74f2016-07-26 18:00:24144 const SubstitutionList& runtime_outputs() const {
145 return runtime_outputs_;
Nico Webere3398c12016-02-11 02:25:20146 }
brettw15e0e74f2016-07-26 18:00:24147 void set_runtime_outputs(SubstitutionList run_out) {
Nico Webere3398c12016-02-11 02:25:20148 DCHECK(!complete_);
brettw15e0e74f2016-07-26 18:00:24149 runtime_outputs_ = std::move(run_out);
Nico Webere3398c12016-02-11 02:25:20150 }
151
[email protected]0dfcae72014-08-19 22:52:16152 const std::string& output_prefix() const {
153 return output_prefix_;
154 }
brettw15e0e74f2016-07-26 18:00:24155 void set_output_prefix(std::string s) {
[email protected]0dfcae72014-08-19 22:52:16156 DCHECK(!complete_);
brettw15e0e74f2016-07-26 18:00:24157 output_prefix_ = std::move(s);
[email protected]0dfcae72014-08-19 22:52:16158 }
159
[email protected]0dfcae72014-08-19 22:52:16160 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 }
brettw15e0e74f2016-07-26 18:00:24171 void set_rspfile(SubstitutionPattern rsp) {
[email protected]0dfcae72014-08-19 22:52:16172 DCHECK(!complete_);
brettw15e0e74f2016-07-26 18:00:24173 rspfile_ = std::move(rsp);
[email protected]0dfcae72014-08-19 22:52:16174 }
175
176 const SubstitutionPattern& rspfile_content() const {
177 return rspfile_content_;
178 }
brettw15e0e74f2016-07-26 18:00:24179 void set_rspfile_content(SubstitutionPattern content) {
[email protected]0dfcae72014-08-19 22:52:16180 DCHECK(!complete_);
brettw15e0e74f2016-07-26 18:00:24181 rspfile_content_ = std::move(content);
[email protected]0dfcae72014-08-19 22:52:16182 }
183
sdefresne40451c52016-06-04 12:37:29184 const LabelPtrPair<Pool>& pool() const { return pool_; }
brettw15e0e74f2016-07-26 18:00:24185 void set_pool(LabelPtrPair<Pool> pool) { pool_ = std::move(pool); }
sdefresne40451c52016-06-04 12:37:29186
[email protected]0dfcae72014-08-19 22:52:16187 // 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
sdefresne40451c52016-06-04 12:37:29205 bool OnResolved(Err* err);
206
tfarina0cac060b2015-04-01 12:29:20207 private:
brettw15e0e74f2016-07-26 18:00:24208 const ParseNode* defined_from_;
209
[email protected]0dfcae72014-08-19 22:52:16210 SubstitutionPattern command_;
211 std::string default_output_extension_;
brettwf2eba7f2016-04-14 18:14:45212 SubstitutionPattern default_output_dir_;
[email protected]0dfcae72014-08-19 22:52:16213 SubstitutionPattern depfile_;
214 DepsFormat depsformat_;
brettw3dab5fe2015-06-29 23:00:15215 PrecompiledHeaderType precompiled_header_type_;
[email protected]0dfcae72014-08-19 22:52:16216 SubstitutionPattern description_;
217 std::string lib_switch_;
218 std::string lib_dir_switch_;
219 SubstitutionList outputs_;
220 SubstitutionPattern link_output_;
221 SubstitutionPattern depend_output_;
brettw15e0e74f2016-07-26 18:00:24222 SubstitutionList runtime_outputs_;
[email protected]0dfcae72014-08-19 22:52:16223 std::string output_prefix_;
[email protected]0dfcae72014-08-19 22:52:16224 bool restat_;
225 SubstitutionPattern rspfile_;
226 SubstitutionPattern rspfile_content_;
sdefresne40451c52016-06-04 12:37:29227 LabelPtrPair<Pool> pool_;
[email protected]0dfcae72014-08-19 22:52:16228
229 bool complete_;
230
231 SubstitutionBits substitution_bits_;
232
233 DISALLOW_COPY_AND_ASSIGN(Tool);
234};
235
236#endif // TOOLS_GN_TOOL_H_