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 #ifndef TOOLS_GN_BUILDER_H_ | 5 #ifndef TOOLS_GN_BUILDER_H_ |
6 #define TOOLS_GN_BUILDER_H_ | 6 #define TOOLS_GN_BUILDER_H_ |
7 | 7 |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/containers/hash_tables.h" | 9 #include "base/containers/hash_tables.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/memory/ref_counted.h" | |
12 #include "tools/gn/builder_record.h" | 11 #include "tools/gn/builder_record.h" |
13 #include "tools/gn/label.h" | 12 #include "tools/gn/label.h" |
14 #include "tools/gn/label_ptr.h" | 13 #include "tools/gn/label_ptr.h" |
15 #include "tools/gn/unique_vector.h" | 14 #include "tools/gn/unique_vector.h" |
16 | 15 |
17 class Config; | 16 class Config; |
18 class Err; | 17 class Err; |
19 class Loader; | 18 class Loader; |
20 class ParseNode; | 19 class ParseNode; |
21 | 20 |
22 class Builder : public base::RefCountedThreadSafe<Builder> { | 21 // The builder assembles the dependency tree. It is not threadsafe and runs on |
| 22 // the main thread only. See also BuilderRecord. |
| 23 class Builder { |
23 public: | 24 public: |
24 typedef base::Callback<void(const BuilderRecord*)> ResolvedCallback; | 25 typedef base::Callback<void(const BuilderRecord*)> ResolvedCallback; |
25 | 26 |
26 explicit Builder(Loader* loader); | 27 explicit Builder(Loader* loader); |
| 28 ~Builder(); |
27 | 29 |
28 // The resolved callback is called whenever a target has been resolved. This | 30 // The resolved callback is called whenever a target has been resolved. This |
29 // will be executed only on the main thread. | 31 // will be executed only on the main thread. |
30 void set_resolved_callback(const ResolvedCallback& cb) { | 32 void set_resolved_callback(const ResolvedCallback& cb) { |
31 resolved_callback_ = cb; | 33 resolved_callback_ = cb; |
32 } | 34 } |
33 | 35 |
34 Loader* loader() const { return loader_; } | 36 Loader* loader() const { return loader_; } |
35 | 37 |
36 void ItemDefined(std::unique_ptr<Item> item); | 38 void ItemDefined(std::unique_ptr<Item> item); |
37 | 39 |
38 // Returns NULL if there is not a thing with the corresponding label. | 40 // Returns NULL if there is not a thing with the corresponding label. |
39 const Item* GetItem(const Label& label) const; | 41 const Item* GetItem(const Label& label) const; |
40 const Toolchain* GetToolchain(const Label& label) const; | 42 const Toolchain* GetToolchain(const Label& label) const; |
41 | 43 |
42 std::vector<const BuilderRecord*> GetAllRecords() const; | 44 std::vector<const BuilderRecord*> GetAllRecords() const; |
43 | 45 |
44 // Returns targets which should be generated and which are defined. | 46 // Returns targets which should be generated and which are defined. |
45 std::vector<const Target*> GetAllResolvedTargets() const; | 47 std::vector<const Target*> GetAllResolvedTargets() const; |
46 | 48 |
47 // Returns the record for the given label, or NULL if it doesn't exist. | 49 // Returns the record for the given label, or NULL if it doesn't exist. |
48 // Mostly used for unit tests. | 50 // Mostly used for unit tests. |
49 const BuilderRecord* GetRecord(const Label& label) const; | 51 const BuilderRecord* GetRecord(const Label& label) const; |
50 BuilderRecord* GetRecord(const Label& label); | 52 BuilderRecord* GetRecord(const Label& label); |
51 | 53 |
52 // If there are any undefined references, returns false and sets the error. | 54 // If there are any undefined references, returns false and sets the error. |
53 bool CheckForBadItems(Err* err) const; | 55 bool CheckForBadItems(Err* err) const; |
54 | 56 |
55 private: | 57 private: |
56 friend class base::RefCountedThreadSafe<Builder>; | |
57 | |
58 virtual ~Builder(); | |
59 | |
60 bool TargetDefined(BuilderRecord* record, Err* err); | 58 bool TargetDefined(BuilderRecord* record, Err* err); |
61 bool ConfigDefined(BuilderRecord* record, Err* err); | 59 bool ConfigDefined(BuilderRecord* record, Err* err); |
62 bool ToolchainDefined(BuilderRecord* record, Err* err); | 60 bool ToolchainDefined(BuilderRecord* record, Err* err); |
63 | 61 |
64 // Returns the record associated with the given label. This function checks | 62 // Returns the record associated with the given label. This function checks |
65 // that if we already have references for it, the type matches. If no record | 63 // that if we already have references for it, the type matches. If no record |
66 // exists yet, a new one will be created. | 64 // exists yet, a new one will be created. |
67 // | 65 // |
68 // If any of the conditions fail, the return value will be null and the error | 66 // If any of the conditions fail, the return value will be null and the error |
69 // will be set. request_from is used as the source of the error. | 67 // will be set. request_from is used as the source of the error. |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 // Owning pointers. | 131 // Owning pointers. |
134 typedef base::hash_map<Label, BuilderRecord*> RecordMap; | 132 typedef base::hash_map<Label, BuilderRecord*> RecordMap; |
135 RecordMap records_; | 133 RecordMap records_; |
136 | 134 |
137 ResolvedCallback resolved_callback_; | 135 ResolvedCallback resolved_callback_; |
138 | 136 |
139 DISALLOW_COPY_AND_ASSIGN(Builder); | 137 DISALLOW_COPY_AND_ASSIGN(Builder); |
140 }; | 138 }; |
141 | 139 |
142 #endif // TOOLS_GN_BUILDER_H_ | 140 #endif // TOOLS_GN_BUILDER_H_ |
OLD | NEW |