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

Side by Side Diff: tools/gn/loader.h

Issue 318383003: Improve error messages and reporting in GN (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « tools/gn/input_file_manager.cc ('k') | tools/gn/loader.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 #ifndef TOOLS_GN_LOADER_H_ 5 #ifndef TOOLS_GN_LOADER_H_
6 #define TOOLS_GN_LOADER_H_ 6 #define TOOLS_GN_LOADER_H_
7 7
8 #include <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 10
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "tools/gn/label.h" 13 #include "tools/gn/label.h"
14 #include "tools/gn/scope.h" 14 #include "tools/gn/scope.h"
15 15
16 namespace base { 16 namespace base {
17 class MessageLoop; 17 class MessageLoop;
18 } 18 }
19 19
20 class BuildSettings; 20 class BuildSettings;
21 class LocationRange;
21 class Settings; 22 class Settings;
22 class SourceFile; 23 class SourceFile;
23 class Toolchain; 24 class Toolchain;
24 25
25 // The loader manages execution of the different build files. It receives 26 // The loader manages execution of the different build files. It receives
26 // requests (normally from the Builder) when new references are found, and also 27 // requests (normally from the Builder) when new references are found, and also
27 // manages loading the build config files. 28 // manages loading the build config files.
28 // 29 //
29 // This loader class is abstract so it can be mocked out for testing the 30 // This loader class is abstract so it can be mocked out for testing the
30 // Builder. 31 // Builder.
31 class Loader : public base::RefCountedThreadSafe<Loader> { 32 class Loader : public base::RefCountedThreadSafe<Loader> {
32 public: 33 public:
33 Loader(); 34 Loader();
34 35
35 // Loads the given file in the conext of the given toolchain. The initial 36 // Loads the given file in the conext of the given toolchain. The initial
36 // call to this (the one that actually starts the generation) should have an 37 // call to this (the one that actually starts the generation) should have an
37 // empty toolchain name, which will trigger the load of the default build 38 // empty toolchain name, which will trigger the load of the default build
38 // config. 39 // config.
39 virtual void Load(const SourceFile& file, 40 virtual void Load(const SourceFile& file,
41 const LocationRange& origin,
40 const Label& toolchain_name) = 0; 42 const Label& toolchain_name) = 0;
41 43
42 // Notification that the given toolchain has loaded. This will unblock files 44 // Notification that the given toolchain has loaded. This will unblock files
43 // waiting on this definition. 45 // waiting on this definition.
44 virtual void ToolchainLoaded(const Toolchain* toolchain) = 0; 46 virtual void ToolchainLoaded(const Toolchain* toolchain) = 0;
45 47
46 // Returns the label of the default toolchain. 48 // Returns the label of the default toolchain.
47 virtual Label GetDefaultToolchain() const = 0; 49 virtual Label GetDefaultToolchain() const = 0;
48 50
49 // Returns information about the toolchain with the given label. Will return 51 // Returns information about the toolchain with the given label. Will return
50 // false if we haven't processed this toolchain yet. 52 // false if we haven't processed this toolchain yet.
51 virtual const Settings* GetToolchainSettings(const Label& label) const = 0; 53 virtual const Settings* GetToolchainSettings(const Label& label) const = 0;
52 54
53 // Helper function that extracts the file and toolchain name from the given 55 // Helper function that extracts the file and toolchain name from the given
54 // label, and calls Load(). 56 // label, and calls Load().
55 void Load(const Label& label); 57 void Load(const Label& label, const LocationRange& origin);
56 58
57 // Returns the build file that the given label references. 59 // Returns the build file that the given label references.
58 static SourceFile BuildFileForLabel(const Label& label); 60 static SourceFile BuildFileForLabel(const Label& label);
59 61
60 // When processing the default build config, we want to capture the argument 62 // When processing the default build config, we want to capture the argument
61 // of set_default_build_config. The implementation of that function uses this 63 // of set_default_build_config. The implementation of that function uses this
62 // constant as a property key to get the Label* out of the scope where the 64 // constant as a property key to get the Label* out of the scope where the
63 // label should be stored. 65 // label should be stored.
64 static const void* kDefaultToolchainKey; 66 static const void* kDefaultToolchainKey;
65 67
66 protected: 68 protected:
67 friend class base::RefCountedThreadSafe<Loader>; 69 friend class base::RefCountedThreadSafe<Loader>;
68 virtual ~Loader(); 70 virtual ~Loader();
69 }; 71 };
70 72
71 class LoaderImpl : public Loader { 73 class LoaderImpl : public Loader {
72 public: 74 public:
73 // Callback to emulate InputFileManager::AsyncLoadFile. 75 // Callback to emulate InputFileManager::AsyncLoadFile.
74 typedef base::Callback<bool(const LocationRange&, 76 typedef base::Callback<bool(const LocationRange&,
75 const BuildSettings*, 77 const BuildSettings*,
76 const SourceFile&, 78 const SourceFile&,
77 const base::Callback<void(const ParseNode*)>&, 79 const base::Callback<void(const ParseNode*)>&,
78 Err*)> AsyncLoadFileCallback; 80 Err*)> AsyncLoadFileCallback;
79 81
80 LoaderImpl(const BuildSettings* build_settings); 82 LoaderImpl(const BuildSettings* build_settings);
81 83
82 // Loader implementation. 84 // Loader implementation.
83 virtual void Load(const SourceFile& file, 85 virtual void Load(const SourceFile& file,
86 const LocationRange& origin,
84 const Label& toolchain_name) OVERRIDE; 87 const Label& toolchain_name) OVERRIDE;
85 virtual void ToolchainLoaded(const Toolchain* toolchain) OVERRIDE; 88 virtual void ToolchainLoaded(const Toolchain* toolchain) OVERRIDE;
86 virtual Label GetDefaultToolchain() const OVERRIDE; 89 virtual Label GetDefaultToolchain() const OVERRIDE;
87 virtual const Settings* GetToolchainSettings( 90 virtual const Settings* GetToolchainSettings(
88 const Label& label) const OVERRIDE; 91 const Label& label) const OVERRIDE;
89 92
90 // Sets the message loop corresponding to the main thread. By default this 93 // Sets the message loop corresponding to the main thread. By default this
91 // class will use the thread active during construction, but there is not 94 // class will use the thread active during construction, but there is not
92 // a message loop active during construction all the time. 95 // a message loop active during construction all the time.
93 void set_main_loop(base::MessageLoop* loop) { main_loop_ = loop; } 96 void set_main_loop(base::MessageLoop* loop) { main_loop_ = loop; }
(...skipping 15 matching lines...) Expand all
109 } 112 }
110 113
111 private: 114 private:
112 struct LoadID; 115 struct LoadID;
113 struct ToolchainRecord; 116 struct ToolchainRecord;
114 117
115 virtual ~LoaderImpl(); 118 virtual ~LoaderImpl();
116 119
117 // Schedules the input file manager to load the given file. 120 // Schedules the input file manager to load the given file.
118 void ScheduleLoadFile(const Settings* settings, 121 void ScheduleLoadFile(const Settings* settings,
122 const LocationRange& origin,
119 const SourceFile& file); 123 const SourceFile& file);
120 void ScheduleLoadBuildConfig( 124 void ScheduleLoadBuildConfig(
121 Settings* settings, 125 Settings* settings,
122 const Scope::KeyValueMap& toolchain_overrides); 126 const Scope::KeyValueMap& toolchain_overrides);
123 127
124 // Runs the given file on the background thread. These are called by the 128 // Runs the given file on the background thread. These are called by the
125 // input file manager. 129 // input file manager.
126 void BackgroundLoadFile(const Settings* settings, 130 void BackgroundLoadFile(const Settings* settings,
127 const SourceFile& file_name, 131 const SourceFile& file_name,
128 const ParseNode* root); 132 const ParseNode* root);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 const BuildSettings* build_settings_; 173 const BuildSettings* build_settings_;
170 Label default_toolchain_label_; 174 Label default_toolchain_label_;
171 175
172 // Records for the build config file loads. 176 // Records for the build config file loads.
173 // Owning pointers. 177 // Owning pointers.
174 typedef std::map<Label, ToolchainRecord*> ToolchainRecordMap; 178 typedef std::map<Label, ToolchainRecord*> ToolchainRecordMap;
175 ToolchainRecordMap toolchain_records_; 179 ToolchainRecordMap toolchain_records_;
176 }; 180 };
177 181
178 #endif // TOOLS_GN_LOADER_H_ 182 #endif // TOOLS_GN_LOADER_H_
OLDNEW
« no previous file with comments | « tools/gn/input_file_manager.cc ('k') | tools/gn/loader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698