#!/bin/sh

#
# Copyright 2019-2021 Signal Messenger, LLC
# SPDX-License-Identifier: AGPL-3.0-only
#

set -e

# shellcheck source=bin/env.sh
. "$(dirname "$0")"/env.sh

MANIFEST="${RINGRTC_SRC_DIR}/rust/Cargo.toml"

OUTPUT_DIR="${OUTPUT_DIR}/rust-lint"

# Remove some of the build products, so that the lint is generated
# every time.
rm -rf "${OUTPUT_DIR}"/*/*/*/*ringrtc* "${OUTPUT_DIR}"/*/*/.fingerprint/*ringrtc*

case $WEBRTC_PLATFORM in
    android)
        TARGET=aarch64-linux-android
        ;;
    ios)
        TARGET=aarch64-apple-ios
        ;;
    *)
        echo "ERROR: Unknown platform: $WEBRTC_PLATFORM"
        exit 1
esac

echo "Entering directory \`$(dirname "$MANIFEST")'"

cargo clippy \
    --target $TARGET \
    --target-dir "$OUTPUT_DIR" \
    --manifest-path "$MANIFEST" \
    -- -D warnings
