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