blob: d94152930c80970c1afdf3b7cbf20662ec6bbd45 [file] [log] [blame]
MarkDacekb98b3a42023-07-24 19:49:28 +00001#!/bin/bash -eu
2
3###############
4# Removes the Bazel output base and ninja file.
5# This is intended to solve an issue when a build top is moved.
6# Starlark symlinks are absolute and a moved build top will have many
7# dangling symlinks and fail to function as intended.
8# If the bazel output base is removed WITHOUT the top moving,
9# then any subsequent builds will fail as soong_build will not rerun.
10# Removing the ninja file will force a re-execution.
11#
12# You MUST lunch again after moving your build top, before running this.
13###############
14
15if [[ ! -v ANDROID_BUILD_TOP ]]; then
16 echo "ANDROID_BUILD_TOP not found in environment. Please run lunch before running this script"
17 exit 1
18fi
19
20if [[ ! -v OUT_DIR ]]; then
21 out_dir="$ANDROID_BUILD_TOP/out"
22else
23 out_dir="$ANDROID_BUILD_TOP/$OUT_DIR"
24fi
25
26output_base=$out_dir/bazel/output/
27ninja_file=$out_dir/soong/build*ninja
28
29if [[ ! -d $output_base ]]; then
30 echo "The specified output directory doesn't exist."
31 echo "Have you rerun lunch since moving directories?"
32 exit 1
33fi
34
35read -p "Are you sure you want to remove $output_base and the ninja file $ninja_file? Y/N " -n 1 -r
36echo
37if [[ $REPLY =~ ^[Yy]$ ]]
38then
39 rm -rf $output_base
40 rm $ninja_file
41fi