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 | // |
| 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 | 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" |
| 25 | ) |
| 26 | |
| 27 | var _ android.ImageInterface = (*Module)(nil) |
| 28 | |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 29 | type ImageVariantType string |
Inseob Kim | 74d2556 | 2020-08-04 00:41:38 +0900 | [diff] [blame] | 30 | |
| 31 | const ( |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 32 | coreImageVariant ImageVariantType = "core" |
| 33 | vendorImageVariant ImageVariantType = "vendor" |
| 34 | productImageVariant ImageVariantType = "product" |
| 35 | ramdiskImageVariant ImageVariantType = "ramdisk" |
| 36 | vendorRamdiskImageVariant ImageVariantType = "vendor_ramdisk" |
| 37 | recoveryImageVariant ImageVariantType = "recovery" |
| 38 | hostImageVariant ImageVariantType = "host" |
Inseob Kim | 74d2556 | 2020-08-04 00:41:38 +0900 | [diff] [blame] | 39 | ) |
| 40 | |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 41 | const ( |
| 42 | // VendorVariationPrefix is the variant prefix used for /vendor code that compiles |
| 43 | // against the VNDK. |
| 44 | VendorVariationPrefix = "vendor." |
| 45 | |
| 46 | // ProductVariationPrefix is the variant prefix used for /product code that compiles |
| 47 | // against the VNDK. |
| 48 | ProductVariationPrefix = "product." |
| 49 | ) |
| 50 | |
| 51 | func (ctx *moduleContext) ProductSpecific() bool { |
Justin Yun | 7f99ec7 | 2021-04-12 13:19:28 +0900 | [diff] [blame^] | 52 | return ctx.ModuleContext.ProductSpecific() || ctx.mod.productSpecificModuleContext() |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | func (ctx *moduleContext) SocSpecific() bool { |
Justin Yun | 7f99ec7 | 2021-04-12 13:19:28 +0900 | [diff] [blame^] | 56 | return ctx.ModuleContext.SocSpecific() || ctx.mod.socSpecificModuleContext() |
Justin Yun | ebcf0c5 | 2021-01-08 18:00:19 +0900 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | func (ctx *moduleContext) DeviceSpecific() bool { |
Justin Yun | 7f99ec7 | 2021-04-12 13:19:28 +0900 | [diff] [blame^] | 60 | return ctx.ModuleContext.DeviceSpecific() || ctx.mod.deviceSpecificModuleContext() |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | func (ctx *moduleContextImpl) inProduct() bool { |
Ivan Lozano | f9e2172 | 2020-12-02 09:00:51 -0500 | [diff] [blame] | 64 | return ctx.mod.InProduct() |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | func (ctx *moduleContextImpl) inVendor() bool { |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 68 | return ctx.mod.InVendor() |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | func (ctx *moduleContextImpl) inRamdisk() bool { |
| 72 | return ctx.mod.InRamdisk() |
| 73 | } |
| 74 | |
Yifan Hong | 60e0cfb | 2020-10-21 15:17:56 -0700 | [diff] [blame] | 75 | func (ctx *moduleContextImpl) inVendorRamdisk() bool { |
| 76 | return ctx.mod.InVendorRamdisk() |
| 77 | } |
| 78 | |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 79 | func (ctx *moduleContextImpl) inRecovery() bool { |
| 80 | return ctx.mod.InRecovery() |
| 81 | } |
| 82 | |
Justin Yun | 7f99ec7 | 2021-04-12 13:19:28 +0900 | [diff] [blame^] | 83 | func (c *Module) productSpecificModuleContext() bool { |
| 84 | // Additionally check if this module is inProduct() that means it is a "product" variant of a |
| 85 | // module. As well as product specific modules, product variants must be installed to /product. |
| 86 | return c.InProduct() |
| 87 | } |
| 88 | |
| 89 | func (c *Module) socSpecificModuleContext() bool { |
| 90 | // Additionally check if this module is inVendor() that means it is a "vendor" variant of a |
| 91 | // module. As well as SoC specific modules, vendor variants must be installed to /vendor |
| 92 | // unless they have "odm_available: true". |
| 93 | return c.HasVendorVariant() && c.InVendor() && !c.VendorVariantToOdm() |
| 94 | } |
| 95 | |
| 96 | func (c *Module) deviceSpecificModuleContext() bool { |
| 97 | // Some vendor variants want to be installed to /odm by setting "odm_available: true". |
| 98 | return c.InVendor() && c.VendorVariantToOdm() |
| 99 | } |
| 100 | |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 101 | // 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] | 102 | func (c *Module) HasVendorVariant() bool { |
Justin Yun | ebcf0c5 | 2021-01-08 18:00:19 +0900 | [diff] [blame] | 103 | return Bool(c.VendorProperties.Vendor_available) || Bool(c.VendorProperties.Odm_available) |
| 104 | } |
| 105 | |
| 106 | // Returns true when this module creates a vendor variant and wants to install the vendor variant |
| 107 | // to the odm partition. |
| 108 | func (c *Module) VendorVariantToOdm() bool { |
| 109 | return Bool(c.VendorProperties.Odm_available) |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 110 | } |
| 111 | |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 112 | // Returns true when this module is configured to have core and product variants. |
| 113 | func (c *Module) HasProductVariant() bool { |
Justin Yun | c0d8c49 | 2021-01-07 17:45:31 +0900 | [diff] [blame] | 114 | return Bool(c.VendorProperties.Product_available) |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | // Returns true when this module is configured to have core and either product or vendor variants. |
| 118 | func (c *Module) HasNonSystemVariants() bool { |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 119 | return c.HasVendorVariant() || c.HasProductVariant() |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 120 | } |
| 121 | |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 122 | // 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] | 123 | func (c *Module) InProduct() bool { |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 124 | return c.Properties.ImageVariationPrefix == ProductVariationPrefix |
| 125 | } |
| 126 | |
| 127 | // 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] | 128 | func (c *Module) InVendor() bool { |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 129 | return c.Properties.ImageVariationPrefix == VendorVariationPrefix |
| 130 | } |
| 131 | |
| 132 | func (c *Module) InRamdisk() bool { |
| 133 | return c.ModuleBase.InRamdisk() || c.ModuleBase.InstallInRamdisk() |
| 134 | } |
| 135 | |
Yifan Hong | 60e0cfb | 2020-10-21 15:17:56 -0700 | [diff] [blame] | 136 | func (c *Module) InVendorRamdisk() bool { |
| 137 | return c.ModuleBase.InVendorRamdisk() || c.ModuleBase.InstallInVendorRamdisk() |
| 138 | } |
| 139 | |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 140 | func (c *Module) InRecovery() bool { |
| 141 | return c.ModuleBase.InRecovery() || c.ModuleBase.InstallInRecovery() |
| 142 | } |
| 143 | |
| 144 | func (c *Module) OnlyInRamdisk() bool { |
| 145 | return c.ModuleBase.InstallInRamdisk() |
| 146 | } |
| 147 | |
Yifan Hong | 60e0cfb | 2020-10-21 15:17:56 -0700 | [diff] [blame] | 148 | func (c *Module) OnlyInVendorRamdisk() bool { |
| 149 | return c.ModuleBase.InstallInVendorRamdisk() |
| 150 | } |
| 151 | |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 152 | func (c *Module) OnlyInRecovery() bool { |
| 153 | return c.ModuleBase.InstallInRecovery() |
| 154 | } |
| 155 | |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 156 | func visitPropsAndCompareVendorAndProductProps(v reflect.Value) bool { |
| 157 | if v.Kind() != reflect.Struct { |
| 158 | return true |
| 159 | } |
| 160 | for i := 0; i < v.NumField(); i++ { |
| 161 | prop := v.Field(i) |
| 162 | if prop.Kind() == reflect.Struct && v.Type().Field(i).Name == "Target" { |
| 163 | vendor_prop := prop.FieldByName("Vendor") |
| 164 | product_prop := prop.FieldByName("Product") |
| 165 | if vendor_prop.Kind() != reflect.Struct && product_prop.Kind() != reflect.Struct { |
| 166 | // Neither Target.Vendor nor Target.Product is defined |
| 167 | continue |
| 168 | } |
| 169 | if vendor_prop.Kind() != reflect.Struct || product_prop.Kind() != reflect.Struct || |
| 170 | !reflect.DeepEqual(vendor_prop.Interface(), product_prop.Interface()) { |
| 171 | // If only one of either Target.Vendor or Target.Product is |
| 172 | // defined or they have different values, it fails the build |
| 173 | // since VNDK must have the same properties for both vendor |
| 174 | // and product variants. |
| 175 | return false |
| 176 | } |
| 177 | } else if !visitPropsAndCompareVendorAndProductProps(prop) { |
| 178 | // Visit the substructures to find Target.Vendor and Target.Product |
| 179 | return false |
| 180 | } |
| 181 | } |
| 182 | return true |
| 183 | } |
| 184 | |
| 185 | // In the case of VNDK, vendor and product variants must have the same properties. |
| 186 | // VNDK installs only one file and shares it for both vendor and product modules on |
| 187 | // runtime. We may not define different versions of a VNDK lib for each partition. |
| 188 | // This function is used only for the VNDK modules that is available to both vendor |
| 189 | // and product partitions. |
| 190 | func (c *Module) compareVendorAndProductProps() bool { |
Justin Yun | c0d8c49 | 2021-01-07 17:45:31 +0900 | [diff] [blame] | 191 | if !c.IsVndk() && !Bool(c.VendorProperties.Product_available) { |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 192 | panic(fmt.Errorf("This is only for product available VNDK libs. %q is not a VNDK library or not product available", c.Name())) |
| 193 | } |
| 194 | for _, properties := range c.GetProperties() { |
| 195 | if !visitPropsAndCompareVendorAndProductProps(reflect.ValueOf(properties).Elem()) { |
| 196 | return false |
| 197 | } |
| 198 | } |
| 199 | return true |
| 200 | } |
| 201 | |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 202 | func (m *Module) ImageMutatorBegin(mctx android.BaseModuleContext) { |
| 203 | // Validation check |
| 204 | vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific() |
| 205 | productSpecific := mctx.ProductSpecific() |
| 206 | |
Justin Yun | c0d8c49 | 2021-01-07 17:45:31 +0900 | [diff] [blame] | 207 | if Bool(m.VendorProperties.Vendor_available) { |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 208 | if vendorSpecific { |
| 209 | mctx.PropertyErrorf("vendor_available", |
Justin Yun | ebcf0c5 | 2021-01-08 18:00:19 +0900 | [diff] [blame] | 210 | "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific: true`") |
| 211 | } |
| 212 | if Bool(m.VendorProperties.Odm_available) { |
| 213 | mctx.PropertyErrorf("vendor_available", |
| 214 | "doesn't make sense at the same time as `odm_available: true`") |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | if Bool(m.VendorProperties.Odm_available) { |
| 219 | if vendorSpecific { |
| 220 | mctx.PropertyErrorf("odm_available", |
| 221 | "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific: true`") |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 222 | } |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 223 | } |
| 224 | |
Justin Yun | c0d8c49 | 2021-01-07 17:45:31 +0900 | [diff] [blame] | 225 | if Bool(m.VendorProperties.Product_available) { |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 226 | if productSpecific { |
| 227 | mctx.PropertyErrorf("product_available", |
| 228 | "doesn't make sense at the same time as `product_specific: true`") |
| 229 | } |
| 230 | if vendorSpecific { |
| 231 | mctx.PropertyErrorf("product_available", |
| 232 | "cannot provide product variant from a vendor module. Please use `product_specific: true` with `vendor_available: true`") |
| 233 | } |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | if vndkdep := m.vndkdep; vndkdep != nil { |
| 237 | if vndkdep.isVndk() { |
| 238 | if vendorSpecific || productSpecific { |
| 239 | if !vndkdep.isVndkExt() { |
| 240 | mctx.PropertyErrorf("vndk", |
| 241 | "must set `extends: \"...\"` to vndk extension") |
Justin Yun | c0d8c49 | 2021-01-07 17:45:31 +0900 | [diff] [blame] | 242 | } else if Bool(m.VendorProperties.Vendor_available) { |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 243 | mctx.PropertyErrorf("vendor_available", |
| 244 | "must not set at the same time as `vndk: {extends: \"...\"}`") |
Justin Yun | c0d8c49 | 2021-01-07 17:45:31 +0900 | [diff] [blame] | 245 | } else if Bool(m.VendorProperties.Product_available) { |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 246 | mctx.PropertyErrorf("product_available", |
| 247 | "must not set at the same time as `vndk: {extends: \"...\"}`") |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 248 | } |
| 249 | } else { |
| 250 | if vndkdep.isVndkExt() { |
| 251 | mctx.PropertyErrorf("vndk", |
| 252 | "must set `vendor: true` or `product_specific: true` to set `extends: %q`", |
| 253 | m.getVndkExtendsModuleName()) |
| 254 | } |
Justin Yun | c0d8c49 | 2021-01-07 17:45:31 +0900 | [diff] [blame] | 255 | if !Bool(m.VendorProperties.Vendor_available) { |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 256 | mctx.PropertyErrorf("vndk", |
Justin Yun | c0d8c49 | 2021-01-07 17:45:31 +0900 | [diff] [blame] | 257 | "vendor_available must be set to true when `vndk: {enabled: true}`") |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 258 | } |
Justin Yun | c0d8c49 | 2021-01-07 17:45:31 +0900 | [diff] [blame] | 259 | if Bool(m.VendorProperties.Product_available) { |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 260 | // If a VNDK module creates both product and vendor variants, they |
| 261 | // must have the same properties since they share a single VNDK |
| 262 | // library on runtime. |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 263 | if !m.compareVendorAndProductProps() { |
| 264 | mctx.ModuleErrorf("product properties must have the same values with the vendor properties for VNDK modules") |
| 265 | } |
| 266 | } |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 267 | } |
| 268 | } else { |
| 269 | if vndkdep.isVndkSp() { |
| 270 | mctx.PropertyErrorf("vndk", |
| 271 | "must set `enabled: true` to set `support_system_process: true`") |
| 272 | } |
| 273 | if vndkdep.isVndkExt() { |
| 274 | mctx.PropertyErrorf("vndk", |
| 275 | "must set `enabled: true` to set `extends: %q`", |
| 276 | m.getVndkExtendsModuleName()) |
| 277 | } |
| 278 | } |
| 279 | } |
| 280 | |
| 281 | var coreVariantNeeded bool = false |
| 282 | var ramdiskVariantNeeded bool = false |
Yifan Hong | 60e0cfb | 2020-10-21 15:17:56 -0700 | [diff] [blame] | 283 | var vendorRamdiskVariantNeeded bool = false |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 284 | var recoveryVariantNeeded bool = false |
| 285 | |
| 286 | var vendorVariants []string |
| 287 | var productVariants []string |
| 288 | |
| 289 | platformVndkVersion := mctx.DeviceConfig().PlatformVndkVersion() |
| 290 | boardVndkVersion := mctx.DeviceConfig().VndkVersion() |
| 291 | productVndkVersion := mctx.DeviceConfig().ProductVndkVersion() |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 292 | recoverySnapshotVersion := mctx.DeviceConfig().RecoverySnapshotVersion() |
| 293 | usingRecoverySnapshot := recoverySnapshotVersion != "current" && |
| 294 | recoverySnapshotVersion != "" |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 295 | if boardVndkVersion == "current" { |
| 296 | boardVndkVersion = platformVndkVersion |
| 297 | } |
| 298 | if productVndkVersion == "current" { |
| 299 | productVndkVersion = platformVndkVersion |
| 300 | } |
| 301 | |
Colin Cross | b5f6fa6 | 2021-01-06 17:05:04 -0800 | [diff] [blame] | 302 | _, isLLNDKLibrary := m.linker.(*llndkStubDecorator) |
| 303 | _, isLLNDKHeaders := m.linker.(*llndkHeadersDecorator) |
| 304 | lib := moduleLibraryInterface(m) |
| 305 | hasLLNDKStubs := lib != nil && lib.hasLLNDKStubs() |
| 306 | |
| 307 | if isLLNDKLibrary || isLLNDKHeaders || hasLLNDKStubs { |
| 308 | // This is an LLNDK library. The implementation of the library will be on /system, |
| 309 | // and vendor and product variants will be created with LLNDK stubs. |
| 310 | // The LLNDK libraries need vendor variants even if there is no VNDK. |
| 311 | // The obsolete llndk_library and llndk_headers modules also need the vendor variants |
| 312 | // so the cc_library LLNDK stubs can depend on them. |
| 313 | if hasLLNDKStubs { |
| 314 | coreVariantNeeded = true |
| 315 | } |
| 316 | if platformVndkVersion != "" { |
| 317 | vendorVariants = append(vendorVariants, platformVndkVersion) |
| 318 | productVariants = append(productVariants, platformVndkVersion) |
| 319 | } |
| 320 | if boardVndkVersion != "" { |
| 321 | vendorVariants = append(vendorVariants, boardVndkVersion) |
| 322 | } |
| 323 | if productVndkVersion != "" { |
| 324 | productVariants = append(productVariants, productVndkVersion) |
| 325 | } |
| 326 | } else if boardVndkVersion == "" { |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 327 | // If the device isn't compiling against the VNDK, we always |
| 328 | // use the core mode. |
| 329 | coreVariantNeeded = true |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 330 | } else if m.isSnapshotPrebuilt() { |
| 331 | // Make vendor variants only for the versions in BOARD_VNDK_VERSION and |
| 332 | // PRODUCT_EXTRA_VNDK_VERSIONS. |
Colin Cross | a889080 | 2021-01-22 14:06:33 -0800 | [diff] [blame] | 333 | if snapshot, ok := m.linker.(snapshotInterface); ok { |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 334 | if m.InstallInRecovery() { |
| 335 | recoveryVariantNeeded = true |
| 336 | } else { |
| 337 | vendorVariants = append(vendorVariants, snapshot.version()) |
| 338 | } |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 339 | } else { |
| 340 | mctx.ModuleErrorf("version is unknown for snapshot prebuilt") |
| 341 | } |
Ivan Lozano | f9e2172 | 2020-12-02 09:00:51 -0500 | [diff] [blame] | 342 | } else if m.HasNonSystemVariants() && !m.IsVndkExt() { |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 343 | // This will be available to /system unless it is product_specific |
| 344 | // which will be handled later. |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 345 | coreVariantNeeded = true |
| 346 | |
| 347 | // We assume that modules under proprietary paths are compatible for |
| 348 | // BOARD_VNDK_VERSION. The other modules are regarded as AOSP, or |
| 349 | // PLATFORM_VNDK_VERSION. |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 350 | if m.HasVendorVariant() { |
| 351 | if isVendorProprietaryModule(mctx) { |
| 352 | vendorVariants = append(vendorVariants, boardVndkVersion) |
| 353 | } else { |
| 354 | vendorVariants = append(vendorVariants, platformVndkVersion) |
| 355 | } |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 356 | } |
| 357 | |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 358 | // product_available modules are available to /product. |
| 359 | if m.HasProductVariant() { |
| 360 | productVariants = append(productVariants, platformVndkVersion) |
| 361 | // VNDK is always PLATFORM_VNDK_VERSION |
| 362 | if !m.IsVndk() { |
| 363 | productVariants = append(productVariants, productVndkVersion) |
| 364 | } |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 365 | } |
| 366 | } else if vendorSpecific && String(m.Properties.Sdk_version) == "" { |
| 367 | // This will be available in /vendor (or /odm) only |
| 368 | |
| 369 | // kernel_headers is a special module type whose exported headers |
| 370 | // are coming from DeviceKernelHeaders() which is always vendor |
| 371 | // dependent. They'll always have both vendor variants. |
| 372 | // For other modules, we assume that modules under proprietary |
| 373 | // paths are compatible for BOARD_VNDK_VERSION. The other modules |
| 374 | // are regarded as AOSP, which is PLATFORM_VNDK_VERSION. |
| 375 | if _, ok := m.linker.(*kernelHeadersDecorator); ok { |
| 376 | vendorVariants = append(vendorVariants, |
| 377 | platformVndkVersion, |
| 378 | boardVndkVersion, |
| 379 | ) |
Bill Peckham | 945441c | 2020-08-31 16:07:58 -0700 | [diff] [blame] | 380 | } else if isVendorProprietaryModule(mctx) { |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 381 | vendorVariants = append(vendorVariants, boardVndkVersion) |
| 382 | } else { |
| 383 | vendorVariants = append(vendorVariants, platformVndkVersion) |
| 384 | } |
| 385 | } else { |
| 386 | // This is either in /system (or similar: /data), or is a |
| 387 | // modules built with the NDK. Modules built with the NDK |
| 388 | // will be restricted using the existing link type checks. |
| 389 | coreVariantNeeded = true |
| 390 | } |
| 391 | |
| 392 | if boardVndkVersion != "" && productVndkVersion != "" { |
| 393 | if coreVariantNeeded && productSpecific && String(m.Properties.Sdk_version) == "" { |
| 394 | // The module has "product_specific: true" that does not create core variant. |
| 395 | coreVariantNeeded = false |
| 396 | productVariants = append(productVariants, productVndkVersion) |
| 397 | } |
| 398 | } else { |
| 399 | // Unless PRODUCT_PRODUCT_VNDK_VERSION is set, product partition has no |
| 400 | // restriction to use system libs. |
| 401 | // No product variants defined in this case. |
| 402 | productVariants = []string{} |
| 403 | } |
| 404 | |
| 405 | if Bool(m.Properties.Ramdisk_available) { |
| 406 | ramdiskVariantNeeded = true |
| 407 | } |
| 408 | |
| 409 | if m.ModuleBase.InstallInRamdisk() { |
| 410 | ramdiskVariantNeeded = true |
| 411 | coreVariantNeeded = false |
| 412 | } |
| 413 | |
Yifan Hong | 60e0cfb | 2020-10-21 15:17:56 -0700 | [diff] [blame] | 414 | if Bool(m.Properties.Vendor_ramdisk_available) { |
| 415 | vendorRamdiskVariantNeeded = true |
| 416 | } |
| 417 | |
| 418 | if m.ModuleBase.InstallInVendorRamdisk() { |
| 419 | vendorRamdiskVariantNeeded = true |
| 420 | coreVariantNeeded = false |
| 421 | } |
| 422 | |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 423 | if Bool(m.Properties.Recovery_available) { |
| 424 | recoveryVariantNeeded = true |
| 425 | } |
| 426 | |
| 427 | if m.ModuleBase.InstallInRecovery() { |
| 428 | recoveryVariantNeeded = true |
| 429 | coreVariantNeeded = false |
| 430 | } |
| 431 | |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 432 | // If using a snapshot, the recovery variant under AOSP directories is not needed, |
| 433 | // except for kernel headers, which needs all variants. |
| 434 | if _, ok := m.linker.(*kernelHeadersDecorator); !ok && |
| 435 | !m.isSnapshotPrebuilt() && |
| 436 | usingRecoverySnapshot && |
| 437 | !isRecoveryProprietaryModule(mctx) { |
| 438 | recoveryVariantNeeded = false |
| 439 | } |
| 440 | |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 441 | for _, variant := range android.FirstUniqueStrings(vendorVariants) { |
| 442 | m.Properties.ExtraVariants = append(m.Properties.ExtraVariants, VendorVariationPrefix+variant) |
| 443 | } |
| 444 | |
| 445 | for _, variant := range android.FirstUniqueStrings(productVariants) { |
| 446 | m.Properties.ExtraVariants = append(m.Properties.ExtraVariants, ProductVariationPrefix+variant) |
| 447 | } |
| 448 | |
| 449 | m.Properties.RamdiskVariantNeeded = ramdiskVariantNeeded |
Yifan Hong | 60e0cfb | 2020-10-21 15:17:56 -0700 | [diff] [blame] | 450 | m.Properties.VendorRamdiskVariantNeeded = vendorRamdiskVariantNeeded |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 451 | m.Properties.RecoveryVariantNeeded = recoveryVariantNeeded |
| 452 | m.Properties.CoreVariantNeeded = coreVariantNeeded |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 453 | |
| 454 | // Disable the module if no variants are needed. |
| 455 | if !ramdiskVariantNeeded && |
| 456 | !recoveryVariantNeeded && |
| 457 | !coreVariantNeeded && |
| 458 | len(m.Properties.ExtraVariants) == 0 { |
| 459 | m.Disable() |
| 460 | } |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 461 | } |
| 462 | |
| 463 | func (c *Module) CoreVariantNeeded(ctx android.BaseModuleContext) bool { |
| 464 | return c.Properties.CoreVariantNeeded |
| 465 | } |
| 466 | |
| 467 | func (c *Module) RamdiskVariantNeeded(ctx android.BaseModuleContext) bool { |
| 468 | return c.Properties.RamdiskVariantNeeded |
| 469 | } |
| 470 | |
Yifan Hong | 60e0cfb | 2020-10-21 15:17:56 -0700 | [diff] [blame] | 471 | func (c *Module) VendorRamdiskVariantNeeded(ctx android.BaseModuleContext) bool { |
| 472 | return c.Properties.VendorRamdiskVariantNeeded |
| 473 | } |
| 474 | |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 475 | func (c *Module) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool { |
| 476 | return c.Properties.RecoveryVariantNeeded |
| 477 | } |
| 478 | |
| 479 | func (c *Module) ExtraImageVariations(ctx android.BaseModuleContext) []string { |
| 480 | return c.Properties.ExtraVariants |
| 481 | } |
| 482 | |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 483 | func squashVendorSrcs(m *Module) { |
| 484 | if lib, ok := m.compiler.(*libraryDecorator); ok { |
| 485 | lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs, |
| 486 | lib.baseCompiler.Properties.Target.Vendor.Srcs...) |
| 487 | |
| 488 | lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs, |
| 489 | lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...) |
| 490 | |
| 491 | lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources, |
| 492 | lib.baseCompiler.Properties.Target.Vendor.Exclude_generated_sources...) |
| 493 | } |
| 494 | } |
| 495 | |
| 496 | func squashProductSrcs(m *Module) { |
| 497 | if lib, ok := m.compiler.(*libraryDecorator); ok { |
| 498 | lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs, |
| 499 | lib.baseCompiler.Properties.Target.Product.Srcs...) |
| 500 | |
| 501 | lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs, |
| 502 | lib.baseCompiler.Properties.Target.Product.Exclude_srcs...) |
| 503 | |
| 504 | lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources, |
| 505 | lib.baseCompiler.Properties.Target.Product.Exclude_generated_sources...) |
| 506 | } |
| 507 | } |
| 508 | |
| 509 | func squashRecoverySrcs(m *Module) { |
| 510 | if lib, ok := m.compiler.(*libraryDecorator); ok { |
| 511 | lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs, |
| 512 | lib.baseCompiler.Properties.Target.Recovery.Srcs...) |
| 513 | |
| 514 | lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs, |
| 515 | lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...) |
| 516 | |
| 517 | lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources, |
| 518 | lib.baseCompiler.Properties.Target.Recovery.Exclude_generated_sources...) |
| 519 | } |
| 520 | } |
| 521 | |
| 522 | func squashVendorRamdiskSrcs(m *Module) { |
| 523 | if lib, ok := m.compiler.(*libraryDecorator); ok { |
| 524 | lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs, lib.baseCompiler.Properties.Target.Vendor_ramdisk.Exclude_srcs...) |
| 525 | } |
| 526 | } |
| 527 | |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 528 | func (c *Module) SetImageVariation(ctx android.BaseModuleContext, variant string, module android.Module) { |
| 529 | m := module.(*Module) |
Yifan Hong | 6da33c2 | 2020-10-27 15:01:21 -0700 | [diff] [blame] | 530 | if variant == android.RamdiskVariation { |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 531 | m.MakeAsPlatform() |
Yifan Hong | 6da33c2 | 2020-10-27 15:01:21 -0700 | [diff] [blame] | 532 | } else if variant == android.VendorRamdiskVariation { |
| 533 | m.MakeAsPlatform() |
| 534 | squashVendorRamdiskSrcs(m) |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 535 | } else if variant == android.RecoveryVariation { |
| 536 | m.MakeAsPlatform() |
| 537 | squashRecoverySrcs(m) |
| 538 | } else if strings.HasPrefix(variant, VendorVariationPrefix) { |
| 539 | m.Properties.ImageVariationPrefix = VendorVariationPrefix |
| 540 | m.Properties.VndkVersion = strings.TrimPrefix(variant, VendorVariationPrefix) |
| 541 | squashVendorSrcs(m) |
| 542 | |
| 543 | // Makefile shouldn't know vendor modules other than BOARD_VNDK_VERSION. |
| 544 | // Hide other vendor variants to avoid collision. |
| 545 | vndkVersion := ctx.DeviceConfig().VndkVersion() |
| 546 | if vndkVersion != "current" && vndkVersion != "" && vndkVersion != m.Properties.VndkVersion { |
| 547 | m.Properties.HideFromMake = true |
Colin Cross | a9c8c9f | 2020-12-16 10:20:23 -0800 | [diff] [blame] | 548 | m.HideFromMake() |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 549 | } |
| 550 | } else if strings.HasPrefix(variant, ProductVariationPrefix) { |
| 551 | m.Properties.ImageVariationPrefix = ProductVariationPrefix |
| 552 | m.Properties.VndkVersion = strings.TrimPrefix(variant, ProductVariationPrefix) |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 553 | squashProductSrcs(m) |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 554 | } |
| 555 | } |