Deprecate Snapshot build
Existing snapshot code will no longer work from VNDK deprecation, but it
can give confusion to users if we keep code for the snapshot - and it
adds complexity on existing code while it is not in use. This change
removes all snapshot definition except host snapshot and its usage.
Bug: 330100430
Bug: 332986564
Test: AOSP CF build succeeded
Change-Id: Ieb6fa43d5e38315c662ce997bc305b744b367c24
diff --git a/snapshot/Android.bp b/snapshot/Android.bp
index 3354993..6cb318e 100644
--- a/snapshot/Android.bp
+++ b/snapshot/Android.bp
@@ -16,15 +16,11 @@
srcs: [
"host_fake_snapshot.go",
"host_snapshot.go",
- "recovery_snapshot.go",
- "snapshot.go",
"snapshot_base.go",
"util.go",
- "vendor_snapshot.go",
],
testSrcs: [
"host_test.go",
- "test.go",
],
pluginFor: ["soong_build"],
}
diff --git a/snapshot/recovery_snapshot.go b/snapshot/recovery_snapshot.go
deleted file mode 100644
index ab114b4..0000000
--- a/snapshot/recovery_snapshot.go
+++ /dev/null
@@ -1,132 +0,0 @@
-// Copyright 2021 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-package snapshot
-
-import "android/soong/android"
-
-// Interface for modules which can be captured in the recovery snapshot.
-type RecoverySnapshotModuleInterface interface {
- SnapshotModuleInterfaceBase
- InRecovery() bool
- ExcludeFromRecoverySnapshot() bool
-}
-
-func RecoverySnapshotSingleton() android.Singleton {
- return &SnapshotSingleton{
- "recovery", // name
- "SOONG_RECOVERY_SNAPSHOT_ZIP", // makeVar
- android.OptionalPath{}, // snapshotZipFile
- RecoverySnapshotImageSingleton, // Image
- false, // Fake
- }
-}
-
-// 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 IsRecoveryProprietaryModule(ctx android.BaseModuleContext) bool {
-
- // Any module in a recovery proprietary path is a recovery proprietary
- // module.
- if isRecoveryProprietaryPath(ctx.ModuleDir(), ctx.DeviceConfig()) {
- 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.
-
- if c, ok := ctx.Module().(RecoverySnapshotModuleInterface); ok {
- if c.ExcludeFromRecoverySnapshot() {
- return true
- }
- }
-
- return false
-}
-
-var RecoverySnapshotImageName = "recovery"
-
-type RecoverySnapshotImage struct{}
-
-func (RecoverySnapshotImage) Init(ctx android.RegistrationContext) {
- ctx.RegisterParallelSingletonType("recovery-snapshot", RecoverySnapshotSingleton)
-}
-
-func (RecoverySnapshotImage) RegisterAdditionalModule(ctx android.RegistrationContext, name string, factory android.ModuleFactory) {
- ctx.RegisterModuleType(name, factory)
-}
-
-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 SnapshotModuleInterfaceBase) func() bool {
- r, ok := m.(RecoverySnapshotModuleInterface)
-
- if !ok {
- // This module does not support recovery snapshot
- return func() bool { return false }
- }
- return r.InRecovery
-}
-
-func (RecoverySnapshotImage) IsProprietaryPath(dir string, deviceConfig android.DeviceConfig) bool {
- return isDirectoryExcluded(dir, deviceConfig.RecoverySnapshotDirsExcludedMap(), deviceConfig.RecoverySnapshotDirsIncludedMap())
-}
-
-func (RecoverySnapshotImage) ExcludeFromSnapshot(m SnapshotModuleInterfaceBase) bool {
- r, ok := m.(RecoverySnapshotModuleInterface)
-
- if !ok {
- // This module does not support recovery snapshot
- return true
- }
- return r.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) ImageName() string {
- return RecoverySnapshotImageName
-}
-
-var RecoverySnapshotImageSingleton RecoverySnapshotImage
-
-func init() {
- RecoverySnapshotImageSingleton.Init(android.InitRegistrationContext)
-}
diff --git a/snapshot/snapshot.go b/snapshot/snapshot.go
deleted file mode 100644
index c95a537..0000000
--- a/snapshot/snapshot.go
+++ /dev/null
@@ -1,146 +0,0 @@
-// Copyright 2021 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-package snapshot
-
-import (
- "path/filepath"
- "sort"
-
- "android/soong/android"
-)
-
-// This file contains singletons to capture snapshots. This singleton will generate snapshot of each target
-// image, and capturing snapshot module will be delegated to each module which implements GenerateSnapshotAction
-// function and register with RegisterSnapshotAction.
-
-var pctx = android.NewPackageContext("android/soong/snapshot")
-
-func init() {
- pctx.Import("android/soong/android")
-}
-
-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
-
- // 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
-}
-
-// The output files to be included in the snapshot.
-type SnapshotPaths struct {
- // All files to be included in the snapshot
- OutputFiles android.Paths
-
- // Notice files of the snapshot output files
- NoticeFiles android.Paths
-}
-
-// Interface of function to capture snapshot from each module
-// Returns snapshot ouputs and notice files.
-type GenerateSnapshotAction func(snapshot SnapshotSingleton, ctx android.SingletonContext, snapshotArchDir string) SnapshotPaths
-
-var snapshotActionList []GenerateSnapshotAction
-
-// Register GenerateSnapshotAction function so it can be called while generating snapshot
-func RegisterSnapshotAction(x GenerateSnapshotAction) {
- snapshotActionList = append(snapshotActionList, x)
-}
-
-func (c *SnapshotSingleton) GenerateBuildActions(ctx android.SingletonContext) {
- if !c.Image.shouldGenerateSnapshot(ctx) {
- return
- }
-
- var snapshotOutputs android.Paths
-
- // Snapshot zipped artifacts will be captured under {SNAPSHOT_ARCH} directory
-
- 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())
- noticeDir := filepath.Join(snapshotArchDir, "NOTICE_FILES")
- installedNotices := make(map[string]bool)
-
- for _, f := range snapshotActionList {
- snapshotPaths := f(*c, ctx, snapshotArchDir)
- snapshotOutputs = append(snapshotOutputs, snapshotPaths.OutputFiles...)
- for _, notice := range snapshotPaths.NoticeFiles {
- if _, ok := installedNotices[notice.String()]; !ok {
- installedNotices[notice.String()] = true
- snapshotOutputs = append(snapshotOutputs, CopyFileRule(
- pctx, ctx, notice, filepath.Join(noticeDir, notice.String())))
- }
- }
- }
-
- // 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)
-}
-
-func (c *SnapshotSingleton) MakeVars(ctx android.MakeVarsContext) {
- ctx.Strict(
- c.makeVar,
- c.snapshotZipFile.String())
-}
diff --git a/snapshot/snapshot_base.go b/snapshot/snapshot_base.go
index fb4ee0c..6bf3c87 100644
--- a/snapshot/snapshot_base.go
+++ b/snapshot/snapshot_base.go
@@ -15,92 +15,12 @@
import (
"android/soong/android"
- "path/filepath"
)
-// Interface for modules which can be captured in the snapshot.
-type SnapshotModuleInterfaceBase interface{}
+var pctx = android.NewPackageContext("android/soong/snapshot")
-// Defines the specifics of different images to which the snapshot process is applicable, e.g.,
-// vendor, recovery, ramdisk.
-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 SnapshotModuleInterfaceBase) func() 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 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 SnapshotModuleInterfaceBase) 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
-
- // Returns target image name
- ImageName() string
-}
-
-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 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 init() {
+ pctx.Import("android/soong/android")
}
// This is to be saved as .json files, which is for development/vendor_snapshot/update.py.
diff --git a/snapshot/test.go b/snapshot/test.go
deleted file mode 100644
index 346af2b..0000000
--- a/snapshot/test.go
+++ /dev/null
@@ -1,24 +0,0 @@
-// Copyright 2021 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package snapshot
-
-import (
- "os"
- "testing"
-)
-
-func TestMain(m *testing.M) {
- os.Exit(m.Run())
-}
diff --git a/snapshot/vendor_snapshot.go b/snapshot/vendor_snapshot.go
deleted file mode 100644
index 3e5f546..0000000
--- a/snapshot/vendor_snapshot.go
+++ /dev/null
@@ -1,143 +0,0 @@
-// Copyright 2021 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-package snapshot
-
-import "android/soong/android"
-
-// Interface for modules which can be captured in the vendor snapshot.
-type VendorSnapshotModuleInterface interface {
- SnapshotModuleInterfaceBase
- InVendor() bool
- ExcludeFromVendorSnapshot() bool
-}
-
-func VendorSnapshotSingleton() android.Singleton {
- return &SnapshotSingleton{
- "vendor", // name
- "SOONG_VENDOR_SNAPSHOT_ZIP", // makeVar
- android.OptionalPath{}, // snapshotZipFile
- VendorSnapshotImageSingleton, // Image
- false, // Fake
- }
-}
-
-func VendorFakeSnapshotSingleton() android.Singleton {
- return &SnapshotSingleton{
- "vendor", // name
- "SOONG_VENDOR_FAKE_SNAPSHOT_ZIP", // makeVar
- android.OptionalPath{}, // snapshotZipFile
- VendorSnapshotImageSingleton, // Image
- true, // Fake
- }
-}
-
-// 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)
-}
-
-func IsVendorProprietaryModule(ctx android.BaseModuleContext) bool {
- // Any module in a vendor proprietary path is a vendor proprietary
- // module.
- if isVendorProprietaryPath(ctx.ModuleDir(), ctx.DeviceConfig()) {
- 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().(VendorSnapshotModuleInterface); ok {
- if c.ExcludeFromVendorSnapshot() {
- return true
- }
- }
-
- return false
-}
-
-var VendorSnapshotImageName = "vendor"
-
-type VendorSnapshotImage struct{}
-
-func (VendorSnapshotImage) Init(ctx android.RegistrationContext) {
- ctx.RegisterParallelSingletonType("vendor-snapshot", VendorSnapshotSingleton)
- ctx.RegisterParallelSingletonType("vendor-fake-snapshot", VendorFakeSnapshotSingleton)
-}
-
-func (VendorSnapshotImage) RegisterAdditionalModule(ctx android.RegistrationContext, name string, factory android.ModuleFactory) {
- ctx.RegisterModuleType(name, factory)
-}
-
-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 SnapshotModuleInterfaceBase) func() bool {
- v, ok := m.(VendorSnapshotModuleInterface)
-
- if !ok {
- // This module does not support Vendor snapshot
- return func() bool { return false }
- }
-
- return v.InVendor
-}
-
-func (VendorSnapshotImage) IsProprietaryPath(dir string, deviceConfig android.DeviceConfig) bool {
- return isDirectoryExcluded(dir, deviceConfig.VendorSnapshotDirsExcludedMap(), deviceConfig.VendorSnapshotDirsIncludedMap())
-}
-
-func (VendorSnapshotImage) ExcludeFromSnapshot(m SnapshotModuleInterfaceBase) bool {
- v, ok := m.(VendorSnapshotModuleInterface)
-
- if !ok {
- // This module does not support Vendor snapshot
- return true
- }
-
- return v.ExcludeFromVendorSnapshot()
-}
-
-func (VendorSnapshotImage) IsUsingSnapshot(cfg android.DeviceConfig) bool {
- vndkVersion := cfg.VndkVersion()
- return vndkVersion != "current" && vndkVersion != ""
-}
-
-func (VendorSnapshotImage) TargetSnapshotVersion(cfg android.DeviceConfig) string {
- return cfg.VndkVersion()
-}
-
-// 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 (VendorSnapshotImage) ImageName() string {
- return VendorSnapshotImageName
-}
-
-var VendorSnapshotImageSingleton VendorSnapshotImage
-
-func init() {
- VendorSnapshotImageSingleton.Init(android.InitRegistrationContext)
-}