@@ -39,38 +39,34 @@ namespace buildcc {
3939
4040struct UserCustomGeneratorSchema :public internal ::CustomGeneratorSchema {
4141struct UserIdInfo : internal::CustomGeneratorSchema::IdInfo {
42- fs_unordered_set inputs;// TODO, Remove
43- GenerateCb generate_cb;
44- std::shared_ptr<CustomBlobHandler> blob_handler{nullptr };
45-
4642void ConvertToInternal () {
47- internal_inputs =internal::path_schema_convert (
48- inputs, internal::Path::CreateExistingPath);
43+ inputs.ComputeHashForAll ();
4944 userblob = blob_handler !=nullptr ? blob_handler->GetSerializedData ()
5045 : std::vector<uint8_t >();
5146 }
52- };
5347
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+ };
5651
5752void ConvertToInternal () {
5853for (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 ();
6155auto [_, success] = internal_ids.try_emplace (id_key, id_info);
6256env::assert_fatal (success,fmt::format (" Could not save {}" , id_key));
6357 }
6458 }
59+
60+ std::unordered_map<IdKey, UserIdInfo> ids;
6561};
6662
6763class CustomGenerator :public internal ::BuilderInterface {
6864public:
6965CustomGenerator (const std::string &name,const TargetEnv &env)
7066 : name_(name),
7167env_ (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) ) {
7470Initialize ();
7571 }
7672virtual ~CustomGenerator () =default ;
@@ -115,100 +111,9 @@ class CustomGenerator : public internal::BuilderInterface {
115111const fs::path &GetBuildDir ()const {return env_.GetTargetBuildDir (); }
116112const std::string &Get (const std::string &file_identifier)const ;
117113
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-
204114private:
205115void Initialize ();
206-
207- tf::TaskCreateTaskRunner (tf::Subflow &subflow,const std::string &id);
208- void TaskRunner (const std::string &id);
209-
210116void GenerateTask ();
211- void BuildGenerate ();
212117
213118// Recheck states
214119void IdRemoved ();
@@ -227,13 +132,6 @@ class CustomGenerator : public internal::BuilderInterface {
227132// Serialization
228133 UserCustomGeneratorSchema user_;
229134
230- // Comparator
231- Comparator comparator_;
232-
233- std::mutex success_schema_mutex_;
234- std::unordered_map<std::string, UserCustomGeneratorSchema::UserIdInfo>
235- success_schema_;
236-
237135// Internal
238136 env::Command command_;
239137};