Remove ConvertWithBp2build implementations

Remove the ConvertWithBp2build implementations from all the module
types, along with the related code.

Bug: 315353489
Test: m blueprint_tests
Change-Id: I212672286686a318893bc7348ddd5a5ec51e77a7
This commit is contained in:
Colin Cross
2023-12-07 13:10:56 -08:00
parent e51c6e4109
commit 8ff105860d
168 changed files with 64 additions and 39712 deletions

View File

@@ -40,64 +40,8 @@ bootstrap_go_package {
"soong-ui-metrics",
],
testSrcs: [
"go_conversion_test.go",
"aar_conversion_test.go",
"aconfig_conversion_test.go",
"aidl_library_conversion_test.go",
"android_app_certificate_conversion_test.go",
"android_app_conversion_test.go",
"android_test_conversion_test.go",
"apex_conversion_test.go",
"apex_key_conversion_test.go",
"build_conversion_test.go",
"bp2build_product_config_test.go",
"bzl_conversion_test.go",
"cc_binary_conversion_test.go",
"cc_library_conversion_test.go",
"cc_library_headers_conversion_test.go",
"cc_library_shared_conversion_test.go",
"cc_library_static_conversion_test.go",
"cc_object_conversion_test.go",
"cc_prebuilt_library_conversion_test.go",
"cc_prebuilt_library_shared_test.go",
"cc_prebuilt_library_static_test.go",
"cc_prebuilt_object_conversion_test.go",
"cc_test_conversion_test.go",
"cc_yasm_conversion_test.go",
"conversion_test.go",
"droiddoc_exported_dir_conversion_test.go",
"fdo_profile_conversion_test.go",
"filegroup_conversion_test.go",
"genrule_conversion_test.go",
"gensrcs_conversion_test.go",
"java_binary_host_conversion_test.go",
"java_host_for_device_conversion_test.go",
"java_import_conversion_test.go",
"java_library_conversion_test.go",
"java_library_host_conversion_test.go",
"java_plugin_conversion_test.go",
"java_proto_conversion_test.go",
"java_sdk_library_conversion_test.go",
"java_sdk_library_import_conversion_test.go",
"java_test_host_conversion_test.go",
"license_conversion_test.go",
"license_kind_conversion_test.go",
"linker_config_conversion_test.go",
"package_conversion_test.go",
"performance_test.go",
"platform_compat_config_conversion_test.go",
"prebuilt_etc_conversion_test.go",
"python_binary_conversion_test.go",
"python_library_conversion_test.go",
"python_test_conversion_test.go",
"rust_binary_conversion_test.go",
"rust_ffi_conversion_test.go",
"rust_library_conversion_test.go",
"rust_proc_macro_conversion_test.go",
"rust_protobuf_conversion_test.go",
"sh_conversion_test.go",
"sh_test_conversion_test.go",
"soong_config_module_type_conversion_test.go",
],
pluginFor: [
"soong_build",

View File

@@ -1,249 +0,0 @@
// Copyright 2022 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"
)
func runAndroidLibraryImportTestWithRegistrationCtxFunc(t *testing.T, registrationCtxFunc func(ctx android.RegistrationContext), tc Bp2buildTestCase) {
t.Helper()
(&tc).ModuleTypeUnderTest = "android_library_import"
(&tc).ModuleTypeUnderTestFactory = java.AARImportFactory
RunBp2BuildTestCase(t, registrationCtxFunc, tc)
}
func runAndroidLibraryImportTest(t *testing.T, tc Bp2buildTestCase) {
runAndroidLibraryImportTestWithRegistrationCtxFunc(t, func(ctx android.RegistrationContext) {}, tc)
}
func TestConvertAndroidLibrary(t *testing.T) {
t.Helper()
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, Bp2buildTestCase{
Description: "Android Library - simple example",
ModuleTypeUnderTest: "android_library",
ModuleTypeUnderTestFactory: java.AndroidLibraryFactory,
Filesystem: map[string]string{
"lib.java": "",
"arm.java": "",
"x86.java": "",
"res/res.png": "",
"manifest/AndroidManifest.xml": "",
},
StubbedBuildDefinitions: []string{"static_lib_dep"},
Blueprint: simpleModule("android_library", "static_lib_dep") + `
android_library {
name: "TestLib",
srcs: ["lib.java"],
arch: {
arm: {
srcs: ["arm.java"],
},
x86: {
srcs: ["x86.java"],
}
},
manifest: "manifest/AndroidManifest.xml",
static_libs: ["static_lib_dep"],
sdk_version: "current",
}
`,
ExpectedBazelTargets: []string{
MakeBazelTarget(
"android_library",
"TestLib",
AttrNameToString{
"srcs": `["lib.java"] + select({
"//build/bazel_common_rules/platforms/arch:arm": ["arm.java"],
"//build/bazel_common_rules/platforms/arch:x86": ["x86.java"],
"//conditions:default": [],
})`,
"manifest": `"manifest/AndroidManifest.xml"`,
"resource_files": `["res/res.png"]`,
"deps": `[":static_lib_dep"]`,
"exports": `[":static_lib_dep"]`,
"sdk_version": `"current"`, // use as default
}),
MakeNeverlinkDuplicateTarget("android_library", "TestLib"),
}})
}
func TestConvertAndroidLibraryWithNoSources(t *testing.T) {
t.Helper()
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, Bp2buildTestCase{
Description: "Android Library - modules will deps when there are no sources",
ModuleTypeUnderTest: "android_library",
ModuleTypeUnderTestFactory: java.AndroidLibraryFactory,
Filesystem: map[string]string{
"res/res.png": "",
"AndroidManifest.xml": "",
},
Blueprint: simpleModule("android_library", "lib_dep") + `
android_library {
name: "TestLib",
srcs: [],
manifest: "AndroidManifest.xml",
libs: ["lib_dep"],
sdk_version: "current",
}
`,
StubbedBuildDefinitions: []string{"lib_dep"},
ExpectedBazelTargets: []string{
MakeBazelTarget(
"android_library",
"TestLib",
AttrNameToString{
"manifest": `"AndroidManifest.xml"`,
"resource_files": `["res/res.png"]`,
"sdk_version": `"current"`, // use as default
},
),
MakeNeverlinkDuplicateTarget("android_library", "TestLib"),
},
})
}
func TestConvertAndroidLibraryImport(t *testing.T) {
runAndroidLibraryImportTestWithRegistrationCtxFunc(t,
func(ctx android.RegistrationContext) {
ctx.RegisterModuleType("android_library", java.AndroidLibraryFactory)
},
Bp2buildTestCase{
Description: "Android Library Import",
StubbedBuildDefinitions: []string{"static_lib_dep", "static_import_dep", "static_import_dep-neverlink"},
// Bazel's aar_import can only export *_import targets, so we expect
// only "static_import_dep" in exports, but both "static_lib_dep" and
// "static_import_dep" in deps
Blueprint: simpleModule("android_library", "static_lib_dep") + `
android_library_import {
name: "TestImport",
aars: ["import.aar"],
static_libs: ["static_lib_dep", "static_import_dep"],
sdk_version: "current",
}
android_library_import {
name: "static_import_dep",
aars: ["import.aar"],
}
`,
ExpectedBazelTargets: []string{
MakeBazelTarget(
"aar_import",
"TestImport",
AttrNameToString{
"aar": `"import.aar"`,
"deps": `[
":static_lib_dep",
":static_import_dep",
]`,
"exports": `[":static_import_dep"]`,
"sdk_version": `"current"`, // use as default
},
),
MakeNeverlinkDuplicateTarget("android_library", "TestImport"),
},
},
)
}
func TestConvertAndroidLibraryKotlin(t *testing.T) {
t.Helper()
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, Bp2buildTestCase{
Description: "Android Library with .kt srcs and common_srcs attribute",
ModuleTypeUnderTest: "android_library",
ModuleTypeUnderTestFactory: java.AndroidLibraryFactory,
Filesystem: map[string]string{
"AndroidManifest.xml": "",
},
Blueprint: `
android_library {
name: "TestLib",
srcs: ["a.java", "b.kt"],
common_srcs: ["c.kt"],
sdk_version: "current",
}
`,
ExpectedBazelTargets: []string{
MakeBazelTarget(
"android_library",
"TestLib",
AttrNameToString{
"srcs": `[
"a.java",
"b.kt",
]`,
"common_srcs": `["c.kt"]`,
"manifest": `"AndroidManifest.xml"`,
"resource_files": `[]`,
"sdk_version": `"current"`, // use as default
}),
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"],
sdk_version: "current",
}
`,
ExpectedBazelTargets: []string{
MakeBazelTarget(
"android_library",
"TestLib",
AttrNameToString{
"srcs": `[
"a.java",
"b.kt",
]`,
"kotlincflags": `[
"-flag1",
"-flag2",
]`,
"manifest": `"AndroidManifest.xml"`,
"resource_files": `[]`,
"sdk_version": `"current"`, // use as default
}),
MakeNeverlinkDuplicateTarget("android_library", "TestLib"),
}})
}
func TestAarImportFailsToConvertNoAars(t *testing.T) {
runAndroidLibraryImportTest(t,
Bp2buildTestCase{
Description: "Android Library Import with no aars does not convert.",
Blueprint: `
android_library_import {
name: "no_aar_import",
}
`,
ExpectedBazelTargets: []string{},
})
}

View File

@@ -1,254 +0,0 @@
// Copyright 2023 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 (
"android/soong/aconfig/codegen"
"testing"
"android/soong/aconfig"
"android/soong/android"
"android/soong/cc"
"android/soong/java"
)
func registerAconfigModuleTypes(ctx android.RegistrationContext) {
aconfig.RegisterBuildComponents(ctx)
codegen.RegisterBuildComponents(ctx)
ctx.RegisterModuleType("cc_library", cc.LibraryFactory)
ctx.RegisterModuleType("java_library", java.LibraryFactory)
}
func TestAconfigDeclarations(t *testing.T) {
bp := `
aconfig_declarations {
name: "foo",
srcs: [
"foo1.aconfig",
"test/foo2.aconfig",
],
package: "com.android.foo",
}
`
expectedBazelTarget := MakeBazelTargetNoRestrictions(
"aconfig_declarations",
"foo",
AttrNameToString{
"srcs": `[
"foo1.aconfig",
"test/foo2.aconfig",
]`,
"package": `"com.android.foo"`,
},
)
RunBp2BuildTestCase(t, registerAconfigModuleTypes, Bp2buildTestCase{
Blueprint: bp,
ExpectedBazelTargets: []string{expectedBazelTarget},
})
}
func TestAconfigValues(t *testing.T) {
bp := `
aconfig_values {
name: "foo",
srcs: [
"foo1.textproto",
],
package: "com.android.foo",
}
aconfig_value_set {
name: "bar",
values: [
"foo"
]
}
`
expectedBazelTargets := []string{
MakeBazelTargetNoRestrictions(
"aconfig_values",
"foo",
AttrNameToString{
"srcs": `["foo1.textproto"]`,
"package": `"com.android.foo"`,
},
),
MakeBazelTargetNoRestrictions(
"aconfig_value_set",
"bar",
AttrNameToString{
"values": `[":foo"]`,
},
)}
RunBp2BuildTestCase(t, registerAconfigModuleTypes, Bp2buildTestCase{
Blueprint: bp,
ExpectedBazelTargets: expectedBazelTargets,
})
}
func TestCcAconfigLibrary(t *testing.T) {
bp := `
aconfig_declarations {
name: "foo_aconfig_declarations",
srcs: [
"foo1.aconfig",
],
package: "com.android.foo",
}
cc_library {
name: "server_configurable_flags",
srcs: ["bar.cc"],
}
cc_aconfig_library {
name: "foo",
aconfig_declarations: "foo_aconfig_declarations",
}
`
expectedBazelTargets := []string{
MakeBazelTargetNoRestrictions(
"aconfig_declarations",
"foo_aconfig_declarations",
AttrNameToString{
"srcs": `["foo1.aconfig"]`,
"package": `"com.android.foo"`,
},
),
MakeBazelTargetNoRestrictions(
"cc_aconfig_library",
"foo",
AttrNameToString{
"aconfig_declarations": `":foo_aconfig_declarations"`,
"dynamic_deps": `[":server_configurable_flags"]`,
"target_compatible_with": `["//build/bazel_common_rules/platforms/os:android"]`,
},
)}
RunBp2BuildTestCase(t, registerAconfigModuleTypes, Bp2buildTestCase{
Blueprint: bp,
ExpectedBazelTargets: expectedBazelTargets,
StubbedBuildDefinitions: []string{"server_configurable_flags"},
})
}
func TestJavaAconfigLibrary(t *testing.T) {
bp := `
aconfig_declarations {
name: "foo_aconfig_declarations",
srcs: [
"foo1.aconfig",
],
package: "com.android.foo",
}
java_library {
name: "foo_java_library",
srcs: ["foo.java"],
sdk_version: "current",
}
java_aconfig_library {
name: "foo",
aconfig_declarations: "foo_aconfig_declarations",
libs: ["foo_java_library"],
mode: "test",
}
`
expectedBazelTargets := []string{
MakeBazelTargetNoRestrictions(
"aconfig_declarations",
"foo_aconfig_declarations",
AttrNameToString{
"srcs": `["foo1.aconfig"]`,
"package": `"com.android.foo"`,
},
),
MakeBazelTargetNoRestrictions(
"java_library",
"foo_java_library",
AttrNameToString{
"srcs": `["foo.java"]`,
"sdk_version": `"current"`,
"target_compatible_with": `["//build/bazel_common_rules/platforms/os:android"]`,
},
),
MakeNeverlinkDuplicateTarget("java_library", "foo_java_library"),
MakeBazelTargetNoRestrictions(
"java_aconfig_library",
"foo",
AttrNameToString{
"aconfig_declarations": `":foo_aconfig_declarations"`,
"libs": `[":foo_java_library-neverlink"]`,
"sdk_version": `"system_current"`,
"target_compatible_with": `["//build/bazel_common_rules/platforms/os:android"]`,
},
)}
RunBp2BuildTestCase(t, registerAconfigModuleTypes, Bp2buildTestCase{
Blueprint: bp,
ExpectedBazelTargets: expectedBazelTargets,
})
}
func TestJavaAconfigLibraryAsTaggedOutput(t *testing.T) {
bp := `
aconfig_declarations {
name: "foo_aconfig_declarations",
srcs: [
"foo.aconfig",
],
package: "com.android.foo",
}
java_library {
name: "foo_library",
srcs: [":foo_aconfig_library{.generated_srcjars}"],
sdk_version: "current",
bazel_module: { bp2build_available: true },
}
java_aconfig_library {
name: "foo_aconfig_library",
aconfig_declarations: "foo_aconfig_declarations",
mode: "test",
}
`
expectedBazelTargets := []string{
MakeBazelTargetNoRestrictions(
"aconfig_declarations",
"foo_aconfig_declarations",
AttrNameToString{
"srcs": `["foo.aconfig"]`,
"package": `"com.android.foo"`,
},
),
MakeBazelTargetNoRestrictions(
"java_aconfig_library",
"foo_aconfig_library",
AttrNameToString{
"aconfig_declarations": `":foo_aconfig_declarations"`,
"sdk_version": `"system_current"`,
"target_compatible_with": `["//build/bazel_common_rules/platforms/os:android"]`,
},
),
MakeBazelTargetNoRestrictions(
"java_library",
"foo_library",
AttrNameToString{
"srcs": `[":foo_aconfig_library.generated_srcjars"]`,
"sdk_version": `"current"`,
"target_compatible_with": `["//build/bazel_common_rules/platforms/os:android"]`,
},
),
MakeNeverlinkDuplicateTarget("java_library", "foo_library"),
}
RunBp2BuildTestCase(t, registerAconfigModuleTypes, Bp2buildTestCase{
Blueprint: bp,
ExpectedBazelTargets: expectedBazelTargets,
})
}

View File

@@ -1,119 +0,0 @@
// Copyright 2023 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/aidl_library"
"android/soong/android"
)
func runAidlLibraryTestCase(t *testing.T, tc Bp2buildTestCase) {
t.Helper()
(&tc).ModuleTypeUnderTest = "aidl_library"
(&tc).ModuleTypeUnderTestFactory = aidl_library.AidlLibraryFactory
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, tc)
}
func TestAidlLibrary(t *testing.T) {
testcases := []struct {
name string
bp string
expectedBazelAttrs AttrNameToString
}{
{
name: "aidl_library with strip_import_prefix",
bp: `
aidl_library {
name: "foo",
srcs: ["aidl/foo.aidl"],
hdrs: ["aidl/header.aidl"],
strip_import_prefix: "aidl",
}`,
expectedBazelAttrs: AttrNameToString{
"srcs": `["aidl/foo.aidl"]`,
"hdrs": `["aidl/header.aidl"]`,
"strip_import_prefix": `"aidl"`,
"tags": `["apex_available=//apex_available:anyapex"]`,
},
},
{
name: "aidl_library without strip_import_prefix",
bp: `
aidl_library {
name: "foo",
srcs: ["aidl/foo.aidl"],
hdrs: ["aidl/header.aidl"],
}`,
expectedBazelAttrs: AttrNameToString{
"srcs": `["aidl/foo.aidl"]`,
"hdrs": `["aidl/header.aidl"]`,
"tags": `["apex_available=//apex_available:anyapex"]`,
},
},
}
for _, test := range testcases {
t.Run(test.name, func(t *testing.T) {
expectedBazelTargets := []string{
MakeBazelTargetNoRestrictions("aidl_library", "foo", test.expectedBazelAttrs),
}
runAidlLibraryTestCase(t, Bp2buildTestCase{
Description: test.name,
Blueprint: test.bp,
ExpectedBazelTargets: expectedBazelTargets,
})
})
}
}
func TestAidlLibraryWithDeps(t *testing.T) {
bp := `
aidl_library {
name: "bar",
srcs: ["Bar.aidl"],
hdrs: ["aidl/BarHeader.aidl"],
}
aidl_library {
name: "foo",
srcs: ["aidl/Foo.aidl"],
hdrs: ["aidl/FooHeader.aidl"],
strip_import_prefix: "aidl",
deps: ["bar"],
}`
t.Run("aidl_library with deps", func(t *testing.T) {
expectedBazelTargets := []string{
MakeBazelTargetNoRestrictions("aidl_library", "bar", AttrNameToString{
"srcs": `["Bar.aidl"]`,
"hdrs": `["aidl/BarHeader.aidl"]`,
"tags": `["apex_available=//apex_available:anyapex"]`,
}),
MakeBazelTargetNoRestrictions("aidl_library", "foo", AttrNameToString{
"srcs": `["aidl/Foo.aidl"]`,
"hdrs": `["aidl/FooHeader.aidl"]`,
"strip_import_prefix": `"aidl"`,
"deps": `[":bar"]`,
"tags": `["apex_available=//apex_available:anyapex"]`,
}),
}
runAidlLibraryTestCase(t, Bp2buildTestCase{
Description: "aidl_library with deps",
Blueprint: bp,
ExpectedBazelTargets: expectedBazelTargets,
})
})
}

View File

@@ -1,49 +0,0 @@
// 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 (
"android/soong/android"
"android/soong/java"
"testing"
)
func runAndroidAppCertificateTestCase(t *testing.T, tc Bp2buildTestCase) {
t.Helper()
RunBp2BuildTestCase(t, registerAndroidAppCertificateModuleTypes, tc)
}
func registerAndroidAppCertificateModuleTypes(ctx android.RegistrationContext) {
}
func TestAndroidAppCertificateSimple(t *testing.T) {
runAndroidAppCertificateTestCase(t, Bp2buildTestCase{
Description: "Android app certificate - simple example",
ModuleTypeUnderTest: "android_app_certificate",
ModuleTypeUnderTestFactory: java.AndroidAppCertificateFactory,
Filesystem: map[string]string{},
Blueprint: `
android_app_certificate {
name: "com.android.apogee.cert",
certificate: "chamber_of_secrets_dir",
}
`,
ExpectedBazelTargets: []string{
MakeBazelTargetNoRestrictions("android_app_certificate", "com.android.apogee.cert", AttrNameToString{
"certificate": `"chamber_of_secrets_dir"`,
}),
}})
}

View File

@@ -1,518 +0,0 @@
// 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 (
"android/soong/android"
"android/soong/cc"
"android/soong/java"
"testing"
)
func runAndroidAppTestCase(t *testing.T, tc Bp2buildTestCase) {
t.Helper()
RunBp2BuildTestCase(t, registerAndroidAppModuleTypes, tc)
}
func registerAndroidAppModuleTypes(ctx android.RegistrationContext) {
ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
ctx.RegisterModuleType("java_library", java.LibraryFactory)
ctx.RegisterModuleType("cc_library_shared", cc.LibrarySharedFactory)
}
func TestMinimalAndroidApp(t *testing.T) {
runAndroidAppTestCase(t, Bp2buildTestCase{
Description: "Android app - simple example",
ModuleTypeUnderTest: "android_app",
ModuleTypeUnderTestFactory: java.AndroidAppFactory,
Filesystem: map[string]string{
"app.java": "",
"res/res.png": "",
"AndroidManifest.xml": "",
"assets/asset.png": "",
},
Blueprint: `
android_app {
name: "TestApp",
srcs: ["app.java"],
sdk_version: "current",
optimize: {
shrink: true,
optimize: true,
obfuscate: true,
},
}
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("android_binary", "TestApp", AttrNameToString{
"srcs": `["app.java"]`,
"manifest": `"AndroidManifest.xml"`,
"resource_files": `["res/res.png"]`,
"sdk_version": `"current"`,
"assets": `["assets/asset.png"]`,
"assets_dir": `"assets"`,
}),
}})
}
func TestAndroidAppAllSupportedFields(t *testing.T) {
runAndroidAppTestCase(t, Bp2buildTestCase{
Description: "Android app - all supported fields",
ModuleTypeUnderTest: "android_app",
ModuleTypeUnderTestFactory: java.AndroidAppFactory,
Filesystem: map[string]string{
"app.java": "",
"resa/res.png": "",
"resb/res.png": "",
"manifest/AndroidManifest.xml": "",
"assets_/asset.png": "",
},
StubbedBuildDefinitions: []string{"static_lib_dep", "jni_lib"},
Blueprint: simpleModule("android_app", "static_lib_dep") +
simpleModule("cc_library_shared", "jni_lib") + `
android_app {
name: "TestApp",
srcs: ["app.java"],
sdk_version: "current",
package_name: "com.google",
resource_dirs: ["resa", "resb"],
manifest: "manifest/AndroidManifest.xml",
static_libs: ["static_lib_dep"],
java_version: "7",
certificate: "foocert",
required: ["static_lib_dep"],
asset_dirs: ["assets_"],
optimize: {
enabled: true,
optimize: false,
proguard_flags_files: ["proguard.flags"],
shrink: false,
obfuscate: false,
ignore_warnings: true,
},
jni_libs: ["jni_lib"],
}
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("android_binary", "TestApp", AttrNameToString{
"srcs": `["app.java"]`,
"manifest": `"manifest/AndroidManifest.xml"`,
"resource_files": `[
"resa/res.png",
"resb/res.png",
]`,
"assets": `["assets_/asset.png"]`,
"assets_dir": `"assets_"`,
"custom_package": `"com.google"`,
"deps": `[
":static_lib_dep",
":jni_lib",
]`,
"java_version": `"7"`,
"sdk_version": `"current"`,
"certificate_name": `"foocert"`,
"proguard_specs": `[
"proguard.flags",
":TestApp_proguard_flags",
]`,
}),
MakeBazelTarget("genrule", "TestApp_proguard_flags", AttrNameToString{
"outs": `["TestApp_proguard.flags"]`,
"cmd": `"echo -ignorewarning -dontshrink -dontoptimize -dontobfuscate > $(OUTS)"`,
}),
}})
}
func TestAndroidAppArchVariantSrcs(t *testing.T) {
runAndroidAppTestCase(t, Bp2buildTestCase{
Description: "Android app - arch variant srcs",
ModuleTypeUnderTest: "android_app",
ModuleTypeUnderTestFactory: java.AndroidAppFactory,
Filesystem: map[string]string{
"arm.java": "",
"x86.java": "",
"res/res.png": "",
"AndroidManifest.xml": "",
},
Blueprint: `
android_app {
name: "TestApp",
sdk_version: "current",
arch: {
arm: {
srcs: ["arm.java"],
},
x86: {
srcs: ["x86.java"],
}
},
optimize: {
enabled: false,
},
}
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("android_binary", "TestApp", AttrNameToString{
"srcs": `select({
"//build/bazel_common_rules/platforms/arch:arm": ["arm.java"],
"//build/bazel_common_rules/platforms/arch:x86": ["x86.java"],
"//conditions:default": [],
})`,
"manifest": `"AndroidManifest.xml"`,
"resource_files": `["res/res.png"]`,
"sdk_version": `"current"`,
"optimize": `False`,
}),
}})
}
func TestAndroidAppCertIsModule(t *testing.T) {
runAndroidAppTestCase(t, Bp2buildTestCase{
Description: "Android app - cert is module",
ModuleTypeUnderTest: "android_app",
ModuleTypeUnderTestFactory: java.AndroidAppFactory,
Filesystem: map[string]string{},
StubbedBuildDefinitions: []string{"foocert"},
Blueprint: simpleModule("filegroup", "foocert") + `
android_app {
name: "TestApp",
certificate: ":foocert",
sdk_version: "current",
optimize: {
enabled: false,
},
}
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("android_binary", "TestApp", AttrNameToString{
"certificate": `":foocert"`,
"manifest": `"AndroidManifest.xml"`,
"resource_files": `[]`,
"sdk_version": `"current"`, // use as default
"optimize": `False`,
}),
}})
}
func TestAndroidAppCertIsSrcFile(t *testing.T) {
runAndroidAppTestCase(t, Bp2buildTestCase{
Description: "Android app - cert is src file",
ModuleTypeUnderTest: "android_app",
ModuleTypeUnderTestFactory: java.AndroidAppFactory,
Filesystem: map[string]string{
"foocert": "",
},
Blueprint: `
android_app {
name: "TestApp",
certificate: "foocert",
sdk_version: "current",
optimize: {
enabled: false,
},
}
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("android_binary", "TestApp", AttrNameToString{
"certificate": `"foocert"`,
"manifest": `"AndroidManifest.xml"`,
"resource_files": `[]`,
"sdk_version": `"current"`, // use as default
"optimize": `False`,
}),
}})
}
func TestAndroidAppCertIsNotSrcOrModule(t *testing.T) {
runAndroidAppTestCase(t, Bp2buildTestCase{
Description: "Android app - cert is not src or module",
ModuleTypeUnderTest: "android_app",
ModuleTypeUnderTestFactory: java.AndroidAppFactory,
Filesystem: map[string]string{
// deliberate empty
},
Blueprint: `
android_app {
name: "TestApp",
certificate: "foocert",
sdk_version: "current",
optimize: {
enabled: false,
},
}
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("android_binary", "TestApp", AttrNameToString{
"certificate_name": `"foocert"`,
"manifest": `"AndroidManifest.xml"`,
"resource_files": `[]`,
"sdk_version": `"current"`, // use as default
"optimize": `False`,
}),
}})
}
func TestAndroidAppLibs(t *testing.T) {
runAndroidAppTestCase(t, Bp2buildTestCase{
Description: "Android app with libs",
ModuleTypeUnderTest: "android_app",
ModuleTypeUnderTestFactory: java.AndroidAppFactory,
Filesystem: map[string]string{},
StubbedBuildDefinitions: []string{"barLib"},
Blueprint: simpleModule("java_library", "barLib") + `
android_app {
name: "foo",
libs: ["barLib"],
sdk_version: "current",
optimize: {
enabled: false,
},
}
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("android_binary", "foo", AttrNameToString{
"manifest": `"AndroidManifest.xml"`,
"resource_files": `[]`,
"deps": `[":barLib-neverlink"]`,
"sdk_version": `"current"`, // use as default
"optimize": `False`,
}),
}})
}
func TestAndroidAppKotlinSrcs(t *testing.T) {
runAndroidAppTestCase(t, Bp2buildTestCase{
Description: "Android app with kotlin sources and common_srcs",
ModuleTypeUnderTest: "android_app",
ModuleTypeUnderTestFactory: java.AndroidAppFactory,
Filesystem: map[string]string{
"res/res.png": "",
},
StubbedBuildDefinitions: []string{"foocert", "barLib"},
Blueprint: simpleModule("filegroup", "foocert") +
simpleModule("java_library", "barLib") + `
android_app {
name: "foo",
srcs: ["a.java", "b.kt"],
certificate: ":foocert",
manifest: "fooManifest.xml",
libs: ["barLib"],
sdk_version: "current",
optimize: {
enabled: false,
},
}
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("android_library", "foo_kt", AttrNameToString{
"srcs": `[
"a.java",
"b.kt",
]`,
"manifest": `"fooManifest.xml"`,
"resource_files": `["res/res.png"]`,
"deps": `[":barLib-neverlink"]`,
"sdk_version": `"current"`, // use as default
}),
MakeBazelTarget("android_binary", "foo", AttrNameToString{
"deps": `[":foo_kt"]`,
"certificate": `":foocert"`,
"manifest": `"fooManifest.xml"`,
"sdk_version": `"current"`, // use as default
"optimize": `False`,
}),
}})
}
func TestAndroidAppCommonSrcs(t *testing.T) {
runAndroidAppTestCase(t, Bp2buildTestCase{
Description: "Android app with common_srcs",
ModuleTypeUnderTest: "android_app",
ModuleTypeUnderTestFactory: java.AndroidAppFactory,
Filesystem: map[string]string{
"res/res.png": "",
},
StubbedBuildDefinitions: []string{"barLib"},
Blueprint: `
android_app {
name: "foo",
srcs: ["a.java"],
common_srcs: ["b.kt"],
manifest: "fooManifest.xml",
libs: ["barLib"],
sdk_version: "current",
optimize: {
enabled: false,
},
}
java_library{
name: "barLib",
}
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("android_library", "foo_kt", AttrNameToString{
"srcs": `["a.java"]`,
"common_srcs": `["b.kt"]`,
"manifest": `"fooManifest.xml"`,
"resource_files": `["res/res.png"]`,
"deps": `[":barLib-neverlink"]`,
"sdk_version": `"current"`, // use as default
}),
MakeBazelTarget("android_binary", "foo", AttrNameToString{
"deps": `[":foo_kt"]`,
"manifest": `"fooManifest.xml"`,
"sdk_version": `"current"`, // use as default
"optimize": `False`,
}),
}})
}
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: `
android_app {
name: "foo",
srcs: ["a.java", "b.kt"],
manifest: "fooManifest.xml",
kotlincflags: ["-flag1", "-flag2"],
sdk_version: "current",
optimize: {
enabled: false,
},
}
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("android_library", "foo_kt", AttrNameToString{
"srcs": `[
"a.java",
"b.kt",
]`,
"manifest": `"fooManifest.xml"`,
"resource_files": `["res/res.png"]`,
"kotlincflags": `[
"-flag1",
"-flag2",
]`,
"sdk_version": `"current"`, // use as default
}),
MakeBazelTarget("android_binary", "foo", AttrNameToString{
"deps": `[":foo_kt"]`,
"manifest": `"fooManifest.xml"`,
"sdk_version": `"current"`,
"optimize": `False`,
}),
}})
}
func TestAndroidAppManifestSdkVersionsProvided(t *testing.T) {
runAndroidAppTestCase(t, Bp2buildTestCase{
Description: "Android app with value for min_sdk_version",
ModuleTypeUnderTest: "android_app",
ModuleTypeUnderTestFactory: java.AndroidAppFactory,
Filesystem: map[string]string{},
Blueprint: `
android_app {
name: "foo",
sdk_version: "current",
min_sdk_version: "24",
target_sdk_version: "29",
optimize: {
enabled: false,
},
}
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("android_binary", "foo", AttrNameToString{
"manifest": `"AndroidManifest.xml"`,
"resource_files": `[]`,
"manifest_values": `{
"minSdkVersion": "24",
"targetSdkVersion": "29",
}`,
"sdk_version": `"current"`,
"optimize": `False`,
}),
}})
}
func TestAndroidAppMinAndTargetSdkDefaultToSdkVersion(t *testing.T) {
runAndroidAppTestCase(t, Bp2buildTestCase{
Description: "Android app with value for sdk_version",
ModuleTypeUnderTest: "android_app",
ModuleTypeUnderTestFactory: java.AndroidAppFactory,
Filesystem: map[string]string{},
Blueprint: `
android_app {
name: "foo",
sdk_version: "30",
optimize: {
enabled: false,
},
}
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("android_binary", "foo", AttrNameToString{
"manifest": `"AndroidManifest.xml"`,
"resource_files": `[]`,
"sdk_version": `"30"`,
"optimize": `False`,
}),
}})
}
func TestFrameworkResConversion(t *testing.T) {
runAndroidAppTestCase(t, Bp2buildTestCase{
Description: "Framework Res custom conversion",
ModuleTypeUnderTest: "android_app",
ModuleTypeUnderTestFactory: java.AndroidAppFactory,
Filesystem: map[string]string{
"res/values/attrs.xml": "",
"resource_zip.zip": "",
},
Blueprint: `
android_app {
name: "framework-res",
resource_zips: [
"resource_zip.zip",
],
certificate: "platform",
}
filegroup {
name: "framework-res-package-jar",
srcs: [":framework-res{.export-package.apk}"],
}
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("framework_resources", "framework-res", AttrNameToString{
"certificate_name": `"platform"`,
"manifest": `"AndroidManifest.xml"`,
"resource_files": `["res/values/attrs.xml"]`,
"resource_zips": `["resource_zip.zip"]`,
"target_compatible_with": `["//build/bazel_common_rules/platforms/os:android"]`,
}),
MakeBazelTargetNoRestrictions("filegroup", "framework-res-package-jar", AttrNameToString{
"srcs": `[":framework-res.export-package.apk"]`,
}),
}})
}

View File

