From 8a35724397e84e9d23a44a4f2d3a3e73fe25d9e7 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Tue, 22 Jun 2021 18:48:16 +0200 Subject: Add parameters to add, delete and list build configurations. --- Makefile | 4 +-- bootstrap.sh | 7 +---- libcppbuild.cc | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 90 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index 4b43083..14d909e 100644 --- a/Makefile +++ b/Makefile @@ -24,8 +24,8 @@ CXXFLAGS = -g -O3 -std=c++17 -I. libcppbuild.a: $(OBJ) ar rcs $@ $(OBJ) -cppbuild: cppbuild.cc subdir/cppbuild.cc libcppbuild.a - g++ $(CXXFLAGS) -pthread cppbuild.cc subdir/cppbuild.cc libcppbuild.a -o $@ +cppbuild: libcppbuild.a + g++ $(CXXFLAGS) -pthread libcppbuild.a -o $@ clean: rm -f libcppbuild.a $(OBJ) cppbuild $(DEPFILES) diff --git a/bootstrap.sh b/bootstrap.sh index 0172c10..29b422b 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -1,7 +1,2 @@ #!/bin/bash -CFGS="\ - cppbuild.cc \ - subdir/cppbuild.cc \ -" - -g++ -std=c++17 $CFGS -pthread libcppbuild.a -o cppbuild +g++ -std=c++17 -pthread libcppbuild.a -o cppbuild diff --git a/libcppbuild.cc b/libcppbuild.cc index 5e63029..7280910 100644 --- a/libcppbuild.cc +++ b/libcppbuild.cc @@ -12,6 +12,7 @@ #include #include #include +#include #include @@ -147,7 +148,7 @@ struct BuildConfigurationEntry std::vector (*cb)(); }; std::array configFiles; -int numConfigFiles{0}; +std::size_t numConfigFiles{0}; } // TODO: Use c++20 when ready, somehing like this: @@ -165,12 +166,37 @@ int reg(const char* location, std::vector (*cb)()) configFiles[numConfigFiles].file = location; configFiles[numConfigFiles].cb = cb; ++numConfigFiles; + return 0; } -void recompileCheck(const Settings& settings, int argc, char* argv[]) +int unreg(const char* location) { - bool dirty{false}; + std::size_t found{0}; + for(std::size_t i = 0; i < numConfigFiles;) + { + if(std::string(location) == configFiles[i].file) + { + ++found; + for(std::size_t j = i; j < numConfigFiles; ++j) + { + configFiles[j] = configFiles[j + 1]; + } + --numConfigFiles; + } + else + { + ++i; + } + } + + return found; +} + +void recompileCheck(const Settings& settings, int argc, char* argv[], + bool force = false) +{ + bool dirty{force}; std::vector args; args.push_back("-s"); @@ -203,7 +229,7 @@ void recompileCheck(const Settings& settings, int argc, char* argv[]) std::cout << "Recompile check (" << numConfigFiles << "):\n"; } - for(int i = 0; i < numConfigFiles; ++i) + for(std::size_t i = 0; i < numConfigFiles; ++i) { std::string location = configFiles[i].file; if(settings.verbose > 1) @@ -254,7 +280,7 @@ std::list> getTasks(const Settings& settings) { static std::deque build_configs; std::list> tasks; - for(int i = 0; i < numConfigFiles; ++i) + for(std::size_t i = 0; i < numConfigFiles; ++i) { std::string path = std::filesystem::path(configFiles[i].file).parent_path(); @@ -410,6 +436,9 @@ int main(int argc, char* argv[]) std::string compilation_database; bool print_configure_cmd{false}; bool print_configure_db{false}; + std::vector add_files; + std::vector remove_files; + bool list_files{false}; dg::Options opt; int key{256}; @@ -444,6 +473,27 @@ int main(int argc, char* argv[]) return 0; }); + opt.add("add", required_argument, 'a', + "Add specified file to the build configurations.", + [&]() { + add_files.push_back(optarg); + return 0; + }); + + opt.add("remove", required_argument, 'r', + "Remove specified file from the build configurations.", + [&]() { + remove_files.push_back(optarg); + return 0; + }); + + opt.add("list", no_argument, 'l', + "List files in the build configurations.", + [&]() { + list_files = true; + return 0; + }); + opt.add("configure-cmd", no_argument, key++, "Print commandline for last configure.", [&]() { @@ -477,6 +527,38 @@ int main(int argc, char* argv[]) opt.process(argc, argv); + if(list_files) + { + std::set files; + for(std::size_t i = 0; i < numConfigFiles; ++i) + { + files.insert(configFiles[i].file); + } + + for(const auto& file : files) + { + std::cout << file << "\n"; + } + + return 0; + } + + if(!add_files.empty() || !remove_files.empty()) + { + for(const auto& add_file : add_files) + { + reg(add_file.data(), [](){ return std::vector{};}); + } + + for(const auto& remove_file : remove_files) + { + unreg(remove_file.data()); + } + + // Force rebuild if files were added + recompileCheck(settings, 1, argv, true); + } + recompileCheck(settings, argc, argv); std::filesystem::path builddir(settings.builddir); -- cgit v1.2.3