OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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_TARGET_H_ | 5 #ifndef TOOLS_GN_TARGET_H_ |
6 #define TOOLS_GN_TARGET_H_ | 6 #define TOOLS_GN_TARGET_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/strings/string_piece.h" | 15 #include "base/strings/string_piece.h" |
16 #include "base/synchronization/lock.h" | 16 #include "base/synchronization/lock.h" |
17 #include "tools/gn/action_values.h" | 17 #include "tools/gn/action_values.h" |
18 #include "tools/gn/config_values.h" | 18 #include "tools/gn/config_values.h" |
19 #include "tools/gn/item.h" | 19 #include "tools/gn/item.h" |
20 #include "tools/gn/label_ptr.h" | 20 #include "tools/gn/label_ptr.h" |
21 #include "tools/gn/ordered_set.h" | 21 #include "tools/gn/ordered_set.h" |
| 22 #include "tools/gn/output_file.h" |
22 #include "tools/gn/source_file.h" | 23 #include "tools/gn/source_file.h" |
23 #include "tools/gn/unique_vector.h" | 24 #include "tools/gn/unique_vector.h" |
24 | 25 |
25 class InputFile; | 26 class InputFile; |
26 class Settings; | 27 class Settings; |
27 class Token; | 28 class Token; |
| 29 class Toolchain; |
28 | 30 |
29 class Target : public Item { | 31 class Target : public Item { |
30 public: | 32 public: |
31 enum OutputType { | 33 enum OutputType { |
32 UNKNOWN, | 34 UNKNOWN, |
33 GROUP, | 35 GROUP, |
34 EXECUTABLE, | 36 EXECUTABLE, |
35 SHARED_LIBRARY, | 37 SHARED_LIBRARY, |
36 STATIC_LIBRARY, | 38 STATIC_LIBRARY, |
37 SOURCE_SET, | 39 SOURCE_SET, |
(...skipping 14 matching lines...) Expand all Loading... |
52 virtual Target* AsTarget() OVERRIDE; | 54 virtual Target* AsTarget() OVERRIDE; |
53 virtual const Target* AsTarget() const OVERRIDE; | 55 virtual const Target* AsTarget() const OVERRIDE; |
54 virtual void OnResolved() OVERRIDE; | 56 virtual void OnResolved() OVERRIDE; |
55 | 57 |
56 OutputType output_type() const { return output_type_; } | 58 OutputType output_type() const { return output_type_; } |
57 void set_output_type(OutputType t) { output_type_ = t; } | 59 void set_output_type(OutputType t) { output_type_ = t; } |
58 | 60 |
59 bool IsLinkable() const; | 61 bool IsLinkable() const; |
60 | 62 |
61 // Will be the empty string to use the target label as the output name. | 63 // Will be the empty string to use the target label as the output name. |
| 64 // See GetComputedOutputName(). |
62 const std::string& output_name() const { return output_name_; } | 65 const std::string& output_name() const { return output_name_; } |
63 void set_output_name(const std::string& name) { output_name_ = name; } | 66 void set_output_name(const std::string& name) { output_name_ = name; } |
64 | 67 |
| 68 // Returns the output name for this target, which is the output_name if |
| 69 // specified, or the target label if not. If the flag is set, it will also |
| 70 // include any output prefix specified on the tool (often "lib" on Linux). |
| 71 // |
| 72 // Because this depends on the tool for this target, the toolchain must |
| 73 // have been set before calling. |
| 74 std::string GetComputedOutputName(bool include_prefix) const; |
| 75 |
65 const std::string& output_extension() const { return output_extension_; } | 76 const std::string& output_extension() const { return output_extension_; } |
66 void set_output_extension(const std::string& extension) { | 77 void set_output_extension(const std::string& extension) { |
67 output_extension_ = extension; | 78 output_extension_ = extension; |
68 } | 79 } |
69 | 80 |
70 const FileList& sources() const { return sources_; } | 81 const FileList& sources() const { return sources_; } |
71 FileList& sources() { return sources_; } | 82 FileList& sources() { return sources_; } |
72 | 83 |
73 // Set to true when all sources are public. This is the default. In this case | 84 // Set to true when all sources are public. This is the default. In this case |
74 // the public headers list should be empty. | 85 // the public headers list should be empty. |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 ActionValues& action_values() { return action_values_; } | 159 ActionValues& action_values() { return action_values_; } |
149 const ActionValues& action_values() const { return action_values_; } | 160 const ActionValues& action_values() const { return action_values_; } |
150 | 161 |
151 const OrderedSet<SourceDir>& all_lib_dirs() const { return all_lib_dirs_; } | 162 const OrderedSet<SourceDir>& all_lib_dirs() const { return all_lib_dirs_; } |
152 const OrderedSet<std::string>& all_libs() const { return all_libs_; } | 163 const OrderedSet<std::string>& all_libs() const { return all_libs_; } |
153 | 164 |
154 const std::set<const Target*>& recursive_hard_deps() const { | 165 const std::set<const Target*>& recursive_hard_deps() const { |
155 return recursive_hard_deps_; | 166 return recursive_hard_deps_; |
156 } | 167 } |
157 | 168 |
| 169 // The toolchain is only known once this target is resolved (all if its |
| 170 // dependencies are known). They will be null until then. Generally, this can |
| 171 // only be used during target writing. |
| 172 const Toolchain* toolchain() const { return toolchain_; } |
| 173 |
| 174 // Sets the toolchain. The toolchain must include a tool for this target |
| 175 // or the error will be set and the function will return false. Unusually, |
| 176 // this function's "err" output is optional since this is commonly used |
| 177 // frequently by unit tests which become needlessly verbose. |
| 178 bool SetToolchain(const Toolchain* toolchain, Err* err = NULL); |
| 179 |
| 180 // Returns outputs from this target. The link output file is the one that |
| 181 // other targets link to when they depend on this target. This will only be |
| 182 // valid for libraries and will be empty for all other target types. |
| 183 // |
| 184 // The dependency output file is the file that should be used to express |
| 185 // a dependency on this one. It could be the same as the link output file |
| 186 // (this will be the case for static libraries). For shared libraries it |
| 187 // could be the same or different than the link output file, depending on the |
| 188 // system. For actions this will be the stamp file. |
| 189 // |
| 190 // These are only known once the target is resolved and will be empty before |
| 191 // that. This is a cache of the files to prevent every target that depends on |
| 192 // a given library from recomputing the same pattern. |
| 193 const OutputFile& link_output_file() const { |
| 194 return link_output_file_; |
| 195 } |
| 196 const OutputFile& dependency_output_file() const { |
| 197 return dependency_output_file_; |
| 198 } |
| 199 |
158 private: | 200 private: |
159 // Pulls necessary information from dependencies to this one when all | 201 // Pulls necessary information from dependencies to this one when all |
160 // dependencies have been resolved. | 202 // dependencies have been resolved. |
161 void PullDependentTargetInfo(); | 203 void PullDependentTargetInfo(); |
162 | 204 |
163 // These each pull specific things from dependencies to this one when all | 205 // These each pull specific things from dependencies to this one when all |
164 // deps have been resolved. | 206 // deps have been resolved. |
165 void PullForwardedDependentConfigs(); | 207 void PullForwardedDependentConfigs(); |
166 void PullRecursiveHardDeps(); | 208 void PullRecursiveHardDeps(); |
167 | 209 |
| 210 // Fills the link and dependency output files when a target is resolved. |
| 211 void FillOutputFiles(); |
| 212 |
168 OutputType output_type_; | 213 OutputType output_type_; |
169 std::string output_name_; | 214 std::string output_name_; |
170 std::string output_extension_; | 215 std::string output_extension_; |
171 | 216 |
172 FileList sources_; | 217 FileList sources_; |
173 bool all_headers_public_; | 218 bool all_headers_public_; |
174 FileList public_headers_; | 219 FileList public_headers_; |
175 FileList inputs_; | 220 FileList inputs_; |
176 FileList data_; | 221 FileList data_; |
177 | 222 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 OrderedSet<SourceDir> all_lib_dirs_; | 255 OrderedSet<SourceDir> all_lib_dirs_; |
211 OrderedSet<std::string> all_libs_; | 256 OrderedSet<std::string> all_libs_; |
212 | 257 |
213 // All hard deps from this target and all dependencies. Filled in when this | 258 // All hard deps from this target and all dependencies. Filled in when this |
214 // target is marked resolved. This will not include the current target. | 259 // target is marked resolved. This will not include the current target. |
215 std::set<const Target*> recursive_hard_deps_; | 260 std::set<const Target*> recursive_hard_deps_; |
216 | 261 |
217 ConfigValues config_values_; // Used for all binary targets. | 262 ConfigValues config_values_; // Used for all binary targets. |
218 ActionValues action_values_; // Used for action[_foreach] targets. | 263 ActionValues action_values_; // Used for action[_foreach] targets. |
219 | 264 |
| 265 // Toolchain used by this target. Null until target is resolved. |
| 266 const Toolchain* toolchain_; |
| 267 |
| 268 // Output files. Null until the target is resolved. |
| 269 OutputFile link_output_file_; |
| 270 OutputFile dependency_output_file_; |
| 271 |
220 DISALLOW_COPY_AND_ASSIGN(Target); | 272 DISALLOW_COPY_AND_ASSIGN(Target); |
221 }; | 273 }; |
222 | 274 |
223 namespace BASE_HASH_NAMESPACE { | 275 namespace BASE_HASH_NAMESPACE { |
224 | 276 |
225 #if defined(COMPILER_GCC) | 277 #if defined(COMPILER_GCC) |
226 template<> struct hash<const Target*> { | 278 template<> struct hash<const Target*> { |
227 std::size_t operator()(const Target* t) const { | 279 std::size_t operator()(const Target* t) const { |
228 return reinterpret_cast<std::size_t>(t); | 280 return reinterpret_cast<std::size_t>(t); |
229 } | 281 } |
230 }; | 282 }; |
231 #elif defined(COMPILER_MSVC) | 283 #elif defined(COMPILER_MSVC) |
232 inline size_t hash_value(const Target* t) { | 284 inline size_t hash_value(const Target* t) { |
233 return reinterpret_cast<size_t>(t); | 285 return reinterpret_cast<size_t>(t); |
234 } | 286 } |
235 #endif // COMPILER... | 287 #endif // COMPILER... |
236 | 288 |
237 } // namespace BASE_HASH_NAMESPACE | 289 } // namespace BASE_HASH_NAMESPACE |
238 | 290 |
239 #endif // TOOLS_GN_TARGET_H_ | 291 #endif // TOOLS_GN_TARGET_H_ |
OLD | NEW |