@@ -1,178 +0,0 @@
// Copyright 2023 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 (
"android/soong/android"
"android/soong/java"
"testing"
)
func runAndroidTestTestCase(t *testing.T, tc Bp2buildTestCase) {
t.Helper()
RunBp2BuildTestCase(t, registerAndroidTestModuleTypes, tc)
}
func registerAndroidTestModuleTypes(ctx android.RegistrationContext) {
ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
ctx.RegisterModuleType("java_library", java.LibraryFactory)
}
func TestMinimalAndroidTest(t *testing.T) {
runAndroidAppTestCase(t, Bp2buildTestCase{
Description: "Android test - simple example",
ModuleTypeUnderTest: "android_test",
ModuleTypeUnderTestFactory: java.AndroidTestFactory,
Filesystem: map[string]string{
"app.java": "",
"res/res.png": "",
"AndroidManifest.xml": "",
"assets/asset.png": "",
},
Blueprint: `
android_test {
name: "TestApp",
srcs: ["app.java"],
sdk_version: "current",
}
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("android_test", "TestApp", AttrNameToString{
"srcs": `["app.java"]`,
"manifest": `"AndroidManifest.xml"`,
"resource_files": `["res/res.png"]`,
"sdk_version": `"current"`,
"assets": `["assets/asset.png"]`,
"assets_dir": `"assets"`,
// no need for optimize = False because it's false for
// android_test by default
}),
}})
}
func TestAndroidTest_OptimizationEnabled(t *testing.T) {
runAndroidAppTestCase(t, Bp2buildTestCase{
Description: "Android test - simple example",
ModuleTypeUnderTest: "android_test",
ModuleTypeUnderTestFactory: java.AndroidTestFactory,
Filesystem: map[string]string{
"app.java": "",
"res/res.png": "",
"AndroidManifest.xml": "",
"assets/asset.png": "",
},
Blueprint: `
android_test {
name: "TestApp",
srcs: ["app.java"],
sdk_version: "current",
optimize: {
enabled: true,
shrink: true,
optimize: true,
obfuscate: true,
},
}
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("android_test", "TestApp", AttrNameToString{
"srcs": `["app.java"]`,
"manifest": `"AndroidManifest.xml"`,
"resource_files": `["res/res.png"]`,
"sdk_version": `"current"`,
"assets": `["assets/asset.png"]`,
"assets_dir": `"assets"`,
// optimize = True because it's false for android_test by
// default
"optimize": `True`,
}),
}})
}
func TestMinimalAndroidTestHelperApp(t *testing.T) {
runAndroidAppTestCase(t, Bp2buildTestCase{
Description: "Android test helper app - simple example",
ModuleTypeUnderTest: "android_test_helper_app",
ModuleTypeUnderTestFactory: java.AndroidTestHelperAppFactory,
Filesystem: map[string]string{
"app.java": "",
"res/res.png": "",
"AndroidManifest.xml": "",
"assets/asset.png": "",
},
Blueprint: `
android_test_helper_app {
name: "TestApp",
srcs: ["app.java"],
sdk_version: "current",
optimize: {
shrink: true,
optimize: true,
obfuscate: true,
},
}
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("android_binary", "TestApp", AttrNameToString{
"srcs": `["app.java"]`,
"manifest": `"AndroidManifest.xml"`,
"resource_files": `["res/res.png"]`,
"sdk_version": `"current"`,
"assets": `["assets/asset.png"]`,
"assets_dir": `"assets"`,
"testonly": `True`,
// no need for optimize = True because it's true for
// android_test_helper_app by default
}),
}})
}
func TestAndroidTestHelperApp_OptimizationDisabled(t *testing.T) {
runAndroidAppTestCase(t, Bp2buildTestCase{
Description: "Android test helper app - simple example",
ModuleTypeUnderTest: "android_test_helper_app",
ModuleTypeUnderTestFactory: java.AndroidTestHelperAppFactory,
Filesystem: map[string]string{
"app.java": "",
"res/res.png": "",
"AndroidManifest.xml": "",
"assets/asset.png": "",
},
Blueprint: `
android_test_helper_app {
name: "TestApp",
srcs: ["app.java"],
sdk_version: "current",
optimize: {
enabled: false,
},
}
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("android_binary", "TestApp", AttrNameToString{
"srcs": `["app.java"]`,
"manifest": `"AndroidManifest.xml"`,
"resource_files": `["res/res.png"]`,
"sdk_version": `"current"`,
"assets": `["assets/asset.png"]`,
"assets_dir": `"assets"`,
"testonly": `True`,
// optimize = False because it's true for
// android_test_helper_app by default
"optimize": `False`,
}),
}})
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,101 +0,0 @@
// 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 (
"android/soong/android"
"android/soong/apex"
"testing"
)
func runApexKeyTestCase(t *testing.T, tc Bp2buildTestCase) {
t.Helper()
RunBp2BuildTestCase(t, registerApexKeyModuleTypes, tc)
}
func registerApexKeyModuleTypes(ctx android.RegistrationContext) {
ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
}
func TestApexKeySimple_KeysAreSrcFilesInSameDir(t *testing.T) {
runApexKeyTestCase(t, Bp2buildTestCase{
Description: "apex key - keys are src files, use key attributes",
ModuleTypeUnderTest: "apex_key",
ModuleTypeUnderTestFactory: apex.ApexKeyFactory,
Filesystem: map[string]string{
"com.android.apogee.avbpubkey": "",
"com.android.apogee.pem": "",
},
Blueprint: `
apex_key {
name: "com.android.apogee.key",
public_key: "com.android.apogee.avbpubkey",
private_key: "com.android.apogee.pem",
}
`,
ExpectedBazelTargets: []string{MakeBazelTargetNoRestrictions("apex_key", "com.android.apogee.key", AttrNameToString{
"private_key": `"com.android.apogee.pem"`,
"public_key": `"com.android.apogee.avbpubkey"`,
"target_compatible_with": `["//build/bazel_common_rules/platforms/os:android"]`,
}),
}})
}
func TestApexKeySimple_KeysAreSrcFilesNotInDir(t *testing.T) {
runApexKeyTestCase(t, Bp2buildTestCase{
Description: "apex key - keys are not src or module, use key_name attributes",
ModuleTypeUnderTest: "apex_key",
ModuleTypeUnderTestFactory: apex.ApexKeyFactory,
Filesystem: map[string]string{
// deliberately left empty
},
Blueprint: `
apex_key {
name: "com.android.apogee.key",
public_key: "com.android.apogee.avbpubkey",
private_key: "com.android.apogee.pem",
}
`,
ExpectedBazelTargets: []string{MakeBazelTargetNoRestrictions("apex_key", "com.android.apogee.key", AttrNameToString{
"private_key_name": `"com.android.apogee.pem"`,
"public_key_name": `"com.android.apogee.avbpubkey"`,
"target_compatible_with": `["//build/bazel_common_rules/platforms/os:android"]`,
}),
}})
}
func TestApexKey_KeysAreModules(t *testing.T) {
runApexKeyTestCase(t, Bp2buildTestCase{
Description: "apex key - keys are modules, use key attributes",
ModuleTypeUnderTest: "apex_key",
ModuleTypeUnderTestFactory: apex.ApexKeyFactory,
Filesystem: map[string]string{},
StubbedBuildDefinitions: []string{"com.android.apogee.avbpubkey", "com.android.apogee.pem"},
Blueprint: `
apex_key {
name: "com.android.apogee.key",
public_key: ":com.android.apogee.avbpubkey",
private_key: ":com.android.apogee.pem",
}
` + simpleModule("filegroup", "com.android.apogee.avbpubkey") +
simpleModule("filegroup", "com.android.apogee.pem"),
ExpectedBazelTargets: []string{MakeBazelTargetNoRestrictions("apex_key", "com.android.apogee.key", AttrNameToString{
"private_key": `":com.android.apogee.pem"`,
"public_key": `":com.android.apogee.avbpubkey"`,
"target_compatible_with": `["//build/bazel_common_rules/platforms/os:android"]`,
}),
}})
}

View File

@@ -1,154 +0,0 @@
package bp2build
import (
"android/soong/android"
"android/soong/cc"
"android/soong/starlark_import"
"encoding/json"
"reflect"
"testing"
"github.com/google/blueprint/proptools"
"go.starlark.net/starlark"
)
func createStarlarkValue(t *testing.T, code string) starlark.Value {
t.Helper()
result, err := starlark.ExecFile(&starlark.Thread{}, "main.bzl", "x = "+code, nil)
if err != nil {
t.Error(err)
}
return result["x"]
}
func createStarlarkProductVariablesMap(t *testing.T, code string) map[string]starlark.Value {
t.Helper()
rawValue := createStarlarkValue(t, code)
value, err := starlark_import.Unmarshal[map[string]starlark.Value](rawValue)
if err != nil {
t.Error(err)
}
return value
}
func TestStarlarkMapToProductVariables(t *testing.T) {
thirty := 30
cases := []struct {
starlark string
result android.ProductVariables
}{
{
starlark: `{"CompressedApex": True}`,
result: android.ProductVariables{CompressedApex: proptools.BoolPtr(true)},
},
{
starlark: `{"ApexGlobalMinSdkVersionOverride": "Tiramisu"}`,
result: android.ProductVariables{ApexGlobalMinSdkVersionOverride: proptools.StringPtr("Tiramisu")},
},
{
starlark: `{"ProductManufacturer": "Google"}`,
result: android.ProductVariables{ProductManufacturer: "Google"},
},
{
starlark: `{"Unbundled_build_apps": ["app1", "app2"]}`,
result: android.ProductVariables{Unbundled_build_apps: []string{"app1", "app2"}},
},
{
starlark: `{"Platform_sdk_version": 30}`,
result: android.ProductVariables{Platform_sdk_version: &thirty},
},
{
starlark: `{"HostFakeSnapshotEnabled": True}`,
result: android.ProductVariables{HostFakeSnapshotEnabled: true},
},
}
for _, testCase := range cases {
productVariables, err := starlarkMapToProductVariables(createStarlarkProductVariablesMap(t,
testCase.starlark))
if err != nil {
t.Error(err)
continue
}
testCase.result.Native_coverage = proptools.BoolPtr(false)
if !reflect.DeepEqual(testCase.result, productVariables) {
expected, err := json.Marshal(testCase.result)
if err != nil {
t.Error(err)
continue
}
actual, err := json.Marshal(productVariables)
if err != nil {
t.Error(err)
continue
}
expectedStr := string(expected)
actualStr := string(actual)
t.Errorf("expected %q, but got %q", expectedStr, actualStr)
}
}
}
func TestSystemPartitionDeps(t *testing.T) {
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {
ctx.RegisterModuleType("cc_library", cc.LibraryFactory)
}, Bp2buildTestCase{
ExtraFixturePreparer: android.GroupFixturePreparers(
android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
deviceProduct := "aosp_arm64"
variables.DeviceProduct = &deviceProduct
partitionVars := &variables.PartitionVarsForBazelMigrationOnlyDoNotUse
partitionVars.ProductDirectory = "build/make/target/product/"
partitionVars.ProductPackages = []string{"foo"}
var systemVars android.PartitionQualifiedVariablesType
systemVars.BuildingImage = true
partitionVars.PartitionQualifiedVariables = map[string]android.PartitionQualifiedVariablesType{
"system": systemVars,
}
}),
android.FixtureModifyConfig(func(config android.Config) {
// MockBazelContext will pretend everything is mixed-builds allowlisted.
// The default is noopBazelContext, which does the opposite.
config.BazelContext = android.MockBazelContext{}
}),
),
Blueprint: `
cc_library {
name: "foo",
}`,
ExpectedBazelTargets: []string{`android_product(
name = "aosp_arm64",
soong_variables = _soong_variables,
)`, `partition(
name = "system_image",
base_staging_dir = "//build/bazel/bazel_sandwich:system_staging_dir",
base_staging_dir_file_list = "//build/bazel/bazel_sandwich:system_staging_dir_file_list",
root_dir = "//build/bazel/bazel_sandwich:root_staging_dir",
selinux_file_contexts = "//build/bazel/bazel_sandwich:selinux_file_contexts",
image_properties = """
building_system_image=true
erofs_sparse_flag=-s
extfs_sparse_flag=-s
f2fs_sparse_flag=-S
skip_fsck=true
squashfs_sparse_flag=-s
system_disable_sparse=true
""",
deps = [
"//:foo",
],
type = "system",
)`, `partition_diff_test(
name = "system_image_test",
partition1 = "//build/bazel/bazel_sandwich:make_system_image",
partition2 = ":system_image",
)`, `run_test_in_build(
name = "run_system_image_test",
test = ":system_image_test",
)`},
Dir: "build/make/target/product/aosp_arm64",
RunBp2buildProductConfig: true,
})
}

View File

@@ -1,65 +0,0 @@
// Copyright 2022 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 (
"android/soong/android"
"android/soong/bpf"
"testing"
)
func runBpfTestCase(t *testing.T, tc Bp2buildTestCase) {
t.Helper()
(&tc).ModuleTypeUnderTest = "bpf"
(&tc).ModuleTypeUnderTestFactory = bpf.BpfFactory
RunBp2BuildTestCase(t, registerBpfModuleTypes, tc)
}
func registerBpfModuleTypes(ctx android.RegistrationContext) {}
func TestBpfSupportedAttrs(t *testing.T) {
runBpfTestCase(t, Bp2buildTestCase{
Description: "Bpf module only converts supported attributes",
Filesystem: map[string]string{},
Blueprint: `
bpf {
name: "bpfTestOut.o",
srcs: ["bpfTestSrcOne.c",
"bpfTestSrcTwo.c"],
btf: true,
cflags: ["-bpfCflagOne",
"-bpfCflagTwo"],
include_dirs: ["ia/ib/ic"],
sub_dir: "sa/ab",
}
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("bpf", "bpfTestOut.o", AttrNameToString{
"absolute_includes": `["ia/ib/ic"]`,
"btf": `True`,
"copts": `[
"-bpfCflagOne",
"-bpfCflagTwo",
]`,
"srcs": `[
"bpfTestSrcOne.c",
"bpfTestSrcTwo.c",
]`,
"target_compatible_with": `["//build/bazel_common_rules/platforms/os:android"]`,
}),
},
})
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,241 +0,0 @@
// Copyright 2020 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 (
"io/ioutil"
"os"
"strings"
"testing"
"android/soong/android"
)
func setUp() {
var err error
buildDir, err = ioutil.TempDir("", "bazel_queryview_test")
if err != nil {
panic(err)
}
}
func tearDown() {
os.RemoveAll(buildDir)
}
func TestMain(m *testing.M) {
run := func() int {
setUp()
defer tearDown()
return m.Run()
}
os.Exit(run())
}
func TestGenerateModuleRuleShims(t *testing.T) {
moduleTypeFactories := map[string]android.ModuleFactory{
"custom": customModuleFactoryBase,
"custom_test": customTestModuleFactoryBase,
"custom_defaults": customDefaultsModuleFactoryBasic,
}
ruleShims := CreateRuleShims(moduleTypeFactories)
if len(ruleShims) != 1 {
t.Errorf("Expected to generate 1 rule shim, but got %d", len(ruleShims))
}
ruleShim := ruleShims["bp2build"]
expectedRules := []string{
"custom",
"custom_defaults",
"custom_test_",
}
if len(ruleShim.rules) != len(expectedRules) {
t.Errorf("Expected %d rules, but got %d", len(expectedRules), len(ruleShim.rules))
}
for i, rule := range ruleShim.rules {
if rule != expectedRules[i] {
t.Errorf("Expected rule shim to contain %s, but got %s", expectedRules[i], rule)
}
}
expectedBzl := `load("//build/bazel/queryview_rules:providers.bzl", "SoongModuleInfo")
def _custom_impl(ctx):
return [SoongModuleInfo()]
custom = rule(
implementation = _custom_impl,
attrs = {
"soong_module_name": attr.string(mandatory = True),
"soong_module_variant": attr.string(),
"soong_module_deps": attr.label_list(providers = [SoongModuleInfo]),
"api": attr.string(),
"arch_paths": attr.string_list(),
"arch_paths_exclude": attr.string_list(),
# bazel_module start
# "label": attr.string(),
# "bp2build_available": attr.bool(),
# bazel_module end
"bool_prop": attr.bool(),
"bool_ptr_prop": attr.bool(),
"dir": attr.string(),
"does_not_convert_to_bazel": attr.bool(),
"embedded_prop": attr.string(),
"int64_ptr_prop": attr.int(),
# nested_props start
# "nested_prop": attr.string(),
# nested_props end
# nested_props_ptr start
# "nested_prop": attr.string(),
# nested_props_ptr end
"one_to_many_prop": attr.bool(),
"other_embedded_prop": attr.string(),
"string_list_prop": attr.string_list(),
"string_literal_prop": attr.string(),
"string_prop": attr.string(),
"string_ptr_prop": attr.string(),
"test_config_setting": attr.bool(),
},
)
def _custom_defaults_impl(ctx):
return [SoongModuleInfo()]
custom_defaults = rule(
implementation = _custom_defaults_impl,
attrs = {
"soong_module_name": attr.string(mandatory = True),
"soong_module_variant": attr.string(),
"soong_module_deps": attr.label_list(providers = [SoongModuleInfo]),
"api": attr.string(),
"arch_paths": attr.string_list(),
"arch_paths_exclude": attr.string_list(),
"bool_prop": attr.bool(),
"bool_ptr_prop": attr.bool(),
"dir": attr.string(),
"does_not_convert_to_bazel": attr.bool(),
"embedded_prop": attr.string(),
"int64_ptr_prop": attr.int(),
# nested_props start
# "nested_prop": attr.string(),
# nested_props end
# nested_props_ptr start
# "nested_prop": attr.string(),
# nested_props_ptr end
"one_to_many_prop": attr.bool(),
"other_embedded_prop": attr.string(),
"string_list_prop": attr.string_list(),
"string_literal_prop": attr.string(),
"string_prop": attr.string(),
"string_ptr_prop": attr.string(),
"test_config_setting": attr.bool(),
},
)
def _custom_test__impl(ctx):
return [SoongModuleInfo()]
custom_test_ = rule(
implementation = _custom_test__impl,
attrs = {
"soong_module_name": attr.string(mandatory = True),
"soong_module_variant": attr.string(),
"soong_module_deps": attr.label_list(providers = [SoongModuleInfo]),
"api": attr.string(),
"arch_paths": attr.string_list(),
"arch_paths_exclude": attr.string_list(),
"bool_prop": attr.bool(),
"bool_ptr_prop": attr.bool(),
"dir": attr.string(),
"does_not_convert_to_bazel": attr.bool(),
"embedded_prop": attr.string(),
"int64_ptr_prop": attr.int(),
# nested_props start
# "nested_prop": attr.string(),
# nested_props end
# nested_props_ptr start
# "nested_prop": attr.string(),
# nested_props_ptr end
"one_to_many_prop": attr.bool(),
"other_embedded_prop": attr.string(),
"string_list_prop": attr.string_list(),
"string_literal_prop": attr.string(),
"string_prop": attr.string(),
"string_ptr_prop": attr.string(),
"test_config_setting": attr.bool(),
# test_prop start
# "test_string_prop": attr.string(),
# test_prop end
},
)
`
if ruleShim.content != expectedBzl {
t.Errorf(
"Expected the generated rule shim bzl to be:\n%s\nbut got:\n%s",
expectedBzl,
ruleShim.content)
}
}
func TestGenerateSoongModuleBzl(t *testing.T) {
ruleShims := map[string]RuleShim{
"file1": RuleShim{
rules: []string{"a", "b"},
content: "irrelevant",
},
"file2": RuleShim{
rules: []string{"c", "d"},
content: "irrelevant",
},
}
files := CreateBazelFiles(ruleShims, make(map[string]BazelTargets), QueryView)
var actualSoongModuleBzl BazelFile
for _, f := range files {
if f.Basename == "soong_module.bzl" {
actualSoongModuleBzl = f
}
}
expectedLoad := `load("//build/bazel/queryview_rules:file1.bzl", "a", "b")
load("//build/bazel/queryview_rules:file2.bzl", "c", "d")
`
expectedRuleMap := `soong_module_rule_map = {
"a": a,
"b": b,
"c": c,
"d": d,
}`
if !strings.Contains(actualSoongModuleBzl.Contents, expectedLoad) {
t.Errorf(
"Generated soong_module.bzl:\n\n%s\n\n"+
"Could not find the load statement in the generated soong_module.bzl:\n%s",
actualSoongModuleBzl.Contents,
expectedLoad)
}
if !strings.Contains(actualSoongModuleBzl.Contents, expectedRuleMap) {
t.Errorf(
"Generated soong_module.bzl:\n\n%s\n\n"+
"Could not find the module -> rule map in the generated soong_module.bzl:\n%s",
actualSoongModuleBzl.Contents,
expectedRuleMap)
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,486 +0,0 @@
// 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/cc"
)
const (
// See cc/testing.go for more context
soongCcLibraryHeadersPreamble = `
cc_defaults {
name: "linux_bionic_supported",
}`
)
func TestCcLibraryHeadersLoadStatement(t *testing.T) {
testCases := []struct {
bazelTargets BazelTargets
expectedLoadStatements string
}{
{
bazelTargets: BazelTargets{
BazelTarget{
name: "cc_library_headers_target",
ruleClass: "cc_library_headers",
// Note: no bzlLoadLocation for native rules
},
},
expectedLoadStatements: ``,
},
}
for _, testCase := range testCases {
actual := testCase.bazelTargets.LoadStatements()
expected := testCase.expectedLoadStatements
if actual != expected {
t.Fatalf("Expected load statements to be %s, got %s", expected, actual)
}
}
}
func registerCcLibraryHeadersModuleTypes(ctx android.RegistrationContext) {
cc.RegisterCCBuildComponents(ctx)
cc.RegisterLibraryHeadersBuildComponents(ctx)
ctx.RegisterModuleType("cc_library_shared", cc.LibrarySharedFactory)
}
func runCcLibraryHeadersTestCase(t *testing.T, tc Bp2buildTestCase) {
t.Helper()
RunBp2BuildTestCase(t, registerCcLibraryHeadersModuleTypes, tc)
}
func TestCcLibraryHeadersSimple(t *testing.T) {
runCcLibraryHeadersTestCase(t, Bp2buildTestCase{
Description: "cc_library_headers test",
Filesystem: map[string]string{
"dir-1/dir1a.h": "",
"dir-1/dir1b.h": "",
"dir-2/dir2a.h": "",
"dir-2/dir2b.h": "",
"arch_arm64_exported_include_dir/a.h": "",
"arch_x86_exported_include_dir/b.h": "",
"arch_x86_64_exported_include_dir/c.h": "",
},
Blueprint: soongCcLibraryHeadersPreamble + `
cc_library_headers {
name: "foo_headers",
export_include_dirs: ["dir-1", "dir-2"],
arch: {
arm64: {
// We expect dir-1 headers to be dropped, because dir-1 is already in export_include_dirs
export_include_dirs: ["arch_arm64_exported_include_dir", "dir-1"],
},
x86: {
export_include_dirs: ["arch_x86_exported_include_dir"],
},
x86_64: {
export_include_dirs: ["arch_x86_64_exported_include_dir"],
},
},
sdk_version: "current",
min_sdk_version: "29",
// TODO: Also support export_header_lib_headers
}`,
ExpectedBazelTargets: []string{
MakeBazelTarget("cc_library_headers", "foo_headers", AttrNameToString{
"export_includes": `select({
"//build/bazel_common_rules/platforms/arch:arm64": ["arch_arm64_exported_include_dir"],
"//build/bazel_common_rules/platforms/arch:x86": ["arch_x86_exported_include_dir"],
"//build/bazel_common_rules/platforms/arch:x86_64": ["arch_x86_64_exported_include_dir"],
"//conditions:default": [],
}) + [
"dir-1",
"dir-2",
]`,
"sdk_version": `"current"`,
"min_sdk_version": `"29"`,
"deps": `select({
"//build/bazel/rules/apex:unbundled_app": ["//build/bazel/rules/cc:ndk_sysroot"],
"//conditions:default": [],
})`,
}),
},
})
}
// header_libs has "variant_prepend" tag. In bp2build output,
// variant info(select) should go before general info.
func TestCcLibraryHeadersOsSpecificHeader(t *testing.T) {
runCcLibraryHeadersTestCase(t, Bp2buildTestCase{
Description: "cc_library_headers test with os-specific header_libs props",
Filesystem: map[string]string{},
StubbedBuildDefinitions: []string{"android-lib", "base-lib", "darwin-lib",
"linux-lib", "linux_bionic-lib", "windows-lib"},
Blueprint: soongCcLibraryPreamble + `
cc_library_headers {
name: "android-lib",
}
cc_library_headers {
name: "base-lib",
}
cc_library_headers {
name: "darwin-lib",
}
cc_library_headers {
name: "linux-lib",
}
cc_library_headers {
name: "linux_bionic-lib",
}
cc_library_headers {
name: "windows-lib",
}
cc_library_headers {
name: "foo_headers",
header_libs: ["base-lib"],
export_header_lib_headers: ["base-lib"],
target: {
android: {
header_libs: ["android-lib"],
export_header_lib_headers: ["android-lib"],
},
darwin: {
header_libs: ["darwin-lib"],
export_header_lib_headers: ["darwin-lib"],
},
linux_bionic: {
header_libs: ["linux_bionic-lib"],
export_header_lib_headers: ["linux_bionic-lib"],
},
linux_glibc: {
header_libs: ["linux-lib"],
export_header_lib_headers: ["linux-lib"],
},
windows: {
header_libs: ["windows-lib"],
export_header_lib_headers: ["windows-lib"],
},
},
include_build_directory: false,
}`,
ExpectedBazelTargets: []string{
MakeBazelTarget("cc_library_headers", "foo_headers", AttrNameToString{
"deps": `select({
"//build/bazel_common_rules/platforms/os:android": [":android-lib"],
"//build/bazel_common_rules/platforms/os:darwin": [":darwin-lib"],
"//build/bazel_common_rules/platforms/os:linux_bionic": [":linux_bionic-lib"],
"//build/bazel_common_rules/platforms/os:linux_glibc": [":linux-lib"],
"//build/bazel_common_rules/platforms/os:windows": [":windows-lib"],
"//conditions:default": [],
}) + [":base-lib"]`,
}),
},
})
}
func TestCcLibraryHeadersOsSpecficHeaderLibsExportHeaderLibHeaders(t *testing.T) {
runCcLibraryHeadersTestCase(t, Bp2buildTestCase{
Description: "cc_library_headers test with os-specific header_libs and export_header_lib_headers props",
Filesystem: map[string]string{},
StubbedBuildDefinitions: []string{"android-lib", "exported-lib"},
Blueprint: soongCcLibraryPreamble + `
cc_library_headers {
name: "android-lib",
}
cc_library_headers {
name: "exported-lib",
}
cc_library_headers {
name: "foo_headers",
target: {
android: {
header_libs: ["android-lib", "exported-lib"],
export_header_lib_headers: ["exported-lib"]
},
},
include_build_directory: false,
}`,
ExpectedBazelTargets: []string{
MakeBazelTarget("cc_library_headers", "foo_headers", AttrNameToString{
"deps": `select({
"//build/bazel_common_rules/platforms/os:android": [":exported-lib"],
"//conditions:default": [],
})`,
}),
},
})
}
func TestCcLibraryHeadersArchAndTargetExportSystemIncludes(t *testing.T) {
runCcLibraryHeadersTestCase(t, Bp2buildTestCase{
Description: "cc_library_headers test with arch-specific and target-specific export_system_include_dirs props",
Filesystem: map[string]string{},
Blueprint: soongCcLibraryPreamble + `cc_library_headers {
name: "foo_headers",
export_system_include_dirs: [
"shared_include_dir",
],
target: {
android: {
export_system_include_dirs: [
"android_include_dir",
],
},
linux_glibc: {
export_system_include_dirs: [
"linux_include_dir",
],
},
darwin: {
export_system_include_dirs: [
"darwin_include_dir",
],
},
},
arch: {
arm: {
export_system_include_dirs: [
"arm_include_dir",
],
},
x86_64: {
export_system_include_dirs: [
"x86_64_include_dir",
],
},
},
include_build_directory: false,
}`,
ExpectedBazelTargets: []string{
MakeBazelTarget("cc_library_headers", "foo_headers", AttrNameToString{
"export_system_includes": `select({
"//build/bazel_common_rules/platforms/os:android": ["android_include_dir"],
"//build/bazel_common_rules/platforms/os:darwin": ["darwin_include_dir"],
"//build/bazel_common_rules/platforms/os:linux_glibc": ["linux_include_dir"],
"//conditions:default": [],
}) + select({
"//build/bazel_common_rules/platforms/arch:arm": ["arm_include_dir"],
"//build/bazel_common_rules/platforms/arch:x86_64": ["x86_64_include_dir"],
"//conditions:default": [],
}) + ["shared_include_dir"]`,
}),
},
})
}
func TestCcLibraryHeadersNoCrtIgnored(t *testing.T) {
runCcLibraryHeadersTestCase(t, Bp2buildTestCase{
Description: "cc_library_headers test",
Filesystem: map[string]string{
"lib-1/lib1a.h": "",
"lib-1/lib1b.h": "",
"lib-2/lib2a.h": "",
"lib-2/lib2b.h": "",
"dir-1/dir1a.h": "",
"dir-1/dir1b.h": "",
"dir-2/dir2a.h": "",
"dir-2/dir2b.h": "",
"arch_arm64_exported_include_dir/a.h": "",
"arch_x86_exported_include_dir/b.h": "",
"arch_x86_64_exported_include_dir/c.h": "",
},
Blueprint: soongCcLibraryHeadersPreamble + `
cc_library_headers {
name: "lib-1",
export_include_dirs: ["lib-1"],
no_libcrt: true,
include_build_directory: false,
}`,
ExpectedBazelTargets: []string{
MakeBazelTarget("cc_library_headers", "lib-1", AttrNameToString{
"export_includes": `["lib-1"]`,
}),
},
})
}
func TestCcLibraryHeadersExportedStaticLibHeadersReexported(t *testing.T) {
runCcLibraryHeadersTestCase(t, Bp2buildTestCase{
Description: "cc_library_headers exported_static_lib_headers is reexported",
Filesystem: map[string]string{},
StubbedBuildDefinitions: []string{"foo_export", "foo_no_reexport"},
Blueprint: soongCcLibraryHeadersPreamble + `
cc_library_headers {
name: "foo_headers",
export_static_lib_headers: ["foo_export"],
static_libs: ["foo_export", "foo_no_reexport"],
bazel_module: { bp2build_available: true },
}
` + simpleModule("cc_library_headers", "foo_export") +
simpleModule("cc_library_headers", "foo_no_reexport"),
ExpectedBazelTargets: []string{
MakeBazelTarget("cc_library_headers", "foo_headers", AttrNameToString{
"deps": `[":foo_export"]`,
}),
},
})
}
func TestCcLibraryHeadersExportedSharedLibHeadersReexported(t *testing.T) {
runCcLibraryHeadersTestCase(t, Bp2buildTestCase{
Description: "cc_library_headers exported_shared_lib_headers is reexported",
Filesystem: map[string]string{},
StubbedBuildDefinitions: []string{"foo_export", "foo_no_reexport"},
Blueprint: soongCcLibraryHeadersPreamble + `
cc_library_headers {
name: "foo_headers",
export_shared_lib_headers: ["foo_export"],
shared_libs: ["foo_export", "foo_no_reexport"],
bazel_module: { bp2build_available: true },
}
` + simpleModule("cc_library_headers", "foo_export") +
simpleModule("cc_library_headers", "foo_no_reexport"),
ExpectedBazelTargets: []string{
MakeBazelTarget("cc_library_headers", "foo_headers", AttrNameToString{
"deps": `[":foo_export"]`,
}),
},
})
}
func TestCcLibraryHeadersExportedHeaderLibHeadersReexported(t *testing.T) {
runCcLibraryHeadersTestCase(t, Bp2buildTestCase{
Description: "cc_library_headers exported_header_lib_headers is reexported",
Filesystem: map[string]string{},
StubbedBuildDefinitions: []string{"foo_export", "foo_no_reexport"},
Blueprint: soongCcLibraryHeadersPreamble + `
cc_library_headers {
name: "foo_headers",
export_header_lib_headers: ["foo_export"],
header_libs: ["foo_export", "foo_no_reexport"],
bazel_module: { bp2build_available: true },
}
` + simpleModule("cc_library_headers", "foo_export") +
simpleModule("cc_library_headers", "foo_no_reexport"),
ExpectedBazelTargets: []string{
MakeBazelTarget("cc_library_headers", "foo_headers", AttrNameToString{
"deps": `[":foo_export"]`,
}),
},
})
}
func TestCcLibraryHeadersWholeStaticLibsReexported(t *testing.T) {
runCcLibraryHeadersTestCase(t, Bp2buildTestCase{
Description: "cc_library_headers whole_static_libs is reexported",
Filesystem: map[string]string{},
StubbedBuildDefinitions: []string{"foo_export"},
Blueprint: soongCcLibraryHeadersPreamble + `
cc_library_headers {
name: "foo_headers",
whole_static_libs: ["foo_export"],
bazel_module: { bp2build_available: true },
}
` + simpleModule("cc_library_headers", "foo_export"),
ExpectedBazelTargets: []string{
MakeBazelTarget("cc_library_headers", "foo_headers", AttrNameToString{
"deps": `[":foo_export"]`,
}),
},
})
}
func TestPrebuiltCcLibraryHeadersWholeStaticLibsReexported(t *testing.T) {
runCcLibraryHeadersTestCase(t, Bp2buildTestCase{
Description: "cc_library_headers whole_static_libs is reexported",
Filesystem: map[string]string{
"foo/bar/Android.bp": simpleModule("cc_library_headers", "foo_headers"),
},
StubbedBuildDefinitions: []string{"foo_export"},
Blueprint: soongCcLibraryHeadersPreamble + `
cc_prebuilt_library_headers {
name: "foo_headers",
whole_static_libs: ["foo_export"],
bazel_module: { bp2build_available: true },
}
` + simpleModule("cc_library_headers", "foo_export"),
ExpectedBazelTargets: []string{
MakeBazelTarget("cc_library_headers", "foo_headers", AttrNameToString{
"deps": `[":foo_export"]`,
}),
},
})
}
func TestPrebuiltCcLibraryHeadersPreferredRdepUpdated(t *testing.T) {
runCcLibraryHeadersTestCase(t, Bp2buildTestCase{
Description: "cc_library_headers prebuilt preferred is used as rdep",
StubbedBuildDefinitions: []string{"foo_export", "//foo/bar:foo_headers"},
Filesystem: map[string]string{
"foo/bar/Android.bp": simpleModule("cc_library_headers", "foo_headers"),
},
Blueprint: soongCcLibraryHeadersPreamble + `
cc_prebuilt_library_headers {
name: "foo_headers",
whole_static_libs: ["foo_export"],
bazel_module: { bp2build_available: true },
prefer: true,
}
cc_library_shared {
name: "foo",
header_libs: ["foo_headers"],
include_build_directory: false,
}
` + simpleModule("cc_library_headers", "foo_export"),
ExpectedBazelTargets: []string{
MakeBazelTarget("cc_library_headers", "foo_headers", AttrNameToString{
"deps": `[":foo_export"]`,
}),
MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
"implementation_deps": `[":foo_headers"]`,
}),
},
})
}
func TestPrebuiltCcLibraryHeadersRdepUpdated(t *testing.T) {
runCcLibraryHeadersTestCase(t, Bp2buildTestCase{
Description: "cc_library_headers not preferred is not used for rdep",
StubbedBuildDefinitions: []string{"foo_export", "//foo/bar:foo_headers"},
Filesystem: map[string]string{
"foo/bar/Android.bp": simpleModule("cc_library_headers", "foo_headers"),
},
Blueprint: soongCcLibraryHeadersPreamble + `
cc_prebuilt_library_headers {
name: "foo_headers",
whole_static_libs: ["foo_export"],
bazel_module: { bp2build_available: true },
prefer: false,
}
cc_library_shared {
name: "foo",
header_libs: ["foo_headers"],
include_build_directory: false,
}
` + simpleModule("cc_library_headers", "foo_export"),
ExpectedBazelTargets: []string{
MakeBazelTarget("cc_library_headers", "foo_headers", AttrNameToString{
"deps": `[":foo_export"]`,
}),
MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
"implementation_deps": `["//foo/bar:foo_headers"]`,
}),
},
})
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,478 +0,0 @@
// 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/cc"
)
func registerCcObjectModuleTypes(ctx android.RegistrationContext) {
// Always register cc_defaults module factory
ctx.RegisterModuleType("cc_defaults", func() android.Module { return cc.DefaultsFactory() })
ctx.RegisterModuleType("cc_library_headers", cc.LibraryHeaderFactory)
}
func runCcObjectTestCase(t *testing.T, tc Bp2buildTestCase) {
t.Helper()
(&tc).ModuleTypeUnderTest = "cc_object"
(&tc).ModuleTypeUnderTestFactory = cc.ObjectFactory
RunBp2BuildTestCase(t, registerCcObjectModuleTypes, tc)
}
func TestCcObjectSimple(t *testing.T) {
runCcObjectTestCase(t, Bp2buildTestCase{
Description: "simple cc_object generates cc_object with include header dep",
Filesystem: map[string]string{
"a/b/foo.h": "",
"a/b/bar.h": "",
"a/b/exclude.c": "",
"a/b/c.c": "",
},
Blueprint: `cc_object {
name: "foo",
local_include_dirs: ["include"],
system_shared_libs: [],
cflags: [
"-Wno-gcc-compat",
"-Wall",
"-Werror",
],
srcs: [
"a/b/*.c"
],
exclude_srcs: ["a/b/exclude.c"],
sdk_version: "current",
min_sdk_version: "29",
crt: true,
}
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("cc_object", "foo", AttrNameToString{
"copts": `[
"-fno-addrsig",
"-Wno-gcc-compat",
"-Wall",
"-Werror",
]`,
"local_includes": `[
"include",
".",
]`,
"srcs": `["a/b/c.c"]`,
"system_dynamic_deps": `[]`,
"sdk_version": `"current"`,
"min_sdk_version": `"29"`,
"crt": "True",
}),
},
})
}
func TestCcObjectDefaults(t *testing.T) {
runCcObjectTestCase(t, Bp2buildTestCase{
Blueprint: `cc_object {
name: "foo",
system_shared_libs: [],
srcs: [
"a/b/*.h",
"a/b/c.c"
],
defaults: ["foo_defaults"],
}
cc_defaults {
name: "foo_defaults",
defaults: ["foo_bar_defaults"],
}
cc_defaults {
name: "foo_bar_defaults",
cflags: [
"-Werror",
],
}
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("cc_object", "foo", AttrNameToString{
"copts": `[
"-Werror",
"-fno-addrsig",
]`,
"local_includes": `["."]`,
"srcs": `["a/b/c.c"]`,
"system_dynamic_deps": `[]`,
}),
}})
}
func TestCcObjectCcObjetDepsInObjs(t *testing.T) {
runCcObjectTestCase(t, Bp2buildTestCase{
Description: "cc_object with cc_object deps in objs props",
Filesystem: map[string]string{
"a/b/c.c": "",
"x/y/z.c": "",
},
Blueprint: `cc_object {
name: "foo",
system_shared_libs: [],
srcs: ["a/b/c.c"],
objs: ["bar"],
include_build_directory: false,
}
cc_object {
name: "bar",
system_shared_libs: [],
srcs: ["x/y/z.c"],
include_build_directory: false,
}
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("cc_object", "bar", AttrNameToString{
"copts": `["-fno-addrsig"]`,
"srcs": `["x/y/z.c"]`,
"system_dynamic_deps": `[]`,
}), MakeBazelTarget("cc_object", "foo", AttrNameToString{
"copts": `["-fno-addrsig"]`,
"objs": `[":bar"]`,
"srcs": `["a/b/c.c"]`,
"system_dynamic_deps": `[]`,
}),
},
})
}
func TestCcObjectIncludeBuildDirFalse(t *testing.T) {
runCcObjectTestCase(t, Bp2buildTestCase{
Description: "cc_object with include_build_dir: false",
Filesystem: map[string]string{
"a/b/c.c": "",
"x/y/z.c": "",
},
Blueprint: `cc_object {
name: "foo",
system_shared_libs: [],
srcs: ["a/b/c.c"],
include_build_directory: false,
}
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("cc_object", "foo", AttrNameToString{
"copts": `["-fno-addrsig"]`,
"srcs": `["a/b/c.c"]`,
"system_dynamic_deps": `[]`,
}),
},
})
}
func TestCcObjectProductVariable(t *testing.T) {
runCcObjectTestCase(t, Bp2buildTestCase{
Description: "cc_object with product variable",
Blueprint: `cc_object {
name: "foo",
system_shared_libs: [],
include_build_directory: false,
product_variables: {
platform_sdk_version: {
asflags: ["-DPLATFORM_SDK_VERSION=%d"],
},
},
srcs: ["src.S"],
}
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("cc_object", "foo", AttrNameToString{
"asflags": `select({
"//build/bazel/product_config/config_settings:platform_sdk_version": ["-DPLATFORM_SDK_VERSION=$(Platform_sdk_version)"],
"//conditions:default": [],
})`,
"copts": `["-fno-addrsig"]`,
"srcs_as": `["src.S"]`,
"system_dynamic_deps": `[]`,
}),
},
})
}
func TestCcObjectCflagsOneArch(t *testing.T) {
runCcObjectTestCase(t, Bp2buildTestCase{
Description: "cc_object setting cflags for one arch",
Blueprint: `cc_object {
name: "foo",
system_shared_libs: [],
srcs: ["a.cpp"],
arch: {
x86: {
cflags: ["-fPIC"], // string list
},
arm: {
srcs: ["arch/arm/file.cpp"], // label list
},
},
include_build_directory: false,
}
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("cc_object", "foo", AttrNameToString{
"copts": `["-fno-addrsig"] + select({
"//build/bazel_common_rules/platforms/arch:x86": ["-fPIC"],
"//conditions:default": [],
})`,
"srcs": `["a.cpp"] + select({
"//build/bazel_common_rules/platforms/arch:arm": ["arch/arm/file.cpp"],
"//conditions:default": [],
})`,
"system_dynamic_deps": `[]`,
}),
},
})
}
func TestCcObjectCflagsFourArch(t *testing.T) {
runCcObjectTestCase(t, Bp2buildTestCase{
Description: "cc_object setting cflags for 4 architectures",
Blueprint: `cc_object {
name: "foo",
system_shared_libs: [],
srcs: ["base.cpp"],
arch: {
x86: {
srcs: ["x86.cpp"],
cflags: ["-fPIC"],
},
x86_64: {
srcs: ["x86_64.cpp"],
cflags: ["-fPIC"],
},
arm: {
srcs: ["arm.cpp"],
cflags: ["-Wall"],
},
arm64: {
srcs: ["arm64.cpp"],
cflags: ["-Wall"],
},
},
include_build_directory: false,
}
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("cc_object", "foo", AttrNameToString{
"copts": `["-fno-addrsig"] + select({
"//build/bazel_common_rules/platforms/arch:arm": ["-Wall"],
"//build/bazel_common_rules/platforms/arch:arm64": ["-Wall"],
"//build/bazel_common_rules/platforms/arch:x86": ["-fPIC"],
"//build/bazel_common_rules/platforms/arch:x86_64": ["-fPIC"],
"//conditions:default": [],
})`,
"srcs": `["base.cpp"] + select({
"//build/bazel_common_rules/platforms/arch:arm": ["arm.cpp"],
"//build/bazel_common_rules/platforms/arch:arm64": ["arm64.cpp"],
"//build/bazel_common_rules/platforms/arch:x86": ["x86.cpp"],
"//build/bazel_common_rules/platforms/arch:x86_64": ["x86_64.cpp"],
"//conditions:default": [],
})`,
"system_dynamic_deps": `[]`,
}),
},
})
}
func TestCcObjectLinkerScript(t *testing.T) {
runCcObjectTestCase(t, Bp2buildTestCase{
Description: "cc_object setting linker_script",
Blueprint: `cc_object {
name: "foo",
srcs: ["base.cpp"],
linker_script: "bunny.lds",
include_build_directory: false,
}
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("cc_object", "foo", AttrNameToString{
"copts": `["-fno-addrsig"]`,
"linker_script": `"bunny.lds"`,
"srcs": `["base.cpp"]`,
}),
},
})
}
func TestCcObjectDepsAndLinkerScriptSelects(t *testing.T) {
runCcObjectTestCase(t, Bp2buildTestCase{
Description: "cc_object setting deps and linker_script across archs",
StubbedBuildDefinitions: []string{"x86_obj", "x86_64_obj", "arm_obj"},
Blueprint: `cc_object {
name: "foo",
srcs: ["base.cpp"],
arch: {
x86: {
objs: ["x86_obj"],
linker_script: "x86.lds",
},
x86_64: {
objs: ["x86_64_obj"],
linker_script: "x86_64.lds",
},
arm: {
objs: ["arm_obj"],
linker_script: "arm.lds",
},
},
include_build_directory: false,
}
cc_object {
name: "x86_obj",
system_shared_libs: [],
srcs: ["x86.cpp"],
include_build_directory: false,
}
cc_object {
name: "x86_64_obj",
system_shared_libs: [],
srcs: ["x86_64.cpp"],
include_build_directory: false,
}
cc_object {
name: "arm_obj",
system_shared_libs: [],
srcs: ["arm.cpp"],
include_build_directory: false,
}
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("cc_object", "foo", AttrNameToString{
"copts": `["-fno-addrsig"]`,
"objs": `select({
"//build/bazel_common_rules/platforms/arch:arm": [":arm_obj"],
"//build/bazel_common_rules/platforms/arch:x86": [":x86_obj"],
"//build/bazel_common_rules/platforms/arch:x86_64": [":x86_64_obj"],
"//conditions:default": [],
})`,
"linker_script": `select({
"//build/bazel_common_rules/platforms/arch:arm": "arm.lds",
"//build/bazel_common_rules/platforms/arch:x86": "x86.lds",
"//build/bazel_common_rules/platforms/arch:x86_64": "x86_64.lds",
"//conditions:default": None,
})`,
"srcs": `["base.cpp"]`,
}),
},
})
}
func TestCcObjectSelectOnLinuxAndBionicArchs(t *testing.T) {
runCcObjectTestCase(t, Bp2buildTestCase{
Description: "cc_object setting srcs based on linux and bionic archs",
Blueprint: `cc_object {
name: "foo",
srcs: ["base.cpp"],
target: {
linux_arm64: {
srcs: ["linux_arm64.cpp",]
},
linux_x86: {
srcs: ["linux_x86.cpp",]
},
bionic_arm64: {
srcs: ["bionic_arm64.cpp",]
},
},
include_build_directory: false,
}
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("cc_object", "foo", AttrNameToString{
"copts": `["-fno-addrsig"]`,
"srcs": `["base.cpp"] + select({
"//build/bazel_common_rules/platforms/os_arch:android_arm64": [
"linux_arm64.cpp",
"bionic_arm64.cpp",
],
"//build/bazel_common_rules/platforms/os_arch:android_x86": ["linux_x86.cpp"],
"//build/bazel_common_rules/platforms/os_arch:linux_bionic_arm64": [
"linux_arm64.cpp",
"bionic_arm64.cpp",
],
"//build/bazel_common_rules/platforms/os_arch:linux_glibc_x86": ["linux_x86.cpp"],
"//build/bazel_common_rules/platforms/os_arch:linux_musl_arm64": ["linux_arm64.cpp"],
"//build/bazel_common_rules/platforms/os_arch:linux_musl_x86": ["linux_x86.cpp"],
"//conditions:default": [],
})`,
}),
},
})
}
func TestCcObjectHeaderLib(t *testing.T) {
runCcObjectTestCase(t, Bp2buildTestCase{
Description: "simple cc_object generates cc_object with include header dep",
Filesystem: map[string]string{
"a/b/foo.h": "",
"a/b/bar.h": "",
"a/b/exclude.c": "",
"a/b/c.c": "",
},
Blueprint: `cc_object {
name: "foo",
header_libs: ["libheaders"],
system_shared_libs: [],
cflags: [
"-Wno-gcc-compat",
"-Wall",
"-Werror",
],
srcs: [
"a/b/*.c"
],
exclude_srcs: ["a/b/exclude.c"],
sdk_version: "current",
min_sdk_version: "29",
}
cc_library_headers {
name: "libheaders",
export_include_dirs: ["include"],
}
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("cc_object", "foo", AttrNameToString{
"copts": `[
"-fno-addrsig",
"-Wno-gcc-compat",
"-Wall",
"-Werror",
]`,
"deps": `[":libheaders"]`,
"local_includes": `["."]`,
"srcs": `["a/b/c.c"]`,
"system_dynamic_deps": `[]`,
"sdk_version": `"current"`,
"min_sdk_version": `"29"`,
}),
MakeBazelTarget("cc_library_headers", "libheaders", AttrNameToString{
"export_includes": `["include"]`,
}),
},
})
}

