diff options
author | Bent Bisballe Nyeng <deva@aasimon.org> | 2021-10-30 18:02:10 +0200 |
---|---|---|
committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2021-10-30 18:02:10 +0200 |
commit | bc474f716407dec521626e76b6101df4a2f1a40a (patch) | |
tree | 2e7aa3ba12a1f65297225616ad4de59b181c932c /src/rebuild.cc | |
parent | 7bf162fcd98920644e4f61ac0181037eb62c807e (diff) |
Add external configs.
Diffstat (limited to 'src/rebuild.cc')
-rw-r--r-- | src/rebuild.cc | 54 |
1 files changed, 54 insertions, 0 deletions
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<ExternalConfigurationEntry, 1024> 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<ExternalConfiguration> (*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<Source>& 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) |