| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 1 | // Copyright 2020 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 | // | 
| Colin Cross | d079e0b | 2022-08-16 10:27:33 -0700 | [diff] [blame] | 7 | //	http://www.apache.org/licenses/LICENSE-2.0 | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 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 | package cc | 
 | 15 |  | 
 | 16 | // This file contains image variant related things, including image mutator functions, utility | 
 | 17 | // functions to determine where a module is installed, etc. | 
 | 18 |  | 
 | 19 | import ( | 
| Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 20 | 	"fmt" | 
 | 21 | 	"reflect" | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 22 | 	"strings" | 
 | 23 |  | 
 | 24 | 	"android/soong/android" | 
| Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 25 | 	"android/soong/snapshot" | 
| Jooyung Han | 85707de | 2023-12-01 14:21:13 +0900 | [diff] [blame] | 26 |  | 
 | 27 | 	"github.com/google/blueprint/proptools" | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 28 | ) | 
 | 29 |  | 
 | 30 | var _ android.ImageInterface = (*Module)(nil) | 
 | 31 |  | 
| Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 32 | type ImageVariantType string | 
| Inseob Kim | 74d2556 | 2020-08-04 00:41:38 +0900 | [diff] [blame] | 33 |  | 
 | 34 | const ( | 
| Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 35 | 	coreImageVariant          ImageVariantType = "core" | 
 | 36 | 	vendorImageVariant        ImageVariantType = "vendor" | 
 | 37 | 	productImageVariant       ImageVariantType = "product" | 
 | 38 | 	ramdiskImageVariant       ImageVariantType = "ramdisk" | 
 | 39 | 	vendorRamdiskImageVariant ImageVariantType = "vendor_ramdisk" | 
 | 40 | 	recoveryImageVariant      ImageVariantType = "recovery" | 
 | 41 | 	hostImageVariant          ImageVariantType = "host" | 
| Inseob Kim | 74d2556 | 2020-08-04 00:41:38 +0900 | [diff] [blame] | 42 | ) | 
 | 43 |  | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 44 | const ( | 
 | 45 | 	// VendorVariationPrefix is the variant prefix used for /vendor code that compiles | 
 | 46 | 	// against the VNDK. | 
 | 47 | 	VendorVariationPrefix = "vendor." | 
 | 48 |  | 
 | 49 | 	// ProductVariationPrefix is the variant prefix used for /product code that compiles | 
 | 50 | 	// against the VNDK. | 
 | 51 | 	ProductVariationPrefix = "product." | 
 | 52 | ) | 
 | 53 |  | 
 | 54 | func (ctx *moduleContext) ProductSpecific() bool { | 
| Justin Yun | 7f99ec7 | 2021-04-12 13:19:28 +0900 | [diff] [blame] | 55 | 	return ctx.ModuleContext.ProductSpecific() || ctx.mod.productSpecificModuleContext() | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 56 | } | 
 | 57 |  | 
 | 58 | func (ctx *moduleContext) SocSpecific() bool { | 
| Justin Yun | 7f99ec7 | 2021-04-12 13:19:28 +0900 | [diff] [blame] | 59 | 	return ctx.ModuleContext.SocSpecific() || ctx.mod.socSpecificModuleContext() | 
| Justin Yun | ebcf0c5 | 2021-01-08 18:00:19 +0900 | [diff] [blame] | 60 | } | 
 | 61 |  | 
 | 62 | func (ctx *moduleContext) DeviceSpecific() bool { | 
| Justin Yun | 7f99ec7 | 2021-04-12 13:19:28 +0900 | [diff] [blame] | 63 | 	return ctx.ModuleContext.DeviceSpecific() || ctx.mod.deviceSpecificModuleContext() | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 64 | } | 
 | 65 |  | 
 | 66 | func (ctx *moduleContextImpl) inProduct() bool { | 
| Ivan Lozano | f9e2172 | 2020-12-02 09:00:51 -0500 | [diff] [blame] | 67 | 	return ctx.mod.InProduct() | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 68 | } | 
 | 69 |  | 
 | 70 | func (ctx *moduleContextImpl) inVendor() bool { | 
| Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 71 | 	return ctx.mod.InVendor() | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 72 | } | 
 | 73 |  | 
 | 74 | func (ctx *moduleContextImpl) inRamdisk() bool { | 
 | 75 | 	return ctx.mod.InRamdisk() | 
 | 76 | } | 
 | 77 |  | 
| Yifan Hong | 60e0cfb | 2020-10-21 15:17:56 -0700 | [diff] [blame] | 78 | func (ctx *moduleContextImpl) inVendorRamdisk() bool { | 
 | 79 | 	return ctx.mod.InVendorRamdisk() | 
 | 80 | } | 
 | 81 |  | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 82 | func (ctx *moduleContextImpl) inRecovery() bool { | 
 | 83 | 	return ctx.mod.InRecovery() | 
 | 84 | } | 
 | 85 |  | 
| Justin Yun | 7f99ec7 | 2021-04-12 13:19:28 +0900 | [diff] [blame] | 86 | func (c *Module) productSpecificModuleContext() bool { | 
 | 87 | 	// Additionally check if this module is inProduct() that means it is a "product" variant of a | 
 | 88 | 	// module. As well as product specific modules, product variants must be installed to /product. | 
 | 89 | 	return c.InProduct() | 
 | 90 | } | 
 | 91 |  | 
 | 92 | func (c *Module) socSpecificModuleContext() bool { | 
 | 93 | 	// Additionally check if this module is inVendor() that means it is a "vendor" variant of a | 
 | 94 | 	// module. As well as SoC specific modules, vendor variants must be installed to /vendor | 
 | 95 | 	// unless they have "odm_available: true". | 
 | 96 | 	return c.HasVendorVariant() && c.InVendor() && !c.VendorVariantToOdm() | 
 | 97 | } | 
 | 98 |  | 
 | 99 | func (c *Module) deviceSpecificModuleContext() bool { | 
 | 100 | 	// Some vendor variants want to be installed to /odm by setting "odm_available: true". | 
 | 101 | 	return c.InVendor() && c.VendorVariantToOdm() | 
 | 102 | } | 
 | 103 |  | 
| Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 104 | // Returns true when this module is configured to have core and vendor variants. | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 105 | func (c *Module) HasVendorVariant() bool { | 
| Justin Yun | ebcf0c5 | 2021-01-08 18:00:19 +0900 | [diff] [blame] | 106 | 	return Bool(c.VendorProperties.Vendor_available) || Bool(c.VendorProperties.Odm_available) | 
 | 107 | } | 
 | 108 |  | 
 | 109 | // Returns true when this module creates a vendor variant and wants to install the vendor variant | 
 | 110 | // to the odm partition. | 
 | 111 | func (c *Module) VendorVariantToOdm() bool { | 
 | 112 | 	return Bool(c.VendorProperties.Odm_available) | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 113 | } | 
 | 114 |  | 
| Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 115 | // Returns true when this module is configured to have core and product variants. | 
 | 116 | func (c *Module) HasProductVariant() bool { | 
| Justin Yun | c0d8c49 | 2021-01-07 17:45:31 +0900 | [diff] [blame] | 117 | 	return Bool(c.VendorProperties.Product_available) | 
| Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 118 | } | 
 | 119 |  | 
 | 120 | // Returns true when this module is configured to have core and either product or vendor variants. | 
 | 121 | func (c *Module) HasNonSystemVariants() bool { | 
| Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 122 | 	return c.HasVendorVariant() || c.HasProductVariant() | 
| Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 123 | } | 
 | 124 |  | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 125 | // Returns true if the module is "product" variant. Usually these modules are installed in /product | 
| Ivan Lozano | f9e2172 | 2020-12-02 09:00:51 -0500 | [diff] [blame] | 126 | func (c *Module) InProduct() bool { | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 127 | 	return c.Properties.ImageVariationPrefix == ProductVariationPrefix | 
 | 128 | } | 
 | 129 |  | 
 | 130 | // Returns true if the module is "vendor" variant. Usually these modules are installed in /vendor | 
| Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 131 | func (c *Module) InVendor() bool { | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 132 | 	return c.Properties.ImageVariationPrefix == VendorVariationPrefix | 
 | 133 | } | 
 | 134 |  | 
 | 135 | func (c *Module) InRamdisk() bool { | 
 | 136 | 	return c.ModuleBase.InRamdisk() || c.ModuleBase.InstallInRamdisk() | 
 | 137 | } | 
 | 138 |  | 
| Yifan Hong | 60e0cfb | 2020-10-21 15:17:56 -0700 | [diff] [blame] | 139 | func (c *Module) InVendorRamdisk() bool { | 
 | 140 | 	return c.ModuleBase.InVendorRamdisk() || c.ModuleBase.InstallInVendorRamdisk() | 
 | 141 | } | 
 | 142 |  | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 143 | func (c *Module) InRecovery() bool { | 
 | 144 | 	return c.ModuleBase.InRecovery() || c.ModuleBase.InstallInRecovery() | 
 | 145 | } | 
 | 146 |  | 
 | 147 | func (c *Module) OnlyInRamdisk() bool { | 
 | 148 | 	return c.ModuleBase.InstallInRamdisk() | 
 | 149 | } | 
 | 150 |  | 
| Yifan Hong | 60e0cfb | 2020-10-21 15:17:56 -0700 | [diff] [blame] | 151 | func (c *Module) OnlyInVendorRamdisk() bool { | 
 | 152 | 	return c.ModuleBase.InstallInVendorRamdisk() | 
 | 153 | } | 
 | 154 |  | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 155 | func (c *Module) OnlyInRecovery() bool { | 
 | 156 | 	return c.ModuleBase.InstallInRecovery() | 
 | 157 | } | 
 | 158 |  | 
| Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 159 | func visitPropsAndCompareVendorAndProductProps(v reflect.Value) bool { | 
 | 160 | 	if v.Kind() != reflect.Struct { | 
 | 161 | 		return true | 
 | 162 | 	} | 
 | 163 | 	for i := 0; i < v.NumField(); i++ { | 
 | 164 | 		prop := v.Field(i) | 
 | 165 | 		if prop.Kind() == reflect.Struct && v.Type().Field(i).Name == "Target" { | 
 | 166 | 			vendor_prop := prop.FieldByName("Vendor") | 
 | 167 | 			product_prop := prop.FieldByName("Product") | 
 | 168 | 			if vendor_prop.Kind() != reflect.Struct && product_prop.Kind() != reflect.Struct { | 
 | 169 | 				// Neither Target.Vendor nor Target.Product is defined | 
 | 170 | 				continue | 
 | 171 | 			} | 
 | 172 | 			if vendor_prop.Kind() != reflect.Struct || product_prop.Kind() != reflect.Struct || | 
 | 173 | 				!reflect.DeepEqual(vendor_prop.Interface(), product_prop.Interface()) { | 
 | 174 | 				// If only one of either Target.Vendor or Target.Product is | 
 | 175 | 				// defined or they have different values, it fails the build | 
 | 176 | 				// since VNDK must have the same properties for both vendor | 
 | 177 | 				// and product variants. | 
 | 178 | 				return false | 
 | 179 | 			} | 
 | 180 | 		} else if !visitPropsAndCompareVendorAndProductProps(prop) { | 
 | 181 | 			// Visit the substructures to find Target.Vendor and Target.Product | 
 | 182 | 			return false | 
 | 183 | 		} | 
 | 184 | 	} | 
 | 185 | 	return true | 
 | 186 | } | 
 | 187 |  | 
 | 188 | // In the case of VNDK, vendor and product variants must have the same properties. | 
 | 189 | // VNDK installs only one file and shares it for both vendor and product modules on | 
 | 190 | // runtime. We may not define different versions of a VNDK lib for each partition. | 
 | 191 | // This function is used only for the VNDK modules that is available to both vendor | 
 | 192 | // and product partitions. | 
 | 193 | func (c *Module) compareVendorAndProductProps() bool { | 
| Justin Yun | c0d8c49 | 2021-01-07 17:45:31 +0900 | [diff] [blame] | 194 | 	if !c.IsVndk() && !Bool(c.VendorProperties.Product_available) { | 
| Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 195 | 		panic(fmt.Errorf("This is only for product available VNDK libs. %q is not a VNDK library or not product available", c.Name())) | 
 | 196 | 	} | 
 | 197 | 	for _, properties := range c.GetProperties() { | 
 | 198 | 		if !visitPropsAndCompareVendorAndProductProps(reflect.ValueOf(properties).Elem()) { | 
 | 199 | 			return false | 
 | 200 | 		} | 
 | 201 | 	} | 
 | 202 | 	return true | 
 | 203 | } | 
 | 204 |  | 
| Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 205 | // ImageMutatableModule provides a common image mutation interface for  LinkableInterface modules. | 
 | 206 | type ImageMutatableModule interface { | 
 | 207 | 	android.Module | 
 | 208 | 	LinkableInterface | 
 | 209 |  | 
 | 210 | 	// AndroidModuleBase returns the android.ModuleBase for this module | 
 | 211 | 	AndroidModuleBase() *android.ModuleBase | 
 | 212 |  | 
 | 213 | 	// VendorAvailable returns true if this module is available on the vendor image. | 
 | 214 | 	VendorAvailable() bool | 
 | 215 |  | 
 | 216 | 	// OdmAvailable returns true if this module is available on the odm image. | 
 | 217 | 	OdmAvailable() bool | 
 | 218 |  | 
 | 219 | 	// ProductAvailable returns true if this module is available on the product image. | 
 | 220 | 	ProductAvailable() bool | 
 | 221 |  | 
 | 222 | 	// RamdiskAvailable returns true if this module is available on the ramdisk image. | 
 | 223 | 	RamdiskAvailable() bool | 
 | 224 |  | 
 | 225 | 	// RecoveryAvailable returns true if this module is available on the recovery image. | 
 | 226 | 	RecoveryAvailable() bool | 
 | 227 |  | 
 | 228 | 	// VendorRamdiskAvailable returns true if this module is available on the vendor ramdisk image. | 
 | 229 | 	VendorRamdiskAvailable() bool | 
 | 230 |  | 
 | 231 | 	// IsSnapshotPrebuilt returns true if this module is a snapshot prebuilt. | 
 | 232 | 	IsSnapshotPrebuilt() bool | 
 | 233 |  | 
 | 234 | 	// SnapshotVersion returns the snapshot version for this module. | 
 | 235 | 	SnapshotVersion(mctx android.BaseModuleContext) string | 
 | 236 |  | 
 | 237 | 	// SdkVersion returns the SDK version for this module. | 
 | 238 | 	SdkVersion() string | 
 | 239 |  | 
 | 240 | 	// ExtraVariants returns the list of extra variants this module requires. | 
 | 241 | 	ExtraVariants() []string | 
 | 242 |  | 
 | 243 | 	// AppendExtraVariant returns an extra variant to the list of extra variants this module requires. | 
 | 244 | 	AppendExtraVariant(extraVariant string) | 
 | 245 |  | 
 | 246 | 	// SetRamdiskVariantNeeded sets whether the Ramdisk Variant is needed. | 
 | 247 | 	SetRamdiskVariantNeeded(b bool) | 
 | 248 |  | 
 | 249 | 	// SetVendorRamdiskVariantNeeded sets whether the Vendor Ramdisk Variant is needed. | 
 | 250 | 	SetVendorRamdiskVariantNeeded(b bool) | 
 | 251 |  | 
 | 252 | 	// SetRecoveryVariantNeeded sets whether the Recovery Variant is needed. | 
 | 253 | 	SetRecoveryVariantNeeded(b bool) | 
 | 254 |  | 
 | 255 | 	// SetCoreVariantNeeded sets whether the Core Variant is needed. | 
 | 256 | 	SetCoreVariantNeeded(b bool) | 
 | 257 | } | 
 | 258 |  | 
 | 259 | var _ ImageMutatableModule = (*Module)(nil) | 
 | 260 |  | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 261 | func (m *Module) ImageMutatorBegin(mctx android.BaseModuleContext) { | 
| Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 262 | 	m.CheckVndkProperties(mctx) | 
 | 263 | 	MutateImage(mctx, m) | 
 | 264 | } | 
 | 265 |  | 
 | 266 | // CheckVndkProperties checks whether the VNDK-related properties are set correctly. | 
 | 267 | // If properties are not set correctly, results in a module context property error. | 
 | 268 | func (m *Module) CheckVndkProperties(mctx android.BaseModuleContext) { | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 269 | 	vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific() | 
 | 270 | 	productSpecific := mctx.ProductSpecific() | 
 | 271 |  | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 272 | 	if vndkdep := m.vndkdep; vndkdep != nil { | 
 | 273 | 		if vndkdep.isVndk() { | 
 | 274 | 			if vendorSpecific || productSpecific { | 
 | 275 | 				if !vndkdep.isVndkExt() { | 
 | 276 | 					mctx.PropertyErrorf("vndk", | 
 | 277 | 						"must set `extends: \"...\"` to vndk extension") | 
| Justin Yun | c0d8c49 | 2021-01-07 17:45:31 +0900 | [diff] [blame] | 278 | 				} else if Bool(m.VendorProperties.Vendor_available) { | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 279 | 					mctx.PropertyErrorf("vendor_available", | 
 | 280 | 						"must not set at the same time as `vndk: {extends: \"...\"}`") | 
| Justin Yun | c0d8c49 | 2021-01-07 17:45:31 +0900 | [diff] [blame] | 281 | 				} else if Bool(m.VendorProperties.Product_available) { | 
| Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 282 | 					mctx.PropertyErrorf("product_available", | 
 | 283 | 						"must not set at the same time as `vndk: {extends: \"...\"}`") | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 284 | 				} | 
 | 285 | 			} else { | 
 | 286 | 				if vndkdep.isVndkExt() { | 
 | 287 | 					mctx.PropertyErrorf("vndk", | 
 | 288 | 						"must set `vendor: true` or `product_specific: true` to set `extends: %q`", | 
 | 289 | 						m.getVndkExtendsModuleName()) | 
 | 290 | 				} | 
| Justin Yun | c0d8c49 | 2021-01-07 17:45:31 +0900 | [diff] [blame] | 291 | 				if !Bool(m.VendorProperties.Vendor_available) { | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 292 | 					mctx.PropertyErrorf("vndk", | 
| Justin Yun | c0d8c49 | 2021-01-07 17:45:31 +0900 | [diff] [blame] | 293 | 						"vendor_available must be set to true when `vndk: {enabled: true}`") | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 294 | 				} | 
| Justin Yun | c0d8c49 | 2021-01-07 17:45:31 +0900 | [diff] [blame] | 295 | 				if Bool(m.VendorProperties.Product_available) { | 
| Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 296 | 					// If a VNDK module creates both product and vendor variants, they | 
 | 297 | 					// must have the same properties since they share a single VNDK | 
 | 298 | 					// library on runtime. | 
| Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 299 | 					if !m.compareVendorAndProductProps() { | 
 | 300 | 						mctx.ModuleErrorf("product properties must have the same values with the vendor properties for VNDK modules") | 
 | 301 | 					} | 
 | 302 | 				} | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 303 | 			} | 
 | 304 | 		} else { | 
 | 305 | 			if vndkdep.isVndkSp() { | 
 | 306 | 				mctx.PropertyErrorf("vndk", | 
 | 307 | 					"must set `enabled: true` to set `support_system_process: true`") | 
 | 308 | 			} | 
 | 309 | 			if vndkdep.isVndkExt() { | 
 | 310 | 				mctx.PropertyErrorf("vndk", | 
 | 311 | 					"must set `enabled: true` to set `extends: %q`", | 
 | 312 | 					m.getVndkExtendsModuleName()) | 
 | 313 | 			} | 
 | 314 | 		} | 
 | 315 | 	} | 
| Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 316 | } | 
 | 317 |  | 
 | 318 | func (m *Module) VendorAvailable() bool { | 
 | 319 | 	return Bool(m.VendorProperties.Vendor_available) | 
 | 320 | } | 
 | 321 |  | 
 | 322 | func (m *Module) OdmAvailable() bool { | 
 | 323 | 	return Bool(m.VendorProperties.Odm_available) | 
 | 324 | } | 
 | 325 |  | 
 | 326 | func (m *Module) ProductAvailable() bool { | 
 | 327 | 	return Bool(m.VendorProperties.Product_available) | 
 | 328 | } | 
 | 329 |  | 
 | 330 | func (m *Module) RamdiskAvailable() bool { | 
 | 331 | 	return Bool(m.Properties.Ramdisk_available) | 
 | 332 | } | 
 | 333 |  | 
 | 334 | func (m *Module) VendorRamdiskAvailable() bool { | 
 | 335 | 	return Bool(m.Properties.Vendor_ramdisk_available) | 
 | 336 | } | 
 | 337 |  | 
 | 338 | func (m *Module) AndroidModuleBase() *android.ModuleBase { | 
 | 339 | 	return &m.ModuleBase | 
 | 340 | } | 
 | 341 |  | 
 | 342 | func (m *Module) RecoveryAvailable() bool { | 
 | 343 | 	return Bool(m.Properties.Recovery_available) | 
 | 344 | } | 
 | 345 |  | 
 | 346 | func (m *Module) ExtraVariants() []string { | 
| Lukacs T. Berki | 2f5c340 | 2021-06-15 11:27:56 +0200 | [diff] [blame] | 347 | 	return m.Properties.ExtraVersionedImageVariations | 
| Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 348 | } | 
 | 349 |  | 
 | 350 | func (m *Module) AppendExtraVariant(extraVariant string) { | 
| Lukacs T. Berki | 2f5c340 | 2021-06-15 11:27:56 +0200 | [diff] [blame] | 351 | 	m.Properties.ExtraVersionedImageVariations = append(m.Properties.ExtraVersionedImageVariations, extraVariant) | 
| Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 352 | } | 
 | 353 |  | 
 | 354 | func (m *Module) SetRamdiskVariantNeeded(b bool) { | 
 | 355 | 	m.Properties.RamdiskVariantNeeded = b | 
 | 356 | } | 
 | 357 |  | 
 | 358 | func (m *Module) SetVendorRamdiskVariantNeeded(b bool) { | 
 | 359 | 	m.Properties.VendorRamdiskVariantNeeded = b | 
 | 360 | } | 
 | 361 |  | 
 | 362 | func (m *Module) SetRecoveryVariantNeeded(b bool) { | 
 | 363 | 	m.Properties.RecoveryVariantNeeded = b | 
 | 364 | } | 
 | 365 |  | 
 | 366 | func (m *Module) SetCoreVariantNeeded(b bool) { | 
 | 367 | 	m.Properties.CoreVariantNeeded = b | 
 | 368 | } | 
 | 369 |  | 
 | 370 | func (m *Module) SnapshotVersion(mctx android.BaseModuleContext) string { | 
| Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 371 | 	if snapshot, ok := m.linker.(SnapshotInterface); ok { | 
 | 372 | 		return snapshot.Version() | 
| Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 373 | 	} else { | 
 | 374 | 		mctx.ModuleErrorf("version is unknown for snapshot prebuilt") | 
 | 375 | 		// Should we be panicking here instead? | 
 | 376 | 		return "" | 
 | 377 | 	} | 
 | 378 | } | 
 | 379 |  | 
 | 380 | func (m *Module) KernelHeadersDecorator() bool { | 
 | 381 | 	if _, ok := m.linker.(*kernelHeadersDecorator); ok { | 
 | 382 | 		return true | 
 | 383 | 	} | 
 | 384 | 	return false | 
 | 385 | } | 
 | 386 |  | 
 | 387 | // MutateImage handles common image mutations for ImageMutatableModule interfaces. | 
 | 388 | func MutateImage(mctx android.BaseModuleContext, m ImageMutatableModule) { | 
 | 389 | 	// Validation check | 
 | 390 | 	vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific() | 
 | 391 | 	productSpecific := mctx.ProductSpecific() | 
 | 392 |  | 
 | 393 | 	if m.VendorAvailable() { | 
 | 394 | 		if vendorSpecific { | 
 | 395 | 			mctx.PropertyErrorf("vendor_available", | 
 | 396 | 				"doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific: true`") | 
 | 397 | 		} | 
 | 398 | 		if m.OdmAvailable() { | 
 | 399 | 			mctx.PropertyErrorf("vendor_available", | 
 | 400 | 				"doesn't make sense at the same time as `odm_available: true`") | 
 | 401 | 		} | 
 | 402 | 	} | 
 | 403 |  | 
 | 404 | 	if m.OdmAvailable() { | 
 | 405 | 		if vendorSpecific { | 
 | 406 | 			mctx.PropertyErrorf("odm_available", | 
 | 407 | 				"doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific: true`") | 
 | 408 | 		} | 
 | 409 | 	} | 
 | 410 |  | 
 | 411 | 	if m.ProductAvailable() { | 
 | 412 | 		if productSpecific { | 
 | 413 | 			mctx.PropertyErrorf("product_available", | 
 | 414 | 				"doesn't make sense at the same time as `product_specific: true`") | 
 | 415 | 		} | 
 | 416 | 		if vendorSpecific { | 
 | 417 | 			mctx.PropertyErrorf("product_available", | 
 | 418 | 				"cannot provide product variant from a vendor module. Please use `product_specific: true` with `vendor_available: true`") | 
 | 419 | 		} | 
 | 420 | 	} | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 421 |  | 
 | 422 | 	var coreVariantNeeded bool = false | 
 | 423 | 	var ramdiskVariantNeeded bool = false | 
| Yifan Hong | 60e0cfb | 2020-10-21 15:17:56 -0700 | [diff] [blame] | 424 | 	var vendorRamdiskVariantNeeded bool = false | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 425 | 	var recoveryVariantNeeded bool = false | 
 | 426 |  | 
 | 427 | 	var vendorVariants []string | 
 | 428 | 	var productVariants []string | 
 | 429 |  | 
 | 430 | 	platformVndkVersion := mctx.DeviceConfig().PlatformVndkVersion() | 
 | 431 | 	boardVndkVersion := mctx.DeviceConfig().VndkVersion() | 
| Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 432 | 	recoverySnapshotVersion := mctx.DeviceConfig().RecoverySnapshotVersion() | 
 | 433 | 	usingRecoverySnapshot := recoverySnapshotVersion != "current" && | 
 | 434 | 		recoverySnapshotVersion != "" | 
| Justin Yun | dee806f | 2021-05-18 23:10:00 +0900 | [diff] [blame] | 435 | 	needVndkVersionVendorVariantForLlndk := false | 
 | 436 | 	if boardVndkVersion != "" { | 
 | 437 | 		boardVndkApiLevel, err := android.ApiLevelFromUser(mctx, boardVndkVersion) | 
 | 438 | 		if err == nil && !boardVndkApiLevel.IsPreview() { | 
 | 439 | 			// VNDK snapshot newer than v30 has LLNDK stub libraries. | 
 | 440 | 			// Only the VNDK version less than or equal to v30 requires generating the vendor | 
 | 441 | 			// variant of the VNDK version from the source tree. | 
 | 442 | 			needVndkVersionVendorVariantForLlndk = boardVndkApiLevel.LessThanOrEqualTo(android.ApiLevelOrPanic(mctx, "30")) | 
 | 443 | 		} | 
 | 444 | 	} | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 445 | 	if boardVndkVersion == "current" { | 
 | 446 | 		boardVndkVersion = platformVndkVersion | 
 | 447 | 	} | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 448 |  | 
| Colin Cross | 203b421 | 2021-04-26 17:19:41 -0700 | [diff] [blame] | 449 | 	if m.NeedsLlndkVariants() { | 
| Colin Cross | b5f6fa6 | 2021-01-06 17:05:04 -0800 | [diff] [blame] | 450 | 		// This is an LLNDK library.  The implementation of the library will be on /system, | 
 | 451 | 		// and vendor and product variants will be created with LLNDK stubs. | 
 | 452 | 		// The LLNDK libraries need vendor variants even if there is no VNDK. | 
| Colin Cross | 203b421 | 2021-04-26 17:19:41 -0700 | [diff] [blame] | 453 | 		coreVariantNeeded = true | 
| Colin Cross | b5f6fa6 | 2021-01-06 17:05:04 -0800 | [diff] [blame] | 454 | 		if platformVndkVersion != "" { | 
 | 455 | 			vendorVariants = append(vendorVariants, platformVndkVersion) | 
 | 456 | 			productVariants = append(productVariants, platformVndkVersion) | 
 | 457 | 		} | 
| Justin Yun | dee806f | 2021-05-18 23:10:00 +0900 | [diff] [blame] | 458 | 		// Generate vendor variants for boardVndkVersion only if the VNDK snapshot does not | 
 | 459 | 		// provide the LLNDK stub libraries. | 
 | 460 | 		if needVndkVersionVendorVariantForLlndk { | 
| Colin Cross | b5f6fa6 | 2021-01-06 17:05:04 -0800 | [diff] [blame] | 461 | 			vendorVariants = append(vendorVariants, boardVndkVersion) | 
 | 462 | 		} | 
| Colin Cross | 5271fea | 2021-04-27 13:06:04 -0700 | [diff] [blame] | 463 | 	} else if m.NeedsVendorPublicLibraryVariants() { | 
 | 464 | 		// A vendor public library has the implementation on /vendor, with stub variants | 
 | 465 | 		// for system and product. | 
 | 466 | 		coreVariantNeeded = true | 
 | 467 | 		vendorVariants = append(vendorVariants, boardVndkVersion) | 
 | 468 | 		if platformVndkVersion != "" { | 
 | 469 | 			productVariants = append(productVariants, platformVndkVersion) | 
 | 470 | 		} | 
| Colin Cross | b5f6fa6 | 2021-01-06 17:05:04 -0800 | [diff] [blame] | 471 | 	} else if boardVndkVersion == "" { | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 472 | 		// If the device isn't compiling against the VNDK, we always | 
 | 473 | 		// use the core mode. | 
 | 474 | 		coreVariantNeeded = true | 
| Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 475 | 	} else if m.IsSnapshotPrebuilt() { | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 476 | 		// Make vendor variants only for the versions in BOARD_VNDK_VERSION and | 
 | 477 | 		// PRODUCT_EXTRA_VNDK_VERSIONS. | 
| Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 478 | 		if m.InstallInRecovery() { | 
 | 479 | 			recoveryVariantNeeded = true | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 480 | 		} else { | 
| Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 481 | 			vendorVariants = append(vendorVariants, m.SnapshotVersion(mctx)) | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 482 | 		} | 
| Ivan Lozano | f9e2172 | 2020-12-02 09:00:51 -0500 | [diff] [blame] | 483 | 	} else if m.HasNonSystemVariants() && !m.IsVndkExt() { | 
| Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 484 | 		// This will be available to /system unless it is product_specific | 
 | 485 | 		// which will be handled later. | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 486 | 		coreVariantNeeded = true | 
 | 487 |  | 
 | 488 | 		// We assume that modules under proprietary paths are compatible for | 
 | 489 | 		// BOARD_VNDK_VERSION. The other modules are regarded as AOSP, or | 
 | 490 | 		// PLATFORM_VNDK_VERSION. | 
| Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 491 | 		if m.HasVendorVariant() { | 
| Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 492 | 			if snapshot.IsVendorProprietaryModule(mctx) { | 
| Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 493 | 				vendorVariants = append(vendorVariants, boardVndkVersion) | 
 | 494 | 			} else { | 
 | 495 | 				vendorVariants = append(vendorVariants, platformVndkVersion) | 
 | 496 | 			} | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 497 | 		} | 
 | 498 |  | 
| Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 499 | 		// product_available modules are available to /product. | 
 | 500 | 		if m.HasProductVariant() { | 
 | 501 | 			productVariants = append(productVariants, platformVndkVersion) | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 502 | 		} | 
| Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 503 | 	} else if vendorSpecific && m.SdkVersion() == "" { | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 504 | 		// This will be available in /vendor (or /odm) only | 
 | 505 |  | 
 | 506 | 		// kernel_headers is a special module type whose exported headers | 
 | 507 | 		// are coming from DeviceKernelHeaders() which is always vendor | 
 | 508 | 		// dependent. They'll always have both vendor variants. | 
 | 509 | 		// For other modules, we assume that modules under proprietary | 
 | 510 | 		// paths are compatible for BOARD_VNDK_VERSION. The other modules | 
 | 511 | 		// are regarded as AOSP, which is PLATFORM_VNDK_VERSION. | 
| Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 512 | 		if m.KernelHeadersDecorator() { | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 513 | 			vendorVariants = append(vendorVariants, | 
 | 514 | 				platformVndkVersion, | 
 | 515 | 				boardVndkVersion, | 
 | 516 | 			) | 
| Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 517 | 		} else if snapshot.IsVendorProprietaryModule(mctx) { | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 518 | 			vendorVariants = append(vendorVariants, boardVndkVersion) | 
 | 519 | 		} else { | 
 | 520 | 			vendorVariants = append(vendorVariants, platformVndkVersion) | 
 | 521 | 		} | 
 | 522 | 	} else { | 
 | 523 | 		// This is either in /system (or similar: /data), or is a | 
| jiajia tang | cd1c27b | 2022-07-21 18:04:37 +0800 | [diff] [blame] | 524 | 		// module built with the NDK. Modules built with the NDK | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 525 | 		// will be restricted using the existing link type checks. | 
 | 526 | 		coreVariantNeeded = true | 
 | 527 | 	} | 
 | 528 |  | 
| Justin Yun | af1fde4 | 2023-09-27 16:22:10 +0900 | [diff] [blame] | 529 | 	if coreVariantNeeded && productSpecific && m.SdkVersion() == "" { | 
 | 530 | 		// The module has "product_specific: true" that does not create core variant. | 
 | 531 | 		coreVariantNeeded = false | 
 | 532 | 		productVariants = append(productVariants, platformVndkVersion) | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 533 | 	} | 
 | 534 |  | 
| Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 535 | 	if m.RamdiskAvailable() { | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 536 | 		ramdiskVariantNeeded = true | 
 | 537 | 	} | 
 | 538 |  | 
| Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 539 | 	if m.AndroidModuleBase().InstallInRamdisk() { | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 540 | 		ramdiskVariantNeeded = true | 
 | 541 | 		coreVariantNeeded = false | 
 | 542 | 	} | 
 | 543 |  | 
| Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 544 | 	if m.VendorRamdiskAvailable() { | 
| Yifan Hong | 60e0cfb | 2020-10-21 15:17:56 -0700 | [diff] [blame] | 545 | 		vendorRamdiskVariantNeeded = true | 
 | 546 | 	} | 
 | 547 |  | 
| Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 548 | 	if m.AndroidModuleBase().InstallInVendorRamdisk() { | 
| Yifan Hong | 60e0cfb | 2020-10-21 15:17:56 -0700 | [diff] [blame] | 549 | 		vendorRamdiskVariantNeeded = true | 
 | 550 | 		coreVariantNeeded = false | 
 | 551 | 	} | 
 | 552 |  | 
| Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 553 | 	if m.RecoveryAvailable() { | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 554 | 		recoveryVariantNeeded = true | 
 | 555 | 	} | 
 | 556 |  | 
| Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 557 | 	if m.AndroidModuleBase().InstallInRecovery() { | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 558 | 		recoveryVariantNeeded = true | 
 | 559 | 		coreVariantNeeded = false | 
 | 560 | 	} | 
 | 561 |  | 
| Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 562 | 	// If using a snapshot, the recovery variant under AOSP directories is not needed, | 
 | 563 | 	// except for kernel headers, which needs all variants. | 
| Jose Galmes | 737d0a1 | 2021-05-25 22:06:41 -0700 | [diff] [blame] | 564 | 	if !m.KernelHeadersDecorator() && | 
| Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 565 | 		!m.IsSnapshotPrebuilt() && | 
| Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 566 | 		usingRecoverySnapshot && | 
| Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 567 | 		!snapshot.IsRecoveryProprietaryModule(mctx) { | 
| Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 568 | 		recoveryVariantNeeded = false | 
 | 569 | 	} | 
 | 570 |  | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 571 | 	for _, variant := range android.FirstUniqueStrings(vendorVariants) { | 
| Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 572 | 		m.AppendExtraVariant(VendorVariationPrefix + variant) | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 573 | 	} | 
 | 574 |  | 
 | 575 | 	for _, variant := range android.FirstUniqueStrings(productVariants) { | 
| Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 576 | 		m.AppendExtraVariant(ProductVariationPrefix + variant) | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 577 | 	} | 
 | 578 |  | 
| Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 579 | 	m.SetRamdiskVariantNeeded(ramdiskVariantNeeded) | 
 | 580 | 	m.SetVendorRamdiskVariantNeeded(vendorRamdiskVariantNeeded) | 
 | 581 | 	m.SetRecoveryVariantNeeded(recoveryVariantNeeded) | 
 | 582 | 	m.SetCoreVariantNeeded(coreVariantNeeded) | 
| Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 583 |  | 
 | 584 | 	// Disable the module if no variants are needed. | 
 | 585 | 	if !ramdiskVariantNeeded && | 
 | 586 | 		!recoveryVariantNeeded && | 
 | 587 | 		!coreVariantNeeded && | 
| Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 588 | 		len(m.ExtraVariants()) == 0 { | 
| Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 589 | 		m.Disable() | 
 | 590 | 	} | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 591 | } | 
 | 592 |  | 
 | 593 | func (c *Module) CoreVariantNeeded(ctx android.BaseModuleContext) bool { | 
 | 594 | 	return c.Properties.CoreVariantNeeded | 
 | 595 | } | 
 | 596 |  | 
 | 597 | func (c *Module) RamdiskVariantNeeded(ctx android.BaseModuleContext) bool { | 
 | 598 | 	return c.Properties.RamdiskVariantNeeded | 
 | 599 | } | 
 | 600 |  | 
