#!/bin/bash
#
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
#

set -eux

# Docs, clippy, etc on the smoketest itself
pushd aws-sdk-smoketest &>/dev/null

# Override "fail on warning" for smoke test docs since DynamoDB's modeled docs cause rustdoc warnings
RUSTDOCFLAGS="--cfg docsrs" cargo +"${RUST_NIGHTLY_VERSION}" doc --no-deps --document-private-items --all-features

cargo clippy --all-features
# running `cargo hack` runs this in the prod workspace and ensures that each crate is run individually
cargo +"${RUST_NIGHTLY_VERSION}" hack udeps --all-features
popd &>/dev/null

# Move the smoketest artifacts into smithy-rs and check the integration tests
# (which use path dependencies into the generated artifacts) against them.
mkdir -p smithy-rs/aws/sdk/build
mv aws-sdk-smoketest smithy-rs/aws/sdk/build/aws-sdk
pushd smithy-rs/aws/sdk/integration-tests
cargo check
popd &>/dev/null

pushd smithy-rs/aws/sdk/build/aws-sdk/sdk &>/dev/null
for crate_path in $(ls | grep -v "aws-"); do
    if [[ -d "${crate_path}" ]]; then
        pushd "${crate_path}" &>/dev/null
        # Override "fail on warning" for smoke test docs since DynamoDB's modeled docs cause rustdoc warnings,
        # and `cargo-check-external-types` relies on rustdoc JSON output.
        RUSTDOCFLAGS="" cargo +"${RUST_NIGHTLY_VERSION}" check-external-types --all-features --config ../../../../sdk-external-types.toml
        popd &>/dev/null
    fi
done
popd &>/dev/null
