Skip to content

Commit 8f6a2aa

Browse files
authored
Make jar_app_layer._classpath_as_file public (bazelbuild#1947)
* Rename jar_app_layer._classpath_as_file to classpath_as_file This is being done to make this attribute public so that callers can specify it. * Add classpath_as_file as argument to java_image * Add classpath_as_file as argument to groovy_image * Add classpath_as_file as argument to kt_jvm_image * Add classpath_as_file as argument to scala_image * Adds test for scala_image with classpath_as_file=True * Adds test for java_image with classpath_as_file = True * Adds test for groovy_image with classpath_as_file = True * Adds test for kt_jvm_image with classpath_as_file = True * Ignore new image tests under macos * Trigger build * Trigger build
1 parent 4887961 commit 8f6a2aa

File tree

13 files changed

+157
-2
lines changed

13 files changed

+157
-2
lines changed

Diff for: .bazelci/presubmit.yml

+4
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,15 @@ tasks:
6969
- -//tests/container/go:go_image_test
7070
- -//tests/container/go:go_static_image_test
7171
- -//tests/container/groovy:groovy_image_test
72+
- -//tests/container/groovy:groovy_classpath_as_file_image_test
7273
- -//tests/container/java:java_image_test
74+
- -//tests/container/java:java_classpath_as_file_image_test
7375
- -//tests/container/java:java_partial_entrypoint_image_test
7476
- -//tests/container/java:java_runfiles_as_lib_image_test
7577
- -//tests/container/java:java_runfiles_image_test
7678
- -//tests/container/java:simple_java_entrypoint_image_test
7779
- -//tests/container/kotlin:kotlin_image_test
80+
- -//tests/container/kotlin:kotlin_classpath_as_file_image_test
7881
- -//tests/container/nodejs:nodejs_image_custom_binary_test
7982
- -//tests/container/nodejs:nodejs_image_custom_binary_with_args_test
8083
- -//tests/container/nodejs:nodejs_image_empty_list_args_test
@@ -86,6 +89,7 @@ tasks:
8689
- -//tests/container/python3:py3_image_test
8790
- -//tests/container/rust:rust_image_test
8891
- -//tests/container/scala:scala_image_test
92+
- -//tests/container/scala:scala_classpath_as_file_image_test
8993
- -//tests/contrib:derivative_with_volume_repro_test
9094
- -//tests/contrib:random_file_img_non_repro_test
9195
- -//tests/contrib:rbe-test-xenial_repro_test

Diff for: groovy/image.bzl

+2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def groovy_image(
3333
deps = [],
3434
layers = [],
3535
jvm_flags = [],
36+
classpath_as_file = None,
3637
**kwargs):
3738
"""Builds a container image overlaying the groovy_binary.
3839
@@ -93,6 +94,7 @@ def groovy_image(
9394
args = kwargs.get("args"),
9495
data = kwargs.get("data"),
9596
testonly = kwargs.get("testonly"),
97+
classpath_as_file = classpath_as_file,
9698
)
9799

98100
def repositories():

Diff for: java/image.bzl

+4-2
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ def _jar_app_layer_impl(ctx):
201201
"/usr/bin/java",
202202
"-cp",
203203
# Support optionally passing the classpath as a file.
204-
"@" + classpath_path if ctx.attr._classpath_as_file else classpath,
204+
"@" + classpath_path if ctx.attr.classpath_as_file else classpath,
205205
] + jvm_flags + ([ctx.attr.main_class] + args if ctx.attr.main_class != "" else [])
206206

207207
file_map = {
@@ -245,7 +245,7 @@ jar_app_layer = rule(
245245
"workdir": attr.string(default = ""),
246246

247247
# Whether the classpath should be passed as a file.
248-
"_classpath_as_file": attr.bool(default = False),
248+
"classpath_as_file": attr.bool(default = False),
249249
"_jdk": attr.label(
250250
default = Label("@bazel_tools//tools/jdk:current_java_runtime"),
251251
providers = [java_common.JavaRuntimeInfo],
@@ -265,6 +265,7 @@ def java_image(
265265
runtime_deps = [],
266266
layers = [],
267267
jvm_flags = [],
268+
classpath_as_file = None,
268269
**kwargs):
269270
"""Builds a container image overlaying the java_binary.
270271
@@ -327,6 +328,7 @@ def java_image(
327328
args = kwargs.get("args"),
328329
data = kwargs.get("data"),
329330
testonly = kwargs.get("testonly"),
331+
classpath_as_file = classpath_as_file,
330332
)
331333

332334
def _war_dep_layer_impl(ctx):

Diff for: kotlin/image.bzl

+2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def kt_jvm_image(
3434
deps = [],
3535
layers = [],
3636
jvm_flags = [],
37+
classpath_as_file = None,
3738
**kwargs):
3839
"""Builds a container image overlaying the kt_jvm_binary.
3940
@@ -92,6 +93,7 @@ def kt_jvm_image(
9293
args = kwargs.get("args"),
9394
data = kwargs.get("data"),
9495
testonly = kwargs.get("testonly"),
96+
classpath_as_file = classpath_as_file,
9597
)
9698

9799
def repositories():

Diff for: scala/image.bzl

+2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def scala_image(
3333
runtime_deps = [],
3434
layers = [],
3535
jvm_flags = [],
36+
classpath_as_file = None,
3637
**kwargs):
3738
"""Builds a container image overlaying the scala_binary.
3839
@@ -85,6 +86,7 @@ def scala_image(
8586
args = kwargs.get("args"),
8687
data = kwargs.get("data"),
8788
testonly = kwargs.get("testonly"),
89+
classpath_as_file = classpath_as_file,
8890
)
8991

9092
def repositories():

Diff for: tests/container/groovy/BUILD

+21
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,29 @@ groovy_image(
3838
main_class = "examples.images.Binary",
3939
)
4040

41+
groovy_image(
42+
name = "groovy_classpath_as_file_image",
43+
srcs = ["//testdata:Binary.groovy"],
44+
args = [
45+
"arg0",
46+
"arg1",
47+
"$(location :BUILD)",
48+
],
49+
classpath_as_file = True,
50+
data = [":BUILD"],
51+
jvm_flags = ["-Dbuild.location=$(location :BUILD)"],
52+
layers = [":groovy_image_library"],
53+
main_class = "examples.images.Binary",
54+
)
55+
4156
container_test(
4257
name = "groovy_image_test",
4358
configs = ["//tests/container/groovy/configs:groovy_image.yaml"],
4459
image = ":groovy_image",
4560
)
61+
62+
container_test(
63+
name = "groovy_classpath_as_file_image_test",
64+
configs = ["//tests/container/groovy/configs:groovy_classpath_as_file_image.yaml"],
65+
image = ":groovy_classpath_as_file_image",
66+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
schemaVersion: 2.0.0
2+
3+
metadataTest:
4+
entrypoint: [
5+
'/usr/bin/java',
6+
'-cp',
7+
'@/app/io_bazel_rules_docker/tests/container/groovy/groovy_classpath_as_file_image.classpath',
8+
'-Dbuild.location=tests/container/groovy/BUILD',
9+
'examples.images.Binary',
10+
'arg0',
11+
'arg1',
12+
'tests/container/groovy/BUILD',
13+
]

Diff for: tests/container/java/BUILD

+23
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,23 @@ java_image(
5151
main_class = "examples.images.Binary",
5252
)
5353

54+
java_image(
55+
name = "java_classpath_as_file_image",
56+
srcs = ["//testdata:Binary.java"],
57+
args = [
58+
"arg0",
59+
"arg1",
60+
"$(location :BUILD)",
61+
],
62+
classpath_as_file = True,
63+
data = [":BUILD"],
64+
jvm_flags = [
65+
"-Dbuild.location=$(location :BUILD)",
66+
],
67+
layers = [":java_image_library"],
68+
main_class = "examples.images.Binary",
69+
)
70+
5471
java_image(
5572
name = "java_runfiles_image",
5673
srcs = ["//testdata:Runfiles.java"],
@@ -91,6 +108,12 @@ container_test(
91108
image = ":java_image",
92109
)
93110

111+
container_test(
112+
name = "java_classpath_as_file_image_test",
113+
configs = ["//tests/container/java/configs:java_classpath_as_file_image.yaml"],
114+
image = ":java_classpath_as_file_image",
115+
)
116+
94117
container_test(
95118
name = "java_runfiles_image_test",
96119
configs = ["//tests/container/java/configs:java_runfiles_image.yaml"],
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
schemaVersion: 2.0.0
2+
3+
metadataTest:
4+
env:
5+
- key: JAVA_RUNFILES
6+
value: "/app"
7+
entrypoint: [
8+
'/usr/bin/java',
9+
'-cp',
10+
'@/app/io_bazel_rules_docker/tests/container/java/java_classpath_as_file_image.classpath',
11+
'-Dbuild.location=tests/container/java/BUILD',
12+
'examples.images.Binary',
13+
'arg0',
14+
'arg1',
15+
'tests/container/java/BUILD']

Diff for: tests/container/kotlin/BUILD

+24
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,32 @@ kt_jvm_image(
3434
deps = [],
3535
)
3636

37+
kt_jvm_image(
38+
name = "kt_jvm_classpath_as_file_image",
39+
srcs = [
40+
"//testdata:Binary.kt",
41+
"//testdata:Library.kt",
42+
],
43+
args = [
44+
"arg0",
45+
"arg1",
46+
"$(location :BUILD)",
47+
],
48+
classpath_as_file = True,
49+
data = [":BUILD"],
50+
jvm_flags = ["-Dbuild.location=$(location :BUILD)"],
51+
main_class = "examples.images.Binary",
52+
deps = [],
53+
)
54+
3755
container_test(
3856
name = "kotlin_image_test",
3957
configs = ["//tests/container/kotlin/configs:kt_jvm_image.yaml"],
4058
image = ":kt_jvm_image",
4159
)
60+
61+
container_test(
62+
name = "kotlin_classpath_as_file_image_test",
63+
configs = ["//tests/container/kotlin/configs:kt_jvm_classpath_as_file_image.yaml"],
64+
image = ":kt_jvm_classpath_as_file_image",
65+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
schemaVersion: 2.0.0
2+
3+
metadataTest:
4+
entrypoint: [
5+
'/usr/bin/java',
6+
'-cp',
7+
'@/app/io_bazel_rules_docker/tests/container/kotlin/kt_jvm_classpath_as_file_image.classpath',
8+
'-Dbuild.location=tests/container/kotlin/BUILD',
9+
'examples.images.Binary',
10+
'arg0',
11+
'arg1',
12+
'tests/container/kotlin/BUILD',
13+
]

Diff for: tests/container/scala/BUILD

+21
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,24 @@ container_test(
4343
configs = ["//tests/container/scala/configs:scala_image.yaml"],
4444
image = ":scala_image",
4545
)
46+
47+
scala_image(
48+
name = "scala_classpath_as_file_image",
49+
srcs = ["//testdata:Binary.scala"],
50+
args = [
51+
"arg0",
52+
"arg1",
53+
"$(location :BUILD)",
54+
],
55+
classpath_as_file = True,
56+
data = [":BUILD"],
57+
jvm_flags = ["-Dbuild.location=$(location :BUILD)"],
58+
layers = [":scala_image_library"],
59+
main_class = "examples.images.Binary",
60+
)
61+
62+
container_test(
63+
name = "scala_classpath_as_file_image_test",
64+
configs = ["//tests/container/scala/configs:scala_classpath_as_file_image.yaml"],
65+
image = ":scala_classpath_as_file_image",
66+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
schemaVersion: 2.0.0
2+
3+
metadataTest:
4+
entrypoint: [
5+
'/usr/bin/java',
6+
'-cp',
7+
'@/app/io_bazel_rules_docker/tests/container/scala/scala_classpath_as_file_image.classpath',
8+
'-Dbuild.location=tests/container/scala/BUILD',
9+
'examples.images.Binary',
10+
'arg0',
11+
'arg1',
12+
'tests/container/scala/BUILD',
13+
]

0 commit comments

Comments
 (0)