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:
@@ -259,17 +259,20 @@ func TestJavaBinaryHostKotlinWithResources(t *testing.T) {
|
|||||||
runJavaBinaryHostTestCase(t, Bp2buildTestCase{
|
runJavaBinaryHostTestCase(t, Bp2buildTestCase{
|
||||||
Description: "java_binary_host with srcs, libs, resources.",
|
Description: "java_binary_host with srcs, libs, resources.",
|
||||||
Filesystem: map[string]string{
|
Filesystem: map[string]string{
|
||||||
"test.mf": "Main-Class: com.android.test.MainClass",
|
"adir/test.mf": "Main-Class: com.android.test.MainClass",
|
||||||
"res/a.res": "",
|
"adir/res/a.res": "",
|
||||||
"res/b.res": "",
|
"adir/res/b.res": "",
|
||||||
},
|
"adir/Android.bp": `java_binary_host {
|
||||||
Blueprint: `java_binary_host {
|
|
||||||
name: "java-binary-host",
|
name: "java-binary-host",
|
||||||
manifest: "test.mf",
|
manifest: "test.mf",
|
||||||
srcs: ["a.java", "b.kt"],
|
srcs: ["a.java", "b.kt"],
|
||||||
java_resources: ["res/a.res", "res/b.res"],
|
java_resources: ["res/a.res", "res/b.res"],
|
||||||
|
bazel_module: { bp2build_available: true },
|
||||||
}
|
}
|
||||||
`,
|
`,
|
||||||
|
},
|
||||||
|
Dir: "adir",
|
||||||
|
Blueprint: "",
|
||||||
ExpectedBazelTargets: []string{
|
ExpectedBazelTargets: []string{
|
||||||
MakeBazelTarget("kt_jvm_library", "java-binary-host_lib", AttrNameToString{
|
MakeBazelTarget("kt_jvm_library", "java-binary-host_lib", AttrNameToString{
|
||||||
"srcs": `[
|
"srcs": `[
|
||||||
@@ -280,6 +283,7 @@ func TestJavaBinaryHostKotlinWithResources(t *testing.T) {
|
|||||||
"res/a.res",
|
"res/a.res",
|
||||||
"res/b.res",
|
"res/b.res",
|
||||||
]`,
|
]`,
|
||||||
|
"resource_strip_prefix": `"adir"`,
|
||||||
"target_compatible_with": `select({
|
"target_compatible_with": `select({
|
||||||
"//build/bazel/platforms/os:android": ["@platforms//:incompatible"],
|
"//build/bazel/platforms/os:android": ["@platforms//:incompatible"],
|
||||||
"//conditions:default": [],
|
"//conditions:default": [],
|
||||||
|
@@ -283,21 +283,25 @@ func TestJavaLibraryLogTags(t *testing.T) {
|
|||||||
|
|
||||||
func TestJavaLibraryResources(t *testing.T) {
|
func TestJavaLibraryResources(t *testing.T) {
|
||||||
runJavaLibraryTestCase(t, Bp2buildTestCase{
|
runJavaLibraryTestCase(t, Bp2buildTestCase{
|
||||||
|
Dir: "adir",
|
||||||
Filesystem: map[string]string{
|
Filesystem: map[string]string{
|
||||||
"res/a.res": "",
|
"adir/res/a.res": "",
|
||||||
"res/b.res": "",
|
"adir/res/b.res": "",
|
||||||
"res/dir1/b.res": "",
|
"adir/res/dir1/b.res": "",
|
||||||
},
|
"adir/Android.bp": `java_library {
|
||||||
Blueprint: `java_library {
|
|
||||||
name: "java-lib-1",
|
name: "java-lib-1",
|
||||||
java_resources: ["res/a.res", "res/b.res"],
|
java_resources: ["res/a.res", "res/b.res"],
|
||||||
|
bazel_module: { bp2build_available: true },
|
||||||
}`,
|
}`,
|
||||||
|
},
|
||||||
|
Blueprint: "",
|
||||||
ExpectedBazelTargets: []string{
|
ExpectedBazelTargets: []string{
|
||||||
MakeBazelTarget("java_library", "java-lib-1", AttrNameToString{
|
MakeBazelTarget("java_library", "java-lib-1", AttrNameToString{
|
||||||
"resources": `[
|
"resources": `[
|
||||||
"res/a.res",
|
"res/a.res",
|
||||||
"res/b.res",
|
"res/b.res",
|
||||||
]`,
|
]`,
|
||||||
|
"resource_strip_prefix": `"adir"`,
|
||||||
}),
|
}),
|
||||||
MakeNeverlinkDuplicateTarget("java_library", "java-lib-1"),
|
MakeNeverlinkDuplicateTarget("java_library", "java-lib-1"),
|
||||||
},
|
},
|
||||||
|
@@ -2707,8 +2707,13 @@ func (m *Library) convertJavaResourcesAttributes(ctx android.TopDownMutatorConte
|
|||||||
var resources bazel.LabelList
|
var resources bazel.LabelList
|
||||||
var resourceStripPrefix *string
|
var resourceStripPrefix *string
|
||||||
|
|
||||||
|
if m.properties.Java_resources != nil && len(m.properties.Java_resource_dirs) > 0 {
|
||||||
|
ctx.ModuleErrorf("bp2build doesn't support both java_resources and java_resource_dirs being set on the same module.")
|
||||||
|
}
|
||||||
|
|
||||||
if m.properties.Java_resources != nil {
|
if m.properties.Java_resources != nil {
|
||||||
resources.Append(android.BazelLabelForModuleSrc(ctx, m.properties.Java_resources))
|
resources.Append(android.BazelLabelForModuleSrc(ctx, m.properties.Java_resources))
|
||||||
|
resourceStripPrefix = proptools.StringPtr(ctx.ModuleDir())
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO(b/179889880) handle case where glob includes files outside package
|
//TODO(b/179889880) handle case where glob includes files outside package
|
||||||
|
Reference in New Issue
Block a user