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 SourceFile; |
17 class Target; | 18 class Target; |
18 | 19 |
19 extern const char kSourceExpansion_Help[]; | 20 extern const char kSourceExpansion_Help[]; |
20 | 21 |
21 // A FileTemplate object implements source expansion for a given "template" | 22 // A FileTemplate object implements source expansion for a given "template" |
22 // (either outputs or args, depending on the target type). | 23 // (either outputs or args, depending on the target type). |
23 // | 24 // |
24 // There are two ways you can use this. You can make a template and then | 25 // There are two ways you can use this. You can make a template and then |
25 // apply a source to it to get a list of outputs manually. Or you can do the | 26 // apply a source to it to get a list of outputs manually. Or you can do the |
26 // actual substitution in Ninja, writing the arguments in a rule and using | 27 // actual substitution in Ninja, writing the arguments in a rule and using |
(...skipping 27 matching lines...) Expand all Loading... |
54 Type type; | 55 Type type; |
55 | 56 |
56 // When type_ == LITERAL, this specifies the literal. | 57 // When type_ == LITERAL, this specifies the literal. |
57 std::string literal; | 58 std::string literal; |
58 }; | 59 }; |
59 | 60 |
60 // Constructs a template from the given value. On error, the err will be | 61 // Constructs a template from the given value. On error, the err will be |
61 // set. In this case you should not use this object. | 62 // set. In this case you should not use this object. |
62 FileTemplate(const Value& t, Err* err); | 63 FileTemplate(const Value& t, Err* err); |
63 FileTemplate(const std::vector<std::string>& t); | 64 FileTemplate(const std::vector<std::string>& t); |
| 65 FileTemplate(const std::vector<SourceFile>& t); |
| 66 |
64 ~FileTemplate(); | 67 ~FileTemplate(); |
65 | 68 |
66 // Returns an output template representing the given target's script | 69 // Returns an output template representing the given target's script |
67 // outputs. | 70 // outputs. |
68 static FileTemplate GetForTargetOutputs(const Target* target); | 71 static FileTemplate GetForTargetOutputs(const Target* target); |
69 | 72 |
70 // Returns true if the given substitution type is used by this template. | 73 // Returns true if the given substitution type is used by this template. |
71 bool IsTypeUsed(Subrange::Type type) const; | 74 bool IsTypeUsed(Subrange::Type type) const; |
72 | 75 |
73 // Returns true if there are any substitutions. | 76 // Returns true if there are any substitutions. |
74 bool has_substitutions() const { return has_substitutions_; } | 77 bool has_substitutions() const { return has_substitutions_; } |
75 | 78 |
76 // Applies this template to the given list of sources, appending all | 79 // Applies this template to the given list of sources, appending all |
77 // results to the given dest list. The sources must be a list for the | 80 // results to the given dest list. The sources must be a list for the |
78 // one that takes a value as an input, otherwise the given error will be set. | 81 // one that takes a value as an input, otherwise the given error will be set. |
79 void Apply(const Value& sources, | 82 void Apply(const Value& sources, |
80 const ParseNode* origin, | 83 const ParseNode* origin, |
81 std::vector<Value>* dest, | 84 std::vector<Value>* dest, |
82 Err* err) const; | 85 Err* err) const; |
| 86 |
| 87 // Low-level version of Apply that handles one source file. The results |
| 88 // will be *appended* to the output. |
83 void ApplyString(const std::string& input, | 89 void ApplyString(const std::string& input, |
84 std::vector<std::string>* output) const; | 90 std::vector<std::string>* output) const; |
85 | 91 |
86 // Writes a string representing the template with Ninja variables for the | 92 // Writes a string representing the template with Ninja variables for the |
87 // substitutions, and the literals escaped for Ninja consumption. | 93 // substitutions, and the literals escaped for Ninja consumption. |
88 // | 94 // |
89 // For example, if the input is "foo{{source_name_part}}bar" this will write | 95 // For example, if the input is "foo{{source_name_part}}bar" this will write |
90 // foo${source_name_part}bar. If there are multiple templates (we were | 96 // foo${source_name_part}bar. If there are multiple templates (we were |
91 // constucted with a list of more than one item) then the values will be | 97 // constucted with a list of more than one item) then the values will be |
92 // separated by spaces. | 98 // separated by spaces. |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 // required. This allows us to precompute these types whem applying them | 147 // required. This allows us to precompute these types whem applying them |
142 // to a given source file. | 148 // to a given source file. |
143 bool types_required_[Subrange::NUM_TYPES]; | 149 bool types_required_[Subrange::NUM_TYPES]; |
144 | 150 |
145 // Set when any of the types_required_ is true. Otherwise, everythins is a | 151 // Set when any of the types_required_ is true. Otherwise, everythins is a |
146 // literal (a common case so we can optimize some code paths). | 152 // literal (a common case so we can optimize some code paths). |
147 bool has_substitutions_; | 153 bool has_substitutions_; |
148 }; | 154 }; |
149 | 155 |
150 #endif // TOOLS_GN_FILE_TEMPLATE_H_ | 156 #endif // TOOLS_GN_FILE_TEMPLATE_H_ |
OLD | NEW |