Skip to content

Commit

Permalink
Fix docs generation for artifacts with compile only dependencies (#1291)
Browse files Browse the repository at this point in the history
  • Loading branch information
vinnybod authored Dec 2, 2024
1 parent f3dee26 commit 534e62d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
28 changes: 26 additions & 2 deletions private/rules/has_maven_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,23 @@ _EMPTY_INFO = MavenInfo(
transitive_exports = depset(),
)

_STOPPED_INFO = MavenInfo(
coordinates = "STOPPED",
maven_deps = depset(),
as_maven_dep = depset(),
artifact_infos = depset(),
dep_infos = depset(),
label_to_javainfo = {},
transitive_exports = depset(),
)

_MAVEN_PREFIX = "maven_coordinates="
_STOP_TAGS = ["maven:compile-only", "maven:compile_only", "no-maven"]

_STOP_TAGS = [
"maven:compile-only",
"maven:compile_only",
"no-maven",
]

def read_coordinates(tags):
coordinates = []
Expand Down Expand Up @@ -112,6 +127,8 @@ def _extract_from(gathered, maven_info, dep, include_transitive_exports, is_runt

gathered.label_to_javainfo.update(maven_info.label_to_javainfo)
if java_info:
if maven_info.coordinates == "STOPPED":
pass
if maven_info.coordinates:
gathered.dep_infos.append(dep[JavaInfo])
else:
Expand All @@ -124,9 +141,16 @@ def _has_maven_deps_impl(target, ctx):
return [_EMPTY_INFO]

# Check the stop tags first to let us exit quickly.
# When MavenInfo is set, _extract_from will add the dep to the dep_infos list, propagating
# the dependency info to the pom.xml and excluding its jar from the artifact.
# If _EMPTY_INFO is used, _extract_from will add the dep to the artifact_infos list, which
# will include the jar in the artifact itself.
# If _STOPPED_INFO is used, _extract_from will not add the dep to either list. This is useful
# when we want to stop the propagation of the dependency info to the pom.xml while also excluding
# the jar from the artifact.
for tag in ctx.rule.attr.tags:
if tag in _STOP_TAGS:
return _EMPTY_INFO
return [_STOPPED_INFO]

coordinates = read_coordinates(ctx.rule.attr.tags)
label_to_javainfo = {target.label: target[JavaInfo]}
Expand Down
3 changes: 2 additions & 1 deletion private/rules/maven_project_jar.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ def _maven_project_jar_impl(ctx):
ctx.attr.excluded_workspaces,
)

artifact_srcs = calculate_artifact_source_jars(info)
artifact_srcs = _strip_excluded_workspace_jars(
calculate_artifact_source_jars(info),
artifact_srcs,
ctx.attr.excluded_workspaces,
)

Expand Down

0 comments on commit 534e62d

Please sign in to comment.