| Yifan Hong | 60e0cfb | 2020-10-21 15:17:56 -0700 | [diff] [blame] | 601 | func (c *Module) VendorRamdiskVariantNeeded(ctx android.BaseModuleContext) bool { | 
 | 602 | 	return c.Properties.VendorRamdiskVariantNeeded | 
 | 603 | } | 
 | 604 |  | 
| Inseob Kim | 08758f0 | 2021-04-08 21:13:22 +0900 | [diff] [blame] | 605 | func (c *Module) DebugRamdiskVariantNeeded(ctx android.BaseModuleContext) bool { | 
 | 606 | 	return false | 
 | 607 | } | 
 | 608 |  | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 609 | func (c *Module) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool { | 
 | 610 | 	return c.Properties.RecoveryVariantNeeded | 
 | 611 | } | 
 | 612 |  | 
 | 613 | func (c *Module) ExtraImageVariations(ctx android.BaseModuleContext) []string { | 
| Lukacs T. Berki | 2f5c340 | 2021-06-15 11:27:56 +0200 | [diff] [blame] | 614 | 	return c.Properties.ExtraVersionedImageVariations | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 615 | } | 
 | 616 |  | 
| Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 617 | func squashVendorSrcs(m *Module) { | 
 | 618 | 	if lib, ok := m.compiler.(*libraryDecorator); ok { | 
 | 619 | 		lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs, | 
 | 620 | 			lib.baseCompiler.Properties.Target.Vendor.Srcs...) | 
 | 621 |  | 
 | 622 | 		lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs, | 
 | 623 | 			lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...) | 
 | 624 |  | 
 | 625 | 		lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources, | 
 | 626 | 			lib.baseCompiler.Properties.Target.Vendor.Exclude_generated_sources...) | 
