diff options
author | Bent Bisballe Nyeng <deva@aasimon.org> | 2021-06-19 11:58:12 +0200 |
---|---|---|
committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2021-06-19 11:58:12 +0200 |
commit | 9fe6626a63718635cca6ce8920e1669d099d46a7 (patch) | |
tree | a63b415b0f8a9c2a97ab703234214b6fa7d61eb8 /libcppbuild.cc | |
parent | a2be8eba3aaf11a9a73092793d27d6d46b4270cd (diff) |
Make self-aware (and recompile/re-launch as needed)
Diffstat (limited to 'libcppbuild.cc')
-rw-r--r-- | libcppbuild.cc | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/libcppbuild.cc b/libcppbuild.cc index 69d23ba..b400061 100644 --- a/libcppbuild.cc +++ b/libcppbuild.cc @@ -18,6 +18,7 @@ #include "task_ar.h" #include "task_so.h" #include "settings.h" +#include "execute.h" #include <unistd.h> @@ -82,8 +83,60 @@ std::shared_ptr<Task> getNextTask(const std::list<std::shared_ptr<Task>>& allTas return nullptr; } +namespace +{ +// Hack to get command-line args for re-launch +int g_argc; +char** g_argv; +} + +// TODO: Use c++20 when ready, somehing like this: +//void reg(const std::source_location location = +// std::source_location::current()) +void reg(const std::string& location) +{ + std::filesystem::path configFile(location); + std::filesystem::path binFile(configFile.stem()); + if(std::filesystem::last_write_time(binFile) <= + std::filesystem::last_write_time(configFile)) + { + std::cout << "Rebuilding config\n"; + auto ret = execute("/usr/bin/g++", + { + "-s", + "-O3", + "-std=c++17", + "-pthread", + configFile.string(), + "libcppbuild.a", + "-o", + binFile.string(), + }); + if(ret != 0) + { + std::cerr << "Failed.\n"; + exit(1); + } + else + { + std::cout << "Re-launch\n"; + std::vector<std::string> args; + for(int i = 1; i < g_argc; ++i) + { + args.push_back(g_argv[i]); + } + exit(execute(g_argv[0], args)); + } + } + +// g++ -s -O3 -std=c++17 -pthread $0 libcppbuild.a -o cppbuild +} + int main(int argc, char* argv[]) { + g_argc = argc; + g_argv = argv; + Settings settings; // TODO: Set from commandline settings.builddir = "build/foo"; |