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