Skip to content

Commit b174bfb

Browse files
ittaizAndre Rocha
authored andcommitted
Return providers array instead of legacy struct (bazel-contrib#916)
* runfiles and files are part of explicit DefaultInfo provider and do not come from attributes * removed transitive_rjars attribute as it was only needed internally and before phases was exposed mistakenly because that's how the infra worked Now internally phases use p.compile.rjars * executable attribute part of DefaultInfo as well * use coverage_common.instrumented_files_info provider instead of attribute * remove redundant attributes * linting * return array of providers instead of struct * scala_import return array of providers instead of struct
1 parent 6673900 commit b174bfb

File tree

3 files changed

+20
-31
lines changed

3 files changed

+20
-31
lines changed

scala/private/phases/phase_final.bzl

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,26 @@
44
# DOCUMENT THIS
55
#
66
def phase_binary_final(ctx, p):
7-
return struct(
7+
defaultInfo = DefaultInfo(
88
executable = p.declare_executable,
9-
coverage = p.compile.coverage,
109
files = depset([p.declare_executable, ctx.outputs.jar]),
11-
instrumented_files = p.compile.coverage.instrumented_files,
12-
providers = [p.compile.merged_provider, p.collect_jars.jars2labels] + p.compile.coverage.providers,
1310
runfiles = p.runfiles.runfiles,
14-
transitive_rjars = p.compile.rjars, #calling rules need this for the classpath in the launcher
1511
)
12+
return [defaultInfo, p.compile.merged_provider, p.collect_jars.jars2labels] + p.compile.coverage.providers
1613

1714
def phase_library_final(ctx, p):
18-
return struct(
15+
defaultInfo = DefaultInfo(
1916
files = depset([ctx.outputs.jar] + p.compile.full_jars), # Here is the default output
20-
instrumented_files = p.compile.coverage.instrumented_files,
21-
jars_to_labels = p.collect_jars.jars2labels,
22-
providers = [p.compile.merged_provider, p.collect_jars.jars2labels] + p.compile.coverage.providers,
2317
runfiles = p.runfiles.runfiles,
2418
)
19+
return [defaultInfo, p.compile.merged_provider, p.collect_jars.jars2labels] + p.compile.coverage.providers
2520

2621
def phase_scalatest_final(ctx, p):
2722
coverage_runfiles = p.coverage_runfiles.coverage_runfiles
2823
coverage_runfiles.extend(p.write_executable)
29-
return struct(
24+
defaultInfo = DefaultInfo(
3025
executable = p.declare_executable,
3126
files = depset([p.declare_executable, ctx.outputs.jar]),
32-
instrumented_files = p.compile.coverage.instrumented_files,
33-
providers = [p.compile.merged_provider, p.collect_jars.jars2labels] + p.compile.coverage.providers,
3427
runfiles = ctx.runfiles(coverage_runfiles, transitive_files = p.runfiles.runfiles.files),
3528
)
29+
return [defaultInfo, p.compile.merged_provider, p.collect_jars.jars2labels] + p.compile.coverage.providers

scala/private/rule_impls.bzl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ _scala_extension = ".scala"
4040
_srcjar_extension = ".srcjar"
4141

4242
_empty_coverage_struct = struct(
43-
instrumented_files = struct(),
43+
instrumented_files = None,
4444
providers = [],
4545
replacements = {},
4646
)
@@ -876,14 +876,14 @@ def _jacoco_offline_instrument(ctx, input_jar):
876876
provider = _coverage_replacements_provider.create(
877877
replacements = replacements,
878878
)
879-
879+
instrumented_files_provider = coverage_common.instrumented_files_info(
880+
ctx,
881+
source_attributes = ["srcs"],
882+
dependency_attributes = _coverage_replacements_provider.dependency_attributes,
883+
extensions = ["scala", "java"],
884+
)
880885
return struct(
881-
instrumented_files = struct(
882-
dependency_attributes = _coverage_replacements_provider.dependency_attributes,
883-
extensions = ["scala", "java"],
884-
source_attributes = ["srcs"],
885-
),
886-
providers = [provider],
886+
providers = [provider, instrumented_files_provider],
887887
replacements = replacements,
888888
)
889889

scala/scala_import.bzl

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,13 @@ def _scala_import_impl(ctx):
3232
# TODO(#8867): Migrate away from the placeholder jar hack when #8867 is fixed.
3333
current_target_providers = [_new_java_info(ctx, ctx.file._placeholder_jar)]
3434

35-
return struct(
36-
scala = struct(
37-
outputs = struct(jars = intellij_metadata),
35+
return [
36+
java_common.merge(current_target_providers),
37+
DefaultInfo(
38+
files = current_jars,
3839
),
39-
providers = [
40-
java_common.merge(current_target_providers),
41-
DefaultInfo(
42-
files = current_jars,
43-
),
44-
JarsToLabelsInfo(jars_to_labels = jars2labels),
45-
],
46-
)
40+
JarsToLabelsInfo(jars_to_labels = jars2labels),
41+
]
4742

4843
def _new_java_info(ctx, jar):
4944
return JavaInfo(

0 commit comments

Comments
 (0)