summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2021-06-22 18:48:16 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2021-06-22 18:48:16 +0200
commit8a35724397e84e9d23a44a4f2d3a3e73fe25d9e7 (patch)
treedd73869b71aae0b05cabc833caa9b161c86b24ff
parentf8a52e96685d636be956b5f89d6f493856c0810f (diff)
Add parameters to add, delete and list build configurations.
-rw-r--r--Makefile4
-rwxr-xr-xbootstrap.sh7
-rw-r--r--libcppbuild.cc92
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 <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);