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" |
11 #include "tools/gn/target_generator.h" | 11 #include "tools/gn/target_generator.h" |
12 #include "tools/gn/template.h" | 12 #include "tools/gn/template.h" |
13 #include "tools/gn/value.h" | 13 #include "tools/gn/value.h" |
14 #include "tools/gn/variables.h" | 14 #include "tools/gn/variables.h" |
15 | 15 |
16 #define DEPENDENT_CONFIG_VARS \ | 16 #define DEPENDENT_CONFIG_VARS \ |
17 " Dependent configs: all_dependent_configs, public_configs\n" | 17 " Dependent configs: all_dependent_configs, public_configs\n" |
18 #define DEPS_VARS \ | 18 #define DEPS_VARS \ |
19 " Deps: data_deps, deps, public_deps\n" | 19 " Deps: data_deps, deps, public_deps\n" |
20 #define GENERAL_TARGET_VARS \ | 20 #define GENERAL_TARGET_VARS \ |
21 " General: check_includes, configs, data, inputs, output_name,\n" \ | 21 " General: check_includes, configs, data, inputs, output_name,\n" \ |
22 " output_extension, public, sources, testonly, visibility\n" | 22 " output_extension, public, sources, testonly, visibility,\n" \ |
23 " darwin_bundle\n" | |
23 | 24 |
24 namespace functions { | 25 namespace functions { |
25 | 26 |
26 namespace { | 27 namespace { |
27 | 28 |
28 Value ExecuteGenericTarget(const char* target_type, | 29 Value ExecuteGenericTarget(const char* target_type, |
29 Scope* scope, | 30 Scope* scope, |
30 const FunctionCallNode* function, | 31 const FunctionCallNode* function, |
31 const std::vector<Value>& args, | 32 const std::vector<Value>& args, |
32 BlockNode* block, | 33 BlockNode* block, |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
348 | 349 |
349 Value RunGroup(Scope* scope, | 350 Value RunGroup(Scope* scope, |
350 const FunctionCallNode* function, | 351 const FunctionCallNode* function, |
351 const std::vector<Value>& args, | 352 const std::vector<Value>& args, |
352 BlockNode* block, | 353 BlockNode* block, |
353 Err* err) { | 354 Err* err) { |
354 return ExecuteGenericTarget(functions::kGroup, scope, function, args, | 355 return ExecuteGenericTarget(functions::kGroup, scope, function, args, |
355 block, err); | 356 block, err); |
356 } | 357 } |
357 | 358 |
359 // loadable_module ------------------------------------------------------------- | |
360 | |
361 const char kLoadableModule[] = "loadable_module"; | |
362 const char kLoadableModule_HelpShort[] = | |
363 "loadable_module: Declare a loadable module target."; | |
364 const char kLoadableModule_Help[] = | |
365 "loadable_module: Declare a loadable module target.\n" | |
366 "\n" | |
brettw
2015/10/13 23:13:32
Can you add a paragraph at the top here about how
Bons
2015/10/13 23:30:52
Done.
| |
367 " A loadable module will be specified on the linker line for targets\n" | |
368 " listing the loadable module in its \"deps\". If you don't want this\n" | |
369 " (if you don't need to dynamically load the library at runtime), then\n" | |
370 " you should use a \"shared_library\" target type instead.\n" | |
371 "\n" | |
372 "Variables\n" | |
373 "\n" | |
374 CONFIG_VALUES_VARS_HELP | |
375 DEPS_VARS | |
376 DEPENDENT_CONFIG_VARS | |
377 GENERAL_TARGET_VARS; | |
378 | |
379 Value RunLoadableModule(Scope* scope, | |
380 const FunctionCallNode* function, | |
381 const std::vector<Value>& args, | |
382 BlockNode* block, | |
383 Err* err) { | |
384 return ExecuteGenericTarget(functions::kLoadableModule, scope, function, args, | |
385 block, err); | |
386 } | |
387 | |
358 // shared_library -------------------------------------------------------------- | 388 // shared_library -------------------------------------------------------------- |
359 | 389 |
360 const char kSharedLibrary[] = "shared_library"; | 390 const char kSharedLibrary[] = "shared_library"; |
361 const char kSharedLibrary_HelpShort[] = | 391 const char kSharedLibrary_HelpShort[] = |
362 "shared_library: Declare a shared library target."; | 392 "shared_library: Declare a shared library target."; |
363 const char kSharedLibrary_Help[] = | 393 const char kSharedLibrary_Help[] = |
364 "shared_library: Declare a shared library target.\n" | 394 "shared_library: Declare a shared library target.\n" |
365 "\n" | 395 "\n" |
366 " A shared library will be specified on the linker line for targets\n" | 396 " A shared library will be specified on the linker line for targets\n" |
367 " listing the shared library in its \"deps\". If you don't want this\n" | 397 " listing the shared library in its \"deps\". If you don't want this\n" |
368 " (say you dynamically load the library at runtime), then you should\n" | 398 " (say you dynamically load the library at runtime), then you should\n" |
369 " depend on the shared library via \"data_deps\" instead.\n" | 399 " depend on the shared library via \"data_deps\" or, on Darwin\n" |
brettw
2015/10/13 23:13:33
I'd remove "on Darwin platforms" since this should
| |
400 " platforms, use a \"loadable_module\" target type instead.\n" | |
370 "\n" | 401 "\n" |
371 "Variables\n" | 402 "Variables\n" |
372 "\n" | 403 "\n" |
373 CONFIG_VALUES_VARS_HELP | 404 CONFIG_VALUES_VARS_HELP |
374 DEPS_VARS | 405 DEPS_VARS |
375 DEPENDENT_CONFIG_VARS | 406 DEPENDENT_CONFIG_VARS |
376 GENERAL_TARGET_VARS; | 407 GENERAL_TARGET_VARS; |
377 | 408 |
378 Value RunSharedLibrary(Scope* scope, | 409 Value RunSharedLibrary(Scope* scope, |
379 const FunctionCallNode* function, | 410 const FunctionCallNode* function, |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
494 "\n" | 525 "\n" |
495 " target(my_type, \"foo\") {\n" | 526 " target(my_type, \"foo\") {\n" |
496 " ...\n" | 527 " ...\n" |
497 " }\n"; | 528 " }\n"; |
498 Value RunTarget(Scope* scope, | 529 Value RunTarget(Scope* scope, |
499 const FunctionCallNode* function, | 530 const FunctionCallNode* function, |
500 const std::vector<Value>& args, | 531 const std::vector<Value>& args, |
501 BlockNode* block, | 532 BlockNode* block, |
502 Err* err) { | 533 Err* err) { |
503 if (args.size() != 2) { | 534 if (args.size() != 2) { |
504 *err = Err(function, "Expected two arguments.", | 535 *err = Err(function, "Expected two arguments. Try \"gn help target\"."); |
brettw
2015/10/13 23:13:33
I think the old one with two string args is better
Bons
2015/10/13 23:30:52
Ah that was a mistake. I was just trying to remove
| |
505 "Dude, try \"gn help target\"."); | |
506 return Value(); | 536 return Value(); |
507 } | 537 } |
508 | 538 |
509 // The first argument must be a string (the target type). Don't type-check | 539 // The first argument must be a string (the target type). Don't type-check |
510 // the second argument since the target-specific function will do that. | 540 // the second argument since the target-specific function will do that. |
511 if (!args[0].VerifyTypeIs(Value::STRING, err)) | 541 if (!args[0].VerifyTypeIs(Value::STRING, err)) |
512 return Value(); | 542 return Value(); |
513 const std::string& target_type = args[0].string_value(); | 543 const std::string& target_type = args[0].string_value(); |
514 | 544 |
515 // The rest of the args are passed to the function. | 545 // The rest of the args are passed to the function. |
516 std::vector<Value> sub_args(args.begin() + 1, args.end()); | 546 std::vector<Value> sub_args(args.begin() + 1, args.end()); |
517 | 547 |
518 // Run a template if it is one. | 548 // Run a template if it is one. |
519 const Template* templ = scope->GetTemplate(target_type); | 549 const Template* templ = scope->GetTemplate(target_type); |
520 if (templ) | 550 if (templ) |
521 return templ->Invoke(scope, function, sub_args, block, err); | 551 return templ->Invoke(scope, function, sub_args, block, err); |
522 | 552 |
523 // Otherwise, assume the target is a built-in target type. | 553 // Otherwise, assume the target is a built-in target type. |
524 return ExecuteGenericTarget(target_type.c_str(), scope, function, sub_args, | 554 return ExecuteGenericTarget(target_type.c_str(), scope, function, sub_args, |
525 block, err); | 555 block, err); |
526 } | 556 } |
527 | 557 |
528 } // namespace functions | 558 } // namespace functions |
OLD | NEW |