View File

@@ -1,125 +0,0 @@
// Copyright 2022 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 (
"fmt"
"testing"
"android/soong/cc"
)
func runCcPrebuiltBinaryTestCase(t *testing.T, testCase Bp2buildTestCase) {
t.Helper()
description := fmt.Sprintf("cc_prebuilt_binary: %s", testCase.Description)
testCase.ModuleTypeUnderTest = "cc_prebuilt_binary"
testCase.ModuleTypeUnderTestFactory = cc.PrebuiltBinaryFactory
testCase.Description = description
t.Run(description, func(t *testing.T) {
t.Helper()
RunBp2BuildTestCaseSimple(t, testCase)
})
}
func TestPrebuiltBinary(t *testing.T) {
runCcPrebuiltBinaryTestCase(t,
Bp2buildTestCase{
Description: "simple",
Filesystem: map[string]string{
"bin": "",
},
Blueprint: `
cc_prebuilt_binary {
name: "bintest",
srcs: ["bin"],
bazel_module: { bp2build_available: true },
}`,
ExpectedBazelTargets: []string{
MakeBazelTarget("cc_prebuilt_binary", "bintest", AttrNameToString{
"src": `"bin"`,
})},
})
}
func TestPrebuiltBinaryWithStrip(t *testing.T) {
runCcPrebuiltBinaryTestCase(t,
Bp2buildTestCase{
Description: "with strip",
Filesystem: map[string]string{
"bin": "",
},
Blueprint: `
cc_prebuilt_binary {
name: "bintest",
srcs: ["bin"],
strip: { all: true },
bazel_module: { bp2build_available: true },
}`, ExpectedBazelTargets: []string{
MakeBazelTarget("cc_prebuilt_binary", "bintest", AttrNameToString{
"src": `"bin"`,
"strip": `{
"all": True,
}`,
}),
},
})
}
func TestPrebuiltBinaryWithArchVariance(t *testing.T) {
runCcPrebuiltBinaryTestCase(t,
Bp2buildTestCase{
Description: "with arch variance",
Filesystem: map[string]string{
"bina": "",
"binb": "",
},
Blueprint: `
cc_prebuilt_binary {
name: "bintest",
arch: {
arm64: { srcs: ["bina"], },
arm: { srcs: ["binb"], },
},
bazel_module: { bp2build_available: true },
}`, ExpectedBazelTargets: []string{
MakeBazelTarget("cc_prebuilt_binary", "bintest", AttrNameToString{
"src": `select({
"//build/bazel_common_rules/platforms/arch:arm": "binb",
"//build/bazel_common_rules/platforms/arch:arm64": "bina",
"//conditions:default": None,
})`,
}),
},
})
}
func TestPrebuiltBinaryMultipleSrcsFails(t *testing.T) {
runCcPrebuiltBinaryTestCase(t,
Bp2buildTestCase{
Description: "fails because multiple sources",
Filesystem: map[string]string{
"bina": "",
"binb": "",
},
Blueprint: `
cc_prebuilt_binary {
name: "bintest",
srcs: ["bina", "binb"],
bazel_module: { bp2build_available: true },
}`,
ExpectedErr: fmt.Errorf("Expected at most one source file"),
})
}
// TODO: nosrcs test

View File

@@ -1,412 +0,0 @@
// Copyright 2022 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 (
"fmt"
"testing"
"android/soong/android"
"android/soong/cc"
)
func runCcPrebuiltLibraryTestCase(t *testing.T, tc Bp2buildTestCase) {
t.Helper()
(&tc).ModuleTypeUnderTest = "cc_prebuilt_library"
(&tc).ModuleTypeUnderTestFactory = cc.PrebuiltLibraryFactory
RunBp2BuildTestCaseSimple(t, tc)
}
func TestPrebuiltLibraryStaticAndSharedSimple(t *testing.T) {
runCcPrebuiltLibraryTestCase(t,
Bp2buildTestCase{
Description: "prebuilt library static and shared simple",
Filesystem: map[string]string{
"libf.so": "",
},
Blueprint: `
cc_prebuilt_library {
name: "libtest",
srcs: ["libf.so"],
bazel_module: { bp2build_available: true },
}`,
ExpectedBazelTargets: []string{
MakeBazelTarget("cc_prebuilt_library_static", "libtest_bp2build_cc_library_static", AttrNameToString{
"static_library": `"libf.so"`,
}),
MakeBazelTarget("cc_prebuilt_library_static", "libtest_bp2build_cc_library_static_alwayslink", AttrNameToString{
"static_library": `"libf.so"`,
"alwayslink": "True",
}),
MakeBazelTarget("cc_prebuilt_library_shared", "libtest", AttrNameToString{
"shared_library": `"libf.so"`,
}),
},
})
}
func TestPrebuiltLibraryWithArchVariance(t *testing.T) {
runCcPrebuiltLibraryTestCase(t,
Bp2buildTestCase{
Description: "prebuilt library with arch variance",
Filesystem: map[string]string{
"libf.so": "",
"libg.so": "",
},
Blueprint: `
cc_prebuilt_library {
name: "libtest",
arch: {
arm64: { srcs: ["libf.so"], },
arm: { srcs: ["libg.so"], },
},
bazel_module: { bp2build_available: true },
}`,
ExpectedBazelTargets: []string{
MakeBazelTarget("cc_prebuilt_library_static", "libtest_bp2build_cc_library_static", AttrNameToString{
"static_library": `select({
"//build/bazel_common_rules/platforms/arch:arm": "libg.so",
"//build/bazel_common_rules/platforms/arch:arm64": "libf.so",
"//conditions:default": None,
})`}),
MakeBazelTarget("cc_prebuilt_library_static", "libtest_bp2build_cc_library_static_alwayslink", AttrNameToString{
"alwayslink": "True",
"static_library": `select({
"//build/bazel_common_rules/platforms/arch:arm": "libg.so",
"//build/bazel_common_rules/platforms/arch:arm64": "libf.so",
"//conditions:default": None,
})`}),
MakeBazelTarget("cc_prebuilt_library_shared", "libtest", AttrNameToString{
"shared_library": `select({
"//build/bazel_common_rules/platforms/arch:arm": "libg.so",
"//build/bazel_common_rules/platforms/arch:arm64": "libf.so",
"//conditions:default": None,
})`,
}),
},
})
}
func TestPrebuiltLibraryAdditionalAttrs(t *testing.T) {
runCcPrebuiltLibraryTestCase(t,
Bp2buildTestCase{
Description: "prebuilt library additional attributes",
Filesystem: map[string]string{
"libf.so": "",
"testdir/1/include.h": "",
"testdir/2/other.h": "",
},
Blueprint: `
cc_prebuilt_library {
name: "libtest",
srcs: ["libf.so"],
export_include_dirs: ["testdir/1/"],
export_system_include_dirs: ["testdir/2/"],
bazel_module: { bp2build_available: true },
}`,
ExpectedBazelTargets: []string{
MakeBazelTarget("cc_prebuilt_library_static", "libtest_bp2build_cc_library_static", AttrNameToString{
"static_library": `"libf.so"`,
"export_includes": `["testdir/1/"]`,
"export_system_includes": `["testdir/2/"]`,
}),
MakeBazelTarget("cc_prebuilt_library_static", "libtest_bp2build_cc_library_static_alwayslink", AttrNameToString{
"static_library": `"libf.so"`,
"export_includes": `["testdir/1/"]`,
"export_system_includes": `["testdir/2/"]`,
"alwayslink": "True",
}),
MakeBazelTarget("cc_prebuilt_library_shared", "libtest", AttrNameToString{
"shared_library": `"libf.so"`,
"export_includes": `["testdir/1/"]`,
"export_system_includes": `["testdir/2/"]`,
}),
},
})
}
func TestPrebuiltLibrarySharedStanzaFails(t *testing.T) {
runCcPrebuiltLibraryTestCase(t,
Bp2buildTestCase{
Description: "prebuilt library with shared stanza fails because multiple sources",
Filesystem: map[string]string{
"libf.so": "",
"libg.so": "",
},
Blueprint: `
cc_prebuilt_library {
name: "libtest",
srcs: ["libf.so"],
shared: {
srcs: ["libg.so"],
},
bazel_module: { bp2build_available: true },
}`,
ExpectedErr: fmt.Errorf("Expected at most one source file"),
})
}
func TestPrebuiltLibraryStaticStanzaFails(t *testing.T) {
RunBp2BuildTestCaseSimple(t,
Bp2buildTestCase{
Description: "prebuilt library with static stanza fails because multiple sources",
ModuleTypeUnderTest: "cc_prebuilt_library",
ModuleTypeUnderTestFactory: cc.PrebuiltLibraryFactory,
Filesystem: map[string]string{
"libf.so": "",
"libg.so": "",
},
Blueprint: `
cc_prebuilt_library {
name: "libtest",
srcs: ["libf.so"],
static: {
srcs: ["libg.so"],
},
bazel_module: { bp2build_available: true },
}`,
ExpectedErr: fmt.Errorf("Expected at most one source file"),
})
}
func TestPrebuiltLibrarySharedAndStaticStanzas(t *testing.T) {
runCcPrebuiltLibraryTestCase(t,
Bp2buildTestCase{
Description: "prebuilt library with both shared and static stanzas",
Filesystem: map[string]string{
"libf.so": "",
"libg.so": "",
},
Blueprint: `
cc_prebuilt_library {
name: "libtest",
static: {
srcs: ["libf.so"],
},
shared: {
srcs: ["libg.so"],
},
bazel_module: { bp2build_available: true },
}`,
ExpectedBazelTargets: []string{
MakeBazelTarget("cc_prebuilt_library_static", "libtest_bp2build_cc_library_static", AttrNameToString{
"static_library": `"libf.so"`,
}),
MakeBazelTarget("cc_prebuilt_library_static", "libtest_bp2build_cc_library_static_alwayslink", AttrNameToString{
"static_library": `"libf.so"`,
"alwayslink": "True",
}),
MakeBazelTarget("cc_prebuilt_library_shared", "libtest", AttrNameToString{
"shared_library": `"libg.so"`,
}),
},
})
}
// TODO(b/228623543): When this bug is fixed, enable this test
//func TestPrebuiltLibraryOnlyShared(t *testing.T) {
// runCcPrebuiltLibraryTestCase(t,
// bp2buildTestCase{
// description: "prebuilt library shared only",
// filesystem: map[string]string{
// "libf.so": "",
// },
// blueprint: `
//cc_prebuilt_library {
// name: "libtest",
// srcs: ["libf.so"],
// static: {
// enabled: false,
// },
// bazel_module: { bp2build_available: true },
//}`,
// expectedBazelTargets: []string{
// makeBazelTarget("cc_prebuilt_library_shared", "libtest", attrNameToString{
// "shared_library": `"libf.so"`,
// }),
// },
// })
//}
// TODO(b/228623543): When this bug is fixed, enable this test
//func TestPrebuiltLibraryOnlyStatic(t *testing.T) {
// runCcPrebuiltLibraryTestCase(t,
// bp2buildTestCase{
// description: "prebuilt library static only",
// filesystem: map[string]string{
// "libf.so": "",
// },
// blueprint: `
//cc_prebuilt_library {
// name: "libtest",
// srcs: ["libf.so"],
// shared: {
// enabled: false,
// },
// bazel_module: { bp2build_available: true },
//}`,
// expectedBazelTargets: []string{
// makeBazelTarget("cc_prebuilt_library_static", "libtest_bp2build_cc_library_static", attrNameToString{
// "static_library": `"libf.so"`,
// }),
// makeBazelTarget("cc_prebuilt_library_static", "libtest_bp2build_cc_library_static_always", attrNameToString{
// "static_library": `"libf.so"`,
// "alwayslink": "True",
// }),
// },
// })
//}
func TestPrebuiltLibraryWithExportIncludesArchVariant(t *testing.T) {
runCcPrebuiltLibraryTestCase(t, Bp2buildTestCase{
Description: "cc_prebuilt_library correctly translates export_includes with arch variance",
Filesystem: map[string]string{
"libf.so": "",
"libg.so": "",
},
Blueprint: `
cc_prebuilt_library {
name: "libtest",
srcs: ["libf.so"],
arch: {
arm: { export_include_dirs: ["testdir/1/"], },
arm64: { export_include_dirs: ["testdir/2/"], },
},
bazel_module: { bp2build_available: true },
}`,
ExpectedBazelTargets: []string{
MakeBazelTarget("cc_prebuilt_library_shared", "libtest", AttrNameToString{
"shared_library": `"libf.so"`,
"export_includes": `select({
"//build/bazel_common_rules/platforms/arch:arm": ["testdir/1/"],
"//build/bazel_common_rules/platforms/arch:arm64": ["testdir/2/"],
"//conditions:default": [],
})`,
}),
MakeBazelTarget("cc_prebuilt_library_static", "libtest_bp2build_cc_library_static", AttrNameToString{
"static_library": `"libf.so"`,
"export_includes": `select({
"//build/bazel_common_rules/platforms/arch:arm": ["testdir/1/"],
"//build/bazel_common_rules/platforms/arch:arm64": ["testdir/2/"],
"//conditions:default": [],
})`,
}),
MakeBazelTarget("cc_prebuilt_library_static", "libtest_bp2build_cc_library_static_alwayslink", AttrNameToString{
"alwayslink": "True",
"static_library": `"libf.so"`,
"export_includes": `select({
"//build/bazel_common_rules/platforms/arch:arm": ["testdir/1/"],
"//build/bazel_common_rules/platforms/arch:arm64": ["testdir/2/"],
"//conditions:default": [],
})`,
}),
},
})
}
func TestPrebuiltLibraryWithExportSystemIncludesArchVariant(t *testing.T) {
runCcPrebuiltLibraryTestCase(t, Bp2buildTestCase{
Description: "cc_prebuilt_ibrary correctly translates export_system_includes with arch variance",
Filesystem: map[string]string{
"libf.so": "",
"libg.so": "",
},
Blueprint: `
cc_prebuilt_library {
name: "libtest",
srcs: ["libf.so"],
arch: {
arm: { export_system_include_dirs: ["testdir/1/"], },
arm64: { export_system_include_dirs: ["testdir/2/"], },
},
bazel_module: { bp2build_available: true },
}`,
ExpectedBazelTargets: []string{
MakeBazelTarget("cc_prebuilt_library_shared", "libtest", AttrNameToString{
"shared_library": `"libf.so"`,
"export_system_includes": `select({
"//build/bazel_common_rules/platforms/arch:arm": ["testdir/1/"],
"//build/bazel_common_rules/platforms/arch:arm64": ["testdir/2/"],
"//conditions:default": [],
})`,
}),
MakeBazelTarget("cc_prebuilt_library_static", "libtest_bp2build_cc_library_static", AttrNameToString{
"static_library": `"libf.so"`,
"export_system_includes": `select({
"//build/bazel_common_rules/platforms/arch:arm": ["testdir/1/"],
"//build/bazel_common_rules/platforms/arch:arm64": ["testdir/2/"],
"//conditions:default": [],
})`,
}),
MakeBazelTarget("cc_prebuilt_library_static", "libtest_bp2build_cc_library_static_alwayslink", AttrNameToString{
"alwayslink": "True",
"static_library": `"libf.so"`,
"export_system_includes": `select({
"//build/bazel_common_rules/platforms/arch:arm": ["testdir/1/"],
"//build/bazel_common_rules/platforms/arch:arm64": ["testdir/2/"],
"//conditions:default": [],
})`,
}),
},
})
}
func TestPrebuiltNdkStlConversion(t *testing.T) {
registerNdkStlModuleTypes := func(ctx android.RegistrationContext) {
ctx.RegisterModuleType("ndk_prebuilt_static_stl", cc.NdkPrebuiltStaticStlFactory)
ctx.RegisterModuleType("ndk_prebuilt_shared_stl", cc.NdkPrebuiltSharedStlFactory)
}
RunBp2BuildTestCase(t, registerNdkStlModuleTypes, Bp2buildTestCase{
Description: "TODO",
Blueprint: `
ndk_prebuilt_static_stl {
name: "ndk_libfoo_static",
export_include_dirs: ["dir1", "dir2"],
}
ndk_prebuilt_shared_stl {
name: "ndk_libfoo_shared",
export_include_dirs: ["dir1", "dir2"],
}`,
ExpectedBazelTargets: []string{
MakeBazelTarget("cc_prebuilt_library_static", "ndk_libfoo_static", AttrNameToString{
"static_library": `select({
"//build/bazel_common_rules/platforms/os_arch:android_arm": "current/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a/libfoo_static.a",
"//build/bazel_common_rules/platforms/os_arch:android_arm64": "current/sources/cxx-stl/llvm-libc++/libs/arm64-v8a/libfoo_static.a",
"//build/bazel_common_rules/platforms/os_arch:android_riscv64": "current/sources/cxx-stl/llvm-libc++/libs/riscv64/libfoo_static.a",
"//build/bazel_common_rules/platforms/os_arch:android_x86": "current/sources/cxx-stl/llvm-libc++/libs/x86/libfoo_static.a",
"//build/bazel_common_rules/platforms/os_arch:android_x86_64": "current/sources/cxx-stl/llvm-libc++/libs/x86_64/libfoo_static.a",
"//conditions:default": None,
})`,
"export_system_includes": `[
"dir1",
"dir2",
]`,
}),
MakeBazelTarget("cc_prebuilt_library_shared", "ndk_libfoo_shared", AttrNameToString{
"shared_library": `select({
"//build/bazel_common_rules/platforms/os_arch:android_arm": "current/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a/libfoo_shared.so",
"//build/bazel_common_rules/platforms/os_arch:android_arm64": "current/sources/cxx-stl/llvm-libc++/libs/arm64-v8a/libfoo_shared.so",
"//build/bazel_common_rules/platforms/os_arch:android_riscv64": "current/sources/cxx-stl/llvm-libc++/libs/riscv64/libfoo_shared.so",
"//build/bazel_common_rules/platforms/os_arch:android_x86": "current/sources/cxx-stl/llvm-libc++/libs/x86/libfoo_shared.so",
"//build/bazel_common_rules/platforms/os_arch:android_x86_64": "current/sources/cxx-stl/llvm-libc++/libs/x86_64/libfoo_shared.so",
"//conditions:default": None,
})`,
"export_system_includes": `[
"dir1",
"dir2",
]`,
}),
},
})
}

View File

@@ -1,165 +0,0 @@
// Copyright 2022 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/cc"
)
func runCcPrebuiltLibrarySharedTestCase(t *testing.T, tc Bp2buildTestCase) {
t.Parallel()
t.Helper()
(&tc).ModuleTypeUnderTest = "cc_prebuilt_library_shared"
(&tc).ModuleTypeUnderTestFactory = cc.PrebuiltSharedLibraryFactory
RunBp2BuildTestCaseSimple(t, tc)
}
func TestPrebuiltLibrarySharedSimple(t *testing.T) {
runCcPrebuiltLibrarySharedTestCase(t,
Bp2buildTestCase{
Description: "prebuilt library shared simple",
Filesystem: map[string]string{
"libf.so": "",
},
Blueprint: `
cc_prebuilt_library_shared {
name: "libtest",
srcs: ["libf.so"],
bazel_module: { bp2build_available: true },
}`,
ExpectedBazelTargets: []string{
MakeBazelTarget("cc_prebuilt_library_shared", "libtest", AttrNameToString{
"shared_library": `"libf.so"`,
}),
},
})
}
func TestPrebuiltLibrarySharedWithArchVariance(t *testing.T) {
runCcPrebuiltLibrarySharedTestCase(t,
Bp2buildTestCase{
Description: "prebuilt library shared with arch variance",
Filesystem: map[string]string{
"libf.so": "",
"libg.so": "",
},
Blueprint: `
cc_prebuilt_library_shared {
name: "libtest",
arch: {
arm64: { srcs: ["libf.so"], },
arm: { srcs: ["libg.so"], },
},
bazel_module: { bp2build_available: true },
}`,
ExpectedBazelTargets: []string{
MakeBazelTarget("cc_prebuilt_library_shared", "libtest", AttrNameToString{
"shared_library": `select({
"//build/bazel_common_rules/platforms/arch:arm": "libg.so",
"//build/bazel_common_rules/platforms/arch:arm64": "libf.so",
"//conditions:default": None,
})`,
}),
},
})
}
func TestPrebuiltLibrarySharedAdditionalAttrs(t *testing.T) {
runCcPrebuiltLibrarySharedTestCase(t,
Bp2buildTestCase{
Description: "prebuilt library shared additional attributes",
Filesystem: map[string]string{
"libf.so": "",
"testdir/1/include.h": "",
"testdir/2/other.h": "",
},
Blueprint: `
cc_prebuilt_library_shared {
name: "libtest",
srcs: ["libf.so"],
export_include_dirs: ["testdir/1/"],
export_system_include_dirs: ["testdir/2/"],
bazel_module: { bp2build_available: true },
}`,
ExpectedBazelTargets: []string{
MakeBazelTarget("cc_prebuilt_library_shared", "libtest", AttrNameToString{
"shared_library": `"libf.so"`,
"export_includes": `["testdir/1/"]`,
"export_system_includes": `["testdir/2/"]`,
}),
},
})
}
func TestPrebuiltLibrarySharedWithExportIncludesArchVariant(t *testing.T) {
runCcPrebuiltLibrarySharedTestCase(t, Bp2buildTestCase{
Description: "cc_prebuilt_library_shared correctly translates export_includes with arch variance",
Filesystem: map[string]string{
"libf.so": "",
"libg.so": "",
},
Blueprint: `
cc_prebuilt_library_shared {
name: "libtest",
srcs: ["libf.so"],
arch: {
arm: { export_include_dirs: ["testdir/1/"], },
arm64: { export_include_dirs: ["testdir/2/"], },
},
bazel_module: { bp2build_available: true },
}`,
ExpectedBazelTargets: []string{
MakeBazelTarget("cc_prebuilt_library_shared", "libtest", AttrNameToString{
"shared_library": `"libf.so"`,
"export_includes": `select({
"//build/bazel_common_rules/platforms/arch:arm": ["testdir/1/"],
"//build/bazel_common_rules/platforms/arch:arm64": ["testdir/2/"],
"//conditions:default": [],
})`,
}),
},
})
}
func TestPrebuiltLibrarySharedWithExportSystemIncludesArchVariant(t *testing.T) {
runCcPrebuiltLibrarySharedTestCase(t, Bp2buildTestCase{
Description: "cc_prebuilt_library_shared correctly translates export_system_includes with arch variance",
Filesystem: map[string]string{
"libf.so": "",
"libg.so": "",
},
Blueprint: `
cc_prebuilt_library_shared {
name: "libtest",
srcs: ["libf.so"],
arch: {
arm: { export_system_include_dirs: ["testdir/1/"], },
arm64: { export_system_include_dirs: ["testdir/2/"], },
},
bazel_module: { bp2build_available: true },
}`,
ExpectedBazelTargets: []string{
MakeBazelTarget("cc_prebuilt_library_shared", "libtest", AttrNameToString{
"shared_library": `"libf.so"`,
"export_system_includes": `select({
"//build/bazel_common_rules/platforms/arch:arm": ["testdir/1/"],
"//build/bazel_common_rules/platforms/arch:arm64": ["testdir/2/"],
"//conditions:default": [],
})`,
}),
},
})
}

View File

@@ -1,85 +0,0 @@
package bp2build
import (
"fmt"
"testing"
"android/soong/cc"
)
func TestSharedPrebuiltLibrary(t *testing.T) {
RunBp2BuildTestCaseSimple(t,
Bp2buildTestCase{
Description: "prebuilt library shared simple",
ModuleTypeUnderTest: "cc_prebuilt_library_shared",
ModuleTypeUnderTestFactory: cc.PrebuiltSharedLibraryFactory,
Filesystem: map[string]string{
"libf.so": "",
},
Blueprint: `
cc_prebuilt_library_shared {
name: "libtest",
srcs: ["libf.so"],
bazel_module: { bp2build_available: true },
}`,
ExpectedBazelTargets: []string{
MakeBazelTarget("cc_prebuilt_library_shared", "libtest", AttrNameToString{
"shared_library": `"libf.so"`,
}),
},
})
}
func TestSharedPrebuiltLibraryWithArchVariance(t *testing.T) {
RunBp2BuildTestCaseSimple(t,
Bp2buildTestCase{
Description: "prebuilt library shared with arch variance",
ModuleTypeUnderTest: "cc_prebuilt_library_shared",
ModuleTypeUnderTestFactory: cc.PrebuiltSharedLibraryFactory,
Filesystem: map[string]string{
"libf.so": "",
"libg.so": "",
},
Blueprint: `
cc_prebuilt_library_shared {
name: "libtest",
arch: {
arm64: { srcs: ["libf.so"], },
arm: { srcs: ["libg.so"], },
},
bazel_module: { bp2build_available: true },
}`,
ExpectedBazelTargets: []string{
MakeBazelTarget("cc_prebuilt_library_shared", "libtest", AttrNameToString{
"shared_library": `select({
"//build/bazel_common_rules/platforms/arch:arm": "libg.so",
"//build/bazel_common_rules/platforms/arch:arm64": "libf.so",
"//conditions:default": None,
})`,
}),
},
})
}
func TestSharedPrebuiltLibrarySharedStanzaFails(t *testing.T) {
RunBp2BuildTestCaseSimple(t,
Bp2buildTestCase{
Description: "prebuilt library shared with shared stanza fails because multiple sources",
ModuleTypeUnderTest: "cc_prebuilt_library_shared",
ModuleTypeUnderTestFactory: cc.PrebuiltSharedLibraryFactory,
Filesystem: map[string]string{
"libf.so": "",
"libg.so": "",
},
Blueprint: `
cc_prebuilt_library_shared {
name: "libtest",
srcs: ["libf.so"],
shared: {
srcs: ["libg.so"],
},
bazel_module: { bp2build_available: true},
}`,
ExpectedErr: fmt.Errorf("Expected at most one source file"),
})
}

View File

