OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/substitution_type.h" | 5 #include "tools/gn/substitution_type.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdlib.h> | 8 #include <stdlib.h> |
9 | 9 |
10 #include "tools/gn/err.h" | 10 #include "tools/gn/err.h" |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 type == SUBSTITUTION_SOURCE || | 159 type == SUBSTITUTION_SOURCE || |
160 type == SUBSTITUTION_SOURCE_NAME_PART || | 160 type == SUBSTITUTION_SOURCE_NAME_PART || |
161 type == SUBSTITUTION_SOURCE_FILE_PART || | 161 type == SUBSTITUTION_SOURCE_FILE_PART || |
162 type == SUBSTITUTION_SOURCE_DIR || | 162 type == SUBSTITUTION_SOURCE_DIR || |
163 type == SUBSTITUTION_SOURCE_ROOT_RELATIVE_DIR || | 163 type == SUBSTITUTION_SOURCE_ROOT_RELATIVE_DIR || |
164 type == SUBSTITUTION_SOURCE_GEN_DIR || | 164 type == SUBSTITUTION_SOURCE_GEN_DIR || |
165 type == SUBSTITUTION_SOURCE_OUT_DIR || | 165 type == SUBSTITUTION_SOURCE_OUT_DIR || |
166 type == SUBSTITUTION_SOURCE_TARGET_RELATIVE; | 166 type == SUBSTITUTION_SOURCE_TARGET_RELATIVE; |
167 } | 167 } |
168 | 168 |
| 169 bool IsValidScriptArgsSubstitution(SubstitutionType type) { |
| 170 return IsValidSourceSubstitution(type) || |
| 171 type == SUBSTITUTION_RSP_FILE_NAME; |
| 172 } |
| 173 |
169 bool IsValidToolSubstitution(SubstitutionType type) { | 174 bool IsValidToolSubstitution(SubstitutionType type) { |
170 return type == SUBSTITUTION_LITERAL || | 175 return type == SUBSTITUTION_LITERAL || |
171 type == SUBSTITUTION_OUTPUT || | 176 type == SUBSTITUTION_OUTPUT || |
172 type == SUBSTITUTION_LABEL || | 177 type == SUBSTITUTION_LABEL || |
173 type == SUBSTITUTION_LABEL_NAME || | 178 type == SUBSTITUTION_LABEL_NAME || |
174 type == SUBSTITUTION_ROOT_GEN_DIR || | 179 type == SUBSTITUTION_ROOT_GEN_DIR || |
175 type == SUBSTITUTION_ROOT_OUT_DIR || | 180 type == SUBSTITUTION_ROOT_OUT_DIR || |
176 type == SUBSTITUTION_TARGET_GEN_DIR || | 181 type == SUBSTITUTION_TARGET_GEN_DIR || |
177 type == SUBSTITUTION_TARGET_OUT_DIR || | 182 type == SUBSTITUTION_TARGET_OUT_DIR || |
178 type == SUBSTITUTION_TARGET_OUTPUT_NAME; | 183 type == SUBSTITUTION_TARGET_OUTPUT_NAME; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 return IsValidToolSubstitution(type) || | 234 return IsValidToolSubstitution(type) || |
230 type == SUBSTITUTION_SOURCE; | 235 type == SUBSTITUTION_SOURCE; |
231 } | 236 } |
232 | 237 |
233 bool IsValidCompileXCassetsSubstitution(SubstitutionType type) { | 238 bool IsValidCompileXCassetsSubstitution(SubstitutionType type) { |
234 return IsValidToolSubstitution(type) || | 239 return IsValidToolSubstitution(type) || |
235 type == SUBSTITUTION_LINKER_INPUTS || | 240 type == SUBSTITUTION_LINKER_INPUTS || |
236 type == SUBSTITUTION_BUNDLE_PRODUCT_TYPE; | 241 type == SUBSTITUTION_BUNDLE_PRODUCT_TYPE; |
237 } | 242 } |
238 | 243 |
239 bool EnsureValidSourcesSubstitutions( | 244 bool EnsureValidSubstitutions(const std::vector<SubstitutionType>& types, |
240 const std::vector<SubstitutionType>& types, | 245 bool (*is_valid_subst)(SubstitutionType), |
241 const ParseNode* origin, | 246 const ParseNode* origin, |
242 Err* err) { | 247 Err* err) { |
243 for (size_t i = 0; i < types.size(); i++) { | 248 for (SubstitutionType type : types) { |
244 if (!IsValidSourceSubstitution(types[i])) { | 249 if (!is_valid_subst(type)) { |
245 *err = Err(origin, "Invalid substitution type.", | 250 *err = Err(origin, "Invalid substitution type.", |
246 "The substitution " + std::string(kSubstitutionNames[types[i]]) + | 251 "The substitution " + std::string(kSubstitutionNames[type]) + |
247 " isn't valid for something\n" | 252 " isn't valid for something\n" |
248 "operating on a source file such as this."); | 253 "operating on a source file such as this."); |
249 return false; | 254 return false; |
250 } | 255 } |
251 } | 256 } |
252 return true; | 257 return true; |
253 } | 258 } |
OLD | NEW |