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

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

Issue 1361263004: GN: Don't allow nested things inside template invocations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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
« tools/gn/functions.h ('K') | « tools/gn/functions.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/template.h" 5 #include "tools/gn/template.h"
6 6
7 #include "tools/gn/err.h" 7 #include "tools/gn/err.h"
8 #include "tools/gn/functions.h" 8 #include "tools/gn/functions.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 23 matching lines...) Expand all
34 if (!EnsureNotProcessingImport(invocation, scope, err)) 34 if (!EnsureNotProcessingImport(invocation, scope, err))
35 return Value(); 35 return Value();
36 36
37 // First run the invocation's block. Need to allocate the scope on the heap 37 // First run the invocation's block. Need to allocate the scope on the heap
38 // so we can pass ownership to the template. 38 // so we can pass ownership to the template.
39 scoped_ptr<Scope> invocation_scope(new Scope(scope)); 39 scoped_ptr<Scope> invocation_scope(new Scope(scope));
40 if (!FillTargetBlockScope(scope, invocation, 40 if (!FillTargetBlockScope(scope, invocation,
41 invocation->function().value().as_string(), 41 invocation->function().value().as_string(),
42 block, args, invocation_scope.get(), err)) 42 block, args, invocation_scope.get(), err))
43 return Value(); 43 return Value();
44 block->Execute(invocation_scope.get(), err); 44
45 if (err->has_error()) 45 {
46 return Value(); 46 // Don't allow the block of the template invocation to include other
47 // targets configs, or template invocations. This must only be applied
48 // to the invoker's block rather than the whole function because the
49 // template execution itself must be able to define targets, etc.
50 NonNestableBlock non_nestable(scope, invocation, "template invocation");
51 if (!non_nestable.Enter(err))
52 return Value();
53
54 block->Execute(invocation_scope.get(), err);
55 if (err->has_error())
56 return Value();
57 }
47 58
48 // Set up the scope to run the template and set the current directory for the 59 // Set up the scope to run the template and set the current directory for the
49 // template (which ScopePerFileProvider uses to base the target-related 60 // template (which ScopePerFileProvider uses to base the target-related
50 // variables target_gen_dir and target_out_dir on) to be that of the invoker. 61 // variables target_gen_dir and target_out_dir on) to be that of the invoker.
51 // This way, files don't have to be rebased and target_*_dir works the way 62 // This way, files don't have to be rebased and target_*_dir works the way
52 // people expect (otherwise its to easy to be putting generated files in the 63 // people expect (otherwise its to easy to be putting generated files in the
53 // gen dir corresponding to an imported file). 64 // gen dir corresponding to an imported file).
54 Scope template_scope(closure_.get()); 65 Scope template_scope(closure_.get());
55 template_scope.set_source_dir(scope->GetSourceDir()); 66 template_scope.set_source_dir(scope->GetSourceDir());
56 67
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 // Check for unused variables in the template itself. 116 // Check for unused variables in the template itself.
106 if (!template_scope.CheckForUnusedVars(err)) 117 if (!template_scope.CheckForUnusedVars(err))
107 return Value(); 118 return Value();
108 119
109 return result; 120 return result;
110 } 121 }
111 122
112 LocationRange Template::GetDefinitionRange() const { 123 LocationRange Template::GetDefinitionRange() const {
113 return definition_->GetRange(); 124 return definition_->GetRange();
114 } 125 }
OLDNEW
« tools/gn/functions.h ('K') | « tools/gn/functions.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698