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 #include "tools/gn/action_target_generator.h" | 5 #include "tools/gn/action_target_generator.h" |
6 | 6 |
7 #include "tools/gn/build_settings.h" | 7 #include "tools/gn/build_settings.h" |
8 #include "tools/gn/err.h" | 8 #include "tools/gn/err.h" |
9 #include "tools/gn/filesystem_utils.h" | 9 #include "tools/gn/filesystem_utils.h" |
10 #include "tools/gn/parse_tree.h" | 10 #include "tools/gn/parse_tree.h" |
11 #include "tools/gn/scope.h" | 11 #include "tools/gn/scope.h" |
12 #include "tools/gn/value.h" | 12 #include "tools/gn/value.h" |
13 #include "tools/gn/value_extractors.h" | 13 #include "tools/gn/value_extractors.h" |
14 #include "tools/gn/variables.h" | 14 #include "tools/gn/variables.h" |
15 | 15 |
16 namespace { | |
17 | |
18 // Returns true if the list of files looks like it might have a {{ }} pattern | |
19 // in it. Used for error checking. | |
20 bool StringListHasPattern(const std::vector<std::string>& files) { | |
21 for (size_t i = 0; i < files.size(); i++) { | |
22 if (files[i].find("{{") != std::string::npos && | |
23 files[i].find("}}") != std::string::npos) | |
24 return true; | |
25 } | |
26 return false; | |
27 } | |
28 | |
29 } // namespace | |
30 | |
31 ActionTargetGenerator::ActionTargetGenerator( | 16 ActionTargetGenerator::ActionTargetGenerator( |
32 Target* target, | 17 Target* target, |
33 Scope* scope, | 18 Scope* scope, |
34 const FunctionCallNode* function_call, | 19 const FunctionCallNode* function_call, |
35 Target::OutputType type, | 20 Target::OutputType type, |
36 Err* err) | 21 Err* err) |
37 : TargetGenerator(target, scope, function_call, err), | 22 : TargetGenerator(target, scope, function_call, err), |
38 output_type_(type) { | 23 output_type_(type) { |
39 } | 24 } |
40 | 25 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 return; | 86 return; |
102 } | 87 } |
103 target_->action_values().set_script(script_file); | 88 target_->action_values().set_script(script_file); |
104 } | 89 } |
105 | 90 |
106 void ActionTargetGenerator::FillScriptArgs() { | 91 void ActionTargetGenerator::FillScriptArgs() { |
107 const Value* value = scope_->GetValue(variables::kArgs, true); | 92 const Value* value = scope_->GetValue(variables::kArgs, true); |
108 if (!value) | 93 if (!value) |
109 return; | 94 return; |
110 | 95 |
111 if (!ExtractListOfStringValues(*value, &target_->action_values().args(), | 96 if (!target_->action_values().args().Parse(*value, err_)) |
112 err_)) | |
113 return; | 97 return; |
114 } | 98 } |
115 | 99 |
116 void ActionTargetGenerator::FillDepfile() { | 100 void ActionTargetGenerator::FillDepfile() { |
117 const Value* value = scope_->GetValue(variables::kDepfile, true); | 101 const Value* value = scope_->GetValue(variables::kDepfile, true); |
118 if (!value) | 102 if (!value) |
119 return; | 103 return; |
120 target_->action_values().set_depfile( | 104 |
121 scope_->settings()->build_settings()->build_dir().ResolveRelativeFile( | 105 SubstitutionPattern depfile; |
122 value->string_value())); | 106 if (!depfile.Parse(*value, err_)) |
| 107 return; |
| 108 if (!EnsureSubstitutionIsInOutputDir(depfile, *value)) |
| 109 return; |
| 110 |
| 111 target_->action_values().set_depfile(depfile); |
123 } | 112 } |
124 | 113 |
125 void ActionTargetGenerator::CheckOutputs() { | 114 void ActionTargetGenerator::CheckOutputs() { |
126 const std::vector<std::string>& outputs = target_->action_values().outputs(); | 115 const SubstitutionList& outputs = target_->action_values().outputs(); |
127 if (outputs.empty()) { | 116 if (outputs.list().empty()) { |
128 *err_ = Err(function_call_, "Action has no outputs.", | 117 *err_ = Err(function_call_, "Action has no outputs.", |
129 "If you have no outputs, the build system can not tell when your\n" | 118 "If you have no outputs, the build system can not tell when your\n" |
130 "script needs to be run."); | 119 "script needs to be run."); |
131 return; | 120 return; |
132 } | 121 } |
133 | 122 |
134 if (output_type_ == Target::ACTION) { | 123 if (output_type_ == Target::ACTION) { |
135 // Make sure the outputs for an action have no patterns in them. | 124 if (!outputs.required_types().empty()) { |
136 if (StringListHasPattern(outputs)) { | |
137 *err_ = Err(function_call_, "Action has patterns in the output.", | 125 *err_ = Err(function_call_, "Action has patterns in the output.", |
138 "An action target should have the outputs completely specified. If\n" | 126 "An action target should have the outputs completely specified. If\n" |
139 "you want to provide a mapping from source to output, use an\n" | 127 "you want to provide a mapping from source to output, use an\n" |
140 "\"action_foreach\" target."); | 128 "\"action_foreach\" target."); |
141 return; | 129 return; |
142 } | 130 } |
143 } else if (output_type_ == Target::ACTION_FOREACH) { | 131 } else if (output_type_ == Target::ACTION_FOREACH) { |
144 // A foreach target should always have a pattern in the outputs. | 132 // A foreach target should always have a pattern in the outputs. |
145 if (!StringListHasPattern(outputs)) { | 133 if (outputs.required_types().empty()) { |
146 *err_ = Err(function_call_, | 134 *err_ = Err(function_call_, |
147 "action_foreach should have a pattern in the output.", | 135 "action_foreach should have a pattern in the output.", |
148 "An action_foreach target should have a source expansion pattern in\n" | 136 "An action_foreach target should have a source expansion pattern in\n" |
149 "it to map source file to unique output file name. Otherwise, the\n" | 137 "it to map source file to unique output file name. Otherwise, the\n" |
150 "build system can't determine when your script needs to be run."); | 138 "build system can't determine when your script needs to be run."); |
151 return; | 139 return; |
152 } | 140 } |
153 } | 141 } |
154 } | 142 } |
OLD | NEW |