Skip to content

Commit

Permalink
feat: Pass additional coursier cli options (#1137)
Browse files Browse the repository at this point in the history
  • Loading branch information
honnix committed May 17, 2024
1 parent d3af1e6 commit bc3a190
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
5 changes: 5 additions & 0 deletions private/extensions/maven.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ _install = tag_class(
),
"ignore_empty_files": attr.bool(default = False, doc = "Treat jars that are empty as if they were not found."),
"repin_instructions": attr.string(doc = "Instructions to re-pin the repository if required. Many people have wrapper scripts for keeping dependencies up to date, and would like to point users to that instead of the default. Only honoured for the root module."),
"additional_coursier_options": attr.string_list(doc = "Additional options that will be passed to coursier."),
},
)

Expand Down Expand Up @@ -221,6 +222,7 @@ def _maven_impl(mctx):
# - use_starlark_android_rules: bool. A logical OR over all `use_starlark_android_rules` for all `install` tags with the same name.
# - version_conflict_policy: string. Fails build if different and not a default.
# - ignore_empty_files: Treat jars that are empty as if they were not found.
# - additional_coursier_options: Additional options that will be passed to coursier.

# Mapping of `name`s to `bazel_module.name` This will allow us to warn users when more than
# module attempts to update a maven repo (which is normally undesired behaviour)
Expand Down Expand Up @@ -339,6 +341,8 @@ def _maven_impl(mctx):
if mod.is_root:
repo["repin_instructions"] = install.repin_instructions

repo["additional_coursier_options"] = repo.get("additional_coursier_options", []) + getattr(install, "additional_coursier_options", [])

repos[install.name] = repo

# Breaking out the logic for picking lock files, because it's not terribly simple
Expand Down Expand Up @@ -427,6 +431,7 @@ def _maven_impl(mctx):
aar_import_bzl_label = repo.get("aar_import_bzl_label"),
duplicate_version_warning = repo.get("duplicate_version_warning"),
ignore_empty_files = repo.get("ignore_empty_files"),
additional_coursier_options = repo.get("additional_coursier_options"),
)
else:
# Only the coursier resolver allows the lock file to be omitted.
Expand Down
5 changes: 5 additions & 0 deletions private/rules/coursier.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,7 @@ def make_coursier_dep_tree(
fetch_sources,
fetch_javadoc,
timeout,
additional_coursier_options,
report_progress_prefix = ""):

if not repositories:
Expand Down Expand Up @@ -885,6 +886,8 @@ def make_coursier_dep_tree(
# https://github.com/coursier/coursier/blob/1cbbf39b88ee88944a8d892789680cdb15be4714/modules/paths/src/main/java/coursier/paths/CoursierPaths.java#L29-L56
environment = {"COURSIER_CACHE": str(repository_ctx.path(coursier_cache_location))}

cmd.extend(additional_coursier_options)

# Use an argsfile to avoid command line length limits, requires Java version > 8
java_cmd = cmd[0]
java_args = cmd[1:]
Expand Down Expand Up @@ -991,6 +994,7 @@ def _coursier_fetch_impl(repository_ctx):
repository_ctx.attr.fetch_sources,
repository_ctx.attr.fetch_javadoc,
repository_ctx.attr.resolve_timeout,
repository_ctx.attr.additional_coursier_options,
)

files_to_inspect = []
Expand Down Expand Up @@ -1432,6 +1436,7 @@ coursier_fetch = repository_rule(
],
),
"ignore_empty_files": attr.bool(default = False, doc = "Treat jars that are empty as if they were not found."),
"additional_coursier_options": attr.string_list(doc = "Additional options that will be passed to coursier."),
},
environ = [
"JAVA_HOME",
Expand Down
5 changes: 4 additions & 1 deletion private/rules/maven_install.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ def maven_install(
aar_import_bzl_label = DEFAULT_AAR_IMPORT_LABEL,
duplicate_version_warning = "warn",
repin_instructions = None,
ignore_empty_files = False):
ignore_empty_files = False,
additional_coursier_options = []):
"""Resolves and fetches artifacts transitively from Maven repositories.
This macro runs a repository rule that invokes the Coursier CLI to resolve
Expand Down Expand Up @@ -78,6 +79,7 @@ def maven_install(
is "warn".
repin_instructions: Instructions to re-pin dependencies in your repository. Will be shown when re-pinning is required.
ignore_empty_files: Treat jars that are empty as if they were not found.
additional_coursier_options: Additional options that will be passed to coursier.
"""
if boms and resolver == "coursier":
fail("The coursier resolver does not support resolving Maven BOMs. Please use another resolver.")
Expand Down Expand Up @@ -139,6 +141,7 @@ def maven_install(
aar_import_bzl_label = aar_import_bzl_label,
duplicate_version_warning = duplicate_version_warning,
ignore_empty_files = ignore_empty_files,
additional_coursier_options = additional_coursier_options,
)

else:
Expand Down

0 comments on commit bc3a190

Please sign in to comment.