From c0eacf8e85003844b95e71b9004fa464d4586a38 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Thu, 14 Oct 2021 22:19:26 +0200 Subject: Use dependency system and build system for compiling ctor on config changes. --- src/rebuild.cc | 110 +++++++++++++++++++++++++-------------------------------- 1 file changed, 49 insertions(+), 61 deletions(-) (limited to 'src/rebuild.cc') diff --git a/src/rebuild.cc b/src/rebuild.cc index 7c90fca..e017d92 100644 --- a/src/rebuild.cc +++ b/src/rebuild.cc @@ -7,10 +7,11 @@ #include #include -#include "execute.h" #include "configure.h" #include "settings.h" #include "libctor.h" +#include "tasks.h" +#include "build.h" std::array configFiles; std::size_t numConfigFiles{0}; @@ -57,100 +58,87 @@ int unreg(const char* location) return found; } -void recompileCheck(const Settings& settings, int argc, char* argv[], +namespace +{ +bool contains(const std::vector& sources, const std::string& file) +{ + for(const auto& source : sources) + { + if(source.file == file) + { + return true; + } + } + + return false; +} +} + +void recompileCheck(const Settings& global_settings, int argc, char* argv[], bool force, bool relaunch_allowed) { using namespace std::string_literals; - bool dirty{force}; + if(global_settings.verbose > 1) + { + std::cout << "Recompile check (" << numConfigFiles << "):\n"; + } - std::vector args; - args.push_back("-s"); - args.push_back("-O3"); - args.push_back("-std=c++17"); + BuildConfiguration config; + config.name = "ctor"; + config.cxxflags = std::vector({ "-s", "-O3", "-std=c++17" }); if(hasConfiguration(cfg::ctor_includedir)) { - args.push_back("-I"s + getConfiguration(cfg::ctor_includedir)); + config.cxxflags.push_back("-I"s + getConfiguration(cfg::ctor_includedir)); } if(hasConfiguration(cfg::ctor_libdir)) { - args.push_back("-L"s + getConfiguration(cfg::ctor_libdir)); + config.ldflags.push_back("-L"s + getConfiguration(cfg::ctor_libdir)); } - args.push_back("-lctor"); - args.push_back("-pthread"); + config.ldflags.push_back("-lctor"); + config.ldflags.push_back("-pthread"); - std::filesystem::path binFile(argv[0]); - if(std::filesystem::exists(configurationFile)) - { - args.push_back(configurationFile.string()); + Settings settings{global_settings}; + settings.verbose = -1; // Make check completely silent. + settings.builddir += "/ctor"; // override builddir to use ctor subdir - if(std::filesystem::last_write_time(binFile) <= - std::filesystem::last_write_time(configurationFile)) - { - dirty = true; - } - - const auto& c = configuration(); - if(&c == &default_configuration) - { - // configuration.cc exists, but currently compiled with the default one. - dirty = true; - } + { + std::filesystem::path buildfile = settings.builddir; + std::filesystem::path currentfile = argv[0]; + config.target = std::filesystem::relative(currentfile, buildfile).string(); } - if(settings.verbose > 1) + if(std::filesystem::exists(configurationFile)) { - std::cout << "Recompile check (" << numConfigFiles << "):\n"; + config.sources.push_back(configurationFile.string()); } for(std::size_t i = 0; i < numConfigFiles; ++i) { std::string location = configFiles[i].file; - if(settings.verbose > 1) + if(global_settings.verbose > 1) { std::cout << " - " << location << "\n"; } - std::filesystem::path configFile(location); - if(std::filesystem::last_write_time(binFile) <= - std::filesystem::last_write_time(configFile)) - { - dirty = true; - } - // Support adding multiple config functions from the same file - if(std::find(args.begin(), args.end(), location) == std::end(args)) + // Ensure that files containing multiple configurations are only added once. + if(!contains(config.sources, location)) { - args.push_back(location); + config.sources.push_back(location); } } - args.push_back("-o"); - args.push_back(binFile.string()); + auto tasks = taskFactory({config}, settings, {}); - if(dirty) + for(auto task : tasks) { - std::cout << "Rebuilding config\n"; - auto tool = getConfiguration(cfg::build_cxx, "/usr/bin/g++"); - auto ret = execute(tool, args, settings.verbose > 0); - if(ret != 0) + if(task->registerDepTasks(tasks)) { - std::cerr << "Failed: ." << ret << "\n"; - exit(1); - } - else - { - if(relaunch_allowed) - { - std::cout << "Re-launch\n"; - std::vector args; - for(int i = 1; i < argc; ++i) - { - args.push_back(argv[i]); - } - exit(execute(argv[0], args, settings.verbose > 0)); - } + return; } } + + build(settings, "ctor", tasks); } -- cgit v1.2.3