@@ -1,199 +0,0 @@
// Copyright 2022 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/cc"
)
func runCcPrebuiltLibraryStaticTestCase(t *testing.T, tc Bp2buildTestCase) {
t.Parallel()
t.Helper()
(&tc).ModuleTypeUnderTest = "cc_prebuilt_library_static"
(&tc).ModuleTypeUnderTestFactory = cc.PrebuiltStaticLibraryFactory
RunBp2BuildTestCaseSimple(t, tc)
}
func TestPrebuiltLibraryStaticSimple(t *testing.T) {
runCcPrebuiltLibraryStaticTestCase(t,
Bp2buildTestCase{
Description: "prebuilt library static simple",
Filesystem: map[string]string{
"libf.so": "",
},
Blueprint: `
cc_prebuilt_library_static {
name: "libtest",
srcs: ["libf.so"],
bazel_module: { bp2build_available: true },
}`,
ExpectedBazelTargets: []string{
MakeBazelTarget("cc_prebuilt_library_static", "libtest", AttrNameToString{
"static_library": `"libf.so"`,
}),
MakeBazelTarget("cc_prebuilt_library_static", "libtest_alwayslink", AttrNameToString{
"static_library": `"libf.so"`,
"alwayslink": "True",
}),
},
})
}
func TestPrebuiltLibraryStaticWithArchVariance(t *testing.T) {
runCcPrebuiltLibraryStaticTestCase(t,
Bp2buildTestCase{
Description: "prebuilt library with arch variance",
Filesystem: map[string]string{
"libf.so": "",
"libg.so": "",
},
Blueprint: `
cc_prebuilt_library_static {
name: "libtest",
arch: {
arm64: { srcs: ["libf.so"], },
arm: { srcs: ["libg.so"], },
},
bazel_module: { bp2build_available: true },
}`,
ExpectedBazelTargets: []string{
MakeBazelTarget("cc_prebuilt_library_static", "libtest", AttrNameToString{
"static_library": `select({
"//build/bazel_common_rules/platforms/arch:arm": "libg.so",
"//build/bazel_common_rules/platforms/arch:arm64": "libf.so",
"//conditions:default": None,
})`}),
MakeBazelTarget("cc_prebuilt_library_static", "libtest_alwayslink", AttrNameToString{
"alwayslink": "True",
"static_library": `select({
"//build/bazel_common_rules/platforms/arch:arm": "libg.so",
"//build/bazel_common_rules/platforms/arch:arm64": "libf.so",
"//conditions:default": None,
})`}),
},
})
}
func TestPrebuiltLibraryStaticAdditionalAttrs(t *testing.T) {
runCcPrebuiltLibraryStaticTestCase(t,
Bp2buildTestCase{
Description: "prebuilt library additional attributes",
Filesystem: map[string]string{
"libf.so": "",
"testdir/1/include.h": "",
"testdir/2/other.h": "",
},
Blueprint: `
cc_prebuilt_library_static {
name: "libtest",
srcs: ["libf.so"],
export_include_dirs: ["testdir/1/"],
export_system_include_dirs: ["testdir/2/"],
bazel_module: { bp2build_available: true },
}`,
ExpectedBazelTargets: []string{
MakeBazelTarget("cc_prebuilt_library_static", "libtest", AttrNameToString{
"static_library": `"libf.so"`,
"export_includes": `["testdir/1/"]`,
"export_system_includes": `["testdir/2/"]`,
}),
MakeBazelTarget("cc_prebuilt_library_static", "libtest_alwayslink", AttrNameToString{
"static_library": `"libf.so"`,
"export_includes": `["testdir/1/"]`,
"export_system_includes": `["testdir/2/"]`,
"alwayslink": "True",
}),
},
})
}
func TestPrebuiltLibraryStaticWithExportIncludesArchVariant(t *testing.T) {
runCcPrebuiltLibraryStaticTestCase(t, Bp2buildTestCase{
Description: "cc_prebuilt_library_static correctly translates export_includes with arch variance",
Filesystem: map[string]string{
"libf.so": "",
"libg.so": "",
},
Blueprint: `
cc_prebuilt_library_static {
name: "libtest",
srcs: ["libf.so"],
arch: {
arm: { export_include_dirs: ["testdir/1/"], },
arm64: { export_include_dirs: ["testdir/2/"], },
},
bazel_module: { bp2build_available: true },
}`,
ExpectedBazelTargets: []string{
MakeBazelTarget("cc_prebuilt_library_static", "libtest", AttrNameToString{
"static_library": `"libf.so"`,
"export_includes": `select({
"//build/bazel_common_rules/platforms/arch:arm": ["testdir/1/"],
"//build/bazel_common_rules/platforms/arch:arm64": ["testdir/2/"],
"//conditions:default": [],
})`,
}),
MakeBazelTarget("cc_prebuilt_library_static", "libtest_alwayslink", AttrNameToString{
"alwayslink": "True",
"static_library": `"libf.so"`,
"export_includes": `select({
"//build/bazel_common_rules/platforms/arch:arm": ["testdir/1/"],
"//build/bazel_common_rules/platforms/arch:arm64": ["testdir/2/"],
"//conditions:default": [],
})`,
}),
},
})
}
func TestPrebuiltLibraryStaticWithExportSystemIncludesArchVariant(t *testing.T) {
runCcPrebuiltLibraryStaticTestCase(t, Bp2buildTestCase{
Description: "cc_prebuilt_library_static correctly translates export_system_includes with arch variance",
Filesystem: map[string]string{
"libf.so": "",
"libg.so": "",
},
Blueprint: `
cc_prebuilt_library_static {
name: "libtest",
srcs: ["libf.so"],
arch: {
arm: { export_system_include_dirs: ["testdir/1/"], },
arm64: { export_system_include_dirs: ["testdir/2/"], },
},
bazel_module: { bp2build_available: true },
}`,
ExpectedBazelTargets: []string{
MakeBazelTarget("cc_prebuilt_library_static", "libtest", AttrNameToString{
"static_library": `"libf.so"`,
"export_system_includes": `select({
"//build/bazel_common_rules/platforms/arch:arm": ["testdir/1/"],
"//build/bazel_common_rules/platforms/arch:arm64": ["testdir/2/"],
"//conditions:default": [],
})`,
}),
MakeBazelTarget("cc_prebuilt_library_static", "libtest_alwayslink", AttrNameToString{
"alwayslink": "True",
"static_library": `"libf.so"`,
"export_system_includes": `select({
"//build/bazel_common_rules/platforms/arch:arm": ["testdir/1/"],
"//build/bazel_common_rules/platforms/arch:arm64": ["testdir/2/"],
"//conditions:default": [],
})`,
}),
},
})
}

View File

@@ -1,157 +0,0 @@
// Copyright 2022 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 (
"fmt"
"testing"
"android/soong/cc"
)
func TestStaticPrebuiltLibrary(t *testing.T) {
RunBp2BuildTestCaseSimple(t,
Bp2buildTestCase{
Description: "prebuilt library static simple",
ModuleTypeUnderTest: "cc_prebuilt_library_static",
ModuleTypeUnderTestFactory: cc.PrebuiltStaticLibraryFactory,
Filesystem: map[string]string{
"libf.so": "",
},
Blueprint: `
cc_prebuilt_library_static {
name: "libtest",
srcs: ["libf.so"],
bazel_module: { bp2build_available: true },
}`,
ExpectedBazelTargets: []string{
MakeBazelTarget("cc_prebuilt_library_static", "libtest", AttrNameToString{
"static_library": `"libf.so"`,
}),
MakeBazelTarget("cc_prebuilt_library_static", "libtest_alwayslink", AttrNameToString{
"static_library": `"libf.so"`,
"alwayslink": "True",
}),
},
})
}
func TestStaticPrebuiltLibraryWithArchVariance(t *testing.T) {
RunBp2BuildTestCaseSimple(t,
Bp2buildTestCase{
Description: "prebuilt library static with arch variance",
ModuleTypeUnderTest: "cc_prebuilt_library_static",
ModuleTypeUnderTestFactory: cc.PrebuiltStaticLibraryFactory,
Filesystem: map[string]string{
"libf.so": "",
"libg.so": "",
},
Blueprint: `
cc_prebuilt_library_static {
name: "libtest",
arch: {
arm64: { srcs: ["libf.so"], },
arm: { srcs: ["libg.so"], },
},
bazel_module: { bp2build_available: true },
}`,
ExpectedBazelTargets: []string{
MakeBazelTarget("cc_prebuilt_library_static", "libtest", AttrNameToString{
"static_library": `select({
"//build/bazel_common_rules/platforms/arch:arm": "libg.so",
"//build/bazel_common_rules/platforms/arch:arm64": "libf.so",
"//conditions:default": None,
})`}),
MakeBazelTarget("cc_prebuilt_library_static", "libtest_alwayslink", AttrNameToString{
"alwayslink": "True",
"static_library": `select({
"//build/bazel_common_rules/platforms/arch:arm": "libg.so",
"//build/bazel_common_rules/platforms/arch:arm64": "libf.so",
"//conditions:default": None,
})`}),
},
})
}
func TestStaticPrebuiltLibraryStaticStanzaFails(t *testing.T) {
RunBp2BuildTestCaseSimple(t,
Bp2buildTestCase{
Description: "prebuilt library with static stanza fails because multiple sources",
ModuleTypeUnderTest: "cc_prebuilt_library_static",
ModuleTypeUnderTestFactory: cc.PrebuiltStaticLibraryFactory,
Filesystem: map[string]string{
"libf.so": "",
"libg.so": "",
},
Blueprint: `
cc_prebuilt_library_static {
name: "libtest",
srcs: ["libf.so"],
static: {
srcs: ["libg.so"],
},
bazel_module: { bp2build_available: true },
}`,
ExpectedErr: fmt.Errorf("Expected at most one source file"),
})
}
func TestCcLibraryStaticConvertLex(t *testing.T) {
runCcLibrarySharedTestCase(t, Bp2buildTestCase{
Description: "cc_library_static with lex files",
ModuleTypeUnderTest: "cc_library_static",
ModuleTypeUnderTestFactory: cc.LibraryStaticFactory,
Filesystem: map[string]string{
"foo.c": "",
"bar.cc": "",
"foo1.l": "",
"bar1.ll": "",
"foo2.l": "",
"bar2.ll": "",
},
Blueprint: `cc_library_static {
name: "foo_lib",
srcs: ["foo.c", "bar.cc", "foo1.l", "foo2.l", "bar1.ll", "bar2.ll"],
lex: { flags: ["--foo_flags"] },
include_build_directory: false,
bazel_module: { bp2build_available: true },
}`,
ExpectedBazelTargets: []string{
MakeBazelTarget("genlex", "foo_lib_genlex_l", AttrNameToString{
"srcs": `[
"foo1.l",
"foo2.l",
]`,
"lexopts": `["--foo_flags"]`,
}),
MakeBazelTarget("genlex", "foo_lib_genlex_ll", AttrNameToString{
"srcs": `[
"bar1.ll",
"bar2.ll",
]`,
"lexopts": `["--foo_flags"]`,
}),
MakeBazelTarget("cc_library_static", "foo_lib", AttrNameToString{
"srcs": `[
"bar.cc",
":foo_lib_genlex_ll",
]`,
"srcs_c": `[
"foo.c",
":foo_lib_genlex_l",
]`,
}),
},
})
}

View File

@@ -1,101 +0,0 @@
// Copyright 2022 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 (
"fmt"
"testing"
"android/soong/cc"
)
func runCcPrebuiltObjectTestCase(t *testing.T, testCase Bp2buildTestCase) {
t.Helper()
description := fmt.Sprintf("cc_prebuilt_object: %s", testCase.Description)
testCase.ModuleTypeUnderTest = "cc_prebuilt_object"
testCase.ModuleTypeUnderTestFactory = cc.PrebuiltObjectFactory
testCase.Description = description
t.Run(description, func(t *testing.T) {
t.Helper()
RunBp2BuildTestCaseSimple(t, testCase)
})
}
func TestPrebuiltObject(t *testing.T) {
runCcPrebuiltObjectTestCase(t,
Bp2buildTestCase{
Description: "simple",
Filesystem: map[string]string{
"obj.o": "",
},
Blueprint: `
cc_prebuilt_object {
name: "objtest",
srcs: ["obj.o"],
bazel_module: { bp2build_available: true },
}`,
ExpectedBazelTargets: []string{
MakeBazelTarget("cc_prebuilt_object", "objtest", AttrNameToString{
"src": `"obj.o"`,
})},
})
}
func TestPrebuiltObjectWithArchVariance(t *testing.T) {
runCcPrebuiltObjectTestCase(t,
Bp2buildTestCase{
Description: "with arch variance",
Filesystem: map[string]string{
"obja.o": "",
"objb.o": "",
},
Blueprint: `
cc_prebuilt_object {
name: "objtest",
arch: {
arm64: { srcs: ["obja.o"], },
arm: { srcs: ["objb.o"], },
},
bazel_module: { bp2build_available: true },
}`, ExpectedBazelTargets: []string{
MakeBazelTarget("cc_prebuilt_object", "objtest", AttrNameToString{
"src": `select({
"//build/bazel_common_rules/platforms/arch:arm": "objb.o",
"//build/bazel_common_rules/platforms/arch:arm64": "obja.o",
"//conditions:default": None,
})`,
}),
},
})
}
func TestPrebuiltObjectMultipleSrcsFails(t *testing.T) {
runCcPrebuiltObjectTestCase(t,
Bp2buildTestCase{
Description: "fails because multiple sources",
Filesystem: map[string]string{
"obja": "",
"objb": "",
},
Blueprint: `
cc_prebuilt_object {
name: "objtest",
srcs: ["obja.o", "objb.o"],
bazel_module: { bp2build_available: true },
}`,
ExpectedErr: fmt.Errorf("Expected at most one source file"),
})
}
// TODO: nosrcs test

View File

@@ -1,633 +0,0 @@
// Copyright 2022 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 (
"fmt"
"testing"
"android/soong/android"
"android/soong/cc"
"android/soong/genrule"
)
type ccTestBp2buildTestCase struct {
description string
blueprint string
filesystem map[string]string
targets []testBazelTarget
stubbedBuildDefinitions []string
}
func registerCcTestModuleTypes(ctx android.RegistrationContext) {
cc.RegisterCCBuildComponents(ctx)
ctx.RegisterModuleType("cc_binary", cc.BinaryFactory)
ctx.RegisterModuleType("cc_library_static", cc.LibraryStaticFactory)
ctx.RegisterModuleType("cc_library", cc.LibraryFactory)
ctx.RegisterModuleType("cc_test_library", cc.TestLibraryFactory)
ctx.RegisterModuleType("genrule", genrule.GenRuleFactory)
}
func runCcTestTestCase(t *testing.T, testCase ccTestBp2buildTestCase) {
t.Helper()
moduleTypeUnderTest := "cc_test"
description := fmt.Sprintf("%s %s", moduleTypeUnderTest, testCase.description)
t.Run(description, func(t *testing.T) {
t.Helper()
RunBp2BuildTestCase(t, registerCcTestModuleTypes, Bp2buildTestCase{
ExpectedBazelTargets: generateBazelTargetsForTest(testCase.targets, android.HostAndDeviceSupported),
Filesystem: testCase.filesystem,
ModuleTypeUnderTest: moduleTypeUnderTest,
ModuleTypeUnderTestFactory: cc.TestFactory,
Description: description,
Blueprint: testCase.blueprint,
StubbedBuildDefinitions: testCase.stubbedBuildDefinitions,
})
})
}
func TestBasicCcTest(t *testing.T) {
runCcTestTestCase(t, ccTestBp2buildTestCase{
description: "basic cc_test with commonly used attributes",
stubbedBuildDefinitions: []string{"libbuildversion", "libprotobuf-cpp-lite", "libprotobuf-cpp-full",
"foolib", "hostlib", "data_mod", "cc_bin", "cc_lib", "cc_test_lib2", "libgtest_main", "libgtest"},
blueprint: `
cc_test {
name: "mytest",
host_supported: true,
srcs: ["test.cpp"],
target: {
android: {
srcs: ["android.cpp"],
shared_libs: ["foolib"],
},
linux: {
srcs: ["linux.cpp"],
},
host: {
static_libs: ["hostlib"],
},
},
static_libs: ["cc_test_lib1"],
shared_libs: ["cc_test_lib2"],
data: [":data_mod", "file.txt"],
data_bins: [":cc_bin"],
data_libs: [":cc_lib"],
cflags: ["-Wall"],
}
cc_test_library {
name: "cc_test_lib1",
host_supported: true,
include_build_directory: false,
}
` + simpleModule("cc_library", "foolib") +
simpleModule("cc_library_static", "hostlib") +
simpleModule("genrule", "data_mod") +
simpleModule("cc_binary", "cc_bin") +
simpleModule("cc_library", "cc_lib") +
simpleModule("cc_test_library", "cc_test_lib2") +
simpleModule("cc_library_static", "libgtest_main") +
simpleModule("cc_library_static", "libgtest"),
targets: []testBazelTarget{
{"cc_library_shared", "cc_test_lib1", AttrNameToString{}},
{"cc_library_static", "cc_test_lib1_bp2build_cc_library_static", AttrNameToString{}},
{"cc_test", "mytest", AttrNameToString{
"copts": `["-Wall"]`,
"data": `[
":data_mod",
"file.txt",
":cc_bin",
":cc_lib",
]`,
"deps": `[
":cc_test_lib1_bp2build_cc_library_static",
":libgtest_main",
":libgtest",
] + select({
"//build/bazel_common_rules/platforms/os:darwin": [":hostlib"],
"//build/bazel_common_rules/platforms/os:linux_bionic": [":hostlib"],
"//build/bazel_common_rules/platforms/os:linux_glibc": [":hostlib"],
"//build/bazel_common_rules/platforms/os:linux_musl": [":hostlib"],
"//build/bazel_common_rules/platforms/os:windows": [":hostlib"],
"//conditions:default": [],
})`,
"local_includes": `["."]`,
"dynamic_deps": `[":cc_test_lib2"] + select({
"//build/bazel_common_rules/platforms/os:android": [":foolib"],
"//conditions:default": [],
})`,
"srcs": `["test.cpp"] + select({
"//build/bazel_common_rules/platforms/os:android": [
"linux.cpp",
"android.cpp",
],
"//build/bazel_common_rules/platforms/os:linux_bionic": ["linux.cpp"],
"//build/bazel_common_rules/platforms/os:linux_glibc": ["linux.cpp"],
"//build/bazel_common_rules/platforms/os:linux_musl": ["linux.cpp"],
"//conditions:default": [],
})`,
"runs_on": `[
"host_without_device",
"device",
]`,
"features": `select({
"//build/bazel_common_rules/platforms/os_arch:android_arm64": [
"memtag_heap",
"diag_memtag_heap",
],
"//conditions:default": [],
})`,
},
},
},
})
}
func TestBasicCcTestGtestIsolatedDisabled(t *testing.T) {
runCcTestTestCase(t, ccTestBp2buildTestCase{
description: "cc test with disabled gtest and isolated props",
blueprint: `
cc_test {
name: "mytest",
host_supported: true,
srcs: ["test.cpp"],
gtest: false,
isolated: false,
}
`,
targets: []testBazelTarget{
{"cc_test", "mytest", AttrNameToString{
"gtest": "False",
"local_includes": `["."]`,
"srcs": `["test.cpp"]`,
"runs_on": `[
"host_without_device",
"device",
]`,
"features": `select({
"//build/bazel_common_rules/platforms/os_arch:android_arm64": [
"memtag_heap",
"diag_memtag_heap",
],
"//conditions:default": [],
})`,
},
},
},
})
}
func TestCcTest_TestOptions_Tags(t *testing.T) {
runCcTestTestCase(t, ccTestBp2buildTestCase{
description: "cc test with test_options.tags converted to tags",
stubbedBuildDefinitions: []string{"libgtest_main", "libgtest"},
blueprint: `
cc_test {
name: "mytest",
host_supported: true,
srcs: ["test.cpp"],
test_options: { tags: ["no-remote"] },
}
` + simpleModule("cc_library_static", "libgtest_main") +
simpleModule("cc_library_static", "libgtest"),
targets: []testBazelTarget{
{"cc_test", "mytest", AttrNameToString{
"tags": `["no-remote"]`,
"local_includes": `["."]`,
"srcs": `["test.cpp"]`,
"deps": `[
":libgtest_main",
":libgtest",
]`,
"runs_on": `[
"host_without_device",
"device",
]`,
"features": `select({
"//build/bazel_common_rules/platforms/os_arch:android_arm64": [
"memtag_heap",
"diag_memtag_heap",
],
"//conditions:default": [],
})`,
},
},
},
})
}
func TestCcTest_TestConfig(t *testing.T) {
runCcTestTestCase(t, ccTestBp2buildTestCase{
description: "cc test that sets a test_config",
filesystem: map[string]string{
"test_config.xml": "",
},
stubbedBuildDefinitions: []string{"libgtest_main", "libgtest"},
blueprint: `
cc_test {
name: "mytest",
srcs: ["test.cpp"],
test_config: "test_config.xml",
}
` + simpleModule("cc_library_static", "libgtest_main") +
simpleModule("cc_library_static", "libgtest"),
targets: []testBazelTarget{
{"cc_test", "mytest", AttrNameToString{
"local_includes": `["."]`,
"srcs": `["test.cpp"]`,
"target_compatible_with": `["//build/bazel_common_rules/platforms/os:android"]`,
"test_config": `"test_config.xml"`,
"deps": `[
":libgtest_main",
":libgtest",
]`,
"runs_on": `["device"]`,
"features": `select({
"//build/bazel_common_rules/platforms/os_arch:android_arm64": [
"memtag_heap",
"diag_memtag_heap",
],
"//conditions:default": [],
})`,
},
},
},
})
}
func TestCcTest_TestConfigAndroidTestXML(t *testing.T) {
runCcTestTestCase(t, ccTestBp2buildTestCase{
description: "cc test that defaults to test config AndroidTest.xml",
filesystem: map[string]string{
"AndroidTest.xml": "",
"DynamicConfig.xml": "",
},
stubbedBuildDefinitions: []string{"libgtest_main", "libgtest"},
blueprint: `
cc_test {
name: "mytest",
srcs: ["test.cpp"],
}
` + simpleModule("cc_library_static", "libgtest_main") +
simpleModule("cc_library_static", "libgtest"),
targets: []testBazelTarget{
{"cc_test", "mytest", AttrNameToString{
"local_includes": `["."]`,
"srcs": `["test.cpp"]`,
"target_compatible_with": `["//build/bazel_common_rules/platforms/os:android"]`,
"test_config": `"AndroidTest.xml"`,
"dynamic_config": `"DynamicConfig.xml"`,
"deps": `[
":libgtest_main",
":libgtest",
]`,
"runs_on": `["device"]`,
"features": `select({
"//build/bazel_common_rules/platforms/os_arch:android_arm64": [
"memtag_heap",
"diag_memtag_heap",
],
"//conditions:default": [],
})`,
},
},
},
})
}
func TestCcTest_TestConfigTemplateOptions(t *testing.T) {
runCcTestTestCase(t, ccTestBp2buildTestCase{
description: "cc test that sets test config template attributes",
filesystem: map[string]string{
"test_config_template.xml": "",
},
stubbedBuildDefinitions: []string{"libgtest_isolated_main", "liblog"},
blueprint: `
cc_test {
name: "mytest",
srcs: ["test.cpp"],
test_config_template: "test_config_template.xml",
auto_gen_config: true,
isolated: true,
}
` + simpleModule("cc_library_static", "libgtest_isolated_main") +
simpleModule("cc_library", "liblog"),
targets: []testBazelTarget{
{"cc_test", "mytest", AttrNameToString{
"auto_generate_test_config": "True",
"local_includes": `["."]`,
"srcs": `["test.cpp"]`,
"target_compatible_with": `["//build/bazel_common_rules/platforms/os:android"]`,
"template_configs": `[
"'<target_preparer class=\"com.android.tradefed.targetprep.RootTargetPreparer\">\\n <option name=\"force-root\" value=\"false\" />\\n </target_preparer>'",
"'<option name=\"not-shardable\" value=\"true\" />'",
]`,
"template_install_base": `"/data/local/tmp"`,
"template_test_config": `"test_config_template.xml"`,
"deps": `[":libgtest_isolated_main"]`,
"dynamic_deps": `[":liblog"]`,
"runs_on": `["device"]`,
"features": `select({
"//build/bazel_common_rules/platforms/os_arch:android_arm64": [
"memtag_heap",
"diag_memtag_heap",
],
"//conditions:default": [],
})`,
},
},
},
})
}
func TestCcTest_WithExplicitGTestDepInAndroidBp(t *testing.T) {
runCcTestTestCase(t, ccTestBp2buildTestCase{
description: "cc test that lists libgtest in Android.bp should not have dups of libgtest in BUILD file",
stubbedBuildDefinitions: []string{"libgtest_main", "libgtest"},
blueprint: `
cc_test {
name: "mytest",
srcs: ["test.cpp"],
static_libs: ["libgtest"],
}
` + simpleModule("cc_library_static", "libgtest_main") +
simpleModule("cc_library_static", "libgtest"),
targets: []testBazelTarget{
{"cc_test", "mytest", AttrNameToString{
"local_includes": `["."]`,
"srcs": `["test.cpp"]`,
"target_compatible_with": `["//build/bazel_common_rules/platforms/os:android"]`,
"deps": `[
":libgtest",
":libgtest_main",
]`,
"runs_on": `["device"]`,
"features": `select({
"//build/bazel_common_rules/platforms/os_arch:android_arm64": [
"memtag_heap",
"diag_memtag_heap",
],
"//conditions:default": [],
})`,
},
},
},
})
}
func TestCcTest_WithIsolatedTurnedOn(t *testing.T) {
runCcTestTestCase(t, ccTestBp2buildTestCase{
description: "cc test that sets `isolated: true` should run with ligtest_isolated_main instead of libgtest_main",
stubbedBuildDefinitions: []string{"libgtest_isolated_main", "liblog"},
blueprint: `
cc_test {
name: "mytest",
srcs: ["test.cpp"],
isolated: true,
}
` + simpleModule("cc_library_static", "libgtest_isolated_main") +
simpleModule("cc_library", "liblog"),
targets: []testBazelTarget{
{"cc_test", "mytest", AttrNameToString{
"local_includes": `["."]`,
"srcs": `["test.cpp"]`,
"target_compatible_with": `["//build/bazel_common_rules/platforms/os:android"]`,
"deps": `[":libgtest_isolated_main"]`,
"dynamic_deps": `[":liblog"]`,
"runs_on": `["device"]`,
"features": `select({
"//build/bazel_common_rules/platforms/os_arch:android_arm64": [
"memtag_heap",
"diag_memtag_heap",
],
"//conditions:default": [],
})`,
},
},
},
})
}
func TestCcTest_GtestExplicitlySpecifiedInAndroidBp(t *testing.T) {
runCcTestTestCase(t, ccTestBp2buildTestCase{
description: "If `gtest` is explicit in Android.bp, it should be explicit in BUILD files as well",
stubbedBuildDefinitions: []string{"libgtest_main", "libgtest"},
blueprint: `
cc_test {
name: "mytest_with_gtest",
gtest: true,
}
cc_test {
name: "mytest_with_no_gtest",
gtest: false,
}
` + simpleModule("cc_library_static", "libgtest_main") +
simpleModule("cc_library_static", "libgtest"),
targets: []testBazelTarget{
{"cc_test", "mytest_with_gtest", AttrNameToString{
"local_includes": `["."]`,
"deps": `[
":libgtest_main",
":libgtest",
]`,
"gtest": "True",
"target_compatible_with": `["//build/bazel_common_rules/platforms/os:android"]`,
"runs_on": `["device"]`,
"features": `select({
"//build/bazel_common_rules/platforms/os_arch:android_arm64": [
"memtag_heap",
"diag_memtag_heap",
],
"//conditions:default": [],
})`,
},
},
{"cc_test", "mytest_with_no_gtest", AttrNameToString{
"local_includes": `["."]`,
"gtest": "False",
"target_compatible_with": `["//build/bazel_common_rules/platforms/os:android"]`,
"runs_on": `["device"]`,
"features": `select({
"//build/bazel_common_rules/platforms/os_arch:android_arm64": [
"memtag_heap",
"diag_memtag_heap",
],
"//conditions:default": [],
})`,
},
},
},
})
}
func TestCcTest_DisableMemtagHeap(t *testing.T) {
runCcTestTestCase(t, ccTestBp2buildTestCase{
description: "cc test that disable memtag_heap",
stubbedBuildDefinitions: []string{"libgtest_isolated_main", "liblog"},
blueprint: `
cc_test {
name: "mytest",
srcs: ["test.cpp"],
isolated: true,
sanitize: {
cfi: true,
memtag_heap: false,
},
}
` + simpleModule("cc_library_static", "libgtest_isolated_main") +
simpleModule("cc_library", "liblog"),
targets: []testBazelTarget{
{"cc_test", "mytest", AttrNameToString{
"local_includes": `["."]`,
"srcs": `["test.cpp"]`,
"target_compatible_with": `["//build/bazel_common_rules/platforms/os:android"]`,
"deps": `[":libgtest_isolated_main"]`,
"dynamic_deps": `[":liblog"]`,
"runs_on": `["device"]`,
"features": `["android_cfi"] + select({
"//build/bazel_common_rules/platforms/os_arch:android_arm64": ["-memtag_heap"],
"//conditions:default": [],
})`,
},
},
},
})
}
func TestCcTest_RespectArm64MemtagHeap(t *testing.T) {
runCcTestTestCase(t, ccTestBp2buildTestCase{
description: "cc test that disable memtag_heap",
stubbedBuildDefinitions: []string{"libgtest_isolated_main", "liblog"},
blueprint: `
cc_test {
name: "mytest",
srcs: ["test.cpp"],
isolated: true,
target: {
android_arm64: {
sanitize: {
memtag_heap: false,
}
}
},
}
` + simpleModule("cc_library_static", "libgtest_isolated_main") +
simpleModule("cc_library", "liblog"),
targets: []testBazelTarget{
{"cc_test", "mytest", AttrNameToString{
"local_includes": `["."]`,
"srcs": `["test.cpp"]`,
"target_compatible_with": `["//build/bazel_common_rules/platforms/os:android"]`,
"deps": `[":libgtest_isolated_main"]`,
"dynamic_deps": `[":liblog"]`,
"runs_on": `["device"]`,
"features": `select({
"//build/bazel_common_rules/platforms/os_arch:android_arm64": ["-memtag_heap"],
"//conditions:default": [],
})`,
},
},
},
})
}
func TestCcTest_IgnoreNoneArm64MemtagHeap(t *testing.T) {
runCcTestTestCase(t, ccTestBp2buildTestCase{
description: "cc test that disable memtag_heap",
stubbedBuildDefinitions: []string{"libgtest_isolated_main", "liblog"},
blueprint: `
cc_test {
name: "mytest",
srcs: ["test.cpp"],
isolated: true,
arch: {
x86: {
sanitize: {
memtag_heap: false,
}
}
},
}
` + simpleModule("cc_library_static", "libgtest_isolated_main") +
simpleModule("cc_library", "liblog"),
targets: []testBazelTarget{
{"cc_test", "mytest", AttrNameToString{
"local_includes": `["."]`,
"srcs": `["test.cpp"]`,
"target_compatible_with": `["//build/bazel_common_rules/platforms/os:android"]`,
"deps": `[":libgtest_isolated_main"]`,
"dynamic_deps": `[":liblog"]`,
"runs_on": `["device"]`,
"features": `select({
"//build/bazel_common_rules/platforms/os_arch:android_arm64": [
"memtag_heap",
"diag_memtag_heap",
],
"//conditions:default": [],
})`,
},
},
},
})
}
func TestCcTest_Arm64MemtagHeapOverrideNoConfigOne(t *testing.T) {
runCcTestTestCase(t, ccTestBp2buildTestCase{
description: "cc test that disable memtag_heap",
stubbedBuildDefinitions: []string{"libgtest_isolated_main", "liblog"},
blueprint: `
cc_test {
name: "mytest",
srcs: ["test.cpp"],
isolated: true,
sanitize: {
memtag_heap: true,
},
target: {
android_arm64: {
sanitize: {
memtag_heap: false,
diag: {
memtag_heap: false,
},
}
}
},
}
` + simpleModule("cc_library_static", "libgtest_isolated_main") +
simpleModule("cc_library", "liblog"),
targets: []testBazelTarget{
{"cc_test", "mytest", AttrNameToString{
"local_includes": `["."]`,
"srcs": `["test.cpp"]`,
"target_compatible_with": `["//build/bazel_common_rules/platforms/os:android"]`,
"deps": `[":libgtest_isolated_main"]`,
"dynamic_deps": `[":liblog"]`,
"runs_on": `["device"]`,
"features": `select({
"//build/bazel_common_rules/platforms/os_arch:android_arm64": [
"-memtag_heap",
"-diag_memtag_heap",
],
"//conditions:default": [],
})`,
},
},
},
})
}

View File

@@ -1,179 +0,0 @@
// Copyright 2022 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/cc"
)
func runYasmTestCase(t *testing.T, tc Bp2buildTestCase) {
t.Helper()
RunBp2BuildTestCase(t, registerYasmModuleTypes, tc)
}
func registerYasmModuleTypes(ctx android.RegistrationContext) {
cc.RegisterCCBuildComponents(ctx)
ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
ctx.RegisterModuleType("cc_library_static", cc.LibraryStaticFactory)
ctx.RegisterModuleType("cc_prebuilt_library_static", cc.PrebuiltStaticLibraryFactory)
ctx.RegisterModuleType("cc_library_headers", cc.LibraryHeaderFactory)
}
func TestYasmSimple(t *testing.T) {
runYasmTestCase(t, Bp2buildTestCase{
Description: "Simple yasm test",
ModuleTypeUnderTest: "cc_library",
ModuleTypeUnderTestFactory: cc.LibraryFactory,
Filesystem: map[string]string{
"main.cpp": "",
"myfile.asm": "",
},
Blueprint: `
cc_library {
name: "foo",
srcs: ["main.cpp", "myfile.asm"],
}`,
ExpectedBazelTargets: append([]string{
MakeBazelTarget("yasm", "foo_yasm", map[string]string{
"include_dirs": `["."]`,
"srcs": `["myfile.asm"]`,
}),
}, makeCcLibraryTargets("foo", map[string]string{
"local_includes": `["."]`,
"srcs": `[
"main.cpp",
":foo_yasm",
]`,
})...),
})
}
func TestYasmWithIncludeDirs(t *testing.T) {
runYasmTestCase(t, Bp2buildTestCase{
Description: "Simple yasm test",
ModuleTypeUnderTest: "cc_library",
ModuleTypeUnderTestFactory: cc.LibraryFactory,
Filesystem: map[string]string{
"main.cpp": "",
"myfile.asm": "",
"include1/foo/myinclude.inc": "",
"include2/foo/myinclude2.inc": "",
},
Blueprint: `
cc_library {
name: "foo",
local_include_dirs: ["include1/foo"],
export_include_dirs: ["include2/foo"],
srcs: ["main.cpp", "myfile.asm"],
}`,
ExpectedBazelTargets: append([]string{
MakeBazelTarget("yasm", "foo_yasm", map[string]string{
"include_dirs": `[
"include1/foo",
".",
"include2/foo",
]`,
"srcs": `["myfile.asm"]`,
}),
}, makeCcLibraryTargets("foo", map[string]string{
"local_includes": `[
"include1/foo",
".",
]`,
"export_includes": `["include2/foo"]`,
"srcs": `[
"main.cpp",
":foo_yasm",
]`,
})...),
})
}
func TestYasmConditionalBasedOnArch(t *testing.T) {
runYasmTestCase(t, Bp2buildTestCase{
Description: "Simple yasm test",
ModuleTypeUnderTest: "cc_library",
ModuleTypeUnderTestFactory: cc.LibraryFactory,
Filesystem: map[string]string{
"main.cpp": "",
"myfile.asm": "",
},
Blueprint: `
cc_library {
name: "foo",
srcs: ["main.cpp"],
arch: {
x86: {
srcs: ["myfile.asm"],
},
},
}`,
ExpectedBazelTargets: append([]string{
MakeBazelTarget("yasm", "foo_yasm", map[string]string{
"include_dirs": `["."]`,
"srcs": `select({
"//build/bazel_common_rules/platforms/arch:x86": ["myfile.asm"],
"//conditions:default": [],
})`,
}),
}, makeCcLibraryTargets("foo", map[string]string{
"local_includes": `["."]`,
"srcs": `["main.cpp"] + select({
"//build/bazel_common_rules/platforms/arch:x86": [":foo_yasm"],
"//conditions:default": [],
})`,
})...),
})
}
func TestYasmPartiallyConditional(t *testing.T) {
runYasmTestCase(t, Bp2buildTestCase{
Description: "Simple yasm test",
ModuleTypeUnderTest: "cc_library",
ModuleTypeUnderTestFactory: cc.LibraryFactory,
Filesystem: map[string]string{
"main.cpp": "",
"myfile.asm": "",
"mysecondfile.asm": "",
},
Blueprint: `
cc_library {
name: "foo",
srcs: ["main.cpp", "myfile.asm"],
arch: {
x86: {
srcs: ["mysecondfile.asm"],
},
},
}`,
ExpectedBazelTargets: append([]string{
MakeBazelTarget("yasm", "foo_yasm", map[string]string{
"include_dirs": `["."]`,
"srcs": `["myfile.asm"] + select({
"//build/bazel_common_rules/platforms/arch:x86": ["mysecondfile.asm"],
"//conditions:default": [],
})`,
}),
}, makeCcLibraryTargets("foo", map[string]string{
"local_includes": `["."]`,
"srcs": `[
"main.cpp",
":foo_yasm",
]`,
})...),
})
}

