Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(40)

Side by Side Diff: tools/gn/functions_target.cc

Issue 1263053003: Add forward_variables_from() and target() to GN (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More spelling fixes Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/gn/functions.cc ('k') | tools/gn/gn.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/value.h" 13 #include "tools/gn/value.h"
13 #include "tools/gn/variables.h" 14 #include "tools/gn/variables.h"
14 15
15 #define DEPENDENT_CONFIG_VARS \ 16 #define DEPENDENT_CONFIG_VARS \
16 " Dependent configs: all_dependent_configs, public_configs\n" 17 " Dependent configs: all_dependent_configs, public_configs\n"
17 #define DEPS_VARS \ 18 #define DEPS_VARS \
18 " Deps: data_deps, deps, forward_dependent_configs_from, public_deps\n" 19 " Deps: data_deps, deps, forward_dependent_configs_from, public_deps\n"
19 #define GENERAL_TARGET_VARS \ 20 #define GENERAL_TARGET_VARS \
20 " General: check_includes, configs, data, inputs, output_name,\n" \ 21 " General: check_includes, configs, data, inputs, output_name,\n" \
21 " output_extension, public, sources, testonly, visibility\n" 22 " output_extension, public, sources, testonly, visibility\n"
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 451
451 Value RunStaticLibrary(Scope* scope, 452 Value RunStaticLibrary(Scope* scope,
452 const FunctionCallNode* function, 453 const FunctionCallNode* function,
453 const std::vector<Value>& args, 454 const std::vector<Value>& args,
454 BlockNode* block, 455 BlockNode* block,
455 Err* err) { 456 Err* err) {
456 return ExecuteGenericTarget(functions::kStaticLibrary, scope, function, args, 457 return ExecuteGenericTarget(functions::kStaticLibrary, scope, function, args,
457 block, err); 458 block, err);
458 } 459 }
459 460
461 // target ---------------------------------------------------------------------
462
463 const char kTarget[] = "target";
464 const char kTarget_HelpShort[] =
465 "target: Declare an target with the given programmatic type.";
466 const char kTarget_Help[] =
467 "target: Declare an target with the given programmatic type.\n"
468 "\n"
469 " target(target_type_string, target_name_string) { ... }\n"
470 "\n"
471 " The target() function is a way to invoke a built-in target or template\n"
472 " with a type determined at runtime. This is useful for cases where the\n"
473 " type of a target might not be known statically.\n"
474 "\n"
475 " Only templates and built-in target functions are supported for the\n"
476 " target_type_string parameter. Arbitrary functions, configs, and\n"
477 " toolchains are not supported.\n"
478 "\n"
479 " The call:\n"
480 " target(\"source_set\", \"doom_melon\") {\n"
481 " Is equivalent to:\n"
482 " source_set(\"doom_melon\") {\n"
483 "\n"
484 "Example\n"
485 "\n"
486 " if (foo_build_as_shared) {\n"
487 " my_type = \"shared_library\"\n"
488 " } else {\n"
489 " my_type = \"source_set\"\n"
490 " }\n"
491 "\n"
492 " target(my_type, \"foo\") {\n"
493 " ...\n"
494 " }\n";
495 Value RunTarget(Scope* scope,
496 const FunctionCallNode* function,
497 const std::vector<Value>& args,
498 BlockNode* block,
499 Err* err) {
500 if (args.size() != 2) {
501 *err = Err(function, "Expected two arguments.",
502 "Dude, try \"gn help target\".");
503 return Value();
504 }
505
506 // The first argument must be a string (the target type). Don't type-check
507 // the second argument since the target-specific function will do that.
508 if (!args[0].VerifyTypeIs(Value::STRING, err))
509 return Value();
510 const std::string& target_type = args[0].string_value();
511
512 // The rest of the args are passed to the function.
513 std::vector<Value> sub_args(args.begin() + 1, args.end());
514
515 // Run a template if it is one.
516 const Template* templ = scope->GetTemplate(target_type);
517 if (templ)
518 return templ->Invoke(scope, function, sub_args, block, err);
519
520 // Otherwise, assume the target is a built-in target type.
521 return ExecuteGenericTarget(target_type.c_str(), scope, function, sub_args,
522 block, err);
523 }
524
460 } // namespace functions 525 } // namespace functions
OLDNEW
« no previous file with comments | « tools/gn/functions.cc ('k') | tools/gn/gn.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698