Improve handling of generated include dirs

The exported include dirs includes both source and generated
directories (e.g. containing aidl generated headers). The latter are
always arch specific so if they are present they make all the include
directories arch specific.

This change separates the source and generated include dirs so that
the source include dirs (which are probably not arch specific) can be
optimized separately from the arch specific generated include dirs.

The FilterPathList() func was refactored to extract the more general
FilterPathListPredicate() func.

A number of tests needed to be updated to reflect the more optimal
snapshot creation.

Bug: 142918168
Test: m checkbuild
Change-Id: Id1a23d35a45b250ae2168834f9c2a65c86a5fd77
This commit is contained in:
Paul Duffin 2019-12-13 00:03:35 +00:00
parent a7cd8c8344
commit 57b9e1da75
3 changed files with 60 additions and 92 deletions

View file

@ -512,8 +512,12 @@ func inPathList(p Path, list []Path) bool {
}
func FilterPathList(list []Path, filter []Path) (remainder []Path, filtered []Path) {
return FilterPathListPredicate(list, func(p Path) bool { return inPathList(p, filter) })
}
func FilterPathListPredicate(list []Path, predicate func(Path) bool) (remainder []Path, filtered []Path) {
for _, l := range list {
if inPathList(l, filter) {
if predicate(l) {
filtered = append(filtered, l)
} else {
remainder = append(remainder, l)

View file

@ -1497,14 +1497,20 @@ func (mt *librarySdkMemberType) organizeVariants(member android.SdkMember) *nati
for _, variant := range member.Variants() {
ccModule := variant.(*Module)
// Separate out the generated include dirs (which are arch specific) from the
// include dirs (which may not be).
exportedIncludeDirs, exportedGeneratedIncludeDirs := android.FilterPathListPredicate(
ccModule.ExportedIncludeDirs(), isGeneratedHeaderDirectory)
info.archVariantProperties = append(info.archVariantProperties, nativeLibInfoProperties{
name: memberName,
archType: ccModule.Target().Arch.ArchType.String(),
ExportedIncludeDirs: ccModule.ExportedIncludeDirs(),
ExportedSystemIncludeDirs: ccModule.ExportedSystemIncludeDirs(),
ExportedFlags: ccModule.ExportedFlags(),
exportedGeneratedHeaders: ccModule.ExportedGeneratedHeaders(),
outputFile: ccModule.OutputFile().Path(),
name: memberName,
archType: ccModule.Target().Arch.ArchType.String(),
ExportedIncludeDirs: exportedIncludeDirs,
ExportedGeneratedIncludeDirs: exportedGeneratedIncludeDirs,
ExportedSystemIncludeDirs: ccModule.ExportedSystemIncludeDirs(),
ExportedFlags: ccModule.ExportedFlags(),
exportedGeneratedHeaders: ccModule.ExportedGeneratedHeaders(),
outputFile: ccModule.OutputFile().Path(),
})
}
@ -1518,6 +1524,11 @@ func (mt *librarySdkMemberType) organizeVariants(member android.SdkMember) *nati
return info
}
func isGeneratedHeaderDirectory(p android.Path) bool {
_, gen := p.(android.WritablePath)
return gen
}
// Extract common properties from a slice of property structures of the same type.
//
// All the property structures must be of the same type.
@ -1580,16 +1591,11 @@ func extractCommonProperties(commonProperties interface{}, inputPropertiesSlice
func buildSharedNativeLibSnapshot(sdkModuleContext android.ModuleContext, info *nativeLibInfo, builder android.SnapshotBuilder, member android.SdkMember) {
// a function for emitting include dirs
addExportedDirCopyCommandsForNativeLibs := func(lib nativeLibInfoProperties) {
// Do not include ExportedGeneratedIncludeDirs in the list of directories whose
// contents are copied as they are copied from exportedGeneratedHeaders below.
includeDirs := lib.ExportedIncludeDirs
includeDirs = append(includeDirs, lib.ExportedSystemIncludeDirs...)
if len(includeDirs) == 0 {
return
}
for _, dir := range includeDirs {
if _, gen := dir.(android.WritablePath); gen {
// generated headers are copied via exportedGeneratedHeaders. See below.
continue
}
// lib.ArchType is "" for common properties.
targetDir := filepath.Join(lib.archType, nativeIncludeDir)
@ -1676,13 +1682,14 @@ func nativeIncludeDirPathsFor(lib nativeLibInfoProperties, systemInclude bool) [
var result []string
var includeDirs []android.Path
if !systemInclude {
includeDirs = lib.ExportedIncludeDirs
// Include the generated include dirs in the exported include dirs.
includeDirs = append(lib.ExportedIncludeDirs, lib.ExportedGeneratedIncludeDirs...)
} else {
includeDirs = lib.ExportedSystemIncludeDirs
}
for _, dir := range includeDirs {
var path string
if _, gen := dir.(android.WritablePath); gen {
if isGeneratedHeaderDirectory(dir) {
path = filepath.Join(nativeGeneratedIncludeDir, lib.name)
} else {
path = filepath.Join(nativeIncludeDir, dir.String())
@ -1707,9 +1714,10 @@ type nativeLibInfoProperties struct {
// This is "" for common properties.
archType string
ExportedIncludeDirs android.Paths
ExportedSystemIncludeDirs android.Paths
ExportedFlags []string
ExportedIncludeDirs android.Paths
ExportedGeneratedIncludeDirs android.Paths
ExportedSystemIncludeDirs android.Paths
ExportedFlags []string
// exportedGeneratedHeaders is not exported as if set it is always arch specific.
exportedGeneratedHeaders android.Paths

View file

@ -288,20 +288,15 @@ func TestSnapshotWithCcSharedLibrary(t *testing.T) {
cc_prebuilt_library_shared {
name: "mysdk_mynativelib@current",
sdk_member_name: "mynativelib",
export_include_dirs: ["include/include"],
arch: {
arm64: {
srcs: ["arm64/lib/mynativelib.so"],
export_include_dirs: [
"arm64/include/include",
"arm64/include_gen/mynativelib",
],
export_include_dirs: ["arm64/include_gen/mynativelib"],
},
arm: {
srcs: ["arm/lib/mynativelib.so"],
export_include_dirs: [
"arm/include/include",
"arm/include_gen/mynativelib",
],
export_include_dirs: ["arm/include_gen/mynativelib"],
},
},
stl: "none",
@ -311,20 +306,15 @@ cc_prebuilt_library_shared {
cc_prebuilt_library_shared {
name: "mynativelib",
prefer: false,
export_include_dirs: ["include/include"],
arch: {
arm64: {
srcs: ["arm64/lib/mynativelib.so"],
export_include_dirs: [
"arm64/include/include",
"arm64/include_gen/mynativelib",
],
export_include_dirs: ["arm64/include_gen/mynativelib"],
},
arm: {
srcs: ["arm/lib/mynativelib.so"],
export_include_dirs: [
"arm/include/include",
"arm/include_gen/mynativelib",
],
export_include_dirs: ["arm/include_gen/mynativelib"],
},
},
stl: "none",
@ -337,13 +327,12 @@ sdk_snapshot {
}
`),
checkAllCopyRules(`
include/Test.h -> include/include/Test.h
.intermediates/mynativelib/android_arm64_armv8-a_core_shared/mynativelib.so -> arm64/lib/mynativelib.so
include/Test.h -> arm64/include/include/Test.h
.intermediates/mynativelib/android_arm64_armv8-a_core_shared/gen/aidl/aidl/foo/bar/Test.h -> arm64/include_gen/mynativelib/aidl/foo/bar/Test.h
.intermediates/mynativelib/android_arm64_armv8-a_core_shared/gen/aidl/aidl/foo/bar/BnTest.h -> arm64/include_gen/mynativelib/aidl/foo/bar/BnTest.h
.intermediates/mynativelib/android_arm64_armv8-a_core_shared/gen/aidl/aidl/foo/bar/BpTest.h -> arm64/include_gen/mynativelib/aidl/foo/bar/BpTest.h
.intermediates/mynativelib/android_arm_armv7-a-neon_core_shared/mynativelib.so -> arm/lib/mynativelib.so
include/Test.h -> arm/include/include/Test.h
.intermediates/mynativelib/android_arm_armv7-a-neon_core_shared/gen/aidl/aidl/foo/bar/Test.h -> arm/include_gen/mynativelib/aidl/foo/bar/Test.h
.intermediates/mynativelib/android_arm_armv7-a-neon_core_shared/gen/aidl/aidl/foo/bar/BnTest.h -> arm/include_gen/mynativelib/aidl/foo/bar/BnTest.h
.intermediates/mynativelib/android_arm_armv7-a-neon_core_shared/gen/aidl/aidl/foo/bar/BpTest.h -> arm/include_gen/mynativelib/aidl/foo/bar/BpTest.h
@ -389,20 +378,15 @@ cc_prebuilt_library_shared {
sdk_member_name: "mynativelib",
device_supported: false,
host_supported: true,
export_include_dirs: ["include/include"],
arch: {
x86_64: {
srcs: ["x86_64/lib/mynativelib.so"],
export_include_dirs: [
"x86_64/include/include",
"x86_64/include_gen/mynativelib",
],
export_include_dirs: ["x86_64/include_gen/mynativelib"],
},
x86: {
srcs: ["x86/lib/mynativelib.so"],
export_include_dirs: [
"x86/include/include",
"x86/include_gen/mynativelib",
],
export_include_dirs: ["x86/include_gen/mynativelib"],
},
},
stl: "none",
@ -414,20 +398,15 @@ cc_prebuilt_library_shared {
prefer: false,
device_supported: false,
host_supported: true,
export_include_dirs: ["include/include"],
arch: {
x86_64: {
srcs: ["x86_64/lib/mynativelib.so"],
export_include_dirs: [
"x86_64/include/include",
"x86_64/include_gen/mynativelib",
],
export_include_dirs: ["x86_64/include_gen/mynativelib"],
},
x86: {
srcs: ["x86/lib/mynativelib.so"],
export_include_dirs: [
"x86/include/include",
"x86/include_gen/mynativelib",
],
export_include_dirs: ["x86/include_gen/mynativelib"],
},
},
stl: "none",
@ -442,13 +421,12 @@ sdk_snapshot {
}
`),
checkAllCopyRules(`
include/Test.h -> include/include/Test.h
.intermediates/mynativelib/linux_glibc_x86_64_shared/mynativelib.so -> x86_64/lib/mynativelib.so
include/Test.h -> x86_64/include/include/Test.h
.intermediates/mynativelib/linux_glibc_x86_64_shared/gen/aidl/aidl/foo/bar/Test.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/Test.h
.intermediates/mynativelib/linux_glibc_x86_64_shared/gen/aidl/aidl/foo/bar/BnTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BnTest.h
.intermediates/mynativelib/linux_glibc_x86_64_shared/gen/aidl/aidl/foo/bar/BpTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BpTest.h
.intermediates/mynativelib/linux_glibc_x86_shared/mynativelib.so -> x86/lib/mynativelib.so
include/Test.h -> x86/include/include/Test.h
.intermediates/mynativelib/linux_glibc_x86_shared/gen/aidl/aidl/foo/bar/Test.h -> x86/include_gen/mynativelib/aidl/foo/bar/Test.h
.intermediates/mynativelib/linux_glibc_x86_shared/gen/aidl/aidl/foo/bar/BnTest.h -> x86/include_gen/mynativelib/aidl/foo/bar/BnTest.h
.intermediates/mynativelib/linux_glibc_x86_shared/gen/aidl/aidl/foo/bar/BpTest.h -> x86/include_gen/mynativelib/aidl/foo/bar/BpTest.h
@ -485,20 +463,15 @@ func TestSnapshotWithCcStaticLibrary(t *testing.T) {
cc_prebuilt_library_static {
name: "mysdk_mynativelib@current",
sdk_member_name: "mynativelib",
export_include_dirs: ["include/include"],
arch: {
arm64: {
srcs: ["arm64/lib/mynativelib.a"],
export_include_dirs: [
"arm64/include/include",
"arm64/include_gen/mynativelib",
],
export_include_dirs: ["arm64/include_gen/mynativelib"],
},
arm: {
srcs: ["arm/lib/mynativelib.a"],
export_include_dirs: [
"arm/include/include",
"arm/include_gen/mynativelib",
],
export_include_dirs: ["arm/include_gen/mynativelib"],
},
},
stl: "none",
@ -508,20 +481,15 @@ cc_prebuilt_library_static {
cc_prebuilt_library_static {
name: "mynativelib",
prefer: false,
export_include_dirs: ["include/include"],
arch: {
arm64: {
srcs: ["arm64/lib/mynativelib.a"],
export_include_dirs: [
"arm64/include/include",
"arm64/include_gen/mynativelib",
],
export_include_dirs: ["arm64/include_gen/mynativelib"],
},
arm: {
srcs: ["arm/lib/mynativelib.a"],
export_include_dirs: [
"arm/include/include",
"arm/include_gen/mynativelib",
],
export_include_dirs: ["arm/include_gen/mynativelib"],
},
},
stl: "none",
@ -534,13 +502,12 @@ sdk_snapshot {
}
`),
checkAllCopyRules(`
include/Test.h -> include/include/Test.h
.intermediates/mynativelib/android_arm64_armv8-a_core_static/mynativelib.a -> arm64/lib/mynativelib.a
include/Test.h -> arm64/include/include/Test.h
.intermediates/mynativelib/android_arm64_armv8-a_core_static/gen/aidl/aidl/foo/bar/Test.h -> arm64/include_gen/mynativelib/aidl/foo/bar/Test.h
.intermediates/mynativelib/android_arm64_armv8-a_core_static/gen/aidl/aidl/foo/bar/BnTest.h -> arm64/include_gen/mynativelib/aidl/foo/bar/BnTest.h
.intermediates/mynativelib/android_arm64_armv8-a_core_static/gen/aidl/aidl/foo/bar/BpTest.h -> arm64/include_gen/mynativelib/aidl/foo/bar/BpTest.h
.intermediates/mynativelib/android_arm_armv7-a-neon_core_static/mynativelib.a -> arm/lib/mynativelib.a
include/Test.h -> arm/include/include/Test.h
.intermediates/mynativelib/android_arm_armv7-a-neon_core_static/gen/aidl/aidl/foo/bar/Test.h -> arm/include_gen/mynativelib/aidl/foo/bar/Test.h
.intermediates/mynativelib/android_arm_armv7-a-neon_core_static/gen/aidl/aidl/foo/bar/BnTest.h -> arm/include_gen/mynativelib/aidl/foo/bar/BnTest.h
.intermediates/mynativelib/android_arm_armv7-a-neon_core_static/gen/aidl/aidl/foo/bar/BpTest.h -> arm/include_gen/mynativelib/aidl/foo/bar/BpTest.h
@ -586,20 +553,15 @@ cc_prebuilt_library_static {
sdk_member_name: "mynativelib",
device_supported: false,
host_supported: true,
export_include_dirs: ["include/include"],
arch: {
x86_64: {
srcs: ["x86_64/lib/mynativelib.a"],
export_include_dirs: [
"x86_64/include/include",
"x86_64/include_gen/mynativelib",
],
export_include_dirs: ["x86_64/include_gen/mynativelib"],
},
x86: {
srcs: ["x86/lib/mynativelib.a"],
export_include_dirs: [
"x86/include/include",
"x86/include_gen/mynativelib",
],
export_include_dirs: ["x86/include_gen/mynativelib"],
},
},
stl: "none",
@ -611,20 +573,15 @@ cc_prebuilt_library_static {
prefer: false,
device_supported: false,
host_supported: true,
export_include_dirs: ["include/include"],
arch: {
x86_64: {
srcs: ["x86_64/lib/mynativelib.a"],
export_include_dirs: [
"x86_64/include/include",
"x86_64/include_gen/mynativelib",
],
export_include_dirs: ["x86_64/include_gen/mynativelib"],
},
x86: {
srcs: ["x86/lib/mynativelib.a"],
export_include_dirs: [
"x86/include/include",
"x86/include_gen/mynativelib",
],
export_include_dirs: ["x86/include_gen/mynativelib"],
},
},
stl: "none",
@ -639,13 +596,12 @@ sdk_snapshot {
}
`),
checkAllCopyRules(`
include/Test.h -> include/include/Test.h
.intermediates/mynativelib/linux_glibc_x86_64_static/mynativelib.a -> x86_64/lib/mynativelib.a
include/Test.h -> x86_64/include/include/Test.h
.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/Test.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/Test.h
.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BnTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BnTest.h
.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BpTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BpTest.h
.intermediates/mynativelib/linux_glibc_x86_static/mynativelib.a -> x86/lib/mynativelib.a
include/Test.h -> x86/include/include/Test.h
.intermediates/mynativelib/linux_glibc_x86_static/gen/aidl/aidl/foo/bar/Test.h -> x86/include_gen/mynativelib/aidl/foo/bar/Test.h
.intermediates/mynativelib/linux_glibc_x86_static/gen/aidl/aidl/foo/bar/BnTest.h -> x86/include_gen/mynativelib/aidl/foo/bar/BnTest.h
.intermediates/mynativelib/linux_glibc_x86_static/gen/aidl/aidl/foo/bar/BpTest.h -> x86/include_gen/mynativelib/aidl/foo/bar/BpTest.h