From ef7ab06044c155e4728e5e30e3262de2bb40cb29 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Fri, 24 Sep 2021 18:06:14 +0200 Subject: Fix re-compilation of library itself after boostrap. Add support for supplying libctor lib and include paths. --- bootstrap.sh | 4 ++-- ctor.cc | 2 +- src/build.cc | 25 +++++++++++++++--------- src/configure.cc | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- src/libctor.h | 3 +++ src/rebuild.cc | 14 +++++++++++++- 6 files changed, 92 insertions(+), 14 deletions(-) diff --git a/bootstrap.sh b/bootstrap.sh index 833d3be..815c12f 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh echo "Bootstrapping..." -g++ -std=c++17 -I. -Isrc -pthread src/*.cc ctor.cc test/ctor.cc -o ctor && \ +g++ -std=c++17 -O3 -Isrc -pthread src/*.cc ctor.cc test/ctor.cc -o ctor && \ echo "Done. Now run ./ctor to build." diff --git a/ctor.cc b/ctor.cc index a7c52bf..2e5c763 100644 --- a/ctor.cc +++ b/ctor.cc @@ -1,7 +1,7 @@ // -*- c++ -*- // Distributed under the BSD 2-Clause License. // See accompanying file LICENSE for details. -#include "libctor.h" +#include namespace { diff --git a/src/build.cc b/src/build.cc index 1b70c5b..425ccd3 100644 --- a/src/build.cc +++ b/src/build.cc @@ -78,16 +78,19 @@ int build(const Settings& settings, process != processes.end(); ++process) { - if(process->valid()) + if(process->valid() == false) { - if(process->get() != 0) - { - // TODO: Wait for other processes to finish before returning - return 1; - } - processes.erase(process); - break; + continue; + } + + auto ret = process->get(); + if(ret != 0) + { + // NOTE Wait for other processes to finish before returning + return ret; } + processes.erase(process); + break; } if(started_one) @@ -104,11 +107,15 @@ int build(const Settings& settings, process != processes.end(); ++process) { + if(process->valid() == false) + { + continue; + } process->wait(); auto ret = process->get(); if(ret != 0) { - return 1; + return ret; } } diff --git a/src/configure.cc b/src/configure.cc index b3517dc..9eca0d6 100644 --- a/src/configure.cc +++ b/src/configure.cc @@ -6,6 +6,7 @@ #include #include #include +#include #include @@ -13,6 +14,7 @@ #include "execute.h" #include "libctor.h" #include "tasks.h" +#include "rebuild.h" std::filesystem::path configurationFile("configuration.cc"); std::filesystem::path configHeaderFile("config.h"); @@ -23,8 +25,24 @@ const std::map& __attribute__((weak)) configuration() return default_configuration; } +namespace ctor +{ +std::optional includedir; +std::optional libdir; +} + bool hasConfiguration(const std::string& key) { + if(key == cfg::ctor_includedir && ctor::includedir) + { + return true; + } + + if(key == cfg::ctor_libdir && ctor::libdir) + { + return true; + } + const auto& c = configuration(); return c.find(key) != c.end(); } @@ -32,6 +50,16 @@ bool hasConfiguration(const std::string& key) const std::string& getConfiguration(const std::string& key, const std::string& defaultValue) { + if(key == cfg::ctor_includedir && ctor::includedir) + { + return *ctor::includedir; + } + + if(key == cfg::ctor_libdir && ctor::libdir) + { + return *ctor::libdir; + } + const auto& c = configuration(); if(hasConfiguration(key)) { @@ -119,6 +147,8 @@ int configure(int argc, char* argv[]) std::string cxx_prog = "g++"; std::string ar_prog = "ar"; std::string ld_prog = "ld"; + std::string ctor_includedir; + std::string ctor_libdir; opt.add("build-dir", required_argument, 'b', "Set output directory for build files (default: '" + @@ -191,6 +221,20 @@ int configure(int argc, char* argv[]) return 0; }); + opt.add("ctor-includedir", required_argument, key++, + "Set path to ctor header file, used for re-compiling.", + [&]() { + ctor_includedir = optarg; + return 0; + }); + + opt.add("ctor-libdir", required_argument, key++, + "Set path to ctor library file, used for re-compiling.", + [&]() { + ctor_libdir = optarg; + return 0; + }); + opt.add("help", no_argument, 'h', "Print this help text.", [&]() { @@ -273,7 +317,7 @@ int configure(int argc, char* argv[]) std::cout << "Writing results to: " << configurationFile.string() << "\n"; { std::ofstream istr(configurationFile); - istr << "#include \"libctor.h\"\n\n"; + istr << "#include \n\n"; istr << "const std::map& configuration()\n"; istr << "{\n"; istr << " static std::map c =\n"; @@ -288,6 +332,16 @@ int configure(int argc, char* argv[]) istr << " { \"" << cfg::build_cxx << "\", \"" << build_cxx << "\" },\n"; istr << " { \"" << cfg::build_ar << "\", \"" << build_ar << "\" },\n"; istr << " { \"" << cfg::build_ld << "\", \"" << build_ld << "\" },\n"; + if(!ctor_includedir.empty()) + { + istr << " { \"" << cfg::ctor_includedir << "\", \"" << ctor_includedir << "\" },\n"; + ctor::includedir = ctor_includedir; + } + if(!ctor_libdir.empty()) + { + istr << " { \"" << cfg::ctor_libdir << "\", \"" << ctor_libdir << "\" },\n"; + ctor::libdir = ctor_libdir; + } istr << " };\n"; istr << " return c;\n"; istr << "}\n"; @@ -300,5 +354,7 @@ int configure(int argc, char* argv[]) istr << "//#define HAS_BAR 1\n"; } + recompileCheck(settings, 1, argv, true, false); + return 0; } diff --git a/src/libctor.h b/src/libctor.h index 70c62a8..6903c6b 100644 --- a/src/libctor.h +++ b/src/libctor.h @@ -71,6 +71,9 @@ constexpr auto build_cc = "build-cc"; constexpr auto build_cxx = "build-cpp"; constexpr auto build_ar = "build-ar"; constexpr auto build_ld = "build-ld"; + +constexpr auto ctor_includedir = "ctor-includedir"; +constexpr auto ctor_libdir = "ctor-libdir"; } const std::map& configuration(); diff --git a/src/rebuild.cc b/src/rebuild.cc index 353beb0..7c90fca 100644 --- a/src/rebuild.cc +++ b/src/rebuild.cc @@ -60,12 +60,24 @@ int unreg(const char* location) void recompileCheck(const Settings& settings, int argc, char* argv[], bool force, bool relaunch_allowed) { + using namespace std::string_literals; + bool dirty{force}; std::vector args; args.push_back("-s"); args.push_back("-O3"); args.push_back("-std=c++17"); + + if(hasConfiguration(cfg::ctor_includedir)) + { + args.push_back("-I"s + getConfiguration(cfg::ctor_includedir)); + } + if(hasConfiguration(cfg::ctor_libdir)) + { + args.push_back("-L"s + getConfiguration(cfg::ctor_libdir)); + } + args.push_back("-lctor"); args.push_back("-pthread"); std::filesystem::path binFile(argv[0]); @@ -113,7 +125,7 @@ void recompileCheck(const Settings& settings, int argc, char* argv[], args.push_back(location); } } - args.push_back("libctor.a"); + args.push_back("-o"); args.push_back(binFile.string()); -- cgit v1.2.3