View File

@@ -8,11 +8,6 @@ import (
"strings"
"android/soong/android"
"android/soong/apex"
"android/soong/cc"
cc_config "android/soong/cc/config"
java_config "android/soong/java/config"
rust_config "android/soong/rust/config"
"android/soong/starlark_fmt"
"github.com/google/blueprint/proptools"
@@ -33,23 +28,6 @@ func createSoongInjectionDirFiles(ctx *CodegenContext, metrics CodegenMetrics) (
files = append(files, newFile("android", GeneratedBuildFileName, "")) // Creates a //cc_toolchain package.
files = append(files, newFile("android", "constants.bzl", android.BazelCcToolchainVars(cfg)))
files = append(files, newFile("cc_toolchain", GeneratedBuildFileName, "")) // Creates a //cc_toolchain package.
files = append(files, newFile("cc_toolchain", "config_constants.bzl", cc_config.BazelCcToolchainVars(cfg)))
files = append(files, newFile("cc_toolchain", "sanitizer_constants.bzl", cc.BazelCcSanitizerToolchainVars(cfg)))
files = append(files, newFile("java_toolchain", GeneratedBuildFileName, "")) // Creates a //java_toolchain package.
files = append(files, newFile("java_toolchain", "constants.bzl", java_config.BazelJavaToolchainVars(cfg)))
files = append(files, newFile("rust_toolchain", GeneratedBuildFileName, "")) // Creates a //rust_toolchain package.
files = append(files, newFile("rust_toolchain", "constants.bzl", rust_config.BazelRustToolchainVars(cfg)))
files = append(files, newFile("apex_toolchain", GeneratedBuildFileName, "")) // Creates a //apex_toolchain package.
apexToolchainVars, err := apex.BazelApexToolchainVars()
if err != nil {
return nil, err
}
files = append(files, newFile("apex_toolchain", "constants.bzl", apexToolchainVars))
if buf, err := json.MarshalIndent(metrics.convertedModuleWithType, "", " "); err != nil {
return []BazelFile{}, err
} else {

View File

@@ -17,8 +17,6 @@ package bp2build
import (
"sort"
"testing"
"android/soong/android"
)
type bazelFilepath struct {
@@ -80,148 +78,3 @@ func TestCreateBazelFiles_QueryView_AddsTopLevelFiles(t *testing.T) {
}
}
}
func TestCreateBazelFiles_Bp2Build_CreatesDefaultFiles(t *testing.T) {
testConfig := android.TestConfig("", make(map[string]string), "", make(map[string][]byte))
codegenCtx := NewCodegenContext(testConfig, android.NewTestContext(testConfig).Context, Bp2Build, "")
files, err := createSoongInjectionDirFiles(codegenCtx, CreateCodegenMetrics())
if err != nil {
t.Error(err)
}
expectedFilePaths := []bazelFilepath{
{
dir: "android",
basename: GeneratedBuildFileName,
},
{
dir: "android",
basename: "constants.bzl",
},
{
dir: "cc_toolchain",
basename: GeneratedBuildFileName,
},
{
dir: "cc_toolchain",
basename: "config_constants.bzl",
},
{
dir: "cc_toolchain",
basename: "sanitizer_constants.bzl",
},
{
dir: "java_toolchain",
basename: GeneratedBuildFileName,
},
{
dir: "java_toolchain",
basename: "constants.bzl",
},
{
dir: "rust_toolchain",
basename: GeneratedBuildFileName,
},
{
dir: "rust_toolchain",
basename: "constants.bzl",
},
{
dir: "apex_toolchain",
basename: GeneratedBuildFileName,
},
{
dir: "apex_toolchain",
basename: "constants.bzl",
},
{
dir: "metrics",
basename: "converted_modules.json",
},
{
dir: "metrics",
basename: "BUILD.bazel",
},
{
dir: "metrics",
basename: "converted_modules_path_map.json",
},
{
dir: "metrics",
basename: "converted_modules_path_map.bzl",
},
{
dir: "product_config",
basename: "soong_config_variables.bzl",
},
{
dir: "product_config",
basename: "arch_configuration.bzl",
},
{
dir: "api_levels",
basename: GeneratedBuildFileName,
},
{
dir: "api_levels",
basename: "api_levels.json",
},
{
dir: "api_levels",
basename: "platform_versions.bzl",
},
{
dir: "allowlists",
basename: GeneratedBuildFileName,
},
{
dir: "allowlists",
basename: "mixed_build_prod_allowlist.txt",
},
{
dir: "allowlists",
basename: "mixed_build_staging_allowlist.txt",
},
}
less := func(a bazelFilepath, b bazelFilepath) bool {
return a.dir+"/"+a.basename < b.dir+"/"+b.basename
}
fileToFilepath := func(a BazelFile) bazelFilepath {
return bazelFilepath{basename: a.Basename, dir: a.Dir}
}
sort.Slice(expectedFilePaths, func(i, j int) bool {
return less(expectedFilePaths[i], expectedFilePaths[j])
})
sort.Slice(files, func(i, j int) bool {
return less(fileToFilepath(files[i]), fileToFilepath(files[j]))
})
i := 0
j := 0
for i < len(expectedFilePaths) && j < len(files) {
expectedFile, actualFile := expectedFilePaths[i], files[j]
if actualFile.Dir == expectedFile.dir && actualFile.Basename == expectedFile.basename {
i++
j++
} else if less(expectedFile, fileToFilepath(actualFile)) {
t.Errorf("Did not find expected file %s/%s", expectedFile.dir, expectedFile.basename)
i++
} else {
t.Errorf("Found unexpected file %s/%s", actualFile.Dir, actualFile.Basename)
j++
}
}
for i < len(expectedFilePaths) {
expectedFile := expectedFilePaths[i]
t.Errorf("Did not find expected file %s/%s", expectedFile.dir, expectedFile.basename)
i++
}
for j < len(files) {
actualFile := files[j]
t.Errorf("Found unexpected file %s/%s", actualFile.Dir, actualFile.Basename)
j++
}
}

View File

@@ -1,60 +0,0 @@
// Copyright 2023 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 (
"regexp"
"testing"
"android/soong/java"
)
func TestDroiddocExportedDir(t *testing.T) {
bp := `
droiddoc_exported_dir {
name: "test-module",
path: "docs",
}
`
p := regexp.MustCompile(`\t*\|`)
dedent := func(s string) string {
return p.ReplaceAllString(s, "")
}
expectedBazelTargets := []string{
MakeBazelTargetNoRestrictions(
"droiddoc_exported_dir",
"test-module",
AttrNameToString{
"dir": `"docs"`,
"srcs": dedent(`[
| "docs/android/1.txt",
| "docs/android/nested-1/2.txt",
| "//docs/android/nested-2:3.txt",
| "//docs/android/nested-2:Android.bp",
| ]`),
}),
//note we are not excluding Android.bp files from subpackages for now
}
RunBp2BuildTestCase(t, java.RegisterDocsBuildComponents, Bp2buildTestCase{
Blueprint: bp,
ExpectedBazelTargets: expectedBazelTargets,
Filesystem: map[string]string{
"docs/android/1.txt": "",
"docs/android/nested-1/2.txt": "",
"docs/android/nested-2/Android.bp": "",
"docs/android/nested-2/3.txt": "",
},
})
}

View File

@@ -1,85 +0,0 @@
// Copyright 2023 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/cc"
)
func runFdoProfileTestCase(t *testing.T, tc Bp2buildTestCase) {
t.Helper()
(&tc).ModuleTypeUnderTest = "fdo_profile"
(&tc).ModuleTypeUnderTestFactory = cc.FdoProfileFactory
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, tc)
}
func TestFdoProfile(t *testing.T) {
testcases := []struct {
name string
bp string
expectedBazelAttrs AttrNameToString
}{
{
name: "fdo_profile with arch-specific profiles",
bp: `
fdo_profile {
name: "foo",
arch: {
arm: {
profile: "foo_arm.afdo",
},
arm64: {
profile: "foo_arm64.afdo",
}
}
}`,
expectedBazelAttrs: AttrNameToString{
"profile": `select({
"//build/bazel_common_rules/platforms/arch:arm": "foo_arm.afdo",
"//build/bazel_common_rules/platforms/arch:arm64": "foo_arm64.afdo",
"//conditions:default": None,
})`,
},
},
{
name: "fdo_profile with arch-agnostic profile",
bp: `
fdo_profile {
name: "foo",
profile: "foo.afdo",
}`,
expectedBazelAttrs: AttrNameToString{
"profile": `"foo.afdo"`,
},
},
}
for _, test := range testcases {
t.Run(test.name, func(t *testing.T) {
expectedBazelTargets := []string{
// TODO(b/276287371): Add device-only restriction back to fdo_profile targets
MakeBazelTargetNoRestrictions("fdo_profile", "foo", test.expectedBazelAttrs),
}
runFdoProfileTestCase(t, Bp2buildTestCase{
Description: test.name,
Blueprint: test.bp,
ExpectedBazelTargets: expectedBazelTargets,
})
})
}
}

View File

@@ -1,205 +0,0 @@
// 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 (
"fmt"
"testing"
"android/soong/android"
)
func runFilegroupTestCase(t *testing.T, tc Bp2buildTestCase) {
t.Helper()
(&tc).ModuleTypeUnderTest = "filegroup"
(&tc).ModuleTypeUnderTestFactory = android.FileGroupFactory
RunBp2BuildTestCase(t, registerFilegroupModuleTypes, tc)
}
func registerFilegroupModuleTypes(ctx android.RegistrationContext) {}
func TestFilegroupSameNameAsFile_OneFile(t *testing.T) {
runFilegroupTestCase(t, Bp2buildTestCase{
Description: "filegroup - same name as file, with one file",
Filesystem: map[string]string{},
Blueprint: `
filegroup {
name: "foo",
srcs: ["foo"],
}
`,
ExpectedBazelTargets: []string{},
ExpectedHandcraftedModules: []string{"foo"}},
)
}
func TestFilegroupSameNameAsFile_MultipleFiles(t *testing.T) {
runFilegroupTestCase(t, Bp2buildTestCase{
Description: "filegroup - same name as file, with multiple files",
Filesystem: map[string]string{},
Blueprint: `
filegroup {
name: "foo",
srcs: ["foo", "bar"],
}
`,
ExpectedErr: fmt.Errorf("filegroup 'foo' cannot contain a file with the same name"),
})
}
func TestFilegroupWithAidlSrcs(t *testing.T) {
testcases := []struct {
name string
bp string
expectedBazelAttrs AttrNameToString
}{
{
name: "filegroup with only aidl srcs",
bp: `
filegroup {
name: "foo",
srcs: ["aidl/foo.aidl"],
path: "aidl",
}`,
expectedBazelAttrs: AttrNameToString{
"srcs": `["aidl/foo.aidl"]`,
"strip_import_prefix": `"aidl"`,
"tags": `["apex_available=//apex_available:anyapex"]`,
},
},
{
name: "filegroup without path",
bp: `
filegroup {
name: "foo",
srcs: ["aidl/foo.aidl"],
}`,
expectedBazelAttrs: AttrNameToString{
"srcs": `["aidl/foo.aidl"]`,
"tags": `["apex_available=//apex_available:anyapex"]`,
},
},
}
for _, test := range testcases {
t.Run(test.name, func(t *testing.T) {
expectedBazelTargets := []string{
MakeBazelTargetNoRestrictions("aidl_library", "foo", test.expectedBazelAttrs),
}
runFilegroupTestCase(t, Bp2buildTestCase{
Description: test.name,
Blueprint: test.bp,
ExpectedBazelTargets: expectedBazelTargets,
})
})
}
}
func TestFilegroupWithAidlAndNonAidlSrcs(t *testing.T) {
runFilegroupTestCase(t, Bp2buildTestCase{
Description: "filegroup with aidl and non-aidl srcs",
Filesystem: map[string]string{},
Blueprint: `
filegroup {
name: "foo",
srcs: [
"aidl/foo.aidl",
"buf.proto",
],
}`,
ExpectedBazelTargets: []string{
MakeBazelTargetNoRestrictions("filegroup", "foo", AttrNameToString{
"srcs": `[
"aidl/foo.aidl",
"buf.proto",
]`}),
}})
}
func TestFilegroupWithProtoSrcs(t *testing.T) {
runFilegroupTestCase(t, Bp2buildTestCase{
Description: "filegroup with proto and non-proto srcs",
Filesystem: map[string]string{},
Blueprint: `
filegroup {
name: "foo",
srcs: ["proto/foo.proto"],
path: "proto",
}`,
ExpectedBazelTargets: []string{
MakeBazelTargetNoRestrictions("proto_library", "foo_proto", AttrNameToString{
"srcs": `["proto/foo.proto"]`,
"strip_import_prefix": `"proto"`,
"tags": `[
"apex_available=//apex_available:anyapex",
"manual",
]`,
}),
MakeBazelTargetNoRestrictions("alias", "foo_bp2build_converted", AttrNameToString{
"actual": `"//.:foo_proto"`,
"tags": `[
"apex_available=//apex_available:anyapex",
"manual",
]`,
}),
MakeBazelTargetNoRestrictions("filegroup", "foo", AttrNameToString{
"srcs": `["proto/foo.proto"]`}),
}})
}
func TestFilegroupWithProtoAndNonProtoSrcs(t *testing.T) {
runFilegroupTestCase(t, Bp2buildTestCase{
Description: "filegroup with proto and non-proto srcs",
Filesystem: map[string]string{},
Blueprint: `
filegroup {
name: "foo",
srcs: [
"foo.proto",
"buf.cpp",
],
}`,
ExpectedBazelTargets: []string{
MakeBazelTargetNoRestrictions("filegroup", "foo", AttrNameToString{
"srcs": `[
"foo.proto",
"buf.cpp",
]`}),
}})
}
func TestFilegroupWithProtoInDifferentPackage(t *testing.T) {
runFilegroupTestCase(t, Bp2buildTestCase{
Description: "filegroup with .proto in different package",
Filesystem: map[string]string{
"subdir/Android.bp": "",
},
Blueprint: `
filegroup {
name: "foo",
srcs: ["subdir/foo.proto"],
}`,
Dir: "subdir", // check in subdir
ExpectedBazelTargets: []string{
MakeBazelTargetNoRestrictions("proto_library", "foo_proto", AttrNameToString{
"srcs": `["//subdir:foo.proto"]`,
"import_prefix": `"subdir"`,
"strip_import_prefix": `""`,
"tags": `[
"apex_available=//apex_available:anyapex",
"manual",
]`}),
}})
}

View File

@@ -1,959 +0,0 @@
// 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 (
"fmt"
"path/filepath"
"testing"
"android/soong/android"
"android/soong/cc"
"android/soong/genrule"
"android/soong/java"
)
func registerGenruleModuleTypes(ctx android.RegistrationContext) {
ctx.RegisterModuleType("genrule_defaults", func() android.Module { return genrule.DefaultsFactory() })
ctx.RegisterModuleType("cc_binary", func() android.Module { return cc.BinaryFactory() })
ctx.RegisterModuleType("soong_namespace", func() android.Module { return android.NamespaceFactory() })
}
func runGenruleTestCase(t *testing.T, tc Bp2buildTestCase) {
t.Helper()
(&tc).ModuleTypeUnderTest = "genrule"
(&tc).ModuleTypeUnderTestFactory = genrule.GenRuleFactory
RunBp2BuildTestCase(t, registerGenruleModuleTypes, tc)
}
func otherGenruleBp(genruleTarget string) map[string]string {
return map[string]string{
"other/Android.bp": fmt.Sprintf(`%s {
name: "foo.tool",
out: ["foo_tool.out"],
srcs: ["foo_tool.in"],
cmd: "cp $(in) $(out)",
}
%s {
name: "other.tool",
out: ["other_tool.out"],
srcs: ["other_tool.in"],
cmd: "cp $(in) $(out)",
}`, genruleTarget, genruleTarget),
"other/file.txt": "",
}
}
func TestGenruleCliVariableReplacement(t *testing.T) {
testCases := []struct {
moduleType string
factory android.ModuleFactory
genDir string
hod android.HostOrDeviceSupported
}{
{
moduleType: "genrule",
factory: genrule.GenRuleFactory,
genDir: "$(RULEDIR)",
},
{
moduleType: "cc_genrule",
factory: cc.GenRuleFactory,
genDir: "$(RULEDIR)",
hod: android.DeviceSupported,
},
{
moduleType: "java_genrule",
factory: java.GenRuleFactory,
genDir: "$(RULEDIR)",
hod: android.DeviceSupported,
},
{
moduleType: "java_genrule_host",
factory: java.GenRuleFactoryHost,
genDir: "$(RULEDIR)",
hod: android.HostSupported,
},
}
bp := `%s {
name: "foo.tool",
out: ["foo_tool.out"],
srcs: ["foo_tool.in"],
cmd: "cp $(in) $(out)",
}
%s {
name: "foo",
out: ["foo.out"],
srcs: ["foo.in"],
tools: [":foo.tool"],
cmd: "$(location :foo.tool) --genDir=$(genDir) arg $(in) $(out)",
bazel_module: { bp2build_available: true },
}`
for _, tc := range testCases {
moduleAttrs := AttrNameToString{
"cmd": fmt.Sprintf(`"$(location :foo.tool) --genDir=%s arg $(SRCS) $(OUTS)"`, tc.genDir),
"outs": `["foo.out"]`,
"srcs": `["foo.in"]`,
"tools": `[":foo.tool"]`,
}
expectedBazelTargets := []string{
makeBazelTargetHostOrDevice("genrule", "foo", moduleAttrs, tc.hod),
}
t.Run(tc.moduleType, func(t *testing.T) {
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {},
Bp2buildTestCase{
ModuleTypeUnderTest: tc.moduleType,
ModuleTypeUnderTestFactory: tc.factory,
Blueprint: fmt.Sprintf(bp, tc.moduleType, tc.moduleType),
ExpectedBazelTargets: expectedBazelTargets,
StubbedBuildDefinitions: []string{"foo.tool", "other.tool"},
})
})
}
}
func TestGenruleLocationsLabel(t *testing.T) {
testCases := []struct {
moduleType string
factory android.ModuleFactory
hod android.HostOrDeviceSupported
}{
{
moduleType: "genrule",
factory: genrule.GenRuleFactory,
},
{
moduleType: "cc_genrule",
factory: cc.GenRuleFactory,
hod: android.DeviceSupported,
},
{
moduleType: "java_genrule",
factory: java.GenRuleFactory,
hod: android.DeviceSupported,
},
{
moduleType: "java_genrule_host",
factory: java.GenRuleFactoryHost,
hod: android.HostSupported,
},
}
bp := `%s {
name: "foo.tools",
out: ["foo_tool.out", "foo_tool2.out"],
srcs: ["foo_tool.in"],
cmd: "cp $(in) $(out)",
bazel_module: { bp2build_available: true },
}
%s {
name: "foo",
out: ["foo.out"],
srcs: ["foo.in"],
tools: [":foo.tools"],
cmd: "$(locations :foo.tools) -s $(out) $(in)",
bazel_module: { bp2build_available: true },
}`
for _, tc := range testCases {
fooAttrs := AttrNameToString{
"cmd": `"$(locations :foo.tools) -s $(OUTS) $(SRCS)"`,
"outs": `["foo.out"]`,
"srcs": `["foo.in"]`,
"tools": `[":foo.tools"]`,
}
fooToolsAttrs := AttrNameToString{
"cmd": `"cp $(SRCS) $(OUTS)"`,
"outs": `[
"foo_tool.out",
"foo_tool2.out",
]`,
"srcs": `["foo_tool.in"]`,
}
expectedBazelTargets := []string{
makeBazelTargetHostOrDevice("genrule", "foo", fooAttrs, tc.hod),
makeBazelTargetHostOrDevice("genrule", "foo.tools", fooToolsAttrs, tc.hod),
}
t.Run(tc.moduleType, func(t *testing.T) {
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {},
Bp2buildTestCase{
ModuleTypeUnderTest: tc.moduleType,
ModuleTypeUnderTestFactory: tc.factory,
Blueprint: fmt.Sprintf(bp, tc.moduleType, tc.moduleType),
ExpectedBazelTargets: expectedBazelTargets,
})
})
}
}
func TestGenruleLocationsAbsoluteLabel(t *testing.T) {
testCases := []struct {
moduleType string
factory android.ModuleFactory
hod android.HostOrDeviceSupported
}{
{
moduleType: "genrule",
factory: genrule.GenRuleFactory,
},
{
moduleType: "cc_genrule",
factory: cc.GenRuleFactory,
hod: android.DeviceSupported,
},
{
moduleType: "java_genrule",
factory: java.GenRuleFactory,
hod: android.DeviceSupported,
},
{
moduleType: "java_genrule_host",
factory: java.GenRuleFactoryHost,
hod: android.HostSupported,
},
}
bp := `%s {
name: "foo",
out: ["foo.out"],
srcs: ["foo.in"],
tool_files: [":foo.tool"],
cmd: "$(locations :foo.tool) -s $(out) $(in)",
bazel_module: { bp2build_available: true },
}`
for _, tc := range testCases {
moduleAttrs := AttrNameToString{
"cmd": `"$(locations //other:foo.tool) -s $(OUTS) $(SRCS)"`,
"outs": `["foo.out"]`,
"srcs": `["foo.in"]`,
"tools": `["//other:foo.tool"]`,
}
expectedBazelTargets := []string{
makeBazelTargetHostOrDevice("genrule", "foo", moduleAttrs, tc.hod),
}
t.Run(tc.moduleType, func(t *testing.T) {
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {},
Bp2buildTestCase{
ModuleTypeUnderTest: tc.moduleType,
ModuleTypeUnderTestFactory: tc.factory,
Blueprint: fmt.Sprintf(bp, tc.moduleType),
ExpectedBazelTargets: expectedBazelTargets,
Filesystem: otherGenruleBp(tc.moduleType),
StubbedBuildDefinitions: []string{"//other:foo.tool"},
})
})
}
}
func TestGenruleSrcsLocationsAbsoluteLabel(t *testing.T) {
testCases := []struct {
moduleType string
factory android.ModuleFactory
hod android.HostOrDeviceSupported
}{
{
moduleType: "genrule",
factory: genrule.GenRuleFactory,
},
{
moduleType: "cc_genrule",
factory: cc.GenRuleFactory,
hod: android.DeviceSupported,
},
{
moduleType: "java_genrule",
factory: java.GenRuleFactory,
hod: android.DeviceSupported,
},
{
moduleType: "java_genrule_host",
factory: java.GenRuleFactoryHost,
hod: android.HostSupported,
},
}
bp := `%s {
name: "foo",
out: ["foo.out"],
srcs: [":other.tool", "other/file.txt",],
tool_files: [":foo.tool"],
cmd: "$(locations :foo.tool) $(location other/file.txt) -s $(out) $(location :other.tool)",
bazel_module: { bp2build_available: true },
}`
for _, tc := range testCases {
moduleAttrs := AttrNameToString{
"cmd": `"$(locations //other:foo.tool) $(location //other:file.txt) -s $(OUTS) $(location //other:other.tool)"`,
"outs": `["foo.out"]`,
"srcs": `[
"//other:other.tool",
"//other:file.txt",
]`,
"tools": `["//other:foo.tool"]`,
}
expectedBazelTargets := []string{
makeBazelTargetHostOrDevice("genrule", "foo", moduleAttrs, tc.hod),
}
t.Run(tc.moduleType, func(t *testing.T) {
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {},
Bp2buildTestCase{
ModuleTypeUnderTest: tc.moduleType,
ModuleTypeUnderTestFactory: tc.factory,
Blueprint: fmt.Sprintf(bp, tc.moduleType),
ExpectedBazelTargets: expectedBazelTargets,
Filesystem: otherGenruleBp(tc.moduleType),
StubbedBuildDefinitions: []string{"//other:foo.tool", "//other:other.tool"},
})
})
}
}
func TestGenruleLocationLabelShouldSubstituteFirstToolLabel(t *testing.T) {
testCases := []struct {
moduleType string
factory android.ModuleFactory
hod android.HostOrDeviceSupported
}{
{
moduleType: "genrule",
factory: genrule.GenRuleFactory,
},
{
moduleType: "cc_genrule",
factory: cc.GenRuleFactory,
hod: android.DeviceSupported,
},
{
moduleType: "java_genrule",
factory: java.GenRuleFactory,
hod: android.DeviceSupported,
},
{
moduleType: "java_genrule_host",
factory: java.GenRuleFactoryHost,
hod: android.HostSupported,
},
}
bp := `%s {
name: "foo",
out: ["foo.out"],
srcs: ["foo.in"],
tool_files: [":foo.tool", ":other.tool"],
cmd: "$(location) -s $(out) $(in)",
bazel_module: { bp2build_available: true },
}`
for _, tc := range testCases {
moduleAttrs := AttrNameToString{
"cmd": `"$(location //other:foo.tool) -s $(OUTS) $(SRCS)"`,
"outs": `["foo.out"]`,
"srcs": `["foo.in"]`,
"tools": `[
"//other:foo.tool",
"//other:other.tool",
]`,
}
expectedBazelTargets := []string{
makeBazelTargetHostOrDevice("genrule", "foo", moduleAttrs, tc.hod),
}
t.Run(tc.moduleType, func(t *testing.T) {
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {},
Bp2buildTestCase{
ModuleTypeUnderTest: tc.moduleType,
ModuleTypeUnderTestFactory: tc.factory,
Blueprint: fmt.Sprintf(bp, tc.moduleType),
ExpectedBazelTargets: expectedBazelTargets,
Filesystem: otherGenruleBp(tc.moduleType),
StubbedBuildDefinitions: []string{"//other:foo.tool", "//other:other.tool"},
})
})
}
}
func TestGenruleLocationsLabelShouldSubstituteFirstToolLabel(t *testing.T) {
testCases := []struct {
moduleType string
factory android.ModuleFactory
hod android.HostOrDeviceSupported
}{
{
moduleType: "genrule",
factory: genrule.GenRuleFactory,
},
{
moduleType: "cc_genrule",
factory: cc.GenRuleFactory,
hod: android.DeviceSupported,
},
{
moduleType: "java_genrule",
factory: java.GenRuleFactory,
hod: android.DeviceSupported,
},
{
moduleType: "java_genrule_host",
factory: java.GenRuleFactoryHost,
hod: android.HostSupported,
},
}
bp := `%s {
name: "foo",
out: ["foo.out"],
srcs: ["foo.in"],
tool_files: [":foo.tool", ":other.tool"],
cmd: "$(locations) -s $(out) $(in)",
bazel_module: { bp2build_available: true },
}`
for _, tc := range testCases {
moduleAttrs := AttrNameToString{
"cmd": `"$(locations //other:foo.tool) -s $(OUTS) $(SRCS)"`,
"outs": `["foo.out"]`,
"srcs": `["foo.in"]`,
"tools": `[
"//other:foo.tool",
"//other:other.tool",
]`,
}
expectedBazelTargets := []string{
makeBazelTargetHostOrDevice("genrule", "foo", moduleAttrs, tc.hod),
}
t.Run(tc.moduleType, func(t *testing.T) {
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {},
Bp2buildTestCase{
ModuleTypeUnderTest: tc.moduleType,
ModuleTypeUnderTestFactory: tc.factory,
Blueprint: fmt.Sprintf(bp, tc.moduleType),
ExpectedBazelTargets: expectedBazelTargets,
Filesystem: otherGenruleBp(tc.moduleType),
StubbedBuildDefinitions: []string{"//other:foo.tool", "//other:other.tool"},
})
})
}
}
func TestGenruleWithoutToolsOrToolFiles(t *testing.T) {
testCases := []struct {
moduleType string
factory android.ModuleFactory
hod android.HostOrDeviceSupported
}{
{
moduleType: "genrule",
factory: genrule.GenRuleFactory,
},
{
moduleType: "cc_genrule",
factory: cc.GenRuleFactory,
hod: android.DeviceSupported,
},
{
moduleType: "java_genrule",
factory: java.GenRuleFactory,
hod: android.DeviceSupported,
},
{
moduleType: "java_genrule_host",
factory: java.GenRuleFactoryHost,
hod: android.HostSupported,
},
}
bp := `%s {
name: "foo",
out: ["foo.out"],
srcs: ["foo.in"],
cmd: "cp $(in) $(out)",
bazel_module: { bp2build_available: true },
}`
for _, tc := range testCases {
moduleAttrs := AttrNameToString{
"cmd": `"cp $(SRCS) $(OUTS)"`,
"outs": `["foo.out"]`,
"srcs": `["foo.in"]`,
}
expectedBazelTargets := []string{
makeBazelTargetHostOrDevice("genrule", "foo", moduleAttrs, tc.hod),
}
t.Run(tc.moduleType, func(t *testing.T) {
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {},
Bp2buildTestCase{
ModuleTypeUnderTest: tc.moduleType,
ModuleTypeUnderTestFactory: tc.factory,
Blueprint: fmt.Sprintf(bp, tc.moduleType),
ExpectedBazelTargets: expectedBazelTargets,
})
})
}
}
func TestGenruleBp2BuildInlinesDefaults(t *testing.T) {
testCases := []Bp2buildTestCase{
{
Description: "genrule applies properties from a genrule_defaults dependency if not specified",
Blueprint: `genrule_defaults {
name: "gen_defaults",
cmd: "do-something $(in) $(out)",
}
genrule {
name: "gen",
out: ["out"],
srcs: ["in1"],
defaults: ["gen_defaults"],
bazel_module: { bp2build_available: true },
}
`,
ExpectedBazelTargets: []string{
MakeBazelTargetNoRestrictions("genrule", "gen", AttrNameToString{
"cmd": `"do-something $(SRCS) $(OUTS)"`,
"outs": `["out"]`,
"srcs": `["in1"]`,
}),
},
},
{
Description: "genrule does merges properties from a genrule_defaults dependency, latest-first",
Blueprint: `genrule_defaults {
name: "gen_defaults",
out: ["out-from-defaults"],
srcs: ["in-from-defaults"],
cmd: "cmd-from-defaults",
}
genrule {
name: "gen",
out: ["out"],
srcs: ["in1"],
defaults: ["gen_defaults"],
cmd: "do-something $(in) $(out)",
bazel_module: { bp2build_available: true },
}
`,
ExpectedBazelTargets: []string{
MakeBazelTargetNoRestrictions("genrule", "gen", AttrNameToString{
"cmd": `"do-something $(SRCS) $(OUTS)"`,
"outs": `[
"out-from-defaults",
"out",
]`,
"srcs": `[
"in-from-defaults",
"in1",
]`,
}),
},
},
{
Description: "genrule applies properties from list of genrule_defaults",
Blueprint: `genrule_defaults {
name: "gen_defaults1",
cmd: "cp $(in) $(out)",
}
genrule_defaults {
name: "gen_defaults2",
srcs: ["in1"],
}
genrule {
name: "gen",
out: ["out"],
defaults: ["gen_defaults1", "gen_defaults2"],
bazel_module: { bp2build_available: true },
}
`,
ExpectedBazelTargets: []string{
MakeBazelTargetNoRestrictions("genrule", "gen", AttrNameToString{
"cmd": `"cp $(SRCS) $(OUTS)"`,
"outs": `["out"]`,
"srcs": `["in1"]`,
}),
},
},
{
Description: "genrule applies properties from genrule_defaults transitively",
Blueprint: `genrule_defaults {
name: "gen_defaults1",
defaults: ["gen_defaults2"],
cmd: "cmd1 $(in) $(out)", // overrides gen_defaults2's cmd property value.
}
genrule_defaults {
name: "gen_defaults2",
defaults: ["gen_defaults3"],
cmd: "cmd2 $(in) $(out)",
out: ["out-from-2"],
srcs: ["in1"],
}
genrule_defaults {
name: "gen_defaults3",
out: ["out-from-3"],
srcs: ["srcs-from-3"],
}
genrule {
name: "gen",
out: ["out"],
defaults: ["gen_defaults1"],
bazel_module: { bp2build_available: true },
}
`,
ExpectedBazelTargets: []string{
MakeBazelTargetNoRestrictions("genrule", "gen", AttrNameToString{
"cmd": `"cmd1 $(SRCS) $(OUTS)"`,
"outs": `[
"out-from-3",
"out-from-2",
"out",
]`,
"srcs": `[
"srcs-from-3",
"in1",
]`,
}),
},
},
}
for _, testCase := range testCases {
t.Run(testCase.Description, func(t *testing.T) {
runGenruleTestCase(t, testCase)
})
}
}
func TestCcGenruleArchAndExcludeSrcs(t *testing.T) {
name := "cc_genrule with arch"
bp := `
cc_genrule {
name: "foo",
srcs: [
"foo1.in",
"foo2.in",
],
exclude_srcs: ["foo2.in"],
arch: {
arm: {
srcs: [
"foo1_arch.in",
"foo2_arch.in",
],
exclude_srcs: ["foo2_arch.in"],
},
},
cmd: "cat $(in) > $(out)",
bazel_module: { bp2build_available: true },
}`
expectedBazelAttrs := AttrNameToString{
"srcs": `["foo1.in"] + select({
"//build/bazel_common_rules/platforms/arch:arm": ["foo1_arch.in"],
"//conditions:default": [],
})`,
"cmd": `"cat $(SRCS) > $(OUTS)"`,
"target_compatible_with": `["//build/bazel_common_rules/platforms/os:android"]`,
}
expectedBazelTargets := []string{
MakeBazelTargetNoRestrictions("genrule", "foo", expectedBazelAttrs),
}
t.Run(name, func(t *testing.T) {
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {},
Bp2buildTestCase{
ModuleTypeUnderTest: "cc_genrule",
ModuleTypeUnderTestFactory: cc.GenRuleFactory,
Blueprint: bp,
ExpectedBazelTargets: expectedBazelTargets,
})
})
}
func TestGenruleWithExportIncludeDirs(t *testing.T) {
testCases := []struct {
moduleType string
factory android.ModuleFactory
hod android.HostOrDeviceSupported
}{
{
moduleType: "genrule",
factory: genrule.GenRuleFactory,
},
{
moduleType: "cc_genrule",
factory: cc.GenRuleFactory,
hod: android.DeviceSupported,
},
{
moduleType: "java_genrule",
factory: java.GenRuleFactory,
hod: android.DeviceSupported,
},
{
moduleType: "java_genrule_host",
factory: java.GenRuleFactoryHost,
hod: android.HostSupported,
},
}
dir := "baz"
bp := `%s {
name: "foo",
out: ["foo.out.h"],
srcs: ["foo.in"],
cmd: "cp $(in) $(out)",
export_include_dirs: ["foo", "bar", "."],
bazel_module: { bp2build_available: true },
}`
for _, tc := range testCases {
moduleAttrs := AttrNameToString{
"cmd": `"cp $(SRCS) $(OUTS)"`,
"outs": `["foo.out.h"]`,
"srcs": `["foo.in"]`,
}
expectedBazelTargets := []string{
makeBazelTargetHostOrDevice("genrule", "foo", moduleAttrs, tc.hod),
makeBazelTargetHostOrDevice("cc_library_headers", "foo__header_library", AttrNameToString{
"hdrs": `[":foo"]`,
"export_includes": `[
"foo",
"baz/foo",
"bar",
"baz/bar",
".",
"baz",
]`,
},
tc.hod),
}
t.Run(tc.moduleType, func(t *testing.T) {
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {},
Bp2buildTestCase{
ModuleTypeUnderTest: tc.moduleType,
ModuleTypeUnderTestFactory: tc.factory,
Filesystem: map[string]string{
filepath.Join(dir, "Android.bp"): fmt.Sprintf(bp, tc.moduleType),
},
Dir: dir,
ExpectedBazelTargets: expectedBazelTargets,
})
})
}
}
func TestGenruleWithSoongConfigVariableConfiguredCmd(t *testing.T) {
testCases := []struct {
moduleType string
factory android.ModuleFactory
hod android.HostOrDeviceSupported
}{
{
moduleType: "genrule",
factory: genrule.GenRuleFactory,
},
{
moduleType: "cc_genrule",
factory: cc.GenRuleFactory,
hod: android.DeviceSupported,
},
{
moduleType: "java_genrule",
factory: java.GenRuleFactory,
hod: android.DeviceSupported,
},
{
moduleType: "java_genrule_host",
factory: java.GenRuleFactoryHost,
hod: android.HostSupported,
},
}
bp := `
soong_config_module_type {
name: "my_genrule",
module_type: "%s",
config_namespace: "my_namespace",
bool_variables: ["my_variable"],
properties: ["cmd"],
}
my_genrule {
name: "foo",
out: ["foo.txt"],
cmd: "echo 'no variable' > $(out)",
soong_config_variables: {
my_variable: {
cmd: "echo 'with variable' > $(out)",
},
},
bazel_module: { bp2build_available: true },
}
`
for _, tc := range testCases {
moduleAttrs := AttrNameToString{
"cmd": `select({
"//build/bazel/product_config/config_settings:my_namespace__my_variable": "echo 'with variable' > $(OUTS)",
"//conditions:default": "echo 'no variable' > $(OUTS)",
})`,
"outs": `["foo.txt"]`,
}
expectedBazelTargets := []string{
makeBazelTargetHostOrDevice("genrule", "foo", moduleAttrs, tc.hod),
}
t.Run(tc.moduleType, func(t *testing.T) {
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) { android.RegisterSoongConfigModuleBuildComponents(ctx) },
Bp2buildTestCase{
Blueprint: fmt.Sprintf(bp, tc.moduleType),
ModuleTypeUnderTest: tc.moduleType,
ModuleTypeUnderTestFactory: tc.factory,
ExpectedBazelTargets: expectedBazelTargets,
})
})
}
}
func TestGenruleWithProductVariableConfiguredCmd(t *testing.T) {
testCases := []struct {
moduleType string
factory android.ModuleFactory
hod android.HostOrDeviceSupported
}{
{
moduleType: "genrule",
factory: genrule.GenRuleFactory,
},
{
moduleType: "cc_genrule",
factory: cc.GenRuleFactory,
hod: android.DeviceSupported,
},
{
moduleType: "java_genrule",
factory: java.GenRuleFactory,
hod: android.DeviceSupported,
},
{
moduleType: "java_genrule_host",
factory: java.GenRuleFactoryHost,
hod: android.HostSupported,
},
}
bp := `
%s {
name: "foo",
out: ["foo.txt"],
cmd: "echo 'no variable' > $(out)",
product_variables: {
debuggable: {
cmd: "echo 'with variable' > $(out)",
},
},
bazel_module: { bp2build_available: true },
}
`
for _, tc := range testCases {
moduleAttrs := AttrNameToString{
"cmd": `select({
"//build/bazel/product_config/config_settings:debuggable": "echo 'with variable' > $(OUTS)",
"//conditions:default": "echo 'no variable' > $(OUTS)",
})`,
"outs": `["foo.txt"]`,
}
expectedBazelTargets := []string{
makeBazelTargetHostOrDevice("genrule", "foo", moduleAttrs, tc.hod),
}
t.Run(tc.moduleType, func(t *testing.T) {
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) { android.RegisterSoongConfigModuleBuildComponents(ctx) },
Bp2buildTestCase{
Blueprint: fmt.Sprintf(bp, tc.moduleType),
ModuleTypeUnderTest: tc.moduleType,
ModuleTypeUnderTestFactory: tc.factory,
ExpectedBazelTargets: expectedBazelTargets,
})
})
}
}
func TestGenruleWithModulesInNamespaces(t *testing.T) {
bp := `
genrule {
name: "mygenrule",
cmd: "echo $(location //mynamespace:mymodule) > $(out)",
srcs: ["//mynamespace:mymodule"],
out: ["myout"],
}
`
fs := map[string]string{
"mynamespace/Android.bp": `soong_namespace {}`,
"mynamespace/dir/Android.bp": `cc_binary {name: "mymodule"}`,
}
expectedBazelTargets := []string{
MakeBazelTargetNoRestrictions("genrule", "mygenrule", AttrNameToString{
// The fully qualified soong label is <namespace>:<module_name>
// - here the prefix is mynamespace
// The fully qualifed bazel label is <package>:<module_name>
// - here the prefix is mynamespace/dir, since there is a BUILD file at each level of this FS path
"cmd": `"echo $(location //mynamespace/dir:mymodule) > $(OUTS)"`,
"outs": `["myout"]`,
"srcs": `["//mynamespace/dir:mymodule"]`,
}),
}
t.Run("genrule that uses module from a different namespace", func(t *testing.T) {
runGenruleTestCase(t, Bp2buildTestCase{
Blueprint: bp,
Filesystem: fs,
ModuleTypeUnderTest: "genrule",
ModuleTypeUnderTestFactory: genrule.GenRuleFactory,
ExpectedBazelTargets: expectedBazelTargets,
StubbedBuildDefinitions: []string{"//mynamespace/dir:mymodule"},
})
})
}

