|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -eEuo pipefail |
| 3 | + |
| 4 | +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 5 | +TESTS_DIR="$(cd "${SCRIPT_DIR}/.." && pwd)" |
| 6 | +BOB_ROOT="$(cd "${TESTS_DIR}/.." && pwd)" |
| 7 | +BUILD_DIR="${1:-build-bazel-import}" |
| 8 | +BOB_BUILD_DIR="${BOB_ROOT}/${BUILD_DIR}" |
| 9 | +BAZEL_OUTPUT_USER_ROOT="${BOB_BUILD_DIR}.bazel_output_user_root" |
| 10 | +GENERATED_BPLIST="${BOB_BUILD_DIR}.bplist" |
| 11 | +BAZEL_STARTUP_ARGS=(--output_user_root="${BAZEL_OUTPUT_USER_ROOT}") |
| 12 | + |
| 13 | +cleanup() { |
| 14 | + if [[ -n "${BAZEL:-}" ]]; then |
| 15 | + "${BAZEL}" "${BAZEL_STARTUP_ARGS[@]}" shutdown >/dev/null 2>&1 || true |
| 16 | + fi |
| 17 | + rm -rf "${BOB_BUILD_DIR}" "${BAZEL_OUTPUT_USER_ROOT}" "${GENERATED_BPLIST}" |
| 18 | +} |
| 19 | + |
| 20 | +trap cleanup EXIT |
| 21 | +trap 'echo "<------------- $(basename "${0}") failed"' ERR |
| 22 | + |
| 23 | +require_file() { |
| 24 | + if [[ ! -f "$1" ]]; then |
| 25 | + echo "Expected file does not exist: $1" >&2 |
| 26 | + exit 1 |
| 27 | + fi |
| 28 | +} |
| 29 | + |
| 30 | +require_symlink() { |
| 31 | + if [[ ! -L "$1" ]]; then |
| 32 | + echo "Expected symlink does not exist: $1" >&2 |
| 33 | + exit 1 |
| 34 | + fi |
| 35 | +} |
| 36 | + |
| 37 | +if command -v bazelisk >/dev/null 2>&1; then |
| 38 | + BAZEL=bazelisk |
| 39 | +elif command -v bazel >/dev/null 2>&1; then |
| 40 | + BAZEL=bazel |
| 41 | +else |
| 42 | + echo "Skipping bazel_import test: neither bazelisk nor bazel is available" |
| 43 | + exit 0 |
| 44 | +fi |
| 45 | + |
| 46 | +pushd "${BOB_ROOT}" >/dev/null |
| 47 | + |
| 48 | +"${BAZEL}" "${BAZEL_STARTUP_ARGS[@]}" clean |
| 49 | + |
| 50 | +"${BAZEL}" "${BAZEL_STARTUP_ARGS[@]}" build \ |
| 51 | + --aspects=//tests/bazel_cc_import/bazel:bob_import_cc_aspect.bzl%bob_import_cc_aspect \ |
| 52 | + --output_groups=bob_import_cc_bp \ |
| 53 | + //tests/bazel_cc_import/bazel/header_only/... \ |
| 54 | + |
| 55 | +EXPECTED_BUILD_BPS=( |
| 56 | + bazel-bin/tests/bazel_cc_import/bazel/header_only/includes/tests_bazel_cc_import_bazel_header_only_includes_includes/build.bp |
| 57 | + bazel-bin/tests/bazel_cc_import/bazel/header_only/normal/tests_bazel_cc_import_bazel_header_only_normal_normal/build.bp |
| 58 | + bazel-bin/tests/bazel_cc_import/bazel/header_only/strip_prefix/tests_bazel_cc_import_bazel_header_only_strip_prefix_strip_prefix/build.bp |
| 59 | +) |
| 60 | + |
| 61 | +EXPECTED_HEADER_LINKS=( |
| 62 | + bazel-bin/tests/bazel_cc_import/bazel/header_only/includes/tests_bazel_cc_import_bazel_header_only_includes_includes/include/api.h |
| 63 | + bazel-bin/tests/bazel_cc_import/bazel/header_only/normal/tests_bazel_cc_import_bazel_header_only_normal_normal/include/tests/bazel_cc_import/bazel/header_only/normal/api.h |
| 64 | + bazel-bin/tests/bazel_cc_import/bazel/header_only/strip_prefix/tests_bazel_cc_import_bazel_header_only_strip_prefix_strip_prefix/include/nested/api.h |
| 65 | +) |
| 66 | + |
| 67 | + |
| 68 | +for path in "${EXPECTED_BUILD_BPS[@]}"; do |
| 69 | + require_file "${path}" |
| 70 | +done |
| 71 | + |
| 72 | +for path in "${EXPECTED_HEADER_LINKS[@]}"; do |
| 73 | + require_symlink "${path}" |
| 74 | +done |
| 75 | + |
| 76 | +{ |
| 77 | + printf './bazel_cc_import/build.bp\n' |
| 78 | + printf '%s\n' "${EXPECTED_BUILD_BPS[@]}" | sort | sed 's#^#../#' |
| 79 | + printf './bob/Blueprints\n' |
| 80 | + printf './bob/blueprint/Blueprints\n' |
| 81 | +} > "${GENERATED_BPLIST}" |
| 82 | + |
| 83 | +source "${TESTS_DIR}/bootstrap_utils.sh" |
| 84 | +create_link .. "${TESTS_DIR}/bob" |
| 85 | + |
| 86 | +rm -rf "${BOB_BUILD_DIR}" |
| 87 | +export CONFIGNAME="bob.config" |
| 88 | +export SRCDIR="${TESTS_DIR}" |
| 89 | +export BUILDDIR="${BOB_BUILD_DIR}" |
| 90 | +export BLUEPRINT_LIST_FILE="${GENERATED_BPLIST}" |
| 91 | +export BOB_LOG_WARNINGS_FILE="${BOB_BUILD_DIR}/.bob.warnings.csv" |
| 92 | +export BOB_META_FILE="${BOB_BUILD_DIR}/.bob.meta.json" |
| 93 | +export BOB_LOG_WARNINGS="" |
| 94 | +export BOB_CONFIG_PLUGINS="${TESTS_DIR}/plugins/test_plugin" |
| 95 | + |
| 96 | +"${BOB_ROOT}/bootstrap_linux.bash" |
| 97 | +ln -sf "bob" "${BOB_BUILD_DIR}/buildme" |
| 98 | +"${BOB_BUILD_DIR}/config" |
| 99 | +"${BOB_BUILD_DIR}/buildme" bob_test_bazel_import |
| 100 | + |
| 101 | +TEST_EXECUTABLES=( |
| 102 | + bob_test_bazel_cc_import_header_only_normal |
| 103 | + bob_test_bazel_cc_import_header_only_includes |
| 104 | + bob_test_bazel_cc_import_header_only_strip_prefix |
| 105 | +) |
| 106 | + |
| 107 | +for executable in "${TEST_EXECUTABLES[@]}"; do |
| 108 | + env "${BOB_BUILD_DIR}/target/executable/${executable}" |
| 109 | +done |
| 110 | + |
| 111 | +popd >/dev/null |
0 commit comments