From daa1688cb92e8d4b8c30e58d4d3a34186db96820 Mon Sep 17 00:00:00 2001 From: Hongxin Liang Date: Fri, 11 Oct 2024 15:08:35 +0200 Subject: [PATCH 1/4] fix: Deduplicate deps while amending --- private/rules/coursier.bzl | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/private/rules/coursier.bzl b/private/rules/coursier.bzl index 530a90bfb..28e37464e 100644 --- a/private/rules/coursier.bzl +++ b/private/rules/coursier.bzl @@ -954,6 +954,8 @@ def rewrite_files_attribute_if_necessary(repository_ctx, dep_tree): # `pinned_maven_install`. Oh well, let's just do this the manual way. if dep["file"].endswith(".pom"): jar_path = dep["file"].removesuffix(".pom") + ".jar" + if is_dep(jar_path, amended_deps): + continue if repository_ctx.path(jar_path).exists: dep["file"] = jar_path @@ -963,6 +965,12 @@ def rewrite_files_attribute_if_necessary(repository_ctx, dep_tree): return dep_tree +def is_dep(jar_path, deps): + for dep in reversed(deps): + if jar_path == dep.get("file", None): + return True + return False + def remove_prefix(s, prefix): if s.startswith(prefix): return s[len(prefix):] From 272dc5f9818cf73258b3dab1bd8eb22838785ac6 Mon Sep 17 00:00:00 2001 From: Hongxin Liang Date: Tue, 5 Nov 2024 09:18:10 +0100 Subject: [PATCH 2/4] Add comment --- private/rules/coursier.bzl | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/private/rules/coursier.bzl b/private/rules/coursier.bzl index 28e37464e..228a97968 100644 --- a/private/rules/coursier.bzl +++ b/private/rules/coursier.bzl @@ -954,6 +954,11 @@ def rewrite_files_attribute_if_necessary(repository_ctx, dep_tree): # `pinned_maven_install`. Oh well, let's just do this the manual way. if dep["file"].endswith(".pom"): jar_path = dep["file"].removesuffix(".pom") + ".jar" + + # The same artifact can being depended on via pom and jar at different + # places in the tree. In such case, we deduplicate it so that 2 + # entries do not reference the same file, which will otherwise lead + # in symlink error because of existing file down the road. if is_dep(jar_path, amended_deps): continue if repository_ctx.path(jar_path).exists: From 2f6f39c09c775cbde054761e2a8258fe701f9c65 Mon Sep 17 00:00:00 2001 From: Hongxin Liang Date: Tue, 5 Nov 2024 09:19:00 +0100 Subject: [PATCH 3/4] Remove unnecessary code --- private/rules/coursier.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/private/rules/coursier.bzl b/private/rules/coursier.bzl index 228a97968..18dd3d56f 100644 --- a/private/rules/coursier.bzl +++ b/private/rules/coursier.bzl @@ -971,7 +971,7 @@ def rewrite_files_attribute_if_necessary(repository_ctx, dep_tree): return dep_tree def is_dep(jar_path, deps): - for dep in reversed(deps): + for dep in deps: if jar_path == dep.get("file", None): return True return False From 4b6db34b5473c577ba049da033818b0f4d32769f Mon Sep 17 00:00:00 2001 From: Hongxin Liang Date: Tue, 5 Nov 2024 09:19:38 +0100 Subject: [PATCH 4/4] Add test case --- MODULE.bazel | 2 ++ WORKSPACE | 2 ++ tests/bazel_run_tests.sh | 15 +++++++++++++-- .../regression_testing_coursier_install.json | 8 ++++---- 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/MODULE.bazel b/MODULE.bazel index 5b834dd51..0dca77c53 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -554,6 +554,8 @@ dev_maven.install( "build.buf:protovalidate:0.1.9", # https://github.com/bazelbuild/rules_jvm_external/issues/1250 "com.github.spotbugs:spotbugs:4.7.0", + # https://github.com/bazelbuild/rules_jvm_external/issues/1267 + "org.mockito:mockito-core:pom:3.3.3", ], fail_if_repin_required = True, generate_compat_repositories = True, diff --git a/WORKSPACE b/WORKSPACE index 903b7ecd7..543b0e6dd 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -278,6 +278,8 @@ maven_install( "build.buf:protovalidate:0.1.9", # https://github.com/bazelbuild/rules_jvm_external/issues/1250 "com.github.spotbugs:spotbugs:4.7.0", + # https://github.com/bazelbuild/rules_jvm_external/issues/1267 + "org.mockito:mockito-core:pom:3.3.3", ], fail_if_repin_required = True, generate_compat_repositories = True, diff --git a/tests/bazel_run_tests.sh b/tests/bazel_run_tests.sh index 8095ef3d0..10b6a511d 100755 --- a/tests/bazel_run_tests.sh +++ b/tests/bazel_run_tests.sh @@ -259,7 +259,7 @@ function test_transitive_dependency_with_type_of_pom { bazel query @transitive_dependency_with_type_of_pom//:org_javamoney_moneta_moneta_core >> "$TEST_LOG" 2>&1 } -function test_when_both_pom_and_artifact_are_available_jar_artifact_is_present { +function test_when_both_pom_and_jar_artifact_are_available_jar_artifact_is_present { # The `maven_coordinates` of the target should be set to the coordinates of the jar # If the `pom` classifier is asked for, something has gone wrong and no results will # match @@ -268,6 +268,16 @@ function test_when_both_pom_and_artifact_are_available_jar_artifact_is_present { expect_log "@regression_testing_coursier//:com_github_spotbugs_spotbugs" } +function test_when_both_pom_and_jar_artifact_are_dependencies_jar_artifact_is_present { + # The `maven_coordinates` of the target should be set to the coordinates of the jar + # If both the `jar` and `pom` classifiers are asked for, something has gone wrong and no results + # will match + bazel query 'attr(tags, "org.mockito:mockito-core:3.3.3", @regression_testing_coursier//:org_mockito_mockito_core)' >> "$TEST_LOG" 2>&1 + + expect_log "@regression_testing_coursier//:org_mockito_mockito_core" +} + + TESTS=( "test_maven_resolution" "test_dependency_aggregation" @@ -286,7 +296,8 @@ TESTS=( "test_v1_lock_file_format" "test_dependency_pom_exclusion" "test_transitive_dependency_with_type_of_pom" - "test_when_both_pom_and_artifact_are_available_jar_artifact_is_present" + "test_when_both_pom_and_jar_artifact_are_available_jar_artifact_is_present" + "test_when_both_pom_and_jar_artifact_are_dependencies_jar_artifact_is_present" ) function run_tests() { diff --git a/tests/custom_maven_install/regression_testing_coursier_install.json b/tests/custom_maven_install/regression_testing_coursier_install.json index 85e5e822e..337241d4d 100644 --- a/tests/custom_maven_install/regression_testing_coursier_install.json +++ b/tests/custom_maven_install/regression_testing_coursier_install.json @@ -1,7 +1,7 @@ { "__AUTOGENERATED_FILE_DO_NOT_MODIFY_THIS_FILE_MANUALLY": "THERE_IS_NO_DATA_ONLY_ZUUL", - "__INPUT_ARTIFACTS_HASH": 1906932742, - "__RESOLVED_ARTIFACTS_HASH": 1555926687, + "__INPUT_ARTIFACTS_HASH": -1504192575, + "__RESOLVED_ARTIFACTS_HASH": 2071728921, "artifacts": { "android.arch.core:common": { "shasums": { @@ -618,9 +618,9 @@ }, "com.nimbusds:nimbus-jose-jwt": { "shasums": { - "jar": "978cc75ee13ef021e288bf1aa78d8ad9f69cee558119a09a5a64e7fc92085000" + "jar": "388f3fcec4f7ce41557b0271033c978c30f386cc302a6783be181edd599e9dff" }, - "version": "9.41.1" + "version": "9.45" }, "com.nimbusds:oauth2-oidc-sdk": { "shasums": {