View File

@@ -1,96 +0,0 @@
// Copyright 2020 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/genrule"
)
func registerModulesForGensrcsTests(ctx android.RegistrationContext) {
ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
}
func TestGensrcs(t *testing.T) {
testcases := []struct {
name string
bp string
expectedBazelAttrs AttrNameToString
stubbedBuildDefinitions []string
}{
{
name: "gensrcs with common usage of properties",
bp: `
gensrcs {
name: "foo",
srcs: ["test/input.txt", ":external_files"],
tool_files: ["program.py"],
cmd: "$(location program.py) $(in) $(out) $(location foo/file.txt) $(location :external_files)",
data: ["foo/file.txt", ":external_files"],
output_extension: "out",
bazel_module: { bp2build_available: true },
}
filegroup {
name: "external_files",
}`,
stubbedBuildDefinitions: []string{"external_files"},
expectedBazelAttrs: AttrNameToString{
"srcs": `[
"test/input.txt",
":external_files",
]`,
"tools": `["program.py"]`,
"output_extension": `"out"`,
"cmd": `"$(location program.py) $(SRC) $(OUT) $(location foo/file.txt) $(location :external_files)"`,
"data": `[
"foo/file.txt",
":external_files",
]`,
},
},
{
name: "gensrcs with out_extension unset",
bp: `
gensrcs {
name: "foo",
srcs: ["input.txt"],
cmd: "cat $(in) > $(out)",
bazel_module: { bp2build_available: true },
}`,
expectedBazelAttrs: AttrNameToString{
"srcs": `["input.txt"]`,
"cmd": `"cat $(SRC) > $(OUT)"`,
},
},
}
for _, test := range testcases {
expectedBazelTargets := []string{
MakeBazelTargetNoRestrictions("gensrcs", "foo", test.expectedBazelAttrs),
}
t.Run(test.name, func(t *testing.T) {
RunBp2BuildTestCase(t, registerModulesForGensrcsTests,
Bp2buildTestCase{
ModuleTypeUnderTest: "gensrcs",
ModuleTypeUnderTestFactory: genrule.GenSrcsFactory,
Blueprint: test.bp,
ExpectedBazelTargets: expectedBazelTargets,
StubbedBuildDefinitions: test.stubbedBuildDefinitions,
})
})
}
}

View File

@@ -1,208 +0,0 @@
// Copyright 2023 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"
"github.com/google/blueprint/bootstrap"
"android/soong/android"
)
func runGoTests(t *testing.T, tc Bp2buildTestCase) {
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {
tCtx := ctx.(*android.TestContext)
bootstrap.RegisterGoModuleTypes(tCtx.Context.Context) // android.TestContext --> android.Context --> blueprint.Context
}, tc)
}
func TestConvertGoPackage(t *testing.T) {
bp := `
bootstrap_go_package {
name: "foo",
pkgPath: "android/foo",
deps: [
"bar",
],
srcs: [
"foo1.go",
"foo2.go",
],
linux: {
srcs: [
"foo_linux.go",
],
testSrcs: [
"foo_linux_test.go",
],
},
darwin: {
srcs: [
"foo_darwin.go",
],
testSrcs: [
"foo_darwin_test.go",
],
},
testSrcs: [
"foo1_test.go",
"foo2_test.go",
],
}
`
depBp := `
bootstrap_go_package {
name: "bar",
}
`
t.Parallel()
runGoTests(t, Bp2buildTestCase{
Description: "Convert bootstrap_go_package to go_library",
ModuleTypeUnderTest: "bootrstap_go_package",
Blueprint: bp,
Filesystem: map[string]string{
"bar/Android.bp": depBp, // Put dep in Android.bp to reduce boilerplate in ExpectedBazelTargets
},
ExpectedBazelTargets: []string{makeBazelTargetHostOrDevice("go_library", "foo",
AttrNameToString{
"deps": `["//bar:bar"]`,
"importpath": `"android/foo"`,
"srcs": `[
"foo1.go",
"foo2.go",
] + select({
"//build/bazel_common_rules/platforms/os:darwin": ["foo_darwin.go"],
"//build/bazel_common_rules/platforms/os:linux_glibc": ["foo_linux.go"],
"//conditions:default": [],
})`,
},
android.HostSupported,
),
makeBazelTargetHostOrDevice("go_test", "foo-test",
AttrNameToString{
"embed": `[":foo"]`,
"srcs": `[
"foo1_test.go",
"foo2_test.go",
] + select({
"//build/bazel_common_rules/platforms/os:darwin": ["foo_darwin_test.go"],
"//build/bazel_common_rules/platforms/os:linux_glibc": ["foo_linux_test.go"],
"//conditions:default": [],
})`,
},
android.HostSupported,
)},
})
}
func TestConvertGoBinaryWithTransitiveDeps(t *testing.T) {
bp := `
blueprint_go_binary {
name: "foo",
srcs: ["main.go"],
deps: ["bar"],
}
`
depBp := `
bootstrap_go_package {
name: "bar",
deps: ["baz"],
}
bootstrap_go_package {
name: "baz",
}
`
t.Parallel()
runGoTests(t, Bp2buildTestCase{
Description: "Convert blueprint_go_binary to go_binary",
Blueprint: bp,
Filesystem: map[string]string{
"bar/Android.bp": depBp, // Put dep in Android.bp to reduce boilerplate in ExpectedBazelTargets
},
ExpectedBazelTargets: []string{makeBazelTargetHostOrDevice("go_binary", "foo",
AttrNameToString{
"deps": `[
"//bar:bar",
"//bar:baz",
]`,
"srcs": `["main.go"]`,
},
android.HostSupported,
)},
})
}
func TestConvertGoBinaryWithTestSrcs(t *testing.T) {
bp := `
blueprint_go_binary {
name: "foo",
srcs: ["main.go"],
testSrcs: ["main_test.go"],
}
`
t.Parallel()
runGoTests(t, Bp2buildTestCase{
Description: "Convert blueprint_go_binary with testSrcs",
Blueprint: bp,
ExpectedBazelTargets: []string{
makeBazelTargetHostOrDevice("go_binary", "foo",
AttrNameToString{
"deps": `[]`,
"embed": `[":foo-source"]`,
},
android.HostSupported,
),
makeBazelTargetHostOrDevice("go_source", "foo-source",
AttrNameToString{
"deps": `[]`,
"srcs": `["main.go"]`,
},
android.HostSupported,
),
makeBazelTargetHostOrDevice("go_test", "foo-test",
AttrNameToString{
"embed": `[":foo-source"]`,
"srcs": `["main_test.go"]`,
},
android.HostSupported,
),
},
})
}
func TestConvertGoBinaryWithSrcInDifferentPackage(t *testing.T) {
bp := `
blueprint_go_binary {
name: "foo",
srcs: ["subdir/main.go"],
}
`
t.Parallel()
runGoTests(t, Bp2buildTestCase{
Description: "Convert blueprint_go_binary with src in different package",
Blueprint: bp,
Filesystem: map[string]string{
"subdir/Android.bp": "",
},
ExpectedBazelTargets: []string{makeBazelTargetHostOrDevice("go_binary", "foo",
AttrNameToString{
"deps": `[]`,
"srcs": `["//subdir:main.go"]`,
},
android.HostSupported,
)},
})
}

View File

@@ -1,338 +0,0 @@
// 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/cc"
"android/soong/java"
)
func runJavaBinaryHostTestCase(t *testing.T, tc Bp2buildTestCase) {
t.Helper()
(&tc).ModuleTypeUnderTest = "java_binary_host"
(&tc).ModuleTypeUnderTestFactory = java.BinaryHostFactory
tc.StubbedBuildDefinitions = append(tc.StubbedBuildDefinitions, "//other:jni-lib-1")
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {
ctx.RegisterModuleType("cc_library_host_shared", cc.LibraryHostSharedFactory)
ctx.RegisterModuleType("java_library", java.LibraryFactory)
ctx.RegisterModuleType("java_import_host", java.ImportFactory)
}, tc)
}
var testFs = map[string]string{
"test.mf": "Main-Class: com.android.test.MainClass",
"other/Android.bp": `cc_library_host_shared {
name: "jni-lib-1",
stl: "none",
}`,
}
func TestJavaBinaryHost(t *testing.T) {
runJavaBinaryHostTestCase(t, Bp2buildTestCase{
Description: "java_binary_host with srcs, exclude_srcs, jni_libs, javacflags, and manifest.",
Filesystem: testFs,
Blueprint: `java_binary_host {
name: "java-binary-host-1",
srcs: ["a.java", "b.java"],
exclude_srcs: ["b.java"],
manifest: "test.mf",
jni_libs: ["jni-lib-1"],
javacflags: ["-Xdoclint:all/protected"],
bazel_module: { bp2build_available: true },
java_version: "8",
}`,
ExpectedBazelTargets: []string{
MakeBazelTarget("java_library", "java-binary-host-1_lib", AttrNameToString{
"srcs": `["a.java"]`,
"deps": `["//other:jni-lib-1"]`,
"java_version": `"8"`,
"javacopts": `["-Xdoclint:all/protected"]`,
"target_compatible_with": `select({
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
"//conditions:default": [],
})`,
}),
MakeBazelTarget("java_binary", "java-binary-host-1", AttrNameToString{
"main_class": `"com.android.test.MainClass"`,
"jvm_flags": `["-Djava.library.path=$${RUNPATH}other/jni-lib-1"]`,
"target_compatible_with": `select({
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
"//conditions:default": [],
})`,
"runtime_deps": `[":java-binary-host-1_lib"]`,
}),
},
})
}
func TestJavaBinaryHostRuntimeDeps(t *testing.T) {
runJavaBinaryHostTestCase(t, Bp2buildTestCase{
Description: "java_binary_host with srcs, exclude_srcs, jni_libs, javacflags, and manifest.",
Filesystem: testFs,
StubbedBuildDefinitions: []string{"java-dep-1"},
Blueprint: `java_binary_host {
name: "java-binary-host-1",
static_libs: ["java-dep-1"],
manifest: "test.mf",
bazel_module: { bp2build_available: true },
}
java_library {
name: "java-dep-1",
srcs: ["a.java"],
}
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("java_binary", "java-binary-host-1", AttrNameToString{
"main_class": `"com.android.test.MainClass"`,
"runtime_deps": `[":java-dep-1"]`,
"target_compatible_with": `select({
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
"//conditions:default": [],
})`,
}),
},
})
}
func TestJavaBinaryHostLibs(t *testing.T) {
runJavaBinaryHostTestCase(t, Bp2buildTestCase{
Description: "java_binary_host with srcs, libs.",
Filesystem: testFs,
StubbedBuildDefinitions: []string{"java-lib-dep-1", "java-lib-dep-1-neverlink"},
Blueprint: `java_binary_host {
name: "java-binary-host-libs",
libs: ["java-lib-dep-1"],
manifest: "test.mf",
srcs: ["a.java"],
}
java_import_host{
name: "java-lib-dep-1",
jars: ["foo.jar"],
}
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("java_library", "java-binary-host-libs_lib", AttrNameToString{
"srcs": `["a.java"]`,
"deps": `[":java-lib-dep-1-neverlink"]`,
"target_compatible_with": `select({
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
"//conditions:default": [],
})`,
}),
MakeBazelTarget("java_binary", "java-binary-host-libs", AttrNameToString{
"main_class": `"com.android.test.MainClass"`,
"target_compatible_with": `select({
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
"//conditions:default": [],
})`,
"runtime_deps": `[":java-binary-host-libs_lib"]`,
}),
},
})
}
func TestJavaBinaryHostKotlinSrcs(t *testing.T) {
runJavaBinaryHostTestCase(t, Bp2buildTestCase{
Description: "java_binary_host with srcs, libs.",
Filesystem: testFs,
Blueprint: `java_binary_host {
name: "java-binary-host",
manifest: "test.mf",
srcs: ["a.java", "b.kt"],
}
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("kt_jvm_library", "java-binary-host_lib", AttrNameToString{
"srcs": `[
"a.java",
"b.kt",
]`,
"target_compatible_with": `select({
"//build/bazel_common_rules/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_lib"]`,
"target_compatible_with": `select({
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
"//conditions:default": [],
})`,
}),
},
})
}
func TestJavaBinaryHostKotlinCommonSrcs(t *testing.T) {
runJavaBinaryHostTestCase(t, Bp2buildTestCase{
Description: "java_binary_host with common_srcs",
Filesystem: testFs,
Blueprint: `java_binary_host {
name: "java-binary-host",
manifest: "test.mf",
srcs: ["a.java"],
common_srcs: ["b.kt"],
}
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("kt_jvm_library", "java-binary-host_lib", AttrNameToString{
"srcs": `["a.java"]`,
"common_srcs": `["b.kt"]`,
"target_compatible_with": `select({
"//build/bazel_common_rules/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_lib"]`,
"target_compatible_with": `select({
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
"//conditions:default": [],
})`,
}),
},
})
}
func TestJavaBinaryHostKotlinWithResourceDir(t *testing.T) {
runJavaBinaryHostTestCase(t, Bp2buildTestCase{
Description: "java_binary_host with srcs, libs, resource dir .",
Filesystem: map[string]string{
"test.mf": "Main-Class: com.android.test.MainClass",
"res/a.res": "",
"res/dir1/b.res": "",
},
Blueprint: `java_binary_host {
name: "java-binary-host",
manifest: "test.mf",
srcs: ["a.java", "b.kt"],
java_resource_dirs: ["res"],
}
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("kt_jvm_library", "java-binary-host_lib", AttrNameToString{
"srcs": `[
"a.java",
"b.kt",
]`,
"resources": `[
"res/a.res",
"res/dir1/b.res",
]`,
"resource_strip_prefix": `"res"`,
"target_compatible_with": `select({
"//build/bazel_common_rules/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_lib"]`,
"target_compatible_with": `select({
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
"//conditions:default": [],
})`,
}),
},
})
}
func TestJavaBinaryHostKotlinWithResources(t *testing.T) {
runJavaBinaryHostTestCase(t, Bp2buildTestCase{
Description: "java_binary_host with srcs, libs, resources.",
Filesystem: map[string]string{
"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": `[
"a.java",
"b.kt",
]`,
"resources": `[
"res/a.res",
"res/b.res",
]`,
"resource_strip_prefix": `"adir"`,
"target_compatible_with": `select({
"//build/bazel_common_rules/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_lib"]`,
"target_compatible_with": `select({
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
"//conditions:default": [],
})`,
}),
},
})
}
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_lib", AttrNameToString{
"srcs": `["a.kt"]`,
"kotlincflags": `[
"-flag1",
"-flag2",
]`,
"target_compatible_with": `select({
"//build/bazel_common_rules/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_lib"]`,
"target_compatible_with": `select({
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
"//conditions:default": [],
})`,
}),
},
})
}

View File

@@ -1,67 +0,0 @@
// Copyright 2023 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"
)
func runJavaHostForDeviceTestCaseWithRegistrationCtxFunc(t *testing.T, tc Bp2buildTestCase, registrationCtxFunc func(ctx android.RegistrationContext)) {
t.Helper()
(&tc).ModuleTypeUnderTest = "java_host_for_device"
(&tc).ModuleTypeUnderTestFactory = java.HostForDeviceFactory
RunBp2BuildTestCase(t, registrationCtxFunc, tc)
}
func runJavaHostForDeviceTestCase(t *testing.T, tc Bp2buildTestCase) {
t.Helper()
runJavaHostForDeviceTestCaseWithRegistrationCtxFunc(t, tc, func(ctx android.RegistrationContext) {
ctx.RegisterModuleType("java_library", java.LibraryFactory)
})
}
func TestJavaHostForDevice(t *testing.T) {
runJavaHostForDeviceTestCase(t, Bp2buildTestCase{
Description: "java_host_for_device test",
Blueprint: `java_host_for_device {
name: "java-lib-1",
libs: ["java-lib-2"],
bazel_module: { bp2build_available: true },
}
java_library {
name: "java-lib-2",
srcs: ["b.java"],
bazel_module: { bp2build_available: true },
sdk_version: "current",
}`,
ExpectedBazelTargets: []string{
MakeBazelTarget("java_host_for_device", "java-lib-1", AttrNameToString{
"exports": `[":java-lib-2"]`,
}),
MakeNeverlinkDuplicateTargetWithAttrs("java_library", "java-lib-1", AttrNameToString{
"sdk_version": `"none"`,
}),
MakeBazelTarget("java_library", "java-lib-2", AttrNameToString{
"srcs": `["b.java"]`,
"sdk_version": `"current"`,
}),
MakeNeverlinkDuplicateTarget("java_library", "java-lib-2"),
},
})
}

View File

@@ -1,157 +0,0 @@
// Copyright 2022 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 (
"android/soong/android"
"android/soong/java"
"testing"
)
func runJavaImportTestCaseWithRegistrationCtxFunc(t *testing.T, tc Bp2buildTestCase, registrationCtxFunc func(ctx android.RegistrationContext)) {
t.Helper()
(&tc).ModuleTypeUnderTest = "java_import"
(&tc).ModuleTypeUnderTestFactory = java.ImportFactory
RunBp2BuildTestCase(t, registrationCtxFunc, tc)
}
func runJavaImportTestCase(t *testing.T, tc Bp2buildTestCase) {
t.Helper()
RunBp2BuildTestCase(t, registerJavaImportModuleTypes, tc)
}
func registerJavaImportModuleTypes(ctx android.RegistrationContext) {
}
func TestJavaImportMinimal(t *testing.T) {
runJavaImportTestCase(t, Bp2buildTestCase{
Description: "Java import - simple example",
ModuleTypeUnderTest: "java_import",
ModuleTypeUnderTestFactory: java.ImportFactory,
Filesystem: map[string]string{
"import.jar": "",
},
Blueprint: `
java_import {
name: "example_import",
jars: ["import.jar"],
bazel_module: { bp2build_available: true },
}
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("java_import", "example_import", AttrNameToString{
"jars": `["import.jar"]`,
}),
MakeBazelTarget("java_library", "example_import-neverlink", AttrNameToString{
"exports": `[":example_import"]`,
"neverlink": `True`,
"sdk_version": `"none"`,
}),
}})
}
func TestJavaImportArchVariant(t *testing.T) {
runJavaImportTestCase(t, Bp2buildTestCase{
Description: "Java import - simple example",
ModuleTypeUnderTest: "java_import",
ModuleTypeUnderTestFactory: java.ImportFactory,
Filesystem: map[string]string{
"import.jar": "",
},
Blueprint: `
java_import {
name: "example_import",
target: {
android: {
jars: ["android.jar"],
},
linux_glibc: {
jars: ["linux.jar"],
},
},
bazel_module: { bp2build_available: true },
}
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("java_import", "example_import", AttrNameToString{
"jars": `select({
"//build/bazel_common_rules/platforms/os:android": ["android.jar"],
"//build/bazel_common_rules/platforms/os:linux_glibc": ["linux.jar"],
"//conditions:default": [],
})`,
}),
MakeBazelTarget("java_library", "example_import-neverlink", AttrNameToString{
"exports": `[":example_import"]`,
"neverlink": `True`,
"sdk_version": `"none"`,
}),
}})
}
func TestJavaImportHost(t *testing.T) {
runJavaImportTestCase(t, Bp2buildTestCase{
Description: "Java import host- simple example",
ModuleTypeUnderTest: "java_import_host",
ModuleTypeUnderTestFactory: java.ImportFactory,
Filesystem: map[string]string{
"import.jar": "",
},
Blueprint: `
java_import_host {
name: "example_import",
jars: ["import.jar"],
bazel_module: { bp2build_available: true },
}
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("java_import", "example_import", AttrNameToString{
"jars": `["import.jar"]`,
}),
MakeBazelTarget("java_library", "example_import-neverlink", AttrNameToString{
"exports": `[":example_import"]`,
"neverlink": `True`,
"sdk_version": `"none"`,
}),
}})
}
func TestJavaImportSameNameAsJavaLibrary(t *testing.T) {
runJavaImportTestCaseWithRegistrationCtxFunc(t, Bp2buildTestCase{
Description: "java_import has the same name as other package java_library's",
Filesystem: map[string]string{
"foo/bar/Android.bp": simpleModule("java_library", "test_lib"),
"test.jar": "",
},
Blueprint: `java_import {
name: "test_lib",
jars: ["test.jar"],
bazel_module: { bp2build_available: true },
}
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("java_import", "test_lib", AttrNameToString{
"jars": `["test.jar"]`,
}),
MakeBazelTarget("java_library", "test_lib-neverlink", AttrNameToString{
"exports": `[":test_lib"]`,
"neverlink": `True`,
"sdk_version": `"none"`,
}),
},
}, func(ctx android.RegistrationContext) {
ctx.RegisterModuleType("java_library", java.LibraryFactory)
})
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,84 +0,0 @@
// 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"
)
func runJavaLibraryHostTestCase(t *testing.T, tc Bp2buildTestCase) {
t.Helper()
(&tc).ModuleTypeUnderTest = "java_library_host"
(&tc).ModuleTypeUnderTestFactory = java.LibraryHostFactory
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, tc)
}
func TestJavaLibraryHost(t *testing.T) {
runJavaLibraryHostTestCase(t, Bp2buildTestCase{
Description: "java_library_host with srcs, exclude_srcs and libs",
Blueprint: `java_library_host {
name: "java-lib-host-1",
srcs: ["a.java", "b.java"],
exclude_srcs: ["b.java"],
libs: ["java-lib-host-2"],
bazel_module: { bp2build_available: true },
}
java_library_host {
name: "java-lib-host-2",
srcs: ["c.java"],
bazel_module: { bp2build_available: true },
java_version: "9",
}`,
ExpectedBazelTargets: []string{
MakeBazelTarget("java_library", "java-lib-host-1", AttrNameToString{
"srcs": `["a.java"]`,
"deps": `[":java-lib-host-2-neverlink"]`,
"target_compatible_with": `select({
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
"//conditions:default": [],
})`,
}),
MakeBazelTarget("java_library", "java-lib-host-1-neverlink", AttrNameToString{
"exports": `[":java-lib-host-1"]`,
"neverlink": `True`,
"target_compatible_with": `select({
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
"//conditions:default": [],
})`,
}),
MakeBazelTarget("java_library", "java-lib-host-2", AttrNameToString{
"java_version": `"9"`,
"srcs": `["c.java"]`,
"target_compatible_with": `select({
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
"//conditions:default": [],
})`,
}),
MakeBazelTarget("java_library", "java-lib-host-2-neverlink", AttrNameToString{
"exports": `[":java-lib-host-2"]`,
"neverlink": `True`,
"target_compatible_with": `select({
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
"//conditions:default": [],
})`,
"java_version": `"9"`,
}),
},
})
}

View File

@@ -1,108 +0,0 @@
// 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"
)
func runJavaPluginTestCase(t *testing.T, tc Bp2buildTestCase) {
t.Helper()
(&tc).ModuleTypeUnderTest = "java_plugin"
(&tc).ModuleTypeUnderTestFactory = java.PluginFactory
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {
ctx.RegisterModuleType("java_library", java.LibraryFactory)
}, tc)
}
func TestJavaPlugin(t *testing.T) {
runJavaPluginTestCase(t, Bp2buildTestCase{
Description: "java_plugin with srcs, libs, static_libs",
StubbedBuildDefinitions: []string{"java-lib-1", "java-lib-2"},
Blueprint: `java_plugin {
name: "java-plug-1",
srcs: ["a.java", "b.java"],
libs: ["java-lib-1"],
static_libs: ["java-lib-2"],
bazel_module: { bp2build_available: true },
java_version: "7",
}
java_library {
name: "java-lib-1",
srcs: ["b.java"],
}
java_library {
name: "java-lib-2",
srcs: ["c.java"],
}`,
ExpectedBazelTargets: []string{
MakeBazelTarget("java_plugin", "java-plug-1", AttrNameToString{
"target_compatible_with": `select({
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
"//conditions:default": [],
})`,
"deps": `[
":java-lib-1-neverlink",
":java-lib-2",
]`,
"srcs": `[
"a.java",
"b.java",
]`,
"java_version": `"7"`,
}),
},
})
}
func TestJavaPluginNoSrcs(t *testing.T) {
runJavaPluginTestCase(t, Bp2buildTestCase{
Description: "java_plugin without srcs converts (static) libs to deps",
StubbedBuildDefinitions: []string{"java-lib-1", "java-lib-2"},
Blueprint: `java_plugin {
name: "java-plug-1",
libs: ["java-lib-1"],
static_libs: ["java-lib-2"],
bazel_module: { bp2build_available: true },
}
java_library {
name: "java-lib-1",
srcs: ["b.java"],
}
java_library {
name: "java-lib-2",
srcs: ["c.java"],
}`,
ExpectedBazelTargets: []string{
MakeBazelTarget("java_plugin", "java-plug-1", AttrNameToString{
"target_compatible_with": `select({
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
"//conditions:default": [],
})`,
"deps": `[
":java-lib-1-neverlink",
":java-lib-2",
]`,
}),
},
})
}

View File

@@ -1,238 +0,0 @@
// 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 (
"fmt"
"testing"
"android/soong/android"
"android/soong/java"
)
func runJavaProtoTestCase(t *testing.T, tc Bp2buildTestCase) {
t.Helper()
(&tc).ModuleTypeUnderTest = "java_library_static"
(&tc).ModuleTypeUnderTestFactory = java.LibraryFactory
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, tc)
}
func TestJavaProto(t *testing.T) {
testCases := []struct {
protoType string
javaLibraryType string
javaLibraryNameExtension string
}{
{
protoType: "nano",
javaLibraryType: "java_nano_proto_library",
javaLibraryNameExtension: "java_proto_nano",
},
{
protoType: "micro",
javaLibraryType: "java_micro_proto_library",
javaLibraryNameExtension: "java_proto_micro",
},
{
protoType: "lite",
javaLibraryType: "java_lite_proto_library",
javaLibraryNameExtension: "java_proto_lite",
},
{
protoType: "stream",
javaLibraryType: "java_stream_proto_library",
javaLibraryNameExtension: "java_proto_stream",
},
{
protoType: "full",
javaLibraryType: "java_proto_library",
javaLibraryNameExtension: "java_proto",
},
}
bp := `java_library_static {
name: "java-protos",
proto: {
type: "%s",
},
srcs: ["a.proto"],
sdk_version: "current",
}`
protoLibrary := MakeBazelTarget("proto_library", "java-protos_proto", AttrNameToString{
"srcs": `["a.proto"]`,
})
for _, tc := range testCases {
javaLibraryName := fmt.Sprintf("java-protos_%s", tc.javaLibraryNameExtension)
runJavaProtoTestCase(t, Bp2buildTestCase{
Description: fmt.Sprintf("java_proto %s", tc.protoType),
Blueprint: fmt.Sprintf(bp, tc.protoType),
ExpectedBazelTargets: []string{
protoLibrary,
MakeBazelTarget(
tc.javaLibraryType,
javaLibraryName,
AttrNameToString{
"deps": `[":java-protos_proto"]`,
"sdk_version": `"current"`,
}),
MakeBazelTarget("java_library", "java-protos", AttrNameToString{
"exports": fmt.Sprintf(`[":%s"]`, javaLibraryName),
"sdk_version": `"current"`,
}),
MakeNeverlinkDuplicateTarget("java_library", "java-protos"),
},
})
}
}
func TestJavaProtoDefault(t *testing.T) {
runJavaProtoTestCase(t, Bp2buildTestCase{
Description: "java_library proto default",
Blueprint: `java_library_static {
name: "java-protos",
srcs: ["a.proto"],
java_version: "7",
sdk_version: "current",
}
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("proto_library", "java-protos_proto", AttrNameToString{
"srcs": `["a.proto"]`,
}),
MakeBazelTarget(
"java_lite_proto_library",
"java-protos_java_proto_lite",
AttrNameToString{
"deps": `[":java-protos_proto"]`,
"java_version": `"7"`,
"sdk_version": `"current"`,
}),
MakeBazelTarget("java_library", "java-protos", AttrNameToString{
"exports": `[":java-protos_java_proto_lite"]`,
"java_version": `"7"`,
"sdk_version": `"current"`,
}),
MakeNeverlinkDuplicateTargetWithAttrs(
"java_library",
"java-protos",
AttrNameToString{
"java_version": `"7"`,
"sdk_version": `"current"`,
}),
},
})
}
func TestJavaLibsAndOnlyProtoSrcs(t *testing.T) {
runJavaProtoTestCase(t, Bp2buildTestCase{
Description: "java_library that has only proto srcs",
StubbedBuildDefinitions: []string{"java-lib-1", "java-lib-2"},
Blueprint: `java_library_static {
name: "java-protos",
srcs: ["a.proto"],
libs: ["java-lib-1"],
static_libs: ["java-lib-2"],
java_version: "7",
sdk_version: "current",
}
java_library_static {
name: "java-lib-1",
}
java_library_static {
name: "java-lib-2",
}
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("proto_library", "java-protos_proto", AttrNameToString{
"srcs": `["a.proto"]`,
}),
MakeBazelTarget(
"java_lite_proto_library",
"java-protos_java_proto_lite",
AttrNameToString{
"deps": `[":java-protos_proto"]`,
"additional_proto_deps": `[
":java-lib-1-neverlink",
":java-lib-2",
]`,
"java_version": `"7"`,
"sdk_version": `"current"`,
}),
MakeBazelTarget("java_library", "java-protos", AttrNameToString{
"exports": `[
":java-lib-2",
":java-protos_java_proto_lite",
]`,
"java_version": `"7"`,
"sdk_version": `"current"`,
}),
MakeNeverlinkDuplicateTargetWithAttrs(
"java_library",
"java-protos",
AttrNameToString{
"java_version": `"7"`,
"sdk_version": `"current"`,
}),
},
})
}
func TestJavaProtoPlugin(t *testing.T) {
runJavaProtoTestCase(t, Bp2buildTestCase{
Description: "java_library proto plugin",
StubbedBuildDefinitions: []string{"protoc-gen-test-plugin"},
Blueprint: `java_library_static {
name: "java-protos",
srcs: ["a.proto"],
proto: {
plugin: "test-plugin",
},
sdk_version: "current",
}
java_library_static {
name: "protoc-gen-test-plugin",
}
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("proto_library", "java-protos_proto", AttrNameToString{
"srcs": `["a.proto"]`,
}),
MakeBazelTarget(
"java_lite_proto_library",
"java-protos_java_proto_lite",
AttrNameToString{
"deps": `[":java-protos_proto"]`,
"plugin": `":protoc-gen-test-plugin"`,
"sdk_version": `"current"`,
}),
MakeBazelTarget("java_library", "java-protos", AttrNameToString{
"exports": `[":java-protos_java_proto_lite"]`,
"sdk_version": `"current"`,
}),
MakeNeverlinkDuplicateTargetWithAttrs(
"java_library",
"java-protos",
AttrNameToString{
"sdk_version": `"current"`,
}),
},
})
}

View File

