2021-03-24 15:04:33 +01:00
|
|
|
// Copyright 2021 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package bp2build
|
|
|
|
|
|
|
|
import (
|
|
|
|
"android/soong/android"
|
|
|
|
"android/soong/cc"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
// See cc/testing.go for more context
|
|
|
|
soongCcLibraryPreamble = `
|
|
|
|
cc_defaults {
|
|
|
|
name: "linux_bionic_supported",
|
|
|
|
}
|
|
|
|
|
|
|
|
toolchain_library {
|
|
|
|
name: "libclang_rt.builtins-x86_64-android",
|
|
|
|
defaults: ["linux_bionic_supported"],
|
|
|
|
vendor_available: true,
|
|
|
|
vendor_ramdisk_available: true,
|
|
|
|
product_available: true,
|
|
|
|
recovery_available: true,
|
|
|
|
native_bridge_supported: true,
|
|
|
|
src: "",
|
|
|
|
}`
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestCcLibraryBp2Build(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
description string
|
|
|
|
moduleTypeUnderTest string
|
|
|
|
moduleTypeUnderTestFactory android.ModuleFactory
|
|
|
|
moduleTypeUnderTestBp2BuildMutator func(android.TopDownMutatorContext)
|
|
|
|
bp string
|
|
|
|
expectedBazelTargets []string
|
|
|
|
filesystem map[string]string
|
|
|
|
dir string
|
2021-04-29 10:15:13 +02:00
|
|
|
depsMutators []android.RegisterMutatorFunc
|
2021-03-24 15:04:33 +01:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
description: "cc_library - simple example",
|
|
|
|
moduleTypeUnderTest: "cc_library",
|
|
|
|
moduleTypeUnderTestFactory: cc.LibraryFactory,
|
|
|
|
moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
|
|
|
|
filesystem: map[string]string{
|
|
|
|
"android.cpp": "",
|
|
|
|
"darwin.cpp": "",
|
|
|
|
// Refer to cc.headerExts for the supported header extensions in Soong.
|
|
|
|
"header.h": "",
|
|
|
|
"header.hh": "",
|
|
|
|
"header.hpp": "",
|
|
|
|
"header.hxx": "",
|
|
|
|
"header.h++": "",
|
|
|
|
"header.inl": "",
|
|
|
|
"header.inc": "",
|
|
|
|
"header.ipp": "",
|
|
|
|
"header.h.generic": "",
|
|
|
|
"impl.cpp": "",
|
|
|
|
"linux.cpp": "",
|
|
|
|
"x86.cpp": "",
|
|
|
|
"x86_64.cpp": "",
|
|
|
|
"foo-dir/a.h": "",
|
|
|
|
},
|
|
|
|
bp: soongCcLibraryPreamble + `
|
|
|
|
cc_library_headers { name: "some-headers" }
|
|
|
|
cc_library {
|
|
|
|
name: "foo-lib",
|
|
|
|
srcs: ["impl.cpp"],
|
|
|
|
cflags: ["-Wall"],
|
|
|
|
header_libs: ["some-headers"],
|
|
|
|
export_include_dirs: ["foo-dir"],
|
|
|
|
ldflags: ["-Wl,--exclude-libs=bar.a"],
|
|
|
|
arch: {
|
|
|
|
x86: {
|
|
|
|
ldflags: ["-Wl,--exclude-libs=baz.a"],
|
|
|
|
srcs: ["x86.cpp"],
|
|
|
|
},
|
|
|
|
x86_64: {
|
|
|
|
ldflags: ["-Wl,--exclude-libs=qux.a"],
|
|
|
|
srcs: ["x86_64.cpp"],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
target: {
|
|
|
|
android: {
|
|
|
|
srcs: ["android.cpp"],
|
|
|
|
},
|
|
|
|
linux_glibc: {
|
|
|
|
srcs: ["linux.cpp"],
|
|
|
|
},
|
|
|
|
darwin: {
|
|
|
|
srcs: ["darwin.cpp"],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
expectedBazelTargets: []string{`cc_library(
|
|
|
|
name = "foo-lib",
|
2021-04-13 09:14:55 +02:00
|
|
|
copts = [
|
|
|
|
"-Wall",
|
|
|
|
"-I.",
|
2021-05-13 21:13:04 +02:00
|
|
|
"-I$(BINDIR)/.",
|
2021-04-13 09:14:55 +02:00
|
|
|
],
|
2021-05-19 00:35:24 +02:00
|
|
|
implementation_deps = [":some-headers"],
|
2021-04-13 09:14:55 +02:00
|
|
|
includes = ["foo-dir"],
|
|
|
|
linkopts = ["-Wl,--exclude-libs=bar.a"] + select({
|
|
|
|
"//build/bazel/platforms/arch:x86": ["-Wl,--exclude-libs=baz.a"],
|
|
|
|
"//build/bazel/platforms/arch:x86_64": ["-Wl,--exclude-libs=qux.a"],
|
|
|
|
"//conditions:default": [],
|
|
|
|
}),
|
2021-04-27 07:54:20 +02:00
|
|
|
srcs = ["impl.cpp"] + select({
|
2021-04-08 16:40:57 +02:00
|
|
|
"//build/bazel/platforms/arch:x86": ["x86.cpp"],
|
|
|
|
"//build/bazel/platforms/arch:x86_64": ["x86_64.cpp"],
|
2021-03-24 15:04:33 +01:00
|
|
|
"//conditions:default": [],
|
|
|
|
}) + select({
|
2021-04-08 16:40:57 +02:00
|
|
|
"//build/bazel/platforms/os:android": ["android.cpp"],
|
|
|
|
"//build/bazel/platforms/os:darwin": ["darwin.cpp"],
|
|
|
|
"//build/bazel/platforms/os:linux": ["linux.cpp"],
|
2021-03-24 15:04:33 +01:00
|
|
|
"//conditions:default": [],
|
|
|
|
}),
|
|
|
|
)`},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
description: "cc_library - trimmed example of //bionic/linker:ld-android",
|
|
|
|
moduleTypeUnderTest: "cc_library",
|
|
|
|
moduleTypeUnderTestFactory: cc.LibraryFactory,
|
|
|
|
moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
|
|
|
|
filesystem: map[string]string{
|
|
|
|
"ld-android.cpp": "",
|
|
|
|
"linked_list.h": "",
|
|
|
|
"linker.h": "",
|
|
|
|
"linker_block_allocator.h": "",
|
|
|
|
"linker_cfi.h": "",
|
|
|
|
},
|
|
|
|
bp: soongCcLibraryPreamble + `
|
|
|
|
cc_library_headers { name: "libc_headers" }
|
|
|
|
cc_library {
|
|
|
|
name: "fake-ld-android",
|
|
|
|
srcs: ["ld_android.cpp"],
|
|
|
|
cflags: [
|
|
|
|
"-Wall",
|
|
|
|
"-Wextra",
|
|
|
|
"-Wunused",
|
|
|
|
"-Werror",
|
|
|
|
],
|
|
|
|
header_libs: ["libc_headers"],
|
|
|
|
ldflags: [
|
|
|
|
"-Wl,--exclude-libs=libgcc.a",
|
|
|
|
"-Wl,--exclude-libs=libgcc_stripped.a",
|
|
|
|
"-Wl,--exclude-libs=libclang_rt.builtins-arm-android.a",
|
|
|
|
"-Wl,--exclude-libs=libclang_rt.builtins-aarch64-android.a",
|
|
|
|
"-Wl,--exclude-libs=libclang_rt.builtins-i686-android.a",
|
|
|
|
"-Wl,--exclude-libs=libclang_rt.builtins-x86_64-android.a",
|
|
|
|
],
|
|
|
|
arch: {
|
|
|
|
x86: {
|
|
|
|
ldflags: ["-Wl,--exclude-libs=libgcc_eh.a"],
|
|
|
|
},
|
|
|
|
x86_64: {
|
|
|
|
ldflags: ["-Wl,--exclude-libs=libgcc_eh.a"],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
expectedBazelTargets: []string{`cc_library(
|
|
|
|
name = "fake-ld-android",
|
|
|
|
copts = [
|
|
|
|
"-Wall",
|
|
|
|
"-Wextra",
|
|
|
|
"-Wunused",
|
|
|
|
"-Werror",
|
2021-04-13 09:14:55 +02:00
|
|
|
"-I.",
|
2021-05-13 21:13:04 +02:00
|
|
|
"-I$(BINDIR)/.",
|
2021-03-24 15:04:33 +01:00
|
|
|
],
|
2021-05-19 00:35:24 +02:00
|
|
|
implementation_deps = [":libc_headers"],
|
2021-03-24 15:04:33 +01:00
|
|
|
linkopts = [
|
|
|
|
"-Wl,--exclude-libs=libgcc.a",
|
|
|
|
"-Wl,--exclude-libs=libgcc_stripped.a",
|
|
|
|
"-Wl,--exclude-libs=libclang_rt.builtins-arm-android.a",
|
|
|
|
"-Wl,--exclude-libs=libclang_rt.builtins-aarch64-android.a",
|
|
|
|
"-Wl,--exclude-libs=libclang_rt.builtins-i686-android.a",
|
|
|
|
"-Wl,--exclude-libs=libclang_rt.builtins-x86_64-android.a",
|
|
|
|
] + select({
|
2021-04-08 16:40:57 +02:00
|
|
|
"//build/bazel/platforms/arch:x86": ["-Wl,--exclude-libs=libgcc_eh.a"],
|
|
|
|
"//build/bazel/platforms/arch:x86_64": ["-Wl,--exclude-libs=libgcc_eh.a"],
|
2021-03-24 15:04:33 +01:00
|
|
|
"//conditions:default": [],
|
|
|
|
}),
|
2021-04-27 07:54:20 +02:00
|
|
|
srcs = ["ld_android.cpp"],
|
2021-04-27 11:47:02 +02:00
|
|
|
)`},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
description: "cc_library exclude_srcs - trimmed example of //external/arm-optimized-routines:libarm-optimized-routines-math",
|
|
|
|
moduleTypeUnderTest: "cc_library",
|
|
|
|
moduleTypeUnderTestFactory: cc.LibraryFactory,
|
|
|
|
moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
|
|
|
|
dir: "external",
|
|
|
|
filesystem: map[string]string{
|
|
|
|
"external/math/cosf.c": "",
|
|
|
|
"external/math/erf.c": "",
|
|
|
|
"external/math/erf_data.c": "",
|
|
|
|
"external/math/erff.c": "",
|
|
|
|
"external/math/erff_data.c": "",
|
|
|
|
"external/Android.bp": `
|
|
|
|
cc_library {
|
|
|
|
name: "fake-libarm-optimized-routines-math",
|
|
|
|
exclude_srcs: [
|
|
|
|
// Provided by:
|
|
|
|
// bionic/libm/upstream-freebsd/lib/msun/src/s_erf.c
|
|
|
|
// bionic/libm/upstream-freebsd/lib/msun/src/s_erff.c
|
|
|
|
"math/erf.c",
|
|
|
|
"math/erf_data.c",
|
|
|
|
"math/erff.c",
|
|
|
|
"math/erff_data.c",
|
|
|
|
],
|
|
|
|
srcs: [
|
|
|
|
"math/*.c",
|
|
|
|
],
|
|
|
|
// arch-specific settings
|
|
|
|
arch: {
|
|
|
|
arm64: {
|
|
|
|
cflags: [
|
|
|
|
"-DHAVE_FAST_FMA=1",
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
bazel_module: { bp2build_available: true },
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
},
|
|
|
|
bp: soongCcLibraryPreamble,
|
|
|
|
expectedBazelTargets: []string{`cc_library(
|
|
|
|
name = "fake-libarm-optimized-routines-math",
|
2021-05-13 21:13:04 +02:00
|
|
|
copts = [
|
|
|
|
"-Iexternal",
|
|
|
|
"-I$(BINDIR)/external",
|
|
|
|
] + select({
|
2021-04-27 11:47:02 +02:00
|
|
|
"//build/bazel/platforms/arch:arm64": ["-DHAVE_FAST_FMA=1"],
|
|
|
|
"//conditions:default": [],
|
|
|
|
}),
|
|
|
|
srcs = ["math/cosf.c"],
|
2021-04-29 10:15:13 +02:00
|
|
|
)`},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
description: "cc_library shared/static props",
|
|
|
|
moduleTypeUnderTest: "cc_library",
|
|
|
|
moduleTypeUnderTestFactory: cc.LibraryFactory,
|
|
|
|
moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
|
|
|
|
depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build},
|
|
|
|
dir: "foo/bar",
|
|
|
|
filesystem: map[string]string{
|
2021-05-06 22:23:19 +02:00
|
|
|
"foo/bar/both.cpp": "",
|
|
|
|
"foo/bar/sharedonly.cpp": "",
|
|
|
|
"foo/bar/staticonly.cpp": "",
|
2021-04-29 10:15:13 +02:00
|
|
|
"foo/bar/Android.bp": `
|
|
|
|
cc_library {
|
|
|
|
name: "a",
|
2021-05-06 22:23:19 +02:00
|
|
|
srcs: ["both.cpp"],
|
|
|
|
cflags: ["bothflag"],
|
|
|
|
shared_libs: ["shared_dep_for_both"],
|
|
|
|
static_libs: ["static_dep_for_both"],
|
|
|
|
whole_static_libs: ["whole_static_lib_for_both"],
|
|
|
|
static: {
|
|
|
|
srcs: ["staticonly.cpp"],
|
|
|
|
cflags: ["staticflag"],
|
|
|
|
shared_libs: ["shared_dep_for_static"],
|
|
|
|
static_libs: ["static_dep_for_static"],
|
|
|
|
whole_static_libs: ["whole_static_lib_for_static"],
|
|
|
|
},
|
|
|
|
shared: {
|
|
|
|
srcs: ["sharedonly.cpp"],
|
|
|
|
cflags: ["sharedflag"],
|
|
|
|
shared_libs: ["shared_dep_for_shared"],
|
|
|
|
static_libs: ["static_dep_for_shared"],
|
|
|
|
whole_static_libs: ["whole_static_lib_for_shared"],
|
|
|
|
},
|
2021-04-29 10:15:13 +02:00
|
|
|
bazel_module: { bp2build_available: true },
|
|
|
|
}
|
|
|
|
|
2021-05-06 22:23:19 +02:00
|
|
|
cc_library_static { name: "static_dep_for_shared" }
|
|
|
|
|
|
|
|
cc_library_static { name: "static_dep_for_static" }
|
|
|
|
|
|
|
|
cc_library_static { name: "static_dep_for_both" }
|
|
|
|
|
|
|
|
cc_library_static { name: "whole_static_lib_for_shared" }
|
|
|
|
|
|
|
|
cc_library_static { name: "whole_static_lib_for_static" }
|
|
|
|
|
|
|
|
cc_library_static { name: "whole_static_lib_for_both" }
|
|
|
|
|
|
|
|
cc_library { name: "shared_dep_for_shared" }
|
|
|
|
|
|
|
|
cc_library { name: "shared_dep_for_static" }
|
|
|
|
|
|
|
|
cc_library { name: "shared_dep_for_both" }
|
2021-04-29 10:15:13 +02:00
|
|
|
`,
|
|
|
|
},
|
|
|
|
bp: soongCcLibraryPreamble,
|
|
|
|
expectedBazelTargets: []string{`cc_library(
|
|
|
|
name = "a",
|
2021-05-06 22:23:19 +02:00
|
|
|
copts = [
|
|
|
|
"bothflag",
|
|
|
|
"-Ifoo/bar",
|
2021-05-13 21:13:04 +02:00
|
|
|
"-I$(BINDIR)/foo/bar",
|
2021-05-06 22:23:19 +02:00
|
|
|
],
|
|
|
|
dynamic_deps = [":shared_dep_for_both"],
|
|
|
|
dynamic_deps_for_shared = [":shared_dep_for_shared"],
|
|
|
|
dynamic_deps_for_static = [":shared_dep_for_static"],
|
2021-05-19 00:35:24 +02:00
|
|
|
implementation_deps = [":static_dep_for_both"],
|
2021-05-06 22:23:19 +02:00
|
|
|
shared_copts = ["sharedflag"],
|
|
|
|
shared_srcs = ["sharedonly.cpp"],
|
|
|
|
srcs = ["both.cpp"],
|
|
|
|
static_copts = ["staticflag"],
|
|
|
|
static_deps_for_shared = [":static_dep_for_shared"],
|
|
|
|
static_deps_for_static = [":static_dep_for_static"],
|
|
|
|
static_srcs = ["staticonly.cpp"],
|
|
|
|
whole_archive_deps = [":whole_static_lib_for_both"],
|
|
|
|
whole_archive_deps_for_shared = [":whole_static_lib_for_shared"],
|
|
|
|
whole_archive_deps_for_static = [":whole_static_lib_for_static"],
|
2021-04-30 15:35:09 +02:00
|
|
|
)`},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
description: "cc_library non-configured version script",
|
|
|
|
moduleTypeUnderTest: "cc_library",
|
|
|
|
moduleTypeUnderTestFactory: cc.LibraryFactory,
|
|
|
|
moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
|
|
|
|
depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build},
|
|
|
|
dir: "foo/bar",
|
|
|
|
filesystem: map[string]string{
|
|
|
|
"foo/bar/Android.bp": `
|
|
|
|
cc_library {
|
|
|
|
name: "a",
|
|
|
|
srcs: ["a.cpp"],
|
|
|
|
version_script: "v.map",
|
|
|
|
bazel_module: { bp2build_available: true },
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
},
|
|
|
|
bp: soongCcLibraryPreamble,
|
|
|
|
expectedBazelTargets: []string{`cc_library(
|
|
|
|
name = "a",
|
2021-05-13 21:13:04 +02:00
|
|
|
copts = [
|
|
|
|
"-Ifoo/bar",
|
|
|
|
"-I$(BINDIR)/foo/bar",
|
|
|
|
],
|
2021-04-30 15:35:09 +02:00
|
|
|
srcs = ["a.cpp"],
|
|
|
|
version_script = "v.map",
|
2021-05-12 12:36:45 +02:00
|
|
|
)`},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
description: "cc_library configured version script",
|
|
|
|
moduleTypeUnderTest: "cc_library",
|
|
|
|
moduleTypeUnderTestFactory: cc.LibraryFactory,
|
|
|
|
moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
|
|
|
|
depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build},
|
|
|
|
dir: "foo/bar",
|
|
|
|
filesystem: map[string]string{
|
|
|
|
"foo/bar/Android.bp": `
|
|
|
|
cc_library {
|
|
|
|
name: "a",
|
|
|
|
srcs: ["a.cpp"],
|
|
|
|
arch: {
|
|
|
|
arm: {
|
|
|
|
version_script: "arm.map",
|
|
|
|
},
|
|
|
|
arm64: {
|
|
|
|
version_script: "arm64.map",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
bazel_module: { bp2build_available: true },
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
},
|
|
|
|
bp: soongCcLibraryPreamble,
|
|
|
|
expectedBazelTargets: []string{`cc_library(
|
|
|
|
name = "a",
|
2021-05-13 21:13:04 +02:00
|
|
|
copts = [
|
|
|
|
"-Ifoo/bar",
|
|
|
|
"-I$(BINDIR)/foo/bar",
|
|
|
|
],
|
2021-05-12 12:36:45 +02:00
|
|
|
srcs = ["a.cpp"],
|
|
|
|
version_script = select({
|
|
|
|
"//build/bazel/platforms/arch:arm": "arm.map",
|
|
|
|
"//build/bazel/platforms/arch:arm64": "arm64.map",
|
|
|
|
"//conditions:default": None,
|
|
|
|
}),
|
2021-05-06 08:40:33 +02:00
|
|
|
)`},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
description: "cc_library shared_libs",
|
|
|
|
moduleTypeUnderTest: "cc_library",
|
|
|
|
moduleTypeUnderTestFactory: cc.LibraryFactory,
|
|
|
|
moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
|
|
|
|
depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build},
|
|
|
|
dir: "foo/bar",
|
|
|
|
filesystem: map[string]string{
|
|
|
|
"foo/bar/Android.bp": `
|
|
|
|
cc_library {
|
|
|
|
name: "mylib",
|
|
|
|
bazel_module: { bp2build_available: true },
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "a",
|
|
|
|
shared_libs: ["mylib",],
|
|
|
|
bazel_module: { bp2build_available: true },
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
},
|
|
|
|
bp: soongCcLibraryPreamble,
|
|
|
|
expectedBazelTargets: []string{`cc_library(
|
|
|
|
name = "a",
|
2021-05-13 21:13:04 +02:00
|
|
|
copts = [
|
|
|
|
"-Ifoo/bar",
|
|
|
|
"-I$(BINDIR)/foo/bar",
|
|
|
|
],
|
2021-05-06 08:40:33 +02:00
|
|
|
dynamic_deps = [":mylib"],
|
|
|
|
)`, `cc_library(
|
|
|
|
name = "mylib",
|
2021-05-13 21:13:04 +02:00
|
|
|
copts = [
|
|
|
|
"-Ifoo/bar",
|
|
|
|
"-I$(BINDIR)/foo/bar",
|
|
|
|
],
|
2021-05-10 05:55:51 +02:00
|
|
|
)`},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
description: "cc_library pack_relocations test",
|
|
|
|
moduleTypeUnderTest: "cc_library",
|
|
|
|
moduleTypeUnderTestFactory: cc.LibraryFactory,
|
|
|
|
moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
|
|
|
|
depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build},
|
|
|
|
dir: "foo/bar",
|
|
|
|
filesystem: map[string]string{
|
|
|
|
"foo/bar/Android.bp": `
|
|
|
|
cc_library {
|
|
|
|
name: "a",
|
|
|
|
srcs: ["a.cpp"],
|
|
|
|
pack_relocations: false,
|
|
|
|
bazel_module: { bp2build_available: true },
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "b",
|
|
|
|
srcs: ["b.cpp"],
|
|
|
|
arch: {
|
|
|
|
x86_64: {
|
|
|
|
pack_relocations: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
bazel_module: { bp2build_available: true },
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "c",
|
|
|
|
srcs: ["c.cpp"],
|
|
|
|
target: {
|
|
|
|
darwin: {
|
|
|
|
pack_relocations: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
bazel_module: { bp2build_available: true },
|
|
|
|
}`,
|
|
|
|
},
|
|
|
|
bp: soongCcLibraryPreamble,
|
|
|
|
expectedBazelTargets: []string{`cc_library(
|
|
|
|
name = "a",
|
2021-05-13 21:13:04 +02:00
|
|
|
copts = [
|
|
|
|
"-Ifoo/bar",
|
|
|
|
"-I$(BINDIR)/foo/bar",
|
|
|
|
],
|
2021-05-10 05:55:51 +02:00
|
|
|
linkopts = ["-Wl,--pack-dyn-relocs=none"],
|
|
|
|
srcs = ["a.cpp"],
|
|
|
|
)`, `cc_library(
|
|
|
|
name = "b",
|
2021-05-13 21:13:04 +02:00
|
|
|
copts = [
|
|
|
|
"-Ifoo/bar",
|
|
|
|
"-I$(BINDIR)/foo/bar",
|
|
|
|
],
|
2021-05-10 05:55:51 +02:00
|
|
|
linkopts = select({
|
|
|
|
"//build/bazel/platforms/arch:x86_64": ["-Wl,--pack-dyn-relocs=none"],
|
|
|
|
"//conditions:default": [],
|
|
|
|
}),
|
|
|
|
srcs = ["b.cpp"],
|
|
|
|
)`, `cc_library(
|
|
|
|
name = "c",
|
2021-05-13 21:13:04 +02:00
|
|
|
copts = [
|
|
|
|
"-Ifoo/bar",
|
|
|
|
"-I$(BINDIR)/foo/bar",
|
|
|
|
],
|
2021-05-10 05:55:51 +02:00
|
|
|
linkopts = select({
|
|
|
|
"//build/bazel/platforms/os:darwin": ["-Wl,--pack-dyn-relocs=none"],
|
|
|
|
"//conditions:default": [],
|
|
|
|
}),
|
|
|
|
srcs = ["c.cpp"],
|
2021-05-12 06:33:00 +02:00
|
|
|
)`},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
description: "cc_library spaces in copts",
|
|
|
|
moduleTypeUnderTest: "cc_library",
|
|
|
|
moduleTypeUnderTestFactory: cc.LibraryFactory,
|
|
|
|
moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
|
|
|
|
depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build},
|
|
|
|
dir: "foo/bar",
|
|
|
|
filesystem: map[string]string{
|
|
|
|
"foo/bar/Android.bp": `
|
|
|
|
cc_library {
|
|
|
|
name: "a",
|
|
|
|
cflags: ["-include header.h",],
|
|
|
|
bazel_module: { bp2build_available: true },
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
},
|
|
|
|
bp: soongCcLibraryPreamble,
|
|
|
|
expectedBazelTargets: []string{`cc_library(
|
|
|
|
name = "a",
|
|
|
|
copts = [
|
|
|
|
"-include",
|
|
|
|
"header.h",
|
|
|
|
"-Ifoo/bar",
|
2021-05-13 21:13:04 +02:00
|
|
|
"-I$(BINDIR)/foo/bar",
|
2021-05-12 06:33:00 +02:00
|
|
|
],
|
2021-05-12 07:04:58 +02:00
|
|
|
)`},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
description: "cc_library cppflags goes into copts",
|
|
|
|
moduleTypeUnderTest: "cc_library",
|
|
|
|
moduleTypeUnderTestFactory: cc.LibraryFactory,
|
|
|
|
moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
|
|
|
|
depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build},
|
|
|
|
dir: "foo/bar",
|
|
|
|
filesystem: map[string]string{
|
|
|
|
"foo/bar/Android.bp": `cc_library {
|
|
|
|
name: "a",
|
|
|
|
srcs: ["a.cpp"],
|
|
|
|
cflags: [
|
|
|
|
"-Wall",
|
|
|
|
],
|
|
|
|
cppflags: [
|
|
|
|
"-fsigned-char",
|
|
|
|
"-pedantic",
|
|
|
|
],
|
|
|
|
arch: {
|
|
|
|
arm64: {
|
|
|
|
cppflags: ["-DARM64=1"],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
target: {
|
|
|
|
android: {
|
|
|
|
cppflags: ["-DANDROID=1"],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
bazel_module: { bp2build_available: true },
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
},
|
|
|
|
bp: soongCcLibraryPreamble,
|
|
|
|
expectedBazelTargets: []string{`cc_library(
|
|
|
|
name = "a",
|
|
|
|
copts = [
|
|
|
|
"-Wall",
|
|
|
|
"-fsigned-char",
|
|
|
|
"-pedantic",
|
|
|
|
"-Ifoo/bar",
|
2021-05-13 21:13:04 +02:00
|
|
|
"-I$(BINDIR)/foo/bar",
|
2021-05-12 07:04:58 +02:00
|
|
|
] + select({
|
|
|
|
"//build/bazel/platforms/arch:arm64": ["-DARM64=1"],
|
|
|
|
"//conditions:default": [],
|
|
|
|
}) + select({
|
|
|
|
"//build/bazel/platforms/os:android": ["-DANDROID=1"],
|
|
|
|
"//conditions:default": [],
|
|
|
|
}),
|
|
|
|
srcs = ["a.cpp"],
|
2021-03-24 15:04:33 +01:00
|
|
|
)`},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
dir := "."
|
|
|
|
for _, testCase := range testCases {
|
|
|
|
filesystem := make(map[string][]byte)
|
|
|
|
toParse := []string{
|
|
|
|
"Android.bp",
|
|
|
|
}
|
|
|
|
for f, content := range testCase.filesystem {
|
|
|
|
if strings.HasSuffix(f, "Android.bp") {
|
|
|
|
toParse = append(toParse, f)
|
|
|
|
}
|
|
|
|
filesystem[f] = []byte(content)
|
|
|
|
}
|
|
|
|
config := android.TestConfig(buildDir, nil, testCase.bp, filesystem)
|
|
|
|
ctx := android.NewTestContext(config)
|
|
|
|
|
|
|
|
cc.RegisterCCBuildComponents(ctx)
|
2021-04-29 10:15:13 +02:00
|
|
|
ctx.RegisterModuleType("cc_library_static", cc.LibraryStaticFactory)
|
2021-03-24 15:04:33 +01:00
|
|
|
ctx.RegisterModuleType("toolchain_library", cc.ToolchainLibraryFactory)
|
|
|
|
ctx.RegisterModuleType("cc_library_headers", cc.LibraryHeaderFactory)
|
|
|
|
ctx.RegisterModuleType(testCase.moduleTypeUnderTest, testCase.moduleTypeUnderTestFactory)
|
|
|
|
ctx.RegisterBp2BuildMutator(testCase.moduleTypeUnderTest, testCase.moduleTypeUnderTestBp2BuildMutator)
|
|
|
|
ctx.RegisterBp2BuildConfig(bp2buildConfig) // TODO(jingwen): make this the default for all tests
|
2021-04-29 10:15:13 +02:00
|
|
|
for _, m := range testCase.depsMutators {
|
|
|
|
ctx.DepsBp2BuildMutators(m)
|
|
|
|
}
|
2021-03-24 15:04:33 +01:00
|
|
|
ctx.RegisterForBazelConversion()
|
|
|
|
|
|
|
|
_, errs := ctx.ParseFileList(dir, toParse)
|
2021-05-19 15:14:26 +02:00
|
|
|
if errored(t, testCase.description, errs) {
|
2021-03-24 15:04:33 +01:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
_, errs = ctx.ResolveDependencies(config)
|
2021-05-19 15:14:26 +02:00
|
|
|
if errored(t, testCase.description, errs) {
|
2021-03-24 15:04:33 +01:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
checkDir := dir
|
|
|
|
if testCase.dir != "" {
|
|
|
|
checkDir = testCase.dir
|
|
|
|
}
|
|
|
|
codegenCtx := NewCodegenContext(config, *ctx.Context, Bp2Build)
|
|
|
|
bazelTargets := generateBazelTargetsForDir(codegenCtx, checkDir)
|
|
|
|
if actualCount, expectedCount := len(bazelTargets), len(testCase.expectedBazelTargets); actualCount != expectedCount {
|
|
|
|
t.Errorf("%s: Expected %d bazel target, got %d", testCase.description, expectedCount, actualCount)
|
|
|
|
} else {
|
|
|
|
for i, target := range bazelTargets {
|
|
|
|
if w, g := testCase.expectedBazelTargets[i], target.content; w != g {
|
|
|
|
t.Errorf(
|
|
|
|
"%s: Expected generated Bazel target to be '%s', got '%s'",
|
|
|
|
testCase.description,
|
|
|
|
w,
|
|
|
|
g,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|