1919
2020#include < functional>
2121#include < string>
22+ #include < unordered_map>
2223#include < vector>
2324
2425#include " taskflow/taskflow.hpp"
2526
2627#include " env/env.h"
2728
29+ #include " command/command.h"
30+
2831#include " target/builder_interface.h"
2932
3033#include " target/generator_loader.h"
3134#include " target/path.h"
3235
3336namespace buildcc ::base {
3437
35- typedef std::function<bool (
36- const internal::geninfo_unordered_map &previous_info,
37- const internal::geninfo_unordered_map ¤t_info,
38- std::vector<const internal::GenInfo *> &output_generated_files,
39- std::vector<const internal::GenInfo *> &output_dummy_generated_files)>
40- custom_regenerate_cb_params;
41-
4238class Generator : public BuilderInterface {
4339public:
44- Generator (const std::string &name, const fs::path &path)
45- : name_(name), loader_(name, path) {
46- unique_id_ = name;
40+ Generator (const std::string &name,
41+ const fs::path &target_path_relative_to_root, bool parallel = false )
42+ : name_(name), generator_root_dir_(env::get_project_root_dir() /
43+ target_path_relative_to_root),
44+ generator_build_dir_ (env::get_project_build_dir() / name),
45+ loader_(name, generator_build_dir_), parallel_(parallel) {
46+ Initialize ();
4747 }
4848 Generator (const Generator &generator) = delete;
4949
5050 /* *
51- * @brief Define your input - output - command relation
51+ * @brief Add default arguments for input, output and command requirements
5252 *
53- * @param name GenInfo task name
54- * @param inputs Input files
55- * @param outputs Output files generated
56- * @param commands Commands for input files to generate output files
57- * @param parallel Run commands in parallel
58- */
59- void AddGenInfo (const std::string &name,
60- const internal::fs_unordered_set &inputs,
61- const internal::fs_unordered_set &outputs,
62- const std::vector<std::string> &commands, bool parallel);
63-
64- /* *
65- * @brief Implement your own Regenerate callback.
66- * - See `Regenerate` function for generic implementation
67- * - See `Recheck*` APIs in BuilderInterface for custom checks
68- *
69- * @param cb Gives 4 parameters
70- *
71- * const internal::geninfo_unordered_map &previous_info
72- * const internal::geninfo_unordered_map ¤t_info
73- * std::vector<const internal::GenInfo *> &output_generated_files
74- * std::vector<const internal::GenInfo *> &output_dummy_generated_files
75- *
76- * @return cb should return true or false which sets the dirty_ flag
77- */
78- void AddCustomRegenerateCb (const custom_regenerate_cb_params &cb);
79-
80- /* *
81- * @brief Custom pre generate callback run before the core generate function
53+ * @param arguments Key-Value pair for arguments
54+ * NOTE, Key must be a variable (lvalue) not a constant (rvalue)
8255 *
83- * @param cb
8456 */
85- void AddPregenerateCb (const std::function<void (void )> &cb);
57+ void AddDefaultArguments (
58+ const std::unordered_map<const char *, std::string> &arguments);
8659
87- /* *
88- * @brief Custom post generate callback run after the core generate function
89- * IF dirty_ == true
90- *
91- * @param cb
92- */
93- void AddPostgenerateCb ( const std::function< void ( void ) > &cb );
60+ void AddInput ( const std::string &absolute_input_pattern,
61+ const char *identifier = nullptr );
62+ void AddOutput ( const std::string &absolute_output_pattern,
63+ const char *identifier = nullptr );
64+ void AddCommand (
65+ const std::string &command_pattern,
66+ const std::unordered_map< const char *, std::string > &arguments = {} );
9467
9568 void Build () override ;
96- void Build (tf::FlowBuilder &builder);
9769
9870 // Getter
9971 fs::path GetBinaryPath () const { return loader_.GetBinaryPath (); }
10072 tf::Taskflow &GetTaskflow () { return tf_; }
10173
10274private:
103- void GenerateTask (tf::FlowBuilder &builder);
75+ void Initialize ();
76+
77+ void GenerateTask ();
10478 void Convert ();
105- void
106- BuildGenerate (std::vector<const internal::GenInfo *> &generated_files,
107- std::vector<const internal::GenInfo *> &dummy_generated_files);
108- bool
109- Regenerate (std::vector<const internal::GenInfo *> &generated_files,
110- std::vector<const internal::GenInfo *> &dummy_generated_files);
79+ void BuildGenerate ();
11180
11281 bool Store () override ;
11382
@@ -120,15 +89,20 @@ class Generator : public BuilderInterface {
12089 void CommandChanged ();
12190
12291private:
92+ // Constructor
12393 std::string name_;
124- std::unordered_map<std::string, internal::GenInfo> current_info_;
125-
126- custom_regenerate_cb_params custom_regenerate_cb_;
127- std::function<void (void )> pregenerate_cb_{[]() {}};
128- std::function<void (void )> postgenerate_cb_{[]() {}};
129-
94+ fs::path generator_root_dir_;
95+ fs::path generator_build_dir_;
13096 internal::GeneratorLoader loader_;
13197
98+ // Serialization
99+ internal::default_files current_input_files_;
100+ internal::fs_unordered_set current_output_files_;
101+ std::vector<std::string> current_commands_;
102+ bool parallel_{false };
103+
104+ // Internal
105+ Command command_;
132106 tf::Taskflow tf_;
133107};
134108
0 commit comments