Merge "bp2build kotlinCFlags"
This commit is contained in:
@@ -699,6 +699,11 @@ var (
|
|||||||
|
|
||||||
// for api_fingerprint.txt generation
|
// for api_fingerprint.txt generation
|
||||||
"api_fingerprint",
|
"api_fingerprint",
|
||||||
|
|
||||||
|
// allowlisting for kotlinx_coroutines
|
||||||
|
"kotlinx_coroutines",
|
||||||
|
"annotations",
|
||||||
|
"kotlinx-coroutines-android-annotation-stubs",
|
||||||
}
|
}
|
||||||
|
|
||||||
Bp2buildModuleTypeAlwaysConvertList = []string{
|
Bp2buildModuleTypeAlwaysConvertList = []string{
|
||||||
|
@@ -171,3 +171,39 @@ android_library {
|
|||||||
MakeNeverlinkDuplicateTarget("android_library", "TestLib"),
|
MakeNeverlinkDuplicateTarget("android_library", "TestLib"),
|
||||||
}})
|
}})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestConvertAndroidLibraryKotlinCflags(t *testing.T) {
|
||||||
|
t.Helper()
|
||||||
|
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, Bp2buildTestCase{
|
||||||
|
Description: "Android Library with .kt srcs and kotlincflags ",
|
||||||
|
ModuleTypeUnderTest: "android_library",
|
||||||
|
ModuleTypeUnderTestFactory: java.AndroidLibraryFactory,
|
||||||
|
Filesystem: map[string]string{
|
||||||
|
"AndroidManifest.xml": "",
|
||||||
|
},
|
||||||
|
Blueprint: `
|
||||||
|
android_library {
|
||||||
|
name: "TestLib",
|
||||||
|
srcs: ["a.java", "b.kt"],
|
||||||
|
kotlincflags: ["-flag1", "-flag2"],
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
ExpectedBazelTargets: []string{
|
||||||
|
MakeBazelTarget(
|
||||||
|
"android_library",
|
||||||
|
"TestLib",
|
||||||
|
AttrNameToString{
|
||||||
|
"srcs": `[
|
||||||
|
"a.java",
|
||||||
|
"b.kt",
|
||||||
|
]`,
|
||||||
|
"kotlincflags": `[
|
||||||
|
"-flag1",
|
||||||
|
"-flag2",
|
||||||
|
]`,
|
||||||
|
"manifest": `"AndroidManifest.xml"`,
|
||||||
|
"resource_files": `[]`,
|
||||||
|
}),
|
||||||
|
MakeNeverlinkDuplicateTarget("android_library", "TestLib"),
|
||||||
|
}})
|
||||||
|
}
|
||||||
|
@@ -306,3 +306,41 @@ java_library{
|
|||||||
}),
|
}),
|
||||||
}})
|
}})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAndroidAppKotlinCflags(t *testing.T) {
|
||||||
|
runAndroidAppTestCase(t, Bp2buildTestCase{
|
||||||
|
Description: "Android app with kotlincflags",
|
||||||
|
ModuleTypeUnderTest: "android_app",
|
||||||
|
ModuleTypeUnderTestFactory: java.AndroidAppFactory,
|
||||||
|
Filesystem: map[string]string{
|
||||||
|
"res/res.png": "",
|
||||||
|
},
|
||||||
|
Blueprint: simpleModuleDoNotConvertBp2build("filegroup", "foocert") + `
|
||||||
|
android_app {
|
||||||
|
name: "foo",
|
||||||
|
srcs: ["a.java", "b.kt"],
|
||||||
|
certificate: ":foocert",
|
||||||
|
manifest: "fooManifest.xml",
|
||||||
|
kotlincflags: ["-flag1", "-flag2"],
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
ExpectedBazelTargets: []string{
|
||||||
|
MakeBazelTarget("android_library", "foo_kt", AttrNameToString{
|
||||||
|
"srcs": `[
|
||||||
|
"a.java",
|
||||||
|
"b.kt",
|
||||||
|
]`,
|
||||||
|
"manifest": `"fooManifest.xml"`,
|
||||||
|
"resource_files": `["res/res.png"]`,
|
||||||
|
"kotlincflags": `[
|
||||||
|
"-flag1",
|
||||||
|
"-flag2",
|
||||||
|
]`,
|
||||||
|
}),
|
||||||
|
MakeBazelTarget("android_binary", "foo", AttrNameToString{
|
||||||
|
"deps": `[":foo_kt"]`,
|
||||||
|
"certificate": `":foocert"`,
|
||||||
|
"manifest": `"fooManifest.xml"`,
|
||||||
|
}),
|
||||||
|
}})
|
||||||
|
}
|
||||||
|
@@ -284,3 +284,38 @@ func TestJavaBinaryHostKotlinWithResources(t *testing.T) {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestJavaBinaryHostKotlinCflags(t *testing.T) {
|
||||||
|
runJavaBinaryHostTestCase(t, Bp2buildTestCase{
|
||||||
|
Description: "java_binary_host with kotlincflags",
|
||||||
|
Filesystem: testFs,
|
||||||
|
Blueprint: `java_binary_host {
|
||||||
|
name: "java-binary-host",
|
||||||
|
manifest: "test.mf",
|
||||||
|
srcs: ["a.kt"],
|
||||||
|
kotlincflags: ["-flag1", "-flag2"],
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
ExpectedBazelTargets: []string{
|
||||||
|
MakeBazelTarget("kt_jvm_library", "java-binary-host_kt", AttrNameToString{
|
||||||
|
"srcs": `["a.kt"]`,
|
||||||
|
"kotlincflags": `[
|
||||||
|
"-flag1",
|
||||||
|
"-flag2",
|
||||||
|
]`,
|
||||||
|
"target_compatible_with": `select({
|
||||||
|
"//build/bazel/platforms/os:android": ["@platforms//:incompatible"],
|
||||||
|
"//conditions:default": [],
|
||||||
|
})`,
|
||||||
|
}),
|
||||||
|
MakeBazelTarget("java_binary", "java-binary-host", AttrNameToString{
|
||||||
|
"main_class": `"com.android.test.MainClass"`,
|
||||||
|
"runtime_deps": `[":java-binary-host_kt"]`,
|
||||||
|
"target_compatible_with": `select({
|
||||||
|
"//build/bazel/platforms/os:android": ["@platforms//:incompatible"],
|
||||||
|
"//conditions:default": [],
|
||||||
|
})`,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
@@ -673,7 +673,7 @@ android_library {
|
|||||||
|
|
||||||
func TestJavaLibraryKotlinSrcs(t *testing.T) {
|
func TestJavaLibraryKotlinSrcs(t *testing.T) {
|
||||||
runJavaLibraryTestCase(t, Bp2buildTestCase{
|
runJavaLibraryTestCase(t, Bp2buildTestCase{
|
||||||
Description: "java_library with kotlin srcs",
|
Description: "java_library with kotlin srcs",
|
||||||
Blueprint: `java_library {
|
Blueprint: `java_library {
|
||||||
name: "java-lib-1",
|
name: "java-lib-1",
|
||||||
srcs: ["a.java", "b.java", "c.kt"],
|
srcs: ["a.java", "b.java", "c.kt"],
|
||||||
@@ -693,9 +693,32 @@ func TestJavaLibraryKotlinSrcs(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 },
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
ExpectedBazelTargets: []string{
|
||||||
|
MakeBazelTarget("kt_jvm_library", "java-lib-1", AttrNameToString{
|
||||||
|
"srcs": `["a.kt"]`,
|
||||||
|
"kotlincflags": `[
|
||||||
|
"-flag1",
|
||||||
|
"-flag2",
|
||||||
|
]`,
|
||||||
|
}),
|
||||||
|
MakeNeverlinkDuplicateTarget("kt_jvm_library", "java-lib-1"),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func TestJavaLibraryKotlinCommonSrcs(t *testing.T) {
|
func TestJavaLibraryKotlinCommonSrcs(t *testing.T) {
|
||||||
runJavaLibraryTestCase(t, Bp2buildTestCase{
|
runJavaLibraryTestCase(t, Bp2buildTestCase{
|
||||||
Description: "java_library with kotlin common_srcs",
|
Description: "java_library with kotlin common_srcs",
|
||||||
Blueprint: `java_library {
|
Blueprint: `java_library {
|
||||||
name: "java-lib-1",
|
name: "java-lib-1",
|
||||||
srcs: ["a.java", "b.java"],
|
srcs: ["a.java", "b.java"],
|
||||||
|
10
java/java.go
10
java/java.go
@@ -2787,11 +2787,12 @@ func (m *Library) convertLibraryAttrsBp2Build(ctx android.TopDownMutatorContext)
|
|||||||
depLabels.StaticDeps = bazel.MakeLabelListAttribute(staticDeps)
|
depLabels.StaticDeps = bazel.MakeLabelListAttribute(staticDeps)
|
||||||
|
|
||||||
hasKotlin := !kotlinSrcs.IsEmpty()
|
hasKotlin := !kotlinSrcs.IsEmpty()
|
||||||
|
commonAttrs.kotlinAttributes = &kotlinAttributes{
|
||||||
|
Kotlincflags: &m.properties.Kotlincflags,
|
||||||
|
}
|
||||||
if len(m.properties.Common_srcs) != 0 {
|
if len(m.properties.Common_srcs) != 0 {
|
||||||
hasKotlin = true
|
hasKotlin = true
|
||||||
commonAttrs.kotlinAttributes = &kotlinAttributes{
|
commonAttrs.kotlinAttributes.Common_srcs = bazel.MakeLabelListAttribute(android.BazelLabelForModuleSrc(ctx, m.properties.Common_srcs))
|
||||||
bazel.MakeLabelListAttribute(android.BazelLabelForModuleSrc(ctx, m.properties.Common_srcs)),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bp2BuildInfo := &bp2BuildJavaInfo{
|
bp2BuildInfo := &bp2BuildJavaInfo{
|
||||||
@@ -2810,7 +2811,8 @@ type javaLibraryAttributes struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type kotlinAttributes struct {
|
type kotlinAttributes struct {
|
||||||
Common_srcs bazel.LabelListAttribute
|
Common_srcs bazel.LabelListAttribute
|
||||||
|
Kotlincflags *[]string
|
||||||
}
|
}
|
||||||
|
|
||||||
func javaLibraryBp2Build(ctx android.TopDownMutatorContext, m *Library) {
|
func javaLibraryBp2Build(ctx android.TopDownMutatorContext, m *Library) {
|
||||||
|
Reference in New Issue
Block a user