| Jooyung Han | 85707de | 2023-12-01 14:21:13 +0900 | [diff] [blame] | 627 |  | 
 | 628 | 		if lib.Properties.Target.Vendor.No_stubs { | 
 | 629 | 			proptools.Clear(&lib.Properties.Stubs) | 
 | 630 | 		} | 
| Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 631 | 	} | 
 | 632 | } | 
 | 633 |  | 
 | 634 | func squashProductSrcs(m *Module) { | 
 | 635 | 	if lib, ok := m.compiler.(*libraryDecorator); ok { | 
 | 636 | 		lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs, | 
 | 637 | 			lib.baseCompiler.Properties.Target.Product.Srcs...) | 
 | 638 |  | 
 | 639 | 		lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs, | 
 | 640 | 			lib.baseCompiler.Properties.Target.Product.Exclude_srcs...) | 
 | 641 |  | 
 | 642 | 		lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources, | 
 | 643 | 			lib.baseCompiler.Properties.Target.Product.Exclude_generated_sources...) | 
| Jooyung Han | 85707de | 2023-12-01 14:21:13 +0900 | [diff] [blame] | 644 |  | 
 | 645 | 		if lib.Properties.Target.Product.No_stubs { | 
 | 646 | 			proptools.Clear(&lib.Properties.Stubs) | 
 | 647 | 		} | 
| Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 648 | 	} | 
 | 649 | } | 
 | 650 |  | 
 | 651 | func squashRecoverySrcs(m *Module) { | 
 | 652 | 	if lib, ok := m.compiler.(*libraryDecorator); ok { | 
 | 653 | 		lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs, | 
 | 654 | 			lib.baseCompiler.Properties.Target.Recovery.Srcs...) | 
 | 655 |  | 
 | 656 | 		lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs, | 
 | 657 | 			lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...) | 
 | 658 |  | 
 | 659 | 		lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources, | 
 | 660 | 			lib.baseCompiler.Properties.Target.Recovery.Exclude_generated_sources...) | 
 | 661 | 	} | 
 | 662 | } | 
 | 663 |  | 
 | 664 | func squashVendorRamdiskSrcs(m *Module) { | 
 | 665 | 	if lib, ok := m.compiler.(*libraryDecorator); ok { | 
 | 666 | 		lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs, lib.baseCompiler.Properties.Target.Vendor_ramdisk.Exclude_srcs...) | 
 | 667 | 	} | 
 | 668 | } | 
 | 669 |  | 
| Christopher Ferris | e0202c4 | 2023-07-27 17:06:46 -0700 | [diff] [blame] | 670 | func squashRamdiskSrcs(m *Module) { | 
 | 671 | 	if lib, ok := m.compiler.(*libraryDecorator); ok { | 
 | 672 | 		lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs, lib.baseCompiler.Properties.Target.Ramdisk.Exclude_srcs...) | 
 | 673 | 	} | 
 | 674 | } | 
 | 675 |  | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 676 | func (c *Module) SetImageVariation(ctx android.BaseModuleContext, variant string, module android.Module) { | 
 | 677 | 	m := module.(*Module) | 
| Yifan Hong | 6da33c2 | 2020-10-27 15:01:21 -0700 | [diff] [blame] | 678 | 	if variant == android.RamdiskVariation { | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 679 | 		m.MakeAsPlatform() | 
| Christopher Ferris | e0202c4 | 2023-07-27 17:06:46 -0700 | [diff] [blame] | 680 | 		squashRamdiskSrcs(m) | 
| Yifan Hong | 6da33c2 | 2020-10-27 15:01:21 -0700 | [diff] [blame] | 681 | 	} else if variant == android.VendorRamdiskVariation { | 
 | 682 | 		m.MakeAsPlatform() | 
 | 683 | 		squashVendorRamdiskSrcs(m) | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 684 | 	} else if variant == android.RecoveryVariation { | 
 | 685 | 		m.MakeAsPlatform() | 
 | 686 | 		squashRecoverySrcs(m) | 
 | 687 | 	} else if strings.HasPrefix(variant, VendorVariationPrefix) { | 
 | 688 | 		m.Properties.ImageVariationPrefix = VendorVariationPrefix | 
 | 689 | 		m.Properties.VndkVersion = strings.TrimPrefix(variant, VendorVariationPrefix) | 
 | 690 | 		squashVendorSrcs(m) | 
 | 691 |  | 
 | 692 | 		// Makefile shouldn't know vendor modules other than BOARD_VNDK_VERSION. | 
 | 693 | 		// Hide other vendor variants to avoid collision. | 
 | 694 | 		vndkVersion := ctx.DeviceConfig().VndkVersion() | 
 | 695 | 		if vndkVersion != "current" && vndkVersion != "" && vndkVersion != m.Properties.VndkVersion { | 
 | 696 | 			m.Properties.HideFromMake = true | 
| Colin Cross | a9c8c9f | 2020-12-16 10:20:23 -0800 | [diff] [blame] | 697 | 			m.HideFromMake() | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 698 | 		} | 
 | 699 | 	} else if strings.HasPrefix(variant, ProductVariationPrefix) { | 
 | 700 | 		m.Properties.ImageVariationPrefix = ProductVariationPrefix | 
 | 701 | 		m.Properties.VndkVersion = strings.TrimPrefix(variant, ProductVariationPrefix) | 
| Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 702 | 		squashProductSrcs(m) | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 703 | 	} | 
| Colin Cross | 5271fea | 2021-04-27 13:06:04 -0700 | [diff] [blame] | 704 |  | 
 | 705 | 	if c.NeedsVendorPublicLibraryVariants() && | 
 | 706 | 		(variant == android.CoreVariation || strings.HasPrefix(variant, ProductVariationPrefix)) { | 
 | 707 | 		c.VendorProperties.IsVendorPublicLibrary = true | 
 | 708 | 	} | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 709 | } |