xref: /aosp_15_r20/prebuilts/rust/tests/rust-analyzer-integration-test.sh (revision b40554a23088fb75aa6945dfe8e65169c8484da3)
1#!/bin/bash
2# rust-analyzer integration test.
3# Ensure that the prebuilt version of rust-analyzer is able to parse our
4# automatically generated rust-project.json. This script must be run in a valid
5# repository tree.
6#
7# The following environment variables affect the result:
8#   DIST_DIR  where the output of `rust-analyzer analysis-stats` will be stored.
9
10set -e
11
12readonly UNAME="$(uname)"
13case "$UNAME" in
14Linux)
15    readonly OS='linux'
16    ;;
17Darwin)
18    readonly OS='darwin'
19    ;;
20*)
21    echo "Unsupported OS '$UNAME'"
22    exit 1
23    ;;
24esac
25
26readonly ANDROID_TOP="$(cd $(dirname $0)/../../..; pwd)"
27cd "$ANDROID_TOP"
28
29export OUT_DIR="${OUT_DIR:-out}"
30readonly SOONG_OUT="${OUT_DIR}/soong"
31readonly RUST_PROJECT_PATH="${SOONG_OUT}/rust-project.json"
32
33# http://b/222532724
34# https://github.com/rust-analyzer/rust-analyzer/issues/11614
35# Set CHALK_OVERFLOW_DEPTH to work around current limits (300 isn't sufficient).
36export CHALK_OVERFLOW_DEPTH="${CHALK_OVERFLOW_DEPTH:-400}"
37
38# Generate rust-project.json.
39build/soong/soong_ui.bash --make-mode SOONG_GEN_RUST_PROJECT=1 nothing
40
41# Symlink it from ANDROID_TOP.
42[ -f "${RUST_PROJECT_PATH}" ]
43ln -s "${RUST_PROJECT_PATH}" .
44trap "rm \"${ANDROID_TOP}\"/rust-project.json" EXIT
45
46# Run rust-analyzer analysis-stats. It will return 0 if rust-project.json can be found and parsed.
47prebuilts/rust/${OS}-x86/stable/rust-analyzer analysis-stats . 2>"${DIST_DIR}"/rust-analyzer-stats.log
48retval=$?
49if [[ "$retval" -ne 0 ]]; then
50  echo "Error returned by 'rust-analyzer analysis-stats .'"
51  echo "Check rust-analyzer-stats.log for more details."
52  exit "$retval"
53fi
54