summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2023-01-11 16:35:57 +0100
committerBent Bisballe Nyeng <deva@aasimon.org>2023-01-11 17:09:12 +0100
commitf31661d392c1332ceb0edcbc9fd35f4cb49bb50d (patch)
tree6034e11da079476e0ab4b0b3c6bfefaee187d5e9
parent0b0cb4afa08210b572a9be6cadcb6397935b99d1 (diff)
Support using custom build-dir during bootstrap.
-rw-r--r--Jenkinsfile16
-rwxr-xr-xbootstrap.sh5
-rw-r--r--src/bootstrap.cc8
-rw-r--r--src/configure.cc30
4 files changed, 39 insertions, 20 deletions
diff --git a/Jenkinsfile b/Jenkinsfile
index 9a99f2d..14f0547 100644
--- a/Jenkinsfile
+++ b/Jenkinsfile
@@ -5,13 +5,13 @@ pipeline {
stage('Clean') {
steps {
echo 'Cleaning workspace ...'
- sh 'rm -Rf build build-gcc build-clang'
+ sh 'rm -Rf build*'
}
}
stage('Build-gcc') {
steps {
echo 'Building (gcc) ...'
- sh './bootstrap.sh'
+ sh 'BUILDDIR=build-gcc CXX=g++ ./bootstrap.sh'
}
}
stage('Test-gcc') {
@@ -19,16 +19,11 @@ pipeline {
echo 'Testing (gcc) ...'
sh './ctor check'
}
- post {
- always {
- sh 'mv build build-gcc'
- }
- }
}
stage('Build-clang') {
steps {
echo 'Building (clang) ...'
- sh 'CXX=clang++ ./bootstrap.sh'
+ sh 'BUILDDIR=build-clang CXX=clang++ ./bootstrap.sh'
}
}
stage('Test-clang') {
@@ -36,11 +31,6 @@ pipeline {
echo 'Testing (clang) ...'
sh './ctor check'
}
- post {
- always {
- sh 'mv build build-clang'
- }
- }
}
}
diff --git a/bootstrap.sh b/bootstrap.sh
index 5873e83..76503bb 100755
--- a/bootstrap.sh
+++ b/bootstrap.sh
@@ -1,10 +1,11 @@
#!/bin/sh
: ${CXX:=g++}
+: ${BUILDDIR:=build}
CXX=$(which $CXX)
echo "Bootstrapping..."
$CXX -std=c++20 -Wall -O3 -Isrc -pthread src/bootstrap.cc ctor.cc test/ctor.cc -o ctor && \
./ctor && \
-$CXX -std=c++20 -Wall -O3 -Isrc -pthread ctor.cc test/ctor.cc -Lbuild -lctor -o ctor && \
-./ctor configure --ctor-includedir=src --ctor-libdir=build && \
+$CXX -std=c++20 -Wall -O3 -Isrc -pthread ctor.cc test/ctor.cc -L$BUILDDIR -lctor -o ctor && \
+./ctor configure --ctor-includedir=src --ctor-libdir=$BUILDDIR --build-dir=$BUILDDIR&& \
echo "Done. Now run ./ctor to (re)build."
diff --git a/src/bootstrap.cc b/src/bootstrap.cc
index c58c399..d473689 100644
--- a/src/bootstrap.cc
+++ b/src/bootstrap.cc
@@ -42,6 +42,12 @@ const std::string& getConfiguration(const std::string& key,
return s;
}
+ if(key == cfg::builddir && std::getenv("BUILDDIR"))
+ {
+ static std::string s = std::getenv("BUILDDIR");
+ return s;
+ }
+
return defaultValue;
}
@@ -56,7 +62,7 @@ int main(int argc, char* argv[])
Settings settings{};
- settings.builddir = getConfiguration(cfg::builddir, "build");
+ settings.builddir = getConfiguration(cfg::builddir, settings.builddir);
settings.parallel_processes =
std::max(1u, std::thread::hardware_concurrency() * 2 - 1);
settings.verbose = 0;
diff --git a/src/configure.cc b/src/configure.cc
index 50a7c32..25403f7 100644
--- a/src/configure.cc
+++ b/src/configure.cc
@@ -32,6 +32,7 @@ namespace ctor
{
std::optional<std::string> includedir;
std::optional<std::string> libdir;
+std::optional<std::string> builddir;
std::map<std::string, std::string> conf_values;
}
@@ -47,6 +48,11 @@ bool hasConfiguration(const std::string& key)
return true;
}
+ if(key == cfg::builddir && ctor::builddir)
+ {
+ return true;
+ }
+
if(ctor::conf_values.find(key) != ctor::conf_values.end())
{
return true;
@@ -69,6 +75,11 @@ const std::string& getConfiguration(const std::string& key,
return *ctor::libdir;
}
+ if(key == cfg::builddir && ctor::builddir)
+ {
+ return *ctor::builddir;
+ }
+
if(ctor::conf_values.find(key) != ctor::conf_values.end())
{
return ctor::conf_values[key];
@@ -160,11 +171,10 @@ public:
// helper constant for the visitor
template<class> inline constexpr bool always_false_v = false;
-int regenerateCache(const Settings& default_settings,
+int regenerateCache(Settings& settings,
const std::vector<std::string>& args,
const std::map<std::string, std::string>& env)
{
- Settings settings{default_settings};
Args vargs(args);
dg::Options opt;
@@ -180,12 +190,14 @@ int regenerateCache(const Settings& default_settings,
std::string ld_prog = "ld";
std::string ctor_includedir;
std::string ctor_libdir;
+ std::string builddir;
opt.add("build-dir", required_argument, 'b',
"Set output directory for build files (default: '" +
settings.builddir + "').",
[&]() {
settings.builddir = optarg;
+ builddir = optarg;
return 0;
});
@@ -396,6 +408,10 @@ int regenerateCache(const Settings& default_settings,
{
ctor::conf_values[cfg::ctor_libdir] = ctor_libdir;
}
+ if(!builddir.empty())
+ {
+ ctor::conf_values[cfg::builddir] = builddir;
+ }
ctor::conf_values[cfg::host_cxx] = host_cxx;
ctor::conf_values[cfg::build_cxx] = build_cxx;
@@ -421,7 +437,11 @@ int regenerateCache(const Settings& default_settings,
istr << "},\n";
istr << " .tools = {\n";
- istr << " { \"" << cfg::builddir << "\", \"" << settings.builddir << "\" },\n";
+ if(!builddir.empty())
+ {
+ istr << " { \"" << cfg::builddir << "\", \"" << builddir << "\" },\n";
+ ctor::builddir = builddir;
+ }
istr << " { \"" << cfg::host_cc << "\", \"" << host_cc << "\" },\n";
istr << " { \"" << cfg::host_cxx << "\", \"" << host_cxx << "\" },\n";
istr << " { \"" << cfg::host_ar << "\", \"" << host_ar << "\" },\n";
@@ -567,8 +587,10 @@ int configure(const Settings& global_settings, int argc, char* argv[])
return 0;
}
-int reconfigure(const Settings& settings, int argc, char* argv[])
+int reconfigure(const Settings& global_settings, int argc, char* argv[])
{
+ Settings settings{global_settings};
+
bool no_rerun{false};
std::vector<std::string> args;