8000 Prepare for enabling Bzlmod for Bazel · coderabbit-test/bazel@9d30849 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9d30849

Browse files
meteorcloudycopybara-github
authored andcommitted
Prepare for enabling Bzlmod for Bazel
- Update MODULE.bazel for missing dependencies - Fix tests broken by repo mappings PiperOrigin-RevId: 554726284 Change-Id: I756041a126a9d0b4f1a26ebe264e23178c23f977
1 parent 87ef521 commit 9d30849

16 files changed

+152
-83
lines changed

MODULE.bazel

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Bazel build and test dependencies."""
2+
13
module(
24
name = "bazel",
35
version = "7.0.0-pre",
@@ -11,7 +13,7 @@ bazel_dep(name = "grpc", version = "1.48.1.bcr.1", repo_name = "com_github_grpc_
1113
bazel_dep(name = "platforms", version = "0.0.7")
1214
bazel_dep(name = "rules_pkg", version = "0.7.0")
1315
bazel_dep(name = "stardoc", version = "0.5.3", repo_name = "io_bazel_skydoc")
14-
bazel_dep(name = "zstd-jni", version = "1.5.2-3")
16+
bazel_dep(name = "zstd-jni", version = "1.5.2-3.bcr.1")
1517
bazel_dep(name = "blake3", version = "1.3.3")
1618
bazel_dep(name = "zlib", version = "1.2.13")
1719
bazel_dep(name = "rules_cc", version = "0.0.8")
@@ -42,7 +44,7 @@ local_path_override(
4244
)
4345

4446
# =========================================
45-
# Bazel Java dependencies
47+
# Java dependencies
4648
# =========================================
4749

4850
maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven")
@@ -57,6 +59,9 @@ maven.install(
5759
)
5860
use_repo(maven, "maven")
5961

62+
java_toolchains = use_extension("@rules_java//java:extensions.bzl", "toolchains")
63+
use_repo(java_toolchains, "local_jdk")
64+
6065
# =========================================
6166
# Other Bazel internal dependencies
6267
# - embedded JDKs
@@ -85,10 +90,44 @@ register_execution_platforms("//:default_host_platform")
8590

8691
register_toolchains("@bazel_tools//tools/python:autodetecting_toolchain")
8792

93+
register_toolchains("@local_config_winsdk//:all")
94+
8895
register_toolchains("//src/main/res:empty_rc_toolchain")
8996

9097
# =========================================
91-
# Android tools dependencies
98+
# Python dependencies
99+
# =========================================
100+
101+
python = use_extension("@rules_python//python/extensions:python.bzl", "python")
102+
python.toolchain(python_version = "3.8")
103+
104+
pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip")
105+
pip.parse(
106+
hub_name = "bazel_pip_dev_deps",
107+
python_version = "3.8",
108+
requirements_lock = "//:requirements.txt",
109+
)
110+
use_repo(pip, "bazel_pip_dev_deps")
111+
112+
# =========================================
113+
# Other dev dependencies
114+
# =========================================
115+
116+
bazel_dep(name = "googletest", version = "1.12.1", repo_name = "com_google_googletest")
117+
118+
bazel_dev_deps = use_extension("//:extensions.bzl", "bazel_dev_deps")
119+
use_repo(
120+
bazel_dev_deps,
121+
"local_bazel_source_list",
122+
"local_config_winsdk",
123+
"bazelci_rules",
124+
)
125+
126+
bazel_rbe_deps = use_extension("//:rbe_extension.bzl", "bazel_rbe_deps")
127+
use_repo(bazel_rbe_deps, "rbe_ubuntu1804_java11")
128+
129+
# =========================================
130+
# Android tools Java dependencies
92131
# =========================================
93132

94133
maven_android = use_extension("@rules_jvm_external//:extensions.bzl", "maven")
@@ -111,20 +150,3 @@ use_repo(
111150
"android_gmaven_r8",
112151
"desugar_jdk_libs",
113152
)
114-
115-
# =========================================
116-
# Bazel dev dependencies
117-
# =========================================
10000
118-
119-
bazel_dep(name = "googletest", version = "1.12.1", repo_name = "com_google_googletest")
120-
121-
bazel_dev_deps = use_extension("//:extensions.bzl", "bazel_dev_deps")
122-
use_repo(bazel_dev_deps, "local_bazel_source_list")
123-
124-
pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip")
125-
pip.parse(
126-
hub_name = "bazel_pip_dev_deps",
127-
python_version = "3.8",
128-
requirements_lock = "//:requirements.txt",
129-
)
130-
use_repo(pip, "bazel_pip_dev_deps")

extensions.bzl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ load("//:repositories.bzl", "embedded_jdk_repositories")
2020
load("//:distdir.bzl", "dist_http_archive", "dist_http_jar")
2121
load("//tools/distributions/debian:deps.bzl", "debian_deps")
2222
load("//src/test/shell/bazel:list_source_repository.bzl", "list_source_repository")
23+
load("//src/main/res:winsdk_configure.bzl", "winsdk_configure")
2324

2425
### Extra dependencies for building Bazel
2526

@@ -33,6 +34,8 @@ bazel_internal_deps = module_extension(implementation = _bazel_internal_deps)
3334

3435
def _bazel_dev_deps(_ctx):
3536
list_source_repository(name = "local_bazel_source_list")
37+
dist_http_archive(name = "bazelci_rules")
38+
winsdk_configure(name = "local_config_winsdk")
3639

3740
bazel_dev_deps = module_extension(implementation = _bazel_dev_deps)
3841

rbe_extension.bzl

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Copyright 2023 The Bazel Authors. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""Module extensions for loading RBE toolchains.
16+
17+
"""
18+
19+
load("@bazelci_rules//:rbe_repo.bzl", "rbe_preconfig")
20+
21+
def _bazel_rbe_deps(_ctx):
22+
rbe_preconfig(
23+
name = "rbe_ubuntu1804_java11",
24+
toolchain = "ubuntu1804-bazel-java11",
25+
)
26+
27+
bazel_rbe_deps = module_extension(implementation = _bazel_rbe_deps)

