@@ -56,19 +56,48 @@ typedef std::function<bool(CustomGeneratorContext &)> GenerateCb;
56
56
typedef std::function<void (std::unordered_map<std::string, tf::Task> &)> DependencyCb;
57
57
// clang-format on
58
58
59
- struct UserRelInputOutputSchema : internal::RelInputOutputSchema {
59
+ class CustomBlobHandler {
60
+ public:
61
+ bool CheckChanged (const std::vector<uint8_t > &previous,
62
+ const std::vector<uint8_t > ¤t) const {
63
+ env::assert_fatal (
64
+ Verify (previous),
65
+ " Stored blob is corrupted or User verification is incorrect" );
66
+ env::assert_fatal (
67
+ Verify (current),
68
+ " Current blob is corrupted or User verification is incorrect" );
69
+ return !IsEqual (previous, current);
70
+ };
71
+
72
+ std::vector<uint8_t > GetSerializedData () {
73
+ auto serialized_data = Serialize ();
74
+ env::assert_fatal (
75
+ Verify (serialized_data),
76
+ " Serialized data is corrupted or Serialize function is incorrect" );
77
+ return serialized_data;
78
+ }
79
+
80
+ private:
81
+ virtual bool Verify (const std::vector<uint8_t > &serialized_data) const = 0;
82
+ virtual bool IsEqual (const std::vector<uint8_t > &previous,
83
+ const std::vector<uint8_t > ¤t) const = 0;
84
+ virtual std::vector<uint8_t > Serialize () const = 0;
85
+ };
86
+
87
+ struct UserGenInfo : internal::GenInfo {
60
88
fs_unordered_set inputs;
61
89
GenerateCb generate_cb;
90
+ std::shared_ptr<CustomBlobHandler> blob_handler{nullptr };
62
91
};
63
92
64
93
struct UserCustomGeneratorSchema : public internal ::CustomGeneratorSchema {
65
- std::unordered_map<std::string, UserRelInputOutputSchema> rels_map ;
94
+ std::unordered_map<std::string, UserGenInfo> gen_info_map ;
66
95
67
96
void ConvertToInternal () {
68
- for (auto &r_miter : rels_map ) {
97
+ for (auto &r_miter : gen_info_map ) {
69
98
r_miter.second .internal_inputs = path_schema_convert (
70
99
r_miter.second .inputs , internal::Path::CreateExistingPath);
71
- auto p = internal_rels_map .emplace (r_miter.first , r_miter.second );
100
+ auto p = internal_gen_info_map .emplace (r_miter.first , r_miter.second );
72
101
env::assert_fatal (p.second ,
73
102
fmt::format (" Could not save {}" , r_miter.first ));
74
103
}
@@ -86,13 +115,17 @@ class CustomGenerator : public internal::BuilderInterface {
86
115
virtual ~CustomGenerator () = default ;
87
116
CustomGenerator (const CustomGenerator &) = delete;
88
117
89
- /* *
90
- * @brief Add default arguments for input, output and command requirements
91
- *
92
- * @param arguments Key-Value pair for arguments
93
- */
118
+ // From env::Command module, forwarding here
119
+ // TODO, Create a Mixin
120
+ void AddDefaultArgument (const std::string &identifier,
121
+ const std::string &pattern);
94
122
void AddDefaultArguments (
95
123
const std::unordered_map<std::string, std::string> &arguments);
124
+ std::string Construct (
125
+ const std::string &pattern,
126
+ const std::unordered_map<const char *, std::string> &arguments = {});
127
+ const std::string &
128
+ GetValueByIdentifier (const std::string &file_identifier) const ;
96
129
97
130
/* *
98
131
* @brief Single Generator task for inputs->generate_cb->outputs
@@ -105,7 +138,8 @@ class CustomGenerator : public internal::BuilderInterface {
105
138
*/
106
139
void AddGenInfo (const std::string &id, const fs_unordered_set &inputs,
107
140
const fs_unordered_set &outputs,
108
- const GenerateCb &generate_cb);
141
+ const GenerateCb &generate_cb,
142
+ std::shared_ptr<CustomBlobHandler> blob_handler = nullptr );
109
143
110
144
// Callbacks
111
145
/* *
@@ -127,6 +161,7 @@ class CustomGenerator : public internal::BuilderInterface {
127
161
void Build () override ;
128
162
129
163
// Getters
164
+ const std::string &GetName () const { return name_; }
130
165
const fs::path &GetBinaryPath () const {
131
166
return serialization_.GetSerializedFile ();
132
167
}
@@ -140,10 +175,9 @@ class CustomGenerator : public internal::BuilderInterface {
140
175
template <bool run> void TaskRunner (const std::string &id);
141
176
142
177
void GenerateTask ();
143
- void BuildGenerate (std::unordered_map<std::string, UserRelInputOutputSchema>
144
- &gen_selected_map,
145
- std::unordered_map<std::string, UserRelInputOutputSchema>
146
- &dummy_gen_selected_map);
178
+ void BuildGenerate (
179
+ std::unordered_map<std::string, UserGenInfo> &gen_selected_map,
180
+ std::unordered_map<std::string, UserGenInfo> &dummy_gen_selected_map);
147
181
148
182
// Recheck states
149
183
void IdRemoved ();
@@ -159,7 +193,7 @@ class CustomGenerator : public internal::BuilderInterface {
159
193
UserCustomGeneratorSchema user_;
160
194
161
195
std::mutex success_schema_mutex_;
162
- std::unordered_map<std::string, UserRelInputOutputSchema > success_schema_;
196
+ std::unordered_map<std::string, UserGenInfo > success_schema_;
163
197
164
198
// Internal
165
199
env::Command command_;
0 commit comments