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/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "tools/gn/build_settings.h" | 10 #include "tools/gn/build_settings.h" |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 return &found_toolchain->second->settings; | 204 return &found_toolchain->second->settings; |
205 } | 205 } |
206 | 206 |
207 void LoaderImpl::ScheduleLoadFile(const Settings* settings, | 207 void LoaderImpl::ScheduleLoadFile(const Settings* settings, |
208 const LocationRange& origin, | 208 const LocationRange& origin, |
209 const SourceFile& file) { | 209 const SourceFile& file) { |
210 Err err; | 210 Err err; |
211 pending_loads_++; | 211 pending_loads_++; |
212 if (!AsyncLoadFile(origin, settings->build_settings(), file, | 212 if (!AsyncLoadFile(origin, settings->build_settings(), file, |
213 base::Bind(&LoaderImpl::BackgroundLoadFile, this, | 213 base::Bind(&LoaderImpl::BackgroundLoadFile, this, |
214 settings, file), | 214 settings, file, origin), |
215 &err)) { | 215 &err)) { |
216 g_scheduler->FailWithError(err); | 216 g_scheduler->FailWithError(err); |
217 DecrementPendingLoads(); | 217 DecrementPendingLoads(); |
218 } | 218 } |
219 } | 219 } |
220 | 220 |
221 void LoaderImpl::ScheduleLoadBuildConfig( | 221 void LoaderImpl::ScheduleLoadBuildConfig( |
222 Settings* settings, | 222 Settings* settings, |
223 const Scope::KeyValueMap& toolchain_overrides) { | 223 const Scope::KeyValueMap& toolchain_overrides) { |
224 Err err; | 224 Err err; |
225 pending_loads_++; | 225 pending_loads_++; |
226 if (!AsyncLoadFile(LocationRange(), settings->build_settings(), | 226 if (!AsyncLoadFile(LocationRange(), settings->build_settings(), |
227 settings->build_settings()->build_config_file(), | 227 settings->build_settings()->build_config_file(), |
228 base::Bind(&LoaderImpl::BackgroundLoadBuildConfig, | 228 base::Bind(&LoaderImpl::BackgroundLoadBuildConfig, |
229 this, settings, toolchain_overrides), | 229 this, settings, toolchain_overrides), |
230 &err)) { | 230 &err)) { |
231 g_scheduler->FailWithError(err); | 231 g_scheduler->FailWithError(err); |
232 DecrementPendingLoads(); | 232 DecrementPendingLoads(); |
233 } | 233 } |
234 } | 234 } |
235 | 235 |
236 void LoaderImpl::BackgroundLoadFile(const Settings* settings, | 236 void LoaderImpl::BackgroundLoadFile(const Settings* settings, |
237 const SourceFile& file_name, | 237 const SourceFile& file_name, |
| 238 const LocationRange& origin, |
238 const ParseNode* root) { | 239 const ParseNode* root) { |
239 if (!root) { | 240 if (!root) { |
240 main_loop_->PostTask(FROM_HERE, | 241 main_loop_->PostTask(FROM_HERE, |
241 base::Bind(&LoaderImpl::DecrementPendingLoads, this)); | 242 base::Bind(&LoaderImpl::DecrementPendingLoads, this)); |
242 return; | 243 return; |
243 } | 244 } |
244 | 245 |
245 if (g_scheduler->verbose_logging()) { | 246 if (g_scheduler->verbose_logging()) { |
246 g_scheduler->Log("Running", file_name.value() + " with toolchain " + | 247 g_scheduler->Log("Running", file_name.value() + " with toolchain " + |
247 settings->toolchain_label().GetUserVisibleName(false)); | 248 settings->toolchain_label().GetUserVisibleName(false)); |
248 } | 249 } |
249 | 250 |
250 Scope our_scope(settings->base_config()); | 251 Scope our_scope(settings->base_config()); |
251 ScopePerFileProvider per_file_provider(&our_scope, true); | 252 ScopePerFileProvider per_file_provider(&our_scope, true); |
252 our_scope.set_source_dir(file_name.GetDir()); | 253 our_scope.set_source_dir(file_name.GetDir()); |
253 | 254 |
254 // Targets, etc. generated as part of running this file will end up here. | 255 // Targets, etc. generated as part of running this file will end up here. |
255 Scope::ItemVector collected_items; | 256 Scope::ItemVector collected_items; |
256 our_scope.set_item_collector(&collected_items); | 257 our_scope.set_item_collector(&collected_items); |
257 | 258 |
258 ScopedTrace trace(TraceItem::TRACE_FILE_EXECUTE, file_name.value()); | 259 ScopedTrace trace(TraceItem::TRACE_FILE_EXECUTE, file_name.value()); |
259 trace.SetToolchain(settings->toolchain_label()); | 260 trace.SetToolchain(settings->toolchain_label()); |
260 | 261 |
261 Err err; | 262 Err err; |
262 root->Execute(&our_scope, &err); | 263 root->Execute(&our_scope, &err); |
263 if (err.has_error()) | 264 if (!err.has_error()) |
| 265 our_scope.CheckForUnusedVars(&err); |
| 266 |
| 267 if (err.has_error()) { |
| 268 if (!origin.is_null()) |
| 269 err.AppendSubErr(Err(origin, "which caused the file to be included.")); |
264 g_scheduler->FailWithError(err); | 270 g_scheduler->FailWithError(err); |
| 271 } |
265 | 272 |
266 if (!our_scope.CheckForUnusedVars(&err)) | |
267 g_scheduler->FailWithError(err); | |
268 | 273 |
269 // Pass all of the items that were defined off to the builder. | 274 // Pass all of the items that were defined off to the builder. |
270 for (auto& item : collected_items) { | 275 for (auto& item : collected_items) { |
271 settings->build_settings()->ItemDefined(base::WrapUnique(item)); | 276 settings->build_settings()->ItemDefined(base::WrapUnique(item)); |
272 item = nullptr; | 277 item = nullptr; |
273 } | 278 } |
274 | 279 |
275 trace.Done(); | 280 trace.Done(); |
276 | 281 |
277 main_loop_->PostTask(FROM_HERE, base::Bind(&LoaderImpl::DidLoadFile, this)); | 282 main_loop_->PostTask(FROM_HERE, base::Bind(&LoaderImpl::DidLoadFile, this)); |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 const SourceFile& file_name, | 419 const SourceFile& file_name, |
415 const base::Callback<void(const ParseNode*)>& callback, | 420 const base::Callback<void(const ParseNode*)>& callback, |
416 Err* err) { | 421 Err* err) { |
417 if (async_load_file_.is_null()) { | 422 if (async_load_file_.is_null()) { |
418 return g_scheduler->input_file_manager()->AsyncLoadFile( | 423 return g_scheduler->input_file_manager()->AsyncLoadFile( |
419 origin, build_settings, file_name, callback, err); | 424 origin, build_settings, file_name, callback, err); |
420 } | 425 } |
421 return async_load_file_.Run( | 426 return async_load_file_.Run( |
422 origin, build_settings, file_name, callback, err); | 427 origin, build_settings, file_name, callback, err); |
423 } | 428 } |
OLD | NEW |