Skip to content

Commit fe2e139

Browse files
hvadehrarules_java Copybara
authored andcommitted
Add a test for java_common.compile() with a custom bootclasspathinfo and empty bootclasspath
PiperOrigin-RevId: 729522132 Change-Id: Ib49f848211c8b2f83f42c5cd9e82ffdb1505c85d
1 parent 8b95028 commit fe2e139

2 files changed

Lines changed: 44 additions & 8 deletions

File tree

java/test/common/java_common_tests.bzl

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,14 +163,16 @@ def _test_compile_extend_compile_time_jdeps_rule_outputs_impl(env, targets):
163163
])
164164

165165
def _test_compile_bootclasspath(name):
166+
files = [
167+
"custom-system/lib/jrt-fs.jar",
168+
"custom-system/lib/modules",
169+
"custom-system/release",
170+
]
166171
util.helper_target(
167172
custom_bootclasspath,
168173
name = name + "/bootclasspath",
169-
srcs = [
170-
"custom-system/lib/jrt-fs.jar",
171-
"custom-system/lib/modules",
172-
"custom-system/release",
173-
],
174+
bootclasspath = files,
175+
system = files,
174176
)
175177
util.helper_target(
176178
custom_library_with_bootclasspath,
@@ -197,6 +199,39 @@ def _test_compile_bootclasspath_impl(env, target):
197199
"{}/custom-system".format(target.label.package),
198200
)])
199201

202+
def _test_compile_override_with_empty_bootclasspath(name):
203+
util.helper_target(
204+
custom_bootclasspath,
205+
name = name + "/bootclasspath",
206+
bootclasspath = [],
207+
system = [
208+
"custom-system/lib/jrt-fs.jar",
209+
"custom-system/lib/modules",
210+
"custom-system/release",
211+
],
212+
)
213+
util.helper_target(
214+
custom_library_with_bootclasspath,
215+
name = name + "/custom",
216+
srcs = ["Main.java"],
217+
bootclasspath = name + "/bootclasspath",
218+
)
219+
220+
analysis_test(
221+
name = name,
222+
impl = _test_compile_override_with_empty_bootclasspath_impl,
223+
target = name + "/custom",
224+
attr_values = {"tags": ["min_bazel_7"]},
225+
)
226+
227+
def _test_compile_override_with_empty_bootclasspath_impl(env, target):
228+
assert_that_javac = env.expect.that_target(target).action_named("Javac")
229+
230+
assert_that_javac.contains_flag_values([(
231+
"--system",
232+
"{}/custom-system".format(target.label.package),
233+
)])
234+
200235
def java_common_tests(name):
201236
test_suite(
202237
name = name,
@@ -208,5 +243,6 @@ def java_common_tests(name):
208243
_test_compile_extend_compile_time_jdeps,
209244
_test_compile_extend_compile_time_jdeps_rule_outputs,
210245
_test_compile_bootclasspath,
246+
_test_compile_override_with_empty_bootclasspath,
211247
],
212248
)

java/test/testutil/rules/custom_library_with_bootclasspath.bzl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ load("//java/common:java_common.bzl", "java_common")
44
load("//java/common:java_semantics.bzl", "semantics")
55

66
def _bootclasspath(ctx):
7-
files = ctx.files.srcs
8-
return [java_common.BootClassPathInfo(bootclasspath = files, system = files)]
7+
return [java_common.BootClassPathInfo(bootclasspath = ctx.files.bootclasspath, system = ctx.files.system)]
98

109
custom_bootclasspath = rule(
1110
implementation = _bootclasspath,
1211
attrs = {
13-
"srcs": attr.label_list(allow_files = True),
12+
"bootclasspath": attr.label_list(allow_files = True),
13+
"system": attr.label_list(allow_files = True),
1414
},
1515
)
1616

0 commit comments

Comments
 (0)