Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force bzlmod in shell tests #2382

Merged
merged 3 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,9 @@ filegroup(
"WORKSPACE",
"//apple:for_bazel_tests",
"//tools:for_bazel_tests",
"@build_bazel_apple_support//:for_bazel_tests",
"@build_bazel_rules_swift//:for_bazel_tests",
"@xctestrunner//:for_bazel_tests",
],
visibility = [
"//:__subpackages__",
"//test:__subpackages__",
],
)

Expand Down
16 changes: 0 additions & 16 deletions test/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,6 @@ filegroup(
visibility = ["//visibility:public"],
)

# Gather external dependencies into a target that can be injected into the
# integration tests. The test script will then mock out the files required
# to make these proper WORKSPACES that can be used in tests.
# This enables us to:
# 1. Reuse the download of the external dependencies across all tests.
# 2. Remove the need to update dependency versions in the repo's
# WORKSPACE and the test WORKSPACE.
filegroup(
name = "external_deps",
testonly = 1,
srcs = [
"@bazel_skylib//:test_deps",
"@xctestrunner//:ios_test_runner",
],
)

# ----------------------------------------------------------------------------

# Ballpark number for shared_count:
Expand Down
1 change: 1 addition & 0 deletions test/apple_shell_testutils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,7 @@ function do_action() {
"--apple_crosstool_top=@local_config_apple_cc//:toolchain"
"--crosstool_top=@local_config_apple_cc//:toolchain"
"--host_crosstool_top=@local_config_apple_cc//:toolchain"
"--enable_bzlmod"
)

if [[ -n "${XCODE_VERSION_FOR_TESTS-}" ]]; then
Expand Down
87 changes: 6 additions & 81 deletions test/bazel_testrunner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,105 +69,30 @@ function create_new_workspace() {
mkdir -p "${new_workspace_dir}"
cd "${new_workspace_dir}"

# Make a modifiable copy of external, so that we can mock out missing
# test resources. This should only be needed for mocking the xctestrunner
# BUILD file below; if we can workaround this, we don't need to make this
# 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")
# Specify oldest possible bzlmod versions and let rules_apple versions take precedence
bazel_dep(name = "apple_support", version = "0.11.0", repo_name = "build_bazel_apple_support")
bazel_dep(name = "rules_swift", version = "1.2.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",
)
apple_cc_configure = use_extension("@build_bazel_apple_support//crosstool:setup.bzl", "apple_cc_configure_extension")
use_repo(apple_cc_configure, "local_config_apple_cc")

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')

# We can't use local_repository as the dependencies won't
# copy some of the build files or WORKSPACE. new_local_repository
# will create a new WORKSPACE file and we just need to pass the
# contents for a top level BUILD file, which can be empty.
new_local_repository(
name = "bazel_skylib",
build_file_content = '',
path = '$PWD/../external/bazel_skylib',
)

local_repository(
name = 'build_bazel_rules_apple',
path = '$rules_apple_path',
)

local_repository(
name = 'build_bazel_rules_swift',
path = '$rules_swift_path',
)

local_repository(
name = 'build_bazel_apple_support',
path = '$apple_support_path',
)

local_repository(
name = 'xctestrunner',
path = '$(resolve_external_repository xctestrunner)',
)

# We load rules_swift dependencies into the WORKSPACE. This is safe to do
# _for now_ because Swift currently depends on:
#
# * skylib - which is already loaded, so it won't be loaded again.
# * swift_protobuf - which is not used in the integration tests, so it won't be
# loaded.
# * protobuf - which also is not used in the integration tests.
# * swift_toolchain - which is generated locally, so nothing to download.
#
# If these assumptions change over time, we'll need to reassess this way of
# loading rules_swift dependencies.

load(
"@build_bazel_rules_swift//swift:repositories.bzl",
"swift_rules_dependencies",
)

swift_rules_dependencies()

load(
"@build_bazel_apple_support//lib:repositories.bzl",
"apple_support_dependencies",
)

apple_support_dependencies()
EOF

cp "$(rlocation build_bazel_rules_apple/platform_mappings)" platform_mappings
}

# Set-up a clean default workspace.
Expand Down
3 changes: 0 additions & 3 deletions test/test_rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,10 @@ def apple_shell_test(
src,
"//:for_bazel_tests",
"//:platform_mappings",
"//test:external_deps",
"//test:apple_shell_testutils.sh",
"//test/testdata/provisioning:integration_testing_profiles",
"//test:unittest.bash",
"@build_bazel_apple_support//:BUILD",
"@build_bazel_rules_apple//:BUILD",
"@build_bazel_rules_swift//:BUILD",
] + (data or []),
deps = [
"@bazel_tools//tools/bash/runfiles",
Expand Down