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
This commit is contained in:
Kiyoung Kim
2024-04-04 09:56:15 +09:00
parent 4caca1d797
commit 37693d0a27
37 changed files with 85 additions and 3853 deletions

View File

@@ -9,16 +9,13 @@ bootstrap_go_package {
"blueprint",
"soong",
"soong-android",
"soong-snapshot",
],
srcs: [
"prebuilt_etc.go",
"snapshot_etc.go",
"install_symlink.go",
],
testSrcs: [
"prebuilt_etc_test.go",
"snapshot_etc_test.go",
"install_symlink_test.go",
],
pluginFor: ["soong_build"],

View File

@@ -28,7 +28,6 @@ package etc
// various `prebuilt_*` mutators.
import (
"encoding/json"
"fmt"
"path/filepath"
"strings"
@@ -36,7 +35,6 @@ import (
"github.com/google/blueprint/proptools"
"android/soong/android"
"android/soong/snapshot"
)
var pctx = android.NewPackageContext("android/soong/etc")
@@ -46,7 +44,6 @@ var pctx = android.NewPackageContext("android/soong/etc")
func init() {
pctx.Import("android/soong/android")
RegisterPrebuiltEtcBuildComponents(android.InitRegistrationContext)
snapshot.RegisterSnapshotAction(generatePrebuiltSnapshot)
}
func RegisterPrebuiltEtcBuildComponents(ctx android.RegistrationContext) {
@@ -142,9 +139,6 @@ type PrebuiltEtc struct {
android.ModuleBase
android.DefaultableModuleBase
snapshot.VendorSnapshotModuleInterface
snapshot.RecoverySnapshotModuleInterface
properties prebuiltEtcProperties
subdirProperties prebuiltSubdirProperties
@@ -305,14 +299,6 @@ func (p *PrebuiltEtc) InVendor() bool {
return p.ModuleBase.InstallInVendor()
}
func (p *PrebuiltEtc) ExcludeFromVendorSnapshot() bool {
return false
}
func (p *PrebuiltEtc) ExcludeFromRecoverySnapshot() bool {
return false
}
func (p *PrebuiltEtc) installBaseDir(ctx android.ModuleContext) string {
// If soc install dir was specified and SOC specific is set, set the installDirPath to the
// specified socInstallDirBase.
@@ -686,121 +672,3 @@ func PrebuiltRFSAFactory() android.Module {
android.InitDefaultableModule(module)
return module
}
// Copy file into the snapshot
func copyFile(ctx android.SingletonContext, path android.Path, out string, fake bool) android.OutputPath {
if fake {
// Create empty file instead for the fake snapshot
return snapshot.WriteStringToFileRule(ctx, "", out)
} else {
return snapshot.CopyFileRule(pctx, ctx, path, out)
}
}
// Check if the module is target of the snapshot
func isSnapshotAware(ctx android.SingletonContext, m *PrebuiltEtc, image snapshot.SnapshotImage) bool {
if !m.Enabled() {
return false
}
// Skip if the module is not included in the image
if !image.InImage(m)() {
return false
}
// When android/prebuilt.go selects between source and prebuilt, it sets
// HideFromMake on the other one to avoid duplicate install rules in make.
if m.IsHideFromMake() {
return false
}
// There are some prebuilt_etc module with multiple definition of same name.
// Check if the target would be included from the build
if !m.ExportedToMake() {
return false
}
// Skip if the module is in the predefined path list to skip
if image.IsProprietaryPath(ctx.ModuleDir(m), ctx.DeviceConfig()) {
return false
}
// Skip if the module should be excluded
if image.ExcludeFromSnapshot(m) || image.ExcludeFromDirectedSnapshot(ctx.DeviceConfig(), m.BaseModuleName()) {
return false
}
// Skip from other exceptional cases
if m.Target().Os.Class != android.Device {
return false
}
if m.Target().NativeBridge == android.NativeBridgeEnabled {
return false
}
return true
}
func generatePrebuiltSnapshot(s snapshot.SnapshotSingleton, ctx android.SingletonContext, snapshotArchDir string) snapshot.SnapshotPaths {
/*
Snapshot zipped artifacts directory structure for etc modules:
{SNAPSHOT_ARCH}/
arch-{TARGET_ARCH}-{TARGET_ARCH_VARIANT}/
etc/
(prebuilt etc files)
arch-{TARGET_2ND_ARCH}-{TARGET_2ND_ARCH_VARIANT}/
etc/
(prebuilt etc files)
NOTICE_FILES/
(notice files)
*/
var snapshotOutputs android.Paths
var snapshotNotices android.Paths
installedNotices := make(map[string]bool)
ctx.VisitAllModules(func(module android.Module) {
m, ok := module.(*PrebuiltEtc)
if !ok {
return
}
if !isSnapshotAware(ctx, m, s.Image) {
return
}
targetArch := "arch-" + m.Target().Arch.ArchType.String()
snapshotLibOut := filepath.Join(snapshotArchDir, targetArch, "etc", m.BaseModuleName())
outputs, _ := m.OutputFiles("")
for _, output := range outputs {
cp := copyFile(ctx, output, snapshotLibOut, s.Fake)
snapshotOutputs = append(snapshotOutputs, cp)
}
prop := snapshot.SnapshotJsonFlags{}
propOut := snapshotLibOut + ".json"
prop.InitBaseSnapshotProps(m)
prop.RelativeInstallPath = m.SubDir()
if m.properties.Filename != nil {
prop.Filename = *m.properties.Filename
}
j, err := json.Marshal(prop)
if err != nil {
ctx.Errorf("json marshal to %q failed: %#v", propOut, err)
return
}
snapshotOutputs = append(snapshotOutputs, snapshot.WriteStringToFileRule(ctx, string(j), propOut))
for _, notice := range m.EffectiveLicenseFiles() {
if _, ok := installedNotices[notice.String()]; !ok {
installedNotices[notice.String()] = true
snapshotNotices = append(snapshotNotices, notice)
}
}
})
return snapshot.SnapshotPaths{OutputFiles: snapshotOutputs, NoticeFiles: snapshotNotices}
}

View File

@@ -1,186 +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 etc
// This file implements snapshot module of 'prebuilt_etc' type
// 'snapshot_etc' module defines android.PrebuiltInterface so it can be handled
// as prebuilt of 'prebuilt_etc' type.
// Properties of 'snapshot_etc' follows properties from snapshotJsonFlags type
import (
"android/soong/android"
"fmt"
"strings"
"github.com/google/blueprint"
"github.com/google/blueprint/proptools"
)
func RegisterSnapshotEtcModule(ctx android.RegistrationContext) {
ctx.RegisterModuleType("snapshot_etc", SnapshotEtcFactory)
}
func init() {
RegisterSnapshotEtcModule(android.InitRegistrationContext)
}
// snapshot_etc is a prebuilt module type to be installed under etc which is auto-generated by
// development/vendor_snapshot/update.py. This module will override prebuilt_etc module with same
// name when 'prefer' property is true.
func SnapshotEtcFactory() android.Module {
module := &SnapshotEtc{}
module.AddProperties(&module.properties)
var srcsSupplier = func(_ android.BaseModuleContext, prebuilt android.Module) []string {
s, ok := prebuilt.(*SnapshotEtc)
if !ok || s.properties.Src == nil {
return []string{}
}
return []string{*s.properties.Src}
}
android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
android.InitPrebuiltModuleWithSrcSupplier(module, srcsSupplier, "src")
return module
}
type snapshotEtcProperties struct {
Src *string `android:"path,arch_variant"` // Source of snapshot_etc file
Filename *string `android:"arch_variant"` // Target file name when it differs from module name
Relative_install_path *string `android:"arch_variant"` // Relative install path when it should be installed subdirectory of etc
}
type SnapshotEtc struct {
android.ModuleBase
prebuilt android.Prebuilt
properties snapshotEtcProperties
outputFilePath android.OutputPath
installDirPath android.InstallPath
}
func (s *SnapshotEtc) Prebuilt() *android.Prebuilt {
return &s.prebuilt
}
func (s *SnapshotEtc) Name() string {
return s.prebuilt.Name(s.BaseModuleName())
}
func (s *SnapshotEtc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
if s.properties.Src == nil {
ctx.PropertyErrorf("src", "missing prebuilt source file")
return
}
sourceFilePath := s.prebuilt.SingleSourcePath(ctx)
// Determine the output file basename.
// If Filename is set, use the name specified by the property.
// Otherwise use the module name.
filename := proptools.String(s.properties.Filename)
if filename == "" {
filename = ctx.ModuleName()
}
s.outputFilePath = android.PathForModuleOut(ctx, filename).OutputPath
if strings.Contains(filename, "/") {
ctx.PropertyErrorf("filename", "filename cannot contain separator '/'")
return
}
subDir := ""
if s.properties.Relative_install_path != nil {
subDir = *s.properties.Relative_install_path
}
s.installDirPath = android.PathForModuleInstall(ctx, "etc", subDir)
// This ensures that outputFilePath has the correct name for others to
// use, as the source file may have a different name.
ctx.Build(pctx, android.BuildParams{
Rule: android.Cp,
Input: sourceFilePath,
Output: s.outputFilePath,
Description: "Install snapshot etc module " + s.BaseModuleName(),
})
ctx.InstallFile(s.installDirPath, s.outputFilePath.Base(), sourceFilePath)
}
func (p *SnapshotEtc) AndroidMkEntries() []android.AndroidMkEntries {
return []android.AndroidMkEntries{{
Class: "ETC",
OutputFile: android.OptionalPathForPath(p.outputFilePath),
ExtraEntries: []android.AndroidMkExtraEntriesFunc{
func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
entries.SetString("LOCAL_MODULE_TAGS", "optional")
entries.SetString("LOCAL_MODULE_PATH", p.installDirPath.String())
entries.SetString("LOCAL_INSTALLED_MODULE_STEM", p.outputFilePath.Base())
},
},
}}
}
type snapshotEtcDependencyTag struct {
blueprint.DependencyTag
}
var tag = snapshotEtcDependencyTag{}
func (s *SnapshotEtc) CoreVariantNeeded(ctx android.BaseModuleContext) bool {
return !s.ModuleBase.InstallInRecovery() && !s.ModuleBase.InstallInRamdisk() &&
!s.ModuleBase.InstallInVendorRamdisk() && !s.ModuleBase.InstallInDebugRamdisk()
}
func (p *SnapshotEtc) RamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
return p.ModuleBase.InstallInRamdisk()
}
func (p *SnapshotEtc) VendorRamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
return p.ModuleBase.InstallInVendorRamdisk()
}
func (p *SnapshotEtc) DebugRamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
return p.ModuleBase.InstallInDebugRamdisk()
}
func (p *SnapshotEtc) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool {
return p.ModuleBase.InstallInRecovery()
}
func (p *SnapshotEtc) ExtraImageVariations(ctx android.BaseModuleContext) []string {
return nil
}
func (p *SnapshotEtc) SetImageVariation(ctx android.BaseModuleContext, variation string, module android.Module) {
}
func (p *SnapshotEtc) ImageMutatorBegin(ctx android.BaseModuleContext) {}
func (p *SnapshotEtc) OutputFiles(tag string) (android.Paths, error) {
switch tag {
case "":
return android.Paths{p.outputFilePath}, nil
default:
return nil, fmt.Errorf("unsupported module reference tag %q", tag)
}
}
var _ android.PrebuiltInterface = (*SnapshotEtc)(nil)
var _ android.ImageInterface = (*SnapshotEtc)(nil)
var _ android.OutputFileProducer = (*SnapshotEtc)(nil)

