diff options
| -rw-r--r-- | src/configure.cc | 28 | ||||
| -rw-r--r-- | src/ctor.h | 3 | ||||
| -rw-r--r-- | test/ctor.cc | 7 | ||||
| -rw-r--r-- | test/source_type_test.cc | 3 | ||||
| -rw-r--r-- | test/tasks_test.cc | 4 | ||||
| -rw-r--r-- | test/tools_test.cc | 23 |
6 files changed, 37 insertions, 31 deletions
diff --git a/src/configure.cc b/src/configure.cc index 1b8caa6..5ba87c3 100644 --- a/src/configure.cc +++ b/src/configure.cc @@ -10,6 +10,7 @@ #include <optional> #include <span> #include <cstring> +#include <functional> #include "execute.h" #include "ctor.h" @@ -26,8 +27,30 @@ const std::filesystem::path configHeaderFile("config.h"); std::map<std::string, std::string> external_includedir; std::map<std::string, std::string> external_libdir; -const ctor::configuration& __attribute__((weak)) ctor::get_configuration() +std::function<const ctor::configuration&()>& getConfigurationCallback() { + static std::function<const ctor::configuration&()> configuration_callback; + return configuration_callback; +} + +namespace ctor { +int reg(std::function<const ctor::configuration&()> cb, + [[maybe_unused]]const std::source_location location) +{ + auto& configuration_callback = getConfigurationCallback(); + configuration_callback = cb; + return {}; +} +} // ctor:: + +const ctor::configuration& ctor::get_configuration() +{ + auto& configuration_callback = getConfigurationCallback(); + if(configuration_callback) + { + return configuration_callback(); + } + static ctor::configuration cfg; static bool initialised{false}; if(!initialised) @@ -752,7 +775,7 @@ int regenerateCache(ctor::settings& settings, std::cout << "Generating configuration: " << configurationFile.string() << "\n"; { std::stringstream istr; istr << "#include <ctor.h>\n\n"; - istr << "const ctor::configuration& ctor::get_configuration()\n"; + istr << "const ctor::configuration& stored_configuration()\n"; istr << "{\n"; istr << " static ctor::configuration cfg =\n"; istr << " {\n"; @@ -902,6 +925,7 @@ int regenerateCache(ctor::settings& settings, istr << " };\n"; istr << " return cfg;\n"; istr << "}\n"; + istr << "\nREG(stored_configuration);\n"; auto new_configuration = istr.str(); auto current_configuration = readFile(configurationFile.string()); @@ -579,4 +579,7 @@ struct configuration const ctor::configuration& get_configuration(); +int reg(std::function<const ctor::configuration&()> cb, + const std::source_location location = std::source_location::current()); + } // ctor:: diff --git a/test/ctor.cc b/test/ctor.cc index afec91c..d1c0188 100644 --- a/test/ctor.cc +++ b/test/ctor.cc @@ -31,6 +31,7 @@ ctor::build_configurations ctorTestConfigs(const ctor::settings& settings) ctor::sources{ "generated_sources_test.cc", "testmain.cc", + "../configuration.cc", }, ctor::depends({"libctor_nomain.a"}), ctor::cxx_flags{ @@ -146,6 +147,7 @@ ctor::build_configurations ctorTestConfigs(const ctor::settings& settings) ctor::sources{ "cycle_test.cc", "testmain.cc", + "../configuration.cc", }, ctor::depends({"libctor_nomain.a"}), ctor::cxx_flags{ @@ -163,6 +165,7 @@ ctor::build_configurations ctorTestConfigs(const ctor::settings& settings) ctor::sources{ "source_type_test.cc", "testmain.cc", + "../configuration.cc", }, ctor::depends({"libctor_nomain.a"}), ctor::cxx_flags{ @@ -180,8 +183,7 @@ ctor::build_configurations ctorTestConfigs(const ctor::settings& settings) ctor::sources{ "tools_test.cc", "testmain.cc", - "../src/util.cc", - "../src/tools.cc", + "../configuration.cc", }, ctor::depends({"libctor_nomain.a"}), ctor::cxx_flags{ @@ -212,7 +214,6 @@ ctor::build_configurations ctorTestConfigs(const ctor::settings& settings) "../src/tools.cc", "../src/util.cc", "../src/externals_manual.cc", - "../configuration.cc", }, ctor::cxx_flags{ "-std=c++20", "-O3", "-Wall", diff --git a/test/source_type_test.cc b/test/source_type_test.cc index 90e77cf..345c591 100644 --- a/test/source_type_test.cc +++ b/test/source_type_test.cc @@ -26,13 +26,14 @@ std::ostream& operator<<(std::ostream& stream, const ctor::language& lang) return stream; } -const ctor::configuration& ctor::get_configuration() +const ctor::configuration& test_configuration() { static ctor::configuration cfg{}; cfg.build_toolchain = ctor::toolchain::gcc; cfg.build_arch = ctor::arch::unix; return cfg; } +REG(test_configuration); class TestableTaskCC : public TaskCC diff --git a/test/tasks_test.cc b/test/tasks_test.cc index 32bed5a..c8e4cf8 100644 --- a/test/tasks_test.cc +++ b/test/tasks_test.cc @@ -38,14 +38,14 @@ namespace test_global { ctor::toolchain toolchain{}; ctor::arch arch{}; } -const ctor::configuration& ctor::get_configuration() +const ctor::configuration& test_configuration() { static ctor::configuration cfg{}; cfg.build_toolchain = test_global::toolchain; cfg.build_arch = test_global::arch; return cfg; } - +REG(test_configuration); REG(ctorTestConfigs1); REG(ctorTestConfigs2); diff --git a/test/tools_test.cc b/test/tools_test.cc index 5ae04c3..cfbcbce 100644 --- a/test/tools_test.cc +++ b/test/tools_test.cc @@ -114,29 +114,6 @@ bool operator!=(const ctor::asm_flag& a, const ctor::asm_flag& b) #include <uunit.h> -const ctor::configuration& ctor::get_configuration() -{ - static ctor::configuration cfg; - return cfg; -} - -std::string ctor::configuration::get(const std::string& key, [[maybe_unused]]const std::string& default_value) const -{ - if(key == ctor::cfg::host_cxx) - { - return {}; - } - - if(key == ctor::cfg::build_cxx) - { - return {}; - } - - assert(false); // bad key - - return {}; -} - class ToolsTest : public uUnit { |
