-
Notifications
You must be signed in to change notification settings - Fork 281
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix resource priority under name collision (#1456)
* Add failing test for resource name duplication * Topological sort jars (so that the target jar comes first) fix #1456 * Sort jars by pre-topological sort to preserve leftmost-first guarantee With topological order, there's no left-to-right order guarantee https://bazel.build/rules/lib/depset As a result, `test/shell/test_misc`'s `test_multi_service_manifest` fails because the order of `exepected_service_manifest.txt` reverses.
- Loading branch information
1 parent
dee33f4
commit 15f2461
Showing
6 changed files
with
37 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
test/src/main/scala/scalarules/test/duplicated_resources/child/BUILD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
load("//scala:scala.bzl", "scala_test") | ||
|
||
# https://github.com/bazelbuild/rules_scala/issues/1455 | ||
scala_test( | ||
name = "child", | ||
size = "small", | ||
srcs = ["ScalaLibResourcesDuplicatedTest.scala"], | ||
resource_strip_prefix = "test/src/main/scala/scalarules/test/duplicated_resources/child/", | ||
resources = ["resource.txt"], | ||
unused_dependency_checker_mode = "off", | ||
deps = ["//test/src/main/scala/scalarules/test/duplicated_resources/parent"], | ||
) |
14 changes: 14 additions & 0 deletions
14
...in/scala/scalarules/test/duplicated_resources/child/ScalaLibResourcesDuplicatedTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package scalarules.test.duplicated | ||
|
||
import org.scalatest.funsuite._ | ||
|
||
class ScalaLibResourcesDuplicatedTest extends AnyFunSuite { | ||
|
||
test("Scala library depends on resource + deps that contains same name resources, have higher priority on this target's resource.") { | ||
assert(get("/resource.txt") === "I am a text resource from child!\n") | ||
} | ||
|
||
private def get(s: String): String = | ||
scala.io.Source.fromInputStream(getClass.getResourceAsStream(s)).mkString | ||
|
||
} |
1 change: 1 addition & 0 deletions
1
test/src/main/scala/scalarules/test/duplicated_resources/child/resource.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
I am a text resource from child! |
8 changes: 8 additions & 0 deletions
8
test/src/main/scala/scalarules/test/duplicated_resources/parent/BUILD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
load("//scala:scala.bzl", "scala_library") | ||
|
||
scala_library( | ||
name = "parent", | ||
resource_strip_prefix = "test/src/main/scala/scalarules/test/duplicated_resources/parent/", | ||
resources = ["resource.txt"], | ||
visibility = ["//test/src/main/scala/scalarules/test/duplicated_resources/child:__pkg__"], | ||
) |
1 change: 1 addition & 0 deletions
1
test/src/main/scala/scalarules/test/duplicated_resources/parent/resource.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
I am a text resource from parent! |