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

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

Issue 1314773005: Throw errors for nested targets in GN. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 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.h ('k') | tools/gn/functions_target.cc » ('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 <iostream> 7 #include <iostream>
8 8
9 #include "base/environment.h" 9 #include "base/environment.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 } 124 }
125 125
126 Label MakeLabelForScope(const Scope* scope, 126 Label MakeLabelForScope(const Scope* scope,
127 const FunctionCallNode* function, 127 const FunctionCallNode* function,
128 const std::string& name) { 128 const std::string& name) {
129 const Label& toolchain_label = ToolchainLabelForScope(scope); 129 const Label& toolchain_label = ToolchainLabelForScope(scope);
130 return Label(scope->GetSourceDir(), name, toolchain_label.dir(), 130 return Label(scope->GetSourceDir(), name, toolchain_label.dir(),
131 toolchain_label.name()); 131 toolchain_label.name());
132 } 132 }
133 133
134 // static
135 const int NonNestableBlock::kKey = 0;
136
137 NonNestableBlock::NonNestableBlock(
138 Scope* scope,
139 const FunctionCallNode* function,
140 const char* type_description)
141 : scope_(scope),
142 function_(function),
143 type_description_(type_description),
144 key_added_(false) {
145 }
146
147 NonNestableBlock::~NonNestableBlock() {
148 if (key_added_)
149 scope_->SetProperty(&kKey, nullptr);
150 }
151
152 bool NonNestableBlock::Enter(Err* err) {
153 void* scope_value = scope_->GetProperty(&kKey, nullptr);
154 if (scope_value) {
155 // Existing block.
156 const NonNestableBlock* existing =
157 reinterpret_cast<const NonNestableBlock*>(scope_value);
158 *err = Err(function_, "Can't nest these things.",
159 std::string("You are trying to nest a ") + type_description_ +
160 " inside a " + existing->type_description_ + ".");
161 err->AppendSubErr(Err(existing->function_, "The enclosing block."));
162 return false;
163 }
164
165 scope_->SetProperty(&kKey, this);
166 key_added_ = true;
167 return true;
168 }
169
134 namespace functions { 170 namespace functions {
135 171
136 // assert ---------------------------------------------------------------------- 172 // assert ----------------------------------------------------------------------
137 173
138 const char kAssert[] = "assert"; 174 const char kAssert[] = "assert";
139 const char kAssert_HelpShort[] = 175 const char kAssert_HelpShort[] =
140 "assert: Assert an expression is true at generation time."; 176 "assert: Assert an expression is true at generation time.";
141 const char kAssert_Help[] = 177 const char kAssert_Help[] =
142 "assert: Assert an expression is true at generation time.\n" 178 "assert: Assert an expression is true at generation time.\n"
143 "\n" 179 "\n"
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 " }\n" 273 " }\n"
238 "\n" 274 "\n"
239 " executable(\"mything\") {\n" 275 " executable(\"mything\") {\n"
240 " configs = [ \":myconfig\" ]\n" 276 " configs = [ \":myconfig\" ]\n"
241 " }\n"; 277 " }\n";
242 278
243 Value RunConfig(const FunctionCallNode* function, 279 Value RunConfig(const FunctionCallNode* function,
244 const std::vector<Value>& args, 280 const std::vector<Value>& args,
245 Scope* scope, 281 Scope* scope,
246 Err* err) { 282 Err* err) {
283 NonNestableBlock non_nestable(scope, function, "config");
284 if (!non_nestable.Enter(err))
285 return Value();
286
247 if (!EnsureSingleStringArg(function, args, err) || 287 if (!EnsureSingleStringArg(function, args, err) ||
248 !EnsureNotProcessingImport(function, scope, err)) 288 !EnsureNotProcessingImport(function, scope, err))
249 return Value(); 289 return Value();
250 290
251 Label label(MakeLabelForScope(scope, function, args[0].string_value())); 291 Label label(MakeLabelForScope(scope, function, args[0].string_value()));
252 292
253 if (g_scheduler->verbose_logging()) 293 if (g_scheduler->verbose_logging())
254 g_scheduler->Log("Defining config", label.GetUserVisibleName(true)); 294 g_scheduler->Log("Defining config", label.GetUserVisibleName(true));
255 295
256 // Create the new config. 296 // Create the new config.
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 " If you want to override the (default disabled) Doom Melon:\n" 341 " If you want to override the (default disabled) Doom Melon:\n"
302 " gn --args=\"enable_doom_melon=true enable_teleporter=false\"\n" 342 " gn --args=\"enable_doom_melon=true enable_teleporter=false\"\n"
303 " This also sets the teleporter, but it's already defaulted to on so\n" 343 " This also sets the teleporter, but it's already defaulted to on so\n"
304 " it will have no effect.\n"; 344 " it will have no effect.\n";
305 345
306 Value RunDeclareArgs(Scope* scope, 346 Value RunDeclareArgs(Scope* scope,
307 const FunctionCallNode* function, 347 const FunctionCallNode* function,
308 const std::vector<Value>& args, 348 const std::vector<Value>& args,
309 BlockNode* block, 349 BlockNode* block,
310 Err* err) { 350 Err* err) {
351 NonNestableBlock non_nestable(scope, function, "declare_args");
352 if (!non_nestable.Enter(err))
353 return Value();
354
311 Scope block_scope(scope); 355 Scope block_scope(scope);
312 block->Execute(&block_scope, err); 356 block->Execute(&block_scope, err);
313 if (err->has_error()) 357 if (err->has_error())
314 return Value(); 358 return Value();
315 359
316 // Pass the values from our scope into the Args object for adding to the 360 // Pass the values from our scope into the Args object for adding to the
317 // scope with the proper values (taking into account the defaults given in 361 // scope with the proper values (taking into account the defaults given in
318 // the block_scope, and arguments passed into the build). 362 // the block_scope, and arguments passed into the build).
319 Scope::KeyValueMap values; 363 Scope::KeyValueMap values;
320 block_scope.GetCurrentScopeValues(&values); 364 block_scope.GetCurrentScopeValues(&values);
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after
818 } 862 }
819 863
820 // Otherwise it's a no-block function. 864 // Otherwise it's a no-block function.
821 if (!VerifyNoBlockForFunctionCall(function, block, err)) 865 if (!VerifyNoBlockForFunctionCall(function, block, err))
822 return Value(); 866 return Value();
823 return found_function->second.no_block_runner(scope, function, 867 return found_function->second.no_block_runner(scope, function,
824 args.list_value(), err); 868 args.list_value(), err);
825 } 869 }
826 870
827 } // namespace functions 871 } // namespace functions
OLDNEW
« no previous file with comments | « tools/gn/functions.h ('k') | tools/gn/functions_target.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698