blob: 3668e2bea926482ba05012cb09c6e6340476b407 [file] [log] [blame]
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001// Copyright 2017 Google Inc. All rights reserved.
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
15package cc
16
17import (
18 "android/soong/android"
19 "android/soong/genrule"
20)
21
22func init() {
23 android.RegisterModuleType("cc_genrule", genRuleFactory)
24}
25
Jiyong Park3f736c92018-05-24 13:36:56 +090026type GenruleExtraProperties struct {
Yifan Hong60e0cfb2020-10-21 15:17:56 -070027 Vendor_available *bool
Justin Yun63e9ec72020-10-29 16:49:43 +090028 Product_available *bool
Yifan Hong60e0cfb2020-10-21 15:17:56 -070029 Ramdisk_available *bool
30 Vendor_ramdisk_available *bool
31 Recovery_available *bool
32 Sdk_version *string
Jiyong Park3f736c92018-05-24 13:36:56 +090033}
34
Dan Willemsen3e5bdf22017-09-13 18:37:08 -070035// cc_genrule is a genrule that can depend on other cc_* objects.
36// The cmd may be run multiple times, once for each of the different arch/etc
37// variations.
38func genRuleFactory() android.Module {
39 module := genrule.NewGenRule()
40
Colin Cross7228ecd2019-11-18 16:00:16 -080041 extra := &GenruleExtraProperties{}
42 module.Extra = extra
43 module.ImageInterface = extra
Dan Willemsen3e5bdf22017-09-13 18:37:08 -070044 module.AddProperties(module.Extra)
45
46 android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibBoth)
47
Jiyong Parkfc752ca2019-06-12 13:27:29 +090048 android.InitApexModule(module)
49
Dan Willemsen3e5bdf22017-09-13 18:37:08 -070050 return module
51}
Colin Cross7228ecd2019-11-18 16:00:16 -080052
53var _ android.ImageInterface = (*GenruleExtraProperties)(nil)
54
55func (g *GenruleExtraProperties) ImageMutatorBegin(ctx android.BaseModuleContext) {}
56
57func (g *GenruleExtraProperties) CoreVariantNeeded(ctx android.BaseModuleContext) bool {
58 if ctx.DeviceConfig().VndkVersion() == "" {
59 return true
60 }
61
Justin Yun5f7f7e82019-11-18 19:52:14 +090062 if ctx.DeviceConfig().ProductVndkVersion() != "" && ctx.ProductSpecific() {
63 return false
64 }
65
Justin Yun63e9ec72020-10-29 16:49:43 +090066 return Bool(g.Vendor_available) || Bool(g.Product_available) || !(ctx.SocSpecific() || ctx.DeviceSpecific())
Colin Cross7228ecd2019-11-18 16:00:16 -080067}
68
Yifan Hong1b3348d2020-01-21 15:53:22 -080069func (g *GenruleExtraProperties) RamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
70 return Bool(g.Ramdisk_available)
71}
72
Yifan Hong60e0cfb2020-10-21 15:17:56 -070073func (g *GenruleExtraProperties) VendorRamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
74 return Bool(g.Vendor_ramdisk_available)
75}
76
Colin Cross7228ecd2019-11-18 16:00:16 -080077func (g *GenruleExtraProperties) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool {
Colin Crossfb0c16e2019-11-20 17:12:35 -080078 return Bool(g.Recovery_available)
Colin Cross7228ecd2019-11-18 16:00:16 -080079}
80
81func (g *GenruleExtraProperties) ExtraImageVariations(ctx android.BaseModuleContext) []string {
82 if ctx.DeviceConfig().VndkVersion() == "" {
83 return nil
84 }
85
Justin Yun5f7f7e82019-11-18 19:52:14 +090086 var variants []string
Colin Cross7228ecd2019-11-18 16:00:16 -080087 if Bool(g.Vendor_available) || ctx.SocSpecific() || ctx.DeviceSpecific() {
Inseob Kim85708802020-06-02 00:06:15 +090088 vndkVersion := ctx.DeviceConfig().VndkVersion()
89 // If vndkVersion is current, we can always use PlatformVndkVersion.
90 // If not, we assume modules under proprietary paths are compatible for
91 // BOARD_VNDK_VERSION. The other modules are regarded as AOSP, that is
92 // PLATFORM_VNDK_VERSION.
Bill Peckham945441c2020-08-31 16:07:58 -070093 if vndkVersion == "current" || !isVendorProprietaryModule(ctx) {
Inseob Kim85708802020-06-02 00:06:15 +090094 variants = append(variants, VendorVariationPrefix+ctx.DeviceConfig().PlatformVndkVersion())
95 } else {
Colin Cross7228ecd2019-11-18 16:00:16 -080096 variants = append(variants, VendorVariationPrefix+vndkVersion)
97 }
Justin Yun5f7f7e82019-11-18 19:52:14 +090098 }
99
100 if ctx.DeviceConfig().ProductVndkVersion() == "" {
Colin Cross7228ecd2019-11-18 16:00:16 -0800101 return variants
102 }
103
Justin Yun63e9ec72020-10-29 16:49:43 +0900104 // TODO(b/150902910): vendor_available will not create product variant. Remove Bool(g.Vendor_available)
105 if Bool(g.Vendor_available) || Bool(g.Product_available) || ctx.ProductSpecific() {
Justin Yun5f7f7e82019-11-18 19:52:14 +0900106 variants = append(variants, ProductVariationPrefix+ctx.DeviceConfig().PlatformVndkVersion())
107 if vndkVersion := ctx.DeviceConfig().ProductVndkVersion(); vndkVersion != "current" {
108 variants = append(variants, ProductVariationPrefix+vndkVersion)
109 }
110 }
111
112 return variants
Colin Cross7228ecd2019-11-18 16:00:16 -0800113}
114
115func (g *GenruleExtraProperties) SetImageVariation(ctx android.BaseModuleContext, variation string, module android.Module) {
116}