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 { | 16 namespace { |
17 | 17 |
18 // Returns true if the list of files looks like it might have a {{ }} pattern | 18 // Returns true if the list of files looks like it might have a {{ }} pattern |
19 // in it. Used for error checking. | 19 // in it. Used for error checking. |
20 bool FileListHasPattern(const Target::FileList& files) { | 20 bool StringListHasPattern(const std::vector<std::string>& files) { |
21 for (size_t i = 0; i < files.size(); i++) { | 21 for (size_t i = 0; i < files.size(); i++) { |
22 if (files[i].value().find("{{") != std::string::npos && | 22 if (files[i].find("{{") != std::string::npos && |
23 files[i].value().find("}}") != std::string::npos) | 23 files[i].find("}}") != std::string::npos) |
24 return true; | 24 return true; |
25 } | 25 } |
26 return false; | 26 return false; |
27 } | 27 } |
28 | 28 |
29 } // namespace | 29 } // namespace |
30 | 30 |
31 ActionTargetGenerator::ActionTargetGenerator( | 31 ActionTargetGenerator::ActionTargetGenerator( |
32 Target* target, | 32 Target* target, |
33 Scope* scope, | 33 Scope* scope, |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 return; | 101 return; |
102 } | 102 } |
103 target_->action_values().set_script(script_file); | 103 target_->action_values().set_script(script_file); |
104 } | 104 } |
105 | 105 |
106 void ActionTargetGenerator::FillScriptArgs() { | 106 void ActionTargetGenerator::FillScriptArgs() { |
107 const Value* value = scope_->GetValue(variables::kArgs, true); | 107 const Value* value = scope_->GetValue(variables::kArgs, true); |
108 if (!value) | 108 if (!value) |
109 return; | 109 return; |
110 | 110 |
111 std::vector<std::string> args; | 111 if (!ExtractListOfStringValues(*value, &target_->action_values().args(), |
112 if (!ExtractListOfStringValues(*value, &args, err_)) | 112 err_)) |
113 return; | 113 return; |
114 target_->action_values().swap_in_args(&args); | |
115 } | 114 } |
116 | 115 |
117 void ActionTargetGenerator::FillDepfile() { | 116 void ActionTargetGenerator::FillDepfile() { |
118 const Value* value = scope_->GetValue(variables::kDepfile, true); | 117 const Value* value = scope_->GetValue(variables::kDepfile, true); |
119 if (!value) | 118 if (!value) |
120 return; | 119 return; |
121 target_->action_values().set_depfile( | 120 target_->action_values().set_depfile( |
122 scope_->settings()->build_settings()->build_dir().ResolveRelativeFile( | 121 scope_->settings()->build_settings()->build_dir().ResolveRelativeFile( |
123 value->string_value())); | 122 value->string_value())); |
124 } | 123 } |
125 | 124 |
126 void ActionTargetGenerator::CheckOutputs() { | 125 void ActionTargetGenerator::CheckOutputs() { |
127 const Target::FileList& outputs = target_->action_values().outputs(); | 126 const std::vector<std::string>& outputs = target_->action_values().outputs(); |
128 if (outputs.empty()) { | 127 if (outputs.empty()) { |
129 *err_ = Err(function_call_, "Action has no outputs.", | 128 *err_ = Err(function_call_, "Action has no outputs.", |
130 "If you have no outputs, the build system can not tell when your\n" | 129 "If you have no outputs, the build system can not tell when your\n" |
131 "script needs to be run."); | 130 "script needs to be run."); |
132 return; | 131 return; |
133 } | 132 } |
134 | 133 |
135 if (output_type_ == Target::ACTION) { | 134 if (output_type_ == Target::ACTION) { |
136 // Make sure the outputs for an action have no patterns in them. | 135 // Make sure the outputs for an action have no patterns in them. |
137 if (FileListHasPattern(outputs)) { | 136 if (StringListHasPattern(outputs)) { |
138 *err_ = Err(function_call_, "Action has patterns in the output.", | 137 *err_ = Err(function_call_, "Action has patterns in the output.", |
139 "An action target should have the outputs completely specified. If\n" | 138 "An action target should have the outputs completely specified. If\n" |
140 "you want to provide a mapping from source to output, use an\n" | 139 "you want to provide a mapping from source to output, use an\n" |
141 "\"action_foreach\" target."); | 140 "\"action_foreach\" target."); |
142 return; | 141 return; |
143 } | 142 } |
144 } else if (output_type_ == Target::ACTION_FOREACH) { | 143 } else if (output_type_ == Target::ACTION_FOREACH) { |
145 // A foreach target should always have a pattern in the outputs. | 144 // A foreach target should always have a pattern in the outputs. |
146 if (!FileListHasPattern(outputs)) { | 145 if (!StringListHasPattern(outputs)) { |
147 *err_ = Err(function_call_, | 146 *err_ = Err(function_call_, |
148 "action_foreach should have a pattern in the output.", | 147 "action_foreach should have a pattern in the output.", |
149 "An action_foreach target should have a source expansion pattern in\n" | 148 "An action_foreach target should have a source expansion pattern in\n" |
150 "it to map source file to unique output file name. Otherwise, the\n" | 149 "it to map source file to unique output file name. Otherwise, the\n" |
151 "build system can't determine when your script needs to be run."); | 150 "build system can't determine when your script needs to be run."); |
152 return; | 151 return; |
153 } | 152 } |
154 } | 153 } |
155 } | 154 } |
OLD | NEW |