Skip to content

Commit c0c98a2

Browse files
comiuscopybara-github
authored andcommitted
Add loads to integration tests
These are needed to flip --incompatible_disable_autoloads_in_main_repository PiperOrigin-RevId: 747798337 Change-Id: Ia600652523c5b41f436db0f612607e7f403a4157
1 parent 0d44148 commit c0c98a2

26 files changed

+576
-207
lines changed

examples/py/BUILD

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
load("@rules_python//python:py_binary.bzl", "py_binary")
2+
load("@rules_python//python:py_library.bzl", "py_library")
3+
14
py_library(
25
name = "lib",
36
srcs = ["lib.py"],

examples/py_native/BUILD

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
load("@rules_python//python:py_binary.bzl", "py_binary")
2+
load("@rules_python//python:py_library.bzl", "py_library")
3+
load("@rules_python//python:py_test.bzl", "py_test")
4+
15
filegroup(
26
name = "srcs",
37
srcs = glob(["*.py"]) + [

examples/py_native/fibonacci/BUILD

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
load("@rules_python//python:py_library.bzl", "py_library")
2+
13
filegroup(
24
name = "srcs",
35
srcs = glob(["*.py"]) + [

examples/shell/BUILD

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
load("@rules_shell//shell:sh_binary.bzl", "sh_binary")
2+
load("@rules_shell//shell:sh_library.bzl", "sh_library")
3+
load("@rules_shell//shell:sh_test.bzl", "sh_test")
4+
15
package(default_visibility = ["//visibility:public"])
26

37
sh_binary(

src/BUILD

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ load("@bazel_pip_dev_deps//:requirements.bzl", "requirement")
44
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
55
load("@rules_java//java:java_binary.bzl", "java_binary")
66
load("@rules_python//python:defs.bzl", "py_binary", "py_library")
7+
load("@rules_shell//shell:sh_binary.bzl", "sh_binary")
78
load("//src:build_defs.bzl", "transition_java_language_8_archive")
89
load("//src:release_archive.bzl", "release_archive")
910
load(":embedded_tools.bzl", "srcsfile")

src/main/java/com/google/devtools/build/skyframe/BUILD

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
load("@com_google_protobuf//bazel:java_proto_library.bzl", "java_proto_library")
12
load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library")
23
load("@rules_java//java:defs.bzl", "java_library")
34
load("//tools/build_rules:utilities.bzl", "java_library_srcs")

src/main/starlark/tests/builtins_bzl/builtin_test_setup.sh

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ function setup_tests() {
2323
add_bazel_skylib "MODULE.bazel"
2424
add_rules_python "MODULE.bazel"
2525
add_platforms "MODULE.bazel"
26+
add_rules_shell "MODULE.bazel"
2627
src=$(get_runfiles_dir $1)
2728
dest="${2:-$1}"
2829
if [ ! -e "$src" ]; then

src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test/BUILD.builtin_test

+4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ load(
1515
"runfiles_test",
1616
"wrapped_cc_lib",
1717
)
18+
load("@rules_cc//cc:cc_library.bzl", "cc_library")
19+
load("@rules_cc//cc:cc_binary.bzl", "cc_binary")
20+
load("@rules_cc//cc:cc_import.bzl", "cc_import")
21+
load("@rules_shell//shell:sh_test.bzl", "sh_test")
1822

1923
LINKABLE_MORE_THAN_ONCE = "LINKABLE_MORE_THAN_ONCE"
2024

src/main/starlark/tests/builtins_bzl/cc/cc_static_library/test/BUILD.builtin_test

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
load(":starlark_tests.bzl", "analysis_test_suite")
2+
load("@rules_cc//cc:cc_library.bzl", "cc_library")
3+
load("@rules_cc//cc:cc_import.bzl", "cc_import")
4+
load("@rules_shell//shell:sh_test.bzl", "sh_test")
25

36
cc_static_library(
47
name = "static",

src/test/java/com/google/devtools/build/lib/blackbox/tests/PythonBlackBoxTest.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ protected ImmutableList<ToolsSetup> getAdditionalTools() {
3838

3939
@Test
4040
public void testCompileAndRunHelloWorldStub() throws Exception {
41+
context().write(MODULE_DOT_BAZEL, "bazel_dep(name = 'rules_python', version = '0.40.0')");
42+
4143
writeHelloWorldFiles();
4244

4345
BuilderRunner bazel = context().bazel();
@@ -51,7 +53,11 @@ public void testCompileAndRunHelloWorldStub() throws Exception {
5153
}
5254

5355
private void writeHelloWorldFiles() throws IOException {
54-
context().write("python/hello/BUILD", "py_binary(name = 'hello', srcs = ['hello.py'])");
56+
context()
57+
.write(
58+
"python/hello/BUILD",
59+
"load('@rules_python//python:py_binary.bzl', 'py_binary')",
60+
"py_binary(name = 'hello', srcs = ['hello.py'])");
5561
context().write("python/hello/hello.py", String.format("print ('%s')", HELLO));
5662
}
5763
}

src/test/py/bazel/bazel_external_repository_test.py

+30-35
Original file line numberDiff line numberDiff line change
@@ -66,23 +66,20 @@ def tearDown(self):
6666
def testNewHttpArchive(self):
6767
ip, port = self._http_server.server_address
6868
rule_definition = [
69-
(
70-
'http_archive ='
71-
' use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl",'
72-
' "http_archive")'
73-
),
69+
'bazel_dep(name = "rules_python", version = "0.40.0")',
70+
'http_archive = use_repo_rule(',
71+
' "@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")',
7472
'http_archive(',
7573
' name = "hello_archive",',
7674
' urls = ["http://%s:%s/hello-1.0.0.tar.gz"],' % (ip, port),
77-
(
78-
' sha256 = '
79-
'"154740b327bcfee5669ef2ce0a04bf0904227a3bfe0fee08a5aaca96ea5a601a",'
80-
),
75+
' sha256 = ',
76+
' "154740b327bcfee5669ef2ce0a04bf0904227a3bfe0fee08a5aaca96ea5a601a",',
8177
' strip_prefix = "hello-1.0.0",',
8278
' build_file = "@//third_party:hello.BUILD",',
8379
')',
8480
]
8581
build_file = [
82+
'load("@rules_python//python:py_library.bzl", "py_library")',
8683
'py_library(',
8784
' name = "hello",',
8885
' srcs = ["hello.py"],',
@@ -189,20 +186,16 @@ def testNewHttpTarWithSparseFile(self):
189186

190187
ip, port = self._http_server.server_address
191188
rule_definition = [
192-
(
193-
'http_archive ='
194-
' use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl",'
195-
' "http_archive")'
196-
),
189+
'bazel_dep(name = "rules_python", version = "0.40.0")',
190+
'http_archive = use_repo_rule(',
191+
' "@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")',
197192
'http_archive(',
198193
' name = "sparse_archive",',
199194
' urls = ["http://%s:%s/sparse_archive.tar"],' % (ip, port),
200195
' build_file = "@//:sparse_archive.BUILD",',
201196
' sha256 = ',
202-
(
203-
' "a1a2b2ce4acd51a8cc1ab80adce6f134ac73e885219911a960a42000e312bb65",'
204-
')'
205-
),
197+
' "a1a2b2ce4acd51a8cc1ab80adce6f134ac73e885219911a960a42000e312bb65",',
198+
')',
206199
]
207200
self.ScratchFile('MODULE.bazel', rule_definition)
208201
self.ScratchFile(
@@ -224,13 +217,12 @@ def testNewHttpTarWithSparseFile(self):
224217
self.ScratchFile(
225218
'BUILD',
226219
[
220+
'load("@rules_python//python:py_test.bzl", "py_test")',
227221
'py_test(',
228222
' name = "test",',
229223
' srcs = ["test.py"],',
230-
(
231-
' args = ["$(rlocationpath @sparse_archive//:sparse_file)"],'
232-
' data = ['
233-
),
224+
' args = ["$(rlocationpath @sparse_archive//:sparse_file)"],',
225+
' data = [',
234226
' "@sparse_archive//:sparse_file",',
235227
' "@bazel_tools//tools/python/runfiles",',
236228
' ],)',
@@ -260,10 +252,11 @@ def _CreatePyWritingStarlarkRule(self, print_string):
260252
def testNewLocalRepositoryNoticesFileChangeInRepoRoot(self):
261253
"""Regression test for https://github.com/bazelbuild/bazel/issues/7063."""
262254
rule_definition = [
255+
'bazel_dep(name = "rules_python", version = "0.40.0")',
256+
'new_local_repository = use_repo_rule(',
263257
(
264-
'new_local_repository ='
265-
' use_repo_rule("@bazel_tools//tools/build_defs/repo:local.bzl",'
266-
' "new_local_repository")'
258+
' "@bazel_tools//tools/build_defs/repo:local.bzl",'
259+
' "new_local_repository")'
267260
),
268261
'new_local_repository(',
269262
' name = "r",',
@@ -273,11 +266,15 @@ def testNewLocalRepositoryNoticesFileChangeInRepoRoot(self):
273266
]
274267
self.ScratchFile('MODULE.bazel', rule_definition)
275268
self._CreatePyWritingStarlarkRule('hello!')
276-
self.ScratchFile('BUILD', [
277-
'load("@r//:foo.bzl", "gen_py")',
278-
'gen_py(name = "gen")',
279-
'py_binary(name = "bin", srcs = [":gen"], main = "gen.py")',
280-
])
269+
self.ScratchFile(
270+
'BUILD',
271+
[
272+
'load("@r//:foo.bzl", "gen_py")',
273+
'load("@rules_python//python:py_binary.bzl", "py_binary")',
274+
'gen_py(name = "gen")',
275+
'py_binary(name = "bin", srcs = [":gen"], main = "gen.py")',
276+
],
277+
)
281278

282279
_, stdout, _ = self.RunBazel(['run', '//:bin'])
283280
self.assertIn('hello!', os.linesep.join(stdout))
@@ -294,11 +291,9 @@ def setUpOtherRepoMyRepo(self):
294291
self.ScratchFile(
295292
'my_repo/MODULE.bazel',
296293
[
297-
(
298-
'local_repository ='
299-
' use_repo_rule("@bazel_tools//tools/build_defs/repo:local.bzl",'
300-
' "local_repository")'
301-
),
294+
'local_repository = use_repo_rule(',
295+
' "@bazel_tools//tools/build_defs/repo:local.bzl",',
296+
' "local_repository")',
302297
'local_repository(name = "other_repo", path="../other_repo")',
303298
],
304299
)

0 commit comments

Comments
 (0)