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/loader.h" | 5 #include "tools/gn/loader.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "tools/gn/build_settings.h" | 10 #include "tools/gn/build_settings.h" |
11 #include "tools/gn/err.h" | 11 #include "tools/gn/err.h" |
12 #include "tools/gn/filesystem_utils.h" | 12 #include "tools/gn/filesystem_utils.h" |
13 #include "tools/gn/input_file_manager.h" | 13 #include "tools/gn/input_file_manager.h" |
14 #include "tools/gn/parse_tree.h" | 14 #include "tools/gn/parse_tree.h" |
15 #include "tools/gn/scheduler.h" | 15 #include "tools/gn/scheduler.h" |
16 #include "tools/gn/scope_per_file_provider.h" | 16 #include "tools/gn/scope_per_file_provider.h" |
17 #include "tools/gn/settings.h" | 17 #include "tools/gn/settings.h" |
18 #include "tools/gn/source_dir.h" | 18 #include "tools/gn/source_dir.h" |
19 #include "tools/gn/source_file.h" | 19 #include "tools/gn/source_file.h" |
20 #include "tools/gn/trace.h" | 20 #include "tools/gn/trace.h" |
21 | 21 |
22 namespace { | |
23 | |
24 void ClearPrivateVariables(Scope* scope) { | |
cjhopman
2014/05/14 16:42:43
Why not just add this on Scope?
brettw
2014/05/15 19:44:15
Done.
| |
25 std::vector<base::StringPiece> variables; | |
26 scope->GetCurrentScopeVariables(&variables); | |
27 for (size_t i = 0; i < variables.size(); i++) { | |
28 if (Scope::IsPrivateVar(variables[i])) | |
29 scope->DeleteValue(variables[i]); | |
30 } | |
31 } | |
32 | |
33 } // namespace | |
34 | |
22 // Identifies one time a file is loaded in a given toolchain so we don't load | 35 // Identifies one time a file is loaded in a given toolchain so we don't load |
23 // it more than once. | 36 // it more than once. |
24 struct LoaderImpl::LoadID { | 37 struct LoaderImpl::LoadID { |
25 LoadID() {} | 38 LoadID() {} |
26 LoadID(const SourceFile& f, const Label& tc_name) | 39 LoadID(const SourceFile& f, const Label& tc_name) |
27 : file(f), | 40 : file(f), |
28 toolchain_name(tc_name) { | 41 toolchain_name(tc_name) { |
29 } | 42 } |
30 | 43 |
31 bool operator<(const LoadID& other) const { | 44 bool operator<(const LoadID& other) const { |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
238 our_scope.set_item_collector(&collected_items); | 251 our_scope.set_item_collector(&collected_items); |
239 | 252 |
240 ScopedTrace trace(TraceItem::TRACE_FILE_EXECUTE, file_name.value()); | 253 ScopedTrace trace(TraceItem::TRACE_FILE_EXECUTE, file_name.value()); |
241 trace.SetToolchain(settings->toolchain_label()); | 254 trace.SetToolchain(settings->toolchain_label()); |
242 | 255 |
243 Err err; | 256 Err err; |
244 root->Execute(&our_scope, &err); | 257 root->Execute(&our_scope, &err); |
245 if (err.has_error()) | 258 if (err.has_error()) |
246 g_scheduler->FailWithError(err); | 259 g_scheduler->FailWithError(err); |
247 | 260 |
261 if (!our_scope.CheckForUnusedVars(&err)) | |
262 g_scheduler->FailWithError(err); | |
263 | |
248 // Pass all of the items that were defined off to the builder. | 264 // Pass all of the items that were defined off to the builder. |
249 for (size_t i = 0; i < collected_items.size(); i++) | 265 for (size_t i = 0; i < collected_items.size(); i++) |
250 settings->build_settings()->ItemDefined(collected_items[i]->Pass()); | 266 settings->build_settings()->ItemDefined(collected_items[i]->Pass()); |
251 | 267 |
252 trace.Done(); | 268 trace.Done(); |
253 | 269 |
254 main_loop_->PostTask(FROM_HERE, base::Bind(&LoaderImpl::DidLoadFile, this)); | 270 main_loop_->PostTask(FROM_HERE, base::Bind(&LoaderImpl::DidLoadFile, this)); |
255 } | 271 } |
256 | 272 |
257 void LoaderImpl::BackgroundLoadBuildConfig( | 273 void LoaderImpl::BackgroundLoadBuildConfig( |
(...skipping 20 matching lines...) Expand all Loading... | |
278 base_config->SetProperty(kDefaultToolchainKey, &default_toolchain_label); | 294 base_config->SetProperty(kDefaultToolchainKey, &default_toolchain_label); |
279 | 295 |
280 ScopedTrace trace(TraceItem::TRACE_FILE_EXECUTE, | 296 ScopedTrace trace(TraceItem::TRACE_FILE_EXECUTE, |
281 settings->build_settings()->build_config_file().value()); | 297 settings->build_settings()->build_config_file().value()); |
282 trace.SetToolchain(settings->toolchain_label()); | 298 trace.SetToolchain(settings->toolchain_label()); |
283 | 299 |
284 const BlockNode* root_block = root->AsBlock(); | 300 const BlockNode* root_block = root->AsBlock(); |
285 Err err; | 301 Err err; |
286 root_block->ExecuteBlockInScope(base_config, &err); | 302 root_block->ExecuteBlockInScope(base_config, &err); |
287 | 303 |
304 // Clear all private variables left in the scope. We want the root build | |
305 // config to be like a .gni file in that variables beginning with an | |
306 // underscore aren't exported. | |
307 ClearPrivateVariables(base_config); | |
308 | |
288 trace.Done(); | 309 trace.Done(); |
289 | 310 |
290 if (err.has_error()) | 311 if (err.has_error()) |
291 g_scheduler->FailWithError(err); | 312 g_scheduler->FailWithError(err); |
292 | 313 |
293 base_config->ClearProcessingBuildConfig(); | 314 base_config->ClearProcessingBuildConfig(); |
294 if (settings->is_default()) { | 315 if (settings->is_default()) { |
295 // The default toolchain must have been set in the default build config | 316 // The default toolchain must have been set in the default build config |
296 // file. | 317 // file. |
297 if (default_toolchain_label.is_null()) { | 318 if (default_toolchain_label.is_null()) { |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
386 const SourceFile& file_name, | 407 const SourceFile& file_name, |
387 const base::Callback<void(const ParseNode*)>& callback, | 408 const base::Callback<void(const ParseNode*)>& callback, |
388 Err* err) { | 409 Err* err) { |
389 if (async_load_file_.is_null()) { | 410 if (async_load_file_.is_null()) { |
390 return g_scheduler->input_file_manager()->AsyncLoadFile( | 411 return g_scheduler->input_file_manager()->AsyncLoadFile( |
391 origin, build_settings, file_name, callback, err); | 412 origin, build_settings, file_name, callback, err); |
392 } | 413 } |
393 return async_load_file_.Run( | 414 return async_load_file_.Run( |
394 origin, build_settings, file_name, callback, err); | 415 origin, build_settings, file_name, callback, err); |
395 } | 416 } |
OLD | NEW |