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