Merge "Add unit tests for cpp/assembly flags."
This commit is contained in:
212
cc/cc_test.go
212
cc/cc_test.go
@@ -3869,10 +3869,99 @@ func TestIncludeDirsExporting(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestIncludeDirectoryOrdering(t *testing.T) {
|
||||
bp := `
|
||||
baseExpectedFlags := []string{
|
||||
"${config.ArmThumbCflags}",
|
||||
"${config.ArmCflags}",
|
||||
"${config.CommonGlobalCflags}",
|
||||
"${config.DeviceGlobalCflags}",
|
||||
"${config.ExternalCflags}",
|
||||
"${config.ArmToolchainCflags}",
|
||||
"${config.ArmArmv7ANeonCflags}",
|
||||
"${config.ArmGenericCflags}",
|
||||
"-target",
|
||||
"armv7a-linux-androideabi20",
|
||||
"-B${config.ArmGccRoot}/arm-linux-androideabi/bin",
|
||||
}
|
||||
|
||||
expectedIncludes := []string{
|
||||
"external/foo/android_arm_export_include_dirs",
|
||||
"external/foo/lib32_export_include_dirs",
|
||||
"external/foo/arm_export_include_dirs",
|
||||
"external/foo/android_export_include_dirs",
|
||||
"external/foo/linux_export_include_dirs",
|
||||
"external/foo/export_include_dirs",
|
||||
"external/foo/android_arm_local_include_dirs",
|
||||
"external/foo/lib32_local_include_dirs",
|
||||
"external/foo/arm_local_include_dirs",
|
||||
"external/foo/android_local_include_dirs",
|
||||
"external/foo/linux_local_include_dirs",
|
||||
"external/foo/local_include_dirs",
|
||||
"external/foo",
|
||||
"external/foo/libheader1",
|
||||
"external/foo/libheader2",
|
||||
"external/foo/libwhole1",
|
||||
"external/foo/libwhole2",
|
||||
"external/foo/libstatic1",
|
||||
"external/foo/libstatic2",
|
||||
"external/foo/libshared1",
|
||||
"external/foo/libshared2",
|
||||
"external/foo/liblinux",
|
||||
"external/foo/libandroid",
|
||||
"external/foo/libarm",
|
||||
"external/foo/lib32",
|
||||
"external/foo/libandroid_arm",
|
||||
"defaults/cc/common/ndk_libc++_shared",
|
||||
"defaults/cc/common/ndk_libandroid_support",
|
||||
}
|
||||
|
||||
conly := []string{"-fPIC", "${config.CommonGlobalConlyflags}"}
|
||||
cppOnly := []string{"-fPIC", "${config.CommonGlobalCppflags}", "${config.DeviceGlobalCppflags}", "${config.ArmCppflags}"}
|
||||
|
||||
cflags := []string{"-Wall", "-Werror"}
|
||||
cstd := []string{"-std=gnu99"}
|
||||
cppstd := []string{"-std=gnu++17", "-fno-rtti"}
|
||||
|
||||
lastIncludes := []string{
|
||||
"out/soong/ndk/sysroot/usr/include",
|
||||
"out/soong/ndk/sysroot/usr/include/arm-linux-androideabi",
|
||||
}
|
||||
|
||||
combineSlices := func(slices ...[]string) []string {
|
||||
var ret []string
|
||||
for _, s := range slices {
|
||||
ret = append(ret, s...)
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
src string
|
||||
expected []string
|
||||
}{
|
||||
{
|
||||
name: "c",
|
||||
src: "foo.c",
|
||||
expected: combineSlices(baseExpectedFlags, conly, expectedIncludes, cflags, cstd, lastIncludes, []string{"${config.NoOverrideGlobalCflags}"}),
|
||||
},
|
||||
{
|
||||
name: "cc",
|
||||
src: "foo.cc",
|
||||
expected: combineSlices(baseExpectedFlags, cppOnly, expectedIncludes, cflags, cppstd, lastIncludes, []string{"${config.NoOverrideGlobalCflags}"}),
|
||||
},
|
||||
{
|
||||
name: "assemble",
|
||||
src: "foo.s",
|
||||
expected: combineSlices(baseExpectedFlags, []string{"-D__ASSEMBLY__"}, expectedIncludes, lastIncludes),
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
bp := fmt.Sprintf(`
|
||||
cc_library {
|
||||
name: "libfoo",
|
||||
srcs: ["foo.c"],
|
||||
srcs: ["%s"],
|
||||
local_include_dirs: ["local_include_dirs"],
|
||||
export_include_dirs: ["export_include_dirs"],
|
||||
export_system_include_dirs: ["export_system_include_dirs"],
|
||||
@@ -3928,24 +4017,24 @@ func TestIncludeDirectoryOrdering(t *testing.T) {
|
||||
sdk_version: "20",
|
||||
stl: "none",
|
||||
}
|
||||
`
|
||||
`, tc.src)
|
||||
|
||||
libs := []string{
|
||||
"libstatic1",
|
||||
"libstatic2",
|
||||
"libwhole1",
|
||||
"libwhole2",
|
||||
"libshared1",
|
||||
"libshared2",
|
||||
"libandroid",
|
||||
"libandroid_arm",
|
||||
"liblinux",
|
||||
"lib32",
|
||||
"libarm",
|
||||
}
|
||||
libs := []string{
|
||||
"libstatic1",
|
||||
"libstatic2",
|
||||
"libwhole1",
|
||||
"libwhole2",
|
||||
"libshared1",
|
||||
"libshared2",
|
||||
"libandroid",
|
||||
"libandroid_arm",
|
||||
"liblinux",
|
||||
"lib32",
|
||||
"libarm",
|
||||
}
|
||||
|
||||
for _, lib := range libs {
|
||||
bp += fmt.Sprintf(`
|
||||
for _, lib := range libs {
|
||||
bp += fmt.Sprintf(`
|
||||
cc_library {
|
||||
name: "%s",
|
||||
export_include_dirs: ["%s"],
|
||||
@@ -3953,69 +4042,30 @@ func TestIncludeDirectoryOrdering(t *testing.T) {
|
||||
stl: "none",
|
||||
}
|
||||
`, lib, lib)
|
||||
}
|
||||
|
||||
ctx := android.GroupFixturePreparers(
|
||||
PrepareForIntegrationTestWithCc,
|
||||
android.FixtureAddTextFile("external/foo/Android.bp", bp),
|
||||
).RunTest(t)
|
||||
// Use the arm variant instead of the arm64 variant so that it gets headers from
|
||||
// ndk_libandroid_support to test LateStaticLibs.
|
||||
cflags := ctx.ModuleForTests("libfoo", "android_arm_armv7-a-neon_sdk_static").Output("obj/external/foo/foo.o").Args["cFlags"]
|
||||
|
||||
var includes []string
|
||||
flags := strings.Split(cflags, " ")
|
||||
for _, flag := range flags {
|
||||
if strings.HasPrefix(flag, "-I") {
|
||||
includes = append(includes, strings.TrimPrefix(flag, "-I"))
|
||||
} else if flag == "-isystem" {
|
||||
// skip isystem, include next
|
||||
} else if len(flag) > 0 {
|
||||
includes = append(includes, flag)
|
||||
}
|
||||
}
|
||||
|
||||
android.AssertArrayString(t, "includes", tc.expected, includes)
|
||||
})
|
||||
}
|
||||
|
||||
ctx := android.GroupFixturePreparers(
|
||||
PrepareForIntegrationTestWithCc,
|
||||
android.FixtureAddTextFile("external/foo/Android.bp", bp),
|
||||
).RunTest(t)
|
||||
// Use the arm variant instead of the arm64 variant so that it gets headers from
|
||||
// ndk_libandroid_support to test LateStaticLibs.
|
||||
cflags := ctx.ModuleForTests("libfoo", "android_arm_armv7-a-neon_sdk_static").Output("obj/external/foo/foo.o").Args["cFlags"]
|
||||
|
||||
var includes []string
|
||||
flags := strings.Split(cflags, " ")
|
||||
for i, flag := range flags {
|
||||
if strings.Contains(flag, "Cflags") {
|
||||
includes = append(includes, flag)
|
||||
} else if strings.HasPrefix(flag, "-I") {
|
||||
includes = append(includes, strings.TrimPrefix(flag, "-I"))
|
||||
} else if flag == "-isystem" {
|
||||
includes = append(includes, flags[i+1])
|
||||
}
|
||||
}
|
||||
|
||||
want := []string{
|
||||
"${config.ArmThumbCflags}",
|
||||
"${config.ArmCflags}",
|
||||
"${config.CommonGlobalCflags}",
|
||||
"${config.DeviceGlobalCflags}",
|
||||
"${config.ExternalCflags}",
|
||||
"${config.ArmToolchainCflags}",
|
||||
"${config.ArmArmv7ANeonCflags}",
|
||||
"${config.ArmGenericCflags}",
|
||||
"external/foo/android_arm_export_include_dirs",
|
||||
"external/foo/lib32_export_include_dirs",
|
||||
"external/foo/arm_export_include_dirs",
|
||||
"external/foo/android_export_include_dirs",
|
||||
"external/foo/linux_export_include_dirs",
|
||||
"external/foo/export_include_dirs",
|
||||
"external/foo/android_arm_local_include_dirs",
|
||||
"external/foo/lib32_local_include_dirs",
|
||||
"external/foo/arm_local_include_dirs",
|
||||
"external/foo/android_local_include_dirs",
|
||||
"external/foo/linux_local_include_dirs",
|
||||
"external/foo/local_include_dirs",
|
||||
"external/foo",
|
||||
"external/foo/libheader1",
|
||||
"external/foo/libheader2",
|
||||
"external/foo/libwhole1",
|
||||
"external/foo/libwhole2",
|
||||
"external/foo/libstatic1",
|
||||
"external/foo/libstatic2",
|
||||
"external/foo/libshared1",
|
||||
"external/foo/libshared2",
|
||||
"external/foo/liblinux",
|
||||
"external/foo/libandroid",
|
||||
"external/foo/libarm",
|
||||
"external/foo/lib32",
|
||||
"external/foo/libandroid_arm",
|
||||
"defaults/cc/common/ndk_libc++_shared",
|
||||
"defaults/cc/common/ndk_libandroid_support",
|
||||
"out/soong/ndk/sysroot/usr/include",
|
||||
"out/soong/ndk/sysroot/usr/include/arm-linux-androideabi",
|
||||
"${config.NoOverrideGlobalCflags}",
|
||||
}
|
||||
|
||||
android.AssertArrayString(t, "includes", want, includes)
|
||||
}
|
||||
|
Reference in New Issue
Block a user