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

Side by Side Diff: tools/gn/function_template.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/function_forward_variables_from_unittest.cc ('k') | tools/gn/functions.h » ('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/parse_tree.h" 7 #include "tools/gn/parse_tree.h"
8 #include "tools/gn/scope.h" 8 #include "tools/gn/scope.h"
9 #include "tools/gn/template.h" 9 #include "tools/gn/template.h"
10 #include "tools/gn/value.h" 10 #include "tools/gn/value.h"
(...skipping 10 matching lines...) Expand all
21 " provides a way to add to the built-in target types.\n" 21 " provides a way to add to the built-in target types.\n"
22 "\n" 22 "\n"
23 " The template() function is used to declare a template. To invoke the\n" 23 " The template() function is used to declare a template. To invoke the\n"
24 " template, just use the name of the template like any other target\n" 24 " template, just use the name of the template like any other target\n"
25 " type.\n" 25 " type.\n"
26 "\n" 26 "\n"
27 " Often you will want to declare your template in a special file that\n" 27 " Often you will want to declare your template in a special file that\n"
28 " other files will import (see \"gn help import\") so your template\n" 28 " other files will import (see \"gn help import\") so your template\n"
29 " rule can be shared across build files.\n" 29 " rule can be shared across build files.\n"
30 "\n" 30 "\n"
31 "More details:\n" 31 "Variables and templates:\n"
32 "\n" 32 "\n"
33 " When you call template() it creates a closure around all variables\n" 33 " When you call template() it creates a closure around all variables\n"
34 " currently in scope with the code in the template block. When the\n" 34 " currently in scope with the code in the template block. When the\n"
35 " template is invoked, the closure will be executed.\n" 35 " template is invoked, the closure will be executed.\n"
36 "\n" 36 "\n"
37 " When the template is invoked, the code in the caller is executed and\n" 37 " When the template is invoked, the code in the caller is executed and\n"
38 " passed to the template code as an implicit \"invoker\" variable. The\n" 38 " passed to the template code as an implicit \"invoker\" variable. The\n"
39 " template uses this to read state out of the invoking code.\n" 39 " template uses this to read state out of the invoking code.\n"
40 "\n" 40 "\n"
41 " One thing explicitly excluded from the closure is the \"current\n" 41 " One thing explicitly excluded from the closure is the \"current\n"
42 " directory\" against which relative file names are resolved. The\n" 42 " directory\" against which relative file names are resolved. The\n"
43 " current directory will be that of the invoking code, since typically\n" 43 " current directory will be that of the invoking code, since typically\n"
44 " that code specifies the file names. This means all files internal\n" 44 " that code specifies the file names. This means all files internal\n"
45 " to the template should use absolute names.\n" 45 " to the template should use absolute names.\n"
46 "\n" 46 "\n"
47 " A template will typically forward some or all variables from the\n"
48 " invoking scope to a target that it defines. Often, such variables\n"
49 " might be optional. Use the pattern:\n"
50 "\n"
51 " if (defined(invoker.deps)) {\n"
52 " deps = invoker.deps\n"
53 " }\n"
54 "\n"
55 " The function forward_variables_from() provides a shortcut to forward\n"
56 " one or more or possibly all variables in this manner:\n"
57 "\n"
58 " forward_variables_from(invoker, [\"deps\", \"public_deps\"])\n"
59 "\n"
47 "Target naming:\n" 60 "Target naming:\n"
48 "\n" 61 "\n"
49 " Your template should almost always define a built-in target with the\n" 62 " Your template should almost always define a built-in target with the\n"
50 " name the template invoker specified. For example, if you have an IDL\n" 63 " name the template invoker specified. For example, if you have an IDL\n"
51 " template and somebody does:\n" 64 " template and somebody does:\n"
52 " idl(\"foo\") {...\n" 65 " idl(\"foo\") {...\n"
53 " you will normally want this to expand to something defining a\n" 66 " you will normally want this to expand to something defining a\n"
54 " source_set or static_library named \"foo\" (among other things you may\n" 67 " source_set or static_library named \"foo\" (among other things you may\n"
55 " need). This way, when another target specifies a dependency on\n" 68 " need). This way, when another target specifies a dependency on\n"
56 " \"foo\", the static_library or source_set will be linked.\n" 69 " \"foo\", the static_library or source_set will be linked.\n"
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 err->AppendSubErr(Err(existing_template->GetDefinitionRange(), 181 err->AppendSubErr(Err(existing_template->GetDefinitionRange(),
169 "Previous definition.")); 182 "Previous definition."));
170 return Value(); 183 return Value();
171 } 184 }
172 185
173 scope->AddTemplate(template_name, new Template(scope, function)); 186 scope->AddTemplate(template_name, new Template(scope, function));
174 return Value(); 187 return Value();
175 } 188 }
176 189
177 } // namespace functions 190 } // namespace functions
OLDNEW
« no previous file with comments | « tools/gn/function_forward_variables_from_unittest.cc ('k') | tools/gn/functions.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698