Merge "Add unit tests for cpp/assembly flags."
This commit is contained in:
148
cc/cc_test.go
148
cc/cc_test.go
@@ -3869,10 +3869,99 @@ func TestIncludeDirsExporting(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestIncludeDirectoryOrdering(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 {
|
cc_library {
|
||||||
name: "libfoo",
|
name: "libfoo",
|
||||||
srcs: ["foo.c"],
|
srcs: ["%s"],
|
||||||
local_include_dirs: ["local_include_dirs"],
|
local_include_dirs: ["local_include_dirs"],
|
||||||
export_include_dirs: ["export_include_dirs"],
|
export_include_dirs: ["export_include_dirs"],
|
||||||
export_system_include_dirs: ["export_system_include_dirs"],
|
export_system_include_dirs: ["export_system_include_dirs"],
|
||||||
@@ -3928,7 +4017,7 @@ func TestIncludeDirectoryOrdering(t *testing.T) {
|
|||||||
sdk_version: "20",
|
sdk_version: "20",
|
||||||
stl: "none",
|
stl: "none",
|
||||||
}
|
}
|
||||||
`
|
`, tc.src)
|
||||||
|
|
||||||
libs := []string{
|
libs := []string{
|
||||||
"libstatic1",
|
"libstatic1",
|
||||||
@@ -3965,57 +4054,18 @@ func TestIncludeDirectoryOrdering(t *testing.T) {
|
|||||||
|
|
||||||
var includes []string
|
var includes []string
|
||||||
flags := strings.Split(cflags, " ")
|
flags := strings.Split(cflags, " ")
|
||||||
for i, flag := range flags {
|
for _, flag := range flags {
|
||||||
if strings.Contains(flag, "Cflags") {
|
if strings.HasPrefix(flag, "-I") {
|
||||||
includes = append(includes, flag)
|
|
||||||
} else if strings.HasPrefix(flag, "-I") {
|
|
||||||
includes = append(includes, strings.TrimPrefix(flag, "-I"))
|
includes = append(includes, strings.TrimPrefix(flag, "-I"))
|
||||||
} else if flag == "-isystem" {
|
} else if flag == "-isystem" {
|
||||||
includes = append(includes, flags[i+1])
|
// skip isystem, include next
|
||||||
|
} else if len(flag) > 0 {
|
||||||
|
includes = append(includes, flag)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
want := []string{
|
android.AssertArrayString(t, "includes", tc.expected, includes)
|
||||||
"${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