2021-12-10 12:14:59 +01:00
|
|
|
// Copyright 2021 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package bp2build
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"android/soong/android"
|
|
|
|
"android/soong/java"
|
|
|
|
)
|
|
|
|
|
2022-06-21 21:28:33 +02:00
|
|
|
func runJavaLibraryTestCaseWithRegistrationCtxFunc(t *testing.T, tc Bp2buildTestCase, registrationCtxFunc func(ctx android.RegistrationContext)) {
|
2021-12-10 12:14:59 +01:00
|
|
|
t.Helper()
|
2022-06-21 21:28:33 +02:00
|
|
|
(&tc).ModuleTypeUnderTest = "java_library"
|
|
|
|
(&tc).ModuleTypeUnderTestFactory = java.LibraryFactory
|
|
|
|
RunBp2BuildTestCase(t, registrationCtxFunc, tc)
|
2022-03-18 15:11:07 +01:00
|
|
|
}
|
|
|
|
|
2022-06-21 21:28:33 +02:00
|
|
|
func runJavaLibraryTestCase(t *testing.T, tc Bp2buildTestCase) {
|
2022-03-15 22:02:09 +01:00
|
|
|
t.Helper()
|
2022-03-18 15:11:07 +01:00
|
|
|
runJavaLibraryTestCaseWithRegistrationCtxFunc(t, tc, func(ctx android.RegistrationContext) {})
|
2021-12-10 12:14:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestJavaLibrary(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
runJavaLibraryTestCase(t, Bp2buildTestCase{
|
|
|
|
Description: "java_library with srcs, exclude_srcs and libs",
|
|
|
|
Blueprint: `java_library {
|
2021-12-10 12:14:59 +01:00
|
|
|
name: "java-lib-1",
|
|
|
|
srcs: ["a.java", "b.java"],
|
|
|
|
exclude_srcs: ["b.java"],
|
|
|
|
libs: ["java-lib-2"],
|
2023-08-07 19:38:18 +02:00
|
|
|
sdk_version: "current",
|
2021-12-10 12:14:59 +01:00
|
|
|
bazel_module: { bp2build_available: true },
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "java-lib-2",
|
|
|
|
srcs: ["b.java"],
|
2023-08-07 19:38:18 +02:00
|
|
|
sdk_version: "current",
|
2021-12-10 12:14:59 +01:00
|
|
|
bazel_module: { bp2build_available: true },
|
|
|
|
}`,
|
2022-06-21 21:28:33 +02:00
|
|
|
ExpectedBazelTargets: []string{
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("java_library", "java-lib-1", AttrNameToString{
|
2023-08-07 19:38:18 +02:00
|
|
|
"srcs": `["a.java"]`,
|
|
|
|
"deps": `[":java-lib-2-neverlink"]`,
|
|
|
|
"sdk_version": `"current"`,
|
2021-12-10 12:14:59 +01:00
|
|
|
}),
|
2022-10-31 20:08:18 +01:00
|
|
|
MakeNeverlinkDuplicateTarget("java_library", "java-lib-1"),
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("java_library", "java-lib-2", AttrNameToString{
|
2023-08-07 19:38:18 +02:00
|
|
|
"srcs": `["b.java"]`,
|
|
|
|
"sdk_version": `"current"`,
|
2021-12-10 12:14:59 +01:00
|
|
|
}),
|
2022-10-31 20:08:18 +01:00
|
|
|
MakeNeverlinkDuplicateTarget("java_library", "java-lib-2"),
|
2021-12-10 12:14:59 +01:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
2022-02-25 22:34:51 +01:00
|
|
|
|
|
|
|
func TestJavaLibraryConvertsStaticLibsToDepsAndExports(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
runJavaLibraryTestCase(t, Bp2buildTestCase{
|
2023-09-19 03:12:48 +02:00
|
|
|
StubbedBuildDefinitions: []string{"java-lib-2", "java-lib-3"},
|
2022-06-21 21:28:33 +02:00
|
|
|
Blueprint: `java_library {
|
2022-02-25 22:34:51 +01:00
|
|
|
name: "java-lib-1",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
libs: ["java-lib-2"],
|
|
|
|
static_libs: ["java-lib-3"],
|
2023-08-07 19:38:18 +02:00
|
|
|
sdk_version: "current",
|
2022-02-25 22:34:51 +01:00
|
|
|
bazel_module: { bp2build_available: true },
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "java-lib-2",
|
|
|
|
srcs: ["b.java"],
|
2023-08-07 19:38:18 +02:00
|
|
|
sdk_version: "current",
|
2022-02-25 22:34:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "java-lib-3",
|
|
|
|
srcs: ["c.java"],
|
2023-08-07 19:38:18 +02:00
|
|
|
sdk_version: "current",
|
2022-02-25 22:34:51 +01:00
|
|
|
}`,
|
2022-06-21 21:28:33 +02:00
|
|
|
ExpectedBazelTargets: []string{
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("java_library", "java-lib-1", AttrNameToString{
|
2022-02-25 22:34:51 +01:00
|
|
|
"srcs": `["a.java"]`,
|
|
|
|
"deps": `[
|
2022-10-31 20:08:18 +01:00
|
|
|
":java-lib-2-neverlink",
|
2022-02-25 22:34:51 +01:00
|
|
|
":java-lib-3",
|
|
|
|
]`,
|
2023-08-07 19:38:18 +02:00
|
|
|
"exports": `[":java-lib-3"]`,
|
|
|
|
"sdk_version": `"current"`,
|
2022-02-25 22:34:51 +01:00
|
|
|
}),
|
2022-10-31 20:08:18 +01:00
|
|
|
MakeNeverlinkDuplicateTarget("java_library", "java-lib-1"),
|
2022-02-25 22:34:51 +01:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestJavaLibraryConvertsStaticLibsToExportsIfNoSrcs(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
runJavaLibraryTestCase(t, Bp2buildTestCase{
|
2023-09-19 03:12:48 +02:00
|
|
|
StubbedBuildDefinitions: []string{"java-lib-2"},
|
2022-06-21 21:28:33 +02:00
|
|
|
Blueprint: `java_library {
|
2022-02-25 22:34:51 +01:00
|
|
|
name: "java-lib-1",
|
|
|
|
static_libs: ["java-lib-2"],
|
2023-08-07 19:38:18 +02:00
|
|
|
sdk_version: "current",
|
2022-02-25 22:34:51 +01:00
|
|
|
bazel_module: { bp2build_available: true },
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "java-lib-2",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
}`,
|
2022-06-21 21:28:33 +02:00
|
|
|
ExpectedBazelTargets: []string{
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("java_library", "java-lib-1", AttrNameToString{
|
2023-08-07 19:38:18 +02:00
|
|
|
"exports": `[":java-lib-2"]`,
|
|
|
|
"sdk_version": `"current"`,
|
2022-02-25 22:34:51 +01:00
|
|
|
}),
|
2022-10-31 20:08:18 +01:00
|
|
|
MakeNeverlinkDuplicateTarget("java_library", "java-lib-1"),
|
2022-02-25 22:34:51 +01:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-08-07 19:38:18 +02:00
|
|
|
func TestJavaLibraryFailsToConvertNoSdkVersion(t *testing.T) {
|
|
|
|
runJavaLibraryTestCase(t, Bp2buildTestCase{
|
|
|
|
Blueprint: `
|
|
|
|
java_library {
|
|
|
|
name: "lib",
|
|
|
|
bazel_module: { bp2build_available: true },
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
ExpectedBazelTargets: []string{}, // no targets expected because sdk_version is not set
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-03-18 15:11:07 +01:00
|
|
|
func TestJavaLibraryPlugins(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
runJavaLibraryTestCaseWithRegistrationCtxFunc(t, Bp2buildTestCase{
|
2023-09-19 03:12:48 +02:00
|
|
|
StubbedBuildDefinitions: []string{"java-plugin-1"},
|
2022-06-21 21:28:33 +02:00
|
|
|
Blueprint: `java_library {
|
2022-03-18 15:11:07 +01:00
|
|
|
name: "java-lib-1",
|
|
|
|
plugins: ["java-plugin-1"],
|
2023-08-07 19:38:18 +02:00
|
|
|
sdk_version: "current",
|
2022-03-18 15:11:07 +01:00
|
|
|
bazel_module: { bp2build_available: true },
|
|
|
|
}
|
|
|
|
|
|
|
|
java_plugin {
|
|
|
|
name: "java-plugin-1",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
}`,
|
2022-06-21 21:28:33 +02:00
|
|
|
ExpectedBazelTargets: []string{
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("java_library", "java-lib-1", AttrNameToString{
|
2023-08-07 19:38:18 +02:00
|
|
|
"plugins": `[":java-plugin-1"]`,
|
|
|
|
"sdk_version": `"current"`,
|
2022-03-18 15:11:07 +01:00
|
|
|
}),
|
2022-10-31 20:08:18 +01:00
|
|
|
MakeNeverlinkDuplicateTarget("java_library", "java-lib-1"),
|
2022-03-18 15:11:07 +01:00
|
|
|
},
|
|
|
|
}, func(ctx android.RegistrationContext) {
|
|
|
|
ctx.RegisterModuleType("java_plugin", java.PluginFactory)
|
|
|
|
})
|
|
|
|
}
|
2022-03-15 22:02:09 +01:00
|
|
|
|
2022-04-23 01:09:58 +02:00
|
|
|
func TestJavaLibraryJavaVersion(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
runJavaLibraryTestCase(t, Bp2buildTestCase{
|
|
|
|
Blueprint: `java_library {
|
2022-04-23 01:09:58 +02:00
|
|
|
name: "java-lib-1",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
java_version: "11",
|
2023-08-07 19:38:18 +02:00
|
|
|
sdk_version: "current",
|
2022-04-23 01:09:58 +02:00
|
|
|
}`,
|
2022-06-21 21:28:33 +02:00
|
|
|
ExpectedBazelTargets: []string{
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("java_library", "java-lib-1", AttrNameToString{
|
2023-02-24 18:07:08 +01:00
|
|
|
"srcs": `["a.java"]`,
|
|
|
|
"java_version": `"11"`,
|
2023-08-07 19:38:18 +02:00
|
|
|
"sdk_version": `"current"`,
|
2022-04-23 01:09:58 +02:00
|
|
|
}),
|
2023-02-24 18:07:08 +01:00
|
|
|
MakeNeverlinkDuplicateTargetWithAttrs(
|
|
|
|
"java_library",
|
|
|
|
"java-lib-1",
|
2023-08-07 19:38:18 +02:00
|
|
|
AttrNameToString{
|
|
|
|
"java_version": `"11"`,
|
|
|
|
"sdk_version": `"current"`,
|
|
|
|
}),
|
2022-04-23 01:09:58 +02:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-10-06 22:47:00 +02:00
|
|
|
func TestJavaLibraryOpenjdk9(t *testing.T) {
|
|
|
|
runJavaLibraryTestCase(t, Bp2buildTestCase{
|
|
|
|
Blueprint: `java_library {
|
|
|
|
name: "java-lib-1",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
exclude_srcs: ["b.java"],
|
|
|
|
javacflags: ["flag"],
|
|
|
|
target: {
|
|
|
|
android: {
|
|
|
|
srcs: ["android.java"],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
openjdk9: {
|
|
|
|
srcs: ["b.java", "foo.java"],
|
|
|
|
javacflags: ["extraflag"],
|
|
|
|
},
|
|
|
|
sdk_version: "current",
|
|
|
|
}`,
|
|
|
|
ExpectedBazelTargets: []string{
|
|
|
|
MakeBazelTarget("java_library", "java-lib-1", AttrNameToString{
|
|
|
|
"srcs": `[
|
|
|
|
"a.java",
|
|
|
|
"foo.java",
|
|
|
|
] + select({
|
|
|
|
"//build/bazel_common_rules/platforms/os:android": ["android.java"],
|
|
|
|
"//conditions:default": [],
|
|
|
|
})`,
|
|
|
|
"sdk_version": `"current"`,
|
|
|
|
"javacopts": `[
|
|
|
|
"flag",
|
|
|
|
"extraflag",
|
|
|
|
]`,
|
|
|
|
}),
|
|
|
|
MakeNeverlinkDuplicateTarget("java_library", "java-lib-1"),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-06-20 23:00:40 +02:00
|
|
|
func TestJavaLibraryErrorproneEnabledManually(t *testing.T) {
|
|
|
|
runJavaLibraryTestCaseWithRegistrationCtxFunc(t, Bp2buildTestCase{
|
2023-09-19 03:12:48 +02:00
|
|
|
StubbedBuildDefinitions: []string{"plugin2"},
|
2022-06-21 21:28:33 +02:00
|
|
|
Blueprint: `java_library {
|
2022-03-15 22:02:09 +01:00
|
|
|
name: "java-lib-1",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
javacflags: ["-Xsuper-fast"],
|
2023-08-07 19:38:18 +02:00
|
|
|
sdk_version: "current",
|
2022-03-15 22:02:09 +01:00
|
|
|
errorprone: {
|
|
|
|
enabled: true,
|
|
|
|
javacflags: ["-Xep:SpeedLimit:OFF"],
|
2023-06-20 23:00:40 +02:00
|
|
|
extra_check_modules: ["plugin2"],
|
2022-03-15 22:02:09 +01:00
|
|
|
},
|
2023-06-20 23:00:40 +02:00
|
|
|
}
|
|
|
|
java_plugin {
|
|
|
|
name: "plugin2",
|
|
|
|
srcs: ["a.java"],
|
2022-03-15 22:02:09 +01:00
|
|
|
}`,
|
2022-06-21 21:28:33 +02:00
|
|
|
ExpectedBazelTargets: []string{
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("java_library", "java-lib-1", AttrNameToString{
|
2022-03-15 22:02:09 +01:00
|
|
|
"javacopts": `[
|
|
|
|
"-Xsuper-fast",
|
|
|
|
"-Xep:SpeedLimit:OFF",
|
|
|
|
]`,
|
2023-06-20 23:00:40 +02:00
|
|
|
"plugins": `[":plugin2"]`,
|
|
|
|
"srcs": `["a.java"]`,
|
|
|
|
"errorprone_force_enable": `True`,
|
2023-08-07 19:38:18 +02:00
|
|
|
"sdk_version": `"current"`,
|
2022-03-15 22:02:09 +01:00
|
|
|
}),
|
2022-10-31 20:08:18 +01:00
|
|
|
MakeNeverlinkDuplicateTarget("java_library", "java-lib-1"),
|
2022-03-15 22:02:09 +01:00
|
|
|
},
|
2023-06-20 23:00:40 +02:00
|
|
|
}, func(ctx android.RegistrationContext) {
|
|
|
|
ctx.RegisterModuleType("java_plugin", java.PluginFactory)
|
2022-03-15 22:02:09 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestJavaLibraryErrorproneJavacflagsErrorproneDisabledByDefault(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
runJavaLibraryTestCase(t, Bp2buildTestCase{
|
|
|
|
Blueprint: `java_library {
|
2022-03-15 22:02:09 +01:00
|
|
|
name: "java-lib-1",
|
|
|
|
srcs: ["a.java"],
|
2023-08-07 19:38:18 +02:00
|
|
|
sdk_version: "current",
|
2022-03-15 22:02:09 +01:00
|
|
|
javacflags: ["-Xsuper-fast"],
|
|
|
|
errorprone: {
|
|
|
|
javacflags: ["-Xep:SpeedLimit:OFF"],
|
|
|
|
},
|
|
|
|
}`,
|
2022-06-21 21:28:33 +02:00
|
|
|
ExpectedBazelTargets: []string{
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("java_library", "java-lib-1", AttrNameToString{
|
2023-08-07 19:38:18 +02:00
|
|
|
"javacopts": `["-Xsuper-fast"]`,
|
|
|
|
"srcs": `["a.java"]`,
|
|
|
|
"sdk_version": `"current"`,
|
2022-03-15 22:02:09 +01:00
|
|
|
}),
|
2022-10-31 20:08:18 +01:00
|
|
|
MakeNeverlinkDuplicateTarget("java_library", "java-lib-1"),
|
2022-03-15 22:02:09 +01:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-06-20 23:00:40 +02:00
|
|
|
func TestJavaLibraryErrorproneDisabledManually(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
runJavaLibraryTestCase(t, Bp2buildTestCase{
|
|
|
|
Blueprint: `java_library {
|
2022-03-15 22:02:09 +01:00
|
|
|
name: "java-lib-1",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
javacflags: ["-Xsuper-fast"],
|
2023-08-07 19:38:18 +02:00
|
|
|
sdk_version: "current",
|
2022-03-15 22:02:09 +01:00
|
|
|
errorprone: {
|
2023-06-20 23:00:40 +02:00
|
|
|
enabled: false,
|
2022-03-15 22:02:09 +01:00
|
|
|
},
|
|
|
|
}`,
|
2022-06-21 21:28:33 +02:00
|
|
|
ExpectedBazelTargets: []string{
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("java_library", "java-lib-1", AttrNameToString{
|
2023-06-20 23:00:40 +02:00
|
|
|
"javacopts": `[
|
|
|
|
"-Xsuper-fast",
|
|
|
|
"-XepDisableAllChecks",
|
|
|
|
]`,
|
2023-08-07 19:38:18 +02:00
|
|
|
"srcs": `["a.java"]`,
|
|
|
|
"sdk_version": `"current"`,
|
2022-03-15 22:02:09 +01:00
|
|
|
}),
|
2022-10-31 20:08:18 +01:00
|
|
|
MakeNeverlinkDuplicateTarget("java_library", "java-lib-1"),
|
2022-03-15 22:02:09 +01:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
2022-03-16 21:36:54 +01:00
|
|
|
|
|
|
|
func TestJavaLibraryLogTags(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
runJavaLibraryTestCase(t, Bp2buildTestCase{
|
|
|
|
Description: "Java library - logtags creates separate dependency",
|
|
|
|
ModuleTypeUnderTest: "java_library",
|
|
|
|
ModuleTypeUnderTestFactory: java.LibraryFactory,
|
|
|
|
Blueprint: `java_library {
|
2023-08-07 19:38:18 +02:00
|
|
|
name: "example_lib",
|
|
|
|
srcs: [
|
|
|
|
"a.java",
|
|
|
|
"b.java",
|
|
|
|
"a.logtag",
|
|
|
|
"b.logtag",
|
|
|
|
],
|
|
|
|
sdk_version: "current",
|
|
|
|
bazel_module: { bp2build_available: true },
|
2022-03-16 21:36:54 +01:00
|
|
|
}`,
|
2022-06-21 21:28:33 +02:00
|
|
|
ExpectedBazelTargets: []string{
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("event_log_tags", "example_lib_logtags", AttrNameToString{
|
2022-03-16 21:36:54 +01:00
|
|
|
"srcs": `[
|
|
|
|
"a.logtag",
|
|
|
|
"b.logtag",
|
|
|
|
]`,
|
|
|
|
}),
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("java_library", "example_lib", AttrNameToString{
|
2022-03-16 21:36:54 +01:00
|
|
|
"srcs": `[
|
|
|
|
"a.java",
|
|
|
|
"b.java",
|
|
|
|
":example_lib_logtags",
|
|
|
|
]`,
|
2023-08-07 19:38:18 +02:00
|
|
|
"sdk_version": `"current"`,
|
2022-03-16 21:36:54 +01:00
|
|
|
}),
|
2022-10-31 20:08:18 +01:00
|
|
|
MakeNeverlinkDuplicateTarget("java_library", "example_lib"),
|
2022-03-16 21:36:54 +01:00
|
|
|
}})
|
|
|
|
}
|
2022-03-23 21:20:42 +01:00
|
|
|
|
|
|
|
func TestJavaLibraryResources(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
runJavaLibraryTestCase(t, Bp2buildTestCase{
|
2023-05-04 20:54:45 +02:00
|
|
|
Dir: "adir",
|
2022-06-21 21:28:33 +02:00
|
|
|
Filesystem: map[string]string{
|
2023-05-04 20:54:45 +02:00
|
|
|
"adir/res/a.res": "",
|
|
|
|
"adir/res/b.res": "",
|
|
|
|
"adir/res/dir1/b.res": "",
|
|
|
|
"adir/Android.bp": `java_library {
|
2023-08-07 19:38:18 +02:00
|
|
|
name: "java-lib-1",
|
|
|
|
java_resources: ["res/a.res", "res/b.res"],
|
|
|
|
sdk_version: "current",
|
|
|
|
bazel_module: { bp2build_available: true },
|
2022-03-23 21:20:42 +01:00
|
|
|
}`,
|
2023-05-04 20:54:45 +02:00
|
|
|
},
|
|
|
|
Blueprint: "",
|
2022-06-21 21:28:33 +02:00
|
|
|
ExpectedBazelTargets: []string{
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("java_library", "java-lib-1", AttrNameToString{
|
2022-03-23 21:20:42 +01:00
|
|
|
"resources": `[
|
|
|
|
"res/a.res",
|
|
|
|
"res/b.res",
|
|
|
|
]`,
|
2023-05-04 20:54:45 +02:00
|
|
|
"resource_strip_prefix": `"adir"`,
|
2023-08-07 19:38:18 +02:00
|
|
|
"sdk_version": `"current"`,
|
2022-03-23 21:20:42 +01:00
|
|
|
}),
|
2022-10-31 20:08:18 +01:00
|
|
|
MakeNeverlinkDuplicateTarget("java_library", "java-lib-1"),
|
2022-03-23 21:20:42 +01:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestJavaLibraryResourceDirs(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
runJavaLibraryTestCase(t, Bp2buildTestCase{
|
|
|
|
Filesystem: map[string]string{
|
2022-03-23 21:20:42 +01:00
|
|
|
"res/a.res": "",
|
|
|
|
"res/b.res": "",
|
|
|
|
"res/dir1/b.res": "",
|
|
|
|
},
|
2022-06-21 21:28:33 +02:00
|
|
|
Blueprint: `java_library {
|
2023-08-07 19:38:18 +02:00
|
|
|
name: "java-lib-1",
|
2022-03-23 21:20:42 +01:00
|
|
|
java_resource_dirs: ["res"],
|
2023-08-07 19:38:18 +02:00
|
|
|
sdk_version: "current",
|
2022-03-23 21:20:42 +01:00
|
|
|
}`,
|
2022-06-21 21:28:33 +02:00
|
|
|
ExpectedBazelTargets: []string{
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("java_library", "java-lib-1", AttrNameToString{
|
2022-03-23 21:20:42 +01:00
|
|
|
"resource_strip_prefix": `"res"`,
|
|
|
|
"resources": `[
|
|
|
|
"res/a.res",
|
|
|
|
"res/b.res",
|
|
|
|
"res/dir1/b.res",
|
|
|
|
]`,
|
2023-08-07 19:38:18 +02:00
|
|
|
"sdk_version": `"current"`,
|
2022-03-23 21:20:42 +01:00
|
|
|
}),
|
2022-10-31 20:08:18 +01:00
|
|
|
MakeNeverlinkDuplicateTarget("java_library", "java-lib-1"),
|
2022-03-23 21:20:42 +01:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestJavaLibraryResourcesExcludeDir(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
runJavaLibraryTestCase(t, Bp2buildTestCase{
|
|
|
|
Filesystem: map[string]string{
|
2022-03-23 21:20:42 +01:00
|
|
|
"res/a.res": "",
|
|
|
|
"res/exclude/b.res": "",
|
|
|
|
},
|
2022-06-21 21:28:33 +02:00
|
|
|
Blueprint: `java_library {
|
2023-08-07 19:38:18 +02:00
|
|
|
name: "java-lib-1",
|
2022-03-23 21:20:42 +01:00
|
|
|
java_resource_dirs: ["res"],
|
2023-08-07 19:38:18 +02:00
|
|
|
sdk_version: "current",
|
2022-03-23 21:20:42 +01:00
|
|
|
exclude_java_resource_dirs: ["res/exclude"],
|
|
|
|
}`,
|
2022-06-21 21:28:33 +02:00
|
|
|
ExpectedBazelTargets: []string{
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("java_library", "java-lib-1", AttrNameToString{
|
2022-03-23 21:20:42 +01:00
|
|
|
"resource_strip_prefix": `"res"`,
|
|
|
|
"resources": `["res/a.res"]`,
|
2023-08-07 19:38:18 +02:00
|
|
|
"sdk_version": `"current"`,
|
2022-03-23 21:20:42 +01:00
|
|
|
}),
|
2022-10-31 20:08:18 +01:00
|
|
|
MakeNeverlinkDuplicateTarget("java_library", "java-lib-1"),
|
2022-03-23 21:20:42 +01:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestJavaLibraryResourcesExcludeFile(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
runJavaLibraryTestCase(t, Bp2buildTestCase{
|
|
|
|
Filesystem: map[string]string{
|
2022-03-23 21:20:42 +01:00
|
|
|
"res/a.res": "",
|
|
|
|
"res/dir1/b.res": "",
|
|
|
|
"res/dir1/exclude.res": "",
|
|
|
|
},
|
2022-06-21 21:28:33 +02:00
|
|
|
Blueprint: `java_library {
|
2023-08-07 19:38:18 +02:00
|
|
|
name: "java-lib-1",
|
2022-03-23 21:20:42 +01:00
|
|
|
java_resource_dirs: ["res"],
|
2023-08-07 19:38:18 +02:00
|
|
|
sdk_version: "current",
|
2022-03-23 21:20:42 +01:00
|
|
|
exclude_java_resources: ["res/dir1/exclude.res"],
|
|
|
|
}`,
|
2022-06-21 21:28:33 +02:00
|
|
|
ExpectedBazelTargets: []string{
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("java_library", "java-lib-1", AttrNameToString{
|
2022-03-23 21:20:42 +01:00
|
|
|
"resource_strip_prefix": `"res"`,
|
|
|
|
"resources": `[
|
|
|
|
"res/a.res",
|
|
|
|
"res/dir1/b.res",
|
|
|
|
]`,
|
2023-08-07 19:38:18 +02:00
|
|
|
"sdk_version": `"current"`,
|
2022-03-23 21:20:42 +01:00
|
|
|
}),
|
2022-10-31 20:08:18 +01:00
|
|
|
MakeNeverlinkDuplicateTarget("java_library", "java-lib-1"),
|
2022-03-23 21:20:42 +01:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-08-16 17:06:31 +02:00
|
|
|
func TestJavaLibraryResourcesWithMultipleDirs(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
runJavaLibraryTestCase(t, Bp2buildTestCase{
|
|
|
|
Filesystem: map[string]string{
|
2023-09-19 03:12:48 +02:00
|
|
|
"res/a.res": "",
|
|
|
|
"res1/b.res": "",
|
2022-03-23 21:20:42 +01:00
|
|
|
},
|
2022-06-21 21:28:33 +02:00
|
|
|
Blueprint: `java_library {
|
2023-08-07 19:38:18 +02:00
|
|
|
name: "java-lib-1",
|
2023-10-09 20:07:46 +02:00
|
|
|
srcs: ["foo.java"],
|
2023-09-19 03:12:48 +02:00
|
|
|
java_resource_dirs: ["res", "res1"],
|
2023-08-07 19:38:18 +02:00
|
|
|
sdk_version: "current",
|
2022-03-23 21:20:42 +01:00
|
|
|
}`,
|
2023-08-16 17:06:31 +02:00
|
|
|
ExpectedBazelTargets: []string{
|
|
|
|
MakeBazelTarget("java_resources", "java-lib-1_resource_dir_res1", AttrNameToString{
|
|
|
|
"resource_strip_prefix": `"res1"`,
|
|
|
|
"resources": `["res1/b.res"]`,
|
|
|
|
}),
|
|
|
|
MakeBazelTarget("java_library", "java-lib-1", AttrNameToString{
|
2023-10-09 20:07:46 +02:00
|
|
|
"deps": `["java-lib-1_resource_dir_res1"]`,
|
2023-08-16 17:06:31 +02:00
|
|
|
"resources": `["res/a.res"]`,
|
|
|
|
"resource_strip_prefix": `"res"`,
|
2023-10-09 20:07:46 +02:00
|
|
|
"srcs": `["foo.java"]`,
|
2023-08-07 19:38:18 +02:00
|
|
|
"sdk_version": `"current"`,
|
2023-08-16 17:06:31 +02:00
|
|
|
}),
|
|
|
|
MakeNeverlinkDuplicateTarget("java_library", "java-lib-1"),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestJavaLibraryJavaResourcesAndResourceDirs(t *testing.T) {
|
|
|
|
runJavaLibraryTestCase(t, Bp2buildTestCase{
|
|
|
|
Filesystem: map[string]string{
|
|
|
|
"resdir/a.res": "",
|
|
|
|
},
|
|
|
|
Blueprint: `java_library {
|
2023-08-07 19:38:18 +02:00
|
|
|
name: "java-lib-1",
|
|
|
|
java_resources: ["res1", "res2"],
|
|
|
|
java_resource_dirs: ["resdir"],
|
|
|
|
sdk_version: "current",
|
2023-10-09 20:07:46 +02:00
|
|
|
srcs: ["foo.java"],
|
2023-08-16 17:06:31 +02:00
|
|
|
}`,
|
|
|
|
ExpectedBazelTargets: []string{
|
|
|
|
MakeBazelTarget("java_resources", "java-lib-1_resource_dir_resdir", AttrNameToString{
|
|
|
|
"resource_strip_prefix": `"resdir"`,
|
|
|
|
"resources": `["resdir/a.res"]`,
|
|
|
|
}),
|
|
|
|
MakeBazelTarget("java_library", "java-lib-1", AttrNameToString{
|
2023-10-09 20:07:46 +02:00
|
|
|
"deps": `["java-lib-1_resource_dir_resdir"]`,
|
2023-08-16 17:06:31 +02:00
|
|
|
"resource_strip_prefix": `"."`,
|
|
|
|
"resources": `[
|
|
|
|
"res1",
|
|
|
|
"res2",
|
|
|
|
]`,
|
2023-10-09 20:07:46 +02:00
|
|
|
"srcs": `["foo.java"]`,
|
2023-08-07 19:38:18 +02:00
|
|
|
"sdk_version": `"current"`,
|
2023-08-16 17:06:31 +02:00
|
|
|
}),
|
|
|
|
MakeNeverlinkDuplicateTarget("java_library", "java-lib-1"),
|
|
|
|
},
|
2022-03-23 21:20:42 +01:00
|
|
|
})
|
|
|
|
}
|
2022-08-25 20:45:31 +02:00
|
|
|
|
|
|
|
func TestJavaLibraryAidl(t *testing.T) {
|
|
|
|
runJavaLibraryTestCase(t, Bp2buildTestCase{
|
|
|
|
Description: "Java library - aidl creates separate dependency",
|
|
|
|
ModuleTypeUnderTest: "java_library",
|
|
|
|
ModuleTypeUnderTestFactory: java.LibraryFactory,
|
|
|
|
Blueprint: `java_library {
|
2023-08-07 19:38:18 +02:00
|
|
|
name: "example_lib",
|
|
|
|
srcs: [
|
|
|
|
"a.java",
|
|
|
|
"b.java",
|
|
|
|
"a.aidl",
|
|
|
|
"b.aidl",
|
|
|
|
],
|
|
|
|
bazel_module: { bp2build_available: true },
|
|
|
|
sdk_version: "current",
|
2022-08-25 20:45:31 +02:00
|
|
|
}`,
|
|
|
|
ExpectedBazelTargets: []string{
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("aidl_library", "example_lib_aidl_library", AttrNameToString{
|
2022-08-25 20:45:31 +02:00
|
|
|
"srcs": `[
|
|
|
|
"a.aidl",
|
|
|
|
"b.aidl",
|
|
|
|
]`,
|
|
|
|
}),
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("java_aidl_library", "example_lib_java_aidl_library", AttrNameToString{
|
2022-08-25 20:45:31 +02:00
|
|
|
"deps": `[":example_lib_aidl_library"]`,
|
|
|
|
}),
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("java_library", "example_lib", AttrNameToString{
|
2022-08-25 20:45:31 +02:00
|
|
|
"deps": `[":example_lib_java_aidl_library"]`,
|
|
|
|
"exports": `[":example_lib_java_aidl_library"]`,
|
|
|
|
"srcs": `[
|
|
|
|
"a.java",
|
|
|
|
"b.java",
|
|
|
|
]`,
|
2023-08-07 19:38:18 +02:00
|
|
|
"sdk_version": `"current"`,
|
2022-08-25 20:45:31 +02:00
|
|
|
}),
|
2022-10-31 20:08:18 +01:00
|
|
|
MakeNeverlinkDuplicateTarget("java_library", "example_lib"),
|
2022-08-25 20:45:31 +02:00
|
|
|
}})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestJavaLibraryAidlSrcsNoFileGroup(t *testing.T) {
|
|
|
|
runJavaLibraryTestCaseWithRegistrationCtxFunc(t, Bp2buildTestCase{
|
|
|
|
Description: "Java library - aidl filegroup is parsed",
|
|
|
|
ModuleTypeUnderTest: "java_library",
|
|
|
|
ModuleTypeUnderTestFactory: java.LibraryFactory,
|
|
|
|
Blueprint: `
|
|
|
|
java_library {
|
2023-08-07 19:38:18 +02:00
|
|
|
name: "example_lib",
|
|
|
|
srcs: [
|
|
|
|
"a.java",
|
|
|
|
"b.aidl",
|
|
|
|
],
|
|
|
|
sdk_version: "current",
|
|
|
|
bazel_module: { bp2build_available: true },
|
2022-08-25 20:45:31 +02:00
|
|
|
}`,
|
|
|
|
ExpectedBazelTargets: []string{
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("aidl_library", "example_lib_aidl_library", AttrNameToString{
|
2022-08-25 20:45:31 +02:00
|
|
|
"srcs": `["b.aidl"]`,
|
|
|
|
}),
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("java_aidl_library", "example_lib_java_aidl_library", AttrNameToString{
|
2022-08-25 20:45:31 +02:00
|
|
|
"deps": `[":example_lib_aidl_library"]`,
|
|
|
|
}),
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("java_library", "example_lib", AttrNameToString{
|
2023-08-07 19:38:18 +02:00
|
|
|
"deps": `[":example_lib_java_aidl_library"]`,
|
|
|
|
"exports": `[":example_lib_java_aidl_library"]`,
|
|
|
|
"srcs": `["a.java"]`,
|
|
|
|
"sdk_version": `"current"`,
|
2022-08-25 20:45:31 +02:00
|
|
|
}),
|
2022-10-31 20:08:18 +01:00
|
|
|
MakeNeverlinkDuplicateTarget("java_library", "example_lib"),
|
2022-08-25 20:45:31 +02:00
|
|
|
},
|
|
|
|
}, func(ctx android.RegistrationContext) {
|
|
|
|
ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestJavaLibraryAidlFilegroup(t *testing.T) {
|
|
|
|
runJavaLibraryTestCaseWithRegistrationCtxFunc(t, Bp2buildTestCase{
|
|
|
|
Description: "Java library - aidl filegroup is parsed",
|
|
|
|
ModuleTypeUnderTest: "java_library",
|
|
|
|
ModuleTypeUnderTestFactory: java.LibraryFactory,
|
|
|
|
Blueprint: `
|
|
|
|
filegroup {
|
|
|
|
name: "random_other_files",
|
|
|
|
srcs: [
|
|
|
|
"a.java",
|
|
|
|
"b.java",
|
|
|
|
],
|
|
|
|
}
|
|
|
|
filegroup {
|
|
|
|
name: "aidl_files",
|
|
|
|
srcs: [
|
|
|
|
"a.aidl",
|
|
|
|
"b.aidl",
|
|
|
|
],
|
|
|
|
}
|
2023-09-27 20:43:45 +02:00
|
|
|
filegroup {
|
|
|
|
name: "aidls_files",
|
|
|
|
srcs: [
|
|
|
|
"a.aidl",
|
|
|
|
"b.aidl",
|
|
|
|
],
|
|
|
|
}
|
2022-08-25 20:45:31 +02:00
|
|
|
java_library {
|
2023-08-07 19:38:18 +02:00
|
|
|
name: "example_lib",
|
|
|
|
srcs: [
|
|
|
|
"a.java",
|
|
|
|
"b.java",
|
|
|
|
":aidl_files",
|
2023-09-27 20:43:45 +02:00
|
|
|
":aidls_files",
|
2023-08-07 19:38:18 +02:00
|
|
|
":random_other_files",
|
|
|
|
],
|
|
|
|
sdk_version: "current",
|
|
|
|
bazel_module: { bp2build_available: true },
|
2022-08-25 20:45:31 +02:00
|
|
|
}`,
|
|
|
|
ExpectedBazelTargets: []string{
|
|
|
|
MakeBazelTargetNoRestrictions("aidl_library", "aidl_files", AttrNameToString{
|
|
|
|
"srcs": `[
|
|
|
|
"a.aidl",
|
|
|
|
"b.aidl",
|
2023-09-27 20:43:45 +02:00
|
|
|
]`,
|
|
|
|
"tags": `["apex_available=//apex_available:anyapex"]`,
|
|
|
|
}),
|
|
|
|
MakeBazelTargetNoRestrictions("aidl_library", "aidls_files", AttrNameToString{
|
|
|
|
"srcs": `[
|
|
|
|
"a.aidl",
|
|
|
|
"b.aidl",
|
2022-08-25 20:45:31 +02:00
|
|
|
]`,
|
2023-03-23 16:51:49 +01:00
|
|
|
"tags": `["apex_available=//apex_available:anyapex"]`,
|
2022-08-25 20:45:31 +02:00
|
|
|
}),
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("java_aidl_library", "example_lib_java_aidl_library", AttrNameToString{
|
2023-09-27 20:43:45 +02:00
|
|
|
"deps": `[
|
|
|
|
":aidl_files",
|
|
|
|
":aidls_files",
|
|
|
|
]`,
|
2022-08-25 20:45:31 +02:00
|
|
|
}),
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("java_library", "example_lib", AttrNameToString{
|
2022-08-25 20:45:31 +02:00
|
|
|
"deps": `[":example_lib_java_aidl_library"]`,
|
|
|
|
"exports": `[":example_lib_java_aidl_library"]`,
|
|
|
|
"srcs": `[
|
|
|
|
"a.java",
|
|
|
|
"b.java",
|
|
|
|
":random_other_files",
|
|
|
|
]`,
|
2023-08-07 19:38:18 +02:00
|
|
|
"sdk_version": `"current"`,
|
2022-08-25 20:45:31 +02:00
|
|
|
}),
|
2022-10-31 20:08:18 +01:00
|
|
|
MakeNeverlinkDuplicateTarget("java_library", "example_lib"),
|
2022-08-25 20:45:31 +02:00
|
|
|
MakeBazelTargetNoRestrictions("filegroup", "random_other_files", AttrNameToString{
|
|
|
|
"srcs": `[
|
|
|
|
"a.java",
|
|
|
|
"b.java",
|
|
|
|
]`,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
}, func(ctx android.RegistrationContext) {
|
|
|
|
ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
|
|
|
|
})
|
|
|
|
}
|
2022-08-25 19:51:21 +02:00
|
|
|
|
|
|
|
func TestJavaLibraryAidlNonAdjacentAidlFilegroup(t *testing.T) {
|
|
|
|
runJavaLibraryTestCaseWithRegistrationCtxFunc(t, Bp2buildTestCase{
|
|
|
|
Description: "java_library with non adjacent aidl filegroup",
|
|
|
|
ModuleTypeUnderTest: "java_library",
|
|
|
|
ModuleTypeUnderTestFactory: java.LibraryFactory,
|
2023-10-05 17:47:07 +02:00
|
|
|
StubbedBuildDefinitions: []string{"//path/to/A:A_aidl"},
|
2022-08-25 19:51:21 +02:00
|
|
|
Filesystem: map[string]string{
|
|
|
|
"path/to/A/Android.bp": `
|
|
|
|
filegroup {
|
2023-08-07 19:38:18 +02:00
|
|
|
name: "A_aidl",
|
|
|
|
srcs: ["aidl/A.aidl"],
|
|
|
|
path: "aidl",
|
2022-08-25 19:51:21 +02:00
|
|
|
}`,
|
|
|
|
},
|
|
|
|
Blueprint: `
|
|
|
|
java_library {
|
2023-08-07 19:38:18 +02:00
|
|
|
name: "foo",
|
|
|
|
srcs: [
|
|
|
|
":A_aidl",
|
|
|
|
],
|
|
|
|
sdk_version: "current",
|
2022-08-25 19:51:21 +02:00
|
|
|
}`,
|
|
|
|
ExpectedBazelTargets: []string{
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("java_aidl_library", "foo_java_aidl_library", AttrNameToString{
|
2022-08-25 19:51:21 +02:00
|
|
|
"deps": `["//path/to/A:A_aidl"]`,
|
|
|
|
}),
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("java_library", "foo", AttrNameToString{
|
2023-08-07 19:38:18 +02:00
|
|
|
"exports": `[":foo_java_aidl_library"]`,
|
|
|
|
"sdk_version": `"current"`,
|
2022-08-25 19:51:21 +02:00
|
|
|
}),
|
2022-10-31 20:08:18 +01:00
|
|
|
MakeNeverlinkDuplicateTarget("java_library", "foo"),
|
2022-08-25 19:51:21 +02:00
|
|
|
},
|
|
|
|
}, func(ctx android.RegistrationContext) {
|
|
|
|
ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
|
|
|
|
})
|
|
|
|
}
|
2022-08-03 03:06:50 +02:00
|
|
|
|
|
|
|
func TestConvertArmNeonVariant(t *testing.T) {
|
|
|
|
t.Helper()
|
|
|
|
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, Bp2buildTestCase{
|
|
|
|
Description: "Android Library - simple arch feature",
|
|
|
|
ModuleTypeUnderTest: "android_library",
|
|
|
|
ModuleTypeUnderTestFactory: java.AndroidLibraryFactory,
|
2023-09-19 03:12:48 +02:00
|
|
|
Blueprint: simpleModule("android_library", "static_lib_dep") + `
|
2022-08-03 03:06:50 +02:00
|
|
|
android_library {
|
2023-08-07 19:38:18 +02:00
|
|
|
name: "TestLib",
|
|
|
|
manifest: "manifest/AndroidManifest.xml",
|
|
|
|
srcs: ["lib.java"],
|
|
|
|
sdk_version: "current",
|
|
|
|
arch: {
|
|
|
|
arm: {
|
|
|
|
neon: {
|
|
|
|
srcs: ["arm_neon.java"],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-08-03 03:06:50 +02:00
|
|
|
}
|
|
|
|
`,
|
|
|
|
ExpectedBazelTargets: []string{
|
|
|
|
MakeBazelTarget(
|
|
|
|
"android_library",
|
|
|
|
"TestLib",
|
|
|
|
AttrNameToString{
|
|
|
|
"srcs": `["lib.java"] + select({
|
|
|
|
"//build/bazel/platforms/arch/variants:arm-neon": ["arm_neon.java"],
|
|
|
|
"//conditions:default": [],
|
|
|
|
})`,
|
|
|
|
"manifest": `"manifest/AndroidManifest.xml"`,
|
|
|
|
"resource_files": `[]`,
|
2023-08-07 19:38:18 +02:00
|
|
|
"sdk_version": `"current"`, // use as default
|
2022-08-03 03:06:50 +02:00
|
|
|
}),
|
2022-10-26 22:40:18 +02:00
|
|
|
MakeNeverlinkDuplicateTarget("android_library", "TestLib"),
|
2022-08-03 03:06:50 +02:00
|
|
|
}})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConvertMultipleArchFeatures(t *testing.T) {
|
|
|
|
t.Helper()
|
|
|
|
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, Bp2buildTestCase{
|
|
|
|
Description: "Android Library - multiple arch features",
|
|
|
|
ModuleTypeUnderTest: "android_library",
|
|
|
|
ModuleTypeUnderTestFactory: java.AndroidLibraryFactory,
|
2023-09-19 03:12:48 +02:00
|
|
|
Blueprint: simpleModule("android_library", "static_lib_dep") + `
|
2022-08-03 03:06:50 +02:00
|
|
|
android_library {
|
2023-08-07 19:38:18 +02:00
|
|
|
name: "TestLib",
|
|
|
|
manifest: "manifest/AndroidManifest.xml",
|
|
|
|
srcs: ["lib.java"],
|
|
|
|
sdk_version: "current",
|
|
|
|
arch: {
|
|
|
|
x86: {
|
|
|
|
ssse3: {
|
|
|
|
srcs: ["ssse3.java"],
|
|
|
|
},
|
|
|
|
sse4_1: {
|
|
|
|
srcs: ["sse4_1.java"],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-08-03 03:06:50 +02:00
|
|
|
}
|
|
|
|
`,
|
|
|
|
ExpectedBazelTargets: []string{
|
|
|
|
MakeBazelTarget(
|
|
|
|
"android_library",
|
|
|
|
"TestLib",
|
|
|
|
AttrNameToString{
|
|
|
|
"srcs": `["lib.java"] + select({
|
|
|
|
"//build/bazel/platforms/arch/variants:x86-sse4_1": ["sse4_1.java"],
|
|
|
|
"//build/bazel/platforms/arch/variants:x86-sse4_1-ssse3": [
|
|
|
|
"sse4_1.java",
|
|
|
|
"ssse3.java",
|
|
|
|
],
|
|
|
|
"//build/bazel/platforms/arch/variants:x86-ssse3": ["ssse3.java"],
|
|
|
|
"//conditions:default": [],
|
|
|
|
})`,
|
|
|
|
"manifest": `"manifest/AndroidManifest.xml"`,
|
|
|
|
"resource_files": `[]`,
|
2023-08-07 19:38:18 +02:00
|
|
|
"sdk_version": `"current"`,
|
2022-08-03 03:06:50 +02:00
|
|
|
}),
|
2022-10-26 22:40:18 +02:00
|
|
|
MakeNeverlinkDuplicateTarget("android_library", "TestLib"),
|
2022-08-03 03:06:50 +02:00
|
|
|
}})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConvertExcludeSrcsArchFeature(t *testing.T) {
|
|
|
|
t.Helper()
|
|
|
|
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, Bp2buildTestCase{
|
|
|
|
Description: "Android Library - exclude_srcs with arch feature",
|
|
|
|
ModuleTypeUnderTest: "android_library",
|
|
|
|
ModuleTypeUnderTestFactory: java.AndroidLibraryFactory,
|
2023-09-19 03:12:48 +02:00
|
|
|
Blueprint: simpleModule("android_library", "static_lib_dep") + `
|
2022-08-03 03:06:50 +02:00
|
|
|
android_library {
|
2023-08-07 19:38:18 +02:00
|
|
|
name: "TestLib",
|
|
|
|
manifest: "manifest/AndroidManifest.xml",
|
|
|
|
srcs: ["lib.java"],
|
|
|
|
arch: {
|
|
|
|
arm: {
|
|
|
|
srcs: ["arm_non_neon.java"],
|
|
|
|
neon: {
|
|
|
|
exclude_srcs: ["arm_non_neon.java"],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
sdk_version: "current",
|
2022-08-03 03:06:50 +02:00
|
|
|
}
|
|
|
|
`,
|
|
|
|
ExpectedBazelTargets: []string{
|
|
|
|
MakeBazelTarget(
|
|
|
|
"android_library",
|
|
|
|
"TestLib",
|
|
|
|
AttrNameToString{
|
|
|
|
"srcs": `["lib.java"] + select({
|
|
|
|
"//build/bazel/platforms/arch/variants:arm-neon": [],
|
2023-10-11 12:51:28 +02:00
|
|
|
"//build/bazel_common_rules/platforms/arch:arm": ["arm_non_neon.java"],
|
2022-08-03 03:06:50 +02:00
|
|
|
"//conditions:default": [],
|
|
|
|
})`,
|
|
|
|
"manifest": `"manifest/AndroidManifest.xml"`,
|
|
|
|
"resource_files": `[]`,
|
2023-08-07 19:38:18 +02:00
|
|
|
"sdk_version": `"current"`, // use as default
|
2022-08-03 03:06:50 +02:00
|
|
|
}),
|
2022-10-26 22:40:18 +02:00
|
|
|
MakeNeverlinkDuplicateTarget("android_library", "TestLib"),
|
2022-08-03 03:06:50 +02:00
|
|
|
}})
|
|
|
|
}
|
2022-11-14 22:38:07 +01:00
|
|
|
|
|
|
|
func TestJavaLibraryKotlinSrcs(t *testing.T) {
|
|
|
|
runJavaLibraryTestCase(t, Bp2buildTestCase{
|
2023-03-06 20:43:55 +01:00
|
|
|
Description: "java_library with kotlin srcs",
|
2022-11-14 22:38:07 +01:00
|
|
|
Blueprint: `java_library {
|
|
|
|
name: "java-lib-1",
|
|
|
|
srcs: ["a.java", "b.java", "c.kt"],
|
|
|
|
bazel_module: { bp2build_available: true },
|
2023-08-07 19:38:18 +02:00
|
|
|
sdk_version: "current",
|
2022-11-14 22:38:07 +01:00
|
|
|
}
|
|
|
|
`,
|
|
|
|
ExpectedBazelTargets: []string{
|
|
|
|
MakeBazelTarget("kt_jvm_library", "java-lib-1", AttrNameToString{
|
|
|
|
"srcs": `[
|
|
|
|
"a.java",
|
|
|
|
"b.java",
|
|
|
|
"c.kt",
|
|
|
|
]`,
|
2023-08-07 19:38:18 +02:00
|
|
|
"sdk_version": `"current"`,
|
2022-11-14 22:38:07 +01:00
|
|
|
}),
|
2022-12-15 07:12:46 +01:00
|
|
|
MakeNeverlinkDuplicateTarget("kt_jvm_library", "java-lib-1"),
|
2022-11-14 22:38:07 +01:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-03-06 20:43:55 +01:00
|
|
|
func TestJavaLibraryKotlincflags(t *testing.T) {
|
|
|
|
runJavaLibraryTestCase(t, Bp2buildTestCase{
|
|
|
|
Description: "java_library with kotlincfalgs",
|
|
|
|
Blueprint: `java_library {
|
|
|
|
name: "java-lib-1",
|
|
|
|
srcs: [ "a.kt"],
|
|
|
|
kotlincflags: ["-flag1", "-flag2"],
|
|
|
|
bazel_module: { bp2build_available: true },
|
2023-08-07 19:38:18 +02:00
|
|
|
sdk_version: "current",
|
2023-03-06 20:43:55 +01:00
|
|
|
}
|
|
|
|
`,
|
|
|
|
ExpectedBazelTargets: []string{
|
|
|
|
MakeBazelTarget("kt_jvm_library", "java-lib-1", AttrNameToString{
|
|
|
|
"srcs": `["a.kt"]`,
|
|
|
|
"kotlincflags": `[
|
|
|
|
"-flag1",
|
|
|
|
"-flag2",
|
|
|
|
]`,
|
2023-08-07 19:38:18 +02:00
|
|
|
"sdk_version": `"current"`,
|
2023-03-06 20:43:55 +01:00
|
|
|
}),
|
|
|
|
MakeNeverlinkDuplicateTarget("kt_jvm_library", "java-lib-1"),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-11-14 22:38:07 +01:00
|
|
|
func TestJavaLibraryKotlinCommonSrcs(t *testing.T) {
|
|
|
|
runJavaLibraryTestCase(t, Bp2buildTestCase{
|
2023-03-06 20:43:55 +01:00
|
|
|
Description: "java_library with kotlin common_srcs",
|
2022-11-14 22:38:07 +01:00
|
|
|
Blueprint: `java_library {
|
|
|
|
name: "java-lib-1",
|
|
|
|
srcs: ["a.java", "b.java"],
|
|
|
|
common_srcs: ["c.kt"],
|
|
|
|
bazel_module: { bp2build_available: true },
|
2023-08-07 19:38:18 +02:00
|
|
|
sdk_version: "current",
|
2022-11-14 22:38:07 +01:00
|
|
|
}
|
|
|
|
`,
|
|
|
|
ExpectedBazelTargets: []string{
|
|
|
|
MakeBazelTarget("kt_jvm_library", "java-lib-1", AttrNameToString{
|
|
|
|
"srcs": `[
|
|
|
|
"a.java",
|
|
|
|
"b.java",
|
|
|
|
]`,
|
|
|
|
"common_srcs": `["c.kt"]`,
|
2023-08-07 19:38:18 +02:00
|
|
|
"sdk_version": `"current"`,
|
2022-11-14 22:38:07 +01:00
|
|
|
}),
|
2022-12-15 07:12:46 +01:00
|
|
|
MakeNeverlinkDuplicateTarget("kt_jvm_library", "java-lib-1"),
|
2022-11-14 22:38:07 +01:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
2023-01-12 19:20:32 +01:00
|
|
|
|
2023-04-04 04:53:34 +02:00
|
|
|
func TestJavaLibraryArchVariantDeps(t *testing.T) {
|
2023-01-12 19:20:32 +01:00
|
|
|
runJavaLibraryTestCase(t, Bp2buildTestCase{
|
2023-09-19 03:12:48 +02:00
|
|
|
Description: "java_library with arch variant libs",
|
|
|
|
StubbedBuildDefinitions: []string{"java-lib-2", "java-lib-3", "java-lib-4"},
|
2023-01-12 19:20:32 +01:00
|
|
|
Blueprint: `java_library {
|
|
|
|
name: "java-lib-1",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
libs: ["java-lib-2"],
|
2023-08-07 19:38:18 +02:00
|
|
|
sdk_version: "current",
|
2023-01-12 19:20:32 +01:00
|
|
|
target: {
|
|
|
|
android: {
|
|
|
|
libs: ["java-lib-3"],
|
2023-04-04 04:53:34 +02:00
|
|
|
static_libs: ["java-lib-4"],
|
2023-01-12 19:20:32 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
bazel_module: { bp2build_available: true },
|
|
|
|
}
|
|
|
|
|
2023-08-07 19:38:18 +02:00
|
|
|
java_library{
|
|
|
|
name: "java-lib-2",
|
2023-01-12 19:20:32 +01:00
|
|
|
}
|
|
|
|
|
2023-08-07 19:38:18 +02:00
|
|
|
java_library{
|
|
|
|
name: "java-lib-3",
|
2023-01-12 19:20:32 +01:00
|
|
|
}
|
2023-04-04 04:53:34 +02:00
|
|
|
|
2023-08-07 19:38:18 +02:00
|
|
|
java_library{
|
|
|
|
name: "java-lib-4",
|
2023-04-04 04:53:34 +02:00
|
|
|
}
|
2023-01-12 19:20:32 +01:00
|
|
|
`,
|
|
|
|
ExpectedBazelTargets: []string{
|
|
|
|
MakeBazelTarget("java_library", "java-lib-1", AttrNameToString{
|
|
|
|
"srcs": `["a.java"]`,
|
2023-04-04 04:53:34 +02:00
|
|
|
"exports": `select({
|
2023-10-11 12:51:28 +02:00
|
|
|
"//build/bazel_common_rules/platforms/os:android": [":java-lib-4"],
|
2023-04-04 04:53:34 +02:00
|
|
|
"//conditions:default": [],
|
|
|
|
})`,
|
2023-01-12 19:20:32 +01:00
|
|
|
"deps": `[":java-lib-2-neverlink"] + select({
|
2023-10-11 12:51:28 +02:00
|
|
|
"//build/bazel_common_rules/platforms/os:android": [
|
2023-04-04 04:53:34 +02:00
|
|
|
":java-lib-3-neverlink",
|
|
|
|
":java-lib-4",
|
|
|
|
],
|
2023-01-12 19:20:32 +01:00
|
|
|
"//conditions:default": [],
|
|
|
|
})`,
|
2023-08-07 19:38:18 +02:00
|
|
|
"sdk_version": `"current"`,
|
2023-01-12 19:20:32 +01:00
|
|
|
}),
|
|
|
|
MakeNeverlinkDuplicateTarget("java_library", "java-lib-1"),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
2023-03-08 22:34:17 +01:00
|
|
|
|
|
|
|
func TestJavaLibraryArchVariantSrcsWithExcludes(t *testing.T) {
|
|
|
|
runJavaLibraryTestCase(t, Bp2buildTestCase{
|
|
|
|
Description: "java_library with arch variant libs",
|
|
|
|
Blueprint: `java_library {
|
|
|
|
name: "java-lib-1",
|
|
|
|
srcs: ["a.java", "b.java"],
|
2023-08-07 19:38:18 +02:00
|
|
|
sdk_version: "current",
|
2023-03-08 22:34:17 +01:00
|
|
|
target: {
|
|
|
|
android: {
|
|
|
|
exclude_srcs: ["a.java"],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
bazel_module: { bp2build_available: true },
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
ExpectedBazelTargets: []string{
|
|
|
|
MakeBazelTarget("java_library", "java-lib-1", AttrNameToString{
|
|
|
|
"srcs": `["b.java"] + select({
|
2023-10-11 12:51:28 +02:00
|
|
|
"//build/bazel_common_rules/platforms/os:android": [],
|
2023-03-08 22:34:17 +01:00
|
|
|
"//conditions:default": ["a.java"],
|
|
|
|
})`,
|
2023-08-07 19:38:18 +02:00
|
|
|
"sdk_version": `"current"`,
|
2023-03-08 22:34:17 +01:00
|
|
|
}),
|
|
|
|
MakeNeverlinkDuplicateTarget("java_library", "java-lib-1"),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
2023-05-09 22:37:49 +02:00
|
|
|
|
|
|
|
func TestJavaLibraryJavaResourcesSingleFilegroup(t *testing.T) {
|
|
|
|
runJavaLibraryTestCaseWithRegistrationCtxFunc(t, Bp2buildTestCase{
|
|
|
|
Filesystem: map[string]string{
|
|
|
|
"res/a.res": "",
|
|
|
|
"res/b.res": "",
|
|
|
|
"res/dir1/b.res": "",
|
|
|
|
},
|
|
|
|
Description: "java_library",
|
|
|
|
Blueprint: `java_library {
|
|
|
|
name: "java-lib-1",
|
|
|
|
srcs: ["a.java"],
|
2023-08-07 19:38:18 +02:00
|
|
|
sdk_version: "current",
|
2023-05-09 22:37:49 +02:00
|
|
|
java_resources: [":filegroup1"],
|
|
|
|
bazel_module: { bp2build_available: true },
|
|
|
|
}
|
|
|
|
|
|
|
|
filegroup {
|
|
|
|
name: "filegroup1",
|
|
|
|
path: "foo",
|
|
|
|
srcs: ["foo/a", "foo/b"],
|
|
|
|
}
|
|
|
|
|
|
|
|
`,
|
|
|
|
ExpectedBazelTargets: []string{
|
|
|
|
MakeBazelTarget("java_library", "java-lib-1", AttrNameToString{
|
|
|
|
"srcs": `["a.java"]`,
|
|
|
|
"resources": `[":filegroup1"]`,
|
|
|
|
"resource_strip_prefix": `"foo"`,
|
2023-08-07 19:38:18 +02:00
|
|
|
"sdk_version": `"current"`,
|
2023-05-09 22:37:49 +02:00
|
|
|
}),
|
|
|
|
MakeNeverlinkDuplicateTarget("java_library", "java-lib-1"),
|
|
|
|
MakeBazelTargetNoRestrictions("filegroup", "filegroup1", AttrNameToString{
|
|
|
|
"srcs": `[
|
|
|
|
"foo/a",
|
|
|
|
"foo/b",
|
|
|
|
]`}),
|
|
|
|
},
|
|
|
|
}, func(ctx android.RegistrationContext) {
|
|
|
|
ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
|
|
|
|
})
|
|
|
|
}
|
2023-08-16 17:06:31 +02:00
|
|
|
|
|
|
|
func TestJavaLibraryJavaResourcesMultipleFilegroup(t *testing.T) {
|
|
|
|
runJavaLibraryTestCaseWithRegistrationCtxFunc(t, Bp2buildTestCase{
|
|
|
|
Filesystem: map[string]string{
|
|
|
|
"a.res": "",
|
|
|
|
},
|
|
|
|
Description: "with java_resources that has multiple filegroups",
|
|
|
|
Blueprint: `java_library {
|
|
|
|
name: "java-lib-1",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
java_resources: ["a.res", ":filegroup1", ":filegroup2"],
|
2023-08-07 19:38:18 +02:00
|
|
|
sdk_version: "current",
|
2023-08-16 17:06:31 +02:00
|
|
|
bazel_module: { bp2build_available: true },
|
|
|
|
}
|
|
|
|
|
|
|
|
filegroup {
|
|
|
|
name: "filegroup1",
|
|
|
|
path: "foo",
|
|
|
|
srcs: ["foo/a"],
|
|
|
|
}
|
|
|
|
|
|
|
|
filegroup {
|
|
|
|
name: "filegroup2",
|
|
|
|
path: "bar",
|
|
|
|
srcs: ["bar/a"],
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
ExpectedBazelTargets: []string{
|
|
|
|
MakeBazelTarget("java_resources", "java-lib-1_filegroup_resources_filegroup1", AttrNameToString{
|
|
|
|
"resource_strip_prefix": `"foo"`,
|
|
|
|
"resources": `[":filegroup1"]`,
|
|
|
|
}),
|
|
|
|
MakeBazelTarget("java_resources", "java-lib-1_filegroup_resources_filegroup2", AttrNameToString{
|
|
|
|
"resource_strip_prefix": `"bar"`,
|
|
|
|
"resources": `[":filegroup2"]`,
|
|
|
|
}),
|
|
|
|
MakeBazelTarget("java_library", "java-lib-1", AttrNameToString{
|
|
|
|
"srcs": `["a.java"]`,
|
|
|
|
"resources": `["a.res"]`,
|
|
|
|
"resource_strip_prefix": `"."`,
|
2023-10-09 20:07:46 +02:00
|
|
|
"deps": `[
|
2023-08-16 17:06:31 +02:00
|
|
|
"java-lib-1_filegroup_resources_filegroup1",
|
|
|
|
"java-lib-1_filegroup_resources_filegroup2",
|
|
|
|
]`,
|
2023-08-07 19:38:18 +02:00
|
|
|
"sdk_version": `"current"`,
|
2023-08-16 17:06:31 +02:00
|
|
|
}),
|
|
|
|
MakeNeverlinkDuplicateTarget("java_library", "java-lib-1"),
|
|
|
|
MakeBazelTargetNoRestrictions("filegroup", "filegroup1", AttrNameToString{
|
|
|
|
"srcs": `["foo/a"]`}),
|
|
|
|
MakeBazelTargetNoRestrictions("filegroup", "filegroup2", AttrNameToString{
|
|
|
|
"srcs": `["bar/a"]`}),
|
|
|
|
},
|
|
|
|
}, func(ctx android.RegistrationContext) {
|
|
|
|
ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
|
|
|
|
})
|
|
|
|
}
|
2023-10-06 20:25:06 +02:00
|
|
|
|
|
|
|
func TestJavaLibrarySameNameAsPrebuilt(t *testing.T) {
|
|
|
|
runJavaLibraryTestCaseWithRegistrationCtxFunc(t, Bp2buildTestCase{
|
|
|
|
Description: "java_library and prebuilt module have the same name",
|
|
|
|
Filesystem: map[string]string{
|
|
|
|
"foo/bar/Android.bp": simpleModule("java_import", "test_lib"),
|
|
|
|
},
|
|
|
|
Blueprint: `java_library {
|
|
|
|
name: "test_lib",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
sdk_version: "current",
|
|
|
|
bazel_module: { bp2build_available: true },
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
ExpectedBazelTargets: []string{
|
|
|
|
MakeBazelTarget("java_library", "test_lib", AttrNameToString{
|
|
|
|
"srcs": `["a.java"]`,
|
|
|
|
"sdk_version": `"current"`,
|
|
|
|
}),
|
|
|
|
MakeNeverlinkDuplicateTarget("java_library", "test_lib"),
|
|
|
|
},
|
|
|
|
}, func(ctx android.RegistrationContext) {
|
|
|
|
ctx.RegisterModuleType("java_import", java.ImportFactory)
|
|
|
|
})
|
|
|
|
}
|