Skip to content

Commit

Permalink
java_export: Fix Make variable substitution (#960)
Browse files Browse the repository at this point in the history
This requires forwarding `toolchains` to all rules as well as evaluating
Make variables for dependency coordinates in `pom_file`.
  • Loading branch information
fmeum authored Oct 11, 2023
1 parent 2c0dc66 commit f0c92a5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
10 changes: 9 additions & 1 deletion private/rules/java_export.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def java_export(
javadocopts = kwargs.pop("javadocopts", [])
doc_deps = kwargs.pop("doc_deps", [])
doc_url = kwargs.pop("doc_url", "")
toolchains = kwargs.pop("toolchains", [])

# Construct the java_library we'll export from here.
native.java_library(
Expand All @@ -108,6 +109,7 @@ def java_export(
classifier_artifacts = classifier_artifacts,
doc_deps = doc_deps,
doc_url = doc_url,
toolchains = toolchains,
)

def maven_export(
Expand All @@ -124,7 +126,8 @@ def maven_export(
classifier_artifacts = {},
*,
doc_deps = [],
doc_url = ""):
doc_url = "",
toolchains = None):
"""
All arguments are the same as java_export with the addition of:
lib_name: Name of the library that has been built.
Expand Down Expand Up @@ -210,6 +213,7 @@ def maven_export(
visibility = visibility,
tags = tags + maven_coordinates_tags,
testonly = testonly,
toolchains = toolchains,
)

native.filegroup(
Expand Down Expand Up @@ -251,6 +255,7 @@ def maven_export(
visibility = visibility,
tags = tags,
testonly = testonly,
toolchains = toolchains,
)
classifier_artifacts.setdefault("javadoc", docs_jar)

Expand All @@ -262,6 +267,7 @@ def maven_export(
visibility = visibility,
tags = tags,
testonly = testonly,
toolchains = toolchains,
)

maven_publish(
Expand All @@ -273,6 +279,7 @@ def maven_export(
visibility = visibility,
tags = tags,
testonly = testonly,
toolchains = toolchains,
)

# We may want to aggregate several `java_export` targets into a single Maven BOM POM
Expand All @@ -287,6 +294,7 @@ def maven_export(
testonly = testonly,
tags = tags,
visibility = visibility,
toolchains = toolchains,
)

# Finally, alias the primary output
Expand Down
6 changes: 5 additions & 1 deletion private/rules/pom_file.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,18 @@ def _pom_file_impl(ctx):
for dep in additional_deps:
for coords in dep[MavenInfo].as_maven_dep.to_list():
all_maven_deps.append(coords)
expanded_maven_deps = [
ctx.expand_make_variables("additional_deps", coords, ctx.var)
for coords in all_maven_deps
]

# Expand maven coordinates for any variables to be replaced.
coordinates = ctx.expand_make_variables("coordinates", info.coordinates, ctx.var)

out = generate_pom(
ctx,
coordinates = coordinates,
versioned_dep_coordinates = sorted(all_maven_deps),
versioned_dep_coordinates = sorted(expanded_maven_deps),
pom_template = ctx.file.pom_template,
out_name = "%s.xml" % ctx.label.name,
)
Expand Down

0 comments on commit f0c92a5

Please sign in to comment.