Skip to content

Commit

Permalink
Make rules_testing available for Bazel tests
Browse files Browse the repository at this point in the history
Includes an update of bazel_skylib to 1.3.0 as the (very old) version 1.0.3 wasn't compatible with rules_testing.

Work towards bazelbuild#1920

Closes bazelbuild#18182.

PiperOrigin-RevId: 527021012
Change-Id: I80ebff1a1aa656974ad6a1bb1809d8f919a2fa22
  • Loading branch information
fmeum authored and fweikert committed May 25, 2023
1 parent a85b30c commit 716541c
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 16 deletions.
1 change: 1 addition & 0 deletions MODULE.bazel
Expand Up @@ -20,6 +20,7 @@ bazel_dep(name = "rules_java", version = "5.5.0")
bazel_dep(name = "rules_proto", version = "5.3.0-21.7")
bazel_dep(name = "rules_jvm_external", version = "4.5")
bazel_dep(name = "rules_python", version = "0.19.0")
bazel_dep(name = "rules_testing", version = "0.0.4")

single_version_override(
module_name = "rules_jvm_external",
Expand Down
16 changes: 16 additions & 0 deletions WORKSPACE
Expand Up @@ -23,6 +23,12 @@ EXPORT_WORKSPACE_IN_BUILD_BAZEL_FILE = [
"echo 'exports_files([\"WORKSPACE\"], visibility = [\"//visibility:public\"])' >> BUILD.bazel",
]

EXPORT_WORKSPACE_BAZEL_IN_BUILD_FILE = [
"test -f BUILD && chmod u+w BUILD || true",
"echo >> BUILD",
"echo 'exports_files([\"WORKSPACE.bazel\"], visibility = [\"//visibility:public\"])' >> BUILD",
]

EXPORT_WORKSPACE_IN_BUILD_FILE_WIN = [
"Add-Content -Path BUILD -Value \"`nexports_files([`\"WORKSPACE`\"], visibility = [`\"//visibility:public`\"])`n\" -Force",
]
Expand All @@ -31,6 +37,10 @@ EXPORT_WORKSPACE_IN_BUILD_BAZEL_FILE_WIN = [
"Add-Content -Path BUILD.bazel -Value \"`nexports_files([`\"WORKSPACE`\"], visibility = [`\"//visibility:public`\"])`n\" -Force",
]

EXPORT_WORKSPACE_BAZEL_IN_BUILD_FILE_WIN = [
"Add-Content -Path BUILD -Value \"`nexports_files([`\"WORKSPACE.bazel`\"], visibility = [`\"//visibility:public`\"])`n\" -Force",
]

# Protobuf expects an //external:python_headers label which would contain the
# Python headers if fast Python protos is enabled. Since we are not using fast
# Python protos, bind python_headers to a dummy target.
Expand Down Expand Up @@ -566,6 +576,12 @@ dist_http_archive(
name = "rules_jvm_external",
)

dist_http_archive(
name = "rules_testing",
patch_cmds = EXPORT_WORKSPACE_BAZEL_IN_BUILD_FILE,
patch_cmds_win = EXPORT_WORKSPACE_BAZEL_IN_BUILD_FILE_WIN,
)

# Projects using gRPC as an external dependency must call both grpc_deps() and
# grpc_extra_deps().
load("@com_github_grpc_grpc//bazel:grpc_deps.bzl", "grpc_deps")
Expand Down
18 changes: 13 additions & 5 deletions distdir_deps.bzl
Expand Up @@ -289,17 +289,17 @@ DIST_DEPS = {
#
###################################################
"bazel_skylib": {
"archive": "bazel-skylib-1.0.3.tar.gz",
"sha256": "1c531376ac7e5a180e0237938a2536de0c54d93f5c278634818e0efc952dd56c",
"archive": "bazel-skylib-1.3.0.tar.gz",
"sha256": "74d544d96f4a5bb630d465ca8bbcfe231e3594e5aae57e1edbf17a6eb3ca2506",
"urls": [
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.0.3/bazel-skylib-1.0.3.tar.gz",
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.0.3/bazel-skylib-1.0.3.tar.gz",
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.3.0/bazel-skylib-1.3.0.tar.gz",
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.3.0/bazel-skylib-1.3.0.tar.gz",
],
"used_in": [
"additional_distfiles",
"test_WORKSPACE_files",
],
"package_version": "1.0.3",
"package_version": "1.3.0",
},
"io_bazel_skydoc": {
"archive": "1ef781ced3b1443dca3ed05dec1989eca1a4e1cd.tar.gz",
Expand Down Expand Up @@ -362,6 +362,14 @@ DIST_DEPS = {
"archive": "rules_python-0.19.0.tar.gz",
"used_in": ["additional_distfiles", "test_WORKSPACE_files"],
},
"rules_testing": {
"sha256": "4e21f9aa7996944ce91431f27bca374bff56e680acfe497276074d56bc5d9af2",
"strip_prefix": "rules_testing-0.0.4",
"urls": ["https://github.com/bazelbuild/rules_testing/releases/download/v0.0.4/rules_testing-v0.0.4.tar.gz"],
"archive": "rules_testing-v0.0.4.tar.gz",
"used_in": ["additional_distfiles", "test_WORKSPACE_files"],
"package_version": "0.0.4",
},
"desugar_jdk_libs": {
# Commit 5847d6a06302136d95a14b4cbd4b55a9c9f1436e of 2021-03-10
"archive": "5847d6a06302136d95a14b4cbd4b55a9c9f1436e.zip",
Expand Down
1 change: 1 addition & 0 deletions src/BUILD
Expand Up @@ -587,6 +587,7 @@ filegroup(
"@rules_pkg//:WORKSPACE",
"@rules_proto//:WORKSPACE",
"@rules_python//:WORKSPACE",
"@rules_testing//:WORKSPACE.bazel",
] + [
"@openjdk%s_%s_archive//:WORKSPACE" % (version, os)
for version in ("17", "20")
Expand Down
2 changes: 2 additions & 0 deletions src/test/shell/BUILD
Expand Up @@ -26,12 +26,14 @@ gen_workspace_stanza(
name = "testenv_sh",
out = "testenv.sh",
repos = [
"bazel_skylib",
"rules_cc",
"rules_java",
"rules_license",
"rules_pkg",
"rules_proto",
"rules_python",
"rules_testing",
],
template = "testenv.sh.tmpl",
visibility = ["//visibility:public"],
Expand Down
22 changes: 11 additions & 11 deletions src/test/shell/testenv.sh.tmpl
Expand Up @@ -512,18 +512,10 @@ function setup_objc_test_support() {
}

function setup_skylib_support() {
# Get skylib path portably by using rlocation to locate a top-level file in
# the repo. Use BUILD because it's in the //:test_deps target (unlike
# WORKSPACE).
local -r skylib_workspace="$(rlocation bazel_skylib/BUILD)"
[[ -n "$skylib_workspace" && -e "$skylib_workspace" ]] || fail "could not find Skylib"
local -r skylib_root="$(dirname "$skylib_workspace")"
cat >> WORKSPACE << EOF
new_local_repository(
name = 'bazel_skylib',
build_file_content = '',
path='$skylib_root',
)
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
{bazel_skylib}
load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
bazel_skylib_workspace()
Expand Down Expand Up @@ -578,6 +570,14 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
EOF
}

function add_rules_testing_to_workspace() {
cat >> "$1"<<EOF
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
{rules_testing}
EOF
}

function create_workspace_with_default_repos() {
write_workspace_file "${1:-WORKSPACE}" "${2:-main}"
echo "$1"
Expand Down

0 comments on commit 716541c

Please sign in to comment.