blob: 4a14f2e03e53dd94966db1580bf491811e5665d9 [file] [log] [blame]
Kiyoung Kim48f37782021-07-07 12:42:39 +09001// Copyright 2021 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14package snapshot
15
16import (
17 "android/soong/android"
18 "path/filepath"
19)
20
21// Interface for modules which can be captured in the snapshot.
22type SnapshotModuleInterfaceBase interface{}
23
24// Defines the specifics of different images to which the snapshot process is applicable, e.g.,
25// vendor, recovery, ramdisk.
26type SnapshotImage interface {
27 // Returns true if a snapshot should be generated for this image.
28 shouldGenerateSnapshot(ctx android.SingletonContext) bool
29
30 // Function that returns true if the module is included in this image.
31 // Using a function return instead of a value to prevent early
32 // evalution of a function that may be not be defined.
33 InImage(m SnapshotModuleInterfaceBase) func() bool
34
35 // Returns true if a dir under source tree is an SoC-owned proprietary
36 // directory, such as device/, vendor/, etc.
37 //
38 // For a given snapshot (e.g., vendor, recovery, etc.) if
39 // isProprietaryPath(dir, deviceConfig) returns true, then the module in dir
40 // will be built from sources.
41 IsProprietaryPath(dir string, deviceConfig android.DeviceConfig) bool
42
43 // Whether a given module has been explicitly excluded from the
44 // snapshot, e.g., using the exclude_from_vendor_snapshot or
45 // exclude_from_recovery_snapshot properties.
46 ExcludeFromSnapshot(m SnapshotModuleInterfaceBase) bool
47
48 // Returns true if the build is using a snapshot for this image.
49 IsUsingSnapshot(cfg android.DeviceConfig) bool
50
51 // Returns a version of which the snapshot should be used in this target.
52 // This will only be meaningful when isUsingSnapshot is true.
53 TargetSnapshotVersion(cfg android.DeviceConfig) string
54
55 // Whether to exclude a given module from the directed snapshot or not.
56 // If the makefile variable DIRECTED_{IMAGE}_SNAPSHOT is true, directed snapshot is turned on,
57 // and only modules listed in {IMAGE}_SNAPSHOT_MODULES will be captured.
58 ExcludeFromDirectedSnapshot(cfg android.DeviceConfig, name string) bool
59
60 // Returns target image name
61 ImageName() string
62}
63
64type directoryMap map[string]bool
65
66var (
67 // Modules under following directories are ignored. They are OEM's and vendor's
68 // proprietary modules(device/, kernel/, vendor/, and hardware/).
69 defaultDirectoryExcludedMap = directoryMap{
70 "device": true,
71 "hardware": true,
72 "kernel": true,
73 "vendor": true,
74 }
75
76 // Modules under following directories are included as they are in AOSP,
77 // although hardware/ and kernel/ are normally for vendor's own.
78 defaultDirectoryIncludedMap = directoryMap{
79 "kernel/configs": true,
80 "kernel/prebuilts": true,
81 "kernel/tests": true,
82 "hardware/interfaces": true,
83 "hardware/libhardware": true,
84 "hardware/libhardware_legacy": true,
85 "hardware/ril": true,
86 }
87)
88
89func isDirectoryExcluded(dir string, excludedMap directoryMap, includedMap directoryMap) bool {
90 if dir == "." || dir == "/" {
91 return false
92 }
93 if includedMap[dir] {
94 return false
95 } else if excludedMap[dir] {
96 return true
97 } else if defaultDirectoryIncludedMap[dir] {
98 return false
99 } else if defaultDirectoryExcludedMap[dir] {
100 return true
101 } else {
102 return isDirectoryExcluded(filepath.Dir(dir), excludedMap, includedMap)
103 }
104}
Rob Seymour925aa092021-08-10 20:42:03 +0000105
106// This is to be saved as .json files, which is for development/vendor_snapshot/update.py.
107// These flags become Android.bp snapshot module properties.
108//
109// Attributes are optional and will be populated based on each module's need.
110// Common attributes are defined here, languages may extend this struct to add
111// additional attributes.
112type SnapshotJsonFlags struct {
113 ModuleName string `json:",omitempty"`
114 RelativeInstallPath string `json:",omitempty"`
115 Filename string `json:",omitempty"`
116 ModuleStemName string `json:",omitempty"`
Ivan Lozano872d5792022-03-23 17:31:39 -0400117 RustProcMacro bool `json:",omitempty"`
118 CrateName string `json:",omitempty"`
Rob Seymour925aa092021-08-10 20:42:03 +0000119
120 // dependencies
121 Required []string `json:",omitempty"`
122}