MarkDacek | b98b3a4 | 2023-07-24 19:49:28 +0000 | [diff] [blame^] | 1 | #!/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 | |
| 15 | if [[ ! -v ANDROID_BUILD_TOP ]]; then |
| 16 | echo "ANDROID_BUILD_TOP not found in environment. Please run lunch before running this script" |
| 17 | exit 1 |
| 18 | fi |
| 19 | |
| 20 | if [[ ! -v OUT_DIR ]]; then |
| 21 | out_dir="$ANDROID_BUILD_TOP/out" |
| 22 | else |
| 23 | out_dir="$ANDROID_BUILD_TOP/$OUT_DIR" |
| 24 | fi |
| 25 | |
| 26 | output_base=$out_dir/bazel/output/ |
| 27 | ninja_file=$out_dir/soong/build*ninja |
| 28 | |
| 29 | if [[ ! -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 |
| 33 | fi |
| 34 | |
| 35 | read -p "Are you sure you want to remove $output_base and the ninja file $ninja_file? Y/N " -n 1 -r |
| 36 | echo |
| 37 | if [[ $REPLY =~ ^[Yy]$ ]] |
| 38 | then |
| 39 | rm -rf $output_base |
| 40 | rm $ninja_file |
| 41 | fi |