Skip to content

Commit 2696c00

Browse files
jjuddJaden Peterson
authored and
Jaden Peterson
committed
Use Providers everywhere and stop using structs
1 parent dd7b6b4 commit 2696c00

14 files changed

+166
-24
lines changed

dev/stardoc/stardoc.bzl

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
load("@bazel_skylib//lib:paths.bzl", "paths")
2+
load(
3+
"@rules_scala_annex//rules:providers.bzl",
4+
_DocInfo = "DocInfo",
5+
)
26

37
_bzl_files_containing_rules = [
48
"//rules:scala.bzl",
@@ -15,7 +19,7 @@ def _get_stardoc_targets():
1519
sanitized_name = label.removeprefix("//rules:").removeprefix("//rules/").replace(":", "_")
1620

1721
result.append(
18-
struct(
22+
_DocInfo(
1923
name = paths.replace_extension(sanitized_name, "-docs"),
2024
input = label,
2125
out = paths.replace_extension(sanitized_name, ".md"),

rules/jvm/private/label.bzl

+13-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
11
load("@rules_java//java/common:java_info.bzl", "JavaInfo")
2-
load("@rules_scala_annex//rules:providers.bzl", "LabeledJars")
2+
load(
3+
"@rules_scala_annex//rules:providers.bzl",
4+
_LabeledJars = "LabeledJars",
5+
_LabeledJarsData = "LabeledJarsData",
6+
)
37

48
def labeled_jars_implementation(target, ctx):
59
if JavaInfo not in target:
610
return []
711

8-
deps_labeled_jars = [dep[LabeledJars] for dep in getattr(ctx.rule.attr, "deps", []) if LabeledJars in dep]
12+
deps_labeled_jars = [dep[_LabeledJars] for dep in getattr(ctx.rule.attr, "deps", []) if _LabeledJars in dep]
913
java_info = target[JavaInfo]
1014
return [
11-
LabeledJars(
15+
_LabeledJars(
1216
values = depset(
13-
[struct(label = ctx.label, jars = depset(transitive = [java_info.compile_jars, java_info.full_compile_jars]))],
17+
[
18+
_LabeledJarsData(
19+
label = ctx.label,
20+
jars = depset(transitive = [java_info.compile_jars, java_info.full_compile_jars]),
21+
),
22+
],
1423
order = "preorder",
1524
transitive = [labeled_jars.values for labeled_jars in deps_labeled_jars],
1625
),

rules/private/coverage_replacements_provider.bzl

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
load("@bazel_skylib//lib:dicts.bzl", _dicts = "dicts")
22
load("@rules_java//java/common:java_info.bzl", "JavaInfo")
3+
load(
4+
"@rules_scala_annex//rules:providers.bzl",
5+
_CoverageReplacementsData = "CoverageReplacementsData",
6+
)
37

48
#
59
# Coverage Replacements are a mapping of normal compiled artifacts to
@@ -73,7 +77,7 @@ _aspect = aspect(
7377
implementation = _aspect_impl,
7478
)
7579

76-
coverage_replacements_provider = struct(
80+
coverage_replacements_provider = _CoverageReplacementsData(
7781
aspect = _aspect,
7882
dependency_attributes = _dependency_attributes,
7983
combine = _combine,

rules/private/phases/api.bzl

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
load(
22
"@rules_scala_annex//rules:providers.bzl",
3+
_PhasesInfo = "PhasesInfo",
4+
_PhasesInitInfo = "PhasesInitInfo",
5+
_PhasesOutInfo = "PhasesOutInfo",
36
_ScalaConfiguration = "ScalaConfiguration",
47
_ScalaRulePhase = "ScalaRulePhase",
58
)
@@ -19,23 +22,23 @@ def run_phases(ctx, phases):
1922
)
2023

2124
result_dict = {
22-
"init": struct(
25+
"init": _PhasesInitInfo(
2326
scala_configuration = toolchain.scala_configuration,
2427
),
25-
"out": struct(
28+
"out": _PhasesOutInfo(
2629
output_groups = {},
2730
providers = [],
2831
),
2932
}
3033

31-
result = struct(**result_dict)
34+
result = _PhasesInfo(**result_dict)
3235

3336
for (name, function) in phases:
3437
addition = function(ctx, result)
3538

3639
if addition != None:
3740
result_dict[name] = addition
38-
result = struct(**result_dict)
41+
result = _PhasesInfo(**result_dict)
3942

4043
return result
4144

rules/private/phases/phase_binary_launcher.bzl

+4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
load("@rules_java//java/common:java_common.bzl", "java_common")
2+
load(
3+
"@rules_scala_annex//rules:providers.bzl",
4+
_ZincCompilationInfo = "ZincCompilationInfo",
5+
)
26
load(
37
"//rules/common:private/utils.bzl",
48
_write_launcher = "write_launcher",

rules/private/phases/phase_classpaths.bzl

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ load("@rules_java//java/common:java_common.bzl", "java_common")
22
load("@rules_java//java/common:java_info.bzl", "JavaInfo")
33
load(
44
"@rules_scala_annex//rules:providers.bzl",
5+
_ClasspathInfo = "ClasspathInfo",
56
_ScalaInfo = "ScalaInfo",
67
)
78
load(
@@ -64,7 +65,7 @@ def phase_classpaths(ctx, g):
6465

6566
jar = ctx.actions.declare_file("{}/classes.jar".format(ctx.label.name))
6667

67-
return struct(
68+
return _ClasspathInfo(
6869
srcs = srcs,
6970
compile = compile_classpath,
7071
compiler = compiler_classpath,

rules/private/phases/phase_coverage_jacoco.bzl

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
load(
22
"@rules_scala_annex//rules:providers.bzl",
33
_CodeCoverageConfiguration = "CodeCoverageConfiguration",
4+
_JacocoInfo = "JacocoInfo",
45
)
56
load(
67
"@rules_scala_annex//rules/common:private/utils.bzl",
@@ -57,7 +58,7 @@ def phase_coverage_jacoco(ctx, g):
5758
),
5859
])
5960

60-
return struct(replacements = replacements)
61+
return _JacocoInfo(replacements = replacements)
6162

6263
def _format_in_out_pairs(in_out_pair):
6364
return (["--jar", "%s=%s" % (in_out_pair[0].path, in_out_pair[1].path)])

rules/private/phases/phase_ijinfo.bzl

+1-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,4 @@ load(
1010
#
1111

1212
def phase_ijinfo(ctx, g):
13-
intellij_info = _create_intellij_info(ctx.label, ctx.attr.deps, g.javainfo.java_info)
14-
g.out.providers.append(intellij_info)
15-
return struct(intellij_info = intellij_info)
13+
g.out.providers.append(_create_intellij_info(ctx.label, ctx.attr.deps, g.javainfo.java_info))

rules/private/phases/phase_javainfo.bzl

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ load("@rules_java//java/common:java_info.bzl", "JavaInfo")
33
load("@rules_java//toolchains:toolchain_utils.bzl", "find_java_toolchain")
44
load(
55
"@rules_scala_annex//rules:providers.bzl",
6+
_JavaScalaInfo = "JavaInfoPhaseInfo",
67
_ScalaConfiguration = "ScalaConfiguration",
78
_ScalaInfo = "ScalaInfo",
89
)
@@ -70,7 +71,7 @@ def phase_javainfo(ctx, g):
7071
g.out.providers.append(java_info)
7172
g.out.providers.append(scala_info)
7273

73-
return struct(
74+
return _JavaScalaInfo(
7475
java_info = java_info,
7576
scala_info = scala_info,
7677
)

rules/private/phases/phase_resources.bzl

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
load(
2-
"//rules/common:private/utils.bzl",
3-
_action_singlejar = "action_singlejar",
2+
"@rules_scala_annex//rules:providers.bzl",
3+
_ResourcesInfo = "ResourcesInfo",
44
)
55
#
66
# PHASE: resources
@@ -11,6 +11,11 @@ load(
1111
# phase will merge it into the final jar.
1212
#
1313

14+
load(
15+
"//rules/common:private/utils.bzl",
16+
_action_singlejar = "action_singlejar",
17+
)
18+
1419
def phase_resources(ctx, g):
1520
if ctx.files.resources:
1621
resource_jar = ctx.actions.declare_file("{}/resources.jar".format(ctx.label.name))
@@ -24,9 +29,9 @@ def phase_resources(ctx, g):
2429
for file in ctx.files.resources
2530
},
2631
)
27-
return struct(jar = resource_jar)
32+
return _ResourcesInfo(jar = resource_jar)
2833
else:
29-
return struct()
34+
return _ResourcesInfo()
3035

3136
def _resources_make_path(file, strip_prefix):
3237
if strip_prefix:

rules/private/phases/phase_semanticdb.bzl

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ load(
33
"@rules_scala_annex//rules:providers.bzl",
44
_ScalaConfiguration = "ScalaConfiguration",
55
_SemanticDbInfo = "SemanticDbInfo",
6+
_SemanticDbPhaseInfo = "SemanticDbPhaseInfo",
67
)
78

89
def _semanticdb_directory_from_file(file):
@@ -27,7 +28,7 @@ def phase_semanticdb(ctx, g):
2728
toolchain = ctx.toolchains["//rules/scala:toolchain_type"]
2829

2930
if toolchain.scala_configuration.semanticdb_bundle:
30-
return struct(outputs = [], arguments_modifier = lambda _: None)
31+
return _SemanticDbPhaseInfo(outputs = [], arguments_modifier = lambda _: None)
3132

3233
directory_name = "{}/semanticdb".format(ctx.label.name)
3334
outputs = []
@@ -72,4 +73,4 @@ def phase_semanticdb(ctx, g):
7273
),
7374
)
7475

75-
return struct(outputs = outputs, arguments_modifier = add_scalacopts)
76+
return _SemanticDbPhaseInfo(outputs = outputs, arguments_modifier = add_scalacopts)

rules/private/phases/phase_zinc_compile.bzl

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ load("@rules_java//toolchains:toolchain_utils.bzl", "find_java_toolchain")
33
load(
44
"@rules_scala_annex//rules:providers.bzl",
55
_ScalaConfiguration = "ScalaConfiguration",
6+
_ZincCompilationInfo = "ZincCompilationInfo",
67
_ZincConfiguration = "ZincConfiguration",
8+
_ZincDepInfo = "ZincDepInfo",
79
_ZincInfo = "ZincInfo",
810
)
911
load(
@@ -123,7 +125,7 @@ def phase_zinc_compile(ctx, g):
123125
deps_files = depset([analysis_store], transitive = [zinc.deps_files for zinc in zincs]),
124126
label = ctx.label,
125127
deps = depset(
126-
[struct(
128+
[_ZincDepInfo(
127129
analysis_store = analysis_store,
128130
jars = tuple(jars),
129131
label = ctx.label,
@@ -133,7 +135,7 @@ def phase_zinc_compile(ctx, g):
133135
)
134136

135137
g.out.providers.append(zinc_info)
136-
return struct(
138+
return _ZincCompilationInfo(
137139
mains_file = mains_file,
138140
used = used,
139141
# todo: see about cleaning up & generalizing fields below

rules/private/phases/phase_zinc_depscheck.bzl

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ load(
22
"@rules_scala_annex//rules:providers.bzl",
33
_DepsConfiguration = "DepsConfiguration",
44
_LabeledJars = "LabeledJars",
5+
_ZincCompilationInfo = "ZincCompilationInfo",
56
)
67
load(
78
"@rules_scala_annex//rules/common:private/utils.bzl",

rules/providers.bzl

+108
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,111 @@ SemanticDbInfo = provider(
8888
"semanticdb_files": "The SemanticDB files.",
8989
},
9090
)
91+
92+
CoverageReplacementsData = provider(
93+
doc = "Data for coverage replacements",
94+
fields = {
95+
"aspect": "Coverage replacement aspect",
96+
"dependency_attributes": "attributes used to form the dependency graph that we'll fold over for our aggregation",
97+
"combine": "Function used to combine coverage replacements",
98+
"from_ctx": "Function used to combine coverage replacements from a ctx",
99+
"create": "Provider to use for coverage replacements",
100+
},
101+
)
102+
103+
ClasspathInfo = provider(
104+
doc = "Outputs from the classpath phase.",
105+
fields = {
106+
"compile": "Classpath for this compilation.",
107+
"compiler": "Classpath needed by the compiler for this compilation.",
108+
"jar": "Output jar for this compilation.",
109+
"plugin": "Classpath for the compiler plugins for this compilation.",
110+
"sdeps": "Deps. TODO: better name for this?",
111+
"src_jars": "Source jars for this compilation.",
112+
"srcs": "Source files for this compilation.",
113+
},
114+
)
115+
116+
DocInfo = provider(
117+
doc = "Documentation realted info for a label.",
118+
fields = {
119+
"input": "Associated label",
120+
"name": "Docs label name",
121+
"out": "Docs file",
122+
},
123+
)
124+
125+
LabeledJarsData = provider(
126+
doc = "Data for LabeledJars",
127+
fields = {
128+
"jars": "Jars associated with the label",
129+
"label": "Label for the jars",
130+
},
131+
)
132+
133+
JacocoInfo = provider(
134+
doc = "Outputs from the Jacoco phase.",
135+
fields = {
136+
"replacements": "Coverage Replacement provider",
137+
},
138+
)
139+
140+
JavaInfoPhaseInfo = provider(
141+
doc = "Outputs from the JavaInfo phase.",
142+
fields = {
143+
"java_info": "JavaInfo provider",
144+
"scala_info": "ScalaInfo provider",
145+
},
146+
)
147+
148+
PhasesInfo = provider(
149+
doc = "Info related to the phases to run.",
150+
)
151+
152+
PhasesInitInfo = provider(
153+
doc = "Init information needed for phases",
154+
fields = {
155+
"scala_configuration": "Scala configuration for the toolchain.",
156+
},
157+
)
158+
159+
PhasesOutInfo = provider(
160+
doc = "Output related information for phases.",
161+
fields = {
162+
"output_groups": "Output groups",
163+
"providers": "Providers",
164+
},
165+
)
166+
167+
ResourcesInfo = provider(
168+
doc = "Outputs from the resources phase",
169+
fields = {
170+
"jar": "Resource jar containing resource files",
171+
},
172+
)
173+
174+
SemanticDbPhaseInfo = provider(
175+
doc = "Outputs from the SemanticDB phase.",
176+
fields = {
177+
"arguments_modifier": "Function to call to modify the scalac arguments for SemanticDB support.",
178+
"outputs": "Extra outputs for the SemanticDB files.",
179+
},
180+
)
181+
182+
ZincCompilationInfo = provider(
183+
doc = "Outputs from the Zinc compilation phase.",
184+
fields = {
185+
"mains_file": "File containing the main methods of this compilation.",
186+
"used": "File containing the used deps for this compilation.",
187+
"zinc_info": "a ZincInfo provider for this compilation.",
188+
},
189+
)
190+
191+
ZincDepInfo = provider(
192+
doc = "Information for a dep in a ZincInfo",
193+
fields = {
194+
"analysis_store": "Analysis store for this label",
195+
"jars": "Jars for this label",
196+
"label": "The label for this dep",
197+
},
198+
)

0 commit comments

Comments
 (0)