From c3c068b65e2c958fa640409628d0b43f77421ab3 Mon Sep 17 00:00:00 2001 From: Malte Poll Date: Wed, 12 Apr 2023 17:29:55 +0200 Subject: [PATCH] bazel: allow running devbuild in containers with other filesystem layout --- .../prepare_developer_workspace.sh.in | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/bazel/devbuild/prepare_developer_workspace.sh.in b/bazel/devbuild/prepare_developer_workspace.sh.in index a41b2ffbd..186ac33b6 100755 --- a/bazel/devbuild/prepare_developer_workspace.sh.in +++ b/bazel/devbuild/prepare_developer_workspace.sh.in @@ -27,13 +27,29 @@ cd "${BUILD_WORKING_DIRECTORY}" ###### script body ###### +replace_prefix() { + local host_cache=$1 + local builder_cache=$2 + local dir=$3 + if [[ ${dir#"${builder_cache}"} == "${dir}" ]]; then + echo "${dir}" + return + fi + relpath=${dir#"${builder_cache}"} + realpath -m "${host_cache}/${relpath}" +} + +# Set HOST_CACHE when running in a container with mounted cache. +host_cache="${HOST_CACHE:-${HOME}/.cache}" +builder_cache="${HOME}/.cache" + if [[ $# -eq 0 ]]; then workdir="." else workdir="$1" fi -ln -sf "${bootstrapper}" "${workdir}/bootstrapper" -ln -sf "${upgrade_agent}" "${workdir}/upgrade-agent" -ln -sf "${cli}" "${workdir}/constellation" -ln -sf "${cdbg}" "${workdir}/cdbg" +ln -sf "$(replace_prefix "${host_cache}" "${builder_cache}" "${bootstrapper}")" "${workdir}/bootstrapper" +ln -sf "$(replace_prefix "${host_cache}" "${builder_cache}" "${upgrade_agent}")" "${workdir}/upgrade-agent" +ln -sf "$(replace_prefix "${host_cache}" "${builder_cache}" "${cli}")" "${workdir}/constellation" +ln -sf "$(replace_prefix "${host_cache}" "${builder_cache}" "${cdbg}")" "${workdir}/cdbg"