#!/bin/bash # # Copyright 2023 The Bazel Authors. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # --- begin runfiles.bash initialization v2 --- # Copy-pasted from the Bazel Bash runfiles library v2. set -uo pipefail; f=bazel_tools/tools/bash/runfiles/runfiles.bash source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \ source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \ source "$0.runfiles/$f" 2>/dev/null || \ source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ { echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e # --- end runfiles.bash initialization v2 --- source "$(rlocation rules_android/test/bashunit/unittest.bash)" || \ (echo >&2 "Failed to locate bashunit.sh" && exit 1) function set_up() { # Clean out the repository. rm -rf * touch WORKSPACE # Clean out the test android SDK if any rm -rf "${TEST_TMPDIR}/android_sdk" # Make sure the rules exist and seed the WORKSPACE. rm -rf "${TEST_TMPDIR}/android_sdk_repository_src" set_up_rules } function set_up_rules() { local android_revision_rule="$(rlocation rules_android/rules/android_revision.bzl)" local repo_rule="$(rlocation rules_android/rules/android_sdk_repository/rule.bzl)" local repo_rule_dir="$(dirname "${repo_rule}")" local dest_dir="${TEST_TMPDIR}/android_sdk_repository_src" mkdir -p "${dest_dir}/rules/android_sdk_repository" cp -r "${repo_rule_dir}"/* "${dest_dir}/rules/android_sdk_repository" cat > "${dest_dir}/WORKSPACE" < "${dest_dir}/rules/BUILD" < "${dest_dir}/rules/android_sdk_repository/BUILD" <> WORKSPACE < verify/BUILD < \$@", "//conditions:default": "echo sdk missing > \$@", }), ) EOF "${BIT_BAZEL_BINARY}" build //verify:check_sdk >& $TEST_log || fail "Expected success" cat bazel-bin/verify/check_sdk.log >$TEST_log } function verify_no_android_sdk() { create_verify expect_log "sdk missing" } function verify_android_sdk() { create_verify expect_log "sdk present" "${BIT_BAZEL_BINARY}" query @androidsdk//:files >& $TEST_log || fail "Expected to exist" } function write_platforms() { mkdir -p platforms cat > platforms/BUILD < sdk_check/check.bzl < sdk_check/check.bzl < sdk_check/BUILD <& $TEST_log || fail "Expected success" expect_log "SDK check results" }