summaryrefslogtreecommitdiff
path: root/libcppbuild.cc
diff options
context:
space:
mode:
Diffstat (limited to 'libcppbuild.cc')
-rw-r--r--libcppbuild.cc92
1 files changed, 87 insertions, 5 deletions
diff --git a/libcppbuild.cc b/libcppbuild.cc
index 5e63029..7280910 100644
--- a/libcppbuild.cc
+++ b/libcppbuild.cc
@@ -12,6 +12,7 @@
#include <array>
#include <deque>
#include <fstream>
+#include <set>
#include <getoptpp/getoptpp.hpp>
@@ -147,7 +148,7 @@ struct BuildConfigurationEntry
std::vector<BuildConfiguration> (*cb)();
};
std::array<BuildConfigurationEntry, 1024> 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<BuildConfiguration> (*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<std::string> 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<std::shared_ptr<Task>> getTasks(const Settings& settings)
{
static std::deque<BuildConfiguration> build_configs;
std::list<std::shared_ptr<Task>> 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<std::string> add_files;
+ std::vector<std::string> 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<std::string> 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<BuildConfiguration>{};});
+ }
+
+ 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);