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/functions.h" | 5 #include "tools/gn/functions.h" |
6 | 6 |
7 #include "tools/gn/config_values_generator.h" | 7 #include "tools/gn/config_values_generator.h" |
8 #include "tools/gn/err.h" | 8 #include "tools/gn/err.h" |
9 #include "tools/gn/parse_tree.h" | 9 #include "tools/gn/parse_tree.h" |
10 #include "tools/gn/scope.h" | 10 #include "tools/gn/scope.h" |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 "\n"; | 224 "\n"; |
225 Value RunActionForEach(Scope* scope, | 225 Value RunActionForEach(Scope* scope, |
226 const FunctionCallNode* function, | 226 const FunctionCallNode* function, |
227 const std::vector<Value>& args, | 227 const std::vector<Value>& args, |
228 BlockNode* block, | 228 BlockNode* block, |
229 Err* err) { | 229 Err* err) { |
230 return ExecuteGenericTarget(functions::kActionForEach, scope, function, args, | 230 return ExecuteGenericTarget(functions::kActionForEach, scope, function, args, |
231 block, err); | 231 block, err); |
232 } | 232 } |
233 | 233 |
234 // component ------------------------------------------------------------------- | |
235 | |
236 const char kComponent[] = "component"; | |
237 const char kComponent_HelpShort[] = | |
238 "component: Declare a component target."; | |
239 const char kComponent_Help[] = | |
240 "component: Declare a component target.\n" | |
241 "\n" | |
242 " A component is a shared library, static library, or source set\n" | |
243 " depending on the component mode. This allows a project to separate\n" | |
244 " out a build into shared libraries for faster development (link time is\n" | |
245 " reduced) but to switch to a static build for releases (for better\n" | |
246 " performance).\n" | |
247 "\n" | |
248 " To use this function you must set the value of the \"component_mode\"\n" | |
249 " variable to one of the following strings:\n" | |
250 " - \"shared_library\"\n" | |
251 " - \"static_library\"\n" | |
252 " - \"source_set\"\n" | |
253 " It is an error to call \"component\" without defining the mode\n" | |
254 " (typically this is done in the master build configuration file).\n"; | |
255 | |
256 Value RunComponent(Scope* scope, | |
257 const FunctionCallNode* function, | |
258 const std::vector<Value>& args, | |
259 BlockNode* block, | |
260 Err* err) { | |
261 // A component is either a shared or static library, depending on the value | |
262 // of |component_mode|. | |
263 const Value* component_mode_value = | |
264 scope->GetValue(variables::kComponentMode); | |
265 | |
266 static const char helptext[] = | |
267 "You're declaring a component here but have not defined " | |
268 "\"component_mode\" to\neither \"shared_library\" or \"static_library\"."; | |
269 if (!component_mode_value) { | |
270 *err = Err(function->function(), "No component mode set.", helptext); | |
271 return Value(); | |
272 } | |
273 if (component_mode_value->type() != Value::STRING || | |
274 (component_mode_value->string_value() != functions::kSharedLibrary && | |
275 component_mode_value->string_value() != functions::kStaticLibrary && | |
276 component_mode_value->string_value() != functions::kSourceSet)) { | |
277 *err = Err(function->function(), "Invalid component mode set.", helptext); | |
278 return Value(); | |
279 } | |
280 const std::string& component_mode = component_mode_value->string_value(); | |
281 | |
282 if (!EnsureNotProcessingImport(function, scope, err)) | |
283 return Value(); | |
284 Scope block_scope(scope); | |
285 if (!FillTargetBlockScope(scope, function, component_mode.c_str(), block, | |
286 args, &block_scope, err)) | |
287 return Value(); | |
288 | |
289 block->ExecuteBlockInScope(&block_scope, err); | |
290 if (err->has_error()) | |
291 return Value(); | |
292 | |
293 TargetGenerator::GenerateTarget(&block_scope, function, args, | |
294 component_mode, err); | |
295 | |
296 block_scope.CheckForUnusedVars(err); | |
297 return Value(); | |
298 } | |
299 | |
300 // copy ------------------------------------------------------------------------ | 234 // copy ------------------------------------------------------------------------ |
301 | 235 |
302 const char kCopy[] = "copy"; | 236 const char kCopy[] = "copy"; |
303 const char kCopy_HelpShort[] = | 237 const char kCopy_HelpShort[] = |
304 "copy: Declare a target that copies files."; | 238 "copy: Declare a target that copies files."; |
305 const char kCopy_Help[] = | 239 const char kCopy_Help[] = |
306 "copy: Declare a target that copies files.\n" | 240 "copy: Declare a target that copies files.\n" |
307 "\n" | 241 "\n" |
308 "File name handling\n" | 242 "File name handling\n" |
309 "\n" | 243 "\n" |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 | 449 |
516 Value RunStaticLibrary(Scope* scope, | 450 Value RunStaticLibrary(Scope* scope, |
517 const FunctionCallNode* function, | 451 const FunctionCallNode* function, |
518 const std::vector<Value>& args, | 452 const std::vector<Value>& args, |
519 BlockNode* block, | 453 BlockNode* block, |
520 Err* err) { | 454 Err* err) { |
521 return ExecuteGenericTarget(functions::kStaticLibrary, scope, function, args, | 455 return ExecuteGenericTarget(functions::kStaticLibrary, scope, function, args, |
522 block, err); | 456 block, err); |
523 } | 457 } |
524 | 458 |
525 // test ------------------------------------------------------------------------ | |
526 | |
527 const char kTest[] = "test"; | |
528 const char kTest_HelpShort[] = | |
529 "test: Declares a test target."; | |
530 const char kTest_Help[] = | |
531 "test: Declares a test target.\n" | |
532 "\n" | |
533 " This is like an executable target, but is named differently to make\n" | |
534 " the purpose of the target more obvious. It's possible in the future\n" | |
535 " we can do some enhancements like \"list all of the tests in a given\n" | |
536 " directory\".\n" | |
537 "\n" | |
538 " See \"gn help executable\" for usage.\n"; | |
539 | |
540 Value RunTest(Scope* scope, | |
541 const FunctionCallNode* function, | |
542 const std::vector<Value>& args, | |
543 BlockNode* block, | |
544 Err* err) { | |
545 return ExecuteGenericTarget(functions::kExecutable, scope, function, args, | |
546 block, err); | |
547 } | |
548 | |
549 } // namespace functions | 459 } // namespace functions |
OLD | NEW |