diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/ctor.h | 87 | ||||
| -rw-r--r-- | src/task_fn.cc | 27 | ||||
| -rw-r--r-- | src/tasks.cc | 11 |
3 files changed, 102 insertions, 23 deletions
@@ -297,8 +297,90 @@ using GeneratorManyToOne = const ctor::build_configuration& config, const ctor::settings& settings)>; +struct name +{ + std::string name; +}; + +struct target +{ + std::string target; +}; + +using sources = std::vector<ctor::source>; + +struct depends +{ + std::vector<std::string> depends; +}; + +struct externals +{ + std::vector<std::string> externals; +}; + struct build_configuration { + template <class ... Args> + requires (( + std::is_same_v<Args, ctor::name> || + std::is_same_v<Args, ctor::target_type> || + std::is_same_v<Args, ctor::output_system> || + std::is_same_v<Args, ctor::target> || + std::is_same_v<Args, ctor::sources> || + std::is_same_v<Args, ctor::depends> || + std::is_same_v<Args, ctor::flags> || + std::is_same_v<Args, ctor::externals> || + std::is_same_v<Args, ctor::GeneratorOneToOne> || + std::is_same_v<Args, ctor::GeneratorManyToOne> + ) && ...) + constexpr build_configuration(Args && ... arg) + { + ([&] + { + if constexpr(std::is_same_v<Args, ctor::name>) + { + name = arg.name; + } + else if constexpr(std::is_same_v<Args, ctor::target_type>) + { + type = arg; + } + else if constexpr(std::is_same_v<Args, ctor::output_system>) + { + system = arg; + } + else if constexpr(std::is_same_v<Args, ctor::target>) + { + target = arg.target; + } + else if constexpr(std::is_same_v<Args, ctor::sources>) + { + sources = arg; + } + else if constexpr(std::is_same_v<Args, ctor::depends>) + { + depends = arg.depends; + } + else if constexpr(std::is_same_v<Args, ctor::flags>) + { + flags = arg; + } + else if constexpr(std::is_same_v<Args, ctor::externals>) + { + externals = arg.externals; + } + else if constexpr(std::is_same_v<Args, ctor::GeneratorOneToOne>) + { + function_one_to_one = arg; + } + else if constexpr(std::is_same_v<Args, ctor::GeneratorManyToOne>) + { + function_many_to_one = arg; + } + }(), ...); + } + std::string name; // Name - used for referring in other configurations. ctor::target_type type{ctor::target_type::automatic}; ctor::output_system system{ctor::output_system::build}; @@ -307,9 +389,8 @@ struct build_configuration std::vector<std::string> depends; // internal target dependencies ctor::flags flags; std::vector<std::string> externals; // externals used by this configuration - std::variant<std::monostate, - GeneratorOneToOne, - GeneratorManyToOne> function; + ctor::GeneratorOneToOne function_one_to_one; + ctor::GeneratorManyToOne function_many_to_one; }; using build_configurations = std::vector<build_configuration>; diff --git a/src/task_fn.cc b/src/task_fn.cc index b712e70..4f27cc7 100644 --- a/src/task_fn.cc +++ b/src/task_fn.cc @@ -24,7 +24,7 @@ TaskFn::TaskFn(ctor::target_type resolved_target_type, sourceDir.parent_path()); source_language = source.language; - if(std::holds_alternative<ctor::GeneratorOneToOne>(config.function)) + if(config.function_one_to_one) { if(source.source_type == ctor::source_type::generated) { @@ -41,7 +41,7 @@ TaskFn::TaskFn(ctor::target_type resolved_target_type, } _targetFile = base / source.output; } - else if(std::holds_alternative<ctor::GeneratorManyToOne>(config.function)) + else if(config.function_many_to_one) { for(const auto& src : config.sources) { @@ -74,7 +74,7 @@ bool TaskFn::dirtyInner() return true; } - if(std::holds_alternative<ctor::GeneratorManyToOne>(config.function)) + if(config.function_many_to_one) { if(!std::filesystem::exists(sourceListFile)) { @@ -94,7 +94,7 @@ bool TaskFn::dirtyInner() std::filesystem::file_time_type last_changed{}; bool missing{false}; - if(std::holds_alternative<ctor::GeneratorOneToOne>(config.function)) + if(config.function_one_to_one) { if(!std::filesystem::exists(sourceFile)) { @@ -102,7 +102,7 @@ bool TaskFn::dirtyInner() } last_changed = std::filesystem::last_write_time(sourceFile); } - else if(std::holds_alternative<ctor::GeneratorManyToOne>(config.function)) + else if(config.function_many_to_one) { bool first{true}; for(const auto& source : sources) @@ -144,7 +144,7 @@ bool TaskFn::dirtyInner() int TaskFn::runInner() { - if(std::holds_alternative<ctor::GeneratorManyToOne>(config.function)) + if(config.function_many_to_one) { // Write sourceList to file. std::ofstream sourceListStream(sourceListFile.string()); @@ -160,20 +160,17 @@ int TaskFn::runInner() } int res{}; - if(std::holds_alternative<std::monostate>(config.function)) + if(config.function_one_to_one) { - } - else if(std::holds_alternative<ctor::GeneratorOneToOne>(config.function)) - { - auto func = std::get<ctor::GeneratorOneToOne>(config.function); + auto func = config.function_one_to_one; res = func(sourceFile.string(), targetFile().string(), config, settings); } - else if(std::holds_alternative<ctor::GeneratorManyToOne>(config.function)) + else if(config.function_many_to_one) { - auto func = std::get<ctor::GeneratorManyToOne>(config.function); + auto func = config.function_many_to_one; res = func(sources, targetFile().string(), config, @@ -196,7 +193,7 @@ int TaskFn::clean() std::filesystem::remove(targetFile()); } - if(std::holds_alternative<ctor::GeneratorManyToOne>(config.function)) + if(config.function_many_to_one) { if(std::filesystem::exists(sourceListFile)) { @@ -211,7 +208,7 @@ int TaskFn::clean() std::vector<std::string> TaskFn::depends() const { std::vector<std::string> deps; - if(std::holds_alternative<ctor::GeneratorManyToOne>(config.function)) + if(config.function_many_to_one) { for(const auto& src : config.sources) { diff --git a/src/tasks.cc b/src/tasks.cc index f520772..5e1d235 100644 --- a/src/tasks.cc +++ b/src/tasks.cc @@ -85,7 +85,7 @@ std::vector<std::shared_ptr<Task>> taskFactory(const ctor::build_configuration& ctor::target_type resolved_target_type{config.type}; if(resolved_target_type == ctor::target_type::automatic) { - if(!std::holds_alternative<std::monostate>(config.function)) + if(config.function_one_to_one || config.function_many_to_one) { resolved_target_type = ctor::target_type::function; } @@ -103,8 +103,10 @@ std::vector<std::shared_ptr<Task>> taskFactory(const ctor::build_configuration& for(const auto& source : config.sources) { if(source.toolchain == ctor::toolchain::any || - (config.system == ctor::output_system::build && source.toolchain == c.build_toolchain) || - (config.system == ctor::output_system::host && source.toolchain == c.host_toolchain)) + (config.system == ctor::output_system::build && + source.toolchain == c.build_toolchain) || + (config.system == ctor::output_system::host && + source.toolchain == c.host_toolchain)) { auto task = std::make_shared<TaskCC>(ctor::target_type::object, config, settings, sourceDir, source); @@ -116,8 +118,7 @@ std::vector<std::shared_ptr<Task>> taskFactory(const ctor::build_configuration& #ifndef BOOTSTRAP else { - bool multi{std::holds_alternative<ctor::GeneratorManyToOne>(config.function)}; - if(multi) + if(config.function_many_to_one) { auto task = std::make_shared<TaskFn>(resolved_target_type, config, settings, sourceDir, ""); |
