Update symlinks in output directory when TOP dir changes

When TOP dir changes and we reuse the same output between the old and new checkouts, we need to rewrite all the symlinks used by Bazel and other tools in the out-directory to point to the new top directory. Otherwise, if the old source dir is deleted, the build will fail.

I used the OUT_DIR/soong/soong.environment.available file to find out the previous PWD.

Tested:
1. Create source dir 1, run build, create source dir 2, remote source dir 1, reuse out dir and rerun build => build succeeded with this change.
2. m libc after moving build TOP. Only the analysis phase was rerun, the actual build was not rerun.

Bug: b/300498226

Change-Id: I196625baa1f4efe7a4734accfa1f0be7c98a7920
This commit is contained in:
Kousik Kumar
2023-10-04 04:14:28 +00:00
parent 72928074f5
commit ca390b2f00
4 changed files with 183 additions and 1 deletions

View File

@@ -8,6 +8,11 @@ HARDWIRED_MOCK_TOP=
REAL_TOP="$(readlink -f "$(dirname "$0")"/../../..)"
function make_mock_top {
mock=$(mktemp -t -d st.XXXXX)
echo "$mock"
}
if [[ -n "$HARDWIRED_MOCK_TOP" ]]; then
MOCK_TOP="$HARDWIRED_MOCK_TOP"
else
@@ -197,3 +202,11 @@ function scan_and_run_tests {
info "Completed test case \e[96;1m$f\e[0m"
done
}
function move_mock_top {
MOCK_TOP2=$(make_mock_top)
rm -rf $MOCK_TOP2
mv $MOCK_TOP $MOCK_TOP2
MOCK_TOP=$MOCK_TOP2
trap cleanup_mock_top EXIT
}