Provide a resource_prefix_strip for java_resources in bp2build.

Although paths to resource files in a Bazel java_library should be
relative to the package, the directory structure in the resulting jar
will have resources under the full path from the top-level of the
workspace, e.g. if a library in "a/BUILD" has java_resouces as
"res/res.txt" then by default the res.txt file would appear under
"a/res/res.txt".
Fix this by adding a resource_strip_prefix in that case.

Test: Unit tests
Change-Id: If4325126f5c19a2a8fb83ee09bc3a95a18673fe3
This commit is contained in:
Romain Jobredeaux
2023-05-04 14:54:45 -04:00
parent 30208863b4
commit d5fe133077
3 changed files with 24 additions and 11 deletions

View File

@@ -259,17 +259,20 @@ func TestJavaBinaryHostKotlinWithResources(t *testing.T) {
runJavaBinaryHostTestCase(t, Bp2buildTestCase{
Description: "java_binary_host with srcs, libs, resources.",
Filesystem: map[string]string{
"test.mf": "Main-Class: com.android.test.MainClass",
"res/a.res": "",
"res/b.res": "",
},
Blueprint: `java_binary_host {
"adir/test.mf": "Main-Class: com.android.test.MainClass",
"adir/res/a.res": "",
"adir/res/b.res": "",
"adir/Android.bp": `java_binary_host {
name: "java-binary-host",
manifest: "test.mf",
srcs: ["a.java", "b.kt"],
java_resources: ["res/a.res", "res/b.res"],
bazel_module: { bp2build_available: true },
}
`,
},
Dir: "adir",
Blueprint: "",
ExpectedBazelTargets: []string{
MakeBazelTarget("kt_jvm_library", "java-binary-host_lib", AttrNameToString{
"srcs": `[
@@ -280,6 +283,7 @@ func TestJavaBinaryHostKotlinWithResources(t *testing.T) {
"res/a.res",
"res/b.res",
]`,
"resource_strip_prefix": `"adir"`,
"target_compatible_with": `select({
"//build/bazel/platforms/os:android": ["@platforms//:incompatible"],
"//conditions:default": [],