1*333d2b36SAndroid Build Coastguard Worker// Copyright (C) 2019 The Android Open Source Project 2*333d2b36SAndroid Build Coastguard Worker// 3*333d2b36SAndroid Build Coastguard Worker// Licensed under the Apache License, Version 2.0 (the "License"); 4*333d2b36SAndroid Build Coastguard Worker// you may not use this file except in compliance with the License. 5*333d2b36SAndroid Build Coastguard Worker// You may obtain a copy of the License at 6*333d2b36SAndroid Build Coastguard Worker// 7*333d2b36SAndroid Build Coastguard Worker// http://www.apache.org/licenses/LICENSE-2.0 8*333d2b36SAndroid Build Coastguard Worker// 9*333d2b36SAndroid Build Coastguard Worker// Unless required by applicable law or agreed to in writing, software 10*333d2b36SAndroid Build Coastguard Worker// distributed under the License is distributed on an "AS IS" BASIS, 11*333d2b36SAndroid Build Coastguard Worker// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12*333d2b36SAndroid Build Coastguard Worker// See the License for the specific language governing permissions and 13*333d2b36SAndroid Build Coastguard Worker// limitations under the License. 14*333d2b36SAndroid Build Coastguard Worker 15*333d2b36SAndroid Build Coastguard Workerpackage android 16*333d2b36SAndroid Build Coastguard Worker 17*333d2b36SAndroid Build Coastguard Workerimport ( 18*333d2b36SAndroid Build Coastguard Worker "fmt" 19*333d2b36SAndroid Build Coastguard Worker "sort" 20*333d2b36SAndroid Build Coastguard Worker "strings" 21*333d2b36SAndroid Build Coastguard Worker 22*333d2b36SAndroid Build Coastguard Worker "github.com/google/blueprint" 23*333d2b36SAndroid Build Coastguard Worker "github.com/google/blueprint/proptools" 24*333d2b36SAndroid Build Coastguard Worker) 25*333d2b36SAndroid Build Coastguard Worker 26*333d2b36SAndroid Build Coastguard Worker// minApiLevelForSdkSnapshot provides access to the min_sdk_version for MinApiLevelForSdkSnapshot 27*333d2b36SAndroid Build Coastguard Workertype minApiLevelForSdkSnapshot interface { 28*333d2b36SAndroid Build Coastguard Worker MinSdkVersion(ctx EarlyModuleContext) ApiLevel 29*333d2b36SAndroid Build Coastguard Worker} 30*333d2b36SAndroid Build Coastguard Worker 31*333d2b36SAndroid Build Coastguard Worker// MinApiLevelForSdkSnapshot returns the ApiLevel of the min_sdk_version of the supplied module. 32*333d2b36SAndroid Build Coastguard Worker// 33*333d2b36SAndroid Build Coastguard Worker// If the module does not provide a min_sdk_version then it defaults to 1. 34*333d2b36SAndroid Build Coastguard Workerfunc MinApiLevelForSdkSnapshot(ctx EarlyModuleContext, module Module) ApiLevel { 35*333d2b36SAndroid Build Coastguard Worker minApiLevel := NoneApiLevel 36*333d2b36SAndroid Build Coastguard Worker if m, ok := module.(minApiLevelForSdkSnapshot); ok { 37*333d2b36SAndroid Build Coastguard Worker minApiLevel = m.MinSdkVersion(ctx) 38*333d2b36SAndroid Build Coastguard Worker } 39*333d2b36SAndroid Build Coastguard Worker if minApiLevel == NoneApiLevel { 40*333d2b36SAndroid Build Coastguard Worker // The default min API level is 1. 41*333d2b36SAndroid Build Coastguard Worker minApiLevel = uncheckedFinalApiLevel(1) 42*333d2b36SAndroid Build Coastguard Worker } 43*333d2b36SAndroid Build Coastguard Worker return minApiLevel 44*333d2b36SAndroid Build Coastguard Worker} 45*333d2b36SAndroid Build Coastguard Worker 46*333d2b36SAndroid Build Coastguard Worker// SnapshotBuilder provides support for generating the build rules which will build the snapshot. 47*333d2b36SAndroid Build Coastguard Workertype SnapshotBuilder interface { 48*333d2b36SAndroid Build Coastguard Worker // CopyToSnapshot generates a rule that will copy the src to the dest (which is a snapshot 49*333d2b36SAndroid Build Coastguard Worker // relative path) and add the dest to the zip. 50*333d2b36SAndroid Build Coastguard Worker CopyToSnapshot(src Path, dest string) 51*333d2b36SAndroid Build Coastguard Worker 52*333d2b36SAndroid Build Coastguard Worker // EmptyFile returns the path to an empty file. 53*333d2b36SAndroid Build Coastguard Worker // 54*333d2b36SAndroid Build Coastguard Worker // This can be used by sdk member types that need to create an empty file in the snapshot, simply 55*333d2b36SAndroid Build Coastguard Worker // pass the value returned from this to the CopyToSnapshot() method. 56*333d2b36SAndroid Build Coastguard Worker EmptyFile() Path 57*333d2b36SAndroid Build Coastguard Worker 58*333d2b36SAndroid Build Coastguard Worker // UnzipToSnapshot generates a rule that will unzip the supplied zip into the snapshot relative 59*333d2b36SAndroid Build Coastguard Worker // directory destDir. 60*333d2b36SAndroid Build Coastguard Worker UnzipToSnapshot(zipPath Path, destDir string) 61*333d2b36SAndroid Build Coastguard Worker 62*333d2b36SAndroid Build Coastguard Worker // AddPrebuiltModule adds a new prebuilt module to the snapshot. 63*333d2b36SAndroid Build Coastguard Worker // 64*333d2b36SAndroid Build Coastguard Worker // It is intended to be called from SdkMemberType.AddPrebuiltModule which can add module type 65*333d2b36SAndroid Build Coastguard Worker // specific properties that are not variant specific. The following properties will be 66*333d2b36SAndroid Build Coastguard Worker // automatically populated before returning. 67*333d2b36SAndroid Build Coastguard Worker // 68*333d2b36SAndroid Build Coastguard Worker // * name 69*333d2b36SAndroid Build Coastguard Worker // * sdk_member_name 70*333d2b36SAndroid Build Coastguard Worker // * prefer 71*333d2b36SAndroid Build Coastguard Worker // 72*333d2b36SAndroid Build Coastguard Worker // Properties that are variant specific will be handled by SdkMemberProperties structure. 73*333d2b36SAndroid Build Coastguard Worker // 74*333d2b36SAndroid Build Coastguard Worker // Each module created by this method can be output to the generated Android.bp file in two 75*333d2b36SAndroid Build Coastguard Worker // different forms, depending on the setting of the SOONG_SDK_SNAPSHOT_VERSION build property. 76*333d2b36SAndroid Build Coastguard Worker // The two forms are: 77*333d2b36SAndroid Build Coastguard Worker // 1. A versioned Soong module that is referenced from a corresponding similarly versioned 78*333d2b36SAndroid Build Coastguard Worker // snapshot module. 79*333d2b36SAndroid Build Coastguard Worker // 2. An unversioned Soong module that. 80*333d2b36SAndroid Build Coastguard Worker // 81*333d2b36SAndroid Build Coastguard Worker // See sdk/update.go for more information. 82*333d2b36SAndroid Build Coastguard Worker AddPrebuiltModule(member SdkMember, moduleType string) BpModule 83*333d2b36SAndroid Build Coastguard Worker 84*333d2b36SAndroid Build Coastguard Worker // SdkMemberReferencePropertyTag returns a property tag to use when adding a property to a 85*333d2b36SAndroid Build Coastguard Worker // BpModule that contains references to other sdk members. 86*333d2b36SAndroid Build Coastguard Worker // 87*333d2b36SAndroid Build Coastguard Worker // Using this will ensure that the reference is correctly output for both versioned and 88*333d2b36SAndroid Build Coastguard Worker // unversioned prebuilts in the snapshot. 89*333d2b36SAndroid Build Coastguard Worker // 90*333d2b36SAndroid Build Coastguard Worker // "required: true" means that the property must only contain references to other members of the 91*333d2b36SAndroid Build Coastguard Worker // sdk. Passing a reference to a module that is not a member of the sdk will result in a build 92*333d2b36SAndroid Build Coastguard Worker // error. 93*333d2b36SAndroid Build Coastguard Worker // 94*333d2b36SAndroid Build Coastguard Worker // "required: false" means that the property can contain references to modules that are either 95*333d2b36SAndroid Build Coastguard Worker // members or not members of the sdk. If a reference is to a module that is a non member then the 96*333d2b36SAndroid Build Coastguard Worker // reference is left unchanged, i.e. it is not transformed as references to members are. 97*333d2b36SAndroid Build Coastguard Worker // 98*333d2b36SAndroid Build Coastguard Worker // The handling of the member names is dependent on whether it is an internal or exported member. 99*333d2b36SAndroid Build Coastguard Worker // An exported member is one whose name is specified in one of the member type specific 100*333d2b36SAndroid Build Coastguard Worker // properties. An internal member is one that is added due to being a part of an exported (or 101*333d2b36SAndroid Build Coastguard Worker // other internal) member and is not itself an exported member. 102*333d2b36SAndroid Build Coastguard Worker // 103*333d2b36SAndroid Build Coastguard Worker // Member names are handled as follows: 104*333d2b36SAndroid Build Coastguard Worker // * When creating the unversioned form of the module the name is left unchecked unless the member 105*333d2b36SAndroid Build Coastguard Worker // is internal in which case it is transformed into an sdk specific name, i.e. by prefixing with 106*333d2b36SAndroid Build Coastguard Worker // the sdk name. 107*333d2b36SAndroid Build Coastguard Worker // 108*333d2b36SAndroid Build Coastguard Worker // * When creating the versioned form of the module the name is transformed into a versioned sdk 109*333d2b36SAndroid Build Coastguard Worker // specific name, i.e. by prefixing with the sdk name and suffixing with the version. 110*333d2b36SAndroid Build Coastguard Worker // 111*333d2b36SAndroid Build Coastguard Worker // e.g. 112*333d2b36SAndroid Build Coastguard Worker // bpPropertySet.AddPropertyWithTag("libs", []string{"member1", "member2"}, builder.SdkMemberReferencePropertyTag(true)) 113*333d2b36SAndroid Build Coastguard Worker SdkMemberReferencePropertyTag(required bool) BpPropertyTag 114*333d2b36SAndroid Build Coastguard Worker} 115*333d2b36SAndroid Build Coastguard Worker 116*333d2b36SAndroid Build Coastguard Worker// BpPropertyTag is a marker interface that can be associated with properties in a BpPropertySet to 117*333d2b36SAndroid Build Coastguard Worker// provide additional information which can be used to customize their behavior. 118*333d2b36SAndroid Build Coastguard Workertype BpPropertyTag interface{} 119*333d2b36SAndroid Build Coastguard Worker 120*333d2b36SAndroid Build Coastguard Worker// BpPropertySet is a set of properties for use in a .bp file. 121*333d2b36SAndroid Build Coastguard Workertype BpPropertySet interface { 122*333d2b36SAndroid Build Coastguard Worker // AddProperty adds a property. 123*333d2b36SAndroid Build Coastguard Worker // 124*333d2b36SAndroid Build Coastguard Worker // The value can be one of the following types: 125*333d2b36SAndroid Build Coastguard Worker // * string 126*333d2b36SAndroid Build Coastguard Worker // * array of the above 127*333d2b36SAndroid Build Coastguard Worker // * bool 128*333d2b36SAndroid Build Coastguard Worker // For these types it is an error if multiple properties with the same name 129*333d2b36SAndroid Build Coastguard Worker // are added. 130*333d2b36SAndroid Build Coastguard Worker // 131*333d2b36SAndroid Build Coastguard Worker // * pointer to a struct 132*333d2b36SAndroid Build Coastguard Worker // * BpPropertySet 133*333d2b36SAndroid Build Coastguard Worker // 134*333d2b36SAndroid Build Coastguard Worker // A pointer to a Blueprint-style property struct is first converted into a 135*333d2b36SAndroid Build Coastguard Worker // BpPropertySet by traversing the fields and adding their values as 136*333d2b36SAndroid Build Coastguard Worker // properties in a BpPropertySet. A field with a struct value is itself 137*333d2b36SAndroid Build Coastguard Worker // converted into a BpPropertySet before adding. 138*333d2b36SAndroid Build Coastguard Worker // 139*333d2b36SAndroid Build Coastguard Worker // Adding a BpPropertySet is done as follows: 140*333d2b36SAndroid Build Coastguard Worker // * If no property with the name exists then the BpPropertySet is added 141*333d2b36SAndroid Build Coastguard Worker // directly to this property. Care must be taken to ensure that it does not 142*333d2b36SAndroid Build Coastguard Worker // introduce a cycle. 143*333d2b36SAndroid Build Coastguard Worker // * If a property exists with the name and the current value is a 144*333d2b36SAndroid Build Coastguard Worker // BpPropertySet then every property of the new BpPropertySet is added to 145*333d2b36SAndroid Build Coastguard Worker // the existing BpPropertySet. 146*333d2b36SAndroid Build Coastguard Worker // * Otherwise, if a property exists with the name then it is an error. 147*333d2b36SAndroid Build Coastguard Worker AddProperty(name string, value interface{}) 148*333d2b36SAndroid Build Coastguard Worker 149*333d2b36SAndroid Build Coastguard Worker // AddPropertyWithTag adds a property with an associated property tag. 150*333d2b36SAndroid Build Coastguard Worker AddPropertyWithTag(name string, value interface{}, tag BpPropertyTag) 151*333d2b36SAndroid Build Coastguard Worker 152*333d2b36SAndroid Build Coastguard Worker // AddPropertySet adds a property set with the specified name and returns it so that additional 153*333d2b36SAndroid Build Coastguard Worker // properties can be added to it. 154*333d2b36SAndroid Build Coastguard Worker AddPropertySet(name string) BpPropertySet 155*333d2b36SAndroid Build Coastguard Worker 156*333d2b36SAndroid Build Coastguard Worker // AddCommentForProperty adds a comment for the named property (or property set). 157*333d2b36SAndroid Build Coastguard Worker AddCommentForProperty(name, text string) 158*333d2b36SAndroid Build Coastguard Worker} 159*333d2b36SAndroid Build Coastguard Worker 160*333d2b36SAndroid Build Coastguard Worker// BpModule represents a module definition in a .bp file. 161*333d2b36SAndroid Build Coastguard Workertype BpModule interface { 162*333d2b36SAndroid Build Coastguard Worker BpPropertySet 163*333d2b36SAndroid Build Coastguard Worker 164*333d2b36SAndroid Build Coastguard Worker // ModuleType returns the module type of the module 165*333d2b36SAndroid Build Coastguard Worker ModuleType() string 166*333d2b36SAndroid Build Coastguard Worker 167*333d2b36SAndroid Build Coastguard Worker // Name returns the name of the module or "" if no name has been specified. 168*333d2b36SAndroid Build Coastguard Worker Name() string 169*333d2b36SAndroid Build Coastguard Worker} 170*333d2b36SAndroid Build Coastguard Worker 171*333d2b36SAndroid Build Coastguard Worker// BpPrintable is a marker interface that must be implemented by any struct that is added as a 172*333d2b36SAndroid Build Coastguard Worker// property value. 173*333d2b36SAndroid Build Coastguard Workertype BpPrintable interface { 174*333d2b36SAndroid Build Coastguard Worker bpPrintable() 175*333d2b36SAndroid Build Coastguard Worker} 176*333d2b36SAndroid Build Coastguard Worker 177*333d2b36SAndroid Build Coastguard Worker// BpPrintableBase must be embedded within any struct that is added as a 178*333d2b36SAndroid Build Coastguard Worker// property value. 179*333d2b36SAndroid Build Coastguard Workertype BpPrintableBase struct { 180*333d2b36SAndroid Build Coastguard Worker} 181*333d2b36SAndroid Build Coastguard Worker 182*333d2b36SAndroid Build Coastguard Workerfunc (b BpPrintableBase) bpPrintable() { 183*333d2b36SAndroid Build Coastguard Worker} 184*333d2b36SAndroid Build Coastguard Worker 185*333d2b36SAndroid Build Coastguard Workervar _ BpPrintable = BpPrintableBase{} 186*333d2b36SAndroid Build Coastguard Worker 187*333d2b36SAndroid Build Coastguard Worker// sdkRegisterable defines the interface that must be implemented by objects that can be registered 188*333d2b36SAndroid Build Coastguard Worker// in an sdkRegistry. 189*333d2b36SAndroid Build Coastguard Workertype sdkRegisterable interface { 190*333d2b36SAndroid Build Coastguard Worker // SdkPropertyName returns the name of the corresponding property on an sdk module. 191*333d2b36SAndroid Build Coastguard Worker SdkPropertyName() string 192*333d2b36SAndroid Build Coastguard Worker} 193*333d2b36SAndroid Build Coastguard Worker 194*333d2b36SAndroid Build Coastguard Worker// sdkRegistry provides support for registering and retrieving objects that define properties for 195*333d2b36SAndroid Build Coastguard Worker// use by sdk and module_exports module types. 196*333d2b36SAndroid Build Coastguard Workertype sdkRegistry struct { 197*333d2b36SAndroid Build Coastguard Worker // The list of registered objects sorted by property name. 198*333d2b36SAndroid Build Coastguard Worker list []sdkRegisterable 199*333d2b36SAndroid Build Coastguard Worker} 200*333d2b36SAndroid Build Coastguard Worker 201*333d2b36SAndroid Build Coastguard Worker// copyAndAppend creates a new sdkRegistry that includes all the traits registered in 202*333d2b36SAndroid Build Coastguard Worker// this registry plus the supplied trait. 203*333d2b36SAndroid Build Coastguard Workerfunc (r *sdkRegistry) copyAndAppend(registerable sdkRegisterable) *sdkRegistry { 204*333d2b36SAndroid Build Coastguard Worker oldList := r.list 205*333d2b36SAndroid Build Coastguard Worker 206*333d2b36SAndroid Build Coastguard Worker // Make sure that list does not already contain the property. Uses a simple linear search instead 207*333d2b36SAndroid Build Coastguard Worker // of a binary search even though the list is sorted. That is because the number of items in the 208*333d2b36SAndroid Build Coastguard Worker // list is small and so not worth the overhead of a binary search. 209*333d2b36SAndroid Build Coastguard Worker found := false 210*333d2b36SAndroid Build Coastguard Worker newPropertyName := registerable.SdkPropertyName() 211*333d2b36SAndroid Build Coastguard Worker for _, r := range oldList { 212*333d2b36SAndroid Build Coastguard Worker if r.SdkPropertyName() == newPropertyName { 213*333d2b36SAndroid Build Coastguard Worker found = true 214*333d2b36SAndroid Build Coastguard Worker break 215*333d2b36SAndroid Build Coastguard Worker } 216*333d2b36SAndroid Build Coastguard Worker } 217*333d2b36SAndroid Build Coastguard Worker if found { 218*333d2b36SAndroid Build Coastguard Worker names := []string{} 219*333d2b36SAndroid Build Coastguard Worker for _, r := range oldList { 220*333d2b36SAndroid Build Coastguard Worker names = append(names, r.SdkPropertyName()) 221*333d2b36SAndroid Build Coastguard Worker } 222*333d2b36SAndroid Build Coastguard Worker panic(fmt.Errorf("duplicate properties found, %q already exists in %q", newPropertyName, names)) 223*333d2b36SAndroid Build Coastguard Worker } 224*333d2b36SAndroid Build Coastguard Worker 225*333d2b36SAndroid Build Coastguard Worker // Copy the slice just in case this is being read while being modified, e.g. when testing. 226*333d2b36SAndroid Build Coastguard Worker list := make([]sdkRegisterable, 0, len(oldList)+1) 227*333d2b36SAndroid Build Coastguard Worker list = append(list, oldList...) 228*333d2b36SAndroid Build Coastguard Worker list = append(list, registerable) 229*333d2b36SAndroid Build Coastguard Worker 230*333d2b36SAndroid Build Coastguard Worker // Sort the registered objects by their property name to ensure that registry order has no effect 231*333d2b36SAndroid Build Coastguard Worker // on behavior. 232*333d2b36SAndroid Build Coastguard Worker sort.Slice(list, func(i1, i2 int) bool { 233*333d2b36SAndroid Build Coastguard Worker t1 := list[i1] 234*333d2b36SAndroid Build Coastguard Worker t2 := list[i2] 235*333d2b36SAndroid Build Coastguard Worker 236*333d2b36SAndroid Build Coastguard Worker return t1.SdkPropertyName() < t2.SdkPropertyName() 237*333d2b36SAndroid Build Coastguard Worker }) 238*333d2b36SAndroid Build Coastguard Worker 239*333d2b36SAndroid Build Coastguard Worker // Create a new registry so the pointer uniquely identifies the set of registered types. 240*333d2b36SAndroid Build Coastguard Worker return &sdkRegistry{ 241*333d2b36SAndroid Build Coastguard Worker list: list, 242*333d2b36SAndroid Build Coastguard Worker } 243*333d2b36SAndroid Build Coastguard Worker} 244*333d2b36SAndroid Build Coastguard Worker 245*333d2b36SAndroid Build Coastguard Worker// registeredObjects returns the list of registered instances. 246*333d2b36SAndroid Build Coastguard Workerfunc (r *sdkRegistry) registeredObjects() []sdkRegisterable { 247*333d2b36SAndroid Build Coastguard Worker return r.list 248*333d2b36SAndroid Build Coastguard Worker} 249*333d2b36SAndroid Build Coastguard Worker 250*333d2b36SAndroid Build Coastguard Worker// uniqueOnceKey returns a key that uniquely identifies this instance and can be used with 251*333d2b36SAndroid Build Coastguard Worker// OncePer.Once 252*333d2b36SAndroid Build Coastguard Workerfunc (r *sdkRegistry) uniqueOnceKey() OnceKey { 253*333d2b36SAndroid Build Coastguard Worker // Use the pointer to the registry as the unique key. The pointer is used because it is guaranteed 254*333d2b36SAndroid Build Coastguard Worker // to uniquely identify the contained list. The list itself cannot be used as slices are not 255*333d2b36SAndroid Build Coastguard Worker // comparable. Using the pointer does mean that two separate registries with identical lists would 256*333d2b36SAndroid Build Coastguard Worker // have different keys and so cause whatever information is cached to be created multiple times. 257*333d2b36SAndroid Build Coastguard Worker // However, that is not an issue in practice as it should not occur outside tests. Constructing a 258*333d2b36SAndroid Build Coastguard Worker // string representation of the list to use instead would avoid that but is an unnecessary 259*333d2b36SAndroid Build Coastguard Worker // complication that provides no significant benefit. 260*333d2b36SAndroid Build Coastguard Worker return NewCustomOnceKey(r) 261*333d2b36SAndroid Build Coastguard Worker} 262*333d2b36SAndroid Build Coastguard Worker 263*333d2b36SAndroid Build Coastguard Worker// SdkMemberTrait represents a trait that members of an sdk module can contribute to the sdk 264*333d2b36SAndroid Build Coastguard Worker// snapshot. 265*333d2b36SAndroid Build Coastguard Worker// 266*333d2b36SAndroid Build Coastguard Worker// A trait is simply a characteristic of sdk member that is not required by default which may be 267*333d2b36SAndroid Build Coastguard Worker// required for some members but not others. Traits can cause additional information to be output 268*333d2b36SAndroid Build Coastguard Worker// to the sdk snapshot or replace the default information exported for a member with something else. 269*333d2b36SAndroid Build Coastguard Worker// e.g. 270*333d2b36SAndroid Build Coastguard Worker// - By default cc libraries only export the default image variants to the SDK. However, for some 271*333d2b36SAndroid Build Coastguard Worker// members it may be necessary to export specific image variants, e.g. vendor, or recovery. 272*333d2b36SAndroid Build Coastguard Worker// - By default cc libraries export all the configured architecture variants except for the native 273*333d2b36SAndroid Build Coastguard Worker// bridge architecture variants. However, for some members it may be necessary to export the 274*333d2b36SAndroid Build Coastguard Worker// native bridge architecture variants as well. 275*333d2b36SAndroid Build Coastguard Worker// - By default cc libraries export the platform variant (i.e. sdk:). However, for some members it 276*333d2b36SAndroid Build Coastguard Worker// may be necessary to export the sdk variant (i.e. sdk:sdk). 277*333d2b36SAndroid Build Coastguard Worker// 278*333d2b36SAndroid Build Coastguard Worker// A sdk can request a module to provide no traits, one trait or a collection of traits. The exact 279*333d2b36SAndroid Build Coastguard Worker// behavior of a trait is determined by how SdkMemberType implementations handle the traits. A trait 280*333d2b36SAndroid Build Coastguard Worker// could be specific to one SdkMemberType or many. Some trait combinations could be incompatible. 281*333d2b36SAndroid Build Coastguard Worker// 282*333d2b36SAndroid Build Coastguard Worker// The sdk module type will create a special traits structure that contains a property for each 283*333d2b36SAndroid Build Coastguard Worker// trait registered with RegisterSdkMemberTrait(). The property names are those returned from 284*333d2b36SAndroid Build Coastguard Worker// SdkPropertyName(). Each property contains a list of modules that are required to have that trait. 285*333d2b36SAndroid Build Coastguard Worker// e.g. something like this: 286*333d2b36SAndroid Build Coastguard Worker// 287*333d2b36SAndroid Build Coastguard Worker// sdk { 288*333d2b36SAndroid Build Coastguard Worker// name: "sdk", 289*333d2b36SAndroid Build Coastguard Worker// ... 290*333d2b36SAndroid Build Coastguard Worker// traits: { 291*333d2b36SAndroid Build Coastguard Worker// recovery_image: ["module1", "module4", "module5"], 292*333d2b36SAndroid Build Coastguard Worker// native_bridge: ["module1", "module2"], 293*333d2b36SAndroid Build Coastguard Worker// native_sdk: ["module1", "module3"], 294*333d2b36SAndroid Build Coastguard Worker// ... 295*333d2b36SAndroid Build Coastguard Worker// }, 296*333d2b36SAndroid Build Coastguard Worker// ... 297*333d2b36SAndroid Build Coastguard Worker// } 298*333d2b36SAndroid Build Coastguard Workertype SdkMemberTrait interface { 299*333d2b36SAndroid Build Coastguard Worker // SdkPropertyName returns the name of the traits property on an sdk module. 300*333d2b36SAndroid Build Coastguard Worker SdkPropertyName() string 301*333d2b36SAndroid Build Coastguard Worker} 302*333d2b36SAndroid Build Coastguard Worker 303*333d2b36SAndroid Build Coastguard Workervar _ sdkRegisterable = (SdkMemberTrait)(nil) 304*333d2b36SAndroid Build Coastguard Worker 305*333d2b36SAndroid Build Coastguard Worker// SdkMemberTraitBase is the base struct that must be embedded within any type that implements 306*333d2b36SAndroid Build Coastguard Worker// SdkMemberTrait. 307*333d2b36SAndroid Build Coastguard Workertype SdkMemberTraitBase struct { 308*333d2b36SAndroid Build Coastguard Worker // PropertyName is the name of the property 309*333d2b36SAndroid Build Coastguard Worker PropertyName string 310*333d2b36SAndroid Build Coastguard Worker} 311*333d2b36SAndroid Build Coastguard Worker 312*333d2b36SAndroid Build Coastguard Workerfunc (b *SdkMemberTraitBase) SdkPropertyName() string { 313*333d2b36SAndroid Build Coastguard Worker return b.PropertyName 314*333d2b36SAndroid Build Coastguard Worker} 315*333d2b36SAndroid Build Coastguard Worker 316*333d2b36SAndroid Build Coastguard Worker// SdkMemberTraitSet is a set of SdkMemberTrait instances. 317*333d2b36SAndroid Build Coastguard Workertype SdkMemberTraitSet interface { 318*333d2b36SAndroid Build Coastguard Worker // Empty returns true if this set is empty. 319*333d2b36SAndroid Build Coastguard Worker Empty() bool 320*333d2b36SAndroid Build Coastguard Worker 321*333d2b36SAndroid Build Coastguard Worker // Contains returns true if this set contains the specified trait. 322*333d2b36SAndroid Build Coastguard Worker Contains(trait SdkMemberTrait) bool 323*333d2b36SAndroid Build Coastguard Worker 324*333d2b36SAndroid Build Coastguard Worker // Subtract returns a new set containing all elements of this set except for those in the 325*333d2b36SAndroid Build Coastguard Worker // other set. 326*333d2b36SAndroid Build Coastguard Worker Subtract(other SdkMemberTraitSet) SdkMemberTraitSet 327*333d2b36SAndroid Build Coastguard Worker 328*333d2b36SAndroid Build Coastguard Worker // String returns a string representation of the set and its contents. 329*333d2b36SAndroid Build Coastguard Worker String() string 330*333d2b36SAndroid Build Coastguard Worker} 331*333d2b36SAndroid Build Coastguard Worker 332*333d2b36SAndroid Build Coastguard Workerfunc NewSdkMemberTraitSet(traits []SdkMemberTrait) SdkMemberTraitSet { 333*333d2b36SAndroid Build Coastguard Worker if len(traits) == 0 { 334*333d2b36SAndroid Build Coastguard Worker return EmptySdkMemberTraitSet() 335*333d2b36SAndroid Build Coastguard Worker } 336*333d2b36SAndroid Build Coastguard Worker 337*333d2b36SAndroid Build Coastguard Worker m := sdkMemberTraitSet{} 338*333d2b36SAndroid Build Coastguard Worker for _, trait := range traits { 339*333d2b36SAndroid Build Coastguard Worker m[trait] = true 340*333d2b36SAndroid Build Coastguard Worker } 341*333d2b36SAndroid Build Coastguard Worker return m 342*333d2b36SAndroid Build Coastguard Worker} 343*333d2b36SAndroid Build Coastguard Worker 344*333d2b36SAndroid Build Coastguard Workerfunc EmptySdkMemberTraitSet() SdkMemberTraitSet { 345*333d2b36SAndroid Build Coastguard Worker return (sdkMemberTraitSet)(nil) 346*333d2b36SAndroid Build Coastguard Worker} 347*333d2b36SAndroid Build Coastguard Worker 348*333d2b36SAndroid Build Coastguard Workertype sdkMemberTraitSet map[SdkMemberTrait]bool 349*333d2b36SAndroid Build Coastguard Worker 350*333d2b36SAndroid Build Coastguard Workervar _ SdkMemberTraitSet = (sdkMemberTraitSet{}) 351*333d2b36SAndroid Build Coastguard Worker 352*333d2b36SAndroid Build Coastguard Workerfunc (s sdkMemberTraitSet) Empty() bool { 353*333d2b36SAndroid Build Coastguard Worker return len(s) == 0 354*333d2b36SAndroid Build Coastguard Worker} 355*333d2b36SAndroid Build Coastguard Worker 356*333d2b36SAndroid Build Coastguard Workerfunc (s sdkMemberTraitSet) Contains(trait SdkMemberTrait) bool { 357*333d2b36SAndroid Build Coastguard Worker return s[trait] 358*333d2b36SAndroid Build Coastguard Worker} 359*333d2b36SAndroid Build Coastguard Worker 360*333d2b36SAndroid Build Coastguard Workerfunc (s sdkMemberTraitSet) Subtract(other SdkMemberTraitSet) SdkMemberTraitSet { 361*333d2b36SAndroid Build Coastguard Worker if other.Empty() { 362*333d2b36SAndroid Build Coastguard Worker return s 363*333d2b36SAndroid Build Coastguard Worker } 364*333d2b36SAndroid Build Coastguard Worker 365*333d2b36SAndroid Build Coastguard Worker var remainder []SdkMemberTrait 366*333d2b36SAndroid Build Coastguard Worker for trait, _ := range s { 367*333d2b36SAndroid Build Coastguard Worker if !other.Contains(trait) { 368*333d2b36SAndroid Build Coastguard Worker remainder = append(remainder, trait) 369*333d2b36SAndroid Build Coastguard Worker } 370*333d2b36SAndroid Build Coastguard Worker } 371*333d2b36SAndroid Build Coastguard Worker 372*333d2b36SAndroid Build Coastguard Worker return NewSdkMemberTraitSet(remainder) 373*333d2b36SAndroid Build Coastguard Worker} 374*333d2b36SAndroid Build Coastguard Worker 375*333d2b36SAndroid Build Coastguard Workerfunc (s sdkMemberTraitSet) String() string { 376*333d2b36SAndroid Build Coastguard Worker list := []string{} 377*333d2b36SAndroid Build Coastguard Worker for trait, _ := range s { 378*333d2b36SAndroid Build Coastguard Worker list = append(list, trait.SdkPropertyName()) 379*333d2b36SAndroid Build Coastguard Worker } 380*333d2b36SAndroid Build Coastguard Worker sort.Strings(list) 381*333d2b36SAndroid Build Coastguard Worker return fmt.Sprintf("[%s]", strings.Join(list, ",")) 382*333d2b36SAndroid Build Coastguard Worker} 383*333d2b36SAndroid Build Coastguard Worker 384*333d2b36SAndroid Build Coastguard Workervar registeredSdkMemberTraits = &sdkRegistry{} 385*333d2b36SAndroid Build Coastguard Worker 386*333d2b36SAndroid Build Coastguard Worker// RegisteredSdkMemberTraits returns a OnceKey and a sorted list of registered traits. 387*333d2b36SAndroid Build Coastguard Worker// 388*333d2b36SAndroid Build Coastguard Worker// The key uniquely identifies the array of traits and can be used with OncePer.Once() to cache 389*333d2b36SAndroid Build Coastguard Worker// information derived from the array of traits. 390*333d2b36SAndroid Build Coastguard Workerfunc RegisteredSdkMemberTraits() (OnceKey, []SdkMemberTrait) { 391*333d2b36SAndroid Build Coastguard Worker registerables := registeredSdkMemberTraits.registeredObjects() 392*333d2b36SAndroid Build Coastguard Worker traits := make([]SdkMemberTrait, len(registerables)) 393*333d2b36SAndroid Build Coastguard Worker for i, registerable := range registerables { 394*333d2b36SAndroid Build Coastguard Worker traits[i] = registerable.(SdkMemberTrait) 395*333d2b36SAndroid Build Coastguard Worker } 396*333d2b36SAndroid Build Coastguard Worker return registeredSdkMemberTraits.uniqueOnceKey(), traits 397*333d2b36SAndroid Build Coastguard Worker} 398*333d2b36SAndroid Build Coastguard Worker 399*333d2b36SAndroid Build Coastguard Worker// RegisterSdkMemberTrait registers an SdkMemberTrait object to allow them to be used in the 400*333d2b36SAndroid Build Coastguard Worker// module_exports, module_exports_snapshot, sdk and sdk_snapshot module types. 401*333d2b36SAndroid Build Coastguard Workerfunc RegisterSdkMemberTrait(trait SdkMemberTrait) { 402*333d2b36SAndroid Build Coastguard Worker registeredSdkMemberTraits = registeredSdkMemberTraits.copyAndAppend(trait) 403*333d2b36SAndroid Build Coastguard Worker} 404*333d2b36SAndroid Build Coastguard Worker 405*333d2b36SAndroid Build Coastguard Worker// SdkMember is an individual member of the SDK. 406*333d2b36SAndroid Build Coastguard Worker// 407*333d2b36SAndroid Build Coastguard Worker// It includes all of the variants that the SDK depends upon. 408*333d2b36SAndroid Build Coastguard Workertype SdkMember interface { 409*333d2b36SAndroid Build Coastguard Worker // Name returns the name of the member. 410*333d2b36SAndroid Build Coastguard Worker Name() string 411*333d2b36SAndroid Build Coastguard Worker 412*333d2b36SAndroid Build Coastguard Worker // Variants returns all the variants of this module depended upon by the SDK. 413*333d2b36SAndroid Build Coastguard Worker Variants() []Module 414*333d2b36SAndroid Build Coastguard Worker} 415*333d2b36SAndroid Build Coastguard Worker 416*333d2b36SAndroid Build Coastguard Worker// SdkMemberDependencyTag is the interface that a tag must implement in order to allow the 417*333d2b36SAndroid Build Coastguard Worker// dependent module to be automatically added to the sdk. 418*333d2b36SAndroid Build Coastguard Workertype SdkMemberDependencyTag interface { 419*333d2b36SAndroid Build Coastguard Worker blueprint.DependencyTag 420*333d2b36SAndroid Build Coastguard Worker 421*333d2b36SAndroid Build Coastguard Worker // SdkMemberType returns the SdkMemberType that will be used to automatically add the child module 422*333d2b36SAndroid Build Coastguard Worker // to the sdk. 423*333d2b36SAndroid Build Coastguard Worker // 424*333d2b36SAndroid Build Coastguard Worker // Returning nil will prevent the module being added to the sdk. 425*333d2b36SAndroid Build Coastguard Worker SdkMemberType(child Module) SdkMemberType 426*333d2b36SAndroid Build Coastguard Worker 427*333d2b36SAndroid Build Coastguard Worker // ExportMember determines whether a module added to the sdk through this tag will be exported 428*333d2b36SAndroid Build Coastguard Worker // from the sdk or not. 429*333d2b36SAndroid Build Coastguard Worker // 430*333d2b36SAndroid Build Coastguard Worker // An exported member is added to the sdk using its own name, e.g. if "foo" was exported from sdk 431*333d2b36SAndroid Build Coastguard Worker // "bar" then its prebuilt would be simply called "foo". A member can be added to the sdk via 432*333d2b36SAndroid Build Coastguard Worker // multiple tags and if any of those tags returns true from this method then the membe will be 433*333d2b36SAndroid Build Coastguard Worker // exported. Every module added directly to the sdk via one of the member type specific 434*333d2b36SAndroid Build Coastguard Worker // properties, e.g. java_libs, will automatically be exported. 435*333d2b36SAndroid Build Coastguard Worker // 436*333d2b36SAndroid Build Coastguard Worker // If a member is not exported then it is treated as an internal implementation detail of the 437*333d2b36SAndroid Build Coastguard Worker // sdk and so will be added with an sdk specific name. e.g. if "foo" was an internal member of sdk 438*333d2b36SAndroid Build Coastguard Worker // "bar" then its prebuilt would be called "bar_foo". Additionally its visibility will be set to 439*333d2b36SAndroid Build Coastguard Worker // "//visibility:private" so it will not be accessible from outside its Android.bp file. 440*333d2b36SAndroid Build Coastguard Worker ExportMember() bool 441*333d2b36SAndroid Build Coastguard Worker} 442*333d2b36SAndroid Build Coastguard Worker 443*333d2b36SAndroid Build Coastguard Workervar _ SdkMemberDependencyTag = (*sdkMemberDependencyTag)(nil) 444*333d2b36SAndroid Build Coastguard Workervar _ ReplaceSourceWithPrebuilt = (*sdkMemberDependencyTag)(nil) 445*333d2b36SAndroid Build Coastguard Worker 446*333d2b36SAndroid Build Coastguard Workertype sdkMemberDependencyTag struct { 447*333d2b36SAndroid Build Coastguard Worker blueprint.BaseDependencyTag 448*333d2b36SAndroid Build Coastguard Worker memberType SdkMemberType 449*333d2b36SAndroid Build Coastguard Worker export bool 450*333d2b36SAndroid Build Coastguard Worker} 451*333d2b36SAndroid Build Coastguard Worker 452*333d2b36SAndroid Build Coastguard Workerfunc (t *sdkMemberDependencyTag) SdkMemberType(_ Module) SdkMemberType { 453*333d2b36SAndroid Build Coastguard Worker return t.memberType 454*333d2b36SAndroid Build Coastguard Worker} 455*333d2b36SAndroid Build Coastguard Worker 456*333d2b36SAndroid Build Coastguard Workerfunc (t *sdkMemberDependencyTag) ExportMember() bool { 457*333d2b36SAndroid Build Coastguard Worker return t.export 458*333d2b36SAndroid Build Coastguard Worker} 459*333d2b36SAndroid Build Coastguard Worker 460*333d2b36SAndroid Build Coastguard Worker// ReplaceSourceWithPrebuilt prevents dependencies from the sdk/module_exports onto their members 461*333d2b36SAndroid Build Coastguard Worker// from being replaced with a preferred prebuilt. 462*333d2b36SAndroid Build Coastguard Workerfunc (t *sdkMemberDependencyTag) ReplaceSourceWithPrebuilt() bool { 463*333d2b36SAndroid Build Coastguard Worker return false 464*333d2b36SAndroid Build Coastguard Worker} 465*333d2b36SAndroid Build Coastguard Worker 466*333d2b36SAndroid Build Coastguard Worker// DependencyTagForSdkMemberType creates an SdkMemberDependencyTag that will cause any 467*333d2b36SAndroid Build Coastguard Worker// dependencies added by the tag to be added to the sdk as the specified SdkMemberType and exported 468*333d2b36SAndroid Build Coastguard Worker// (or not) as specified by the export parameter. 469*333d2b36SAndroid Build Coastguard Workerfunc DependencyTagForSdkMemberType(memberType SdkMemberType, export bool) SdkMemberDependencyTag { 470*333d2b36SAndroid Build Coastguard Worker return &sdkMemberDependencyTag{memberType: memberType, export: export} 471*333d2b36SAndroid Build Coastguard Worker} 472*333d2b36SAndroid Build Coastguard Worker 473*333d2b36SAndroid Build Coastguard Worker// SdkMemberType is the interface that must be implemented for every type that can be a member of an 474*333d2b36SAndroid Build Coastguard Worker// sdk. 475*333d2b36SAndroid Build Coastguard Worker// 476*333d2b36SAndroid Build Coastguard Worker// The basic implementation should look something like this, where ModuleType is 477*333d2b36SAndroid Build Coastguard Worker// the name of the module type being supported. 478*333d2b36SAndroid Build Coastguard Worker// 479*333d2b36SAndroid Build Coastguard Worker// type moduleTypeSdkMemberType struct { 480*333d2b36SAndroid Build Coastguard Worker// android.SdkMemberTypeBase 481*333d2b36SAndroid Build Coastguard Worker// } 482*333d2b36SAndroid Build Coastguard Worker// 483*333d2b36SAndroid Build Coastguard Worker// func init() { 484*333d2b36SAndroid Build Coastguard Worker// android.RegisterSdkMemberType(&moduleTypeSdkMemberType{ 485*333d2b36SAndroid Build Coastguard Worker// SdkMemberTypeBase: android.SdkMemberTypeBase{ 486*333d2b36SAndroid Build Coastguard Worker// PropertyName: "module_types", 487*333d2b36SAndroid Build Coastguard Worker// }, 488*333d2b36SAndroid Build Coastguard Worker// } 489*333d2b36SAndroid Build Coastguard Worker// } 490*333d2b36SAndroid Build Coastguard Worker// 491*333d2b36SAndroid Build Coastguard Worker// ...methods... 492*333d2b36SAndroid Build Coastguard Workertype SdkMemberType interface { 493*333d2b36SAndroid Build Coastguard Worker // SdkPropertyName returns the name of the member type property on an sdk module. 494*333d2b36SAndroid Build Coastguard Worker SdkPropertyName() string 495*333d2b36SAndroid Build Coastguard Worker 496*333d2b36SAndroid Build Coastguard Worker // RequiresBpProperty returns true if this member type requires its property to be usable within 497*333d2b36SAndroid Build Coastguard Worker // an Android.bp file. 498*333d2b36SAndroid Build Coastguard Worker RequiresBpProperty() bool 499*333d2b36SAndroid Build Coastguard Worker 500*333d2b36SAndroid Build Coastguard Worker // SupportedBuildReleases returns the string representation of a set of target build releases that 501*333d2b36SAndroid Build Coastguard Worker // support this member type. 502*333d2b36SAndroid Build Coastguard Worker SupportedBuildReleases() string 503*333d2b36SAndroid Build Coastguard Worker 504*333d2b36SAndroid Build Coastguard Worker // UsableWithSdkAndSdkSnapshot returns true if the member type supports the sdk/sdk_snapshot, 505*333d2b36SAndroid Build Coastguard Worker // false otherwise. 506*333d2b36SAndroid Build Coastguard Worker UsableWithSdkAndSdkSnapshot() bool 507*333d2b36SAndroid Build Coastguard Worker 508*333d2b36SAndroid Build Coastguard Worker // IsHostOsDependent returns true if prebuilt host artifacts may be specific to the host OS. Only 509*333d2b36SAndroid Build Coastguard Worker // applicable to modules where HostSupported() is true. If this is true, snapshots will list each 510*333d2b36SAndroid Build Coastguard Worker // host OS variant explicitly and disable all other host OS'es. 511*333d2b36SAndroid Build Coastguard Worker IsHostOsDependent() bool 512*333d2b36SAndroid Build Coastguard Worker 513*333d2b36SAndroid Build Coastguard Worker // SupportedLinkages returns the names of the linkage variants supported by this module. 514*333d2b36SAndroid Build Coastguard Worker SupportedLinkages() []string 515*333d2b36SAndroid Build Coastguard Worker 516*333d2b36SAndroid Build Coastguard Worker // DisablesStrip returns true if the stripping needs to be disabled for this module. 517*333d2b36SAndroid Build Coastguard Worker DisablesStrip() bool 518*333d2b36SAndroid Build Coastguard Worker 519*333d2b36SAndroid Build Coastguard Worker // ArePrebuiltsRequired returns true if prebuilts are required in the sdk snapshot, false 520*333d2b36SAndroid Build Coastguard Worker // otherwise. 521*333d2b36SAndroid Build Coastguard Worker ArePrebuiltsRequired() bool 522*333d2b36SAndroid Build Coastguard Worker 523*333d2b36SAndroid Build Coastguard Worker // AddDependencies adds dependencies from the SDK module to all the module variants the member 524*333d2b36SAndroid Build Coastguard Worker // type contributes to the SDK. `names` is the list of module names given in the member type 525*333d2b36SAndroid Build Coastguard Worker // property (as returned by SdkPropertyName()) in the SDK module. The exact set of variants 526*333d2b36SAndroid Build Coastguard Worker // required is determined by the SDK and its properties. The dependencies must be added with the 527*333d2b36SAndroid Build Coastguard Worker // supplied tag. 528*333d2b36SAndroid Build Coastguard Worker // 529*333d2b36SAndroid Build Coastguard Worker // The BottomUpMutatorContext provided is for the SDK module. 530*333d2b36SAndroid Build Coastguard Worker AddDependencies(ctx SdkDependencyContext, dependencyTag blueprint.DependencyTag, names []string) 531*333d2b36SAndroid Build Coastguard Worker 532*333d2b36SAndroid Build Coastguard Worker // IsInstance returns true if the supplied module is an instance of this member type. 533*333d2b36SAndroid Build Coastguard Worker // 534*333d2b36SAndroid Build Coastguard Worker // This is used to check the type of each variant before added to the SdkMember. Returning false 535*333d2b36SAndroid Build Coastguard Worker // will cause an error to be logged explaining that the module is not allowed in whichever sdk 536*333d2b36SAndroid Build Coastguard Worker // property it was added. 537*333d2b36SAndroid Build Coastguard Worker IsInstance(module Module) bool 538*333d2b36SAndroid Build Coastguard Worker 539*333d2b36SAndroid Build Coastguard Worker // UsesSourceModuleTypeInSnapshot returns true when the AddPrebuiltModule() method returns a 540*333d2b36SAndroid Build Coastguard Worker // source module type. 541*333d2b36SAndroid Build Coastguard Worker UsesSourceModuleTypeInSnapshot() bool 542*333d2b36SAndroid Build Coastguard Worker 543*333d2b36SAndroid Build Coastguard Worker // AddPrebuiltModule is called to add a prebuilt module that the sdk will populate. 544*333d2b36SAndroid Build Coastguard Worker // 545*333d2b36SAndroid Build Coastguard Worker // The sdk module code generates the snapshot as follows: 546*333d2b36SAndroid Build Coastguard Worker // 547*333d2b36SAndroid Build Coastguard Worker // * A properties struct of type SdkMemberProperties is created for each variant and 548*333d2b36SAndroid Build Coastguard Worker // populated with information from the variant by calling PopulateFromVariant(Module) 549*333d2b36SAndroid Build Coastguard Worker // on the struct. 550*333d2b36SAndroid Build Coastguard Worker // 551*333d2b36SAndroid Build Coastguard Worker // * An additional properties struct is created into which the common properties will be 552*333d2b36SAndroid Build Coastguard Worker // added. 553*333d2b36SAndroid Build Coastguard Worker // 554*333d2b36SAndroid Build Coastguard Worker // * The variant property structs are analysed to find exported (capitalized) fields which 555*333d2b36SAndroid Build Coastguard Worker // have common values. Those fields are cleared and the common value added to the common 556*333d2b36SAndroid Build Coastguard Worker // properties. 557*333d2b36SAndroid Build Coastguard Worker // 558*333d2b36SAndroid Build Coastguard Worker // A field annotated with a tag of `sdk:"ignore"` will be treated as if it 559*333d2b36SAndroid Build Coastguard Worker // was not capitalized, i.e. ignored and not optimized for common values. 560*333d2b36SAndroid Build Coastguard Worker // 561*333d2b36SAndroid Build Coastguard Worker // A field annotated with a tag of `sdk:"keep"` will not be cleared even if the value is common 562*333d2b36SAndroid Build Coastguard Worker // across multiple structs. Common values will still be copied into the common property struct. 563*333d2b36SAndroid Build Coastguard Worker // So, if the same value is placed in all structs populated from variants that value would be 564*333d2b36SAndroid Build Coastguard Worker // copied into all common property structs and so be available in every instance. 565*333d2b36SAndroid Build Coastguard Worker // 566*333d2b36SAndroid Build Coastguard Worker // A field annotated with a tag of `android:"arch_variant"` will be allowed to have 567*333d2b36SAndroid Build Coastguard Worker // values that differ by arch, fields not tagged as such must have common values across 568*333d2b36SAndroid Build Coastguard Worker // all variants. 569*333d2b36SAndroid Build Coastguard Worker // 570*333d2b36SAndroid Build Coastguard Worker // * Additional field tags can be specified on a field that will ignore certain values 571*333d2b36SAndroid Build Coastguard Worker // for the purpose of common value optimization. A value that is ignored must have the 572*333d2b36SAndroid Build Coastguard Worker // default value for the property type. This is to ensure that significant value are not 573*333d2b36SAndroid Build Coastguard Worker // ignored by accident. The purpose of this is to allow the snapshot generation to reflect 574*333d2b36SAndroid Build Coastguard Worker // the behavior of the runtime. e.g. if a property is ignored on the host then a property 575*333d2b36SAndroid Build Coastguard Worker // that is common for android can be treated as if it was common for android and host as 576*333d2b36SAndroid Build Coastguard Worker // the setting for host is ignored anyway. 577*333d2b36SAndroid Build Coastguard Worker // * `sdk:"ignored-on-host" - this indicates the property is ignored on the host variant. 578*333d2b36SAndroid Build Coastguard Worker // 579*333d2b36SAndroid Build Coastguard Worker // * The sdk module type populates the BpModule structure, creating the arch specific 580*333d2b36SAndroid Build Coastguard Worker // structure and calls AddToPropertySet(...) on the properties struct to add the member 581*333d2b36SAndroid Build Coastguard Worker // specific properties in the correct place in the structure. 582*333d2b36SAndroid Build Coastguard Worker // 583*333d2b36SAndroid Build Coastguard Worker AddPrebuiltModule(ctx SdkMemberContext, member SdkMember) BpModule 584*333d2b36SAndroid Build Coastguard Worker 585*333d2b36SAndroid Build Coastguard Worker // CreateVariantPropertiesStruct creates a structure into which variant specific properties can be 586*333d2b36SAndroid Build Coastguard Worker // added. 587*333d2b36SAndroid Build Coastguard Worker CreateVariantPropertiesStruct() SdkMemberProperties 588*333d2b36SAndroid Build Coastguard Worker 589*333d2b36SAndroid Build Coastguard Worker // SupportedTraits returns the set of traits supported by this member type. 590*333d2b36SAndroid Build Coastguard Worker SupportedTraits() SdkMemberTraitSet 591*333d2b36SAndroid Build Coastguard Worker 592*333d2b36SAndroid Build Coastguard Worker // Overrides returns whether type overrides other SdkMemberType 593*333d2b36SAndroid Build Coastguard Worker Overrides(SdkMemberType) bool 594*333d2b36SAndroid Build Coastguard Worker} 595*333d2b36SAndroid Build Coastguard Worker 596*333d2b36SAndroid Build Coastguard Workervar _ sdkRegisterable = (SdkMemberType)(nil) 597*333d2b36SAndroid Build Coastguard Worker 598*333d2b36SAndroid Build Coastguard Worker// SdkDependencyContext provides access to information needed by the SdkMemberType.AddDependencies() 599*333d2b36SAndroid Build Coastguard Worker// implementations. 600*333d2b36SAndroid Build Coastguard Workertype SdkDependencyContext interface { 601*333d2b36SAndroid Build Coastguard Worker BottomUpMutatorContext 602*333d2b36SAndroid Build Coastguard Worker 603*333d2b36SAndroid Build Coastguard Worker // RequiredTraits returns the set of SdkMemberTrait instances that the sdk requires the named 604*333d2b36SAndroid Build Coastguard Worker // member to provide. 605*333d2b36SAndroid Build Coastguard Worker RequiredTraits(name string) SdkMemberTraitSet 606*333d2b36SAndroid Build Coastguard Worker 607*333d2b36SAndroid Build Coastguard Worker // RequiresTrait returns true if the sdk requires the member with the supplied name to provide the 608*333d2b36SAndroid Build Coastguard Worker // supplied trait. 609*333d2b36SAndroid Build Coastguard Worker RequiresTrait(name string, trait SdkMemberTrait) bool 610*333d2b36SAndroid Build Coastguard Worker} 611*333d2b36SAndroid Build Coastguard Worker 612*333d2b36SAndroid Build Coastguard Worker// SdkMemberTypeBase is the base type for SdkMemberType implementations and must be embedded in any 613*333d2b36SAndroid Build Coastguard Worker// struct that implements SdkMemberType. 614*333d2b36SAndroid Build Coastguard Workertype SdkMemberTypeBase struct { 615*333d2b36SAndroid Build Coastguard Worker PropertyName string 616*333d2b36SAndroid Build Coastguard Worker 617*333d2b36SAndroid Build Coastguard Worker // Property names that this SdkMemberTypeBase can override, this is useful when a module type is a 618*333d2b36SAndroid Build Coastguard Worker // superset of another module type. 619*333d2b36SAndroid Build Coastguard Worker OverridesPropertyNames map[string]bool 620*333d2b36SAndroid Build Coastguard Worker 621*333d2b36SAndroid Build Coastguard Worker // The names of linkage variants supported by this module. 622*333d2b36SAndroid Build Coastguard Worker SupportedLinkageNames []string 623*333d2b36SAndroid Build Coastguard Worker 624*333d2b36SAndroid Build Coastguard Worker // StripDisabled returns true if the stripping needs to be disabled for this module. 625*333d2b36SAndroid Build Coastguard Worker StripDisabled bool 626*333d2b36SAndroid Build Coastguard Worker 627*333d2b36SAndroid Build Coastguard Worker // When set to true BpPropertyNotRequired indicates that the member type does not require the 628*333d2b36SAndroid Build Coastguard Worker // property to be specifiable in an Android.bp file. 629*333d2b36SAndroid Build Coastguard Worker BpPropertyNotRequired bool 630*333d2b36SAndroid Build Coastguard Worker 631*333d2b36SAndroid Build Coastguard Worker // The name of the first targeted build release. 632*333d2b36SAndroid Build Coastguard Worker // 633*333d2b36SAndroid Build Coastguard Worker // If not specified then it is assumed to be available on all targeted build releases. 634*333d2b36SAndroid Build Coastguard Worker SupportedBuildReleaseSpecification string 635*333d2b36SAndroid Build Coastguard Worker 636*333d2b36SAndroid Build Coastguard Worker // Set to true if this must be usable with the sdk/sdk_snapshot module types. Otherwise, it will 637*333d2b36SAndroid Build Coastguard Worker // only be usable with module_exports/module_exports_snapshots module types. 638*333d2b36SAndroid Build Coastguard Worker SupportsSdk bool 639*333d2b36SAndroid Build Coastguard Worker 640*333d2b36SAndroid Build Coastguard Worker // Set to true if prebuilt host artifacts of this member may be specific to the host OS. Only 641*333d2b36SAndroid Build Coastguard Worker // applicable to modules where HostSupported() is true. 642*333d2b36SAndroid Build Coastguard Worker HostOsDependent bool 643*333d2b36SAndroid Build Coastguard Worker 644*333d2b36SAndroid Build Coastguard Worker // When set to true UseSourceModuleTypeInSnapshot indicates that the member type creates a source 645*333d2b36SAndroid Build Coastguard Worker // module type in its SdkMemberType.AddPrebuiltModule() method. That prevents the sdk snapshot 646*333d2b36SAndroid Build Coastguard Worker // code from automatically adding a prefer: true flag. 647*333d2b36SAndroid Build Coastguard Worker UseSourceModuleTypeInSnapshot bool 648*333d2b36SAndroid Build Coastguard Worker 649*333d2b36SAndroid Build Coastguard Worker // Set to proptools.BoolPtr(false) if this member does not generate prebuilts but is only provided 650*333d2b36SAndroid Build Coastguard Worker // to allow the sdk to gather members from this member's dependencies. If not specified then 651*333d2b36SAndroid Build Coastguard Worker // defaults to true. 652*333d2b36SAndroid Build Coastguard Worker PrebuiltsRequired *bool 653*333d2b36SAndroid Build Coastguard Worker 654*333d2b36SAndroid Build Coastguard Worker // The list of supported traits. 655*333d2b36SAndroid Build Coastguard Worker Traits []SdkMemberTrait 656*333d2b36SAndroid Build Coastguard Worker} 657*333d2b36SAndroid Build Coastguard Worker 658*333d2b36SAndroid Build Coastguard Workerfunc (b *SdkMemberTypeBase) SdkPropertyName() string { 659*333d2b36SAndroid Build Coastguard Worker return b.PropertyName 660*333d2b36SAndroid Build Coastguard Worker} 661*333d2b36SAndroid Build Coastguard Worker 662*333d2b36SAndroid Build Coastguard Workerfunc (b *SdkMemberTypeBase) RequiresBpProperty() bool { 663*333d2b36SAndroid Build Coastguard Worker return !b.BpPropertyNotRequired 664*333d2b36SAndroid Build Coastguard Worker} 665*333d2b36SAndroid Build Coastguard Worker 666*333d2b36SAndroid Build Coastguard Workerfunc (b *SdkMemberTypeBase) SupportedBuildReleases() string { 667*333d2b36SAndroid Build Coastguard Worker return b.SupportedBuildReleaseSpecification 668*333d2b36SAndroid Build Coastguard Worker} 669*333d2b36SAndroid Build Coastguard Worker 670*333d2b36SAndroid Build Coastguard Workerfunc (b *SdkMemberTypeBase) UsableWithSdkAndSdkSnapshot() bool { 671*333d2b36SAndroid Build Coastguard Worker return b.SupportsSdk 672*333d2b36SAndroid Build Coastguard Worker} 673*333d2b36SAndroid Build Coastguard Worker 674*333d2b36SAndroid Build Coastguard Workerfunc (b *SdkMemberTypeBase) IsHostOsDependent() bool { 675*333d2b36SAndroid Build Coastguard Worker return b.HostOsDependent 676*333d2b36SAndroid Build Coastguard Worker} 677*333d2b36SAndroid Build Coastguard Worker 678*333d2b36SAndroid Build Coastguard Workerfunc (b *SdkMemberTypeBase) ArePrebuiltsRequired() bool { 679*333d2b36SAndroid Build Coastguard Worker return proptools.BoolDefault(b.PrebuiltsRequired, true) 680*333d2b36SAndroid Build Coastguard Worker} 681*333d2b36SAndroid Build Coastguard Worker 682*333d2b36SAndroid Build Coastguard Workerfunc (b *SdkMemberTypeBase) UsesSourceModuleTypeInSnapshot() bool { 683*333d2b36SAndroid Build Coastguard Worker return b.UseSourceModuleTypeInSnapshot 684*333d2b36SAndroid Build Coastguard Worker} 685*333d2b36SAndroid Build Coastguard Worker 686*333d2b36SAndroid Build Coastguard Workerfunc (b *SdkMemberTypeBase) SupportedTraits() SdkMemberTraitSet { 687*333d2b36SAndroid Build Coastguard Worker return NewSdkMemberTraitSet(b.Traits) 688*333d2b36SAndroid Build Coastguard Worker} 689*333d2b36SAndroid Build Coastguard Worker 690*333d2b36SAndroid Build Coastguard Workerfunc (b *SdkMemberTypeBase) Overrides(other SdkMemberType) bool { 691*333d2b36SAndroid Build Coastguard Worker return b.OverridesPropertyNames[other.SdkPropertyName()] 692*333d2b36SAndroid Build Coastguard Worker} 693*333d2b36SAndroid Build Coastguard Worker 694*333d2b36SAndroid Build Coastguard Workerfunc (b *SdkMemberTypeBase) SupportedLinkages() []string { 695*333d2b36SAndroid Build Coastguard Worker return b.SupportedLinkageNames 696*333d2b36SAndroid Build Coastguard Worker} 697*333d2b36SAndroid Build Coastguard Worker 698*333d2b36SAndroid Build Coastguard Workerfunc (b *SdkMemberTypeBase) DisablesStrip() bool { 699*333d2b36SAndroid Build Coastguard Worker return b.StripDisabled 700*333d2b36SAndroid Build Coastguard Worker} 701*333d2b36SAndroid Build Coastguard Worker 702*333d2b36SAndroid Build Coastguard Worker// registeredModuleExportsMemberTypes is the set of registered SdkMemberTypes for module_exports 703*333d2b36SAndroid Build Coastguard Worker// modules. 704*333d2b36SAndroid Build Coastguard Workervar registeredModuleExportsMemberTypes = &sdkRegistry{} 705*333d2b36SAndroid Build Coastguard Worker 706*333d2b36SAndroid Build Coastguard Worker// registeredSdkMemberTypes is the set of registered registeredSdkMemberTypes for sdk modules. 707*333d2b36SAndroid Build Coastguard Workervar registeredSdkMemberTypes = &sdkRegistry{} 708*333d2b36SAndroid Build Coastguard Worker 709*333d2b36SAndroid Build Coastguard Worker// RegisteredSdkMemberTypes returns a OnceKey and a sorted list of registered types. 710*333d2b36SAndroid Build Coastguard Worker// 711*333d2b36SAndroid Build Coastguard Worker// If moduleExports is true then the slice of types includes all registered types that can be used 712*333d2b36SAndroid Build Coastguard Worker// with the module_exports and module_exports_snapshot module types. Otherwise, the slice of types 713*333d2b36SAndroid Build Coastguard Worker// only includes those registered types that can be used with the sdk and sdk_snapshot module 714*333d2b36SAndroid Build Coastguard Worker// types. 715*333d2b36SAndroid Build Coastguard Worker// 716*333d2b36SAndroid Build Coastguard Worker// The key uniquely identifies the array of types and can be used with OncePer.Once() to cache 717*333d2b36SAndroid Build Coastguard Worker// information derived from the array of types. 718*333d2b36SAndroid Build Coastguard Workerfunc RegisteredSdkMemberTypes(moduleExports bool) (OnceKey, []SdkMemberType) { 719*333d2b36SAndroid Build Coastguard Worker var registry *sdkRegistry 720*333d2b36SAndroid Build Coastguard Worker if moduleExports { 721*333d2b36SAndroid Build Coastguard Worker registry = registeredModuleExportsMemberTypes 722*333d2b36SAndroid Build Coastguard Worker } else { 723*333d2b36SAndroid Build Coastguard Worker registry = registeredSdkMemberTypes 724*333d2b36SAndroid Build Coastguard Worker } 725*333d2b36SAndroid Build Coastguard Worker 726*333d2b36SAndroid Build Coastguard Worker registerables := registry.registeredObjects() 727*333d2b36SAndroid Build Coastguard Worker types := make([]SdkMemberType, len(registerables)) 728*333d2b36SAndroid Build Coastguard Worker for i, registerable := range registerables { 729*333d2b36SAndroid Build Coastguard Worker types[i] = registerable.(SdkMemberType) 730*333d2b36SAndroid Build Coastguard Worker } 731*333d2b36SAndroid Build Coastguard Worker return registry.uniqueOnceKey(), types 732*333d2b36SAndroid Build Coastguard Worker} 733*333d2b36SAndroid Build Coastguard Worker 734*333d2b36SAndroid Build Coastguard Worker// RegisterSdkMemberType registers an SdkMemberType object to allow them to be used in the 735*333d2b36SAndroid Build Coastguard Worker// module_exports, module_exports_snapshot and (depending on the value returned from 736*333d2b36SAndroid Build Coastguard Worker// SdkMemberType.UsableWithSdkAndSdkSnapshot) the sdk and sdk_snapshot module types. 737*333d2b36SAndroid Build Coastguard Workerfunc RegisterSdkMemberType(memberType SdkMemberType) { 738*333d2b36SAndroid Build Coastguard Worker // All member types are usable with module_exports. 739*333d2b36SAndroid Build Coastguard Worker registeredModuleExportsMemberTypes = registeredModuleExportsMemberTypes.copyAndAppend(memberType) 740*333d2b36SAndroid Build Coastguard Worker 741*333d2b36SAndroid Build Coastguard Worker // Only those that explicitly indicate it are usable with sdk. 742*333d2b36SAndroid Build Coastguard Worker if memberType.UsableWithSdkAndSdkSnapshot() { 743*333d2b36SAndroid Build Coastguard Worker registeredSdkMemberTypes = registeredSdkMemberTypes.copyAndAppend(memberType) 744*333d2b36SAndroid Build Coastguard Worker } 745*333d2b36SAndroid Build Coastguard Worker} 746*333d2b36SAndroid Build Coastguard Worker 747*333d2b36SAndroid Build Coastguard Worker// SdkMemberPropertiesBase is the base structure for all implementations of SdkMemberProperties and 748*333d2b36SAndroid Build Coastguard Worker// must be embedded in any struct that implements SdkMemberProperties. 749*333d2b36SAndroid Build Coastguard Worker// 750*333d2b36SAndroid Build Coastguard Worker// Contains common properties that apply across many different member types. 751*333d2b36SAndroid Build Coastguard Workertype SdkMemberPropertiesBase struct { 752*333d2b36SAndroid Build Coastguard Worker // The number of unique os types supported by the member variants. 753*333d2b36SAndroid Build Coastguard Worker // 754*333d2b36SAndroid Build Coastguard Worker // If a member has a variant with more than one os type then it will need to differentiate 755*333d2b36SAndroid Build Coastguard Worker // the locations of any of their prebuilt files in the snapshot by os type to prevent them 756*333d2b36SAndroid Build Coastguard Worker // from colliding. See OsPrefix(). 757*333d2b36SAndroid Build Coastguard Worker // 758*333d2b36SAndroid Build Coastguard Worker // Ignore this property during optimization. This is needed because this property is the same for 759*333d2b36SAndroid Build Coastguard Worker // all variants of a member and so would be optimized away if it was not ignored. 760*333d2b36SAndroid Build Coastguard Worker Os_count int `sdk:"ignore"` 761*333d2b36SAndroid Build Coastguard Worker 762*333d2b36SAndroid Build Coastguard Worker // The os type for which these properties refer. 763*333d2b36SAndroid Build Coastguard Worker // 764*333d2b36SAndroid Build Coastguard Worker // Provided to allow a member to differentiate between os types in the locations of their 765*333d2b36SAndroid Build Coastguard Worker // prebuilt files when it supports more than one os type. 766*333d2b36SAndroid Build Coastguard Worker // 767*333d2b36SAndroid Build Coastguard Worker // Ignore this property during optimization. This is needed because this property is the same for 768*333d2b36SAndroid Build Coastguard Worker // all variants of a member and so would be optimized away if it was not ignored. 769*333d2b36SAndroid Build Coastguard Worker Os OsType `sdk:"ignore"` 770*333d2b36SAndroid Build Coastguard Worker 771*333d2b36SAndroid Build Coastguard Worker // The setting to use for the compile_multilib property. 772*333d2b36SAndroid Build Coastguard Worker Compile_multilib string `android:"arch_variant"` 773*333d2b36SAndroid Build Coastguard Worker} 774*333d2b36SAndroid Build Coastguard Worker 775*333d2b36SAndroid Build Coastguard Worker// OsPrefix returns the os prefix to use for any file paths in the sdk. 776*333d2b36SAndroid Build Coastguard Worker// 777*333d2b36SAndroid Build Coastguard Worker// Is an empty string if the member only provides variants for a single os type, otherwise 778*333d2b36SAndroid Build Coastguard Worker// is the OsType.Name. 779*333d2b36SAndroid Build Coastguard Workerfunc (b *SdkMemberPropertiesBase) OsPrefix() string { 780*333d2b36SAndroid Build Coastguard Worker if b.Os_count == 1 { 781*333d2b36SAndroid Build Coastguard Worker return "" 782*333d2b36SAndroid Build Coastguard Worker } else { 783*333d2b36SAndroid Build Coastguard Worker return b.Os.Name 784*333d2b36SAndroid Build Coastguard Worker } 785*333d2b36SAndroid Build Coastguard Worker} 786*333d2b36SAndroid Build Coastguard Worker 787*333d2b36SAndroid Build Coastguard Workerfunc (b *SdkMemberPropertiesBase) Base() *SdkMemberPropertiesBase { 788*333d2b36SAndroid Build Coastguard Worker return b 789*333d2b36SAndroid Build Coastguard Worker} 790*333d2b36SAndroid Build Coastguard Worker 791*333d2b36SAndroid Build Coastguard Worker// SdkMemberProperties is the interface to be implemented on top of a structure that contains 792*333d2b36SAndroid Build Coastguard Worker// variant specific information. 793*333d2b36SAndroid Build Coastguard Worker// 794*333d2b36SAndroid Build Coastguard Worker// Struct fields that are capitalized are examined for common values to extract. Fields that are not 795*333d2b36SAndroid Build Coastguard Worker// capitalized are assumed to be arch specific. 796*333d2b36SAndroid Build Coastguard Workertype SdkMemberProperties interface { 797*333d2b36SAndroid Build Coastguard Worker // Base returns the base structure. 798*333d2b36SAndroid Build Coastguard Worker Base() *SdkMemberPropertiesBase 799*333d2b36SAndroid Build Coastguard Worker 800*333d2b36SAndroid Build Coastguard Worker // PopulateFromVariant populates this structure with information from a module variant. 801*333d2b36SAndroid Build Coastguard Worker // 802*333d2b36SAndroid Build Coastguard Worker // It will typically be called once for each variant of a member module that the SDK depends upon. 803*333d2b36SAndroid Build Coastguard Worker PopulateFromVariant(ctx SdkMemberContext, variant Module) 804*333d2b36SAndroid Build Coastguard Worker 805*333d2b36SAndroid Build Coastguard Worker // AddToPropertySet adds the information from this structure to the property set. 806*333d2b36SAndroid Build Coastguard Worker // 807*333d2b36SAndroid Build Coastguard Worker // This will be called for each instance of this structure on which the PopulateFromVariant method 808*333d2b36SAndroid Build Coastguard Worker // was called and also on a number of different instances of this structure into which properties 809*333d2b36SAndroid Build Coastguard Worker // common to one or more variants have been copied. Therefore, implementations of this must handle 810*333d2b36SAndroid Build Coastguard Worker // the case when this structure is only partially populated. 811*333d2b36SAndroid Build Coastguard Worker AddToPropertySet(ctx SdkMemberContext, propertySet BpPropertySet) 812*333d2b36SAndroid Build Coastguard Worker} 813*333d2b36SAndroid Build Coastguard Worker 814*333d2b36SAndroid Build Coastguard Worker// SdkMemberContext provides access to information common to a specific member. 815*333d2b36SAndroid Build Coastguard Workertype SdkMemberContext interface { 816*333d2b36SAndroid Build Coastguard Worker // SdkModuleContext returns the module context of the sdk common os variant which is creating the 817*333d2b36SAndroid Build Coastguard Worker // snapshot. 818*333d2b36SAndroid Build Coastguard Worker // 819*333d2b36SAndroid Build Coastguard Worker // This is common to all members of the sdk and is not specific to the member being processed. 820*333d2b36SAndroid Build Coastguard Worker // If information about the member being processed needs to be obtained from this ModuleContext it 821*333d2b36SAndroid Build Coastguard Worker // must be obtained using one of the OtherModule... methods not the Module... methods. 822*333d2b36SAndroid Build Coastguard Worker SdkModuleContext() ModuleContext 823*333d2b36SAndroid Build Coastguard Worker 824*333d2b36SAndroid Build Coastguard Worker // SnapshotBuilder the builder of the snapshot. 825*333d2b36SAndroid Build Coastguard Worker SnapshotBuilder() SnapshotBuilder 826*333d2b36SAndroid Build Coastguard Worker 827*333d2b36SAndroid Build Coastguard Worker // MemberType returns the type of the member currently being processed. 828*333d2b36SAndroid Build Coastguard Worker MemberType() SdkMemberType 829*333d2b36SAndroid Build Coastguard Worker 830*333d2b36SAndroid Build Coastguard Worker // Name returns the name of the member currently being processed. 831*333d2b36SAndroid Build Coastguard Worker // 832*333d2b36SAndroid Build Coastguard Worker // Provided for use by sdk members to create a member specific location within the snapshot 833*333d2b36SAndroid Build Coastguard Worker // into which to copy the prebuilt files. 834*333d2b36SAndroid Build Coastguard Worker Name() string 835*333d2b36SAndroid Build Coastguard Worker 836*333d2b36SAndroid Build Coastguard Worker // RequiresTrait returns true if this member is expected to provide the specified trait. 837*333d2b36SAndroid Build Coastguard Worker RequiresTrait(trait SdkMemberTrait) bool 838*333d2b36SAndroid Build Coastguard Worker 839*333d2b36SAndroid Build Coastguard Worker // IsTargetBuildBeforeTiramisu return true if the target build release for which this snapshot is 840*333d2b36SAndroid Build Coastguard Worker // being generated is before Tiramisu, i.e. S. 841*333d2b36SAndroid Build Coastguard Worker IsTargetBuildBeforeTiramisu() bool 842*333d2b36SAndroid Build Coastguard Worker 843*333d2b36SAndroid Build Coastguard Worker // ModuleErrorf reports an error at the line number of the module type in the module definition. 844*333d2b36SAndroid Build Coastguard Worker ModuleErrorf(fmt string, args ...interface{}) 845*333d2b36SAndroid Build Coastguard Worker} 846*333d2b36SAndroid Build Coastguard Worker 847*333d2b36SAndroid Build Coastguard Worker// ExportedComponentsInfo contains information about the components that this module exports to an 848*333d2b36SAndroid Build Coastguard Worker// sdk snapshot. 849*333d2b36SAndroid Build Coastguard Worker// 850*333d2b36SAndroid Build Coastguard Worker// A component of a module is a child module that the module creates and which forms an integral 851*333d2b36SAndroid Build Coastguard Worker// part of the functionality that the creating module provides. A component module is essentially 852*333d2b36SAndroid Build Coastguard Worker// owned by its creator and is tightly coupled to the creator and other components. 853*333d2b36SAndroid Build Coastguard Worker// 854*333d2b36SAndroid Build Coastguard Worker// e.g. the child modules created by prebuilt_apis are not components because they are not tightly 855*333d2b36SAndroid Build Coastguard Worker// coupled to the prebuilt_apis module. Once they are created the prebuilt_apis ignores them. The 856*333d2b36SAndroid Build Coastguard Worker// child impl and stub library created by java_sdk_library (and corresponding import) are components 857*333d2b36SAndroid Build Coastguard Worker// because the creating module depends upon them in order to provide some of its own functionality. 858*333d2b36SAndroid Build Coastguard Worker// 859*333d2b36SAndroid Build Coastguard Worker// A component is exported if it is part of an sdk snapshot. e.g. The xml and impl child modules are 860*333d2b36SAndroid Build Coastguard Worker// components but they are not exported as they are not part of an sdk snapshot. 861*333d2b36SAndroid Build Coastguard Worker// 862*333d2b36SAndroid Build Coastguard Worker// This information is used by the sdk snapshot generation code to ensure that it does not create 863*333d2b36SAndroid Build Coastguard Worker// an sdk snapshot that contains a declaration of the component module and the module that creates 864*333d2b36SAndroid Build Coastguard Worker// it as that would result in duplicate modules when attempting to use the snapshot. e.g. a snapshot 865*333d2b36SAndroid Build Coastguard Worker// that included the java_sdk_library_import "foo" and also a java_import "foo.stubs" would fail 866*333d2b36SAndroid Build Coastguard Worker// as there would be two modules called "foo.stubs". 867*333d2b36SAndroid Build Coastguard Workertype ExportedComponentsInfo struct { 868*333d2b36SAndroid Build Coastguard Worker // The names of the exported components. 869*333d2b36SAndroid Build Coastguard Worker Components []string 870*333d2b36SAndroid Build Coastguard Worker} 871*333d2b36SAndroid Build Coastguard Worker 872*333d2b36SAndroid Build Coastguard Workervar ExportedComponentsInfoProvider = blueprint.NewProvider[ExportedComponentsInfo]() 873*333d2b36SAndroid Build Coastguard Worker 874*333d2b36SAndroid Build Coastguard Worker// AdditionalSdkInfo contains additional properties to add to the generated SDK info file. 875*333d2b36SAndroid Build Coastguard Workertype AdditionalSdkInfo struct { 876*333d2b36SAndroid Build Coastguard Worker Properties map[string]interface{} 877*333d2b36SAndroid Build Coastguard Worker} 878*333d2b36SAndroid Build Coastguard Worker 879*333d2b36SAndroid Build Coastguard Workervar AdditionalSdkInfoProvider = blueprint.NewProvider[AdditionalSdkInfo]() 880*333d2b36SAndroid Build Coastguard Worker 881*333d2b36SAndroid Build Coastguard Workervar apiFingerprintPathKey = NewOnceKey("apiFingerprintPathKey") 882*333d2b36SAndroid Build Coastguard Worker 883*333d2b36SAndroid Build Coastguard Workerfunc ApiFingerprintPath(ctx PathContext) OutputPath { 884*333d2b36SAndroid Build Coastguard Worker return ctx.Config().Once(apiFingerprintPathKey, func() interface{} { 885*333d2b36SAndroid Build Coastguard Worker return PathForOutput(ctx, "api_fingerprint.txt") 886*333d2b36SAndroid Build Coastguard Worker }).(OutputPath) 887*333d2b36SAndroid Build Coastguard Worker} 888