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