Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace uses of JavaInfo.transitive_export with custom label collection. #557

Merged
merged 1 commit into from
May 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions private/rules/has_maven_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ MavenInfo = provider(
"artifact_infos": "Depset of JavaInfo instances of targets to include in the maven artifact",
"dep_infos": "Depset of JavaInfo instances of dependencies that the maven artifact depends on",
"label_to_javainfo": "Dict mapping a label to the JavaInfo that label produces",
"transitive_exports": "Depset of Labels of exported targets",
},
)

Expand All @@ -29,6 +30,7 @@ _EMPTY_INFO = MavenInfo(
artifact_infos = depset(),
dep_infos = depset(),
label_to_javainfo = {},
transitive_exports = depset(),
)

_MAVEN_PREFIX = "maven_coordinates="
Expand Down Expand Up @@ -91,6 +93,7 @@ _gathered = provider(
"all_infos",
"label_to_javainfo",
"artifact_infos",
"transitive_exports",
"dep_infos",
],
)
Expand All @@ -105,6 +108,7 @@ def _extract_from(gathered, maven_info, dep):
gathered.dep_infos.append(dep[JavaInfo])
else:
gathered.artifact_infos.append(dep[JavaInfo])
gathered.transitive_exports.append(maven_info.transitive_exports)

def _has_maven_deps_impl(target, ctx):
if not JavaInfo in target:
Expand All @@ -125,6 +129,7 @@ def _has_maven_deps_impl(target, ctx):
gathered = _gathered(
all_infos = [],
artifact_infos = [target[JavaInfo]],
transitive_exports = [],
dep_infos = [],
label_to_javainfo = {target.label: target[JavaInfo]},
)
Expand All @@ -141,17 +146,27 @@ def _has_maven_deps_impl(target, ctx):

all_infos = gathered.all_infos
artifact_infos = gathered.artifact_infos
transitive_exports_from_deps = gathered.transitive_exports
dep_infos = gathered.dep_infos
label_to_javainfo = gathered.label_to_javainfo
maven_deps = depset(transitive = [i.as_maven_dep for i in all_infos])

transitive_exports_from_exports = depset()
if hasattr(ctx.rule.attr, "exports"):
transitive_exports_from_exports = depset(
[e.label for e in ctx.rule.attr.exports],
transitive =
[e[MavenInfo].transitive_exports for e in ctx.rule.attr.exports]
)

info = MavenInfo(
coordinates = coordinates,
maven_deps = maven_deps,
as_maven_dep = depset([coordinates]) if coordinates else maven_deps,
artifact_infos = depset(direct = artifact_infos),
dep_infos = depset(direct = dep_infos, transitive = [i.dep_infos for i in all_infos]),
label_to_javainfo = label_to_javainfo,
transitive_exports = depset(transitive = [transitive_exports_from_exports] + transitive_exports_from_deps)
)

return [
Expand Down
4 changes: 1 addition & 3 deletions private/rules/maven_project_jar.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ def _maven_project_jar_impl(ctx):

# Grab the exported javainfos
exported_infos = []
targets = [] + target[JavaInfo].transitive_exports.to_list()
for i in info.artifact_infos.to_list():
targets.extend(i.transitive_exports.to_list())
targets = target[MavenInfo].transitive_exports.to_list()

for label in targets:
export_info = info.label_to_javainfo.get(label)
Expand Down