View File

@@ -1,185 +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 etc
import (
"android/soong/android"
"testing"
"github.com/google/blueprint"
)
var registerSourceModule = func(ctx android.RegistrationContext) {
ctx.RegisterModuleType("source", newSourceModule)
}
type sourceModuleProperties struct {
Deps []string `android:"path,arch_variant"`
}
type sourceModule struct {
android.ModuleBase
android.OverridableModuleBase
properties sourceModuleProperties
dependsOnSourceModule, dependsOnPrebuiltModule bool
deps android.Paths
src android.Path
}
func newSourceModule() android.Module {
m := &sourceModule{}
m.AddProperties(&m.properties)
android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibFirst)
android.InitOverridableModule(m, nil)
return m
}
func (s *sourceModule) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
// s.properties.Deps are annotated with android:path, so they are
// automatically added to the dependency by pathDeps mutator
}
func (s *sourceModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
s.deps = android.PathsForModuleSrc(ctx, s.properties.Deps)
s.src = android.PathForModuleSrc(ctx, "source_file")
}
func (s *sourceModule) Srcs() android.Paths {
return android.Paths{s.src}
}
var prepareForSnapshotEtcTest = android.GroupFixturePreparers(
android.PrepareForTestWithArchMutator,
android.PrepareForTestWithPrebuilts,
PrepareForTestWithPrebuiltEtc,
android.FixtureRegisterWithContext(RegisterSnapshotEtcModule),
android.FixtureRegisterWithContext(registerSourceModule),
android.FixtureMergeMockFs(android.MockFS{
"foo.conf": nil,
"bar.conf": nil,
}),
)
func TestSnapshotWithFilename(t *testing.T) {
var androidBp = `
snapshot_etc {
name: "etc_module",
src: "foo.conf",
filename: "bar.conf",
}
`
result := prepareForSnapshotEtcTest.RunTestWithBp(t, androidBp)
for _, variant := range result.ModuleVariantsForTests("etc_module") {
module := result.ModuleForTests("etc_module", variant)
s, ok := module.Module().(*SnapshotEtc)
if !ok {
t.Errorf("Expected snapshot_etc module type")
}
if s.outputFilePath.Base() != "bar.conf" {
t.Errorf("Output file path does not match with specified filename")
}
}
}
func TestSnapshotEtcWithOrigin(t *testing.T) {
var androidBp = `
prebuilt_etc {
name: "etc_module",
src: "foo.conf",
}
snapshot_etc {
name: "etc_module",
src: "bar.conf",
}
source {
name: "source",
deps: [":etc_module"],
}
`
result := prepareForSnapshotEtcTest.RunTestWithBp(t, androidBp)
for _, variant := range result.ModuleVariantsForTests("source") {
source := result.ModuleForTests("source", variant)
result.VisitDirectDeps(source.Module(), func(m blueprint.Module) {
if _, ok := m.(*PrebuiltEtc); !ok {
t.Errorf("Original prebuilt_etc module expected.")
}
})
}
}
func TestSnapshotEtcWithOriginAndPrefer(t *testing.T) {
var androidBp = `
prebuilt_etc {
name: "etc_module",
src: "foo.conf",
}
snapshot_etc {
name: "etc_module",
src: "bar.conf",
prefer: true,
}
source {
name: "source",
deps: [":etc_module"],
}
`
result := prepareForSnapshotEtcTest.RunTestWithBp(t, androidBp)
for _, variant := range result.ModuleVariantsForTests("source") {
source := result.ModuleForTests("source", variant)
result.VisitDirectDeps(source.Module(), func(m blueprint.Module) {
if _, ok := m.(*SnapshotEtc); !ok {
t.Errorf("Preferred snapshot_etc module expected.")
}
})
}
}
func TestSnapshotEtcWithoutOrigin(t *testing.T) {
var androidBp = `
snapshot_etc {
name: "etc_module",
src: "bar.conf",
}
source {
name: "source",
deps: [":etc_module"],
}
`
result := prepareForSnapshotEtcTest.RunTestWithBp(t, androidBp)
for _, variant := range result.ModuleVariantsForTests("source") {
source := result.ModuleForTests("source", variant)
result.VisitDirectDeps(source.Module(), func(m blueprint.Module) {
if _, ok := m.(*SnapshotEtc); !ok {
t.Errorf("Only source snapshot_etc module expected.")
}
})
}
}