diff options
Diffstat (limited to 'cc')
| -rw-r--r-- | cc/Android.bp | 1 | ||||
| -rw-r--r-- | cc/genrule.go | 5 | ||||
| -rw-r--r-- | cc/image.go | 7 | ||||
| -rw-r--r-- | cc/linkable.go | 10 | ||||
| -rw-r--r-- | cc/sanitize.go | 3 | ||||
| -rw-r--r-- | cc/sdk.go | 2 | ||||
| -rw-r--r-- | cc/snapshot_prebuilt.go | 286 | ||||
| -rw-r--r-- | cc/snapshot_utils.go | 2 | ||||
| -rw-r--r-- | cc/testing.go | 13 | ||||
| -rw-r--r-- | cc/util.go | 23 | ||||
| -rw-r--r-- | cc/vendor_snapshot.go | 214 | ||||
| -rw-r--r-- | cc/vndk.go | 13 |
12 files changed, 125 insertions, 454 deletions
diff --git a/cc/Android.bp b/cc/Android.bp index 4b750ff25..164d32b12 100644 --- a/cc/Android.bp +++ b/cc/Android.bp @@ -14,6 +14,7 @@ bootstrap_go_package { "soong-cc-config", "soong-etc", "soong-genrule", + "soong-snapshot", "soong-tradefed", ], srcs: [ diff --git a/cc/genrule.go b/cc/genrule.go index b0efc6ca4..0ca901e61 100644 --- a/cc/genrule.go +++ b/cc/genrule.go @@ -17,6 +17,7 @@ package cc import ( "android/soong/android" "android/soong/genrule" + "android/soong/snapshot" ) func init() { @@ -84,7 +85,7 @@ func (g *GenruleExtraProperties) RecoveryVariantNeeded(ctx android.BaseModuleCon // is not needed. recoverySnapshotVersion := ctx.DeviceConfig().RecoverySnapshotVersion() if recoverySnapshotVersion != "current" && recoverySnapshotVersion != "" && - !isRecoveryProprietaryModule(ctx) { + !snapshot.IsRecoveryProprietaryModule(ctx) { return false } else { return Bool(g.Recovery_available) @@ -103,7 +104,7 @@ func (g *GenruleExtraProperties) ExtraImageVariations(ctx android.BaseModuleCont // If not, we assume modules under proprietary paths are compatible for // BOARD_VNDK_VERSION. The other modules are regarded as AOSP, that is // PLATFORM_VNDK_VERSION. - if vndkVersion == "current" || !IsVendorProprietaryModule(ctx) { + if vndkVersion == "current" || !snapshot.IsVendorProprietaryModule(ctx) { variants = append(variants, VendorVariationPrefix+ctx.DeviceConfig().PlatformVndkVersion()) } else { variants = append(variants, VendorVariationPrefix+vndkVersion) diff --git a/cc/image.go b/cc/image.go index 15ec1c867..3a0857b21 100644 --- a/cc/image.go +++ b/cc/image.go @@ -22,6 +22,7 @@ import ( "strings" "android/soong/android" + "android/soong/snapshot" ) var _ android.ImageInterface = (*Module)(nil) @@ -496,7 +497,7 @@ func MutateImage(mctx android.BaseModuleContext, m ImageMutatableModule) { // BOARD_VNDK_VERSION. The other modules are regarded as AOSP, or // PLATFORM_VNDK_VERSION. if m.HasVendorVariant() { - if IsVendorProprietaryModule(mctx) { + if snapshot.IsVendorProprietaryModule(mctx) { vendorVariants = append(vendorVariants, boardVndkVersion) } else { vendorVariants = append(vendorVariants, platformVndkVersion) @@ -525,7 +526,7 @@ func MutateImage(mctx android.BaseModuleContext, m ImageMutatableModule) { platformVndkVersion, boardVndkVersion, ) - } else if IsVendorProprietaryModule(mctx) { + } else if snapshot.IsVendorProprietaryModule(mctx) { vendorVariants = append(vendorVariants, boardVndkVersion) } else { vendorVariants = append(vendorVariants, platformVndkVersion) @@ -582,7 +583,7 @@ func MutateImage(mctx android.BaseModuleContext, m ImageMutatableModule) { if !m.KernelHeadersDecorator() && !m.IsSnapshotPrebuilt() && usingRecoverySnapshot && - !isRecoveryProprietaryModule(mctx) { + !snapshot.IsRecoveryProprietaryModule(mctx) { recoveryVariantNeeded = false } diff --git a/cc/linkable.go b/cc/linkable.go index 6232efb95..b510508a7 100644 --- a/cc/linkable.go +++ b/cc/linkable.go @@ -3,6 +3,7 @@ package cc import ( "android/soong/android" "android/soong/bazel/cquery" + "android/soong/snapshot" "github.com/google/blueprint" ) @@ -71,15 +72,12 @@ type SantizableDependencyTagChecker func(tag blueprint.DependencyTag) bool // Snapshottable defines those functions necessary for handling module snapshots. type Snapshottable interface { + snapshot.VendorSnapshotModuleInterface + snapshot.RecoverySnapshotModuleInterface + // SnapshotHeaders returns a list of header paths provided by this module. SnapshotHeaders() android.Paths - // ExcludeFromVendorSnapshot returns true if this module should be otherwise excluded from the vendor snapshot. - ExcludeFromVendorSnapshot() bool - - // ExcludeFromRecoverySnapshot returns true if this module should be otherwise excluded from the recovery snapshot. - ExcludeFromRecoverySnapshot() bool - // SnapshotLibrary returns true if this module is a snapshot library. IsSnapshotLibrary() bool diff --git a/cc/sanitize.go b/cc/sanitize.go index defe8fde1..3863c3a7c 100644 --- a/cc/sanitize.go +++ b/cc/sanitize.go @@ -25,6 +25,7 @@ import ( "android/soong/android" "android/soong/cc/config" + "android/soong/snapshot" ) var ( @@ -907,7 +908,7 @@ func (m *Module) SanitizableDepTagChecker() SantizableDependencyTagChecker { // as vendor snapshot. Such modules must create both cfi and non-cfi variants, // except for ones which explicitly disable cfi. func needsCfiForVendorSnapshot(mctx android.TopDownMutatorContext) bool { - if IsVendorProprietaryModule(mctx) { + if snapshot.IsVendorProprietaryModule(mctx) { return false } @@ -76,7 +76,7 @@ func sdkMutator(ctx android.BottomUpMutatorContext) { } ctx.AliasVariation("") } - case *snapshot: + case *snapshotModule: ctx.CreateVariations("") } } diff --git a/cc/snapshot_prebuilt.go b/cc/snapshot_prebuilt.go index 4f031ff96..9672c0fff 100644 --- a/cc/snapshot_prebuilt.go +++ b/cc/snapshot_prebuilt.go @@ -18,57 +18,17 @@ package cc // snapshot mutators and snapshot information maps which are also defined in this file. import ( - "path/filepath" "strings" "android/soong/android" + "android/soong/snapshot" "github.com/google/blueprint" ) -// Defines the specifics of different images to which the snapshot process is applicable, e.g., -// vendor, recovery, ramdisk. +// This interface overrides snapshot.SnapshotImage to implement cc module specific functions type SnapshotImage interface { - // Returns true if a snapshot should be generated for this image. - shouldGenerateSnapshot(ctx android.SingletonContext) bool - - // Function that returns true if the module is included in this image. - // Using a function return instead of a value to prevent early - // evalution of a function that may be not be defined. - inImage(m LinkableInterface) func() bool - - // Returns true if the module is private and must not be included in the - // snapshot. For example VNDK-private modules must return true for the - // vendor snapshots. But false for the recovery snapshots. - private(m LinkableInterface) bool - - // Returns true if a dir under source tree is an SoC-owned proprietary - // directory, such as device/, vendor/, etc. - // - // For a given snapshot (e.g., vendor, recovery, etc.) if - // isProprietaryPath(dir, deviceConfig) returns true, then the module in dir - // will be built from sources. - isProprietaryPath(dir string, deviceConfig android.DeviceConfig) bool - - // Whether to include VNDK in the snapshot for this image. - includeVndk() bool - - // Whether a given module has been explicitly excluded from the - // snapshot, e.g., using the exclude_from_vendor_snapshot or - // exclude_from_recovery_snapshot properties. - excludeFromSnapshot(m LinkableInterface) bool - - // Returns true if the build is using a snapshot for this image. - isUsingSnapshot(cfg android.DeviceConfig) bool - - // Returns a version of which the snapshot should be used in this target. - // This will only be meaningful when isUsingSnapshot is true. - targetSnapshotVersion(cfg android.DeviceConfig) string - - // Whether to exclude a given module from the directed snapshot or not. - // If the makefile variable DIRECTED_{IMAGE}_SNAPSHOT is true, directed snapshot is turned on, - // and only modules listed in {IMAGE}_SNAPSHOT_MODULES will be captured. - excludeFromDirectedSnapshot(cfg android.DeviceConfig, name string) bool + snapshot.SnapshotImage // The image variant name for this snapshot image. // For example, recovery snapshot image will return "recovery", and vendor snapshot image will @@ -80,122 +40,44 @@ type SnapshotImage interface { moduleNameSuffix() string } -type vendorSnapshotImage struct{} -type recoverySnapshotImage struct{} - -type directoryMap map[string]bool - -var ( - // Modules under following directories are ignored. They are OEM's and vendor's - // proprietary modules(device/, kernel/, vendor/, and hardware/). - defaultDirectoryExcludedMap = directoryMap{ - "device": true, - "hardware": true, - "kernel": true, - "vendor": true, - } - - // Modules under following directories are included as they are in AOSP, - // although hardware/ and kernel/ are normally for vendor's own. - defaultDirectoryIncludedMap = directoryMap{ - "kernel/configs": true, - "kernel/prebuilts": true, - "kernel/tests": true, - "hardware/interfaces": true, - "hardware/libhardware": true, - "hardware/libhardware_legacy": true, - "hardware/ril": true, - } -) - -func (vendorSnapshotImage) Init(ctx android.RegistrationContext) { - ctx.RegisterSingletonType("vendor-snapshot", VendorSnapshotSingleton) - ctx.RegisterModuleType("vendor_snapshot", vendorSnapshotFactory) - ctx.RegisterModuleType("vendor_snapshot_shared", VendorSnapshotSharedFactory) - ctx.RegisterModuleType("vendor_snapshot_static", VendorSnapshotStaticFactory) - ctx.RegisterModuleType("vendor_snapshot_header", VendorSnapshotHeaderFactory) - ctx.RegisterModuleType("vendor_snapshot_binary", VendorSnapshotBinaryFactory) - ctx.RegisterModuleType("vendor_snapshot_object", VendorSnapshotObjectFactory) - - ctx.RegisterSingletonType("vendor-fake-snapshot", VendorFakeSnapshotSingleton) +type vendorSnapshotImage struct { + *snapshot.VendorSnapshotImage } -func (vendorSnapshotImage) RegisterAdditionalModule(ctx android.RegistrationContext, name string, factory android.ModuleFactory) { - ctx.RegisterModuleType(name, factory) +type recoverySnapshotImage struct { + *snapshot.RecoverySnapshotImage } -func (vendorSnapshotImage) shouldGenerateSnapshot(ctx android.SingletonContext) bool { - // BOARD_VNDK_VERSION must be set to 'current' in order to generate a snapshot. - return ctx.DeviceConfig().VndkVersion() == "current" -} - -func (vendorSnapshotImage) inImage(m LinkableInterface) func() bool { - return m.InVendor -} - -func (vendorSnapshotImage) private(m LinkableInterface) bool { - return m.IsVndkPrivate() -} - -func isDirectoryExcluded(dir string, excludedMap directoryMap, includedMap directoryMap) bool { - if dir == "." || dir == "/" { - return false - } - if includedMap[dir] { - return false - } else if excludedMap[dir] { - return true - } else if defaultDirectoryIncludedMap[dir] { - return false - } else if defaultDirectoryExcludedMap[dir] { - return true - } else { - return isDirectoryExcluded(filepath.Dir(dir), excludedMap, includedMap) - } -} - -func (vendorSnapshotImage) isProprietaryPath(dir string, deviceConfig android.DeviceConfig) bool { - return isDirectoryExcluded(dir, deviceConfig.VendorSnapshotDirsExcludedMap(), deviceConfig.VendorSnapshotDirsIncludedMap()) -} - -// vendor snapshot includes static/header libraries with vndk: {enabled: true}. -func (vendorSnapshotImage) includeVndk() bool { - return true -} - -func (vendorSnapshotImage) excludeFromSnapshot(m LinkableInterface) bool { - return m.ExcludeFromVendorSnapshot() +func (vendorSnapshotImage) imageVariantName(cfg android.DeviceConfig) string { + return VendorVariationPrefix + cfg.VndkVersion() } -func (vendorSnapshotImage) isUsingSnapshot(cfg android.DeviceConfig) bool { - vndkVersion := cfg.VndkVersion() - return vndkVersion != "current" && vndkVersion != "" +func (vendorSnapshotImage) moduleNameSuffix() string { + return VendorSuffix } -func (vendorSnapshotImage) targetSnapshotVersion(cfg android.DeviceConfig) string { - return cfg.VndkVersion() +func (recoverySnapshotImage) imageVariantName(cfg android.DeviceConfig) string { + return android.RecoveryVariation } -// returns true iff a given module SHOULD BE EXCLUDED, false if included -func (vendorSnapshotImage) excludeFromDirectedSnapshot(cfg android.DeviceConfig, name string) bool { - // If we're using full snapshot, not directed snapshot, capture every module - if !cfg.DirectedVendorSnapshot() { - return false - } - // Else, checks if name is in VENDOR_SNAPSHOT_MODULES. - return !cfg.VendorSnapshotModules()[name] +func (recoverySnapshotImage) moduleNameSuffix() string { + return recoverySuffix } -func (vendorSnapshotImage) imageVariantName(cfg android.DeviceConfig) string { - return VendorVariationPrefix + cfg.VndkVersion() -} +// Override existing vendor and recovery snapshot for cc module specific extra functions +var VendorSnapshotImageSingleton vendorSnapshotImage = vendorSnapshotImage{&snapshot.VendorSnapshotImageSingleton} +var recoverySnapshotImageSingleton recoverySnapshotImage = recoverySnapshotImage{&snapshot.RecoverySnapshotImageSingleton} -func (vendorSnapshotImage) moduleNameSuffix() string { - return VendorSuffix +func RegisterVendorSnapshotModules(ctx android.RegistrationContext) { + ctx.RegisterModuleType("vendor_snapshot", vendorSnapshotFactory) + ctx.RegisterModuleType("vendor_snapshot_shared", VendorSnapshotSharedFactory) + ctx.RegisterModuleType("vendor_snapshot_static", VendorSnapshotStaticFactory) + ctx.RegisterModuleType("vendor_snapshot_header", VendorSnapshotHeaderFactory) + ctx.RegisterModuleType("vendor_snapshot_binary", VendorSnapshotBinaryFactory) + ctx.RegisterModuleType("vendor_snapshot_object", VendorSnapshotObjectFactory) } -func (recoverySnapshotImage) init(ctx android.RegistrationContext) { - ctx.RegisterSingletonType("recovery-snapshot", RecoverySnapshotSingleton) +func RegisterRecoverySnapshotModules(ctx android.RegistrationContext) { ctx.RegisterModuleType("recovery_snapshot", recoverySnapshotFactory) ctx.RegisterModuleType("recovery_snapshot_shared", RecoverySnapshotSharedFactory) ctx.RegisterModuleType("recovery_snapshot_static", RecoverySnapshotStaticFactory) @@ -204,66 +86,9 @@ func (recoverySnapshotImage) init(ctx android.RegistrationContext) { ctx.RegisterModuleType("recovery_snapshot_object", RecoverySnapshotObjectFactory) } -func (recoverySnapshotImage) shouldGenerateSnapshot(ctx android.SingletonContext) bool { - // RECOVERY_SNAPSHOT_VERSION must be set to 'current' in order to generate a - // snapshot. - return ctx.DeviceConfig().RecoverySnapshotVersion() == "current" -} - -func (recoverySnapshotImage) inImage(m LinkableInterface) func() bool { - return m.InRecovery -} - -// recovery snapshot does not have private libraries. -func (recoverySnapshotImage) private(m LinkableInterface) bool { - return false -} - -func (recoverySnapshotImage) isProprietaryPath(dir string, deviceConfig android.DeviceConfig) bool { - return isDirectoryExcluded(dir, deviceConfig.RecoverySnapshotDirsExcludedMap(), deviceConfig.RecoverySnapshotDirsIncludedMap()) -} - -// recovery snapshot does NOT treat vndk specially. -func (recoverySnapshotImage) includeVndk() bool { - return false -} - -func (recoverySnapshotImage) excludeFromSnapshot(m LinkableInterface) bool { - return m.ExcludeFromRecoverySnapshot() -} - -func (recoverySnapshotImage) isUsingSnapshot(cfg android.DeviceConfig) bool { - recoverySnapshotVersion := cfg.RecoverySnapshotVersion() - return recoverySnapshotVersion != "current" && recoverySnapshotVersion != "" -} - -func (recoverySnapshotImage) targetSnapshotVersion(cfg android.DeviceConfig) string { - return cfg.RecoverySnapshotVersion() -} - -func (recoverySnapshotImage) excludeFromDirectedSnapshot(cfg android.DeviceConfig, name string) bool { - // If we're using full snapshot, not directed snapshot, capture every module - if !cfg.DirectedRecoverySnapshot() { - return false - } - // Else, checks if name is in RECOVERY_SNAPSHOT_MODULES. - return !cfg.RecoverySnapshotModules()[name] -} - -func (recoverySnapshotImage) imageVariantName(cfg android.DeviceConfig) string { - return android.RecoveryVariation -} - -func (recoverySnapshotImage) moduleNameSuffix() string { - return recoverySuffix -} - -var VendorSnapshotImageSingleton vendorSnapshotImage -var recoverySnapshotImageSingleton recoverySnapshotImage - func init() { - VendorSnapshotImageSingleton.Init(android.InitRegistrationContext) - recoverySnapshotImageSingleton.init(android.InitRegistrationContext) + RegisterVendorSnapshotModules(android.InitRegistrationContext) + RegisterRecoverySnapshotModules(android.InitRegistrationContext) android.RegisterMakeVarsProvider(pctx, snapshotMakeVarsProvider) } @@ -285,8 +110,7 @@ type SnapshotProperties struct { Binaries []string `android:"arch_variant"` Objects []string `android:"arch_variant"` } - -type snapshot struct { +type snapshotModule struct { android.ModuleBase properties SnapshotProperties @@ -296,41 +120,41 @@ type snapshot struct { image SnapshotImage } -func (s *snapshot) ImageMutatorBegin(ctx android.BaseModuleContext) { +func (s *snapshotModule) ImageMutatorBegin(ctx android.BaseModuleContext) { cfg := ctx.DeviceConfig() - if !s.image.isUsingSnapshot(cfg) || s.image.targetSnapshotVersion(cfg) != s.baseSnapshot.Version() { + if !s.image.IsUsingSnapshot(cfg) || s.image.TargetSnapshotVersion(cfg) != s.baseSnapshot.Version() { s.Disable() } } -func (s *snapshot) CoreVariantNeeded(ctx android.BaseModuleContext) bool { +func (s *snapshotModule) CoreVariantNeeded(ctx android.BaseModuleContext) bool { return false } -func (s *snapshot) RamdiskVariantNeeded(ctx android.BaseModuleContext) bool { +func (s *snapshotModule) RamdiskVariantNeeded(ctx android.BaseModuleContext) bool { return false } -func (s *snapshot) VendorRamdiskVariantNeeded(ctx android.BaseModuleContext) bool { +func (s *snapshotModule) VendorRamdiskVariantNeeded(ctx android.BaseModuleContext) bool { return false } -func (s *snapshot) DebugRamdiskVariantNeeded(ctx android.BaseModuleContext) bool { +func (s *snapshotModule) DebugRamdiskVariantNeeded(ctx android.BaseModuleContext) bool { return false } -func (s *snapshot) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool { +func (s *snapshotModule) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool { return false } -func (s *snapshot) ExtraImageVariations(ctx android.BaseModuleContext) []string { +func (s *snapshotModule) ExtraImageVariations(ctx android.BaseModuleContext) []string { return []string{s.image.imageVariantName(ctx.DeviceConfig())} } -func (s *snapshot) SetImageVariation(ctx android.BaseModuleContext, variation string, module android.Module) { +func (s *snapshotModule) SetImageVariation(ctx android.BaseModuleContext, variation string, module android.Module) { } -func (s *snapshot) GenerateAndroidBuildActions(ctx android.ModuleContext) { +func (s *snapshotModule) GenerateAndroidBuildActions(ctx android.ModuleContext) { // Nothing, the snapshot module is only used to forward dependency information in DepsMutator. } @@ -342,7 +166,7 @@ func getSnapshotNameSuffix(moduleSuffix, version, arch string) string { return moduleSuffix + versionSuffix } -func (s *snapshot) DepsMutator(ctx android.BottomUpMutatorContext) { +func (s *snapshotModule) DepsMutator(ctx android.BottomUpMutatorContext) { collectSnapshotMap := func(names []string, snapshotSuffix, moduleSuffix string) map[string]string { snapshotMap := make(map[string]string) for _, name := range names { @@ -382,12 +206,12 @@ type SnapshotInfo struct { var SnapshotInfoProvider = blueprint.NewMutatorProvider(SnapshotInfo{}, "deps") -var _ android.ImageInterface = (*snapshot)(nil) +var _ android.ImageInterface = (*snapshotModule)(nil) func snapshotMakeVarsProvider(ctx android.MakeVarsContext) { snapshotSet := map[string]struct{}{} ctx.VisitAllModules(func(m android.Module) { - if s, ok := m.(*snapshot); ok { + if s, ok := m.(*snapshotModule); ok { if _, ok := snapshotSet[s.Name()]; ok { // arch variant generates duplicated modules // skip this as we only need to know the path of the module. @@ -411,13 +235,13 @@ func recoverySnapshotFactory() android.Module { } func snapshotFactory(image SnapshotImage) android.Module { - snapshot := &snapshot{} - snapshot.image = image - snapshot.AddProperties( - &snapshot.properties, - &snapshot.baseSnapshot.baseProperties) - android.InitAndroidArchModule(snapshot, android.DeviceSupported, android.MultilibBoth) - return snapshot + snapshotModule := &snapshotModule{} + snapshotModule.image = image + snapshotModule.AddProperties( + &snapshotModule.properties, + &snapshotModule.baseSnapshot.baseProperties) + android.InitAndroidArchModule(snapshotModule, android.DeviceSupported, android.MultilibBoth) + return snapshotModule } type BaseSnapshotDecoratorProperties struct { @@ -449,7 +273,7 @@ type BaseSnapshotDecoratorProperties struct { // will be seen as "libbase.vendor_static.30.arm64" by Soong. type BaseSnapshotDecorator struct { baseProperties BaseSnapshotDecoratorProperties - image SnapshotImage + Image SnapshotImage } func (p *BaseSnapshotDecorator) Name(name string) string { @@ -489,7 +313,7 @@ func (p *BaseSnapshotDecorator) SetSnapshotAndroidMkSuffix(ctx android.ModuleCon Variation: android.CoreVariation}) if ctx.OtherModuleFarDependencyVariantExists(variations, ctx.Module().(LinkableInterface).BaseModuleName()) { - p.baseProperties.Androidmk_suffix = p.image.moduleNameSuffix() + p.baseProperties.Androidmk_suffix = p.Image.moduleNameSuffix() return } @@ -498,14 +322,14 @@ func (p *BaseSnapshotDecorator) SetSnapshotAndroidMkSuffix(ctx android.ModuleCon Variation: ProductVariationPrefix + ctx.DeviceConfig().PlatformVndkVersion()}) if ctx.OtherModuleFarDependencyVariantExists(variations, ctx.Module().(LinkableInterface).BaseModuleName()) { - p.baseProperties.Androidmk_suffix = p.image.moduleNameSuffix() + p.baseProperties.Androidmk_suffix = p.Image.moduleNameSuffix() return } images := []SnapshotImage{VendorSnapshotImageSingleton, recoverySnapshotImageSingleton} for _, image := range images { - if p.image == image { + if p.Image == image { continue } variations = append(ctx.Target().Variations(), blueprint.Variation{ @@ -518,7 +342,7 @@ func (p *BaseSnapshotDecorator) SetSnapshotAndroidMkSuffix(ctx android.ModuleCon image.moduleNameSuffix()+variant, p.Version(), ctx.DeviceConfig().Arches()[0].ArchType.String())) { - p.baseProperties.Androidmk_suffix = p.image.moduleNameSuffix() + p.baseProperties.Androidmk_suffix = p.Image.moduleNameSuffix() return } } @@ -529,7 +353,7 @@ func (p *BaseSnapshotDecorator) SetSnapshotAndroidMkSuffix(ctx android.ModuleCon // Call this with a module suffix after creating a snapshot module, such as // vendorSnapshotSharedSuffix, recoverySnapshotBinarySuffix, etc. func (p *BaseSnapshotDecorator) Init(m LinkableInterface, image SnapshotImage, moduleSuffix string) { - p.image = image + p.Image = image p.baseProperties.ModuleSuffix = image.moduleNameSuffix() + moduleSuffix m.AddProperties(&p.baseProperties) android.AddLoadHook(m, func(ctx android.LoadHookContext) { diff --git a/cc/snapshot_utils.go b/cc/snapshot_utils.go index b0538bea0..24abcce55 100644 --- a/cc/snapshot_utils.go +++ b/cc/snapshot_utils.go @@ -114,7 +114,7 @@ func ShouldCollectHeadersForSnapshot(ctx android.ModuleContext, m LinkableInterf } for _, image := range []SnapshotImage{VendorSnapshotImageSingleton, recoverySnapshotImageSingleton} { - if isSnapshotAware(ctx.DeviceConfig(), m, image.isProprietaryPath(ctx.ModuleDir(), ctx.DeviceConfig()), apexInfo, image) { + if isSnapshotAware(ctx.DeviceConfig(), m, image.IsProprietaryPath(ctx.ModuleDir(), ctx.DeviceConfig()), apexInfo, image) { return true } } diff --git a/cc/testing.go b/cc/testing.go index b9d84f6cb..6a002c05a 100644 --- a/cc/testing.go +++ b/cc/testing.go @@ -20,6 +20,7 @@ import ( "android/soong/android" "android/soong/genrule" + "android/soong/snapshot" ) func RegisterRequiredBuildComponentsForTest(ctx android.RegistrationContext) { @@ -638,8 +639,10 @@ var PrepareForTestOnFuchsia = android.GroupFixturePreparers( var PrepareForTestWithCcIncludeVndk = android.GroupFixturePreparers( PrepareForIntegrationTestWithCc, android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) { - VendorSnapshotImageSingleton.Init(ctx) - recoverySnapshotImageSingleton.init(ctx) + snapshot.VendorSnapshotImageSingleton.Init(ctx) + snapshot.RecoverySnapshotImageSingleton.Init(ctx) + RegisterVendorSnapshotModules(ctx) + RegisterRecoverySnapshotModules(ctx) ctx.RegisterSingletonType("vndk-snapshot", VndkSnapshotSingleton) }), ) @@ -687,8 +690,10 @@ func CreateTestContext(config android.Config) *android.TestContext { ctx.RegisterModuleType("filegroup", android.FileGroupFactory) ctx.RegisterModuleType("vndk_prebuilt_shared", VndkPrebuiltSharedFactory) - VendorSnapshotImageSingleton.Init(ctx) - recoverySnapshotImageSingleton.init(ctx) + snapshot.VendorSnapshotImageSingleton.Init(ctx) + snapshot.RecoverySnapshotImageSingleton.Init(ctx) + RegisterVendorSnapshotModules(ctx) + RegisterRecoverySnapshotModules(ctx) ctx.RegisterSingletonType("vndk-snapshot", VndkSnapshotSingleton) RegisterVndkLibraryTxtTypes(ctx) diff --git a/cc/util.go b/cc/util.go index 1220d8432..9bba87676 100644 --- a/cc/util.go +++ b/cc/util.go @@ -21,6 +21,7 @@ import ( "strings" "android/soong/android" + "android/soong/snapshot" ) // Efficiently converts a list of include directories to a single string @@ -126,20 +127,6 @@ func makeSymlinkCmd(linkDirOnDevice string, linkName string, target string) stri "ln -sf " + target + " " + filepath.Join(dir, linkName) } -func copyFileRule(ctx android.SingletonContext, path android.Path, out string) android.OutputPath { - outPath := android.PathForOutput(ctx, out) - ctx.Build(pctx, android.BuildParams{ - Rule: android.Cp, - Input: path, - Output: outPath, - Description: "copy " + path.String() + " -> " + out, - Args: map[string]string{ - "cpFlags": "-f -L", - }, - }) - return outPath -} - func combineNoticesRule(ctx android.SingletonContext, paths android.Paths, out string) android.OutputPath { outPath := android.PathForOutput(ctx, out) ctx.Build(pctx, android.BuildParams{ @@ -151,12 +138,6 @@ func combineNoticesRule(ctx android.SingletonContext, paths android.Paths, out s return outPath } -func writeStringToFileRule(ctx android.SingletonContext, content, out string) android.OutputPath { - outPath := android.PathForOutput(ctx, out) - android.WriteFileRule(ctx, outPath, content) - return outPath -} - // Dump a map to a list file as: // // {key1} {value1} @@ -172,5 +153,5 @@ func installMapListFileRule(ctx android.SingletonContext, m map[string]string, p txtBuilder.WriteString(" ") txtBuilder.WriteString(m[k]) } - return writeStringToFileRule(ctx, txtBuilder.String(), path) + return snapshot.WriteStringToFileRule(ctx, txtBuilder.String(), path) } diff --git a/cc/vendor_snapshot.go b/cc/vendor_snapshot.go index 003b7c98b..ba4d79fcf 100644 --- a/cc/vendor_snapshot.go +++ b/cc/vendor_snapshot.go @@ -13,141 +13,46 @@ // limitations under the License. package cc -// This file contains singletons to capture vendor and recovery snapshot. They consist of prebuilt -// modules under AOSP so older vendor and recovery can be built with a newer system in a single -// source tree. - import ( "encoding/json" "path/filepath" - "sort" "strings" "android/soong/android" + "android/soong/snapshot" ) -var vendorSnapshotSingleton = snapshotSingleton{ - "vendor", - "SOONG_VENDOR_SNAPSHOT_ZIP", - android.OptionalPath{}, - true, - VendorSnapshotImageSingleton, - false, /* fake */ -} - -var vendorFakeSnapshotSingleton = snapshotSingleton{ - "vendor", - "SOONG_VENDOR_FAKE_SNAPSHOT_ZIP", - android.OptionalPath{}, - true, - VendorSnapshotImageSingleton, - true, /* fake */ -} - -var recoverySnapshotSingleton = snapshotSingleton{ - "recovery", - "SOONG_RECOVERY_SNAPSHOT_ZIP", - android.OptionalPath{}, - false, - recoverySnapshotImageSingleton, - false, /* fake */ -} - -func VendorSnapshotSingleton() android.Singleton { - return &vendorSnapshotSingleton -} - -func VendorFakeSnapshotSingleton() android.Singleton { - return &vendorFakeSnapshotSingleton -} - -func RecoverySnapshotSingleton() android.Singleton { - return &recoverySnapshotSingleton -} - -type snapshotSingleton struct { - // Name, e.g., "vendor", "recovery", "ramdisk". - name string - - // Make variable that points to the snapshot file, e.g., - // "SOONG_RECOVERY_SNAPSHOT_ZIP". - makeVar string - - // Path to the snapshot zip file. - snapshotZipFile android.OptionalPath +// This file defines how to capture cc modules into snapshot package. - // Whether the image supports VNDK extension modules. - supportsVndkExt bool - - // Implementation of the image interface specific to the image - // associated with this snapshot (e.g., specific to the vendor image, - // recovery image, etc.). - image SnapshotImage - - // Whether this singleton is for fake snapshot or not. - // Fake snapshot is a snapshot whose prebuilt binaries and headers are empty. - // It is much faster to generate, and can be used to inspect dependencies. - fake bool -} - -// Determine if a dir under source tree is an SoC-owned proprietary directory based -// on vendor snapshot configuration -// Examples: device/, vendor/ -func isVendorProprietaryPath(dir string, deviceConfig android.DeviceConfig) bool { - return VendorSnapshotSingleton().(*snapshotSingleton).image.isProprietaryPath(dir, deviceConfig) -} - -// Determine if a dir under source tree is an SoC-owned proprietary directory based -// on recovery snapshot configuration -// Examples: device/, vendor/ -func isRecoveryProprietaryPath(dir string, deviceConfig android.DeviceConfig) bool { - return RecoverySnapshotSingleton().(*snapshotSingleton).image.isProprietaryPath(dir, deviceConfig) -} - -func IsVendorProprietaryModule(ctx android.BaseModuleContext) bool { - // Any module in a vendor proprietary path is a vendor proprietary - // module. - if isVendorProprietaryPath(ctx.ModuleDir(), ctx.DeviceConfig()) { +// Checks if the target image would contain VNDK +func includeVndk(image snapshot.SnapshotImage) bool { + if image.ImageName() == snapshot.VendorSnapshotImageName { return true } - // However if the module is not in a vendor proprietary path, it may - // 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().(LinkableInterface); ok { - if c.ExcludeFromVendorSnapshot() { - return true - } - } - return false } -func isRecoveryProprietaryModule(ctx android.BaseModuleContext) bool { - - // Any module in a recovery proprietary path is a recovery proprietary - // module. - if isRecoveryProprietaryPath(ctx.ModuleDir(), ctx.DeviceConfig()) { +// Check if the module is VNDK private +func isPrivate(image snapshot.SnapshotImage, m LinkableInterface) bool { + if image.ImageName() == snapshot.VendorSnapshotImageName && m.IsVndkPrivate() { return true } - // However if the module is not in a recovery proprietary path, it may - // still be a recovery proprietary module. This happens for cc modules - // that are excluded from the recovery snapshot, and it means that the - // vendor has assumed control of the framework-provided module. + return false +} - if c, ok := ctx.Module().(LinkableInterface); ok { - if c.ExcludeFromRecoverySnapshot() { - return true - } +// Checks if target image supports VNDK Ext +func supportsVndkExt(image snapshot.SnapshotImage) bool { + if image.ImageName() == snapshot.VendorSnapshotImageName { + return true } return false } // Determines if the module is a candidate for snapshot. -func isSnapshotAware(cfg android.DeviceConfig, m LinkableInterface, inProprietaryPath bool, apexInfo android.ApexInfo, image SnapshotImage) bool { +func isSnapshotAware(cfg android.DeviceConfig, m LinkableInterface, inProprietaryPath bool, apexInfo android.ApexInfo, image snapshot.SnapshotImage) bool { if !m.Enabled() || m.HiddenFromMake() { return false } @@ -158,12 +63,12 @@ func isSnapshotAware(cfg android.DeviceConfig, m LinkableInterface, inProprietar } // skip proprietary modules, but (for the vendor snapshot only) // include all VNDK (static) - if inProprietaryPath && (!image.includeVndk() || !m.IsVndk()) { + if inProprietaryPath && (!includeVndk(image) || !m.IsVndk()) { return false } // If the module would be included based on its path, check to see if // the module is marked to be excluded. If so, skip it. - if image.excludeFromSnapshot(m) { + if image.ExcludeFromSnapshot(m) { return false } if m.Target().Os.Class != android.Device { @@ -173,7 +78,7 @@ func isSnapshotAware(cfg android.DeviceConfig, m LinkableInterface, inProprietar return false } // the module must be installed in target image - if !apexInfo.IsForPlatform() || m.IsSnapshotPrebuilt() || !image.inImage(m)() { + if !apexInfo.IsForPlatform() || m.IsSnapshotPrebuilt() || !image.InImage(m)() { return false } // skip kernel_headers which always depend on vendor @@ -203,13 +108,13 @@ func isSnapshotAware(cfg android.DeviceConfig, m LinkableInterface, inProprietar } } if sanitizable.Static() { - return sanitizable.OutputFile().Valid() && !image.private(m) + return sanitizable.OutputFile().Valid() && !isPrivate(image, m) } if sanitizable.Shared() || sanitizable.Rlib() { if !sanitizable.OutputFile().Valid() { return false } - if image.includeVndk() { + if includeVndk(image) { if !sanitizable.IsVndk() { return true } @@ -256,15 +161,9 @@ type snapshotJsonFlags struct { VintfFragments []string `json:",omitempty"` } -func (c *snapshotSingleton) GenerateBuildActions(ctx android.SingletonContext) { - if !c.image.shouldGenerateSnapshot(ctx) { - return - } - - var snapshotOutputs android.Paths - +var ccSnapshotAction snapshot.GenerateSnapshotAction = func(s snapshot.SnapshotSingleton, ctx android.SingletonContext, snapshotArchDir string) android.Paths { /* - Vendor snapshot zipped artifacts directory structure: + Vendor snapshot zipped artifacts directory structure for cc modules: {SNAPSHOT_ARCH}/ arch-{TARGET_ARCH}-{TARGET_ARCH_VARIANT}/ shared/ @@ -296,13 +195,7 @@ func (c *snapshotSingleton) GenerateBuildActions(ctx android.SingletonContext) { (header files of same directory structure with source tree) */ - snapshotDir := c.name + "-snapshot" - if c.fake { - // If this is a fake snapshot singleton, place all files under fake/ subdirectory to avoid - // collision with real snapshot files - snapshotDir = filepath.Join("fake", snapshotDir) - } - snapshotArchDir := filepath.Join(snapshotDir, ctx.DeviceConfig().DeviceArch()) + var snapshotOutputs android.Paths includeDir := filepath.Join(snapshotArchDir, "include") configsDir := filepath.Join(snapshotArchDir, "configs") @@ -317,9 +210,9 @@ func (c *snapshotSingleton) GenerateBuildActions(ctx android.SingletonContext) { if fake { // All prebuilt binaries and headers are installed by copyFile function. This makes a fake // snapshot just touch prebuilts and headers, rather than installing real files. - return writeStringToFileRule(ctx, "", out) + return snapshot.WriteStringToFileRule(ctx, "", out) } else { - return copyFileRule(ctx, path, out) + return snapshot.CopyFileRule(pctx, ctx, path, out) } } @@ -337,7 +230,7 @@ func (c *snapshotSingleton) GenerateBuildActions(ctx android.SingletonContext) { // Common properties among snapshots. prop.ModuleName = ctx.ModuleName(m) - if c.supportsVndkExt && m.IsVndkExt() { + if supportsVndkExt(s.Image) && m.IsVndkExt() { // vndk exts are installed to /vendor/lib(64)?/vndk(-sp)? if m.IsVndkSp() { prop.RelativeInstallPath = "vndk-sp" @@ -457,7 +350,7 @@ func (c *snapshotSingleton) GenerateBuildActions(ctx android.SingletonContext) { ctx.Errorf("json marshal to %q failed: %#v", propOut, err) return nil } - ret = append(ret, writeStringToFileRule(ctx, string(j), propOut)) + ret = append(ret, snapshot.WriteStringToFileRule(ctx, string(j), propOut)) return ret } @@ -469,10 +362,10 @@ func (c *snapshotSingleton) GenerateBuildActions(ctx android.SingletonContext) { } moduleDir := ctx.ModuleDir(module) - inProprietaryPath := c.image.isProprietaryPath(moduleDir, ctx.DeviceConfig()) + inProprietaryPath := s.Image.IsProprietaryPath(moduleDir, ctx.DeviceConfig()) apexInfo := ctx.ModuleProvider(module, android.ApexInfoProvider).(android.ApexInfo) - if c.image.excludeFromSnapshot(m) { + if s.Image.ExcludeFromSnapshot(m) { if inProprietaryPath { // Error: exclude_from_vendor_snapshot applies // to framework-path modules only. @@ -481,7 +374,7 @@ func (c *snapshotSingleton) GenerateBuildActions(ctx android.SingletonContext) { } } - if !isSnapshotAware(ctx.DeviceConfig(), m, inProprietaryPath, apexInfo, c.image) { + if !isSnapshotAware(ctx.DeviceConfig(), m, inProprietaryPath, apexInfo, s.Image) { return } @@ -489,8 +382,8 @@ func (c *snapshotSingleton) GenerateBuildActions(ctx android.SingletonContext) { // list, we will still include the module as if it was a fake module. // The reason is that soong needs all the dependencies to be present, even // if they are not using during the build. - installAsFake := c.fake - if c.image.excludeFromDirectedSnapshot(ctx.DeviceConfig(), m.BaseModuleName()) { + installAsFake := s.Fake + if s.Image.ExcludeFromDirectedSnapshot(ctx.DeviceConfig(), m.BaseModuleName()) { installAsFake = true } @@ -514,47 +407,12 @@ func (c *snapshotSingleton) GenerateBuildActions(ctx android.SingletonContext) { // install all headers after removing duplicates for _, header := range android.FirstUniquePaths(headers) { - snapshotOutputs = append(snapshotOutputs, copyFile(ctx, header, filepath.Join(includeDir, header.String()), c.fake)) + snapshotOutputs = append(snapshotOutputs, copyFile(ctx, header, filepath.Join(includeDir, header.String()), s.Fake)) } - // All artifacts are ready. Sort them to normalize ninja and then zip. - sort.Slice(snapshotOutputs, func(i, j int) bool { - return snapshotOutputs[i].String() < snapshotOutputs[j].String() - }) - - zipPath := android.PathForOutput( - ctx, - snapshotDir, - c.name+"-"+ctx.Config().DeviceName()+".zip") - zipRule := android.NewRuleBuilder(pctx, ctx) - - // filenames in rspfile from FlagWithRspFileInputList might be single-quoted. Remove it with tr - snapshotOutputList := android.PathForOutput( - ctx, - snapshotDir, - c.name+"-"+ctx.Config().DeviceName()+"_list") - rspFile := snapshotOutputList.ReplaceExtension(ctx, "rsp") - zipRule.Command(). - Text("tr"). - FlagWithArg("-d ", "\\'"). - FlagWithRspFileInputList("< ", rspFile, snapshotOutputs). - FlagWithOutput("> ", snapshotOutputList) - - zipRule.Temporary(snapshotOutputList) - - zipRule.Command(). - BuiltTool("soong_zip"). - FlagWithOutput("-o ", zipPath). - FlagWithArg("-C ", android.PathForOutput(ctx, snapshotDir).String()). - FlagWithInput("-l ", snapshotOutputList) - - zipRule.Build(zipPath.String(), c.name+" snapshot "+zipPath.String()) - zipRule.DeleteTemporaryFiles() - c.snapshotZipFile = android.OptionalPathForPath(zipPath) + return snapshotOutputs } -func (c *snapshotSingleton) MakeVars(ctx android.MakeVarsContext) { - ctx.Strict( - c.makeVar, - c.snapshotZipFile.String()) +func init() { + snapshot.RegisterSnapshotAction(ccSnapshotAction) } diff --git a/cc/vndk.go b/cc/vndk.go index 499d4282c..1ae79de05 100644 --- a/cc/vndk.go +++ b/cc/vndk.go @@ -25,6 +25,7 @@ import ( "android/soong/android" "android/soong/cc/config" "android/soong/etc" + "android/soong/snapshot" "github.com/google/blueprint" ) @@ -698,7 +699,7 @@ func (c *vndkSnapshotSingleton) GenerateBuildActions(ctx android.SingletonContex libPath := m.outputFile.Path() snapshotLibOut := filepath.Join(snapshotArchDir, targetArch, "shared", vndkType, libPath.Base()) - ret = append(ret, copyFileRule(ctx, libPath, snapshotLibOut)) + ret = append(ret, snapshot.CopyFileRule(pctx, ctx, libPath, snapshotLibOut)) if ctx.Config().VndkSnapshotBuildArtifacts() { prop := struct { @@ -720,7 +721,7 @@ func (c *vndkSnapshotSingleton) GenerateBuildActions(ctx android.SingletonContex ctx.Errorf("json marshal to %q failed: %#v", propOut, err) return nil, false } - ret = append(ret, writeStringToFileRule(ctx, string(j), propOut)) + ret = append(ret, snapshot.WriteStringToFileRule(ctx, string(j), propOut)) } return ret, true } @@ -778,8 +779,8 @@ func (c *vndkSnapshotSingleton) GenerateBuildActions(ctx android.SingletonContex // install all headers after removing duplicates for _, header := range android.FirstUniquePaths(headers) { - snapshotOutputs = append(snapshotOutputs, copyFileRule( - ctx, header, filepath.Join(includeDir, header.String()))) + snapshotOutputs = append(snapshotOutputs, snapshot.CopyFileRule( + pctx, ctx, header, filepath.Join(includeDir, header.String()))) } // install *.libraries.txt except vndkcorevariant.libraries.txt @@ -788,8 +789,8 @@ func (c *vndkSnapshotSingleton) GenerateBuildActions(ctx android.SingletonContex if !ok || !m.Enabled() || m.Name() == vndkUsingCoreVariantLibrariesTxt { return } - snapshotOutputs = append(snapshotOutputs, copyFileRule( - ctx, m.OutputFile(), filepath.Join(configsDir, m.Name()))) + snapshotOutputs = append(snapshotOutputs, snapshot.CopyFileRule( + pctx, ctx, m.OutputFile(), filepath.Join(configsDir, m.Name()))) }) /* |