@@ -1,148 +0,0 @@
// Copyright 2023 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"
)
func runJavaSdkLibraryTestCaseWithRegistrationCtxFunc(t *testing.T, tc Bp2buildTestCase, registrationCtxFunc func(ctx android.RegistrationContext)) {
t.Helper()
(&tc).ModuleTypeUnderTest = "java_sdk_library"
(&tc).ModuleTypeUnderTestFactory = java.SdkLibraryFactory
RunBp2BuildTestCase(t, registrationCtxFunc, tc)
}
func runJavaSdkLibraryTestCase(t *testing.T, tc Bp2buildTestCase) {
t.Helper()
runJavaSdkLibraryTestCaseWithRegistrationCtxFunc(t, tc, func(ctx android.RegistrationContext) {})
}
func TestJavaSdkLibraryApiSurfaceGeneral(t *testing.T) {
runJavaSdkLibraryTestCase(t, Bp2buildTestCase{
Description: "limited java_sdk_library for api surfaces, general conversion",
Filesystem: map[string]string{
"build/soong/scripts/gen-java-current-api-files.sh": "",
"api/current.txt": "",
"api/system-current.txt": "",
"api/test-current.txt": "",
"api/module-lib-current.txt": "",
"api/system-server-current.txt": "",
"api/removed.txt": "",
"api/system-removed.txt": "",
"api/test-removed.txt": "",
"api/module-lib-removed.txt": "",
"api/system-server-removed.txt": "",
},
Blueprint: `java_sdk_library {
name: "java-sdk-lib",
srcs: ["a.java"],
public: {enabled: true},
system: {enabled: true},
test: {enabled: true},
module_lib: {enabled: true},
system_server: {enabled: true},
}`,
ExpectedBazelTargets: []string{
MakeBazelTarget("java_sdk_library", "java-sdk-lib", AttrNameToString{
"public": `"api/current.txt"`,
"system": `"api/system-current.txt"`,
"test": `"api/test-current.txt"`,
"module_lib": `"api/module-lib-current.txt"`,
"system_server": `"api/system-server-current.txt"`,
}),
},
})
}
func TestJavaSdkLibraryApiSurfacePublicDefault(t *testing.T) {
runJavaSdkLibraryTestCase(t, Bp2buildTestCase{
Description: "limited java_sdk_library for api surfaces, public prop uses default value",
Filesystem: map[string]string{
"build/soong/scripts/gen-java-current-api-files.sh": "",
"api/current.txt": "",
"api/system-current.txt": "",
"api/test-current.txt": "",
"api/module-lib-current.txt": "",
"api/system-server-current.txt": "",
"api/removed.txt": "",
"api/system-removed.txt": "",
"api/test-removed.txt": "",
"api/module-lib-removed.txt": "",
"api/system-server-removed.txt": "",
},
Blueprint: `java_sdk_library {
name: "java-sdk-lib",
srcs: ["a.java"],
system: {enabled: false},
test: {enabled: false},
module_lib: {enabled: false},
system_server: {enabled: false},
}`,
ExpectedBazelTargets: []string{
MakeBazelTarget("java_sdk_library", "java-sdk-lib", AttrNameToString{
"public": `"api/current.txt"`,
}),
},
})
}
func TestJavaSdkLibraryApiSurfacePublicNotEnabled(t *testing.T) {
runJavaSdkLibraryTestCase(t, Bp2buildTestCase{
Description: "limited java_sdk_library for api surfaces, public enable is false",
Filesystem: map[string]string{
"build/soong/scripts/gen-java-current-api-files.sh": "",
"api/current.txt": "",
"api/removed.txt": "",
},
Blueprint: `java_sdk_library {
name: "java-sdk-lib",
srcs: ["a.java"],
public: {enabled: false},
}`,
ExpectedBazelTargets: []string{
MakeBazelTarget("java_sdk_library", "java-sdk-lib", AttrNameToString{}),
},
})
}
func TestJavaSdkLibraryApiSurfaceNoScopeIsSet(t *testing.T) {
runJavaSdkLibraryTestCase(t, Bp2buildTestCase{
Description: "limited java_sdk_library for api surfaces, none of the api scopes is set",
Filesystem: map[string]string{
"build/soong/scripts/gen-java-current-api-files.sh": "",
"api/current.txt": "",
"api/system-current.txt": "",
"api/test-current.txt": "",
"api/removed.txt": "",
"api/system-removed.txt": "",
"api/test-removed.txt": "",
},
Blueprint: `java_sdk_library {
name: "java-sdk-lib",
srcs: ["a.java"],
}`,
ExpectedBazelTargets: []string{
MakeBazelTarget("java_sdk_library", "java-sdk-lib", AttrNameToString{
"public": `"api/current.txt"`,
"system": `"api/system-current.txt"`,
"test": `"api/test-current.txt"`,
}),
},
})
}

View File

@@ -1,84 +0,0 @@
// Copyright 2023 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/java"
)
func runJavaSdkLibraryImportTestCase(t *testing.T, tc Bp2buildTestCase) {
t.Helper()
RunBp2BuildTestCase(t, java.RegisterSdkLibraryBuildComponents, tc)
}
func TestJavaSdkLibraryImport(t *testing.T) {
runJavaSdkLibraryImportTestCase(t, Bp2buildTestCase{
Blueprint: `
java_sdk_library_import {
name : "foo",
public: {
current_api: "foo_current.txt",
},
system: {
current_api: "system_foo_current.txt",
},
}
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("java_sdk_library", "foo", AttrNameToString{
"public": `"foo_current.txt"`,
"system": `"system_foo_current.txt"`,
}),
},
})
}
func TestJavaSdkLibraryImportPrebuiltPrefixRemoved(t *testing.T) {
runJavaSdkLibraryImportTestCase(t, Bp2buildTestCase{
Filesystem: map[string]string{
"foobar/Android.bp": `
java_sdk_library {
name: "foo",
srcs: ["**/*.java"],
}
`,
"foobar/api/current.txt": "",
"foobar/api/system-current.txt": "",
"foobar/api/test-current.txt": "",
"foobar/api/removed.txt": "",
"foobar/api/system-removed.txt": "",
"foobar/api/test-removed.txt": "",
},
Blueprint: `
java_sdk_library_import {
name : "foo",
public: {
current_api: "foo_current.txt",
},
system: {
current_api: "system_foo_current.txt",
},
}
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("java_sdk_library", "foo", AttrNameToString{
"public": `"foo_current.txt"`,
"system": `"system_foo_current.txt"`,
}),
},
})
}

View File

@@ -1,156 +0,0 @@
// Copyright 2023 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"
)
func runJavaTestHostTestCase(t *testing.T, tc Bp2buildTestCase) {
t.Helper()
(&tc).ModuleTypeUnderTest = "java_test_host"
(&tc).ModuleTypeUnderTestFactory = java.TestHostFactory
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {
ctx.RegisterModuleType("java_library", java.LibraryFactory)
}, tc)
}
func TestJavaTestHostGeneral(t *testing.T) {
runJavaTestHostTestCase(t, Bp2buildTestCase{
Description: "java_test_host general",
Filesystem: map[string]string{},
StubbedBuildDefinitions: []string{"lib_a", "static_libs_a"},
Blueprint: `
java_test_host {
name: "java_test_host-1",
srcs: ["a.java", "b.java"],
libs: ["lib_a"],
static_libs: ["static_libs_a"],
exclude_srcs: ["b.java"],
javacflags: ["-Xdoclint:all/protected"],
java_version: "8",
}
java_library {
name: "lib_a",
}
java_library {
name: "static_libs_a",
}
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("java_library", "java_test_host-1_lib", AttrNameToString{
"deps": `[
":lib_a-neverlink",
":static_libs_a",
]`,
"java_version": `"8"`,
"javacopts": `["-Xdoclint:all/protected"]`,
"srcs": `["a.java"]`,
"target_compatible_with": `select({
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
"//conditions:default": [],
})`,
}),
MakeBazelTarget("java_test", "java_test_host-1", AttrNameToString{
"runtime_deps": `[":java_test_host-1_lib"]`,
"deps": `[
":lib_a-neverlink",
":static_libs_a",
]`,
"srcs": `["a.java"]`,
"target_compatible_with": `select({
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
"//conditions:default": [],
})`,
}),
},
})
}
func TestJavaTestHostNoSrcs(t *testing.T) {
runJavaTestHostTestCase(t, Bp2buildTestCase{
Description: "java_test_host without srcs",
Filesystem: map[string]string{},
Blueprint: `
java_test_host {
name: "java_test_host-1",
libs: ["lib_a"],
static_libs: ["static_libs_a"],
}
java_library {
name: "lib_a",
}
java_library {
name: "static_libs_a",
}
`,
StubbedBuildDefinitions: []string{"lib_a", "static_libs_a"},
ExpectedBazelTargets: []string{
MakeBazelTarget("java_test", "java_test_host-1", AttrNameToString{
"runtime_deps": `[
":lib_a-neverlink",
":static_libs_a",
]`,
"target_compatible_with": `select({
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
"//conditions:default": [],
})`,
}),
},
})
}
func TestJavaTestHostKotlinSrcs(t *testing.T) {
runJavaTestHostTestCase(t, Bp2buildTestCase{
Description: "java_test_host with .kt in srcs",
Filesystem: map[string]string{},
Blueprint: `
java_test_host {
name: "java_test_host-1",
srcs: ["a.java", "b.kt"],
}
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("java_test", "java_test_host-1", AttrNameToString{
"srcs": `[
"a.java",
"b.kt",
]`,
"runtime_deps": `[":java_test_host-1_lib"]`,
"target_compatible_with": `select({
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
"//conditions:default": [],
})`,
}),
MakeBazelTarget("kt_jvm_library", "java_test_host-1_lib", AttrNameToString{
"srcs": `[
"a.java",
"b.kt",
]`,
"target_compatible_with": `select({
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
"//conditions:default": [],
})`,
}),
},
})
}

View File

@@ -1,81 +0,0 @@
// Copyright 2022 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 (
"android/soong/android"
"testing"
)
func registerLicenseModuleTypes(_ android.RegistrationContext) {}
func TestLicenseBp2Build(t *testing.T) {
tests := []struct {
description string
module string
expected ExpectedRuleTarget
}{
{
description: "license kind and text notice",
module: `
license {
name: "my_license",
license_kinds: [ "SPDX-license-identifier-Apache-2.0"],
license_text: [ "NOTICE"],
}`,
expected: ExpectedRuleTarget{
"android_license",
"my_license",
AttrNameToString{
"license_kinds": `["SPDX-license-identifier-Apache-2.0"]`,
"license_text": `"NOTICE"`,
},
android.HostAndDeviceDefault,
},
},
{
description: "visibility, package_name, copyright_notice",
module: `
license {
name: "my_license",
package_name: "my_package",
visibility: [":__subpackages__"],
copyright_notice: "Copyright © 2022",
}`,
expected: ExpectedRuleTarget{
"android_license",
"my_license",
AttrNameToString{
"copyright_notice": `"Copyright © 2022"`,
"package_name": `"my_package"`,
"visibility": `[":__subpackages__"]`,
},
android.HostAndDeviceDefault,
},
},
}
for _, test := range tests {
RunBp2BuildTestCase(t,
registerLicenseModuleTypes,
Bp2buildTestCase{
Description: test.description,
ModuleTypeUnderTest: "license",
ModuleTypeUnderTestFactory: android.LicenseFactory,
Blueprint: test.module,
ExpectedBazelTargets: []string{test.expected.String()},
})
}
}

View File

@@ -1,69 +0,0 @@
// Copyright 2022 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 (
"android/soong/android"
"testing"
)
func registerLicenseKindModuleTypes(_ android.RegistrationContext) {}
func TestLicenseKindBp2Build(t *testing.T) {
tests := []struct {
description string
module string
expected ExpectedRuleTarget
}{
{
description: "license_kind",
module: `
license_kind {
name: "my_license",
conditions: [
"by_exception_only",
"not_allowed",
],
url: "https://spdx.org/licenses/0BSD",
visibility: ["//visibility:public"],
}`,
expected: ExpectedRuleTarget{
"license_kind",
"my_license",
AttrNameToString{
"conditions": `[
"by_exception_only",
"not_allowed",
]`,
"url": `"https://spdx.org/licenses/0BSD"`,
"visibility": `["//visibility:public"]`,
},
android.HostAndDeviceDefault,
},
},
}
for _, test := range tests {
RunBp2BuildTestCase(t,
registerLicenseKindModuleTypes,
Bp2buildTestCase{
Description: test.description,
ModuleTypeUnderTest: "license_kind",
ModuleTypeUnderTestFactory: android.LicenseKindFactory,
Blueprint: test.module,
ExpectedBazelTargets: []string{test.expected.String()},
})
}
}

View File

@@ -1,59 +0,0 @@
// Copyright 2022 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 (
"fmt"
"testing"
"android/soong/linkerconfig"
)
func runLinkerConfigTestCase(t *testing.T, tc Bp2buildTestCase) {
t.Helper()
(&tc).ModuleTypeUnderTest = "linker_config"
(&tc).ModuleTypeUnderTestFactory = linkerconfig.LinkerConfigFactory
RunBp2BuildTestCaseSimple(t, tc)
}
func TestLinkerConfigConvertsSrc(t *testing.T) {
runLinkerConfigTestCase(t,
Bp2buildTestCase{
Blueprint: `
linker_config {
name: "foo",
src: "a.json",
}
`,
ExpectedBazelTargets: []string{MakeBazelTarget("linker_config", "foo", AttrNameToString{
"src": `"a.json"`,
})},
})
}
func TestLinkerConfigNoSrc(t *testing.T) {
runLinkerConfigTestCase(t,
Bp2buildTestCase{
Blueprint: `
linker_config {
name: "foo",
}
`,
ExpectedBazelTargets: []string{},
ExpectedErr: fmt.Errorf("Android.bp:2:1: module \"foo\": src: empty src is not supported"),
})
}

View File

@@ -1,139 +0,0 @@
// Copyright 2022 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/genrule"
)
func registerDependentModules(ctx android.RegistrationContext) {
ctx.RegisterModuleType("license", android.LicenseFactory)
ctx.RegisterModuleType("genrule", genrule.GenRuleFactory)
}
func TestPackage(t *testing.T) {
tests := []struct {
description string
modules string
fs map[string]string
expected []ExpectedRuleTarget
}{
{
description: "with default applicable licenses",
modules: `
license {
name: "my_license",
visibility: [":__subpackages__"],
license_kinds: ["SPDX-license-identifier-Apache-2.0"],
license_text: ["NOTICE"],
}
package {
default_applicable_licenses: ["my_license"],
}
`,
expected: []ExpectedRuleTarget{
{
"package",
"",
AttrNameToString{
"default_package_metadata": `[":my_license"]`,
"default_visibility": `["//visibility:public"]`,
},
android.HostAndDeviceDefault,
},
{
"android_license",
"my_license",
AttrNameToString{
"license_kinds": `["SPDX-license-identifier-Apache-2.0"]`,
"license_text": `"NOTICE"`,
"visibility": `[":__subpackages__"]`,
},
android.HostAndDeviceDefault,
},
},
},
{
description: "package has METADATA file",
fs: map[string]string{
"METADATA": ``,
},
modules: `
license {
name: "my_license",
visibility: [":__subpackages__"],
license_kinds: ["SPDX-license-identifier-Apache-2.0"],
license_text: ["NOTICE"],
}
package {
default_applicable_licenses: ["my_license"],
}
`,
expected: []ExpectedRuleTarget{
{
"package",
"",
AttrNameToString{
"default_package_metadata": `[
":my_license",
":default_metadata_file",
]`,
"default_visibility": `["//visibility:public"]`,
},
android.HostAndDeviceDefault,
},
{
"android_license",
"my_license",
AttrNameToString{
"license_kinds": `["SPDX-license-identifier-Apache-2.0"]`,
"license_text": `"NOTICE"`,
"visibility": `[":__subpackages__"]`,
},
android.HostAndDeviceDefault,
},
{
"filegroup",
"default_metadata_file",
AttrNameToString{
"applicable_licenses": `[]`,
"srcs": `["METADATA"]`,
},
android.HostAndDeviceDefault,
},
},
},
}
for _, test := range tests {
expected := make([]string, 0, len(test.expected))
for _, e := range test.expected {
expected = append(expected, e.String())
}
RunBp2BuildTestCase(t, registerDependentModules,
Bp2buildTestCase{
Description: test.description,
ModuleTypeUnderTest: "package",
ModuleTypeUnderTestFactory: android.PackageFactory,
Blueprint: test.modules,
ExpectedBazelTargets: expected,
Filesystem: test.fs,
})
}
}

View File

@@ -1,54 +0,0 @@
// Copyright 2023 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"
)
func runPlatformCompatConfigTestCase(t *testing.T, tc Bp2buildTestCase) {
t.Helper()
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {
ctx.RegisterModuleType("java_library", java.LibraryFactory)
ctx.RegisterModuleType("platform_compat_config", java.PlatformCompatConfigFactory)
}, tc)
}
func TestPlatformCompatConfig(t *testing.T) {
runPlatformCompatConfigTestCase(t, Bp2buildTestCase{
Description: "platform_compat_config - conversion test",
Blueprint: `
platform_compat_config {
name: "foo",
src: ":lib",
}`,
StubbedBuildDefinitions: []string{"//a/b:lib"},
Filesystem: map[string]string{
"a/b/Android.bp": `
java_library {
name: "lib",
srcs: ["a.java"],
}`,
},
ExpectedBazelTargets: []string{
MakeBazelTarget("platform_compat_config", "foo", AttrNameToString{
"src": `"//a/b:lib"`,
}),
},
})
}

View File

@@ -1,396 +0,0 @@
// 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 (
"fmt"
"testing"
"android/soong/android"
"android/soong/etc"
)
func runPrebuiltEtcTestCase(t *testing.T, tc Bp2buildTestCase) {
t.Helper()
(&tc).ModuleTypeUnderTest = "prebuilt_etc"
(&tc).ModuleTypeUnderTestFactory = etc.PrebuiltEtcFactory
RunBp2BuildTestCase(t, registerPrebuiltModuleTypes, tc)
}
func runPrebuiltRootHostTestCase(t *testing.T, tc Bp2buildTestCase) {
t.Helper()
(&tc).ModuleTypeUnderTest = "prebuilt_root_host"
(&tc).ModuleTypeUnderTestFactory = etc.PrebuiltRootHostFactory
RunBp2BuildTestCase(t, registerPrebuiltModuleTypes, tc)
}
func registerPrebuiltModuleTypes(ctx android.RegistrationContext) {
}
func TestPrebuiltEtcSimple(t *testing.T) {
runPrebuiltEtcTestCase(t, Bp2buildTestCase{
Description: "prebuilt_etc - simple example",
Filesystem: map[string]string{},
Blueprint: `
prebuilt_etc {
name: "apex_tz_version",
src: "version/tz_version",
filename: "tz_version",
sub_dir: "tz",
installable: false,
}
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("prebuilt_file", "apex_tz_version", AttrNameToString{
"filename": `"tz_version"`,
"installable": `False`,
"src": `"version/tz_version"`,
"dir": `"etc/tz"`,
})}})
}
func TestPrebuiltEtcArchVariant(t *testing.T) {
runPrebuiltEtcTestCase(t, Bp2buildTestCase{
Description: "prebuilt_etc - arch variant",
Filesystem: map[string]string{},
Blueprint: `
prebuilt_etc {
name: "apex_tz_version",
src: "version/tz_version",
filename: "tz_version",
sub_dir: "tz",
installable: false,
arch: {
arm: {
src: "arm",
},
arm64: {
src: "arm64",
},
}
}
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("prebuilt_file", "apex_tz_version", AttrNameToString{
"filename": `"tz_version"`,
"installable": `False`,
"src": `select({
"//build/bazel_common_rules/platforms/arch:arm": "arm",
"//build/bazel_common_rules/platforms/arch:arm64": "arm64",
"//conditions:default": "version/tz_version",
})`,
"dir": `"etc/tz"`,
})}})
}
func TestPrebuiltEtcArchAndTargetVariant(t *testing.T) {
runPrebuiltEtcTestCase(t, Bp2buildTestCase{
Description: "prebuilt_etc - arch variant",
Filesystem: map[string]string{},
Blueprint: `
prebuilt_etc {
name: "apex_tz_version",
src: "version/tz_version",
filename: "tz_version",
sub_dir: "tz",
installable: false,
arch: {
arm: {
src: "arm",
},
arm64: {
src: "darwin_or_arm64",
},
},
target: {
darwin: {
src: "darwin_or_arm64",
}
},
}
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("prebuilt_file", "apex_tz_version", AttrNameToString{
"filename": `"tz_version"`,
"installable": `False`,
"src": `select({
"//build/bazel_common_rules/platforms/os_arch:android_arm": "arm",
"//build/bazel_common_rules/platforms/os_arch:android_arm64": "darwin_or_arm64",
"//build/bazel_common_rules/platforms/os_arch:darwin_arm64": "darwin_or_arm64",
"//build/bazel_common_rules/platforms/os_arch:darwin_x86_64": "darwin_or_arm64",
"//build/bazel_common_rules/platforms/os_arch:linux_bionic_arm64": "darwin_or_arm64",
"//conditions:default": "version/tz_version",
})`,
"dir": `"etc/tz"`,
})}})
}
func TestPrebuiltEtcProductVariables(t *testing.T) {
runPrebuiltEtcTestCase(t, Bp2buildTestCase{
Description: "prebuilt etc - product variables",
Filesystem: map[string]string{},
Blueprint: `
prebuilt_etc {
name: "apex_tz_version",
src: "version/tz_version",
filename: "tz_version",
product_variables: {
native_coverage: {
src: "src1",
},
},
}
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("prebuilt_file", "apex_tz_version", AttrNameToString{
"filename": `"tz_version"`,
"src": `select({
"//build/bazel/product_config/config_settings:native_coverage": "src1",
"//conditions:default": "version/tz_version",
})`,
"dir": `"etc"`,
})}})
}
func runPrebuiltUsrShareTestCase(t *testing.T, tc Bp2buildTestCase) {
t.Helper()
(&tc).ModuleTypeUnderTest = "prebuilt_usr_share"
(&tc).ModuleTypeUnderTestFactory = etc.PrebuiltUserShareFactory
RunBp2BuildTestCase(t, registerPrebuiltModuleTypes, tc)
}
func registerPrebuiltUsrShareModuleTypes(ctx android.RegistrationContext) {
}
func TestPrebuiltUsrShareSimple(t *testing.T) {
runPrebuiltUsrShareTestCase(t, Bp2buildTestCase{
Description: "prebuilt_usr_share - simple example",
Filesystem: map[string]string{},
Blueprint: `
prebuilt_usr_share {
name: "apex_tz_version",
src: "version/tz_version",
filename: "tz_version",
sub_dir: "tz",
installable: false,
}
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("prebuilt_file", "apex_tz_version", AttrNameToString{
"filename": `"tz_version"`,
"installable": `False`,
"src": `"version/tz_version"`,
"dir": `"usr/share/tz"`,
})}})
}
func TestPrebuiltEtcNoSubdir(t *testing.T) {
runPrebuiltEtcTestCase(t, Bp2buildTestCase{
Description: "prebuilt_etc - no subdir",
Filesystem: map[string]string{},
Blueprint: `
prebuilt_etc {
name: "apex_tz_version",
src: "version/tz_version",
filename: "tz_version",
installable: false,
}
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("prebuilt_file", "apex_tz_version", AttrNameToString{
"filename": `"tz_version"`,
"installable": `False`,
"src": `"version/tz_version"`,
"dir": `"etc"`,
})}})
}
func TestFilenameAsProperty(t *testing.T) {
runPrebuiltEtcTestCase(t, Bp2buildTestCase{
Description: "prebuilt_etc - filename is specified as a property ",
Filesystem: map[string]string{},
Blueprint: `
prebuilt_etc {
name: "foo",
src: "fooSrc",
filename: "fooFileName",
}
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("prebuilt_file", "foo", AttrNameToString{
"filename": `"fooFileName"`,
"src": `"fooSrc"`,
"dir": `"etc"`,
})}})
}
func TestFileNameFromSrc(t *testing.T) {
runPrebuiltEtcTestCase(t, Bp2buildTestCase{
Description: "prebuilt_etc - filename_from_src is true ",
Filesystem: map[string]string{},
Blueprint: `
prebuilt_etc {
name: "foo",
filename_from_src: true,
src: "fooSrc",
}
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("prebuilt_file", "foo", AttrNameToString{
"filename": `"fooSrc"`,
"src": `"fooSrc"`,
"dir": `"etc"`,
})}})
}
func TestFileNameFromSrcMultipleSrcs(t *testing.T) {
runPrebuiltEtcTestCase(t, Bp2buildTestCase{
Description: "prebuilt_etc - filename_from_src is true but there are multiple srcs",
Filesystem: map[string]string{},
Blueprint: `
prebuilt_etc {
name: "foo",
filename_from_src: true,
arch: {
arm: {
src: "barSrc",
},
arm64: {
src: "bazSrc",
},
}
}
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("prebuilt_file", "foo", AttrNameToString{
"filename_from_src": `True`,
"dir": `"etc"`,
"src": `select({
"//build/bazel_common_rules/platforms/arch:arm": "barSrc",
"//build/bazel_common_rules/platforms/arch:arm64": "bazSrc",
"//conditions:default": None,
})`,
})}})
}
func TestFilenameFromModuleName(t *testing.T) {
runPrebuiltEtcTestCase(t, Bp2buildTestCase{
Description: "prebuilt_etc - neither filename nor filename_from_src are specified ",
Filesystem: map[string]string{},
Blueprint: `
prebuilt_etc {
name: "foo",
}
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("prebuilt_file", "foo", AttrNameToString{
"filename": `"foo"`,
"dir": `"etc"`,
})}})
}
func TestPrebuiltEtcProductVariableArchSrcs(t *testing.T) {
runPrebuiltEtcTestCase(t, Bp2buildTestCase{
Description: "prebuilt etc- SRcs from arch variant product variables",
Filesystem: map[string]string{},
Blueprint: `
prebuilt_etc {
name: "foo",
filename: "fooFilename",
arch: {
arm: {
src: "armSrc",
product_variables: {
native_coverage: {
src: "nativeCoverageArmSrc",
},
},
},
},
}`,
ExpectedBazelTargets: []string{
MakeBazelTarget("prebuilt_file", "foo", AttrNameToString{
"filename": `"fooFilename"`,
"dir": `"etc"`,
"src": `select({
"//build/bazel/product_config/config_settings:native_coverage-arm": "nativeCoverageArmSrc",
"//build/bazel_common_rules/platforms/arch:arm": "armSrc",
"//conditions:default": None,
})`,
})}})
}
func TestPrebuiltEtcProductVariableError(t *testing.T) {
runPrebuiltEtcTestCase(t, Bp2buildTestCase{
Description: "",
Filesystem: map[string]string{},
Blueprint: `
prebuilt_etc {
name: "foo",
filename: "fooFilename",
arch: {
arm: {
src: "armSrc",
},
},
product_variables: {
native_coverage: {
src: "nativeCoverageArmSrc",
},
},
}`,
ExpectedErr: fmt.Errorf("label attribute could not be collapsed"),
})
}
func TestPrebuiltEtcNoConversionIfSrcEqualsName(t *testing.T) {
runPrebuiltEtcTestCase(t, Bp2buildTestCase{
Description: "",
Filesystem: map[string]string{},
Blueprint: `
prebuilt_etc {
name: "foo",
filename: "fooFilename",
src: "foo",
}`,
ExpectedBazelTargets: []string{},
})
}
func TestPrebuiltRootHostWithWildCardInSrc(t *testing.T) {
runPrebuiltRootHostTestCase(t, Bp2buildTestCase{
Description: "prebuilt_root_host - src string has wild card",
Filesystem: map[string]string{
"prh.dat": "",
},
Blueprint: `
prebuilt_root_host {
name: "prh_test",
src: "*.dat",
filename_from_src: true,
relative_install_path: "test/install/path",
bazel_module: { bp2build_available: true },
}
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("prebuilt_file", "prh_test", AttrNameToString{
"filename": `"prh.dat"`,
"src": `"prh.dat"`,
"dir": `"./test/install/path"`,
"target_compatible_with": `select({
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
"//conditions:default": [],
})`,
})}})
}

View File

@@ -1,320 +0,0 @@
package bp2build
import (
"testing"
"android/soong/android"
"android/soong/genrule"
"android/soong/python"
)
func runBp2BuildTestCaseWithPythonLibraries(t *testing.T, tc Bp2buildTestCase) {
t.Helper()
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {
ctx.RegisterModuleType("python_library", python.PythonLibraryFactory)
ctx.RegisterModuleType("python_library_host", python.PythonLibraryHostFactory)
ctx.RegisterModuleType("genrule", genrule.GenRuleFactory)
ctx.RegisterModuleType("python_defaults", python.DefaultsFactory)
}, tc)
}
func TestPythonBinaryHostSimple(t *testing.T) {
runBp2BuildTestCaseWithPythonLibraries(t, Bp2buildTestCase{
Description: "simple python_binary_host converts to a native py_binary",
ModuleTypeUnderTest: "python_binary_host",
ModuleTypeUnderTestFactory: python.PythonBinaryHostFactory,
Filesystem: map[string]string{
"a.py": "",
"b/c.py": "",
"b/d.py": "",
"b/e.py": "",
"files/data.txt": "",
},
StubbedBuildDefinitions: []string{"bar"},
Blueprint: `python_binary_host {
name: "foo",
main: "a.py",
srcs: ["**/*.py"],
exclude_srcs: ["b/e.py"],
data: ["files/data.txt",],
libs: ["bar"],
bazel_module: { bp2build_available: true },
}
python_library_host {
name: "bar",
srcs: ["b/e.py"],
}`,
ExpectedBazelTargets: []string{
MakeBazelTarget("py_binary", "foo", AttrNameToString{
"data": `["files/data.txt"]`,
"deps": `[":bar"]`,
"main": `"a.py"`,
"imports": `["."]`,
"srcs": `[
"a.py",
"b/c.py",
"b/d.py",
]`,
"target_compatible_with": `select({
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
"//conditions:default": [],
})`,
}),
},
})
}
func TestPythonBinaryHostPy2(t *testing.T) {
RunBp2BuildTestCaseSimple(t, Bp2buildTestCase{
Description: "py2 python_binary_host",
ModuleTypeUnderTest: "python_binary_host",
ModuleTypeUnderTestFactory: python.PythonBinaryHostFactory,
Blueprint: `python_binary_host {
name: "foo",
srcs: ["a.py"],
version: {
py2: {
enabled: true,
},
py3: {
enabled: false,
},
},
bazel_module: { bp2build_available: true },
}
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("py_binary", "foo", AttrNameToString{
"python_version": `"PY2"`,
"imports": `["."]`,
"srcs": `["a.py"]`,
"target_compatible_with": `select({
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
"//conditions:default": [],
})`,
}),
},
})
}
func TestPythonBinaryHostPy3(t *testing.T) {
RunBp2BuildTestCaseSimple(t, Bp2buildTestCase{
Description: "py3 python_binary_host",
ModuleTypeUnderTest: "python_binary_host",
ModuleTypeUnderTestFactory: python.PythonBinaryHostFactory,
Blueprint: `python_binary_host {
name: "foo",
srcs: ["a.py"],
version: {
py2: {
enabled: false,
},
py3: {
enabled: true,
},
},
bazel_module: { bp2build_available: true },
}
`,
ExpectedBazelTargets: []string{
// python_version is PY3 by default.
MakeBazelTarget("py_binary", "foo", AttrNameToString{
"imports": `["."]`,
"srcs": `["a.py"]`,
"target_compatible_with": `select({
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
"//conditions:default": [],
})`,
}),
},
})
}
func TestPythonBinaryHostArchVariance(t *testing.T) {
RunBp2BuildTestCaseSimple(t, Bp2buildTestCase{
Description: "test arch variants",
ModuleTypeUnderTest: "python_binary_host",
ModuleTypeUnderTestFactory: python.PythonBinaryHostFactory,
Filesystem: map[string]string{
"dir/arm.py": "",
"dir/x86.py": "",
},
Blueprint: `python_binary_host {
name: "foo-arm",
arch: {
arm: {
srcs: ["arm.py"],
},
x86: {
srcs: ["x86.py"],
},
},
}`,
ExpectedBazelTargets: []string{
MakeBazelTarget("py_binary", "foo-arm", AttrNameToString{
"imports": `["."]`,
"srcs": `select({
"//build/bazel_common_rules/platforms/arch:arm": ["arm.py"],
"//build/bazel_common_rules/platforms/arch:x86": ["x86.py"],
"//conditions:default": [],
})`,
"target_compatible_with": `select({
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
"//conditions:default": [],
})`,
}),
},
})
}
func TestPythonBinaryMainIsNotSpecified(t *testing.T) {
runBp2BuildTestCaseWithPythonLibraries(t, Bp2buildTestCase{
Description: "python_binary_host main label in same package",
ModuleTypeUnderTest: "python_binary_host",
ModuleTypeUnderTestFactory: python.PythonBinaryHostFactory,
Blueprint: `python_binary_host {
name: "foo",
bazel_module: { bp2build_available: true },
}
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("py_binary", "foo", AttrNameToString{
"imports": `["."]`,
"target_compatible_with": `select({
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
"//conditions:default": [],
})`,
}),
},
})
}
func TestPythonBinaryMainIsLabel(t *testing.T) {
runBp2BuildTestCaseWithPythonLibraries(t, Bp2buildTestCase{
Description: "python_binary_host main label in same package",
ModuleTypeUnderTest: "python_binary_host",
ModuleTypeUnderTestFactory: python.PythonBinaryHostFactory,
StubbedBuildDefinitions: []string{"a"},
Blueprint: `python_binary_host {
name: "foo",
main: ":a",
bazel_module: { bp2build_available: true },
}
genrule {
name: "a",
}
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("py_binary", "foo", AttrNameToString{
"main": `":a"`,
"imports": `["."]`,
"target_compatible_with": `select({
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
"//conditions:default": [],
})`,
}),
},
})
}
func TestPythonBinaryMainIsSubpackageFile(t *testing.T) {
runBp2BuildTestCaseWithPythonLibraries(t, Bp2buildTestCase{
Description: "python_binary_host main is subpackage file",
ModuleTypeUnderTest: "python_binary_host",
ModuleTypeUnderTestFactory: python.PythonBinaryHostFactory,
Filesystem: map[string]string{
"a/Android.bp": "",
"a/b.py": "",
},
Blueprint: `python_binary_host {
name: "foo",
main: "a/b.py",
bazel_module: { bp2build_available: true },
}
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("py_binary", "foo", AttrNameToString{
"main": `"//a:b.py"`,
"imports": `["."]`,
"target_compatible_with": `select({
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
"//conditions:default": [],
})`,
}),
},
})
}
func TestPythonBinaryMainIsSubDirFile(t *testing.T) {
runBp2BuildTestCaseWithPythonLibraries(t, Bp2buildTestCase{
Description: "python_binary_host main is file in sub directory that is not Bazel package",
ModuleTypeUnderTest: "python_binary_host",
ModuleTypeUnderTestFactory: python.PythonBinaryHostFactory,
Filesystem: map[string]string{
"a/b.py": "",
},
Blueprint: `python_binary_host {
name: "foo",
main: "a/b.py",
bazel_module: { bp2build_available: true },
}
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("py_binary", "foo", AttrNameToString{
"main": `"a/b.py"`,
"imports": `["."]`,
"target_compatible_with": `select({
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
"//conditions:default": [],
})`,
}),
},
})
}
func TestPythonBinaryDuplicatesInRequired(t *testing.T) {
runBp2BuildTestCaseWithPythonLibraries(t, Bp2buildTestCase{
Description: "python_binary_host duplicates in required attribute of the module and its defaults",
ModuleTypeUnderTest: "python_binary_host",
ModuleTypeUnderTestFactory: python.PythonBinaryHostFactory,
StubbedBuildDefinitions: []string{"r1", "r2"},
Blueprint: `python_binary_host {
name: "foo",
main: "a.py",
defaults: ["d"],
required: [
"r1",
],
bazel_module: { bp2build_available: true },
}
python_defaults {
name: "d",
required: [
"r1",
"r2",
],
}` + simpleModule("genrule", "r1") +
simpleModule("genrule", "r2"),
ExpectedBazelTargets: []string{
MakeBazelTarget("py_binary", "foo", AttrNameToString{
"main": `"a.py"`,
"imports": `["."]`,
"data": `[
":r1",
":r2",
]`,
"target_compatible_with": `select({
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
"//conditions:default": [],
})`,
}),
},
})
}

View File

