From bc474f716407dec521626e76b6101df4a2f1a40a Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sat, 30 Oct 2021 18:02:10 +0200 Subject: Add external configs. --- src/rebuild.cc | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'src/rebuild.cc') diff --git a/src/rebuild.cc b/src/rebuild.cc index c1f2a4a..3492955 100644 --- a/src/rebuild.cc +++ b/src/rebuild.cc @@ -55,9 +55,48 @@ int unreg(const char* location) } } + for(std::size_t i = 0; i < numExternalConfigFiles;) + { + if(std::string(location) == externalConfigFiles[i].file) + { + ++found; + for(std::size_t j = i; j < numExternalConfigFiles; ++j) + { + externalConfigFiles[j] = externalConfigFiles[j + 1]; + } + --numExternalConfigFiles; + } + else + { + ++i; + } + } + return found; } +std::array externalConfigFiles; +std::size_t numExternalConfigFiles{0}; + +// TODO: Use c++20 when ready, somehing like this: +//int reg(const std::source_location location = std::source_location::current()) +int reg(const char* location, std::vector (*cb)()) +{ + // NOTE: std::cout cannot be used here + if(numExternalConfigFiles >= externalConfigFiles.size()) + { + fprintf(stderr, "Max %d external configurations currently supported.\n", + (int)externalConfigFiles.size()); + exit(1); + } + + externalConfigFiles[numExternalConfigFiles].file = location; + externalConfigFiles[numExternalConfigFiles].cb = cb; + ++numExternalConfigFiles; + + return 0; +} + namespace { bool contains(const std::vector& sources, const std::string& file) @@ -130,6 +169,21 @@ void recompileCheck(const Settings& global_settings, int argc, char* argv[], } } + for(std::size_t i = 0; i < numExternalConfigFiles; ++i) + { + std::string location = externalConfigFiles[i].file; + if(global_settings.verbose > 1) + { + std::cout << " - " << location << "\n"; + } + + // Ensure that files containing multiple configurations are only added once. + if(!contains(config.sources, location)) + { + config.sources.push_back(location); + } + } + auto tasks = taskFactory({config}, settings, {}); for(auto task : tasks) -- cgit v1.2.3