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