#! /usr/bin/env bash # Upgrade remote packages in a bdep-managed build2 toolchain build (default # configurations), essentially as if by executing: # # bdep sync -fur && b # # In each project of the toolchain. # # 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). # # Finally, 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 @|-a # # If the -c option is specified, the configuration is upgraded and configured # 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 # owd="$(pwd)" trap "{ cd '$owd'; exit 1; }" ERR set -o errtrace # Trap in functions. function info () { echo "$*" 1>&2; } function error () { info "$*"; exit 1; } # Run a command with tracing (similar to set -x). # # Note that this function will execute a command with arguments that contain # spaces but it will not print them as quoted (and neither does set -x). # function run () { echo "+ $@" 1>&2 "$@" } function run_no_sync () { echo "+ BDEP_SYNC=0 $@" 1>&2 BDEP_SYNC=0 "$@" } # Make sure the build2 tools are runnable. # b --version >/dev/null bpkg --version >/dev/null bdep --version >/dev/null configure_only= while [ $# -gt 0 ]; do case $1 in -c) configure_only=--configure-only shift ;; *) error "unexpected $1" ;; esac done # Get the configuration directories. # tcfg="$(b info: build2/ | sed -n -re 's/^out_root: (.+)$/\1/p')" lcfg="$(b info: libbutl/ | sed -n -re 's/^out_root: (.+)$/\1/p')" if [ -z "$tcfg" -o -z "$lcfg" ]; then error "unable to determine build configuration directories" fi tcfg="$(dirname "$tcfg")" lcfg="$(dirname "$lcfg")" if [ "$tcfg" = "$lcfg" ]; then lcfg= fi # The plan is as follows: # # 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. # # Step 0. # if test -e "$tcfg.bak"; then error "$tcfg.bak already exist" fi if [ -n "$lcfg" ]; then if test -e "$lcfg.bak"; then error "$lcfg.bak already exist" fi fi run cp -rp "$tcfg" "$tcfg.bak" if [ -n "$lcfg" ]; then run cp -rp "$lcfg" "$lcfg.bak" fi # Step 1. # # @@ TMP: I don't see why we would need this. # #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} run rm -rf /tmp/build2-install run_no_sync bpkg install -d "$tcfg" \ config.install.root=/tmp/build2-install \ config.bin.rpath=/tmp/build2-install/lib \ build2 bpkg bdep opath="$PATH" run export PATH="/tmp/build2-install/bin:$PATH" run which b bpkg bdep run b --version >/dev/null run bpkg --version >/dev/null run bdep --version >/dev/null run bpkg fetch -d "$tcfg" run_no_sync bpkg build -d "$tcfg" --keep-out -ur $configure_only # In configure-only we update the build system manually. # if [ -n "$configure_only" ]; then run_no_sync b build2/ fi if [ -n "$lcfg" ]; then run bpkg fetch -d "$lcfg" run_no_sync bpkg build -d "$lcfg" --keep-out -ur $configure_only 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. fi run rm -rf /tmp/build2-install run rm -rf "$tcfg.bak" if [ -n "$lcfg" ]; then run rm -rf "$lcfg.bak" fi