summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xupgrade79
1 files changed, 55 insertions, 24 deletions
diff --git a/upgrade b/upgrade
index ef5fc7e..8cd4224 100755
--- a/upgrade
+++ b/upgrade
@@ -9,11 +9,11 @@
#
# Note that we can't just do that because as soon as we drop some dependency
# package, the tools (b, bpkg, etc) become non-runnable (missing shared
-# libraries, etc).
+# libraries, etc). The script expects the current build of the toolchain
+# to be runnable.
#
-# Finally, this script only upgrades the default configurations (including
-# -libs, if present). To upgrade the rest you can use the normal way, for
-# example:
+# This script only upgrades the default configurations (including -libs, if
+# present). To upgrade the rest you can use the normal way, for example:
#
# bdep sync -fur @<cfg>|-a
#
@@ -21,7 +21,7 @@
# but only the build system is updated. This can be done at a later stage by
# running the build system in the configuration directory:
#
-# BDEP_SYNC=0 b
+# BDEP_SYNC=0 b builds/gcc7/
#
owd="$(pwd)"
trap "{ cd '$owd'; exit 1; }" ERR
@@ -88,9 +88,9 @@ fi
# 0. First, make backup copies of configurations. If something goes wrong,
# it's likely the tools will be left in a non-runnable state.
#
-# 1. Next, install the build tollchain on the side and then upgrade the
-# configurations using that.
-#
+# 1. Next, setup the environment (PATH, LD_LIBRARY_PATH) so that we use the
+# toolchain from the backup copy. Then upgrade the configurations using
+# that.
# Step 0.
#
@@ -112,29 +112,56 @@ fi
# Step 1.
#
-
-# @@ TMP: I don't see why we would need this.
+# The main problem with running the toolchain from the backup location is the
+# rpaths embedded into the executables. We can make sure the libraries are
+# found in the backup location with LD_LIBRARY_PATH (or equivalent). But for
+# good measure let's also remove all the libraries from the original location
+# to make they don't interfere.
#
-#run_no_sync b "$tcfg"/libbutl/libbutl/hxx{version}
-#run_no_sync b "$tcfg"/libbpkg/libbpkg/hxx{version}
-#run_no_sync b "$tcfg"/build2/libbuild2/hxx{version}
+if [[ "$OSTYPE" == "darwin"* ]]; then
+ so=dylib
+else
+ so=so
+fi
+
+libs=()
+for f in $(find "$tcfg" -name "*.$so" -a '(' -type f -o -type l ')'); do
+ libs+=("$f")
+done
+
+run rm -rf "${libs[@]}"
-run rm -rf /tmp/build2-install
+declare -A lib_dirs
+for f in $(find "$tcfg.bak" -name "*.$so" -a '(' -type f -o -type l ')'); do
+ lib_dirs["$(dirname "$f")"]=
+done
-run_no_sync bpkg install -d "$tcfg" \
- config.install.root=/tmp/build2-install \
- config.bin.rpath=/tmp/build2-install/lib \
- build2 bpkg bdep
+# Note that the order should not matter.
+#
+ldpath=
+for d in "${!lib_dirs[@]}"; do
+ ldpath="$d:$ldpath"
+done
+if [[ "$OSTYPE" == "darwin"* ]]; then
+ oldpath="$DYLD_LIBRARY_PATH"
+ run export DYLD_LIBRARY_PATH="$ldpath$DYLD_LIBRARY_PATH"
+else
+ oldpath="$LD_LIBRARY_PATH"
+ run export LD_LIBRARY_PATH="$ldpath$LD_LIBRARY_PATH"
+fi
opath="$PATH"
-run export PATH="/tmp/build2-install/bin:$PATH"
+run export PATH="$tcfg.bak/build2/build2:$tcfg.bak/bpkg/bpkg:$tcfg.bak/bdep/bdep:$PATH"
+# Make sure the backup toolchain is runnable.
+#
run which b bpkg bdep
-
run b --version >/dev/null
run bpkg --version >/dev/null
run bdep --version >/dev/null
+# Upgrade.
+#
run bpkg fetch -d "$tcfg"
run_no_sync bpkg build -d "$tcfg" --keep-out -ur $configure_only
@@ -149,19 +176,23 @@ if [ -n "$lcfg" ]; then
run_no_sync bpkg build -d "$lcfg" --keep-out -ur $configure_only
fi
+# Restore the original environment.
+#
+if [[ "$OSTYPE" == "darwin"* ]]; then
+ run export DYLD_LIBRARY_PATH="$oldpath"
+else
+ run export LD_LIBRARY_PATH="$oldpath"
+fi
run export PATH="$opath"
run b --version >/dev/null
-run b build2/ # Should be a noop.
if [ -z "$configure_only" ]; then
run bpkg --version >/dev/null
run bdep --version >/dev/null
- run b bpkg/ bdep/ # Should be a noop.
+ run b build2/ bpkg/ bdep/ # Should be a noop.
fi
-run rm -rf /tmp/build2-install
-
run rm -rf "$tcfg.bak"
if [ -n "$lcfg" ]; then