Skip to content

Commit

Permalink
Fix //third_party tests with $(rootpath)
Browse files Browse the repository at this point in the history
Fixes `{strict_deps,unused_dependency_checker}_test` from
`//third_party/dependency_analyzer/src/test` under Bazel 8 by updating
`$(location)` to `$(rootpath)`. Part of bazelbuild#1652.

`//third_party/dependency_analyzer/src/test:strict_deps_test` and
`//third_party/dependency_analyzer/src/test:unused_dependency_checker_test`
both failed with errors of the form:

```txt
StrictDepsTest:
- error on indirect dependency target *** FAILED *** (379 milliseconds)
  nice errors on sequence of strings.this.infos.exists(nice errors on
  sequence of strings.this.checkErrorContainsMessage(target)) was false
  expected an error on //commons:Target to appear in errors (with
  buildozer command)!
  Errors: List(object apache is not a member of package org)
  (StrictDepsTest.scala:85)
```

This happened both under `WORKSPACE` and Bzlmod. Copying the test script
with the following (with `$ID` being one of `7`, `8`, `7-updated`, or
`8-updated`) helped reveal the differences:

```txt
cp bazel-bin/third_party/dependency_analyzer/src/test/strict_deps_test \
  strict_deps_test-$ID.sh
```

Under Bazel 7, we find the following lines whether using `$(location)`
or `$(rootpath)` on the `org.apache.commons` artifact (the other
artifacts already use `$(rootpath)`:

```txt
 -Dscala.library.location=external/io_bazel_rules_scala_scala_library_2_12_20/scala-library-2.12.20.jar
 -Dscala.reflect.location=external/io_bazel_rules_scala_scala_reflect_2_12_20/scala-reflect-2.12.20.jar
 -Dguava.jar.location=external/com_google_guava_guava_21_0_with_file/guava-21.0.jar
 -Dapache.commons.jar.location=external/org_apache_commons_commons_lang_3_5_without_file/commons-lang3-3.5.jar
```

Under Bazel 8, notice that the `external/` prefix has become `../` for
the other paths already using `$(rootpath)`, but remains `external/` for
the `$(location)` artifact. This breaks the Bazel 8 build:

```txt
-Dscala.library.location=../io_bazel_rules_scala_scala_library_2_12_20/scala-library-2.12.20.jar
-Dscala.reflect.location=../io_bazel_rules_scala_scala_reflect_2_12_20/scala-reflect-2.12.20.jar
-Dguava.jar.location=../com_google_guava_guava_21_0_with_file/guava-21.0.jar
-Dapache.commons.jar.location=external/org_apache_commons_commons_lang_3_5_without_file/commons-lang3-3.5.jar
```

Under Bazel 8, using `$(rootpath)` for the `org.apache.commons` artifact
converts its `external/`, fixing the Bazel 8 build:

```txt
-Dscala.library.location=../io_bazel_rules_scala_scala_library_2_12_20/scala-library-2.12.20.jar
-Dscala.reflect.location=../io_bazel_rules_scala_scala_reflect_2_12_20/scala-reflect-2.12.20.jar
-Dguava.jar.location=../com_google_guava_guava_21_0_with_file/guava-21.0.jar
-Dapache.commons.jar.location=../org_apache_commons_commons_lang_3_5_without_file/commons-lang3-3.5.jar
```
  • Loading branch information
mbland committed Dec 10, 2024
1 parent 966fcee commit 5ea7594
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions third_party/dependency_analyzer/src/test/analyzer_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def tests():
],
jvm_flags = common_jvm_flags + [
"-Dguava.jar.location=$(rootpath @com_google_guava_guava_21_0_with_file//jar)",
"-Dapache.commons.jar.location=$(location @org_apache_commons_commons_lang_3_5_without_file//:linkable_org_apache_commons_commons_lang_3_5_without_file)",
"-Dapache.commons.jar.location=$(rootpath @org_apache_commons_commons_lang_3_5_without_file//:linkable_org_apache_commons_commons_lang_3_5_without_file)",
],
unused_dependency_checker_mode = "off",
deps = scala_std_dependencies + [
Expand All @@ -80,7 +80,7 @@ def tests():
"io/bazel/rulesscala/dependencyanalyzer/UnusedDependencyCheckerTest.scala",
],
jvm_flags = common_jvm_flags + [
"-Dapache.commons.jar.location=$(location @org_apache_commons_commons_lang_3_5_without_file//:linkable_org_apache_commons_commons_lang_3_5_without_file)",
"-Dapache.commons.jar.location=$(rootpath @org_apache_commons_commons_lang_3_5_without_file//:linkable_org_apache_commons_commons_lang_3_5_without_file)",
],
unused_dependency_checker_mode = "off",
deps = scala_std_dependencies + [
Expand Down

0 comments on commit 5ea7594

Please sign in to comment.