[refactor] More post-NSS WebCrypto cleanups (utility functions).
[chromium-blink-merge.git] / tools / gn / tool.h
blob8cd0c7eeddcf8ad10f1ff551278e68855d480fd8
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.
5 #ifndef TOOLS_GN_TOOL_H_
6 #define TOOLS_GN_TOOL_H_
8 #include <string>
10 #include "base/logging.h"
11 #include "base/macros.h"
12 #include "tools/gn/substitution_list.h"
13 #include "tools/gn/substitution_pattern.h"
15 class Tool {
16 public:
17 enum DepsFormat {
18 DEPS_GCC = 0,
19 DEPS_MSVC = 1
22 enum PrecompiledHeaderType {
23 PCH_NONE = 0,
24 PCH_GCC = 1,
25 PCH_MSVC = 2
28 Tool();
29 ~Tool();
31 // Getters/setters ----------------------------------------------------------
33 // After the tool has had its attributes set, the caller must call
34 // SetComplete(), at which point no other changes can be made.
36 // Command to run.
37 const SubstitutionPattern& command() const {
38 return command_;
40 void set_command(const SubstitutionPattern& cmd) {
41 DCHECK(!complete_);
42 command_ = cmd;
45 // Should include a leading "." if nonempty.
46 const std::string& default_output_extension() const {
47 return default_output_extension_;
49 void set_default_output_extension(const std::string& ext) {
50 DCHECK(!complete_);
51 DCHECK(ext.empty() || ext[0] == '.');
52 default_output_extension_ = ext;
55 // Dependency file (if supported).
56 const SubstitutionPattern& depfile() const {
57 return depfile_;
59 void set_depfile(const SubstitutionPattern& df) {
60 DCHECK(!complete_);
61 depfile_ = df;
64 DepsFormat depsformat() const {
65 return depsformat_;
67 void set_depsformat(DepsFormat f) {
68 DCHECK(!complete_);
69 depsformat_ = f;
72 PrecompiledHeaderType precompiled_header_type() const {
73 return precompiled_header_type_;
75 void set_precompiled_header_type(PrecompiledHeaderType pch_type) {
76 precompiled_header_type_ = pch_type;
79 const SubstitutionPattern& description() const {
80 return description_;
82 void set_description(const SubstitutionPattern& desc) {
83 DCHECK(!complete_);
84 description_ = desc;
87 const std::string& lib_switch() const {
88 return lib_switch_;
90 void set_lib_switch(const std::string& s) {
91 DCHECK(!complete_);
92 lib_switch_ = s;
95 const std::string& lib_dir_switch() const {
96 return lib_dir_switch_;
98 void set_lib_dir_switch(const std::string& s) {
99 DCHECK(!complete_);
100 lib_dir_switch_ = s;
103 const SubstitutionList& outputs() const {
104 return outputs_;
106 void set_outputs(const SubstitutionList& out) {
107 DCHECK(!complete_);
108 outputs_ = out;
111 // Should match files in the outputs() if nonempty.
112 const SubstitutionPattern& link_output() const {
113 return link_output_;
115 void set_link_output(const SubstitutionPattern& link_out) {
116 DCHECK(!complete_);
117 link_output_ = link_out;
120 const SubstitutionPattern& depend_output() const {
121 return depend_output_;
123 void set_depend_output(const SubstitutionPattern& dep_out) {
124 DCHECK(!complete_);
125 depend_output_ = dep_out;
128 const std::string& output_prefix() const {
129 return output_prefix_;
131 void set_output_prefix(const std::string& s) {
132 DCHECK(!complete_);
133 output_prefix_ = s;
136 bool restat() const {
137 return restat_;
139 void set_restat(bool r) {
140 DCHECK(!complete_);
141 restat_ = r;
144 const SubstitutionPattern& rspfile() const {
145 return rspfile_;
147 void set_rspfile(const SubstitutionPattern& rsp) {
148 DCHECK(!complete_);
149 rspfile_ = rsp;
152 const SubstitutionPattern& rspfile_content() const {
153 return rspfile_content_;
155 void set_rspfile_content(const SubstitutionPattern& content) {
156 DCHECK(!complete_);
157 rspfile_content_ = content;
160 // Other functions ----------------------------------------------------------
162 // Called when the toolchain is saving this tool, after everything is filled
163 // in.
164 void SetComplete();
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();
172 // Substitutions required by this tool.
173 const SubstitutionBits& substitution_bits() const {
174 DCHECK(complete_);
175 return substitution_bits_;
178 private:
179 SubstitutionPattern command_;
180 std::string default_output_extension_;
181 SubstitutionPattern depfile_;
182 DepsFormat depsformat_;
183 PrecompiledHeaderType precompiled_header_type_;
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_;
191 bool restat_;
192 SubstitutionPattern rspfile_;
193 SubstitutionPattern rspfile_content_;
195 bool complete_;
197 SubstitutionBits substitution_bits_;
199 DISALLOW_COPY_AND_ASSIGN(Tool);
202 #endif // TOOLS_GN_TOOL_H_