Skip to content

Commit 04bbcc1

Browse files
authored
Fix scala_proto_library default outputs (bazel-contrib#1701)
* Fix scala_proto_library default outputs scala_proto_library returns too many outputs via DefaultInfo files It returns all transitive jar used for compilation while it should return pair of srcjar and compile jar for each direct proto_library dependency * make test pass * Add test with multiple deps
1 parent 2e59e88 commit 04bbcc1

File tree

3 files changed

+55
-6
lines changed

3 files changed

+55
-6
lines changed

scala_proto/private/scala_proto.bzl

+3-6
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,11 @@ def phase_merge_aspect_java_info(ctx, p):
2222

2323
def phase_default_info(ctx, p):
2424
java_info = p.merge_aspects.java_info
25+
output_jars = [jar.class_jar for jar in java_info.outputs.jars]
26+
source_jars = [jar.source_jar for jar in java_info.outputs.jars if jar.source_jar]
2527
return struct(
2628
external_providers = {
27-
"DefaultInfo": DefaultInfo(
28-
files = depset(
29-
java_info.source_jars,
30-
transitive = [java_info.full_compile_jars],
31-
),
32-
),
29+
"DefaultInfo": DefaultInfo(files = depset(output_jars + source_jars)),
3330
},
3431
)
3532

test/proto/BUILD

+34
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ load(
1212
"//scala_proto:scala_proto_toolchain.bzl",
1313
"scala_proto_toolchain",
1414
)
15+
load(":default_outputs_test.bzl", "default_outputs_test")
1516

1617
scala_proto_toolchain(
1718
name = "test_scala_proto_toolchain_configuration",
@@ -226,3 +227,36 @@ scala_test(
226227
unused_dependency_checker_mode = "off",
227228
deps = [":pack_protos_lib"],
228229
)
230+
231+
scala_proto_library(
232+
name = "standalone_scala_proto",
233+
deps = [":standalone_proto"],
234+
)
235+
236+
default_outputs_test(
237+
name = "standalone_scala_proto_outs_test",
238+
expected_outs = [
239+
"standalone_proto_scalapb-src.jar",
240+
"standalone_proto_scalapb.jar",
241+
],
242+
target_under_test = ":standalone_scala_proto",
243+
)
244+
245+
scala_proto_library(
246+
name = "multiple_deps_scala_proto",
247+
deps = [
248+
":test2",
249+
":test3",
250+
],
251+
)
252+
253+
default_outputs_test(
254+
name = "multiple_deps_scala_proto_outs_test",
255+
expected_outs = [
256+
"test2_scalapb-src.jar",
257+
"test2_scalapb.jar",
258+
"test3_scalapb-src.jar",
259+
"test3_scalapb.jar",
260+
],
261+
target_under_test = ":multiple_deps_scala_proto",
262+
)

test/proto/default_outputs_test.bzl

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
load("@bazel_skylib//lib:unittest.bzl", "analysistest", "asserts")
2+
3+
def _default_outputs_test(ctx):
4+
env = analysistest.begin(ctx)
5+
6+
target_under_test = analysistest.target_under_test(env)
7+
actual_outs = [f.basename for f in target_under_test[DefaultInfo].files.to_list()]
8+
9+
asserts.equals(env, sorted(ctx.attr.expected_outs), sorted(actual_outs))
10+
11+
return analysistest.end(env)
12+
13+
default_outputs_test = analysistest.make(
14+
_default_outputs_test,
15+
attrs = {
16+
"expected_outs": attr.string_list(),
17+
},
18+
)

0 commit comments

Comments
 (0)