scripts/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ sh_test(
3333
"bazel-complete.bash",
3434
"testenv.sh",
3535
"//src/test/shell:bashunit",
36+
"@bazel_tools//tools/bash/runfiles",
3637
],
3738
)
3839

scripts/bash_completion_test.sh

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,16 @@
1616
#
1717
# bash_completion_test.sh: tests of bash command completion.
1818

19-
set -euo pipefail
19+
# --- begin runfiles.bash initialization v3 ---
20+
# Copy-pasted from the Bazel Bash runfiles library v3.
21+
set -uo pipefail; set +e; f=bazel_tools/tools/bash/runfiles/runfiles.bash
22+
source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \
23+
source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \
24+
source "$0.runfiles/$f" 2>/dev/null || \
25+
source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
26+
source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
27+
{ echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e
28+
# --- end runfiles.bash initialization v3 ---
2029

2130
: ${DIR:=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)}
2231
source ${DIR}/testenv.sh || { echo "testenv.sh not found!" >&2; exit 1; }
@@ -25,7 +34,7 @@ source ${DIR}/testenv.sh || { echo "testenv.sh not found!" >&2; exit 1; }
2534
: ${COMMAND_ALIASES:=bazel}
2635

2736
# Completion script
28-
: ${COMPLETION:="$TEST_SRCDIR/io_bazel/scripts/bazel-complete.bash"}
37+
: ${COMPLETION:="$(rlocation io_bazel/scripts/bazel-complete.bash)"}
2938

3039
# Set this to test completion with package path (if enabled)
3140
: ${PACKAGE_PATH_PREFIX:=}

scripts/testenv.sh

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,19 @@
1616
#
1717
# Setting up the environment for Bazel completion script test
1818

