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/import_manager.h" | 5 #include "tools/gn/import_manager.h" |
6 | 6 |
7 #include "tools/gn/err.h" | 7 #include "tools/gn/err.h" |
8 #include "tools/gn/parse_tree.h" | 8 #include "tools/gn/parse_tree.h" |
9 #include "tools/gn/scheduler.h" | 9 #include "tools/gn/scheduler.h" |
10 #include "tools/gn/scope_per_file_provider.h" | 10 #include "tools/gn/scope_per_file_provider.h" |
11 #include "tools/gn/trace.h" | 11 #include "tools/gn/trace.h" |
12 | 12 |
13 namespace { | 13 namespace { |
14 | 14 |
15 // Returns a newly-allocated scope on success, null on failure. | 15 // Returns a newly-allocated scope on success, null on failure. |
16 std::unique_ptr<Scope> UncachedImport(const Settings* settings, | 16 std::unique_ptr<Scope> UncachedImport(const Settings* settings, |
17 const SourceFile& file, | 17 const SourceFile& file, |
18 const ParseNode* node_for_err, | 18 const ParseNode* node_for_err, |
19 Err* err) { | 19 Err* err) { |
20 ScopedTrace load_trace(TraceItem::TRACE_IMPORT_LOAD, file.value()); | 20 ScopedTrace load_trace(TraceItem::TRACE_IMPORT_LOAD, file.value()); |
21 | 21 |
22 const ParseNode* node = g_scheduler->input_file_manager()->SyncLoadFile( | 22 const ParseNode* node = g_scheduler->input_file_manager()->SyncLoadFile( |
23 node_for_err->GetRange(), settings->build_settings(), file, err); | 23 node_for_err->GetRange(), settings->build_settings(), file, err); |
24 if (!node) | 24 if (!node) |
25 return nullptr; | 25 return nullptr; |
26 | 26 |
27 std::unique_ptr<Scope> scope(new Scope(settings->base_config())); | 27 std::unique_ptr<Scope> scope(new Scope(settings->base_config())); |
28 scope->set_source_dir(file.GetDir()); | 28 scope->set_source_dir(file.GetDir()); |
29 | 29 |
| 30 const Location& location = node->GetRange().begin(); |
| 31 if (!location.is_null()) |
| 32 scope->AddInputFile(location.file()); |
| 33 |
30 // Don't allow ScopePerFileProvider to provide target-related variables. | 34 // Don't allow ScopePerFileProvider to provide target-related variables. |
31 // These will be relative to the imported file, which is probably not what | 35 // These will be relative to the imported file, which is probably not what |
32 // people mean when they use these. | 36 // people mean when they use these. |
33 ScopePerFileProvider per_file_provider(scope.get(), false); | 37 ScopePerFileProvider per_file_provider(scope.get(), false); |
34 | 38 |
35 scope->SetProcessingImport(); | 39 scope->SetProcessingImport(); |
36 node->Execute(scope.get(), err); | 40 node->Execute(scope.get(), err); |
37 if (err->has_error()) { | 41 if (err->has_error()) { |
38 // If there was an error, append the caller location so the error message | 42 // If there was an error, append the caller location so the error message |
39 // displays a why the file was imported (esp. useful for failed asserts). | 43 // displays a why the file was imported (esp. useful for failed asserts). |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 "import", err); | 135 "import", err); |
132 } | 136 } |
133 | 137 |
134 std::vector<SourceFile> ImportManager::GetImportedFiles() const { | 138 std::vector<SourceFile> ImportManager::GetImportedFiles() const { |
135 std::vector<SourceFile> imported_files; | 139 std::vector<SourceFile> imported_files; |
136 imported_files.resize(imports_.size()); | 140 imported_files.resize(imports_.size()); |
137 std::transform(imports_.begin(), imports_.end(), imported_files.begin(), | 141 std::transform(imports_.begin(), imports_.end(), imported_files.begin(), |
138 [](const ImportMap::value_type& val) { return val.first; }); | 142 [](const ImportMap::value_type& val) { return val.first; }); |
139 return imported_files; | 143 return imported_files; |
140 } | 144 } |
OLD | NEW |