#!/usr/bin/env bash

set -o errexit -o nounset -o pipefail

# Set the environment variables for the repo rules, tested in `Package.swift`.
export INTERESTING_DEPS_INHERIT_ENV=1

# Use the Bazel binary specified by the integration test. Otherwise, fall back
# to bazel.
bazel="${BIT_BAZEL_BINARY:-bazel}"

# Generate Swift external deps and update build files
"${bazel}" run //:tidy

# Test resolving the package via the `swift_package` repo.
"${bazel}" run @swift_package//:resolve

# Ensure that it builds in both sandbox and local strategies.
# This tests issues with modulemap include/generation.
"${bazel}" test //... --spawn_strategy=sandboxed,local
"${bazel}" test //... --spawn_strategy=local