19-
[ -z "$TEST_SRCDIR" ] && { echo "TEST_SRCDIR not set!" >&2; exit 1; }
19+
# --- begin runfiles.bash initialization v3 ---
20+
# Copy-pasted from the Bazel Bash runfiles library v3.
21+
set -uo pipefail; set +e; f=bazel_tools/tools/bash/runfiles/runfiles.bash
22+
source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \
23+
source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \
24+
source "$0.runfiles/$f" 2>/dev/null || \
25+
source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
26+
source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
27+
{ echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e
28+
# --- end runfiles.bash initialization v3 ---
2029

2130
# Load the unit-testing framework
22-
source "${TEST_SRCDIR}/io_bazel/src/test/shell/unittest.bash" \
31+
source "$(rlocation io_bazel/src/test/shell/unittest.bash)" \
2332
|| { echo "Failed to source unittest.bash" >&2; exit 1; }
2433

2534
set_up() {

src/test/shell/bazel/android/aar_integration_test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ function test_android_binary_fat_apk_contains_all_shared_libraries() {
125125
add_to_bazelrc "build --noincompatible_enable_android_toolchain_resolution"
126126

127127
# sample.aar contains native shared libraries for x86 and armeabi-v7a
128-
cp "${TEST_SRCDIR}/io_bazel/src/test/shell/bazel/android/sample.aar" .
128+
cp "$(rlocation io_bazel/src/test/shell/bazel/android/sample.aar)" .
129129
cat > AndroidManifest.xml <<EOF
130130
<manifest package="com.example"/>
131131
EOF

src/test/shell/bazel/embedded_tools_deps_test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ fi
4242
# Sort the targets for a deterministic diffing experience.
4343
current_deps="${TEST_TMPDIR}/current_deps"
4444
grep -v "^@bazel_tools//\|^@remote_java_tools\|^@debian_cc_deps" \
45-
"${TEST_SRCDIR}/io_bazel/src/test/shell/bazel/embedded_tools_deps" \
45+
"$(rlocation io_bazel/src/test/shell/bazel/embedded_tools_deps)" \
4646
| sort >"${current_deps}"
4747

4848
# TODO: This is a temporary hack to make this test works both before and after

src/test/shell/bazel/java_launcher_test.sh

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,16 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17-
if ! type rlocation &> /dev/null; then
18-
# rlocation is a function defined in testenv.sh
19-
exit 1
20-
fi
17+
# --- begin runfiles.bash initialization v3 ---
18+
# Copy-pasted from the Bazel Bash runfiles library v3.
19+
set -uo pipefail; set +e; f=bazel_tools/tools/bash/runfiles/runfiles.bash
20+
source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \
21+
source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \
22+
source "$0.runfiles/$f" 2>/dev/null || \
23+
source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
24+
source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
25+
{ echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e
26+
# --- end runfiles.bash initialization v3 ---
2127

2228
source "$(rlocation "io_bazel/src/test/shell/integration_test_setup.sh")" \
2329
|| { echo "integration_test_setup.sh not found!" >&2; exit 1; }

src/test/shell/integration/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@ sh_test(
368368
data = [
369369
":rules_proto_stanza.txt",
370370
":test-deps",
371+
"//third_party/zlib",
371372
"@bazel_tools//tools/bash/runfiles",
372373
],
373374
)

src/test/shell/integration/execution_phase_tests.sh

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,16 @@
1818
# behaviors that affect the execution phase.
1919
#
2020

21-
# --- begin runfiles.bash initialization ---
22-
set -euo pipefail
23-
if [[ ! -d "${RUNFILES_DIR:-/dev/null}" && ! -f "${RUNFILES_MANIFEST_FILE:-/dev/null}" ]]; then
24-
if [[ -f "$TEST_SRCDIR/MANIFEST" ]]; then
25-
export RUNFILES_MANIFEST_FILE="$TEST_SRCDIR/MANIFEST"
26-
elif [[ -f "$0.runfiles/MANIFEST" ]]; then
27-
export RUNFILES_MANIFEST_FILE="$0.runfiles/MANIFEST"
28-
elif [[ -f "$TEST_SRCDIR/io_bazel/tools/bash/runfiles/runfiles.bash" ]]; then
29-
export RUNFILES_DIR="$TEST_SRCDIR"
30-
fi
31-
fi
32-
if [[ -f "${RUNFILES_DIR:-/dev/null}/io_bazel/tools/bash/runfiles/runfiles.bash" ]]; then
33-
source "${RUNFILES_DIR}/io_bazel/tools/bash/runfiles/runfiles.bash"
34-
elif [[ -f "${RUNFILES_MANIFEST_FILE:-/dev/null}" ]]; then
35-
source "$(grep -m1 "^io_bazel/tools/bash/runfiles/runfiles.bash " \
36-
"$RUNFILES_MANIFEST_FILE" | cut -d ' ' -f 2-)"
37-
else
38-
echo >&2 "ERROR: cannot find //third_party/bazel/tools/bash/runfiles:runfiles.bash"
39-
exit 1
40-
fi
41-
# --- end runfiles.bash initialization ---
21+
# --- begin runfiles.bash initialization v3 ---
22+
# Copy-pasted from the Bazel Bash runfiles library v3.
23+
set -uo pipefail; set +e; f=io_bazel/tools/bash/runfiles/runfiles.bash
24+
source "${TEST_SRCDIR:-/dev/null}/$f" 2>/dev/null || \
25+
source "$(grep -sm1 "^$f " "${TEST_SRCDIR:-/dev/null}/MANIFEST" | cut -f2- -d' ')" 2>/dev/null || \
26+
source "$0.runfiles/$f" 2>/dev/null || \
27+
source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
28+
source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
29+
{ echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e
30+
# --- end runfiles.bash initialization v3 ---
4231

4332
source "$(rlocation "io_bazel/src/test/shell/integration_test_setup.sh")" \
4433
|| { echo "integration_test_setup.sh not found!" >&2; exit 1; }

src/test/shell/integration/modify_execution_info_test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ rules_proto_toolchains()
160160
# @com_google_protobuf//:protoc depends on @io_bazel//third_party/zlib.
161161
new_local_repository(
162162
name = "io_bazel",
163-
path = "$(dirname $(rlocation io_bazel/third_party/zlib))/..",
163+
path = "$(dirname $(dirname $(dirname $(rlocation io_bazel/third_party/zlib/BUILD))))",
164164
build_file_content = "# Intentionally left empty.",
165165
workspace_file_content = "workspace(name = 'io_bazel')",
166166
)

src/test/shell/integration/target_compatible_with_test_external_repo.sh

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,16 @@
1616
#
1717
# target_compatible_with.sh variations for external repos.
1818

19-
# --- begin runfiles.bash initialization ---
20-
set -euo pipefail
21-
22-
if [[ ! -d "${RUNFILES_DIR:-/dev/null}" && ! -f "${RUNFILES_MANIFEST_FILE:-/dev/null}" ]]; then
23-
if [[ -f "$TEST_SRCDIR/MANIFEST" ]]; then
24-
export RUNFILES_MANIFEST_FILE="$TEST_SRCDIR/MANIFEST"
25-
elif [[ -f "$0.runfiles/MANIFEST" ]]; then
26-
export RUNFILES_MANIFEST_FILE="$0.runfiles/MANIFEST"
27-
elif [[ -f "$TEST_SRCDIR/io_bazel/tools/bash/runfiles/runfiles.bash" ]]; then
28-
export RUNFILES_DIR="$TEST_SRCDIR"
29-
fi
30-
fi
31-
if [[ -f "${RUNFILES_DIR:-/dev/null}/io_bazel/tools/bash/runfiles/runfiles.bash" ]]; then
32-
source "${RUNFILES_DIR}/io_bazel/tools/bash/runfiles/runfiles.bash"
33-
elif [[ -f "${RUNFILES_MANIFEST_FILE:-/dev/null}" ]]; then
34-
source "$(grep -m1 "^io_bazel/tools/bash/runfiles/runfiles.bash " \
35-
"$RUNFILES_MANIFEST_FILE" | cut -d ' ' -f 2-)"
36-
else
37-
echo >&2 "ERROR: cannot find //third_party/bazel/tools/bash/runfiles:runfiles.bash"
38-
exit 1
39-
fi
40-
# --- end runfiles.bash initialization ---
19+
# --- begin runfiles.bash initialization v3 ---
20+
# Copy-pasted from the Bazel Bash runfiles library v3.
21+
set -uo pipefail; set +e; f=io_bazel/tools/bash/runfiles/runfiles.bash
22+
source "${TEST_SRCDIR:-/dev/null}/$f" 2>/dev/null || \
23+
source "$(grep -sm1 "^$f " "${TEST_SRCDIR:-/dev/null}/MANIFEST" | cut -f2- -d' ')" 2>/dev/null || \
24+
source "$0.runfiles/$f" 2>/dev/null || \
25+
source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
26+
source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
27+
{ echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e
28+
# --- end runfiles.bash initialization v3 ---
4129

4230
source "$(rlocation "io_bazel/src/test/shell/integration_test_setup.sh")" \
4331
|| { echo "integration_test_setup.sh not found!" >&2; exit 1; }

src/test/shell/testenv.sh.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ distdir_bzl_file="${BAZEL_RUNFILES}/distdir.bzl"
9292
if [[ $PLATFORM =~ msys ]]; then
9393
jdk_dir="$(cygpath -m $(cd $(rlocation local_jdk/bin/java.exe)/../..; pwd))"
9494
else
95-
jdk_dir="${TEST_SRCDIR}/local_jdk"
95+
jdk_dir="$(dirname $(dirname $(rlocation local_jdk/bin/java)))"
9696
fi
9797

9898
# Tools directory location

third_party/ijar/test/BUILD

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ sh_test(
2020
"$(location :zip_count)",
2121
],
2222
data = [
23-
"testenv.sh",
24-
"//src/test/shell:bashunit",
2523
"//third_party/ijar",
2624
"A.java",
2725
"B.java",
@@ -54,6 +52,7 @@ sh_test(
5452
toolchains = [
5553
"@bazel_tools//tools/jdk:current_java_runtime",
5654
],
55+
deps = [":testenv"],
5756
)
5857

5958
sh_test(
@@ -66,12 +65,18 @@ sh_test(
6665
"unzip",
6766
"zip",
6867
],
69-
data = [
70-
"testenv.sh",
68+
data = ["//third_party/ijar:zipper"],
69+
tags = ["zip"],
70+
deps = [":testenv"],
71+
)
72+
73+
sh_library(
74+
name = "testenv",
75+
srcs = ["testenv.sh"],
76+
deps = [
7177
"//src/test/shell:bashunit",
72-
"//third_party/ijar:zipper",
78+
"@bazel_tools//tools/bash/runfiles",
7379
],
74-
tags = ["zip"],
7580
)
7681

7782
java_library(

0 commit comments

Comments
 (0)
0