Refactor vendor snapshot to use LinkableInterface.
Refactors the vendor snapshot support to use the LinkableInterface
so that support can be extended to Rust. This CL does not add
vendor snapshot support for Rust; that is left for a follow-on CL.
Bug: 184042776
Test: m nothing
Change-Id: Id0c4970ca00053484a52677d182153cbc454c301
diff --git a/cc/vendor_snapshot.go b/cc/vendor_snapshot.go
index 9ad51ad..4e59a95 100644
--- a/cc/vendor_snapshot.go
+++ b/cc/vendor_snapshot.go
@@ -115,7 +115,7 @@
// still be a vendor proprietary module. This happens for cc modules
// that are excluded from the vendor snapshot, and it means that the
// vendor has assumed control of the framework-provided module.
- if c, ok := ctx.Module().(*Module); ok {
+ if c, ok := ctx.Module().(LinkableInterface); ok {
if c.ExcludeFromVendorSnapshot() {
return true
}
@@ -137,7 +137,7 @@
// that are excluded from the recovery snapshot, and it means that the
// vendor has assumed control of the framework-provided module.
- if c, ok := ctx.Module().(*Module); ok {
+ if c, ok := ctx.Module().(LinkableInterface); ok {
if c.ExcludeFromRecoverySnapshot() {
return true
}
@@ -147,8 +147,8 @@
}
// Determines if the module is a candidate for snapshot.
-func isSnapshotAware(cfg android.DeviceConfig, m *Module, inProprietaryPath bool, apexInfo android.ApexInfo, image snapshotImage) bool {
- if !m.Enabled() || m.Properties.HideFromMake {
+func isSnapshotAware(cfg android.DeviceConfig, m LinkableInterface, inProprietaryPath bool, apexInfo android.ApexInfo, image snapshotImage) bool {
+ if !m.Enabled() || m.HiddenFromMake() {
return false
}
// When android/prebuilt.go selects between source and prebuilt, it sets
@@ -177,51 +177,51 @@
return false
}
// skip kernel_headers which always depend on vendor
- if _, ok := m.linker.(*kernelHeadersDecorator); ok {
+ if m.KernelHeadersDecorator() {
return false
}
- // skip LLNDK libraries which are backward compatible
+
if m.IsLlndk() {
return false
}
// Libraries
- if l, ok := m.linker.(snapshotLibraryInterface); ok {
- if m.sanitize != nil {
+ if sanitizable, ok := m.(PlatformSanitizeable); ok && sanitizable.IsSnapshotLibrary() {
+ if sanitizable.SanitizePropDefined() {
// scs and hwasan export both sanitized and unsanitized variants for static and header
// Always use unsanitized variants of them.
for _, t := range []SanitizerType{scs, Hwasan} {
- if !l.shared() && m.sanitize.isSanitizerEnabled(t) {
+ if !sanitizable.Shared() && sanitizable.IsSanitizerEnabled(t) {
return false
}
}
// cfi also exports both variants. But for static, we capture both.
// This is because cfi static libraries can't be linked from non-cfi modules,
// and vice versa. This isn't the case for scs and hwasan sanitizers.
- if !l.static() && !l.shared() && m.sanitize.isSanitizerEnabled(cfi) {
+ if !sanitizable.Static() && !sanitizable.Shared() && sanitizable.IsSanitizerEnabled(cfi) {
return false
}
}
- if l.static() {
- return m.outputFile.Valid() && !image.private(m)
+ if sanitizable.Static() {
+ return sanitizable.OutputFile().Valid() && !image.private(m)
}
- if l.shared() {
- if !m.outputFile.Valid() {
+ if sanitizable.Shared() {
+ if !sanitizable.OutputFile().Valid() {
return false
}
if image.includeVndk() {
- if !m.IsVndk() {
+ if !sanitizable.IsVndk() {
return true
}
- return m.IsVndkExt()
+ return sanitizable.IsVndkExt()
}
}
return true
}
// Binaries and Objects
- if m.binary() || m.object() {
- return m.outputFile.Valid()
+ if m.Binary() || m.Object() {
+ return m.OutputFile().Valid()
}
return false
@@ -323,7 +323,7 @@
// installSnapshot function copies prebuilt file (.so, .a, or executable) and json flag file.
// For executables, init_rc and vintf_fragments files are also copied.
- installSnapshot := func(m *Module, fake bool) android.Paths {
+ installSnapshot := func(m LinkableInterface, fake bool) android.Paths {
targetArch := "arch-" + m.Target().Arch.ArchType.String()
if m.Target().Arch.ArchVariant != "" {
targetArch += "-" + m.Target().Arch.ArchVariant
@@ -337,7 +337,7 @@
prop.ModuleName = ctx.ModuleName(m)
if c.supportsVndkExt && m.IsVndkExt() {
// vndk exts are installed to /vendor/lib(64)?/vndk(-sp)?
- if m.isVndkSp() {
+ if m.IsVndkSp() {
prop.RelativeInstallPath = "vndk-sp"
} else {
prop.RelativeInstallPath = "vndk"
@@ -345,7 +345,7 @@
} else {
prop.RelativeInstallPath = m.RelativeInstallPath()
}
- prop.RuntimeLibs = m.Properties.SnapshotRuntimeLibs
+ prop.RuntimeLibs = m.SnapshotRuntimeLibs()
prop.Required = m.RequiredModuleNames()
for _, path := range m.InitRc() {
prop.InitRc = append(prop.InitRc, filepath.Join("configs", path.Base()))
@@ -365,8 +365,8 @@
var propOut string
- if l, ok := m.linker.(snapshotLibraryInterface); ok {
- exporterInfo := ctx.ModuleProvider(m, FlagExporterInfoProvider).(FlagExporterInfo)
+ if m.IsSnapshotLibrary() {
+ exporterInfo := ctx.ModuleProvider(m.Module(), FlagExporterInfoProvider).(FlagExporterInfo)
// library flags
prop.ExportedFlags = exporterInfo.Flags
@@ -376,19 +376,22 @@
for _, dir := range exporterInfo.SystemIncludeDirs {
prop.ExportedSystemDirs = append(prop.ExportedSystemDirs, filepath.Join("include", dir.String()))
}
+
// shared libs dependencies aren't meaningful on static or header libs
- if l.shared() {
- prop.SharedLibs = m.Properties.SnapshotSharedLibs
+ if m.Shared() {
+ prop.SharedLibs = m.SnapshotSharedLibs()
}
- if l.static() && m.sanitize != nil {
- prop.SanitizeMinimalDep = m.sanitize.Properties.MinimalRuntimeDep || enableMinimalRuntime(m.sanitize)
- prop.SanitizeUbsanDep = m.sanitize.Properties.UbsanRuntimeDep || enableUbsanRuntime(m.sanitize)
+ if sanitizable, ok := m.(PlatformSanitizeable); ok {
+ if sanitizable.Static() && sanitizable.SanitizePropDefined() {
+ prop.SanitizeMinimalDep = sanitizable.MinimalRuntimeDep() || sanitizable.MinimalRuntimeNeeded()
+ prop.SanitizeUbsanDep = sanitizable.UbsanRuntimeDep() || sanitizable.UbsanRuntimeNeeded()
+ }
}
var libType string
- if l.static() {
+ if m.Static() {
libType = "static"
- } else if l.shared() {
+ } else if m.Shared() {
libType = "shared"
} else {
libType = "header"
@@ -398,16 +401,18 @@
// install .a or .so
if libType != "header" {
- libPath := m.outputFile.Path()
+ libPath := m.OutputFile().Path()
stem = libPath.Base()
- if l.static() && m.sanitize != nil && m.sanitize.isSanitizerEnabled(cfi) {
- // both cfi and non-cfi variant for static libraries can exist.
- // attach .cfi to distinguish between cfi and non-cfi.
- // e.g. libbase.a -> libbase.cfi.a
- ext := filepath.Ext(stem)
- stem = strings.TrimSuffix(stem, ext) + ".cfi" + ext
- prop.Sanitize = "cfi"
- prop.ModuleName += ".cfi"
+ if sanitizable, ok := m.(PlatformSanitizeable); ok {
+ if sanitizable.Static() && sanitizable.SanitizePropDefined() && sanitizable.IsSanitizerEnabled(cfi) {
+ // both cfi and non-cfi variant for static libraries can exist.
+ // attach .cfi to distinguish between cfi and non-cfi.
+ // e.g. libbase.a -> libbase.cfi.a
+ ext := filepath.Ext(stem)
+ stem = strings.TrimSuffix(stem, ext) + ".cfi" + ext
+ prop.Sanitize = "cfi"
+ prop.ModuleName += ".cfi"
+ }
}
snapshotLibOut := filepath.Join(snapshotArchDir, targetArch, libType, stem)
ret = append(ret, copyFile(ctx, libPath, snapshotLibOut, fake))
@@ -416,20 +421,20 @@
}
propOut = filepath.Join(snapshotArchDir, targetArch, libType, stem+".json")
- } else if m.binary() {
+ } else if m.Binary() {
// binary flags
prop.Symlinks = m.Symlinks()
- prop.SharedLibs = m.Properties.SnapshotSharedLibs
+ prop.SharedLibs = m.SnapshotSharedLibs()
// install bin
- binPath := m.outputFile.Path()
+ binPath := m.OutputFile().Path()
snapshotBinOut := filepath.Join(snapshotArchDir, targetArch, "binary", binPath.Base())
ret = append(ret, copyFile(ctx, binPath, snapshotBinOut, fake))
propOut = snapshotBinOut + ".json"
- } else if m.object() {
+ } else if m.Object() {
// object files aren't installed to the device, so their names can conflict.
// Use module name as stem.
- objPath := m.outputFile.Path()
+ objPath := m.OutputFile().Path()
snapshotObjOut := filepath.Join(snapshotArchDir, targetArch, "object",
ctx.ModuleName(m)+filepath.Ext(objPath.Base()))
ret = append(ret, copyFile(ctx, objPath, snapshotObjOut, fake))
@@ -450,7 +455,7 @@
}
ctx.VisitAllModules(func(module android.Module) {
- m, ok := module.(*Module)
+ m, ok := module.(LinkableInterface)
if !ok {
return
}
@@ -484,8 +489,8 @@
// installSnapshot installs prebuilts and json flag files
snapshotOutputs = append(snapshotOutputs, installSnapshot(m, installAsFake)...)
// just gather headers and notice files here, because they are to be deduplicated
- if l, ok := m.linker.(snapshotLibraryInterface); ok {
- headers = append(headers, l.snapshotHeaders()...)
+ if m.IsSnapshotLibrary() {
+ headers = append(headers, m.SnapshotHeaders()...)
}
if len(m.NoticeFiles()) > 0 {