From b90e525e35f10d01a97b36945ee35987486f1045 Mon Sep 17 00:00:00 2001 From: Ivo List Date: Mon, 10 May 2021 16:37:08 +0000 Subject: [PATCH] Replace uses of JavaInfo.transitive_export with custom label collection. --- private/rules/has_maven_deps.bzl | 15 +++++++++++++++ private/rules/maven_project_jar.bzl | 4 +--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/private/rules/has_maven_deps.bzl b/private/rules/has_maven_deps.bzl index 10e439c0..92208743 100644 --- a/private/rules/has_maven_deps.bzl +++ b/private/rules/has_maven_deps.bzl @@ -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", }, ) @@ -29,6 +30,7 @@ _EMPTY_INFO = MavenInfo( artifact_infos = depset(), dep_infos = depset(), label_to_javainfo = {}, + transitive_exports = depset(), ) _MAVEN_PREFIX = "maven_coordinates=" @@ -91,6 +93,7 @@ _gathered = provider( "all_infos", "label_to_javainfo", "artifact_infos", + "transitive_exports", "dep_infos", ], ) @@ -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: @@ -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]}, ) @@ -141,10 +146,19 @@ 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, @@ -152,6 +166,7 @@ def _has_maven_deps_impl(target, ctx): 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 [ diff --git a/private/rules/maven_project_jar.bzl b/private/rules/maven_project_jar.bzl index 299b3692..5e3c1fb6 100644 --- a/private/rules/maven_project_jar.bzl +++ b/private/rules/maven_project_jar.bzl @@ -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)