blob: 012267a85e32ffaff5729a1b66192c3434f78333 [file] [log] [blame]
Colin Cross7228ecd2019-11-18 16:00:16 -08001// Copyright 2019 Google Inc. All rights reserved.
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.
14
15package android
16
Cole Faustfa6e0fd2024-10-15 15:22:57 -070017type ImageInterfaceContext interface {
18 ArchModuleContext
19
20 Module() Module
21
22 ModuleErrorf(fmt string, args ...interface{})
23 PropertyErrorf(property, fmt string, args ...interface{})
24
25 DeviceSpecific() bool
26 SocSpecific() bool
27 ProductSpecific() bool
28 SystemExtSpecific() bool
29 Platform() bool
30
31 Config() Config
32}
33
Jihoon Kang5402bbd2024-07-31 18:37:49 +000034// ImageInterface is implemented by modules that need to be split by the imageTransitionMutator.
Colin Cross7228ecd2019-11-18 16:00:16 -080035type ImageInterface interface {
36 // ImageMutatorBegin is called before any other method in the ImageInterface.
Cole Faustfa6e0fd2024-10-15 15:22:57 -070037 ImageMutatorBegin(ctx ImageInterfaceContext)
Colin Cross7228ecd2019-11-18 16:00:16 -080038
Jihoon Kang47e91842024-06-19 00:51:16 +000039 // VendorVariantNeeded should return true if the module needs a vendor variant (installed on the vendor image).
Cole Faustfa6e0fd2024-10-15 15:22:57 -070040 VendorVariantNeeded(ctx ImageInterfaceContext) bool
Jihoon Kang47e91842024-06-19 00:51:16 +000041
Jihoon Kangc3d4e112024-06-24 22:16:27 +000042 // ProductVariantNeeded should return true if the module needs a product variant (installed on the product image).
Cole Faustfa6e0fd2024-10-15 15:22:57 -070043 ProductVariantNeeded(ctx ImageInterfaceContext) bool
Jihoon Kang47e91842024-06-19 00:51:16 +000044
Colin Cross7228ecd2019-11-18 16:00:16 -080045 // CoreVariantNeeded should return true if the module needs a core variant (installed on the system image).
Cole Faustfa6e0fd2024-10-15 15:22:57 -070046 CoreVariantNeeded(ctx ImageInterfaceContext) bool
Colin Cross7228ecd2019-11-18 16:00:16 -080047
Yifan Hong1b3348d2020-01-21 15:53:22 -080048 // RamdiskVariantNeeded should return true if the module needs a ramdisk variant (installed on the
49 // ramdisk partition).
Cole Faustfa6e0fd2024-10-15 15:22:57 -070050 RamdiskVariantNeeded(ctx ImageInterfaceContext) bool
Yifan Hong1b3348d2020-01-21 15:53:22 -080051
Yifan Hong60e0cfb2020-10-21 15:17:56 -070052 // VendorRamdiskVariantNeeded should return true if the module needs a vendor ramdisk variant (installed on the
53 // vendor ramdisk partition).
Cole Faustfa6e0fd2024-10-15 15:22:57 -070054 VendorRamdiskVariantNeeded(ctx ImageInterfaceContext) bool
Yifan Hong60e0cfb2020-10-21 15:17:56 -070055
Inseob Kim08758f02021-04-08 21:13:22 +090056 // DebugRamdiskVariantNeeded should return true if the module needs a debug ramdisk variant (installed on the
57 // debug ramdisk partition: $(PRODUCT_OUT)/debug_ramdisk).
Cole Faustfa6e0fd2024-10-15 15:22:57 -070058 DebugRamdiskVariantNeeded(ctx ImageInterfaceContext) bool
Inseob Kim08758f02021-04-08 21:13:22 +090059
Colin Cross7228ecd2019-11-18 16:00:16 -080060 // RecoveryVariantNeeded should return true if the module needs a recovery variant (installed on the
61 // recovery partition).
Cole Faustfa6e0fd2024-10-15 15:22:57 -070062 RecoveryVariantNeeded(ctx ImageInterfaceContext) bool
Colin Cross7228ecd2019-11-18 16:00:16 -080063
64 // ExtraImageVariations should return a list of the additional variations needed for the module. After the
65 // variants are created the SetImageVariation method will be called on each newly created variant with the
66 // its variation.
Cole Faustfa6e0fd2024-10-15 15:22:57 -070067 ExtraImageVariations(ctx ImageInterfaceContext) []string
Colin Cross7228ecd2019-11-18 16:00:16 -080068
Lukacs T. Berki2f5c3402021-06-15 11:27:56 +020069 // SetImageVariation is called for each newly created image variant. The receiver is the original
Jihoon Kang7583e832024-06-13 21:25:45 +000070 // module, "variation" is the name of the newly created variant. "variation" is set on the receiver.
Cole Faustfa6e0fd2024-10-15 15:22:57 -070071 SetImageVariation(ctx ImageInterfaceContext, variation string)
Colin Cross7228ecd2019-11-18 16:00:16 -080072}
73
74const (
Jihoon Kang47e91842024-06-19 00:51:16 +000075 // VendorVariation is the variant name used for /vendor code that does not
76 // compile against the VNDK.
77 VendorVariation string = "vendor"
78
79 // ProductVariation is the variant name used for /product code that does not
80 // compile against the VNDK.
81 ProductVariation string = "product"
82
Colin Cross7228ecd2019-11-18 16:00:16 -080083 // CoreVariation is the variant used for framework-private libraries, or
84 // SDK libraries. (which framework-private libraries can use), which
85 // will be installed to the system image.
Colin Cross7113d202019-11-20 16:39:12 -080086 CoreVariation string = ""
Colin Cross7228ecd2019-11-18 16:00:16 -080087
88 // RecoveryVariation means a module to be installed to recovery image.
89 RecoveryVariation string = "recovery"
Yifan Hong1b3348d2020-01-21 15:53:22 -080090
91 // RamdiskVariation means a module to be installed to ramdisk image.
92 RamdiskVariation string = "ramdisk"
Yifan Hong60e0cfb2020-10-21 15:17:56 -070093
94 // VendorRamdiskVariation means a module to be installed to vendor ramdisk image.
95 VendorRamdiskVariation string = "vendor_ramdisk"
Inseob Kim08758f02021-04-08 21:13:22 +090096
97 // DebugRamdiskVariation means a module to be installed to debug ramdisk image.
98 DebugRamdiskVariation string = "debug_ramdisk"
Colin Cross7228ecd2019-11-18 16:00:16 -080099)
100
Jihoon Kang5402bbd2024-07-31 18:37:49 +0000101// imageTransitionMutator creates variants for modules that implement the ImageInterface that
Colin Cross7228ecd2019-11-18 16:00:16 -0800102// allow them to build differently for each partition (recovery, core, vendor, etc.).
Jihoon Kang5402bbd2024-07-31 18:37:49 +0000103type imageTransitionMutator struct{}
Colin Cross7228ecd2019-11-18 16:00:16 -0800104
Jihoon Kang5402bbd2024-07-31 18:37:49 +0000105func (imageTransitionMutator) Split(ctx BaseModuleContext) []string {
106 var variations []string
107
108 if m, ok := ctx.Module().(ImageInterface); ctx.Os() == Android && ok {
Colin Cross7228ecd2019-11-18 16:00:16 -0800109 m.ImageMutatorBegin(ctx)
110
Colin Cross7228ecd2019-11-18 16:00:16 -0800111 if m.CoreVariantNeeded(ctx) {
112 variations = append(variations, CoreVariation)
113 }
Yifan Hong1b3348d2020-01-21 15:53:22 -0800114 if m.RamdiskVariantNeeded(ctx) {
115 variations = append(variations, RamdiskVariation)
116 }
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700117 if m.VendorRamdiskVariantNeeded(ctx) {
118 variations = append(variations, VendorRamdiskVariation)
119 }
Inseob Kim08758f02021-04-08 21:13:22 +0900120 if m.DebugRamdiskVariantNeeded(ctx) {
121 variations = append(variations, DebugRamdiskVariation)
122 }
Colin Cross7228ecd2019-11-18 16:00:16 -0800123 if m.RecoveryVariantNeeded(ctx) {
124 variations = append(variations, RecoveryVariation)
125 }
Jihoon Kang47e91842024-06-19 00:51:16 +0000126 if m.VendorVariantNeeded(ctx) {
127 variations = append(variations, VendorVariation)
128 }
129 if m.ProductVariantNeeded(ctx) {
130 variations = append(variations, ProductVariation)
131 }
Colin Cross7228ecd2019-11-18 16:00:16 -0800132
133 extraVariations := m.ExtraImageVariations(ctx)
134 variations = append(variations, extraVariations...)
Jihoon Kang5402bbd2024-07-31 18:37:49 +0000135 }
Colin Cross7228ecd2019-11-18 16:00:16 -0800136
Jihoon Kang5402bbd2024-07-31 18:37:49 +0000137 if len(variations) == 0 {
138 variations = append(variations, "")
139 }
Colin Cross7228ecd2019-11-18 16:00:16 -0800140
Jihoon Kang5402bbd2024-07-31 18:37:49 +0000141 return variations
142}
143
144func (imageTransitionMutator) OutgoingTransition(ctx OutgoingTransitionContext, sourceVariation string) string {
145 return sourceVariation
146}
147
148func (imageTransitionMutator) IncomingTransition(ctx IncomingTransitionContext, incomingVariation string) string {
149 if _, ok := ctx.Module().(ImageInterface); ctx.Os() != Android || !ok {
150 return CoreVariation
151 }
152 return incomingVariation
153}
154
155func (imageTransitionMutator) Mutate(ctx BottomUpMutatorContext, variation string) {
156 ctx.Module().base().setImageVariation(variation)
157 if m, ok := ctx.Module().(ImageInterface); ok {
158 m.SetImageVariation(ctx, variation)
Colin Cross7228ecd2019-11-18 16:00:16 -0800159 }
160}