@@ -1,392 +0,0 @@
package bp2build
import (
"fmt"
"strings"
"testing"
"android/soong/android"
"android/soong/python"
)
// TODO(alexmarquez): Should be lifted into a generic Bp2Build file
type PythonLibBp2Build func(ctx android.TopDownMutatorContext)
type pythonLibBp2BuildTestCase struct {
description string
filesystem map[string]string
blueprint string
expectedBazelTargets []testBazelTarget
dir string
expectedError error
stubbedBuildDefinitions []string
}
func convertPythonLibTestCaseToBp2build_Host(tc pythonLibBp2BuildTestCase) Bp2buildTestCase {
for i := range tc.expectedBazelTargets {
tc.expectedBazelTargets[i].attrs["target_compatible_with"] = `select({
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
"//conditions:default": [],
})`
}
return convertPythonLibTestCaseToBp2build(tc)
}
func convertPythonLibTestCaseToBp2build(tc pythonLibBp2BuildTestCase) Bp2buildTestCase {
var bp2BuildTargets []string
for _, t := range tc.expectedBazelTargets {
bp2BuildTargets = append(bp2BuildTargets, MakeBazelTarget(t.typ, t.name, t.attrs))
}
// Copy the filesystem so that we can change stuff in it later without it
// affecting the original pythonLibBp2BuildTestCase
filesystemCopy := make(map[string]string)
for k, v := range tc.filesystem {
filesystemCopy[k] = v
}
return Bp2buildTestCase{
Description: tc.description,
Filesystem: filesystemCopy,
Blueprint: tc.blueprint,
ExpectedBazelTargets: bp2BuildTargets,
Dir: tc.dir,
ExpectedErr: tc.expectedError,
StubbedBuildDefinitions: tc.stubbedBuildDefinitions,
}
}
func runPythonLibraryTestCase(t *testing.T, tc pythonLibBp2BuildTestCase) {
t.Helper()
testCase := convertPythonLibTestCaseToBp2build(tc)
testCase.Description = fmt.Sprintf(testCase.Description, "python_library")
testCase.Blueprint = fmt.Sprintf(testCase.Blueprint, "python_library")
for name, contents := range testCase.Filesystem {
if strings.HasSuffix(name, "Android.bp") {
testCase.Filesystem[name] = fmt.Sprintf(contents, "python_library")
}
}
testCase.ModuleTypeUnderTest = "python_library"
testCase.ModuleTypeUnderTestFactory = python.PythonLibraryFactory
RunBp2BuildTestCaseSimple(t, testCase)
}
func runPythonLibraryHostTestCase(t *testing.T, tc pythonLibBp2BuildTestCase) {
t.Helper()
testCase := convertPythonLibTestCaseToBp2build_Host(tc)
testCase.Description = fmt.Sprintf(testCase.Description, "python_library_host")
testCase.Blueprint = fmt.Sprintf(testCase.Blueprint, "python_library_host")
for name, contents := range testCase.Filesystem {
if strings.HasSuffix(name, "Android.bp") {
testCase.Filesystem[name] = fmt.Sprintf(contents, "python_library_host")
}
}
testCase.ModuleTypeUnderTest = "python_library_host"
testCase.ModuleTypeUnderTestFactory = python.PythonLibraryHostFactory
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {
ctx.RegisterModuleType("python_library", python.PythonLibraryFactory)
},
testCase)
}
func runPythonLibraryTestCases(t *testing.T, tc pythonLibBp2BuildTestCase) {
t.Helper()
runPythonLibraryTestCase(t, tc)
runPythonLibraryHostTestCase(t, tc)
}
func TestSimplePythonLib(t *testing.T) {
testCases := []pythonLibBp2BuildTestCase{
{
description: "simple %s converts to a native py_library",
filesystem: map[string]string{
"a.py": "",
"b/c.py": "",
"b/d.py": "",
"b/e.py": "",
"files/data.txt": "",
},
stubbedBuildDefinitions: []string{"bar"},
blueprint: `%s {
name: "foo",
srcs: ["**/*.py"],
exclude_srcs: ["b/e.py"],
data: ["files/data.txt",],
libs: ["bar"],
bazel_module: { bp2build_available: true },
}
python_library {
name: "bar",
srcs: ["b/e.py"],
}`,
expectedBazelTargets: []testBazelTarget{
{
typ: "py_library",
name: "foo",
attrs: AttrNameToString{
"data": `["files/data.txt"]`,
"deps": `[":bar"]`,
"srcs": `[
"a.py",
"b/c.py",
"b/d.py",
]`,
"srcs_version": `"PY3"`,
"imports": `["."]`,
},
},
},
},
{
description: "py2 %s converts to a native py_library",
blueprint: `%s {
name: "foo",
srcs: ["a.py"],
version: {
py2: {
enabled: true,
},
py3: {
enabled: false,
},
},
bazel_module: { bp2build_available: true },
}`,
expectedBazelTargets: []testBazelTarget{
{
typ: "py_library",
name: "foo",
attrs: AttrNameToString{
"srcs": `["a.py"]`,
"srcs_version": `"PY2"`,
"imports": `["."]`,
},
},
},
},
{
description: "py3 %s converts to a native py_library",
blueprint: `%s {
name: "foo",
srcs: ["a.py"],
version: {
py2: {
enabled: false,
},
py3: {
enabled: true,
},
},
bazel_module: { bp2build_available: true },
}`,
expectedBazelTargets: []testBazelTarget{
{
typ: "py_library",
name: "foo",
attrs: AttrNameToString{
"srcs": `["a.py"]`,
"srcs_version": `"PY3"`,
"imports": `["."]`,
},
},
},
},
{
description: "py2&3 %s converts to a native py_library",
blueprint: `%s {
name: "foo",
srcs: ["a.py"],
version: {
py2: {
enabled: true,
},
py3: {
enabled: true,
},
},
bazel_module: { bp2build_available: true },
}`,
expectedBazelTargets: []testBazelTarget{
{
// srcs_version is PY2ANDPY3 by default.
typ: "py_library",
name: "foo",
attrs: AttrNameToString{
"srcs": `["a.py"]`,
"imports": `["."]`,
},
},
},
},
{
description: "%s: pkg_path in a subdirectory of the same name converts correctly",
dir: "mylib/subpackage",
filesystem: map[string]string{
"mylib/subpackage/a.py": "",
"mylib/subpackage/Android.bp": `%s {
name: "foo",
srcs: ["a.py"],
pkg_path: "mylib/subpackage",
bazel_module: { bp2build_available: true },
}`,
},
blueprint: `%s {name: "bar"}`,
expectedBazelTargets: []testBazelTarget{
{
// srcs_version is PY2ANDPY3 by default.
typ: "py_library",
name: "foo",
attrs: AttrNameToString{
"srcs": `["a.py"]`,
"imports": `["../.."]`,
"srcs_version": `"PY3"`,
},
},
},
},
{
description: "%s: pkg_path in a subdirectory of a different name fails",
dir: "mylib/subpackage",
filesystem: map[string]string{
"mylib/subpackage/a.py": "",
"mylib/subpackage/Android.bp": `%s {
name: "foo",
srcs: ["a.py"],
pkg_path: "mylib/subpackage2",
bazel_module: { bp2build_available: true },
}`,
},
blueprint: `%s {name: "bar"}`,
expectedError: fmt.Errorf("Currently, bp2build only supports pkg_paths that are the same as the folders the Android.bp file is in."),
},
}
for _, tc := range testCases {
t.Run(tc.description, func(t *testing.T) {
runPythonLibraryTestCases(t, tc)
})
}
}
func TestPythonArchVariance(t *testing.T) {
runPythonLibraryTestCases(t, pythonLibBp2BuildTestCase{
description: "test %s arch variants",
filesystem: map[string]string{
"dir/arm.py": "",
"dir/x86.py": "",
},
blueprint: `%s {
name: "foo",
arch: {
arm: {
srcs: ["arm.py"],
},
x86: {
srcs: ["x86.py"],
},
},
}`,
expectedBazelTargets: []testBazelTarget{
{
typ: "py_library",
name: "foo",
attrs: AttrNameToString{
"srcs": `select({
"//build/bazel_common_rules/platforms/arch:arm": ["arm.py"],
"//build/bazel_common_rules/platforms/arch:x86": ["x86.py"],
"//conditions:default": [],
})`,
"srcs_version": `"PY3"`,
"imports": `["."]`,
},
},
},
})
}
func TestPythonLibraryWithProtobufs(t *testing.T) {
runPythonLibraryTestCases(t, pythonLibBp2BuildTestCase{
description: "test %s protobuf",
filesystem: map[string]string{
"dir/mylib.py": "",
"dir/myproto.proto": "",
},
blueprint: `%s {
name: "foo",
srcs: [
"dir/mylib.py",
"dir/myproto.proto",
],
}`,
expectedBazelTargets: []testBazelTarget{
{
typ: "proto_library",
name: "foo_proto",
attrs: AttrNameToString{
"srcs": `["dir/myproto.proto"]`,
},
},
{
typ: "py_proto_library",
name: "foo_py_proto",
attrs: AttrNameToString{
"deps": `[":foo_proto"]`,
},
},
{
typ: "py_library",
name: "foo",
attrs: AttrNameToString{
"srcs": `["dir/mylib.py"]`,
"srcs_version": `"PY3"`,
"imports": `["."]`,
"deps": `[":foo_py_proto"]`,
},
},
},
})
}
func TestPythonLibraryWithProtobufsAndPkgPath(t *testing.T) {
t.Parallel()
runBp2BuildTestCaseWithPythonLibraries(t, Bp2buildTestCase{
Description: "test python_library protobuf with pkg_path",
Filesystem: map[string]string{
"dir/foo.proto": "",
"dir/bar.proto": "", // bar contains "import dir/foo.proto"
"dir/Android.bp": `
python_library {
name: "foo",
pkg_path: "dir",
srcs: [
"foo.proto",
"bar.proto",
],
bazel_module: {bp2build_available: true},
}`,
},
Dir: "dir",
ExpectedBazelTargets: []string{
MakeBazelTarget("proto_library", "foo_proto", AttrNameToString{
"import_prefix": `"dir"`,
"strip_import_prefix": `""`,
"srcs": `[
"foo.proto",
"bar.proto",
]`,
}),
MakeBazelTarget("py_proto_library", "foo_py_proto", AttrNameToString{
"deps": `[":foo_proto"]`,
}),
MakeBazelTarget("py_library", "foo", AttrNameToString{
"srcs_version": `"PY3"`,
"imports": `[".."]`,
"deps": `[":foo_py_proto"]`,
}),
},
})
}

View File

@@ -1,67 +0,0 @@
// Copyright 2023 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/python"
)
func TestPythonTestHostSimple(t *testing.T) {
runBp2BuildTestCaseWithPythonLibraries(t, Bp2buildTestCase{
Description: "simple python_test_host converts to a native py_test",
ModuleTypeUnderTest: "python_test_host",
ModuleTypeUnderTestFactory: python.PythonTestHostFactory,
Filesystem: map[string]string{
"a.py": "",
"b/c.py": "",
"b/d.py": "",
"b/e.py": "",
"files/data.txt": "",
},
StubbedBuildDefinitions: []string{"bar"},
Blueprint: `python_test_host {
name: "foo",
main: "a.py",
srcs: ["**/*.py"],
exclude_srcs: ["b/e.py"],
data: ["files/data.txt",],
libs: ["bar"],
bazel_module: { bp2build_available: true },
}
python_library_host {
name: "bar",
srcs: ["b/e.py"],
}`,
ExpectedBazelTargets: []string{
MakeBazelTarget("py_test", "foo", AttrNameToString{
"data": `["files/data.txt"]`,
"deps": `[":bar"]`,
"main": `"a.py"`,
"imports": `["."]`,
"srcs": `[
"a.py",
"b/c.py",
"b/d.py",
]`,
"target_compatible_with": `select({
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
"//conditions:default": [],
})`,
}),
},
})
}

View File

@@ -1,88 +0,0 @@
// Copyright 2023 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 (
"android/soong/android"
"android/soong/rust"
"testing"
)
func runRustBinaryTestCase(t *testing.T, tc Bp2buildTestCase) {
t.Helper()
RunBp2BuildTestCase(t, registerRustBinaryModuleTypes, tc)
}
func registerRustBinaryModuleTypes(ctx android.RegistrationContext) {
ctx.RegisterModuleType("rust_binary_host", rust.RustBinaryHostFactory)
ctx.RegisterModuleType("rust_library_host", rust.RustLibraryHostFactory)
ctx.RegisterModuleType("rust_proc_macro", rust.ProcMacroFactory)
}
func TestRustBinaryHost(t *testing.T) {
runRustBinaryTestCase(t, Bp2buildTestCase{
Dir: "external/rust/crates/foo",
Blueprint: "",
Filesystem: map[string]string{
"external/rust/crates/foo/src/lib.rs": "",
"external/rust/crates/foo/src/helper.rs": "",
"external/rust/crates/foo/Android.bp": `
rust_binary_host {
name: "libfoo",
crate_name: "foo",
srcs: ["src/main.rs"],
edition: "2021",
features: ["bah-enabled"],
cfgs: ["baz"],
rustlibs: ["libbar"],
proc_macros: ["libbah"],
bazel_module: { bp2build_available: true },
}
`,
"external/rust/crates/bar/Android.bp": `
rust_library_host {
name: "libbar",
crate_name: "bar",
srcs: ["src/lib.rs"],
bazel_module: { bp2build_available: true },
}
`,
"external/rust/crates/bah/Android.bp": `
rust_proc_macro {
name: "libbah",
crate_name: "bah",
srcs: ["src/lib.rs"],
bazel_module: { bp2build_available: true },
}
`,
},
ExpectedBazelTargets: []string{
makeBazelTargetHostOrDevice("rust_binary", "libfoo", AttrNameToString{
"crate_name": `"foo"`,
"srcs": `[
"src/helper.rs",
"src/lib.rs",
]`,
"deps": `["//external/rust/crates/bar:libbar"]`,
"proc_macro_deps": `["//external/rust/crates/bah:libbah"]`,
"edition": `"2021"`,
"crate_features": `["bah-enabled"]`,
"rustc_flags": `["--cfg=baz"]`,
}, android.HostSupported),
},
},
)
}

View File

@@ -1,78 +0,0 @@
// Copyright 2023 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 (
"android/soong/android"
"android/soong/rust"
"testing"
)
func runRustFfiTestCase(t *testing.T, tc Bp2buildTestCase) {
t.Helper()
RunBp2BuildTestCase(t, registerRustFfiModuleTypes, tc)
}
func registerRustFfiModuleTypes(ctx android.RegistrationContext) {
ctx.RegisterModuleType("rust_ffi_static", rust.RustFFIStaticFactory)
ctx.RegisterModuleType("rust_library", rust.RustLibraryFactory)
}
func TestRustFfiStatic(t *testing.T) {
runRustFfiTestCase(t, Bp2buildTestCase{
Dir: "external/rust/crates/foo",
Blueprint: "",
Filesystem: map[string]string{
"external/rust/crates/foo/src/lib.rs": "",
"external/rust/crates/foo/src/helper.rs": "",
"external/rust/crates/foo/Android.bp": `
rust_ffi_static {
name: "libfoo",
crate_name: "foo",
host_supported: true,
srcs: ["src/lib.rs"],
edition: "2015",
include_dirs: [
"include",
],
rustlibs: ["libbar"],
bazel_module: { bp2build_available: true },
}
`,
"external/rust/crates/bar/Android.bp": `
rust_library {
name: "libbar",
crate_name: "bar",
host_supported: true,
srcs: ["src/lib.rs"],
bazel_module: { bp2build_available: true },
}
`,
},
ExpectedBazelTargets: []string{
MakeBazelTargetNoRestrictions("rust_ffi_static", "libfoo", AttrNameToString{
"crate_name": `"foo"`,
"deps": `["//external/rust/crates/bar:libbar"]`,
"srcs": `[
"src/helper.rs",
"src/lib.rs",
]`,
"edition": `"2015"`,
"export_includes": `["include"]`,
}),
},
},
)
}

View File

@@ -1,109 +0,0 @@
// Copyright 2023 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 (
"android/soong/android"
"android/soong/rust"
"testing"
)
func runRustLibraryTestCase(t *testing.T, tc Bp2buildTestCase) {
t.Helper()
RunBp2BuildTestCase(t, registerRustLibraryModuleTypes, tc)
}
func registerRustLibraryModuleTypes(ctx android.RegistrationContext) {
ctx.RegisterModuleType("rust_library", rust.RustLibraryFactory)
ctx.RegisterModuleType("rust_library_host", rust.RustLibraryHostFactory)
}
func TestLibProtobuf(t *testing.T) {
runRustLibraryTestCase(t, Bp2buildTestCase{
Dir: "external/rust/crates/foo",
Blueprint: "",
Filesystem: map[string]string{
"external/rust/crates/foo/src/lib.rs": "",
"external/rust/crates/foo/Android.bp": `
rust_library_host {
name: "libprotobuf",
crate_name: "protobuf",
srcs: ["src/lib.rs"],
bazel_module: { bp2build_available: true },
}
`,
},
ExpectedBazelTargets: []string{
// TODO(b/290790800): Remove the restriction when rust toolchain for android is implemented
makeBazelTargetHostOrDevice("rust_library", "libprotobuf", AttrNameToString{
"crate_name": `"protobuf"`,
"srcs": `["src/lib.rs"]`,
"deps": `[":libprotobuf_build_script"]`,
}, android.HostSupported),
makeBazelTargetHostOrDevice("cargo_build_script", "libprotobuf_build_script", AttrNameToString{
"srcs": `["build.rs"]`,
}, android.HostSupported),
},
},
)
}
func TestRustLibrary(t *testing.T) {
expectedAttrs := AttrNameToString{
"crate_name": `"foo"`,
"srcs": `[
"src/helper.rs",
"src/lib.rs",
]`,
"crate_features": `["bah-enabled"]`,
"edition": `"2021"`,
"rustc_flags": `["--cfg=baz"]`,
}
runRustLibraryTestCase(t, Bp2buildTestCase{
Dir: "external/rust/crates/foo",
Blueprint: "",
Filesystem: map[string]string{
"external/rust/crates/foo/src/lib.rs": "",
"external/rust/crates/foo/src/helper.rs": "",
"external/rust/crates/foo/Android.bp": `
rust_library {
name: "libfoo",
crate_name: "foo",
host_supported: true,
srcs: ["src/lib.rs"],
edition: "2021",
features: ["bah-enabled"],
cfgs: ["baz"],
bazel_module: { bp2build_available: true },
}
rust_library_host {
name: "libfoo_host",
crate_name: "foo",
srcs: ["src/lib.rs"],
edition: "2021",
features: ["bah-enabled"],
cfgs: ["baz"],
bazel_module: { bp2build_available: true },
}
`,
},
ExpectedBazelTargets: []string{
MakeBazelTargetNoRestrictions("rust_library", "libfoo", expectedAttrs),
makeBazelTargetHostOrDevice("rust_library", "libfoo_host", expectedAttrs, android.HostSupported),
},
},
)
}

View File

@@ -1,76 +0,0 @@
// Copyright 2023 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 (
"android/soong/android"
"android/soong/rust"
"testing"
)
func rustRustProcMacroTestCase(t *testing.T, tc Bp2buildTestCase) {
t.Helper()
RunBp2BuildTestCase(t, registerRustProcMacroModuleTypes, tc)
}
func registerRustProcMacroModuleTypes(ctx android.RegistrationContext) {
ctx.RegisterModuleType("rust_library_host", rust.RustLibraryHostFactory)
ctx.RegisterModuleType("rust_proc_macro", rust.ProcMacroFactory)
}
func TestRustProcMacroLibrary(t *testing.T) {
rustRustProcMacroTestCase(t, Bp2buildTestCase{
Dir: "external/rust/crates/foo",
Blueprint: "",
Filesystem: map[string]string{
"external/rust/crates/foo/src/lib.rs": "",
"external/rust/crates/foo/src/helper.rs": "",
"external/rust/crates/foo/Android.bp": `
rust_proc_macro {
name: "libfoo",
crate_name: "foo",
srcs: ["src/lib.rs"],
edition: "2021",
features: ["bah-enabled"],
cfgs: ["baz"],
rustlibs: ["libbar"],
bazel_module: { bp2build_available: true },
}
`,
"external/rust/crates/bar/src/lib.rs": "",
"external/rust/crates/bar/Android.bp": `
rust_library_host {
name: "libbar",
crate_name: "bar",
srcs: ["src/lib.rs"],
bazel_module: { bp2build_available: true },
}`,
},
ExpectedBazelTargets: []string{
makeBazelTargetHostOrDevice("rust_proc_macro", "libfoo", AttrNameToString{
"crate_name": `"foo"`,
"srcs": `[
"src/helper.rs",
"src/lib.rs",
]`,
"crate_features": `["bah-enabled"]`,
"edition": `"2021"`,
"rustc_flags": `["--cfg=baz"]`,
"deps": `["//external/rust/crates/bar:libbar"]`,
}, android.HostSupported),
},
},
)
}

View File

@@ -1,89 +0,0 @@
// Copyright 2023 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 (
"android/soong/android"
"android/soong/rust"
"testing"
)
func runRustProtobufTestCase(t *testing.T, tc Bp2buildTestCase) {
t.Helper()
RunBp2BuildTestCase(t, registerRustProtobufModuleTypes, tc)
}
func registerRustProtobufModuleTypes(ctx android.RegistrationContext) {
ctx.RegisterModuleType("rust_protobuf_host", rust.RustProtobufHostFactory)
ctx.RegisterModuleType("rust_protobuf", rust.RustProtobufHostFactory)
}
func TestRustProtobufHostTestCase(t *testing.T) {
runRustProtobufTestCase(t, Bp2buildTestCase{
Dir: "external/rust/crates/foo",
Blueprint: "",
Filesystem: map[string]string{
"external/rust/crates/foo/src/lib.rs": "",
"external/rust/crates/foo/src/helper.rs": "",
"external/rust/crates/foo/Android.bp": `
rust_protobuf_host {
name: "libfoo",
crate_name: "foo",
protos: ["src/foo.proto"],
bazel_module: { bp2build_available: true },
}
`,
},
ExpectedBazelTargets: []string{
makeBazelTargetHostOrDevice("proto_library", "libfoo_proto", AttrNameToString{
"srcs": `["src/foo.proto"]`,
}, android.HostSupported),
makeBazelTargetHostOrDevice("rust_proto_library", "libfoo", AttrNameToString{
"crate_name": `"foo"`,
"deps": `[":libfoo_proto"]`,
}, android.HostSupported),
},
},
)
}
func TestRustProtobufTestCase(t *testing.T) {
runRustProtobufTestCase(t, Bp2buildTestCase{
Dir: "external/rust/crates/foo",
Blueprint: "",
Filesystem: map[string]string{
"external/rust/crates/foo/src/lib.rs": "",
"external/rust/crates/foo/src/helper.rs": "",
"external/rust/crates/foo/Android.bp": `
rust_protobuf {
name: "libfoo",
crate_name: "foo",
protos: ["src/foo.proto"],
bazel_module: { bp2build_available: true },
}
`,
},
ExpectedBazelTargets: []string{
makeBazelTargetHostOrDevice("proto_library", "libfoo_proto", AttrNameToString{
"srcs": `["src/foo.proto"]`,
}, android.HostSupported),
makeBazelTargetHostOrDevice("rust_proto_library", "libfoo", AttrNameToString{
"crate_name": `"foo"`,
"deps": `[":libfoo_proto"]`,
}, android.HostSupported),
},
},
)
}

View File

@@ -1,92 +0,0 @@
// 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/sh"
)
func TestShBinaryLoadStatement(t *testing.T) {
testCases := []struct {
bazelTargets BazelTargets
expectedLoadStatements string
}{
{
bazelTargets: BazelTargets{
BazelTarget{
name: "sh_binary_target",
ruleClass: "sh_binary",
// Note: no bzlLoadLocation for native rules
// TODO(ruperts): Could open source the existing, experimental Starlark sh_ rules?
},
},
expectedLoadStatements: ``,
},
}
for _, testCase := range testCases {
actual := testCase.bazelTargets.LoadStatements()
expected := testCase.expectedLoadStatements
if actual != expected {
t.Fatalf("Expected load statements to be %s, got %s", expected, actual)
}
}
}
func runShBinaryTestCase(t *testing.T, tc Bp2buildTestCase) {
t.Helper()
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, tc)
}
func TestShBinarySimple(t *testing.T) {
runShBinaryTestCase(t, Bp2buildTestCase{
Description: "sh_binary test",
ModuleTypeUnderTest: "sh_binary",
ModuleTypeUnderTestFactory: sh.ShBinaryFactory,
Blueprint: `sh_binary {
name: "foo",
src: "foo.sh",
filename: "foo.exe",
sub_dir: "sub",
bazel_module: { bp2build_available: true },
}`,
ExpectedBazelTargets: []string{
MakeBazelTarget("sh_binary", "foo", AttrNameToString{
"srcs": `["foo.sh"]`,
"filename": `"foo.exe"`,
"sub_dir": `"sub"`,
})},
})
}
func TestShBinaryDefaults(t *testing.T) {
runShBinaryTestCase(t, Bp2buildTestCase{
Description: "sh_binary test",
ModuleTypeUnderTest: "sh_binary",
ModuleTypeUnderTestFactory: sh.ShBinaryFactory,
Blueprint: `sh_binary {
name: "foo",
src: "foo.sh",
bazel_module: { bp2build_available: true },
}`,
ExpectedBazelTargets: []string{
MakeBazelTarget("sh_binary", "foo", AttrNameToString{
"srcs": `["foo.sh"]`,
})},
})
}

View File

@@ -1,340 +0,0 @@
// Copyright 2023 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/sh"
)
func TestShTestSimple(t *testing.T) {
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {
ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
}, Bp2buildTestCase{
Description: "sh_test test",
ModuleTypeUnderTest: "sh_test",
StubbedBuildDefinitions: []string{"android.hardware.bluetooth@1.1-service.sim",
"android.hardware.bluetooth@1.1-impl-sim", "libc++", "libcrypto"},
ModuleTypeUnderTestFactory: sh.ShTestFactory,
Blueprint: simpleModule("filegroup", "android.hardware.bluetooth@1.1-service.sim") +
simpleModule("filegroup", "android.hardware.bluetooth@1.1-impl-sim") +
simpleModule("filegroup", "libc++") +
simpleModule("filegroup", "libcrypto") + `sh_test{
name: "sts-rootcanal-sidebins",
src: "empty.sh",
test_suites: [
"sts",
"sts-lite",
],
data_bins: [
"android.hardware.bluetooth@1.1-service.sim",
"android.hardware.bluetooth@1.1-impl-sim"
],
data: ["android.hardware.bluetooth@1.1-service.sim.rc"],
data_libs: ["libc++","libcrypto"],
test_config: "art-gtests-target-install-apex.xml",
test_config_template: ":art-run-test-target-template",
auto_gen_config: false,
test_options:{tags: ["no-remote"],
},
}`,
ExpectedBazelTargets: []string{
MakeBazelTarget("sh_test", "sts-rootcanal-sidebins", AttrNameToString{
"srcs": `["empty.sh"]`,
"runs_on": `["device"]`,
"data": `[
"android.hardware.bluetooth@1.1-service.sim.rc",
":android.hardware.bluetooth@1.1-service.sim",
":android.hardware.bluetooth@1.1-impl-sim",
":libc++",
":libcrypto",
]`,
"data_bins": `[
":android.hardware.bluetooth@1.1-service.sim",
":android.hardware.bluetooth@1.1-impl-sim",
]`,
"tags": `["no-remote"]`,
})},
})
}
func TestShTestHostSimple(t *testing.T) {
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {
ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
}, Bp2buildTestCase{
Description: "sh_test_host test",
ModuleTypeUnderTest: "sh_test_host",
StubbedBuildDefinitions: []string{"android.hardware.bluetooth@1.1-service.sim",
"android.hardware.bluetooth@1.1-impl-sim", "libc++", "libcrypto"},
ModuleTypeUnderTestFactory: sh.ShTestHostFactory,
Blueprint: simpleModule("filegroup", "android.hardware.bluetooth@1.1-service.sim") +
simpleModule("filegroup", "android.hardware.bluetooth@1.1-impl-sim") +
simpleModule("filegroup", "libc++") +
simpleModule("filegroup", "libcrypto") + `sh_test_host{
name: "sts-rootcanal-sidebins",
src: "empty.sh",
test_suites: [
"sts",
"sts-lite",
],
data_bins: [
"android.hardware.bluetooth@1.1-service.sim",
"android.hardware.bluetooth@1.1-impl-sim"
],
data: ["android.hardware.bluetooth@1.1-service.sim.rc"],
data_libs: ["libc++","libcrypto"],
test_config: "art-gtests-target-install-apex.xml",
test_config_template: ":art-run-test-target-template",
auto_gen_config: false,
test_options:{tags: ["no-remote"],
},
}`,
ExpectedBazelTargets: []string{
MakeBazelTarget("sh_test", "sts-rootcanal-sidebins", AttrNameToString{
"srcs": `["empty.sh"]`,
"runs_on": `["host_without_device"]`,
"data": `[
"android.hardware.bluetooth@1.1-service.sim.rc",
":android.hardware.bluetooth@1.1-service.sim",
":android.hardware.bluetooth@1.1-impl-sim",
":libc++",
":libcrypto",
]`,
"data_bins": `[
":android.hardware.bluetooth@1.1-service.sim",
":android.hardware.bluetooth@1.1-impl-sim",
]`,
"tags": `["no-remote"]`,
"target_compatible_with": `select({
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
"//conditions:default": [],
})`,
})},
})
}
func TestShTestAutogen(t *testing.T) {
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {
ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
}, Bp2buildTestCase{
Description: "sh_test test",
ModuleTypeUnderTest: "sh_test",
StubbedBuildDefinitions: []string{"android.hardware.bluetooth@1.1-service.sim",
"android.hardware.bluetooth@1.1-impl-sim", "libc++", "libcrypto", "art-run-test-target-template"},
ModuleTypeUnderTestFactory: sh.ShTestFactory,
Blueprint: simpleModule("filegroup", "android.hardware.bluetooth@1.1-service.sim") +
simpleModule("filegroup", "android.hardware.bluetooth@1.1-impl-sim") +
simpleModule("filegroup", "libc++") +
simpleModule("filegroup", "libcrypto") +
simpleModule("filegroup", "art-run-test-target-template") + `sh_test{
name: "sts-rootcanal-sidebins",
src: "empty.sh",
test_suites: [
"sts",
"sts-lite",
],
data_bins: [
"android.hardware.bluetooth@1.1-service.sim",
"android.hardware.bluetooth@1.1-impl-sim"
],
data: ["android.hardware.bluetooth@1.1-service.sim.rc"],
data_libs: ["libc++","libcrypto"],
test_config: "art-gtests-target-install-apex.xml",
test_config_template: ":art-run-test-target-template",
auto_gen_config: true,
test_options:{tags: ["no-remote"],
},
}`,
ExpectedBazelTargets: []string{
MakeBazelTarget("sh_test", "sts-rootcanal-sidebins", AttrNameToString{
"srcs": `["empty.sh"]`,
"runs_on": `["device"]`,
"auto_generate_test_config": "True",
"target_compatible_with": `["//build/bazel_common_rules/platforms/os:android"]`,
"template_test_config": `":art-run-test-target-template"`,
"data": `[
"android.hardware.bluetooth@1.1-service.sim.rc",
":android.hardware.bluetooth@1.1-service.sim",
":android.hardware.bluetooth@1.1-impl-sim",
":libc++",
":libcrypto",
]`,
"data_bins": `[
":android.hardware.bluetooth@1.1-service.sim",
":android.hardware.bluetooth@1.1-impl-sim",
]`,
"tags": `["no-remote"]`,
})},
})
}
func TestShTestHostAutogen(t *testing.T) {
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {
ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
}, Bp2buildTestCase{
Description: "sh_test_host test",
ModuleTypeUnderTest: "sh_test_host",
StubbedBuildDefinitions: []string{"android.hardware.bluetooth@1.1-service.sim",
"android.hardware.bluetooth@1.1-impl-sim", "libc++", "libcrypto", "art-run-test-target-template"},
ModuleTypeUnderTestFactory: sh.ShTestHostFactory,
Blueprint: simpleModule("filegroup", "android.hardware.bluetooth@1.1-service.sim") +
simpleModule("filegroup", "android.hardware.bluetooth@1.1-impl-sim") +
simpleModule("filegroup", "libc++") +
simpleModule("filegroup", "libcrypto") +
simpleModule("filegroup", "art-run-test-target-template") + `sh_test_host{
name: "sts-rootcanal-sidebins",
src: "empty.sh",
test_suites: [
"sts",
"sts-lite",
],
data_bins: [
"android.hardware.bluetooth@1.1-service.sim",
"android.hardware.bluetooth@1.1-impl-sim"
],
data: ["android.hardware.bluetooth@1.1-service.sim.rc"],
data_libs: ["libc++","libcrypto"],
test_config: "art-gtests-target-install-apex.xml",
test_config_template: ":art-run-test-target-template",
auto_gen_config: true,
test_options:{tags: ["no-remote"],
},
}`,
ExpectedBazelTargets: []string{
MakeBazelTarget("sh_test", "sts-rootcanal-sidebins", AttrNameToString{
"srcs": `["empty.sh"]`,
"runs_on": `["host_without_device"]`,
"auto_generate_test_config": "True",
"target_compatible_with": `select({
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
"//conditions:default": [],
})`,
"template_test_config": `":art-run-test-target-template"`,
"data": `[
"android.hardware.bluetooth@1.1-service.sim.rc",
":android.hardware.bluetooth@1.1-service.sim",
":android.hardware.bluetooth@1.1-impl-sim",
":libc++",
":libcrypto",
]`,
"data_bins": `[
":android.hardware.bluetooth@1.1-service.sim",
":android.hardware.bluetooth@1.1-impl-sim",
]`,
"tags": `["no-remote"]`,
})},
})
}
func TestShTestSimpleUnset(t *testing.T) {
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {
ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
}, Bp2buildTestCase{
Description: "sh_test test",
ModuleTypeUnderTest: "sh_test",
StubbedBuildDefinitions: []string{"android.hardware.bluetooth@1.1-service.sim",
"android.hardware.bluetooth@1.1-impl-sim", "libc++", "libcrypto"},
ModuleTypeUnderTestFactory: sh.ShTestFactory,
Blueprint: simpleModule("filegroup", "android.hardware.bluetooth@1.1-service.sim") +
simpleModule("filegroup", "android.hardware.bluetooth@1.1-impl-sim") +
simpleModule("filegroup", "libc++") +
simpleModule("filegroup", "libcrypto") + `sh_test{
name: "sts-rootcanal-sidebins",
src: "empty.sh",
test_suites: [
"sts",
"sts-lite",
],
data_bins: [
"android.hardware.bluetooth@1.1-service.sim",
"android.hardware.bluetooth@1.1-impl-sim"
],
data: ["android.hardware.bluetooth@1.1-service.sim.rc"],
data_libs: ["libc++","libcrypto"],
test_options:{tags: ["no-remote"],
},
}`,
ExpectedBazelTargets: []string{
MakeBazelTarget("sh_test", "sts-rootcanal-sidebins", AttrNameToString{
"srcs": `["empty.sh"]`,
"runs_on": `["device"]`,
"data": `[
"android.hardware.bluetooth@1.1-service.sim.rc",
":android.hardware.bluetooth@1.1-service.sim",
":android.hardware.bluetooth@1.1-impl-sim",
":libc++",
":libcrypto",
]`,
"data_bins": `[
":android.hardware.bluetooth@1.1-service.sim",
":android.hardware.bluetooth@1.1-impl-sim",
]`,
"tags": `["no-remote"]`,
})},
})
}
func TestShTestHostSimpleUnset(t *testing.T) {
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {
ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
}, Bp2buildTestCase{
Description: "sh_test_host test",
ModuleTypeUnderTest: "sh_test_host",
ModuleTypeUnderTestFactory: sh.ShTestHostFactory,
StubbedBuildDefinitions: []string{"android.hardware.bluetooth@1.1-service.sim",
"android.hardware.bluetooth@1.1-impl-sim", "libc++", "libcrypto"},
Blueprint: simpleModule("filegroup", "android.hardware.bluetooth@1.1-service.sim") +
simpleModule("filegroup", "android.hardware.bluetooth@1.1-impl-sim") +
simpleModule("filegroup", "libc++") +
simpleModule("filegroup", "libcrypto") + `sh_test_host{
name: "sts-rootcanal-sidebins",
src: "empty.sh",
test_suites: [
"sts",
"sts-lite",
],
data_bins: [
"android.hardware.bluetooth@1.1-service.sim",
"android.hardware.bluetooth@1.1-impl-sim"
],
data: ["android.hardware.bluetooth@1.1-service.sim.rc"],
data_libs: ["libc++","libcrypto"],
test_options:{tags: ["no-remote"],
},
}`,
ExpectedBazelTargets: []string{
MakeBazelTarget("sh_test", "sts-rootcanal-sidebins", AttrNameToString{
"srcs": `["empty.sh"]`,
"runs_on": `["host_without_device"]`,
"data": `[
"android.hardware.bluetooth@1.1-service.sim.rc",
":android.hardware.bluetooth@1.1-service.sim",
":android.hardware.bluetooth@1.1-impl-sim",
":libc++",
":libcrypto",
]`,
"data_bins": `[
":android.hardware.bluetooth@1.1-service.sim",
":android.hardware.bluetooth@1.1-impl-sim",
]`,
"tags": `["no-remote"]`,
"target_compatible_with": `select({
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
"//conditions:default": [],
})`,
})},
})
}

File diff suppressed because it is too large Load Diff