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_FILE_TEMPLATE_H_ | 5 #ifndef TOOLS_GN_FILE_TEMPLATE_H_ |
6 #define TOOLS_GN_FILE_TEMPLATE_H_ | 6 #define TOOLS_GN_FILE_TEMPLATE_H_ |
7 | 7 |
8 #include <iosfwd> | 8 #include <iosfwd> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/containers/stack_container.h" | 11 #include "base/containers/stack_container.h" |
12 #include "tools/gn/err.h" | 12 #include "tools/gn/err.h" |
13 #include "tools/gn/value.h" | 13 #include "tools/gn/value.h" |
14 | 14 |
15 struct EscapeOptions; | 15 struct EscapeOptions; |
16 class ParseNode; | 16 class ParseNode; |
| 17 class Target; |
17 | 18 |
18 extern const char kSourceExpansion_Help[]; | 19 extern const char kSourceExpansion_Help[]; |
19 | 20 |
20 // A FileTemplate object implements source expansion for a given "template" | 21 // A FileTemplate object implements source expansion for a given "template" |
21 // (either outputs or args, depending on the target type). | 22 // (either outputs or args, depending on the target type). |
22 // | 23 // |
23 // There are two ways you can use this. You can make a template and then | 24 // There are two ways you can use this. You can make a template and then |
24 // apply a source to it to get a list of outputs manually. Or you can do the | 25 // apply a source to it to get a list of outputs manually. Or you can do the |
25 // actual substitution in Ninja, writing the arguments in a rule and using | 26 // actual substitution in Ninja, writing the arguments in a rule and using |
26 // variables in build statements to invoke the rule with the right | 27 // variables in build statements to invoke the rule with the right |
(...skipping 28 matching lines...) Expand all Loading... |
55 // When type_ == LITERAL, this specifies the literal. | 56 // When type_ == LITERAL, this specifies the literal. |
56 std::string literal; | 57 std::string literal; |
57 }; | 58 }; |
58 | 59 |
59 // Constructs a template from the given value. On error, the err will be | 60 // Constructs a template from the given value. On error, the err will be |
60 // set. In this case you should not use this object. | 61 // set. In this case you should not use this object. |
61 FileTemplate(const Value& t, Err* err); | 62 FileTemplate(const Value& t, Err* err); |
62 FileTemplate(const std::vector<std::string>& t); | 63 FileTemplate(const std::vector<std::string>& t); |
63 ~FileTemplate(); | 64 ~FileTemplate(); |
64 | 65 |
| 66 // Returns an output template representing the given target's script |
| 67 // outputs. |
| 68 static FileTemplate GetForTargetOutputs(const Target* target); |
| 69 |
65 // Returns true if the given substitution type is used by this template. | 70 // Returns true if the given substitution type is used by this template. |
66 bool IsTypeUsed(Subrange::Type type) const; | 71 bool IsTypeUsed(Subrange::Type type) const; |
67 | 72 |
68 // Returns true if there are any substitutions. | 73 // Returns true if there are any substitutions. |
69 bool has_substitutions() const { return has_substitutions_; } | 74 bool has_substitutions() const { return has_substitutions_; } |
70 | 75 |
71 // Applies this template to the given list of sources, appending all | 76 // Applies this template to the given list of sources, appending all |
72 // results to the given dest list. The sources must be a list for the | 77 // results to the given dest list. The sources must be a list for the |
73 // one that takes a value as an input, otherwise the given error will be set. | 78 // one that takes a value as an input, otherwise the given error will be set. |
74 void Apply(const Value& sources, | 79 void Apply(const Value& sources, |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 // required. This allows us to precompute these types whem applying them | 141 // required. This allows us to precompute these types whem applying them |
137 // to a given source file. | 142 // to a given source file. |
138 bool types_required_[Subrange::NUM_TYPES]; | 143 bool types_required_[Subrange::NUM_TYPES]; |
139 | 144 |
140 // Set when any of the types_required_ is true. Otherwise, everythins is a | 145 // Set when any of the types_required_ is true. Otherwise, everythins is a |
141 // literal (a common case so we can optimize some code paths). | 146 // literal (a common case so we can optimize some code paths). |
142 bool has_substitutions_; | 147 bool has_substitutions_; |
143 }; | 148 }; |
144 | 149 |
145 #endif // TOOLS_GN_FILE_TEMPLATE_H_ | 150 #endif // TOOLS_GN_FILE_TEMPLATE_H_ |
OLD | NEW |