From 6accb227b75fef7e99257b0078eb95f9aa0823cc Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Mon, 2 Feb 2026 18:30:58 +0100 Subject: New syntax --- src/ctor.h | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- src/task_fn.cc | 27 ++++++++---------- src/tasks.cc | 11 ++++---- 3 files changed, 102 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/ctor.h b/src/ctor.h index 29c8f6d..aa46e5f 100644 --- a/src/ctor.h +++ b/src/ctor.h @@ -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; + +struct depends +{ + std::vector depends; +}; + +struct externals +{ + std::vector externals; +}; + struct build_configuration { + template + requires (( + std::is_same_v || + std::is_same_v || + std::is_same_v || + std::is_same_v || + std::is_same_v || + std::is_same_v || + std::is_same_v || + std::is_same_v || + std::is_same_v || + std::is_same_v + ) && ...) + constexpr build_configuration(Args && ... arg) + { + ([&] + { + if constexpr(std::is_same_v) + { + name = arg.name; + } + else if constexpr(std::is_same_v) + { + type = arg; + } + else if constexpr(std::is_same_v) + { + system = arg; + } + else if constexpr(std::is_same_v) + { + target = arg.target; + } + else if constexpr(std::is_same_v) + { + sources = arg; + } + else if constexpr(std::is_same_v) + { + depends = arg.depends; + } + else if constexpr(std::is_same_v) + { + flags = arg; + } + else if constexpr(std::is_same_v) + { + externals = arg.externals; + } + else if constexpr(std::is_same_v) + { + function_one_to_one = arg; + } + else if constexpr(std::is_same_v) + { + 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 depends; // internal target dependencies ctor::flags flags; std::vector externals; // externals used by this configuration - std::variant function; + ctor::GeneratorOneToOne function_one_to_one; + ctor::GeneratorManyToOne function_many_to_one; }; using build_configurations = std::vector; 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(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(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(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(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(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(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(config.function)) + if(config.function_one_to_one) { - } - else if(std::holds_alternative(config.function)) - { - auto func = std::get(config.function); + auto func = config.function_one_to_one; res = func(sourceFile.string(), targetFile().string(), config, settings); } - else if(std::holds_alternative(config.function)) + else if(config.function_many_to_one) { - auto func = std::get(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(config.function)) + if(config.function_many_to_one) { if(std::filesystem::exists(sourceListFile)) { @@ -211,7 +208,7 @@ int TaskFn::clean() std::vector TaskFn::depends() const { std::vector deps; - if(std::holds_alternative(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> 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(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> 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(ctor::target_type::object, config, settings, sourceDir, source); @@ -116,8 +118,7 @@ std::vector> taskFactory(const ctor::build_configuration& #ifndef BOOTSTRAP else { - bool multi{std::holds_alternative(config.function)}; - if(multi) + if(config.function_many_to_one) { auto task = std::make_shared(resolved_target_type, config, settings, sourceDir, ""); -- cgit v1.2.3