@@ -39,38 +39,34 @@ namespace buildcc {
39
39
40
40
struct UserCustomGeneratorSchema : public internal ::CustomGeneratorSchema {
41
41
struct UserIdInfo : internal::CustomGeneratorSchema::IdInfo {
42
- fs_unordered_set inputs; // TODO, Remove
43
- GenerateCb generate_cb;
44
- std::shared_ptr<CustomBlobHandler> blob_handler{nullptr };
45
-
46
42
void ConvertToInternal () {
47
- internal_inputs = internal::path_schema_convert (
48
- inputs, internal::Path::CreateExistingPath);
43
+ inputs.ComputeHashForAll ();
49
44
userblob = blob_handler != nullptr ? blob_handler->GetSerializedData ()
50
45
: std::vector<uint8_t >();
51
46
}
52
- };
53
47
54
- using UserIdPair = std::pair<const IdKey, UserIdInfo>;
55
- std::unordered_map<IdKey, UserIdInfo> ids;
48
+ GenerateCb generate_cb;
49
+ std::shared_ptr<CustomBlobHandler> blob_handler{nullptr };
50
+ };
56
51
57
52
void ConvertToInternal () {
58
53
for (auto &[id_key, id_info] : ids) {
59
- id_info.internal_inputs = path_schema_convert (
60
- id_info.inputs , internal::Path::CreateExistingPath);
54
+ id_info.ConvertToInternal ();
61
55
auto [_, success] = internal_ids.try_emplace (id_key, id_info);
62
56
env::assert_fatal (success, fmt::format (" Could not save {}" , id_key));
63
57
}
64
58
}
59
+
60
+ std::unordered_map<IdKey, UserIdInfo> ids;
65
61
};
66
62
67
63
class CustomGenerator : public internal ::BuilderInterface {
68
64
public:
69
65
CustomGenerator (const std::string &name, const TargetEnv &env)
70
66
: name_(name),
71
67
env_ (env.GetTargetRootDir(), env.GetTargetBuildDir() / name),
72
- serialization_(env_.GetTargetBuildDir() / fmt::format( " {}.json " , name)),
73
- comparator_(serialization_.GetLoad(), user_ ) {
68
+ serialization_(env_.GetTargetBuildDir() /
69
+ fmt::format( " {}.json " , name) ) {
74
70
Initialize ();
75
71
}
76
72
virtual ~CustomGenerator () = default ;
@@ -115,100 +111,9 @@ class CustomGenerator : public internal::BuilderInterface {
115
111
const fs::path &GetBuildDir () const { return env_.GetTargetBuildDir (); }
116
112
const std::string &Get (const std::string &file_identifier) const ;
117
113
118
- private:
119
- struct Comparator {
120
- Comparator (const internal::CustomGeneratorSchema &loaded,
121
- const UserCustomGeneratorSchema &us)
122
- : loaded_schema_(loaded), current_schema_(us) {}
123
-
124
- enum class State {
125
- kRemoved ,
126
- kAdded ,
127
- kCheckLater ,
128
- };
129
-
130
- void AddAllIds () {
131
- const auto &curr_ids = current_schema_.ids ;
132
- for (const auto &[id, _] : curr_ids) {
133
- id_state_info_.at (State::kAdded ).insert (id);
134
- }
135
- }
136
-
137
- void CompareIds () {
138
- const auto &prev_ids = loaded_schema_.internal_ids ;
139
- const auto &curr_ids = current_schema_.ids ;
140
-
141
- for (const auto &[prev_id, _] : prev_ids) {
142
- if (curr_ids.find (prev_id) == curr_ids.end ()) {
143
- // Id Removed condition, previous id is not present in the current run
144
- id_state_info_.at (State::kRemoved ).insert (prev_id);
145
- }
146
- }
147
-
148
- for (const auto &[curr_id, _] : curr_ids) {
149
- if (prev_ids.find (curr_id) == prev_ids.end ()) {
150
- // Id Added condition
151
- id_state_info_.at (State::kAdded ).insert (curr_id);
152
- } else {
153
- // Id Check Later condition
154
- id_state_info_.at (State::kCheckLater ).insert (curr_id);
155
- }
156
- }
157
- }
158
-
159
- bool IsChanged (const std::string &id) const {
160
- const auto &previous_id_info = loaded_schema_.internal_ids .at (id);
161
- const auto ¤t_id_info = current_schema_.ids .at (id);
162
-
163
- bool changed = internal::CheckPaths (previous_id_info.internal_inputs ,
164
- current_id_info.internal_inputs ) !=
165
- internal::PathState::kNoChange ;
166
- changed = changed || internal::CheckChanged (previous_id_info.outputs ,
167
- current_id_info.outputs );
168
- if (!changed && current_id_info.blob_handler != nullptr ) {
169
- // We only check blob handler if not changed by inputs/outputs
170
- // Checking blob_handler could be expensive so this optimization is made
171
- // to run only when changed == false
172
- changed = current_id_info.blob_handler ->CheckChanged (
173
- previous_id_info.userblob , current_id_info.userblob );
174
- }
175
- return changed;
176
- }
177
-
178
- const std::unordered_set<std::string> &GetRemovedIds () const {
179
- return id_state_info_.at (State::kRemoved );
180
- }
181
-
182
- const std::unordered_set<std::string> &GetAddedIds () const {
183
- return id_state_info_.at (State::kAdded );
184
- }
185
-
186
- const std::unordered_set<std::string> &GetCheckLaterIds () const {
187
- return id_state_info_.at (State::kCheckLater );
188
- }
189
-
190
- bool IsIdAdded (const std::string &id) const {
191
- return id_state_info_.at (State::kAdded ).count (id) == 1 ;
192
- }
193
-
194
- private:
195
- const internal::CustomGeneratorSchema &loaded_schema_;
196
- const UserCustomGeneratorSchema ¤t_schema_;
197
- std::unordered_map<State, std::unordered_set<std::string>> id_state_info_{
198
- {State::kRemoved , std::unordered_set<std::string>()},
199
- {State::kAdded , std::unordered_set<std::string>()},
200
- {State::kCheckLater , std::unordered_set<std::string>()},
201
- };
202
- };
203
-
204
114
private:
205
115
void Initialize ();
206
-
207
- tf::Task CreateTaskRunner (tf::Subflow &subflow, const std::string &id);
208
- void TaskRunner (const std::string &id);
209
-
210
116
void GenerateTask ();
211
- void BuildGenerate ();
212
117
213
118
// Recheck states
214
119
void IdRemoved ();
@@ -227,13 +132,6 @@ class CustomGenerator : public internal::BuilderInterface {
227
132
// Serialization
228
133
UserCustomGeneratorSchema user_;
229
134
230
- // Comparator
231
- Comparator comparator_;
232
-
233
- std::mutex success_schema_mutex_;
234
- std::unordered_map<std::string, UserCustomGeneratorSchema::UserIdInfo>
235
- success_schema_;
236
-
237
135
// Internal
238
136
env::Command command_;
239
137
};
0 commit comments