Skip to content

Commit

Permalink
Fix the Boringssl static dependency loop (#687)
Browse files Browse the repository at this point in the history
Using netty-tcnative-boringssl-static as a dependency generates internal dependency loop

This is a test which demonstrates the problem and a solution which resolves the problem but may not be a good solution.
  • Loading branch information
tjoneslo committed Apr 29, 2022
1 parent 2286790 commit d2c7811
Show file tree
Hide file tree
Showing 5 changed files with 246 additions and 44 deletions.
2 changes: 2 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ maven_install(
# https://github.com/bazelbuild/rules_jvm_external/issues/371
"com.fasterxml.jackson:jackson-bom:2.9.10",
"org.junit:junit-bom:5.3.1",
# https://github.com/bazelbuild/rules_jvm_external/issues/686
"io.netty:netty-tcnative-boringssl-static:2.0.51.Final",
],
generate_compat_repositories = True,
maven_install_json = "//tests/custom_maven_install:regression_testing_install.json",
Expand Down
43 changes: 24 additions & 19 deletions private/coursier_utilities.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
# Coursier uses these types to determine what files it should resolve and fetch.
# For example, some jars have the type "eclipse-plugin", and Coursier would not
# download them if it's not asked to to resolve "eclipse-plugin".

load ("//:specs.bzl", "parse")

SUPPORTED_PACKAGING_TYPES = [
"jar",
"json",
Expand All @@ -27,6 +30,17 @@ SUPPORTED_PACKAGING_TYPES = [
"scala-jar",
]

# See https://github.com/bazelbuild/rules_jvm_external/issues/686
# A single package uses classifier to distinguish the jar files (one per platform),
# So we need to check these are not dependencies of each other.
PLATFORM_CLASSIFIER = [
"linux-aarch_64",
"linux-x86_64",
"osx-aarch_64",
"osx-x86_64",
"windows-x86_64"
]

def strip_packaging_and_classifier(coord):
# Strip some packaging and classifier values based on the following maven coordinate formats
# groupId:artifactId:version
Expand All @@ -53,28 +67,19 @@ def strip_packaging_and_classifier_and_version(coord):
return ":".join(coordinates)
return ":".join(strip_packaging_and_classifier(coord).split(":")[:-1])

# TODO: Should these methods be combined with _parse_maven_coordinate_string in specs.
def match_group_and_artifact(source, target):
source_coord = parse.parse_maven_coordinate(source)
target_coord = parse.parse_maven_coordinate(target)
return source_coord["group"] == target_coord["group"] and source_coord["artifact"] == target_coord["artifact"]

def get_packaging(coord):
# Get packaging from the following maven coordinate formats
# groupId:artifactId:version
# groupId:artifactId:packaging:version
# groupId:artifactId:packaging:classifier:version
coordinates = coord.split(":")
if len(coordinates) > 3:
return coordinates[2]
else:
return None
# Get packaging from the following maven coordinate
return parse.parse_maven_coordinate(coord).get("packaging", None)

def get_classifier(coord):
# Get classifier from the following maven coordinate formats
# groupId:artifactId:version
# groupId:artifactId:packaging:version
# groupId:artifactId:packaging:classifier:version
coordinates = coord.split(":")
if len(coordinates) > 4:
return coordinates[3]
else:
return None
# Get classifier from the following maven coordinate
return parse.parse_maven_coordinate(coord).get("classifier", None)


def escape(string):
for char in [".", "-", ":", "/", "+"]:
Expand Down
18 changes: 17 additions & 1 deletion private/dependency_tree_parser.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,16 @@ This file contains parsing functions to turn a JSON-like dependency tree
into target declarations (jvm_import) for the final @maven//:BUILD file.
"""

load("//private:coursier_utilities.bzl", "escape", "get_classifier", "get_packaging", "strip_packaging_and_classifier", "strip_packaging_and_classifier_and_version")
load(
"//private:coursier_utilities.bzl",
"escape",
"get_classifier",
"get_packaging",
"match_group_and_artifact",
"strip_packaging_and_classifier",
"strip_packaging_and_classifier_and_version",
"PLATFORM_CLASSIFIER"
)

JETIFY_INCLUDE_LIST_JETIFY_ALL = ["*"]

Expand Down Expand Up @@ -200,6 +209,13 @@ def _generate_imports(repository_ctx, dep_tree, explicit_artifacts, neverlink_ar
stripped_dep = strip_packaging_and_classifier_and_version(dep)
dep_target_label = escape(strip_packaging_and_classifier_and_version(dep))

# If we have matching artifacts with platform classifiers, skip adding this dependency.
# See https://github.com/bazelbuild/rules_jvm_external/issues/686
if match_group_and_artifact(artifact["coord"], dep) and \
get_classifier(artifact["coord"]) in PLATFORM_CLASSIFIER and \
get_classifier(dep) in PLATFORM_CLASSIFIER:
continue

# Coursier returns cyclic dependencies sometimes. Handle it here.
# See https://github.com/bazelbuild/rules_jvm_external/issues/172
if dep_target_label != target_label:
Expand Down

0 comments on commit d2c7811

Please sign in to comment.