Skip to content

Commit

Permalink
Allow Bzlmod with shell tests (#2304)
Browse files Browse the repository at this point in the history
Signed-off-by: Brentley Jones <[email protected]>
  • Loading branch information
brentleyjones authored Oct 18, 2023
1 parent 73c1c47 commit 07a1546
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 6 deletions.
2 changes: 0 additions & 2 deletions test/apple_shell_testutils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -464,8 +464,6 @@ function do_action() {

local -a bazel_options=(
"--announce_rc"
# TODO: Remove once our tests work with Bzlmod
"--noenable_bzlmod"
"--symlink_prefix=test-"
"--verbose_failures"
# Used so that if there's a single configuration transition, its output
Expand Down
37 changes: 34 additions & 3 deletions test/bazel_testrunner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,37 @@ function create_new_workspace() {
# copy and we should reference it from the original location.
cp -rf "$EXTERNAL_DIR" ../external

apple_support_path=$(resolve_external_repository build_bazel_apple_support)
rules_apple_path=$(resolve_external_repository build_bazel_rules_apple)
rules_swift_path=$(resolve_external_repository build_bazel_rules_swift)

touch MODULE.bazel
cat > MODULE.bazel <<EOF
module(name = "build_bazel_rules_apple_integration_tests", version = "0")
bazel_dep(name = "apple_support", version = "0", repo_name = "build_bazel_apple_support")
bazel_dep(name = "rules_swift", version = "0", repo_name = "build_bazel_rules_swift")
bazel_dep(name = "rules_apple", version = "0", repo_name = "build_bazel_rules_apple")
xcode_configure = use_extension("@bazel_tools//tools/osx:xcode_configure.bzl", "xcode_configure_extension")
use_repo(xcode_configure, "local_config_xcode")
local_path_override(
module_name = "apple_support",
path = "$apple_support_path",
)
local_path_override(
module_name = "rules_swift",
path = "$rules_swift_path",
)
local_path_override(
module_name = "rules_apple",
path = "$rules_apple_path",
)
EOF

touch WORKSPACE.bzlmod

touch WORKSPACE
cat > WORKSPACE <<EOF
workspace(name = 'build_bazel_rules_apple_integration_tests')
Expand All @@ -91,17 +122,17 @@ new_local_repository(
local_repository(
name = 'build_bazel_rules_apple',
path = '$(resolve_external_repository build_bazel_rules_apple)',
path = '$rules_apple_path',
)
local_repository(
name = 'build_bazel_rules_swift',
path = '$(resolve_external_repository build_bazel_rules_swift)',
path = '$rules_swift_path',
)
local_repository(
name = 'build_bazel_apple_support',
path = '$(resolve_external_repository build_bazel_apple_support)',
path = '$apple_support_path',
)
local_repository(
Expand Down
9 changes: 8 additions & 1 deletion test/ios_coverage_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,16 @@ function test_hosted_unit_test_coverage() {
# Validate coverage for the hosting binary is included
assert_contains "FN:3,foo" "test-testlogs/app/hosted_test/coverage.dat"

if [ -d "test-bin/app/hosted_test.runfiles/_main" ]; then
# Bzlmod always uses '_main' for current repository
path="test-bin/app/hosted_test.runfiles/_main/app/hosted_test.zip"
else
path="test-bin/app/hosted_test.runfiles/build_bazel_rules_apple_integration_tests/app/hosted_test.zip"
fi

# Validate that the symbol called from the hosted binary exists and is undefined
unzip_single_file \
"test-bin/app/hosted_test.runfiles/build_bazel_rules_apple_integration_tests/app/hosted_test.zip" \
"$path" \
"hosted_test.xctest/hosted_test" \
nm -u - | grep foo || fail "Undefined 'foo' symbol not found"
}
Expand Down

0 comments on commit 07a1546

Please sign in to comment.