1*333d2b36SAndroid Build Coastguard Worker// Copyright 2018 Google Inc. All rights reserved. 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 java 16*333d2b36SAndroid Build Coastguard Worker 17*333d2b36SAndroid Build Coastguard Workerimport ( 18*333d2b36SAndroid Build Coastguard Worker "errors" 19*333d2b36SAndroid Build Coastguard Worker "fmt" 20*333d2b36SAndroid Build Coastguard Worker "path" 21*333d2b36SAndroid Build Coastguard Worker "path/filepath" 22*333d2b36SAndroid Build Coastguard Worker "reflect" 23*333d2b36SAndroid Build Coastguard Worker "sort" 24*333d2b36SAndroid Build Coastguard Worker "strings" 25*333d2b36SAndroid Build Coastguard Worker "sync" 26*333d2b36SAndroid Build Coastguard Worker 27*333d2b36SAndroid Build Coastguard Worker "github.com/google/blueprint" 28*333d2b36SAndroid Build Coastguard Worker "github.com/google/blueprint/proptools" 29*333d2b36SAndroid Build Coastguard Worker 30*333d2b36SAndroid Build Coastguard Worker "android/soong/android" 31*333d2b36SAndroid Build Coastguard Worker "android/soong/dexpreopt" 32*333d2b36SAndroid Build Coastguard Worker) 33*333d2b36SAndroid Build Coastguard Worker 34*333d2b36SAndroid Build Coastguard Worker// A tag to associated a dependency with a specific api scope. 35*333d2b36SAndroid Build Coastguard Workertype scopeDependencyTag struct { 36*333d2b36SAndroid Build Coastguard Worker blueprint.BaseDependencyTag 37*333d2b36SAndroid Build Coastguard Worker name string 38*333d2b36SAndroid Build Coastguard Worker apiScope *apiScope 39*333d2b36SAndroid Build Coastguard Worker 40*333d2b36SAndroid Build Coastguard Worker // Function for extracting appropriate path information from the dependency. 41*333d2b36SAndroid Build Coastguard Worker depInfoExtractor func(paths *scopePaths, ctx android.ModuleContext, dep android.Module) error 42*333d2b36SAndroid Build Coastguard Worker} 43*333d2b36SAndroid Build Coastguard Worker 44*333d2b36SAndroid Build Coastguard Worker// Extract tag specific information from the dependency. 45*333d2b36SAndroid Build Coastguard Workerfunc (tag scopeDependencyTag) extractDepInfo(ctx android.ModuleContext, dep android.Module, paths *scopePaths) { 46*333d2b36SAndroid Build Coastguard Worker err := tag.depInfoExtractor(paths, ctx, dep) 47*333d2b36SAndroid Build Coastguard Worker if err != nil { 48*333d2b36SAndroid Build Coastguard Worker ctx.ModuleErrorf("has an invalid {scopeDependencyTag: %s} dependency on module %s: %s", tag.name, ctx.OtherModuleName(dep), err.Error()) 49*333d2b36SAndroid Build Coastguard Worker } 50*333d2b36SAndroid Build Coastguard Worker} 51*333d2b36SAndroid Build Coastguard Worker 52*333d2b36SAndroid Build Coastguard Workervar _ android.ReplaceSourceWithPrebuilt = (*scopeDependencyTag)(nil) 53*333d2b36SAndroid Build Coastguard Worker 54*333d2b36SAndroid Build Coastguard Workerfunc (tag scopeDependencyTag) ReplaceSourceWithPrebuilt() bool { 55*333d2b36SAndroid Build Coastguard Worker return false 56*333d2b36SAndroid Build Coastguard Worker} 57*333d2b36SAndroid Build Coastguard Worker 58*333d2b36SAndroid Build Coastguard Worker// Provides information about an api scope, e.g. public, system, test. 59*333d2b36SAndroid Build Coastguard Workertype apiScope struct { 60*333d2b36SAndroid Build Coastguard Worker // The name of the api scope, e.g. public, system, test 61*333d2b36SAndroid Build Coastguard Worker name string 62*333d2b36SAndroid Build Coastguard Worker 63*333d2b36SAndroid Build Coastguard Worker // The api scope that this scope extends. 64*333d2b36SAndroid Build Coastguard Worker // 65*333d2b36SAndroid Build Coastguard Worker // This organizes the scopes into an extension hierarchy. 66*333d2b36SAndroid Build Coastguard Worker // 67*333d2b36SAndroid Build Coastguard Worker // If set this means that the API provided by this scope includes the API provided by the scope 68*333d2b36SAndroid Build Coastguard Worker // set in this field. 69*333d2b36SAndroid Build Coastguard Worker extends *apiScope 70*333d2b36SAndroid Build Coastguard Worker 71*333d2b36SAndroid Build Coastguard Worker // The next api scope that a library that uses this scope can access. 72*333d2b36SAndroid Build Coastguard Worker // 73*333d2b36SAndroid Build Coastguard Worker // This organizes the scopes into an access hierarchy. 74*333d2b36SAndroid Build Coastguard Worker // 75*333d2b36SAndroid Build Coastguard Worker // If set this means that a library that can access this API can also access the API provided by 76*333d2b36SAndroid Build Coastguard Worker // the scope set in this field. 77*333d2b36SAndroid Build Coastguard Worker // 78*333d2b36SAndroid Build Coastguard Worker // A module that sets sdk_version: "<scope>_current" should have access to the <scope> API of 79*333d2b36SAndroid Build Coastguard Worker // every java_sdk_library that it depends on. If the library does not provide an API for <scope> 80*333d2b36SAndroid Build Coastguard Worker // then it will traverse up this access hierarchy to find an API that it does provide. 81*333d2b36SAndroid Build Coastguard Worker // 82*333d2b36SAndroid Build Coastguard Worker // If this is not set then it defaults to the scope set in extends. 83*333d2b36SAndroid Build Coastguard Worker canAccess *apiScope 84*333d2b36SAndroid Build Coastguard Worker 85*333d2b36SAndroid Build Coastguard Worker // The legacy enabled status for a specific scope can be dependent on other 86*333d2b36SAndroid Build Coastguard Worker // properties that have been specified on the library so it is provided by 87*333d2b36SAndroid Build Coastguard Worker // a function that can determine the status by examining those properties. 88*333d2b36SAndroid Build Coastguard Worker legacyEnabledStatus func(module *SdkLibrary) bool 89*333d2b36SAndroid Build Coastguard Worker 90*333d2b36SAndroid Build Coastguard Worker // The default enabled status for non-legacy behavior, which is triggered by 91*333d2b36SAndroid Build Coastguard Worker // explicitly enabling at least one api scope. 92*333d2b36SAndroid Build Coastguard Worker defaultEnabledStatus bool 93*333d2b36SAndroid Build Coastguard Worker 94*333d2b36SAndroid Build Coastguard Worker // Gets a pointer to the scope specific properties. 95*333d2b36SAndroid Build Coastguard Worker scopeSpecificProperties func(module *SdkLibrary) *ApiScopeProperties 96*333d2b36SAndroid Build Coastguard Worker 97*333d2b36SAndroid Build Coastguard Worker // The name of the field in the dynamically created structure. 98*333d2b36SAndroid Build Coastguard Worker fieldName string 99*333d2b36SAndroid Build Coastguard Worker 100*333d2b36SAndroid Build Coastguard Worker // The name of the property in the java_sdk_library_import 101*333d2b36SAndroid Build Coastguard Worker propertyName string 102*333d2b36SAndroid Build Coastguard Worker 103*333d2b36SAndroid Build Coastguard Worker // The tag to use to depend on the prebuilt stubs library module 104*333d2b36SAndroid Build Coastguard Worker prebuiltStubsTag scopeDependencyTag 105*333d2b36SAndroid Build Coastguard Worker 106*333d2b36SAndroid Build Coastguard Worker // The tag to use to depend on the everything stubs library module. 107*333d2b36SAndroid Build Coastguard Worker everythingStubsTag scopeDependencyTag 108*333d2b36SAndroid Build Coastguard Worker 109*333d2b36SAndroid Build Coastguard Worker // The tag to use to depend on the exportable stubs library module. 110*333d2b36SAndroid Build Coastguard Worker exportableStubsTag scopeDependencyTag 111*333d2b36SAndroid Build Coastguard Worker 112*333d2b36SAndroid Build Coastguard Worker // The tag to use to depend on the stubs source module (if separate from the API module). 113*333d2b36SAndroid Build Coastguard Worker stubsSourceTag scopeDependencyTag 114*333d2b36SAndroid Build Coastguard Worker 115*333d2b36SAndroid Build Coastguard Worker // The tag to use to depend on the stubs source and API module. 116*333d2b36SAndroid Build Coastguard Worker stubsSourceAndApiTag scopeDependencyTag 117*333d2b36SAndroid Build Coastguard Worker 118*333d2b36SAndroid Build Coastguard Worker // The tag to use to depend on the module that provides the latest version of the API .txt file. 119*333d2b36SAndroid Build Coastguard Worker latestApiModuleTag scopeDependencyTag 120*333d2b36SAndroid Build Coastguard Worker 121*333d2b36SAndroid Build Coastguard Worker // The tag to use to depend on the module that provides the latest version of the API removed.txt 122*333d2b36SAndroid Build Coastguard Worker // file. 123*333d2b36SAndroid Build Coastguard Worker latestRemovedApiModuleTag scopeDependencyTag 124*333d2b36SAndroid Build Coastguard Worker 125*333d2b36SAndroid Build Coastguard Worker // The scope specific prefix to add to the api file base of "current.txt" or "removed.txt". 126*333d2b36SAndroid Build Coastguard Worker apiFilePrefix string 127*333d2b36SAndroid Build Coastguard Worker 128*333d2b36SAndroid Build Coastguard Worker // The scope specific suffix to add to the sdk library module name to construct a scope specific 129*333d2b36SAndroid Build Coastguard Worker // module name. 130*333d2b36SAndroid Build Coastguard Worker moduleSuffix string 131*333d2b36SAndroid Build Coastguard Worker 132*333d2b36SAndroid Build Coastguard Worker // SDK version that the stubs library is built against. Note that this is always 133*333d2b36SAndroid Build Coastguard Worker // *current. Older stubs library built with a numbered SDK version is created from 134*333d2b36SAndroid Build Coastguard Worker // the prebuilt jar. 135*333d2b36SAndroid Build Coastguard Worker sdkVersion string 136*333d2b36SAndroid Build Coastguard Worker 137*333d2b36SAndroid Build Coastguard Worker // The annotation that identifies this API level, empty for the public API scope. 138*333d2b36SAndroid Build Coastguard Worker annotation string 139*333d2b36SAndroid Build Coastguard Worker 140*333d2b36SAndroid Build Coastguard Worker // Extra arguments to pass to droidstubs for this scope. 141*333d2b36SAndroid Build Coastguard Worker // 142*333d2b36SAndroid Build Coastguard Worker // This is not used directly but is used to construct the droidstubsArgs. 143*333d2b36SAndroid Build Coastguard Worker extraArgs []string 144*333d2b36SAndroid Build Coastguard Worker 145*333d2b36SAndroid Build Coastguard Worker // The args that must be passed to droidstubs to generate the API and stubs source 146*333d2b36SAndroid Build Coastguard Worker // for this scope, constructed dynamically by initApiScope(). 147*333d2b36SAndroid Build Coastguard Worker // 148*333d2b36SAndroid Build Coastguard Worker // The API only includes the additional members that this scope adds over the scope 149*333d2b36SAndroid Build Coastguard Worker // that it extends. 150*333d2b36SAndroid Build Coastguard Worker // 151*333d2b36SAndroid Build Coastguard Worker // The stubs source must include the definitions of everything that is in this 152*333d2b36SAndroid Build Coastguard Worker // api scope and all the scopes that this one extends. 153*333d2b36SAndroid Build Coastguard Worker droidstubsArgs []string 154*333d2b36SAndroid Build Coastguard Worker 155*333d2b36SAndroid Build Coastguard Worker // Whether the api scope can be treated as unstable, and should skip compat checks. 156*333d2b36SAndroid Build Coastguard Worker unstable bool 157*333d2b36SAndroid Build Coastguard Worker 158*333d2b36SAndroid Build Coastguard Worker // Represents the SDK kind of this scope. 159*333d2b36SAndroid Build Coastguard Worker kind android.SdkKind 160*333d2b36SAndroid Build Coastguard Worker} 161*333d2b36SAndroid Build Coastguard Worker 162*333d2b36SAndroid Build Coastguard Worker// Initialize a scope, creating and adding appropriate dependency tags 163*333d2b36SAndroid Build Coastguard Workerfunc initApiScope(scope *apiScope) *apiScope { 164*333d2b36SAndroid Build Coastguard Worker name := scope.name 165*333d2b36SAndroid Build Coastguard Worker scopeByName[name] = scope 166*333d2b36SAndroid Build Coastguard Worker allScopeNames = append(allScopeNames, name) 167*333d2b36SAndroid Build Coastguard Worker scope.propertyName = strings.ReplaceAll(name, "-", "_") 168*333d2b36SAndroid Build Coastguard Worker scope.fieldName = proptools.FieldNameForProperty(scope.propertyName) 169*333d2b36SAndroid Build Coastguard Worker scope.prebuiltStubsTag = scopeDependencyTag{ 170*333d2b36SAndroid Build Coastguard Worker name: name + "-stubs", 171*333d2b36SAndroid Build Coastguard Worker apiScope: scope, 172*333d2b36SAndroid Build Coastguard Worker depInfoExtractor: (*scopePaths).extractStubsLibraryInfoFromDependency, 173*333d2b36SAndroid Build Coastguard Worker } 174*333d2b36SAndroid Build Coastguard Worker scope.everythingStubsTag = scopeDependencyTag{ 175*333d2b36SAndroid Build Coastguard Worker name: name + "-stubs-everything", 176*333d2b36SAndroid Build Coastguard Worker apiScope: scope, 177*333d2b36SAndroid Build Coastguard Worker depInfoExtractor: (*scopePaths).extractEverythingStubsLibraryInfoFromDependency, 178*333d2b36SAndroid Build Coastguard Worker } 179*333d2b36SAndroid Build Coastguard Worker scope.exportableStubsTag = scopeDependencyTag{ 180*333d2b36SAndroid Build Coastguard Worker name: name + "-stubs-exportable", 181*333d2b36SAndroid Build Coastguard Worker apiScope: scope, 182*333d2b36SAndroid Build Coastguard Worker depInfoExtractor: (*scopePaths).extractExportableStubsLibraryInfoFromDependency, 183*333d2b36SAndroid Build Coastguard Worker } 184*333d2b36SAndroid Build Coastguard Worker scope.stubsSourceTag = scopeDependencyTag{ 185*333d2b36SAndroid Build Coastguard Worker name: name + "-stubs-source", 186*333d2b36SAndroid Build Coastguard Worker apiScope: scope, 187*333d2b36SAndroid Build Coastguard Worker depInfoExtractor: (*scopePaths).extractStubsSourceInfoFromDep, 188*333d2b36SAndroid Build Coastguard Worker } 189*333d2b36SAndroid Build Coastguard Worker scope.stubsSourceAndApiTag = scopeDependencyTag{ 190*333d2b36SAndroid Build Coastguard Worker name: name + "-stubs-source-and-api", 191*333d2b36SAndroid Build Coastguard Worker apiScope: scope, 192*333d2b36SAndroid Build Coastguard Worker depInfoExtractor: (*scopePaths).extractStubsSourceAndApiInfoFromApiStubsProvider, 193*333d2b36SAndroid Build Coastguard Worker } 194*333d2b36SAndroid Build Coastguard Worker scope.latestApiModuleTag = scopeDependencyTag{ 195*333d2b36SAndroid Build Coastguard Worker name: name + "-latest-api", 196*333d2b36SAndroid Build Coastguard Worker apiScope: scope, 197*333d2b36SAndroid Build Coastguard Worker depInfoExtractor: (*scopePaths).extractLatestApiPath, 198*333d2b36SAndroid Build Coastguard Worker } 199*333d2b36SAndroid Build Coastguard Worker scope.latestRemovedApiModuleTag = scopeDependencyTag{ 200*333d2b36SAndroid Build Coastguard Worker name: name + "-latest-removed-api", 201*333d2b36SAndroid Build Coastguard Worker apiScope: scope, 202*333d2b36SAndroid Build Coastguard Worker depInfoExtractor: (*scopePaths).extractLatestRemovedApiPath, 203*333d2b36SAndroid Build Coastguard Worker } 204*333d2b36SAndroid Build Coastguard Worker 205*333d2b36SAndroid Build Coastguard Worker // To get the args needed to generate the stubs source append all the args from 206*333d2b36SAndroid Build Coastguard Worker // this scope and all the scopes it extends as each set of args adds additional 207*333d2b36SAndroid Build Coastguard Worker // members to the stubs. 208*333d2b36SAndroid Build Coastguard Worker var scopeSpecificArgs []string 209*333d2b36SAndroid Build Coastguard Worker if scope.annotation != "" { 210*333d2b36SAndroid Build Coastguard Worker scopeSpecificArgs = []string{"--show-annotation", scope.annotation} 211*333d2b36SAndroid Build Coastguard Worker } 212*333d2b36SAndroid Build Coastguard Worker for s := scope; s != nil; s = s.extends { 213*333d2b36SAndroid Build Coastguard Worker scopeSpecificArgs = append(scopeSpecificArgs, s.extraArgs...) 214*333d2b36SAndroid Build Coastguard Worker 215*333d2b36SAndroid Build Coastguard Worker // Ensure that the generated stubs includes all the API elements from the API scope 216*333d2b36SAndroid Build Coastguard Worker // that this scope extends. 217*333d2b36SAndroid Build Coastguard Worker if s != scope && s.annotation != "" { 218*333d2b36SAndroid Build Coastguard Worker scopeSpecificArgs = append(scopeSpecificArgs, "--show-for-stub-purposes-annotation", s.annotation) 219*333d2b36SAndroid Build Coastguard Worker } 220*333d2b36SAndroid Build Coastguard Worker } 221*333d2b36SAndroid Build Coastguard Worker 222*333d2b36SAndroid Build Coastguard Worker // By default, a library that can access a scope can also access the scope it extends. 223*333d2b36SAndroid Build Coastguard Worker if scope.canAccess == nil { 224*333d2b36SAndroid Build Coastguard Worker scope.canAccess = scope.extends 225*333d2b36SAndroid Build Coastguard Worker } 226*333d2b36SAndroid Build Coastguard Worker 227*333d2b36SAndroid Build Coastguard Worker // Escape any special characters in the arguments. This is needed because droidstubs 228*333d2b36SAndroid Build Coastguard Worker // passes these directly to the shell command. 229*333d2b36SAndroid Build Coastguard Worker scope.droidstubsArgs = proptools.ShellEscapeList(scopeSpecificArgs) 230*333d2b36SAndroid Build Coastguard Worker 231*333d2b36SAndroid Build Coastguard Worker return scope 232*333d2b36SAndroid Build Coastguard Worker} 233*333d2b36SAndroid Build Coastguard Worker 234*333d2b36SAndroid Build Coastguard Workerfunc (scope *apiScope) stubsLibraryModuleNameSuffix() string { 235*333d2b36SAndroid Build Coastguard Worker return ".stubs" + scope.moduleSuffix 236*333d2b36SAndroid Build Coastguard Worker} 237*333d2b36SAndroid Build Coastguard Worker 238*333d2b36SAndroid Build Coastguard Workerfunc (scope *apiScope) exportableStubsLibraryModuleNameSuffix() string { 239*333d2b36SAndroid Build Coastguard Worker return ".stubs.exportable" + scope.moduleSuffix 240*333d2b36SAndroid Build Coastguard Worker} 241*333d2b36SAndroid Build Coastguard Worker 242*333d2b36SAndroid Build Coastguard Workerfunc (scope *apiScope) apiLibraryModuleName(baseName string) string { 243*333d2b36SAndroid Build Coastguard Worker return scope.stubsLibraryModuleName(baseName) + ".from-text" 244*333d2b36SAndroid Build Coastguard Worker} 245*333d2b36SAndroid Build Coastguard Worker 246*333d2b36SAndroid Build Coastguard Workerfunc (scope *apiScope) sourceStubsLibraryModuleName(baseName string) string { 247*333d2b36SAndroid Build Coastguard Worker return scope.stubsLibraryModuleName(baseName) + ".from-source" 248*333d2b36SAndroid Build Coastguard Worker} 249*333d2b36SAndroid Build Coastguard Worker 250*333d2b36SAndroid Build Coastguard Workerfunc (scope *apiScope) exportableSourceStubsLibraryModuleName(baseName string) string { 251*333d2b36SAndroid Build Coastguard Worker return scope.exportableStubsLibraryModuleName(baseName) + ".from-source" 252*333d2b36SAndroid Build Coastguard Worker} 253*333d2b36SAndroid Build Coastguard Worker 254*333d2b36SAndroid Build Coastguard Workerfunc (scope *apiScope) stubsLibraryModuleName(baseName string) string { 255*333d2b36SAndroid Build Coastguard Worker return baseName + scope.stubsLibraryModuleNameSuffix() 256*333d2b36SAndroid Build Coastguard Worker} 257*333d2b36SAndroid Build Coastguard Worker 258*333d2b36SAndroid Build Coastguard Workerfunc (scope *apiScope) exportableStubsLibraryModuleName(baseName string) string { 259*333d2b36SAndroid Build Coastguard Worker return baseName + scope.exportableStubsLibraryModuleNameSuffix() 260*333d2b36SAndroid Build Coastguard Worker} 261*333d2b36SAndroid Build Coastguard Worker 262*333d2b36SAndroid Build Coastguard Workerfunc (scope *apiScope) stubsSourceModuleName(baseName string) string { 263*333d2b36SAndroid Build Coastguard Worker return baseName + ".stubs.source" + scope.moduleSuffix 264*333d2b36SAndroid Build Coastguard Worker} 265*333d2b36SAndroid Build Coastguard Worker 266*333d2b36SAndroid Build Coastguard Workerfunc (scope *apiScope) String() string { 267*333d2b36SAndroid Build Coastguard Worker return scope.name 268*333d2b36SAndroid Build Coastguard Worker} 269*333d2b36SAndroid Build Coastguard Worker 270*333d2b36SAndroid Build Coastguard Worker// snapshotRelativeDir returns the snapshot directory into which the files related to scopes will 271*333d2b36SAndroid Build Coastguard Worker// be stored. 272*333d2b36SAndroid Build Coastguard Workerfunc (scope *apiScope) snapshotRelativeDir() string { 273*333d2b36SAndroid Build Coastguard Worker return filepath.Join("sdk_library", scope.name) 274*333d2b36SAndroid Build Coastguard Worker} 275*333d2b36SAndroid Build Coastguard Worker 276*333d2b36SAndroid Build Coastguard Worker// snapshotRelativeCurrentApiTxtPath returns the snapshot path to the API .txt file for the named 277*333d2b36SAndroid Build Coastguard Worker// library. 278*333d2b36SAndroid Build Coastguard Workerfunc (scope *apiScope) snapshotRelativeCurrentApiTxtPath(name string) string { 279*333d2b36SAndroid Build Coastguard Worker return filepath.Join(scope.snapshotRelativeDir(), name+".txt") 280*333d2b36SAndroid Build Coastguard Worker} 281*333d2b36SAndroid Build Coastguard Worker 282*333d2b36SAndroid Build Coastguard Worker// snapshotRelativeRemovedApiTxtPath returns the snapshot path to the removed API .txt file for the 283*333d2b36SAndroid Build Coastguard Worker// named library. 284*333d2b36SAndroid Build Coastguard Workerfunc (scope *apiScope) snapshotRelativeRemovedApiTxtPath(name string) string { 285*333d2b36SAndroid Build Coastguard Worker return filepath.Join(scope.snapshotRelativeDir(), name+"-removed.txt") 286*333d2b36SAndroid Build Coastguard Worker} 287*333d2b36SAndroid Build Coastguard Worker 288*333d2b36SAndroid Build Coastguard Workertype apiScopes []*apiScope 289*333d2b36SAndroid Build Coastguard Worker 290*333d2b36SAndroid Build Coastguard Workerfunc (scopes apiScopes) Strings(accessor func(*apiScope) string) []string { 291*333d2b36SAndroid Build Coastguard Worker var list []string 292*333d2b36SAndroid Build Coastguard Worker for _, scope := range scopes { 293*333d2b36SAndroid Build Coastguard Worker list = append(list, accessor(scope)) 294*333d2b36SAndroid Build Coastguard Worker } 295*333d2b36SAndroid Build Coastguard Worker return list 296*333d2b36SAndroid Build Coastguard Worker} 297*333d2b36SAndroid Build Coastguard Worker 298*333d2b36SAndroid Build Coastguard Worker// Method that maps the apiScopes properties to the index of each apiScopes elements. 299*333d2b36SAndroid Build Coastguard Worker// apiScopes property to be used as the key can be specified with the input accessor. 300*333d2b36SAndroid Build Coastguard Worker// Only a string property of apiScope can be used as the key of the map. 301*333d2b36SAndroid Build Coastguard Workerfunc (scopes apiScopes) MapToIndex(accessor func(*apiScope) string) map[string]int { 302*333d2b36SAndroid Build Coastguard Worker ret := make(map[string]int) 303*333d2b36SAndroid Build Coastguard Worker for i, scope := range scopes { 304*333d2b36SAndroid Build Coastguard Worker ret[accessor(scope)] = i 305*333d2b36SAndroid Build Coastguard Worker } 306*333d2b36SAndroid Build Coastguard Worker return ret 307*333d2b36SAndroid Build Coastguard Worker} 308*333d2b36SAndroid Build Coastguard Worker 309*333d2b36SAndroid Build Coastguard Workerfunc (scopes apiScopes) ConvertStubsLibraryExportableToEverything(name string) string { 310*333d2b36SAndroid Build Coastguard Worker for _, scope := range scopes { 311*333d2b36SAndroid Build Coastguard Worker if strings.HasSuffix(name, scope.exportableStubsLibraryModuleNameSuffix()) { 312*333d2b36SAndroid Build Coastguard Worker return strings.TrimSuffix(name, scope.exportableStubsLibraryModuleNameSuffix()) + 313*333d2b36SAndroid Build Coastguard Worker scope.stubsLibraryModuleNameSuffix() 314*333d2b36SAndroid Build Coastguard Worker } 315*333d2b36SAndroid Build Coastguard Worker } 316*333d2b36SAndroid Build Coastguard Worker return name 317*333d2b36SAndroid Build Coastguard Worker} 318*333d2b36SAndroid Build Coastguard Worker 319*333d2b36SAndroid Build Coastguard Workervar ( 320*333d2b36SAndroid Build Coastguard Worker scopeByName = make(map[string]*apiScope) 321*333d2b36SAndroid Build Coastguard Worker allScopeNames []string 322*333d2b36SAndroid Build Coastguard Worker apiScopePublic = initApiScope(&apiScope{ 323*333d2b36SAndroid Build Coastguard Worker name: "public", 324*333d2b36SAndroid Build Coastguard Worker 325*333d2b36SAndroid Build Coastguard Worker // Public scope is enabled by default for both legacy and non-legacy modes. 326*333d2b36SAndroid Build Coastguard Worker legacyEnabledStatus: func(module *SdkLibrary) bool { 327*333d2b36SAndroid Build Coastguard Worker return true 328*333d2b36SAndroid Build Coastguard Worker }, 329*333d2b36SAndroid Build Coastguard Worker defaultEnabledStatus: true, 330*333d2b36SAndroid Build Coastguard Worker 331*333d2b36SAndroid Build Coastguard Worker scopeSpecificProperties: func(module *SdkLibrary) *ApiScopeProperties { 332*333d2b36SAndroid Build Coastguard Worker return &module.sdkLibraryProperties.Public 333*333d2b36SAndroid Build Coastguard Worker }, 334*333d2b36SAndroid Build Coastguard Worker sdkVersion: "current", 335*333d2b36SAndroid Build Coastguard Worker kind: android.SdkPublic, 336*333d2b36SAndroid Build Coastguard Worker }) 337*333d2b36SAndroid Build Coastguard Worker apiScopeSystem = initApiScope(&apiScope{ 338*333d2b36SAndroid Build Coastguard Worker name: "system", 339*333d2b36SAndroid Build Coastguard Worker extends: apiScopePublic, 340*333d2b36SAndroid Build Coastguard Worker legacyEnabledStatus: (*SdkLibrary).generateTestAndSystemScopesByDefault, 341*333d2b36SAndroid Build Coastguard Worker scopeSpecificProperties: func(module *SdkLibrary) *ApiScopeProperties { 342*333d2b36SAndroid Build Coastguard Worker return &module.sdkLibraryProperties.System 343*333d2b36SAndroid Build Coastguard Worker }, 344*333d2b36SAndroid Build Coastguard Worker apiFilePrefix: "system-", 345*333d2b36SAndroid Build Coastguard Worker moduleSuffix: ".system", 346*333d2b36SAndroid Build Coastguard Worker sdkVersion: "system_current", 347*333d2b36SAndroid Build Coastguard Worker annotation: "android.annotation.SystemApi(client=android.annotation.SystemApi.Client.PRIVILEGED_APPS)", 348*333d2b36SAndroid Build Coastguard Worker kind: android.SdkSystem, 349*333d2b36SAndroid Build Coastguard Worker }) 350*333d2b36SAndroid Build Coastguard Worker apiScopeTest = initApiScope(&apiScope{ 351*333d2b36SAndroid Build Coastguard Worker name: "test", 352*333d2b36SAndroid Build Coastguard Worker extends: apiScopeSystem, 353*333d2b36SAndroid Build Coastguard Worker legacyEnabledStatus: (*SdkLibrary).generateTestAndSystemScopesByDefault, 354*333d2b36SAndroid Build Coastguard Worker scopeSpecificProperties: func(module *SdkLibrary) *ApiScopeProperties { 355*333d2b36SAndroid Build Coastguard Worker return &module.sdkLibraryProperties.Test 356*333d2b36SAndroid Build Coastguard Worker }, 357*333d2b36SAndroid Build Coastguard Worker apiFilePrefix: "test-", 358*333d2b36SAndroid Build Coastguard Worker moduleSuffix: ".test", 359*333d2b36SAndroid Build Coastguard Worker sdkVersion: "test_current", 360*333d2b36SAndroid Build Coastguard Worker annotation: "android.annotation.TestApi", 361*333d2b36SAndroid Build Coastguard Worker unstable: true, 362*333d2b36SAndroid Build Coastguard Worker kind: android.SdkTest, 363*333d2b36SAndroid Build Coastguard Worker }) 364*333d2b36SAndroid Build Coastguard Worker apiScopeModuleLib = initApiScope(&apiScope{ 365*333d2b36SAndroid Build Coastguard Worker name: "module-lib", 366*333d2b36SAndroid Build Coastguard Worker extends: apiScopeSystem, 367*333d2b36SAndroid Build Coastguard Worker // The module-lib scope is disabled by default in legacy mode. 368*333d2b36SAndroid Build Coastguard Worker // 369*333d2b36SAndroid Build Coastguard Worker // Enabling this would break existing usages. 370*333d2b36SAndroid Build Coastguard Worker legacyEnabledStatus: func(module *SdkLibrary) bool { 371*333d2b36SAndroid Build Coastguard Worker return false 372*333d2b36SAndroid Build Coastguard Worker }, 373*333d2b36SAndroid Build Coastguard Worker scopeSpecificProperties: func(module *SdkLibrary) *ApiScopeProperties { 374*333d2b36SAndroid Build Coastguard Worker return &module.sdkLibraryProperties.Module_lib 375*333d2b36SAndroid Build Coastguard Worker }, 376*333d2b36SAndroid Build Coastguard Worker apiFilePrefix: "module-lib-", 377*333d2b36SAndroid Build Coastguard Worker moduleSuffix: ".module_lib", 378*333d2b36SAndroid Build Coastguard Worker sdkVersion: "module_current", 379*333d2b36SAndroid Build Coastguard Worker annotation: "android.annotation.SystemApi(client=android.annotation.SystemApi.Client.MODULE_LIBRARIES)", 380*333d2b36SAndroid Build Coastguard Worker kind: android.SdkModule, 381*333d2b36SAndroid Build Coastguard Worker }) 382*333d2b36SAndroid Build Coastguard Worker apiScopeSystemServer = initApiScope(&apiScope{ 383*333d2b36SAndroid Build Coastguard Worker name: "system-server", 384*333d2b36SAndroid Build Coastguard Worker extends: apiScopePublic, 385*333d2b36SAndroid Build Coastguard Worker 386*333d2b36SAndroid Build Coastguard Worker // The system-server scope can access the module-lib scope. 387*333d2b36SAndroid Build Coastguard Worker // 388*333d2b36SAndroid Build Coastguard Worker // A module that provides a system-server API is appended to the standard bootclasspath that is 389*333d2b36SAndroid Build Coastguard Worker // used by the system server. So, it should be able to access module-lib APIs provided by 390*333d2b36SAndroid Build Coastguard Worker // libraries on the bootclasspath. 391*333d2b36SAndroid Build Coastguard Worker canAccess: apiScopeModuleLib, 392*333d2b36SAndroid Build Coastguard Worker 393*333d2b36SAndroid Build Coastguard Worker // The system-server scope is disabled by default in legacy mode. 394*333d2b36SAndroid Build Coastguard Worker // 395*333d2b36SAndroid Build Coastguard Worker // Enabling this would break existing usages. 396*333d2b36SAndroid Build Coastguard Worker legacyEnabledStatus: func(module *SdkLibrary) bool { 397*333d2b36SAndroid Build Coastguard Worker return false 398*333d2b36SAndroid Build Coastguard Worker }, 399*333d2b36SAndroid Build Coastguard Worker scopeSpecificProperties: func(module *SdkLibrary) *ApiScopeProperties { 400*333d2b36SAndroid Build Coastguard Worker return &module.sdkLibraryProperties.System_server 401*333d2b36SAndroid Build Coastguard Worker }, 402*333d2b36SAndroid Build Coastguard Worker apiFilePrefix: "system-server-", 403*333d2b36SAndroid Build Coastguard Worker moduleSuffix: ".system_server", 404*333d2b36SAndroid Build Coastguard Worker sdkVersion: "system_server_current", 405*333d2b36SAndroid Build Coastguard Worker annotation: "android.annotation.SystemApi(client=android.annotation.SystemApi.Client.SYSTEM_SERVER)", 406*333d2b36SAndroid Build Coastguard Worker extraArgs: []string{ 407*333d2b36SAndroid Build Coastguard Worker "--hide-annotation", "android.annotation.Hide", 408*333d2b36SAndroid Build Coastguard Worker // com.android.* classes are okay in this interface" 409*333d2b36SAndroid Build Coastguard Worker "--hide", "InternalClasses", 410*333d2b36SAndroid Build Coastguard Worker }, 411*333d2b36SAndroid Build Coastguard Worker kind: android.SdkSystemServer, 412*333d2b36SAndroid Build Coastguard Worker }) 413*333d2b36SAndroid Build Coastguard Worker AllApiScopes = apiScopes{ 414*333d2b36SAndroid Build Coastguard Worker apiScopePublic, 415*333d2b36SAndroid Build Coastguard Worker apiScopeSystem, 416*333d2b36SAndroid Build Coastguard Worker apiScopeTest, 417*333d2b36SAndroid Build Coastguard Worker apiScopeModuleLib, 418*333d2b36SAndroid Build Coastguard Worker apiScopeSystemServer, 419*333d2b36SAndroid Build Coastguard Worker } 420*333d2b36SAndroid Build Coastguard Worker apiLibraryAdditionalProperties = map[string]string{ 421*333d2b36SAndroid Build Coastguard Worker "legacy.i18n.module.platform.api": "i18n.module.public.api.stubs.source.api.contribution", 422*333d2b36SAndroid Build Coastguard Worker "stable.i18n.module.platform.api": "i18n.module.public.api.stubs.source.api.contribution", 423*333d2b36SAndroid Build Coastguard Worker "conscrypt.module.platform.api": "conscrypt.module.public.api.stubs.source.api.contribution", 424*333d2b36SAndroid Build Coastguard Worker } 425*333d2b36SAndroid Build Coastguard Worker) 426*333d2b36SAndroid Build Coastguard Worker 427*333d2b36SAndroid Build Coastguard Workervar ( 428*333d2b36SAndroid Build Coastguard Worker javaSdkLibrariesLock sync.Mutex 429*333d2b36SAndroid Build Coastguard Worker) 430*333d2b36SAndroid Build Coastguard Worker 431*333d2b36SAndroid Build Coastguard Worker// TODO: these are big features that are currently missing 432*333d2b36SAndroid Build Coastguard Worker// 1) disallowing linking to the runtime shared lib 433*333d2b36SAndroid Build Coastguard Worker// 2) HTML generation 434*333d2b36SAndroid Build Coastguard Worker 435*333d2b36SAndroid Build Coastguard Workerfunc init() { 436*333d2b36SAndroid Build Coastguard Worker RegisterSdkLibraryBuildComponents(android.InitRegistrationContext) 437*333d2b36SAndroid Build Coastguard Worker 438*333d2b36SAndroid Build Coastguard Worker android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) { 439*333d2b36SAndroid Build Coastguard Worker javaSdkLibraries := javaSdkLibraries(ctx.Config()) 440*333d2b36SAndroid Build Coastguard Worker sort.Strings(*javaSdkLibraries) 441*333d2b36SAndroid Build Coastguard Worker ctx.Strict("JAVA_SDK_LIBRARIES", strings.Join(*javaSdkLibraries, " ")) 442*333d2b36SAndroid Build Coastguard Worker }) 443*333d2b36SAndroid Build Coastguard Worker 444*333d2b36SAndroid Build Coastguard Worker // Register sdk member types. 445*333d2b36SAndroid Build Coastguard Worker android.RegisterSdkMemberType(javaSdkLibrarySdkMemberType) 446*333d2b36SAndroid Build Coastguard Worker} 447*333d2b36SAndroid Build Coastguard Worker 448*333d2b36SAndroid Build Coastguard Workerfunc RegisterSdkLibraryBuildComponents(ctx android.RegistrationContext) { 449*333d2b36SAndroid Build Coastguard Worker ctx.RegisterModuleType("java_sdk_library", SdkLibraryFactory) 450*333d2b36SAndroid Build Coastguard Worker ctx.RegisterModuleType("java_sdk_library_import", sdkLibraryImportFactory) 451*333d2b36SAndroid Build Coastguard Worker} 452*333d2b36SAndroid Build Coastguard Worker 453*333d2b36SAndroid Build Coastguard Worker// Properties associated with each api scope. 454*333d2b36SAndroid Build Coastguard Workertype ApiScopeProperties struct { 455*333d2b36SAndroid Build Coastguard Worker // Indicates whether the api surface is generated. 456*333d2b36SAndroid Build Coastguard Worker // 457*333d2b36SAndroid Build Coastguard Worker // If this is set for any scope then all scopes must explicitly specify if they 458*333d2b36SAndroid Build Coastguard Worker // are enabled. This is to prevent new usages from depending on legacy behavior. 459*333d2b36SAndroid Build Coastguard Worker // 460*333d2b36SAndroid Build Coastguard Worker // Otherwise, if this is not set for any scope then the default behavior is 461*333d2b36SAndroid Build Coastguard Worker // scope specific so please refer to the scope specific property documentation. 462*333d2b36SAndroid Build Coastguard Worker Enabled *bool 463*333d2b36SAndroid Build Coastguard Worker 464*333d2b36SAndroid Build Coastguard Worker // The sdk_version to use for building the stubs. 465*333d2b36SAndroid Build Coastguard Worker // 466*333d2b36SAndroid Build Coastguard Worker // If not specified then it will use an sdk_version determined as follows: 467*333d2b36SAndroid Build Coastguard Worker // 468*333d2b36SAndroid Build Coastguard Worker // 1) If the sdk_version specified on the java_sdk_library is none then this 469*333d2b36SAndroid Build Coastguard Worker // will be none. This is used for java_sdk_library instances that are used 470*333d2b36SAndroid Build Coastguard Worker // to create stubs that contribute to the core_current sdk version. 471*333d2b36SAndroid Build Coastguard Worker // 2) Otherwise, it is assumed that this library extends but does not 472*333d2b36SAndroid Build Coastguard Worker // contribute directly to a specific sdk_version and so this uses the 473*333d2b36SAndroid Build Coastguard Worker // sdk_version appropriate for the api scope. e.g. public will use 474*333d2b36SAndroid Build Coastguard Worker // sdk_version: current, system will use sdk_version: system_current, etc. 475*333d2b36SAndroid Build Coastguard Worker // 476*333d2b36SAndroid Build Coastguard Worker // This does not affect the sdk_version used for either generating the stubs source 477*333d2b36SAndroid Build Coastguard Worker // or the API file. They both have to use the same sdk_version as is used for 478*333d2b36SAndroid Build Coastguard Worker // compiling the implementation library. 479*333d2b36SAndroid Build Coastguard Worker Sdk_version *string 480*333d2b36SAndroid Build Coastguard Worker 481*333d2b36SAndroid Build Coastguard Worker // Extra libs used when compiling stubs for this scope. 482*333d2b36SAndroid Build Coastguard Worker Libs []string 483*333d2b36SAndroid Build Coastguard Worker} 484*333d2b36SAndroid Build Coastguard Worker 485*333d2b36SAndroid Build Coastguard Workertype sdkLibraryProperties struct { 486*333d2b36SAndroid Build Coastguard Worker // List of source files that are needed to compile the API, but are not part of runtime library. 487*333d2b36SAndroid Build Coastguard Worker Api_srcs []string `android:"arch_variant"` 488*333d2b36SAndroid Build Coastguard Worker 489*333d2b36SAndroid Build Coastguard Worker // Visibility for impl library module. If not specified then defaults to the 490*333d2b36SAndroid Build Coastguard Worker // visibility property. 491*333d2b36SAndroid Build Coastguard Worker Impl_library_visibility []string 492*333d2b36SAndroid Build Coastguard Worker 493*333d2b36SAndroid Build Coastguard Worker // Visibility for stubs library modules. If not specified then defaults to the 494*333d2b36SAndroid Build Coastguard Worker // visibility property. 495*333d2b36SAndroid Build Coastguard Worker Stubs_library_visibility []string 496*333d2b36SAndroid Build Coastguard Worker 497*333d2b36SAndroid Build Coastguard Worker // Visibility for stubs source modules. If not specified then defaults to the 498*333d2b36SAndroid Build Coastguard Worker // visibility property. 499*333d2b36SAndroid Build Coastguard Worker Stubs_source_visibility []string 500*333d2b36SAndroid Build Coastguard Worker 501*333d2b36SAndroid Build Coastguard Worker // List of Java libraries that will be in the classpath when building the implementation lib 502*333d2b36SAndroid Build Coastguard Worker Impl_only_libs []string `android:"arch_variant"` 503*333d2b36SAndroid Build Coastguard Worker 504*333d2b36SAndroid Build Coastguard Worker // List of Java libraries that will included in the implementation lib. 505*333d2b36SAndroid Build Coastguard Worker Impl_only_static_libs []string `android:"arch_variant"` 506*333d2b36SAndroid Build Coastguard Worker 507*333d2b36SAndroid Build Coastguard Worker // List of Java libraries that will be in the classpath when building stubs 508*333d2b36SAndroid Build Coastguard Worker Stub_only_libs []string `android:"arch_variant"` 509*333d2b36SAndroid Build Coastguard Worker 510*333d2b36SAndroid Build Coastguard Worker // List of Java libraries that will included in stub libraries 511*333d2b36SAndroid Build Coastguard Worker Stub_only_static_libs []string `android:"arch_variant"` 512*333d2b36SAndroid Build Coastguard Worker 513*333d2b36SAndroid Build Coastguard Worker // list of package names that will be documented and publicized as API. 514*333d2b36SAndroid Build Coastguard Worker // This allows the API to be restricted to a subset of the source files provided. 515*333d2b36SAndroid Build Coastguard Worker // If this is unspecified then all the source files will be treated as being part 516*333d2b36SAndroid Build Coastguard Worker // of the API. 517*333d2b36SAndroid Build Coastguard Worker Api_packages []string 518*333d2b36SAndroid Build Coastguard Worker 519*333d2b36SAndroid Build Coastguard Worker // the relative path to the directory containing the api specification files. 520*333d2b36SAndroid Build Coastguard Worker // Defaults to "api". 521*333d2b36SAndroid Build Coastguard Worker Api_dir *string 522*333d2b36SAndroid Build Coastguard Worker 523*333d2b36SAndroid Build Coastguard Worker // Determines whether a runtime implementation library is built; defaults to false. 524*333d2b36SAndroid Build Coastguard Worker // 525*333d2b36SAndroid Build Coastguard Worker // If true then it also prevents the module from being used as a shared module, i.e. 526*333d2b36SAndroid Build Coastguard Worker // it is as if shared_library: false, was set. 527*333d2b36SAndroid Build Coastguard Worker Api_only *bool 528*333d2b36SAndroid Build Coastguard Worker 529*333d2b36SAndroid Build Coastguard Worker // local files that are used within user customized droiddoc options. 530*333d2b36SAndroid Build Coastguard Worker Droiddoc_option_files []string 531*333d2b36SAndroid Build Coastguard Worker 532*333d2b36SAndroid Build Coastguard Worker // additional droiddoc options. 533*333d2b36SAndroid Build Coastguard Worker // Available variables for substitution: 534*333d2b36SAndroid Build Coastguard Worker // 535*333d2b36SAndroid Build Coastguard Worker // $(location <label>): the path to the droiddoc_option_files with name <label> 536*333d2b36SAndroid Build Coastguard Worker Droiddoc_options []string 537*333d2b36SAndroid Build Coastguard Worker 538*333d2b36SAndroid Build Coastguard Worker // is set to true, Metalava will allow framework SDK to contain annotations. 539*333d2b36SAndroid Build Coastguard Worker Annotations_enabled *bool 540*333d2b36SAndroid Build Coastguard Worker 541*333d2b36SAndroid Build Coastguard Worker // a list of top-level directories containing files to merge qualifier annotations 542*333d2b36SAndroid Build Coastguard Worker // (i.e. those intended to be included in the stubs written) from. 543*333d2b36SAndroid Build Coastguard Worker Merge_annotations_dirs []string 544*333d2b36SAndroid Build Coastguard Worker 545*333d2b36SAndroid Build Coastguard Worker // a list of top-level directories containing Java stub files to merge show/hide annotations from. 546*333d2b36SAndroid Build Coastguard Worker Merge_inclusion_annotations_dirs []string 547*333d2b36SAndroid Build Coastguard Worker 548*333d2b36SAndroid Build Coastguard Worker // If set to true then don't create dist rules. 549*333d2b36SAndroid Build Coastguard Worker No_dist *bool 550*333d2b36SAndroid Build Coastguard Worker 551*333d2b36SAndroid Build Coastguard Worker // The stem for the artifacts that are copied to the dist, if not specified 552*333d2b36SAndroid Build Coastguard Worker // then defaults to the base module name. 553*333d2b36SAndroid Build Coastguard Worker // 554*333d2b36SAndroid Build Coastguard Worker // For each scope the following artifacts are copied to the apistubs/<scope> 555*333d2b36SAndroid Build Coastguard Worker // directory in the dist. 556*333d2b36SAndroid Build Coastguard Worker // * stubs impl jar -> <dist-stem>.jar 557*333d2b36SAndroid Build Coastguard Worker // * API specification file -> api/<dist-stem>.txt 558*333d2b36SAndroid Build Coastguard Worker // * Removed API specification file -> api/<dist-stem>-removed.txt 559*333d2b36SAndroid Build Coastguard Worker // 560*333d2b36SAndroid Build Coastguard Worker // Also used to construct the name of the filegroup (created by prebuilt_apis) 561*333d2b36SAndroid Build Coastguard Worker // that references the latest released API and remove API specification files. 562*333d2b36SAndroid Build Coastguard Worker // * API specification filegroup -> <dist-stem>.api.<scope>.latest 563*333d2b36SAndroid Build Coastguard Worker // * Removed API specification filegroup -> <dist-stem>-removed.api.<scope>.latest 564*333d2b36SAndroid Build Coastguard Worker // * API incompatibilities baseline filegroup -> <dist-stem>-incompatibilities.api.<scope>.latest 565*333d2b36SAndroid Build Coastguard Worker Dist_stem *string 566*333d2b36SAndroid Build Coastguard Worker 567*333d2b36SAndroid Build Coastguard Worker // The subdirectory for the artifacts that are copied to the dist directory. If not specified 568*333d2b36SAndroid Build Coastguard Worker // then defaults to "unknown". Should be set to "android" for anything that should be published 569*333d2b36SAndroid Build Coastguard Worker // in the public Android SDK. 570*333d2b36SAndroid Build Coastguard Worker Dist_group *string 571*333d2b36SAndroid Build Coastguard Worker 572*333d2b36SAndroid Build Coastguard Worker // A compatibility mode that allows historical API-tracking files to not exist. 573*333d2b36SAndroid Build Coastguard Worker // Do not use. 574*333d2b36SAndroid Build Coastguard Worker Unsafe_ignore_missing_latest_api bool 575*333d2b36SAndroid Build Coastguard Worker 576*333d2b36SAndroid Build Coastguard Worker // indicates whether system and test apis should be generated. 577*333d2b36SAndroid Build Coastguard Worker Generate_system_and_test_apis bool `blueprint:"mutated"` 578*333d2b36SAndroid Build Coastguard Worker 579*333d2b36SAndroid Build Coastguard Worker // The properties specific to the public api scope 580*333d2b36SAndroid Build Coastguard Worker // 581*333d2b36SAndroid Build Coastguard Worker // Unless explicitly specified by using public.enabled the public api scope is 582*333d2b36SAndroid Build Coastguard Worker // enabled by default in both legacy and non-legacy mode. 583*333d2b36SAndroid Build Coastguard Worker Public ApiScopeProperties 584*333d2b36SAndroid Build Coastguard Worker 585*333d2b36SAndroid Build Coastguard Worker // The properties specific to the system api scope 586*333d2b36SAndroid Build Coastguard Worker // 587*333d2b36SAndroid Build Coastguard Worker // In legacy mode the system api scope is enabled by default when sdk_version 588*333d2b36SAndroid Build Coastguard Worker // is set to something other than "none". 589*333d2b36SAndroid Build Coastguard Worker // 590*333d2b36SAndroid Build Coastguard Worker // In non-legacy mode the system api scope is disabled by default. 591*333d2b36SAndroid Build Coastguard Worker System ApiScopeProperties 592*333d2b36SAndroid Build Coastguard Worker 593*333d2b36SAndroid Build Coastguard Worker // The properties specific to the test api scope 594*333d2b36SAndroid Build Coastguard Worker // 595*333d2b36SAndroid Build Coastguard Worker // In legacy mode the test api scope is enabled by default when sdk_version 596*333d2b36SAndroid Build Coastguard Worker // is set to something other than "none". 597*333d2b36SAndroid Build Coastguard Worker // 598*333d2b36SAndroid Build Coastguard Worker // In non-legacy mode the test api scope is disabled by default. 599*333d2b36SAndroid Build Coastguard Worker Test ApiScopeProperties 600*333d2b36SAndroid Build Coastguard Worker 601*333d2b36SAndroid Build Coastguard Worker // The properties specific to the module-lib api scope 602*333d2b36SAndroid Build Coastguard Worker // 603*333d2b36SAndroid Build Coastguard Worker // Unless explicitly specified by using module_lib.enabled the module_lib api 604*333d2b36SAndroid Build Coastguard Worker // scope is disabled by default. 605*333d2b36SAndroid Build Coastguard Worker Module_lib ApiScopeProperties 606*333d2b36SAndroid Build Coastguard Worker 607*333d2b36SAndroid Build Coastguard Worker // The properties specific to the system-server api scope 608*333d2b36SAndroid Build Coastguard Worker // 609*333d2b36SAndroid Build Coastguard Worker // Unless explicitly specified by using system_server.enabled the 610*333d2b36SAndroid Build Coastguard Worker // system_server api scope is disabled by default. 611*333d2b36SAndroid Build Coastguard Worker System_server ApiScopeProperties 612*333d2b36SAndroid Build Coastguard Worker 613*333d2b36SAndroid Build Coastguard Worker // Determines if the stubs are preferred over the implementation library 614*333d2b36SAndroid Build Coastguard Worker // for linking, even when the client doesn't specify sdk_version. When this 615*333d2b36SAndroid Build Coastguard Worker // is set to true, such clients are provided with the widest API surface that 616*333d2b36SAndroid Build Coastguard Worker // this lib provides. Note however that this option doesn't affect the clients 617*333d2b36SAndroid Build Coastguard Worker // that are in the same APEX as this library. In that case, the clients are 618*333d2b36SAndroid Build Coastguard Worker // always linked with the implementation library. Default is false. 619*333d2b36SAndroid Build Coastguard Worker Default_to_stubs *bool 620*333d2b36SAndroid Build Coastguard Worker 621*333d2b36SAndroid Build Coastguard Worker // Properties related to api linting. 622*333d2b36SAndroid Build Coastguard Worker Api_lint struct { 623*333d2b36SAndroid Build Coastguard Worker // Enable api linting. 624*333d2b36SAndroid Build Coastguard Worker Enabled *bool 625*333d2b36SAndroid Build Coastguard Worker 626*333d2b36SAndroid Build Coastguard Worker // If API lint is enabled, this flag controls whether a set of legitimate lint errors 627*333d2b36SAndroid Build Coastguard Worker // are turned off. The default is true. 628*333d2b36SAndroid Build Coastguard Worker Legacy_errors_allowed *bool 629*333d2b36SAndroid Build Coastguard Worker } 630*333d2b36SAndroid Build Coastguard Worker 631*333d2b36SAndroid Build Coastguard Worker // a list of aconfig_declarations module names that the stubs generated in this module 632*333d2b36SAndroid Build Coastguard Worker // depend on. 633*333d2b36SAndroid Build Coastguard Worker Aconfig_declarations []string 634*333d2b36SAndroid Build Coastguard Worker 635*333d2b36SAndroid Build Coastguard Worker // Determines if the module generates the stubs from the api signature files 636*333d2b36SAndroid Build Coastguard Worker // instead of the source Java files. Defaults to true. 637*333d2b36SAndroid Build Coastguard Worker Build_from_text_stub *bool 638*333d2b36SAndroid Build Coastguard Worker 639*333d2b36SAndroid Build Coastguard Worker // TODO: determines whether to create HTML doc or not 640*333d2b36SAndroid Build Coastguard Worker // Html_doc *bool 641*333d2b36SAndroid Build Coastguard Worker} 642*333d2b36SAndroid Build Coastguard Worker 643*333d2b36SAndroid Build Coastguard Worker// Paths to outputs from java_sdk_library and java_sdk_library_import. 644*333d2b36SAndroid Build Coastguard Worker// 645*333d2b36SAndroid Build Coastguard Worker// Fields that are android.Paths are always set (during GenerateAndroidBuildActions). 646*333d2b36SAndroid Build Coastguard Worker// OptionalPaths are always set by java_sdk_library but may not be set by 647*333d2b36SAndroid Build Coastguard Worker// java_sdk_library_import as not all instances provide that information. 648*333d2b36SAndroid Build Coastguard Workertype scopePaths struct { 649*333d2b36SAndroid Build Coastguard Worker // The path (represented as Paths for convenience when returning) to the stubs header jar. 650*333d2b36SAndroid Build Coastguard Worker // 651*333d2b36SAndroid Build Coastguard Worker // That is the jar that is created by turbine. 652*333d2b36SAndroid Build Coastguard Worker stubsHeaderPath android.Paths 653*333d2b36SAndroid Build Coastguard Worker 654*333d2b36SAndroid Build Coastguard Worker // The path (represented as Paths for convenience when returning) to the stubs implementation jar. 655*333d2b36SAndroid Build Coastguard Worker // 656*333d2b36SAndroid Build Coastguard Worker // This is not the implementation jar, it still only contains stubs. 657*333d2b36SAndroid Build Coastguard Worker stubsImplPath android.Paths 658*333d2b36SAndroid Build Coastguard Worker 659*333d2b36SAndroid Build Coastguard Worker // The dex jar for the stubs. 660*333d2b36SAndroid Build Coastguard Worker // 661*333d2b36SAndroid Build Coastguard Worker // This is not the implementation jar, it still only contains stubs. 662*333d2b36SAndroid Build Coastguard Worker stubsDexJarPath OptionalDexJarPath 663*333d2b36SAndroid Build Coastguard Worker 664*333d2b36SAndroid Build Coastguard Worker // The exportable dex jar for the stubs. 665*333d2b36SAndroid Build Coastguard Worker // This is not the implementation jar, it still only contains stubs. 666*333d2b36SAndroid Build Coastguard Worker // Includes unflagged apis and flagged apis enabled by release configurations. 667*333d2b36SAndroid Build Coastguard Worker exportableStubsDexJarPath OptionalDexJarPath 668*333d2b36SAndroid Build Coastguard Worker 669*333d2b36SAndroid Build Coastguard Worker // The API specification file, e.g. system_current.txt. 670*333d2b36SAndroid Build Coastguard Worker currentApiFilePath android.OptionalPath 671*333d2b36SAndroid Build Coastguard Worker 672*333d2b36SAndroid Build Coastguard Worker // The specification of API elements removed since the last release. 673*333d2b36SAndroid Build Coastguard Worker removedApiFilePath android.OptionalPath 674*333d2b36SAndroid Build Coastguard Worker 675*333d2b36SAndroid Build Coastguard Worker // The stubs source jar. 676*333d2b36SAndroid Build Coastguard Worker stubsSrcJar android.OptionalPath 677*333d2b36SAndroid Build Coastguard Worker 678*333d2b36SAndroid Build Coastguard Worker // Extracted annotations. 679*333d2b36SAndroid Build Coastguard Worker annotationsZip android.OptionalPath 680*333d2b36SAndroid Build Coastguard Worker 681*333d2b36SAndroid Build Coastguard Worker // The path to the latest API file. 682*333d2b36SAndroid Build Coastguard Worker latestApiPaths android.Paths 683*333d2b36SAndroid Build Coastguard Worker 684*333d2b36SAndroid Build Coastguard Worker // The path to the latest removed API file. 685*333d2b36SAndroid Build Coastguard Worker latestRemovedApiPaths android.Paths 686*333d2b36SAndroid Build Coastguard Worker} 687*333d2b36SAndroid Build Coastguard Worker 688*333d2b36SAndroid Build Coastguard Workerfunc (paths *scopePaths) extractStubsLibraryInfoFromDependency(ctx android.ModuleContext, dep android.Module) error { 689*333d2b36SAndroid Build Coastguard Worker if lib, ok := android.OtherModuleProvider(ctx, dep, JavaInfoProvider); ok { 690*333d2b36SAndroid Build Coastguard Worker paths.stubsHeaderPath = lib.HeaderJars 691*333d2b36SAndroid Build Coastguard Worker paths.stubsImplPath = lib.ImplementationJars 692*333d2b36SAndroid Build Coastguard Worker 693*333d2b36SAndroid Build Coastguard Worker libDep := dep.(UsesLibraryDependency) 694*333d2b36SAndroid Build Coastguard Worker paths.stubsDexJarPath = libDep.DexJarBuildPath(ctx) 695*333d2b36SAndroid Build Coastguard Worker paths.exportableStubsDexJarPath = libDep.DexJarBuildPath(ctx) 696*333d2b36SAndroid Build Coastguard Worker return nil 697*333d2b36SAndroid Build Coastguard Worker } else { 698*333d2b36SAndroid Build Coastguard Worker return fmt.Errorf("expected module that has JavaInfoProvider, e.g. java_library") 699*333d2b36SAndroid Build Coastguard Worker } 700*333d2b36SAndroid Build Coastguard Worker} 701*333d2b36SAndroid Build Coastguard Worker 702*333d2b36SAndroid Build Coastguard Workerfunc (paths *scopePaths) extractEverythingStubsLibraryInfoFromDependency(ctx android.ModuleContext, dep android.Module) error { 703*333d2b36SAndroid Build Coastguard Worker if lib, ok := android.OtherModuleProvider(ctx, dep, JavaInfoProvider); ok { 704*333d2b36SAndroid Build Coastguard Worker paths.stubsHeaderPath = lib.HeaderJars 705*333d2b36SAndroid Build Coastguard Worker if !ctx.Config().ReleaseHiddenApiExportableStubs() { 706*333d2b36SAndroid Build Coastguard Worker paths.stubsImplPath = lib.ImplementationJars 707*333d2b36SAndroid Build Coastguard Worker } 708*333d2b36SAndroid Build Coastguard Worker 709*333d2b36SAndroid Build Coastguard Worker libDep := dep.(UsesLibraryDependency) 710*333d2b36SAndroid Build Coastguard Worker paths.stubsDexJarPath = libDep.DexJarBuildPath(ctx) 711*333d2b36SAndroid Build Coastguard Worker return nil 712*333d2b36SAndroid Build Coastguard Worker } else { 713*333d2b36SAndroid Build Coastguard Worker return fmt.Errorf("expected module that has JavaInfoProvider, e.g. java_library") 714*333d2b36SAndroid Build Coastguard Worker } 715*333d2b36SAndroid Build Coastguard Worker} 716*333d2b36SAndroid Build Coastguard Worker 717*333d2b36SAndroid Build Coastguard Workerfunc (paths *scopePaths) extractExportableStubsLibraryInfoFromDependency(ctx android.ModuleContext, dep android.Module) error { 718*333d2b36SAndroid Build Coastguard Worker if lib, ok := android.OtherModuleProvider(ctx, dep, JavaInfoProvider); ok { 719*333d2b36SAndroid Build Coastguard Worker if ctx.Config().ReleaseHiddenApiExportableStubs() { 720*333d2b36SAndroid Build Coastguard Worker paths.stubsImplPath = lib.ImplementationJars 721*333d2b36SAndroid Build Coastguard Worker } 722*333d2b36SAndroid Build Coastguard Worker 723*333d2b36SAndroid Build Coastguard Worker libDep := dep.(UsesLibraryDependency) 724*333d2b36SAndroid Build Coastguard Worker paths.exportableStubsDexJarPath = libDep.DexJarBuildPath(ctx) 725*333d2b36SAndroid Build Coastguard Worker return nil 726*333d2b36SAndroid Build Coastguard Worker } else { 727*333d2b36SAndroid Build Coastguard Worker return fmt.Errorf("expected module that has JavaInfoProvider, e.g. java_library") 728*333d2b36SAndroid Build Coastguard Worker } 729*333d2b36SAndroid Build Coastguard Worker} 730*333d2b36SAndroid Build Coastguard Worker 731*333d2b36SAndroid Build Coastguard Workerfunc (paths *scopePaths) treatDepAsApiStubsProvider(dep android.Module, action func(provider ApiStubsProvider) error) error { 732*333d2b36SAndroid Build Coastguard Worker if apiStubsProvider, ok := dep.(ApiStubsProvider); ok { 733*333d2b36SAndroid Build Coastguard Worker err := action(apiStubsProvider) 734*333d2b36SAndroid Build Coastguard Worker if err != nil { 735*333d2b36SAndroid Build Coastguard Worker return err 736*333d2b36SAndroid Build Coastguard Worker } 737*333d2b36SAndroid Build Coastguard Worker return nil 738*333d2b36SAndroid Build Coastguard Worker } else { 739*333d2b36SAndroid Build Coastguard Worker return fmt.Errorf("expected module that implements ExportableApiStubsSrcProvider, e.g. droidstubs") 740*333d2b36SAndroid Build Coastguard Worker } 741*333d2b36SAndroid Build Coastguard Worker} 742*333d2b36SAndroid Build Coastguard Worker 743*333d2b36SAndroid Build Coastguard Workerfunc (paths *scopePaths) treatDepAsApiStubsSrcProvider(dep android.Module, action func(provider ApiStubsSrcProvider) error) error { 744*333d2b36SAndroid Build Coastguard Worker if apiStubsProvider, ok := dep.(ApiStubsSrcProvider); ok { 745*333d2b36SAndroid Build Coastguard Worker err := action(apiStubsProvider) 746*333d2b36SAndroid Build Coastguard Worker if err != nil { 747*333d2b36SAndroid Build Coastguard Worker return err 748*333d2b36SAndroid Build Coastguard Worker } 749*333d2b36SAndroid Build Coastguard Worker return nil 750*333d2b36SAndroid Build Coastguard Worker } else { 751*333d2b36SAndroid Build Coastguard Worker return fmt.Errorf("expected module that implements ApiStubsSrcProvider, e.g. droidstubs") 752*333d2b36SAndroid Build Coastguard Worker } 753*333d2b36SAndroid Build Coastguard Worker} 754*333d2b36SAndroid Build Coastguard Worker 755*333d2b36SAndroid Build Coastguard Workerfunc (paths *scopePaths) extractApiInfoFromApiStubsProvider(provider ApiStubsProvider, stubsType StubsType) error { 756*333d2b36SAndroid Build Coastguard Worker var annotationsZip, currentApiFilePath, removedApiFilePath android.Path 757*333d2b36SAndroid Build Coastguard Worker annotationsZip, annotationsZipErr := provider.AnnotationsZip(stubsType) 758*333d2b36SAndroid Build Coastguard Worker currentApiFilePath, currentApiFilePathErr := provider.ApiFilePath(stubsType) 759*333d2b36SAndroid Build Coastguard Worker removedApiFilePath, removedApiFilePathErr := provider.RemovedApiFilePath(stubsType) 760*333d2b36SAndroid Build Coastguard Worker 761*333d2b36SAndroid Build Coastguard Worker combinedError := errors.Join(annotationsZipErr, currentApiFilePathErr, removedApiFilePathErr) 762*333d2b36SAndroid Build Coastguard Worker 763*333d2b36SAndroid Build Coastguard Worker if combinedError == nil { 764*333d2b36SAndroid Build Coastguard Worker paths.annotationsZip = android.OptionalPathForPath(annotationsZip) 765*333d2b36SAndroid Build Coastguard Worker paths.currentApiFilePath = android.OptionalPathForPath(currentApiFilePath) 766*333d2b36SAndroid Build Coastguard Worker paths.removedApiFilePath = android.OptionalPathForPath(removedApiFilePath) 767*333d2b36SAndroid Build Coastguard Worker } 768*333d2b36SAndroid Build Coastguard Worker return combinedError 769*333d2b36SAndroid Build Coastguard Worker} 770*333d2b36SAndroid Build Coastguard Worker 771*333d2b36SAndroid Build Coastguard Workerfunc (paths *scopePaths) extractStubsSourceInfoFromApiStubsProviders(provider ApiStubsSrcProvider, stubsType StubsType) error { 772*333d2b36SAndroid Build Coastguard Worker stubsSrcJar, err := provider.StubsSrcJar(stubsType) 773*333d2b36SAndroid Build Coastguard Worker if err == nil { 774*333d2b36SAndroid Build Coastguard Worker paths.stubsSrcJar = android.OptionalPathForPath(stubsSrcJar) 775*333d2b36SAndroid Build Coastguard Worker } 776*333d2b36SAndroid Build Coastguard Worker return err 777*333d2b36SAndroid Build Coastguard Worker} 778*333d2b36SAndroid Build Coastguard Worker 779*333d2b36SAndroid Build Coastguard Workerfunc (paths *scopePaths) extractStubsSourceInfoFromDep(ctx android.ModuleContext, dep android.Module) error { 780*333d2b36SAndroid Build Coastguard Worker stubsType := Everything 781*333d2b36SAndroid Build Coastguard Worker if ctx.Config().ReleaseHiddenApiExportableStubs() { 782*333d2b36SAndroid Build Coastguard Worker stubsType = Exportable 783*333d2b36SAndroid Build Coastguard Worker } 784*333d2b36SAndroid Build Coastguard Worker return paths.treatDepAsApiStubsSrcProvider(dep, func(provider ApiStubsSrcProvider) error { 785*333d2b36SAndroid Build Coastguard Worker return paths.extractStubsSourceInfoFromApiStubsProviders(provider, stubsType) 786*333d2b36SAndroid Build Coastguard Worker }) 787*333d2b36SAndroid Build Coastguard Worker} 788*333d2b36SAndroid Build Coastguard Worker 789*333d2b36SAndroid Build Coastguard Workerfunc (paths *scopePaths) extractStubsSourceAndApiInfoFromApiStubsProvider(ctx android.ModuleContext, dep android.Module) error { 790*333d2b36SAndroid Build Coastguard Worker stubsType := Everything 791*333d2b36SAndroid Build Coastguard Worker if ctx.Config().ReleaseHiddenApiExportableStubs() { 792*333d2b36SAndroid Build Coastguard Worker stubsType = Exportable 793*333d2b36SAndroid Build Coastguard Worker } 794*333d2b36SAndroid Build Coastguard Worker return paths.treatDepAsApiStubsProvider(dep, func(provider ApiStubsProvider) error { 795*333d2b36SAndroid Build Coastguard Worker extractApiInfoErr := paths.extractApiInfoFromApiStubsProvider(provider, stubsType) 796*333d2b36SAndroid Build Coastguard Worker extractStubsSourceInfoErr := paths.extractStubsSourceInfoFromApiStubsProviders(provider, stubsType) 797*333d2b36SAndroid Build Coastguard Worker return errors.Join(extractApiInfoErr, extractStubsSourceInfoErr) 798*333d2b36SAndroid Build Coastguard Worker }) 799*333d2b36SAndroid Build Coastguard Worker} 800*333d2b36SAndroid Build Coastguard Worker 801*333d2b36SAndroid Build Coastguard Workerfunc extractOutputPaths(dep android.Module) (android.Paths, error) { 802*333d2b36SAndroid Build Coastguard Worker var paths android.Paths 803*333d2b36SAndroid Build Coastguard Worker if sourceFileProducer, ok := dep.(android.SourceFileProducer); ok { 804*333d2b36SAndroid Build Coastguard Worker paths = sourceFileProducer.Srcs() 805*333d2b36SAndroid Build Coastguard Worker return paths, nil 806*333d2b36SAndroid Build Coastguard Worker } else { 807*333d2b36SAndroid Build Coastguard Worker return nil, fmt.Errorf("module %q does not produce source files", dep) 808*333d2b36SAndroid Build Coastguard Worker } 809*333d2b36SAndroid Build Coastguard Worker} 810*333d2b36SAndroid Build Coastguard Worker 811*333d2b36SAndroid Build Coastguard Workerfunc (paths *scopePaths) extractLatestApiPath(ctx android.ModuleContext, dep android.Module) error { 812*333d2b36SAndroid Build Coastguard Worker outputPaths, err := extractOutputPaths(dep) 813*333d2b36SAndroid Build Coastguard Worker paths.latestApiPaths = outputPaths 814*333d2b36SAndroid Build Coastguard Worker return err 815*333d2b36SAndroid Build Coastguard Worker} 816*333d2b36SAndroid Build Coastguard Worker 817*333d2b36SAndroid Build Coastguard Workerfunc (paths *scopePaths) extractLatestRemovedApiPath(ctx android.ModuleContext, dep android.Module) error { 818*333d2b36SAndroid Build Coastguard Worker outputPaths, err := extractOutputPaths(dep) 819*333d2b36SAndroid Build Coastguard Worker paths.latestRemovedApiPaths = outputPaths 820*333d2b36SAndroid Build Coastguard Worker return err 821*333d2b36SAndroid Build Coastguard Worker} 822*333d2b36SAndroid Build Coastguard Worker 823*333d2b36SAndroid Build Coastguard Workertype commonToSdkLibraryAndImportProperties struct { 824*333d2b36SAndroid Build Coastguard Worker // Specifies whether this module can be used as an Android shared library; defaults 825*333d2b36SAndroid Build Coastguard Worker // to true. 826*333d2b36SAndroid Build Coastguard Worker // 827*333d2b36SAndroid Build Coastguard Worker // An Android shared library is one that can be referenced in a <uses-library> element 828*333d2b36SAndroid Build Coastguard Worker // in an AndroidManifest.xml. 829*333d2b36SAndroid Build Coastguard Worker Shared_library *bool 830*333d2b36SAndroid Build Coastguard Worker 831*333d2b36SAndroid Build Coastguard Worker // Files containing information about supported java doc tags. 832*333d2b36SAndroid Build Coastguard Worker Doctag_files []string `android:"path"` 833*333d2b36SAndroid Build Coastguard Worker 834*333d2b36SAndroid Build Coastguard Worker // Signals that this shared library is part of the bootclasspath starting 835*333d2b36SAndroid Build Coastguard Worker // on the version indicated in this attribute. 836*333d2b36SAndroid Build Coastguard Worker // 837*333d2b36SAndroid Build Coastguard Worker // This will make platforms at this level and above to ignore 838*333d2b36SAndroid Build Coastguard Worker // <uses-library> tags with this library name because the library is already 839*333d2b36SAndroid Build Coastguard Worker // available 840*333d2b36SAndroid Build Coastguard Worker On_bootclasspath_since *string 841*333d2b36SAndroid Build Coastguard Worker 842*333d2b36SAndroid Build Coastguard Worker // Signals that this shared library was part of the bootclasspath before 843*333d2b36SAndroid Build Coastguard Worker // (but not including) the version indicated in this attribute. 844*333d2b36SAndroid Build Coastguard Worker // 845*333d2b36SAndroid Build Coastguard Worker // The system will automatically add a <uses-library> tag with this library to 846*333d2b36SAndroid Build Coastguard Worker // apps that target any SDK less than the version indicated in this attribute. 847*333d2b36SAndroid Build Coastguard Worker On_bootclasspath_before *string 848*333d2b36SAndroid Build Coastguard Worker 849*333d2b36SAndroid Build Coastguard Worker // Indicates that PackageManager should ignore this shared library if the 850*333d2b36SAndroid Build Coastguard Worker // platform is below the version indicated in this attribute. 851*333d2b36SAndroid Build Coastguard Worker // 852*333d2b36SAndroid Build Coastguard Worker // This means that the device won't recognise this library as installed. 853*333d2b36SAndroid Build Coastguard Worker Min_device_sdk *string 854*333d2b36SAndroid Build Coastguard Worker 855*333d2b36SAndroid Build Coastguard Worker // Indicates that PackageManager should ignore this shared library if the 856*333d2b36SAndroid Build Coastguard Worker // platform is above the version indicated in this attribute. 857*333d2b36SAndroid Build Coastguard Worker // 858*333d2b36SAndroid Build Coastguard Worker // This means that the device won't recognise this library as installed. 859*333d2b36SAndroid Build Coastguard Worker Max_device_sdk *string 860*333d2b36SAndroid Build Coastguard Worker} 861*333d2b36SAndroid Build Coastguard Worker 862*333d2b36SAndroid Build Coastguard Worker// commonSdkLibraryAndImportModule defines the interface that must be provided by a module that 863*333d2b36SAndroid Build Coastguard Worker// embeds the commonToSdkLibraryAndImport struct. 864*333d2b36SAndroid Build Coastguard Workertype commonSdkLibraryAndImportModule interface { 865*333d2b36SAndroid Build Coastguard Worker android.Module 866*333d2b36SAndroid Build Coastguard Worker 867*333d2b36SAndroid Build Coastguard Worker // Returns the name of the root java_sdk_library that creates the child stub libraries 868*333d2b36SAndroid Build Coastguard Worker // This is the `name` as it appears in Android.bp, and not the name in Soong's build graph 869*333d2b36SAndroid Build Coastguard Worker // (with the prebuilt_ prefix) 870*333d2b36SAndroid Build Coastguard Worker // 871*333d2b36SAndroid Build Coastguard Worker // e.g. in the following java_sdk_library_import 872*333d2b36SAndroid Build Coastguard Worker // java_sdk_library_import { 873*333d2b36SAndroid Build Coastguard Worker // name: "framework-foo.v1", 874*333d2b36SAndroid Build Coastguard Worker // source_module_name: "framework-foo", 875*333d2b36SAndroid Build Coastguard Worker // } 876*333d2b36SAndroid Build Coastguard Worker // the values returned by 877*333d2b36SAndroid Build Coastguard Worker // 1. Name(): prebuilt_framework-foo.v1 # unique 878*333d2b36SAndroid Build Coastguard Worker // 2. BaseModuleName(): framework-foo # the source 879*333d2b36SAndroid Build Coastguard Worker // 3. RootLibraryName: framework-foo.v1 # the undecordated `name` from Android.bp 880*333d2b36SAndroid Build Coastguard Worker RootLibraryName() string 881*333d2b36SAndroid Build Coastguard Worker} 882*333d2b36SAndroid Build Coastguard Worker 883*333d2b36SAndroid Build Coastguard Workerfunc (m *SdkLibrary) RootLibraryName() string { 884*333d2b36SAndroid Build Coastguard Worker return m.BaseModuleName() 885*333d2b36SAndroid Build Coastguard Worker} 886*333d2b36SAndroid Build Coastguard Worker 887*333d2b36SAndroid Build Coastguard Workerfunc (m *SdkLibraryImport) RootLibraryName() string { 888*333d2b36SAndroid Build Coastguard Worker // m.BaseModuleName refers to the source of the import 889*333d2b36SAndroid Build Coastguard Worker // use moduleBase.Name to get the name of the module as it appears in the .bp file 890*333d2b36SAndroid Build Coastguard Worker return m.ModuleBase.Name() 891*333d2b36SAndroid Build Coastguard Worker} 892*333d2b36SAndroid Build Coastguard Worker 893*333d2b36SAndroid Build Coastguard Worker// Common code between sdk library and sdk library import 894*333d2b36SAndroid Build Coastguard Workertype commonToSdkLibraryAndImport struct { 895*333d2b36SAndroid Build Coastguard Worker module commonSdkLibraryAndImportModule 896*333d2b36SAndroid Build Coastguard Worker 897*333d2b36SAndroid Build Coastguard Worker scopePaths map[*apiScope]*scopePaths 898*333d2b36SAndroid Build Coastguard Worker 899*333d2b36SAndroid Build Coastguard Worker commonSdkLibraryProperties commonToSdkLibraryAndImportProperties 900*333d2b36SAndroid Build Coastguard Worker 901*333d2b36SAndroid Build Coastguard Worker // Paths to commonSdkLibraryProperties.Doctag_files 902*333d2b36SAndroid Build Coastguard Worker doctagPaths android.Paths 903*333d2b36SAndroid Build Coastguard Worker 904*333d2b36SAndroid Build Coastguard Worker // Functionality related to this being used as a component of a java_sdk_library. 905*333d2b36SAndroid Build Coastguard Worker EmbeddableSdkLibraryComponent 906*333d2b36SAndroid Build Coastguard Worker 907*333d2b36SAndroid Build Coastguard Worker // Path to the header jars of the implementation library 908*333d2b36SAndroid Build Coastguard Worker // This is non-empty only when api_only is false. 909*333d2b36SAndroid Build Coastguard Worker implLibraryHeaderJars android.Paths 910*333d2b36SAndroid Build Coastguard Worker 911*333d2b36SAndroid Build Coastguard Worker // The reference to the implementation library created by the source module. 912*333d2b36SAndroid Build Coastguard Worker // Is nil if the source module does not exist. 913*333d2b36SAndroid Build Coastguard Worker implLibraryModule *Library 914*333d2b36SAndroid Build Coastguard Worker} 915*333d2b36SAndroid Build Coastguard Worker 916*333d2b36SAndroid Build Coastguard Workerfunc (c *commonToSdkLibraryAndImport) initCommon(module commonSdkLibraryAndImportModule) { 917*333d2b36SAndroid Build Coastguard Worker c.module = module 918*333d2b36SAndroid Build Coastguard Worker 919*333d2b36SAndroid Build Coastguard Worker module.AddProperties(&c.commonSdkLibraryProperties) 920*333d2b36SAndroid Build Coastguard Worker 921*333d2b36SAndroid Build Coastguard Worker // Initialize this as an sdk library component. 922*333d2b36SAndroid Build Coastguard Worker c.initSdkLibraryComponent(module) 923*333d2b36SAndroid Build Coastguard Worker} 924*333d2b36SAndroid Build Coastguard Worker 925*333d2b36SAndroid Build Coastguard Workerfunc (c *commonToSdkLibraryAndImport) initCommonAfterDefaultsApplied() bool { 926*333d2b36SAndroid Build Coastguard Worker namePtr := proptools.StringPtr(c.module.RootLibraryName()) 927*333d2b36SAndroid Build Coastguard Worker c.sdkLibraryComponentProperties.SdkLibraryName = namePtr 928*333d2b36SAndroid Build Coastguard Worker 929*333d2b36SAndroid Build Coastguard Worker // Only track this sdk library if this can be used as a shared library. 930*333d2b36SAndroid Build Coastguard Worker if c.sharedLibrary() { 931*333d2b36SAndroid Build Coastguard Worker // Use the name specified in the module definition as the owner. 932*333d2b36SAndroid Build Coastguard Worker c.sdkLibraryComponentProperties.SdkLibraryToImplicitlyTrack = namePtr 933*333d2b36SAndroid Build Coastguard Worker } 934*333d2b36SAndroid Build Coastguard Worker 935*333d2b36SAndroid Build Coastguard Worker return true 936*333d2b36SAndroid Build Coastguard Worker} 937*333d2b36SAndroid Build Coastguard Worker 938*333d2b36SAndroid Build Coastguard Worker// uniqueApexVariations provides common implementation of the ApexModule.UniqueApexVariations 939*333d2b36SAndroid Build Coastguard Worker// method. 940*333d2b36SAndroid Build Coastguard Workerfunc (c *commonToSdkLibraryAndImport) uniqueApexVariations() bool { 941*333d2b36SAndroid Build Coastguard Worker // A java_sdk_library that is a shared library produces an XML file that makes the shared library 942*333d2b36SAndroid Build Coastguard Worker // usable from an AndroidManifest.xml's <uses-library> entry. That XML file contains the name of 943*333d2b36SAndroid Build Coastguard Worker // the APEX and so it needs a unique variation per APEX. 944*333d2b36SAndroid Build Coastguard Worker return c.sharedLibrary() 945*333d2b36SAndroid Build Coastguard Worker} 946*333d2b36SAndroid Build Coastguard Worker 947*333d2b36SAndroid Build Coastguard Workerfunc (c *commonToSdkLibraryAndImport) generateCommonBuildActions(ctx android.ModuleContext) SdkLibraryInfo { 948*333d2b36SAndroid Build Coastguard Worker c.doctagPaths = android.PathsForModuleSrc(ctx, c.commonSdkLibraryProperties.Doctag_files) 949*333d2b36SAndroid Build Coastguard Worker 950*333d2b36SAndroid Build Coastguard Worker everythingStubPaths := make(map[android.SdkKind]OptionalDexJarPath) 951*333d2b36SAndroid Build Coastguard Worker exportableStubPaths := make(map[android.SdkKind]OptionalDexJarPath) 952*333d2b36SAndroid Build Coastguard Worker removedApiFilePaths := make(map[android.SdkKind]android.OptionalPath) 953*333d2b36SAndroid Build Coastguard Worker for kind := android.SdkNone; kind <= android.SdkPrivate; kind += 1 { 954*333d2b36SAndroid Build Coastguard Worker everythingStubPath := makeUnsetDexJarPath() 955*333d2b36SAndroid Build Coastguard Worker exportableStubPath := makeUnsetDexJarPath() 956*333d2b36SAndroid Build Coastguard Worker removedApiFilePath := android.OptionalPath{} 957*333d2b36SAndroid Build Coastguard Worker if scopePath := c.findClosestScopePath(sdkKindToApiScope(kind)); scopePath != nil { 958*333d2b36SAndroid Build Coastguard Worker everythingStubPath = scopePath.stubsDexJarPath 959*333d2b36SAndroid Build Coastguard Worker exportableStubPath = scopePath.exportableStubsDexJarPath 960*333d2b36SAndroid Build Coastguard Worker removedApiFilePath = scopePath.removedApiFilePath 961*333d2b36SAndroid Build Coastguard Worker } 962*333d2b36SAndroid Build Coastguard Worker everythingStubPaths[kind] = everythingStubPath 963*333d2b36SAndroid Build Coastguard Worker exportableStubPaths[kind] = exportableStubPath 964*333d2b36SAndroid Build Coastguard Worker removedApiFilePaths[kind] = removedApiFilePath 965*333d2b36SAndroid Build Coastguard Worker } 966*333d2b36SAndroid Build Coastguard Worker 967*333d2b36SAndroid Build Coastguard Worker return SdkLibraryInfo{ 968*333d2b36SAndroid Build Coastguard Worker EverythingStubDexJarPaths: everythingStubPaths, 969*333d2b36SAndroid Build Coastguard Worker ExportableStubDexJarPaths: exportableStubPaths, 970*333d2b36SAndroid Build Coastguard Worker RemovedTxtFiles: removedApiFilePaths, 971*333d2b36SAndroid Build Coastguard Worker SharedLibrary: c.sharedLibrary(), 972*333d2b36SAndroid Build Coastguard Worker } 973*333d2b36SAndroid Build Coastguard Worker} 974*333d2b36SAndroid Build Coastguard Worker 975*333d2b36SAndroid Build Coastguard Worker// The component names for different outputs of the java_sdk_library. 976*333d2b36SAndroid Build Coastguard Worker// 977*333d2b36SAndroid Build Coastguard Worker// They are similar to the names used for the child modules it creates 978*333d2b36SAndroid Build Coastguard Workerconst ( 979*333d2b36SAndroid Build Coastguard Worker stubsSourceComponentName = "stubs.source" 980*333d2b36SAndroid Build Coastguard Worker 981*333d2b36SAndroid Build Coastguard Worker apiTxtComponentName = "api.txt" 982*333d2b36SAndroid Build Coastguard Worker 983*333d2b36SAndroid Build Coastguard Worker removedApiTxtComponentName = "removed-api.txt" 984*333d2b36SAndroid Build Coastguard Worker 985*333d2b36SAndroid Build Coastguard Worker annotationsComponentName = "annotations.zip" 986*333d2b36SAndroid Build Coastguard Worker) 987*333d2b36SAndroid Build Coastguard Worker 988*333d2b36SAndroid Build Coastguard Workerfunc (module *commonToSdkLibraryAndImport) setOutputFiles(ctx android.ModuleContext) { 989*333d2b36SAndroid Build Coastguard Worker if module.doctagPaths != nil { 990*333d2b36SAndroid Build Coastguard Worker ctx.SetOutputFiles(module.doctagPaths, ".doctags") 991*333d2b36SAndroid Build Coastguard Worker } 992*333d2b36SAndroid Build Coastguard Worker for _, scopeName := range android.SortedKeys(scopeByName) { 993*333d2b36SAndroid Build Coastguard Worker paths := module.findScopePaths(scopeByName[scopeName]) 994*333d2b36SAndroid Build Coastguard Worker if paths == nil { 995*333d2b36SAndroid Build Coastguard Worker continue 996*333d2b36SAndroid Build Coastguard Worker } 997*333d2b36SAndroid Build Coastguard Worker componentToOutput := map[string]android.OptionalPath{ 998*333d2b36SAndroid Build Coastguard Worker stubsSourceComponentName: paths.stubsSrcJar, 999*333d2b36SAndroid Build Coastguard Worker apiTxtComponentName: paths.currentApiFilePath, 1000*333d2b36SAndroid Build Coastguard Worker removedApiTxtComponentName: paths.removedApiFilePath, 1001*333d2b36SAndroid Build Coastguard Worker annotationsComponentName: paths.annotationsZip, 1002*333d2b36SAndroid Build Coastguard Worker } 1003*333d2b36SAndroid Build Coastguard Worker for _, component := range android.SortedKeys(componentToOutput) { 1004*333d2b36SAndroid Build Coastguard Worker if componentToOutput[component].Valid() { 1005*333d2b36SAndroid Build Coastguard Worker ctx.SetOutputFiles(android.Paths{componentToOutput[component].Path()}, "."+scopeName+"."+component) 1006*333d2b36SAndroid Build Coastguard Worker } 1007*333d2b36SAndroid Build Coastguard Worker } 1008*333d2b36SAndroid Build Coastguard Worker } 1009*333d2b36SAndroid Build Coastguard Worker} 1010*333d2b36SAndroid Build Coastguard Worker 1011*333d2b36SAndroid Build Coastguard Workerfunc (c *commonToSdkLibraryAndImport) getScopePathsCreateIfNeeded(scope *apiScope) *scopePaths { 1012*333d2b36SAndroid Build Coastguard Worker if c.scopePaths == nil { 1013*333d2b36SAndroid Build Coastguard Worker c.scopePaths = make(map[*apiScope]*scopePaths) 1014*333d2b36SAndroid Build Coastguard Worker } 1015*333d2b36SAndroid Build Coastguard Worker paths := c.scopePaths[scope] 1016*333d2b36SAndroid Build Coastguard Worker if paths == nil { 1017*333d2b36SAndroid Build Coastguard Worker paths = &scopePaths{} 1018*333d2b36SAndroid Build Coastguard Worker c.scopePaths[scope] = paths 1019*333d2b36SAndroid Build Coastguard Worker } 1020*333d2b36SAndroid Build Coastguard Worker 1021*333d2b36SAndroid Build Coastguard Worker return paths 1022*333d2b36SAndroid Build Coastguard Worker} 1023*333d2b36SAndroid Build Coastguard Worker 1024*333d2b36SAndroid Build Coastguard Workerfunc (c *commonToSdkLibraryAndImport) findScopePaths(scope *apiScope) *scopePaths { 1025*333d2b36SAndroid Build Coastguard Worker if c.scopePaths == nil { 1026*333d2b36SAndroid Build Coastguard Worker return nil 1027*333d2b36SAndroid Build Coastguard Worker } 1028*333d2b36SAndroid Build Coastguard Worker 1029*333d2b36SAndroid Build Coastguard Worker return c.scopePaths[scope] 1030*333d2b36SAndroid Build Coastguard Worker} 1031*333d2b36SAndroid Build Coastguard Worker 1032*333d2b36SAndroid Build Coastguard Worker// If this does not support the requested api scope then find the closest available 1033*333d2b36SAndroid Build Coastguard Worker// scope it does support. Returns nil if no such scope is available. 1034*333d2b36SAndroid Build Coastguard Workerfunc (c *commonToSdkLibraryAndImport) findClosestScopePath(scope *apiScope) *scopePaths { 1035*333d2b36SAndroid Build Coastguard Worker for s := scope; s != nil; s = s.canAccess { 1036*333d2b36SAndroid Build Coastguard Worker if paths := c.findScopePaths(s); paths != nil { 1037*333d2b36SAndroid Build Coastguard Worker return paths 1038*333d2b36SAndroid Build Coastguard Worker } 1039*333d2b36SAndroid Build Coastguard Worker } 1040*333d2b36SAndroid Build Coastguard Worker 1041*333d2b36SAndroid Build Coastguard Worker // This should never happen outside tests as public should be the base scope for every 1042*333d2b36SAndroid Build Coastguard Worker // scope and is enabled by default. 1043*333d2b36SAndroid Build Coastguard Worker return nil 1044*333d2b36SAndroid Build Coastguard Worker} 1045*333d2b36SAndroid Build Coastguard Worker 1046*333d2b36SAndroid Build Coastguard Worker// sdkKindToApiScope maps from android.SdkKind to apiScope. 1047*333d2b36SAndroid Build Coastguard Workerfunc sdkKindToApiScope(kind android.SdkKind) *apiScope { 1048*333d2b36SAndroid Build Coastguard Worker var apiScope *apiScope 1049*333d2b36SAndroid Build Coastguard Worker switch kind { 1050*333d2b36SAndroid Build Coastguard Worker case android.SdkSystem: 1051*333d2b36SAndroid Build Coastguard Worker apiScope = apiScopeSystem 1052*333d2b36SAndroid Build Coastguard Worker case android.SdkModule: 1053*333d2b36SAndroid Build Coastguard Worker apiScope = apiScopeModuleLib 1054*333d2b36SAndroid Build Coastguard Worker case android.SdkTest: 1055*333d2b36SAndroid Build Coastguard Worker apiScope = apiScopeTest 1056*333d2b36SAndroid Build Coastguard Worker case android.SdkSystemServer: 1057*333d2b36SAndroid Build Coastguard Worker apiScope = apiScopeSystemServer 1058*333d2b36SAndroid Build Coastguard Worker default: 1059*333d2b36SAndroid Build Coastguard Worker apiScope = apiScopePublic 1060*333d2b36SAndroid Build Coastguard Worker } 1061*333d2b36SAndroid Build Coastguard Worker return apiScope 1062*333d2b36SAndroid Build Coastguard Worker} 1063*333d2b36SAndroid Build Coastguard Worker 1064*333d2b36SAndroid Build Coastguard Workerfunc (c *commonToSdkLibraryAndImport) sdkComponentPropertiesForChildLibrary() interface{} { 1065*333d2b36SAndroid Build Coastguard Worker componentProps := &struct { 1066*333d2b36SAndroid Build Coastguard Worker SdkLibraryName *string 1067*333d2b36SAndroid Build Coastguard Worker SdkLibraryToImplicitlyTrack *string 1068*333d2b36SAndroid Build Coastguard Worker }{} 1069*333d2b36SAndroid Build Coastguard Worker 1070*333d2b36SAndroid Build Coastguard Worker namePtr := proptools.StringPtr(c.module.RootLibraryName()) 1071*333d2b36SAndroid Build Coastguard Worker componentProps.SdkLibraryName = namePtr 1072*333d2b36SAndroid Build Coastguard Worker 1073*333d2b36SAndroid Build Coastguard Worker if c.sharedLibrary() { 1074*333d2b36SAndroid Build Coastguard Worker // Mark the stubs library as being components of this java_sdk_library so that 1075*333d2b36SAndroid Build Coastguard Worker // any app that includes code which depends (directly or indirectly) on the stubs 1076*333d2b36SAndroid Build Coastguard Worker // library will have the appropriate <uses-library> invocation inserted into its 1077*333d2b36SAndroid Build Coastguard Worker // manifest if necessary. 1078*333d2b36SAndroid Build Coastguard Worker componentProps.SdkLibraryToImplicitlyTrack = namePtr 1079*333d2b36SAndroid Build Coastguard Worker } 1080*333d2b36SAndroid Build Coastguard Worker 1081*333d2b36SAndroid Build Coastguard Worker return componentProps 1082*333d2b36SAndroid Build Coastguard Worker} 1083*333d2b36SAndroid Build Coastguard Worker 1084*333d2b36SAndroid Build Coastguard Workerfunc (c *commonToSdkLibraryAndImport) sharedLibrary() bool { 1085*333d2b36SAndroid Build Coastguard Worker return proptools.BoolDefault(c.commonSdkLibraryProperties.Shared_library, true) 1086*333d2b36SAndroid Build Coastguard Worker} 1087*333d2b36SAndroid Build Coastguard Worker 1088*333d2b36SAndroid Build Coastguard Worker// Check if the stub libraries should be compiled for dex 1089*333d2b36SAndroid Build Coastguard Workerfunc (c *commonToSdkLibraryAndImport) stubLibrariesCompiledForDex() bool { 1090*333d2b36SAndroid Build Coastguard Worker // Always compile the dex file files for the stub libraries if they will be used on the 1091*333d2b36SAndroid Build Coastguard Worker // bootclasspath. 1092*333d2b36SAndroid Build Coastguard Worker return !c.sharedLibrary() 1093*333d2b36SAndroid Build Coastguard Worker} 1094*333d2b36SAndroid Build Coastguard Worker 1095*333d2b36SAndroid Build Coastguard Worker// Properties related to the use of a module as an component of a java_sdk_library. 1096*333d2b36SAndroid Build Coastguard Workertype SdkLibraryComponentProperties struct { 1097*333d2b36SAndroid Build Coastguard Worker // The name of the java_sdk_library/_import module. 1098*333d2b36SAndroid Build Coastguard Worker SdkLibraryName *string `blueprint:"mutated"` 1099*333d2b36SAndroid Build Coastguard Worker 1100*333d2b36SAndroid Build Coastguard Worker // The name of the java_sdk_library/_import to add to a <uses-library> entry 1101*333d2b36SAndroid Build Coastguard Worker // in the AndroidManifest.xml of any Android app that includes code that references 1102*333d2b36SAndroid Build Coastguard Worker // this module. If not set then no java_sdk_library/_import is tracked. 1103*333d2b36SAndroid Build Coastguard Worker SdkLibraryToImplicitlyTrack *string `blueprint:"mutated"` 1104*333d2b36SAndroid Build Coastguard Worker} 1105*333d2b36SAndroid Build Coastguard Worker 1106*333d2b36SAndroid Build Coastguard Worker// Structure to be embedded in a module struct that needs to support the 1107*333d2b36SAndroid Build Coastguard Worker// SdkLibraryComponentDependency interface. 1108*333d2b36SAndroid Build Coastguard Workertype EmbeddableSdkLibraryComponent struct { 1109*333d2b36SAndroid Build Coastguard Worker sdkLibraryComponentProperties SdkLibraryComponentProperties 1110*333d2b36SAndroid Build Coastguard Worker} 1111*333d2b36SAndroid Build Coastguard Worker 1112*333d2b36SAndroid Build Coastguard Workerfunc (e *EmbeddableSdkLibraryComponent) initSdkLibraryComponent(module android.Module) { 1113*333d2b36SAndroid Build Coastguard Worker module.AddProperties(&e.sdkLibraryComponentProperties) 1114*333d2b36SAndroid Build Coastguard Worker} 1115*333d2b36SAndroid Build Coastguard Worker 1116*333d2b36SAndroid Build Coastguard Worker// to satisfy SdkLibraryComponentDependency 1117*333d2b36SAndroid Build Coastguard Workerfunc (e *EmbeddableSdkLibraryComponent) SdkLibraryName() *string { 1118*333d2b36SAndroid Build Coastguard Worker return e.sdkLibraryComponentProperties.SdkLibraryName 1119*333d2b36SAndroid Build Coastguard Worker} 1120*333d2b36SAndroid Build Coastguard Worker 1121*333d2b36SAndroid Build Coastguard Worker// to satisfy SdkLibraryComponentDependency 1122*333d2b36SAndroid Build Coastguard Workerfunc (e *EmbeddableSdkLibraryComponent) OptionalSdkLibraryImplementation() *string { 1123*333d2b36SAndroid Build Coastguard Worker // For shared libraries, this is the same as the SDK library name. If a Java library or app 1124*333d2b36SAndroid Build Coastguard Worker // depends on a component library (e.g. a stub library) it still needs to know the name of the 1125*333d2b36SAndroid Build Coastguard Worker // run-time library and the corresponding module that provides the implementation. This name is 1126*333d2b36SAndroid Build Coastguard Worker // passed to manifest_fixer (to be added to AndroidManifest.xml) and added to CLC (to be used 1127*333d2b36SAndroid Build Coastguard Worker // in dexpreopt). 1128*333d2b36SAndroid Build Coastguard Worker // 1129*333d2b36SAndroid Build Coastguard Worker // For non-shared SDK (component or not) libraries this returns `nil`, as they are not 1130*333d2b36SAndroid Build Coastguard Worker // <uses-library> and should not be added to the manifest or to CLC. 1131*333d2b36SAndroid Build Coastguard Worker return e.sdkLibraryComponentProperties.SdkLibraryToImplicitlyTrack 1132*333d2b36SAndroid Build Coastguard Worker} 1133*333d2b36SAndroid Build Coastguard Worker 1134*333d2b36SAndroid Build Coastguard Worker// Implemented by modules that are (or possibly could be) a component of a java_sdk_library 1135*333d2b36SAndroid Build Coastguard Worker// (including the java_sdk_library) itself. 1136*333d2b36SAndroid Build Coastguard Workertype SdkLibraryComponentDependency interface { 1137*333d2b36SAndroid Build Coastguard Worker UsesLibraryDependency 1138*333d2b36SAndroid Build Coastguard Worker 1139*333d2b36SAndroid Build Coastguard Worker // SdkLibraryName returns the name of the java_sdk_library/_import module. 1140*333d2b36SAndroid Build Coastguard Worker SdkLibraryName() *string 1141*333d2b36SAndroid Build Coastguard Worker 1142*333d2b36SAndroid Build Coastguard Worker // The name of the implementation library for the optional SDK library or nil, if there isn't one. 1143*333d2b36SAndroid Build Coastguard Worker OptionalSdkLibraryImplementation() *string 1144*333d2b36SAndroid Build Coastguard Worker} 1145*333d2b36SAndroid Build Coastguard Worker 1146*333d2b36SAndroid Build Coastguard Worker// Make sure that all the module types that are components of java_sdk_library/_import 1147*333d2b36SAndroid Build Coastguard Worker// and which can be referenced (directly or indirectly) from an android app implement 1148*333d2b36SAndroid Build Coastguard Worker// the SdkLibraryComponentDependency interface. 1149*333d2b36SAndroid Build Coastguard Workervar _ SdkLibraryComponentDependency = (*Library)(nil) 1150*333d2b36SAndroid Build Coastguard Workervar _ SdkLibraryComponentDependency = (*Import)(nil) 1151*333d2b36SAndroid Build Coastguard Workervar _ SdkLibraryComponentDependency = (*SdkLibrary)(nil) 1152*333d2b36SAndroid Build Coastguard Workervar _ SdkLibraryComponentDependency = (*SdkLibraryImport)(nil) 1153*333d2b36SAndroid Build Coastguard Worker 1154*333d2b36SAndroid Build Coastguard Workertype SdkLibraryInfo struct { 1155*333d2b36SAndroid Build Coastguard Worker // GeneratingLibs is the names of the library modules that this sdk library 1156*333d2b36SAndroid Build Coastguard Worker // generates. Note that this only includes the name of the modules that other modules can 1157*333d2b36SAndroid Build Coastguard Worker // depend on, and is not a holistic list of generated modules. 1158*333d2b36SAndroid Build Coastguard Worker GeneratingLibs []string 1159*333d2b36SAndroid Build Coastguard Worker 1160*333d2b36SAndroid Build Coastguard Worker // Map of sdk kind to the dex jar for the "everything" stubs. 1161*333d2b36SAndroid Build Coastguard Worker // It is needed by the hiddenapi processing tool which processes dex files. 1162*333d2b36SAndroid Build Coastguard Worker EverythingStubDexJarPaths map[android.SdkKind]OptionalDexJarPath 1163*333d2b36SAndroid Build Coastguard Worker 1164*333d2b36SAndroid Build Coastguard Worker // Map of sdk kind to the dex jar for the "exportable" stubs. 1165*333d2b36SAndroid Build Coastguard Worker // It is needed by the hiddenapi processing tool which processes dex files. 1166*333d2b36SAndroid Build Coastguard Worker ExportableStubDexJarPaths map[android.SdkKind]OptionalDexJarPath 1167*333d2b36SAndroid Build Coastguard Worker 1168*333d2b36SAndroid Build Coastguard Worker // Map of sdk kind to the optional path to the removed.txt file. 1169*333d2b36SAndroid Build Coastguard Worker RemovedTxtFiles map[android.SdkKind]android.OptionalPath 1170*333d2b36SAndroid Build Coastguard Worker 1171*333d2b36SAndroid Build Coastguard Worker // Whether if this can be used as a shared library. 1172*333d2b36SAndroid Build Coastguard Worker SharedLibrary bool 1173*333d2b36SAndroid Build Coastguard Worker} 1174*333d2b36SAndroid Build Coastguard Worker 1175*333d2b36SAndroid Build Coastguard Workervar SdkLibraryInfoProvider = blueprint.NewProvider[SdkLibraryInfo]() 1176*333d2b36SAndroid Build Coastguard Worker 1177*333d2b36SAndroid Build Coastguard Workerfunc getGeneratingLibs(ctx android.ModuleContext, sdkVersion android.SdkSpec, sdkLibraryModuleName string, sdkInfo SdkLibraryInfo) []string { 1178*333d2b36SAndroid Build Coastguard Worker apiLevel := sdkVersion.ApiLevel 1179*333d2b36SAndroid Build Coastguard Worker if apiLevel.IsPreview() { 1180*333d2b36SAndroid Build Coastguard Worker return sdkInfo.GeneratingLibs 1181*333d2b36SAndroid Build Coastguard Worker } 1182*333d2b36SAndroid Build Coastguard Worker 1183*333d2b36SAndroid Build Coastguard Worker generatingPrebuilts := []string{} 1184*333d2b36SAndroid Build Coastguard Worker for _, apiScope := range AllApiScopes { 1185*333d2b36SAndroid Build Coastguard Worker scopePrebuiltModuleName := prebuiltApiModuleName("sdk", sdkLibraryModuleName, apiScope.name, apiLevel.String()) 1186*333d2b36SAndroid Build Coastguard Worker if ctx.OtherModuleExists(scopePrebuiltModuleName) { 1187*333d2b36SAndroid Build Coastguard Worker generatingPrebuilts = append(generatingPrebuilts, scopePrebuiltModuleName) 1188*333d2b36SAndroid Build Coastguard Worker } 1189*333d2b36SAndroid Build Coastguard Worker } 1190*333d2b36SAndroid Build Coastguard Worker return generatingPrebuilts 1191*333d2b36SAndroid Build Coastguard Worker} 1192*333d2b36SAndroid Build Coastguard Worker 1193*333d2b36SAndroid Build Coastguard Workertype SdkLibrary struct { 1194*333d2b36SAndroid Build Coastguard Worker Library 1195*333d2b36SAndroid Build Coastguard Worker 1196*333d2b36SAndroid Build Coastguard Worker sdkLibraryProperties sdkLibraryProperties 1197*333d2b36SAndroid Build Coastguard Worker 1198*333d2b36SAndroid Build Coastguard Worker // Map from api scope to the scope specific property structure. 1199*333d2b36SAndroid Build Coastguard Worker scopeToProperties map[*apiScope]*ApiScopeProperties 1200*333d2b36SAndroid Build Coastguard Worker 1201*333d2b36SAndroid Build Coastguard Worker commonToSdkLibraryAndImport 1202*333d2b36SAndroid Build Coastguard Worker 1203*333d2b36SAndroid Build Coastguard Worker builtInstalledForApex []dexpreopterInstall 1204*333d2b36SAndroid Build Coastguard Worker} 1205*333d2b36SAndroid Build Coastguard Worker 1206*333d2b36SAndroid Build Coastguard Workerfunc (module *SdkLibrary) generateTestAndSystemScopesByDefault() bool { 1207*333d2b36SAndroid Build Coastguard Worker return module.sdkLibraryProperties.Generate_system_and_test_apis 1208*333d2b36SAndroid Build Coastguard Worker} 1209*333d2b36SAndroid Build Coastguard Worker 1210*333d2b36SAndroid Build Coastguard Workervar _ UsesLibraryDependency = (*SdkLibrary)(nil) 1211*333d2b36SAndroid Build Coastguard Worker 1212*333d2b36SAndroid Build Coastguard Worker// To satisfy the UsesLibraryDependency interface 1213*333d2b36SAndroid Build Coastguard Workerfunc (module *SdkLibrary) DexJarBuildPath(ctx android.ModuleErrorfContext) OptionalDexJarPath { 1214*333d2b36SAndroid Build Coastguard Worker if module.implLibraryModule != nil { 1215*333d2b36SAndroid Build Coastguard Worker return module.implLibraryModule.DexJarBuildPath(ctx) 1216*333d2b36SAndroid Build Coastguard Worker } 1217*333d2b36SAndroid Build Coastguard Worker return makeUnsetDexJarPath() 1218*333d2b36SAndroid Build Coastguard Worker} 1219*333d2b36SAndroid Build Coastguard Worker 1220*333d2b36SAndroid Build Coastguard Worker// To satisfy the UsesLibraryDependency interface 1221*333d2b36SAndroid Build Coastguard Workerfunc (module *SdkLibrary) DexJarInstallPath() android.Path { 1222*333d2b36SAndroid Build Coastguard Worker if module.implLibraryModule != nil { 1223*333d2b36SAndroid Build Coastguard Worker return module.implLibraryModule.DexJarInstallPath() 1224*333d2b36SAndroid Build Coastguard Worker } 1225*333d2b36SAndroid Build Coastguard Worker return nil 1226*333d2b36SAndroid Build Coastguard Worker} 1227*333d2b36SAndroid Build Coastguard Worker 1228*333d2b36SAndroid Build Coastguard Workerfunc (module *SdkLibrary) getGeneratedApiScopes(ctx android.EarlyModuleContext) apiScopes { 1229*333d2b36SAndroid Build Coastguard Worker // Check to see if any scopes have been explicitly enabled. If any have then all 1230*333d2b36SAndroid Build Coastguard Worker // must be. 1231*333d2b36SAndroid Build Coastguard Worker anyScopesExplicitlyEnabled := false 1232*333d2b36SAndroid Build Coastguard Worker for _, scope := range AllApiScopes { 1233*333d2b36SAndroid Build Coastguard Worker scopeProperties := module.scopeToProperties[scope] 1234*333d2b36SAndroid Build Coastguard Worker if scopeProperties.Enabled != nil { 1235*333d2b36SAndroid Build Coastguard Worker anyScopesExplicitlyEnabled = true 1236*333d2b36SAndroid Build Coastguard Worker break 1237*333d2b36SAndroid Build Coastguard Worker } 1238*333d2b36SAndroid Build Coastguard Worker } 1239*333d2b36SAndroid Build Coastguard Worker 1240*333d2b36SAndroid Build Coastguard Worker var generatedScopes apiScopes 1241*333d2b36SAndroid Build Coastguard Worker enabledScopes := make(map[*apiScope]struct{}) 1242*333d2b36SAndroid Build Coastguard Worker for _, scope := range AllApiScopes { 1243*333d2b36SAndroid Build Coastguard Worker scopeProperties := module.scopeToProperties[scope] 1244*333d2b36SAndroid Build Coastguard Worker // If any scopes are explicitly enabled then ignore the legacy enabled status. 1245*333d2b36SAndroid Build Coastguard Worker // This is to ensure that any new usages of this module type do not rely on legacy 1246*333d2b36SAndroid Build Coastguard Worker // behaviour. 1247*333d2b36SAndroid Build Coastguard Worker defaultEnabledStatus := false 1248*333d2b36SAndroid Build Coastguard Worker if anyScopesExplicitlyEnabled { 1249*333d2b36SAndroid Build Coastguard Worker defaultEnabledStatus = scope.defaultEnabledStatus 1250*333d2b36SAndroid Build Coastguard Worker } else { 1251*333d2b36SAndroid Build Coastguard Worker defaultEnabledStatus = scope.legacyEnabledStatus(module) 1252*333d2b36SAndroid Build Coastguard Worker } 1253*333d2b36SAndroid Build Coastguard Worker enabled := proptools.BoolDefault(scopeProperties.Enabled, defaultEnabledStatus) 1254*333d2b36SAndroid Build Coastguard Worker if enabled { 1255*333d2b36SAndroid Build Coastguard Worker enabledScopes[scope] = struct{}{} 1256*333d2b36SAndroid Build Coastguard Worker generatedScopes = append(generatedScopes, scope) 1257*333d2b36SAndroid Build Coastguard Worker } 1258*333d2b36SAndroid Build Coastguard Worker } 1259*333d2b36SAndroid Build Coastguard Worker 1260*333d2b36SAndroid Build Coastguard Worker // Now check to make sure that any scope that is extended by an enabled scope is also 1261*333d2b36SAndroid Build Coastguard Worker // enabled. 1262*333d2b36SAndroid Build Coastguard Worker for _, scope := range AllApiScopes { 1263*333d2b36SAndroid Build Coastguard Worker if _, ok := enabledScopes[scope]; ok { 1264*333d2b36SAndroid Build Coastguard Worker extends := scope.extends 1265*333d2b36SAndroid Build Coastguard Worker if extends != nil { 1266*333d2b36SAndroid Build Coastguard Worker if _, ok := enabledScopes[extends]; !ok { 1267*333d2b36SAndroid Build Coastguard Worker ctx.ModuleErrorf("enabled api scope %q depends on disabled scope %q", scope, extends) 1268*333d2b36SAndroid Build Coastguard Worker } 1269*333d2b36SAndroid Build Coastguard Worker } 1270*333d2b36SAndroid Build Coastguard Worker } 1271*333d2b36SAndroid Build Coastguard Worker } 1272*333d2b36SAndroid Build Coastguard Worker 1273*333d2b36SAndroid Build Coastguard Worker return generatedScopes 1274*333d2b36SAndroid Build Coastguard Worker} 1275*333d2b36SAndroid Build Coastguard Worker 1276*333d2b36SAndroid Build Coastguard Workervar _ android.ModuleWithMinSdkVersionCheck = (*SdkLibrary)(nil) 1277*333d2b36SAndroid Build Coastguard Worker 1278*333d2b36SAndroid Build Coastguard Workerfunc (module *SdkLibrary) CheckMinSdkVersion(ctx android.ModuleContext) { 1279*333d2b36SAndroid Build Coastguard Worker CheckMinSdkVersion(ctx, &module.Library) 1280*333d2b36SAndroid Build Coastguard Worker} 1281*333d2b36SAndroid Build Coastguard Worker 1282*333d2b36SAndroid Build Coastguard Workerfunc CheckMinSdkVersion(ctx android.ModuleContext, module *Library) { 1283*333d2b36SAndroid Build Coastguard Worker android.CheckMinSdkVersion(ctx, module.MinSdkVersion(ctx), func(c android.BaseModuleContext, do android.PayloadDepsCallback) { 1284*333d2b36SAndroid Build Coastguard Worker ctx.WalkDeps(func(child android.Module, parent android.Module) bool { 1285*333d2b36SAndroid Build Coastguard Worker isExternal := !module.depIsInSameApex(ctx, child) 1286*333d2b36SAndroid Build Coastguard Worker if am, ok := child.(android.ApexModule); ok { 1287*333d2b36SAndroid Build Coastguard Worker if !do(ctx, parent, am, isExternal) { 1288*333d2b36SAndroid Build Coastguard Worker return false 1289*333d2b36SAndroid Build Coastguard Worker } 1290*333d2b36SAndroid Build Coastguard Worker } 1291*333d2b36SAndroid Build Coastguard Worker return !isExternal 1292*333d2b36SAndroid Build Coastguard Worker }) 1293*333d2b36SAndroid Build Coastguard Worker }) 1294*333d2b36SAndroid Build Coastguard Worker} 1295*333d2b36SAndroid Build Coastguard Worker 1296*333d2b36SAndroid Build Coastguard Workertype sdkLibraryComponentTag struct { 1297*333d2b36SAndroid Build Coastguard Worker blueprint.BaseDependencyTag 1298*333d2b36SAndroid Build Coastguard Worker name string 1299*333d2b36SAndroid Build Coastguard Worker} 1300*333d2b36SAndroid Build Coastguard Worker 1301*333d2b36SAndroid Build Coastguard Worker// Mark this tag so dependencies that use it are excluded from visibility enforcement. 1302*333d2b36SAndroid Build Coastguard Workerfunc (t sdkLibraryComponentTag) ExcludeFromVisibilityEnforcement() {} 1303*333d2b36SAndroid Build Coastguard Worker 1304*333d2b36SAndroid Build Coastguard Workervar xmlPermissionsFileTag = sdkLibraryComponentTag{name: "xml-permissions-file"} 1305*333d2b36SAndroid Build Coastguard Worker 1306*333d2b36SAndroid Build Coastguard Workerfunc IsXmlPermissionsFileDepTag(depTag blueprint.DependencyTag) bool { 1307*333d2b36SAndroid Build Coastguard Worker if dt, ok := depTag.(sdkLibraryComponentTag); ok { 1308*333d2b36SAndroid Build Coastguard Worker return dt == xmlPermissionsFileTag 1309*333d2b36SAndroid Build Coastguard Worker } 1310*333d2b36SAndroid Build Coastguard Worker return false 1311*333d2b36SAndroid Build Coastguard Worker} 1312*333d2b36SAndroid Build Coastguard Worker 1313*333d2b36SAndroid Build Coastguard Workervar implLibraryTag = sdkLibraryComponentTag{name: "impl-library"} 1314*333d2b36SAndroid Build Coastguard Worker 1315*333d2b36SAndroid Build Coastguard Workervar _ android.InstallNeededDependencyTag = sdkLibraryComponentTag{} 1316*333d2b36SAndroid Build Coastguard Worker 1317*333d2b36SAndroid Build Coastguard Workerfunc (t sdkLibraryComponentTag) InstallDepNeeded() bool { 1318*333d2b36SAndroid Build Coastguard Worker return t.name == "xml-permissions-file" || t.name == "impl-library" 1319*333d2b36SAndroid Build Coastguard Worker} 1320*333d2b36SAndroid Build Coastguard Worker 1321*333d2b36SAndroid Build Coastguard Worker// Add the dependencies on the child modules in the component deps mutator. 1322*333d2b36SAndroid Build Coastguard Workerfunc (module *SdkLibrary) ComponentDepsMutator(ctx android.BottomUpMutatorContext) { 1323*333d2b36SAndroid Build Coastguard Worker for _, apiScope := range module.getGeneratedApiScopes(ctx) { 1324*333d2b36SAndroid Build Coastguard Worker // Add dependencies to the stubs library 1325*333d2b36SAndroid Build Coastguard Worker stubModuleName := module.stubsLibraryModuleName(apiScope) 1326*333d2b36SAndroid Build Coastguard Worker ctx.AddVariationDependencies(nil, apiScope.everythingStubsTag, stubModuleName) 1327*333d2b36SAndroid Build Coastguard Worker 1328*333d2b36SAndroid Build Coastguard Worker exportableStubModuleName := module.exportableStubsLibraryModuleName(apiScope) 1329*333d2b36SAndroid Build Coastguard Worker ctx.AddVariationDependencies(nil, apiScope.exportableStubsTag, exportableStubModuleName) 1330*333d2b36SAndroid Build Coastguard Worker 1331*333d2b36SAndroid Build Coastguard Worker // Add a dependency on the stubs source in order to access both stubs source and api information. 1332*333d2b36SAndroid Build Coastguard Worker ctx.AddVariationDependencies(nil, apiScope.stubsSourceAndApiTag, module.droidstubsModuleName(apiScope)) 1333*333d2b36SAndroid Build Coastguard Worker 1334*333d2b36SAndroid Build Coastguard Worker if module.compareAgainstLatestApi(apiScope) { 1335*333d2b36SAndroid Build Coastguard Worker // Add dependencies on the latest finalized version of the API .txt file. 1336*333d2b36SAndroid Build Coastguard Worker latestApiModuleName := module.latestApiModuleName(apiScope) 1337*333d2b36SAndroid Build Coastguard Worker ctx.AddDependency(module, apiScope.latestApiModuleTag, latestApiModuleName) 1338*333d2b36SAndroid Build Coastguard Worker 1339*333d2b36SAndroid Build Coastguard Worker // Add dependencies on the latest finalized version of the remove API .txt file. 1340*333d2b36SAndroid Build Coastguard Worker latestRemovedApiModuleName := module.latestRemovedApiModuleName(apiScope) 1341*333d2b36SAndroid Build Coastguard Worker ctx.AddDependency(module, apiScope.latestRemovedApiModuleTag, latestRemovedApiModuleName) 1342*333d2b36SAndroid Build Coastguard Worker } 1343*333d2b36SAndroid Build Coastguard Worker } 1344*333d2b36SAndroid Build Coastguard Worker 1345*333d2b36SAndroid Build Coastguard Worker if module.requiresRuntimeImplementationLibrary() { 1346*333d2b36SAndroid Build Coastguard Worker // Add dependency to the rule for generating the implementation library. 1347*333d2b36SAndroid Build Coastguard Worker ctx.AddDependency(module, implLibraryTag, module.implLibraryModuleName()) 1348*333d2b36SAndroid Build Coastguard Worker 1349*333d2b36SAndroid Build Coastguard Worker if module.sharedLibrary() { 1350*333d2b36SAndroid Build Coastguard Worker // Add dependency to the rule for generating the xml permissions file 1351*333d2b36SAndroid Build Coastguard Worker ctx.AddDependency(module, xmlPermissionsFileTag, module.xmlPermissionsModuleName()) 1352*333d2b36SAndroid Build Coastguard Worker } 1353*333d2b36SAndroid Build Coastguard Worker } 1354*333d2b36SAndroid Build Coastguard Worker} 1355*333d2b36SAndroid Build Coastguard Worker 1356*333d2b36SAndroid Build Coastguard Worker// Add other dependencies as normal. 1357*333d2b36SAndroid Build Coastguard Workerfunc (module *SdkLibrary) DepsMutator(ctx android.BottomUpMutatorContext) { 1358*333d2b36SAndroid Build Coastguard Worker // If the module does not create an implementation library or defaults to stubs, 1359*333d2b36SAndroid Build Coastguard Worker // mark the top level sdk library as stubs module as the module will provide stubs via 1360*333d2b36SAndroid Build Coastguard Worker // "magic" when listed as a dependency in the Android.bp files. 1361*333d2b36SAndroid Build Coastguard Worker notCreateImplLib := proptools.Bool(module.sdkLibraryProperties.Api_only) 1362*333d2b36SAndroid Build Coastguard Worker preferStubs := proptools.Bool(module.sdkLibraryProperties.Default_to_stubs) 1363*333d2b36SAndroid Build Coastguard Worker module.properties.Is_stubs_module = proptools.BoolPtr(notCreateImplLib || preferStubs) 1364*333d2b36SAndroid Build Coastguard Worker 1365*333d2b36SAndroid Build Coastguard Worker var missingApiModules []string 1366*333d2b36SAndroid Build Coastguard Worker for _, apiScope := range module.getGeneratedApiScopes(ctx) { 1367*333d2b36SAndroid Build Coastguard Worker if apiScope.unstable { 1368*333d2b36SAndroid Build Coastguard Worker continue 1369*333d2b36SAndroid Build Coastguard Worker } 1370*333d2b36SAndroid Build Coastguard Worker if m := module.latestApiModuleName(apiScope); !ctx.OtherModuleExists(m) { 1371*333d2b36SAndroid Build Coastguard Worker missingApiModules = append(missingApiModules, m) 1372*333d2b36SAndroid Build Coastguard Worker } 1373*333d2b36SAndroid Build Coastguard Worker if m := module.latestRemovedApiModuleName(apiScope); !ctx.OtherModuleExists(m) { 1374*333d2b36SAndroid Build Coastguard Worker missingApiModules = append(missingApiModules, m) 1375*333d2b36SAndroid Build Coastguard Worker } 1376*333d2b36SAndroid Build Coastguard Worker if m := module.latestIncompatibilitiesModuleName(apiScope); !ctx.OtherModuleExists(m) { 1377*333d2b36SAndroid Build Coastguard Worker missingApiModules = append(missingApiModules, m) 1378*333d2b36SAndroid Build Coastguard Worker } 1379*333d2b36SAndroid Build Coastguard Worker } 1380*333d2b36SAndroid Build Coastguard Worker if len(missingApiModules) != 0 && !module.sdkLibraryProperties.Unsafe_ignore_missing_latest_api { 1381*333d2b36SAndroid Build Coastguard Worker m := module.Name() + " is missing tracking files for previously released library versions.\n" 1382*333d2b36SAndroid Build Coastguard Worker m += "You need to do one of the following:\n" 1383*333d2b36SAndroid Build Coastguard Worker m += "- Add `unsafe_ignore_missing_latest_api: true` to your blueprint (to disable compat tracking)\n" 1384*333d2b36SAndroid Build Coastguard Worker m += "- Add a set of prebuilt txt files representing the last released version of this library for compat checking.\n" 1385*333d2b36SAndroid Build Coastguard Worker m += " (the current set of API files can be used as a seed for this compatibility tracking\n" 1386*333d2b36SAndroid Build Coastguard Worker m += "\n" 1387*333d2b36SAndroid Build Coastguard Worker m += "The following filegroup modules are missing:\n " 1388*333d2b36SAndroid Build Coastguard Worker m += strings.Join(missingApiModules, "\n ") + "\n" 1389*333d2b36SAndroid Build Coastguard Worker m += "Please see the documentation of the prebuilt_apis module type (and a usage example in prebuilts/sdk) for a convenient way to generate these." 1390*333d2b36SAndroid Build Coastguard Worker ctx.ModuleErrorf(m) 1391*333d2b36SAndroid Build Coastguard Worker } 1392*333d2b36SAndroid Build Coastguard Worker} 1393*333d2b36SAndroid Build Coastguard Worker 1394*333d2b36SAndroid Build Coastguard Workerfunc (module *SdkLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) { 1395*333d2b36SAndroid Build Coastguard Worker if disableSourceApexVariant(ctx) { 1396*333d2b36SAndroid Build Coastguard Worker // Prebuilts are active, do not create the installation rules for the source javalib. 1397*333d2b36SAndroid Build Coastguard Worker // Even though the source javalib is not used, we need to hide it to prevent duplicate installation rules. 1398*333d2b36SAndroid Build Coastguard Worker // TODO (b/331665856): Implement a principled solution for this. 1399*333d2b36SAndroid Build Coastguard Worker module.HideFromMake() 1400*333d2b36SAndroid Build Coastguard Worker module.SkipInstall() 1401*333d2b36SAndroid Build Coastguard Worker } 1402*333d2b36SAndroid Build Coastguard Worker 1403*333d2b36SAndroid Build Coastguard Worker module.stem = proptools.StringDefault(module.overridableProperties.Stem, ctx.ModuleName()) 1404*333d2b36SAndroid Build Coastguard Worker 1405*333d2b36SAndroid Build Coastguard Worker module.provideHiddenAPIPropertyInfo(ctx) 1406*333d2b36SAndroid Build Coastguard Worker 1407*333d2b36SAndroid Build Coastguard Worker // Collate the components exported by this module. All scope specific modules are exported but 1408*333d2b36SAndroid Build Coastguard Worker // the impl and xml component modules are not. 1409*333d2b36SAndroid Build Coastguard Worker exportedComponents := map[string]struct{}{} 1410*333d2b36SAndroid Build Coastguard Worker 1411*333d2b36SAndroid Build Coastguard Worker // Record the paths to the header jars of the library (stubs and impl). 1412*333d2b36SAndroid Build Coastguard Worker // When this java_sdk_library is depended upon from others via "libs" property, 1413*333d2b36SAndroid Build Coastguard Worker // the recorded paths will be returned depending on the link type of the caller. 1414*333d2b36SAndroid Build Coastguard Worker ctx.VisitDirectDeps(func(to android.Module) { 1415*333d2b36SAndroid Build Coastguard Worker tag := ctx.OtherModuleDependencyTag(to) 1416*333d2b36SAndroid Build Coastguard Worker 1417*333d2b36SAndroid Build Coastguard Worker // Extract information from any of the scope specific dependencies. 1418*333d2b36SAndroid Build Coastguard Worker if scopeTag, ok := tag.(scopeDependencyTag); ok { 1419*333d2b36SAndroid Build Coastguard Worker apiScope := scopeTag.apiScope 1420*333d2b36SAndroid Build Coastguard Worker scopePaths := module.getScopePathsCreateIfNeeded(apiScope) 1421*333d2b36SAndroid Build Coastguard Worker 1422*333d2b36SAndroid Build Coastguard Worker // Extract information from the dependency. The exact information extracted 1423*333d2b36SAndroid Build Coastguard Worker // is determined by the nature of the dependency which is determined by the tag. 1424*333d2b36SAndroid Build Coastguard Worker scopeTag.extractDepInfo(ctx, to, scopePaths) 1425*333d2b36SAndroid Build Coastguard Worker 1426*333d2b36SAndroid Build Coastguard Worker exportedComponents[ctx.OtherModuleName(to)] = struct{}{} 1427*333d2b36SAndroid Build Coastguard Worker 1428*333d2b36SAndroid Build Coastguard Worker ctx.Phony(ctx.ModuleName(), scopePaths.stubsHeaderPath...) 1429*333d2b36SAndroid Build Coastguard Worker } 1430*333d2b36SAndroid Build Coastguard Worker 1431*333d2b36SAndroid Build Coastguard Worker if tag == implLibraryTag { 1432*333d2b36SAndroid Build Coastguard Worker if dep, ok := android.OtherModuleProvider(ctx, to, JavaInfoProvider); ok { 1433*333d2b36SAndroid Build Coastguard Worker module.implLibraryHeaderJars = append(module.implLibraryHeaderJars, dep.HeaderJars...) 1434*333d2b36SAndroid Build Coastguard Worker module.implLibraryModule = to.(*Library) 1435*333d2b36SAndroid Build Coastguard Worker } 1436*333d2b36SAndroid Build Coastguard Worker } 1437*333d2b36SAndroid Build Coastguard Worker }) 1438*333d2b36SAndroid Build Coastguard Worker 1439*333d2b36SAndroid Build Coastguard Worker sdkLibInfo := module.generateCommonBuildActions(ctx) 1440*333d2b36SAndroid Build Coastguard Worker apexInfo, _ := android.ModuleProvider(ctx, android.ApexInfoProvider) 1441*333d2b36SAndroid Build Coastguard Worker if !apexInfo.IsForPlatform() { 1442*333d2b36SAndroid Build Coastguard Worker module.hideApexVariantFromMake = true 1443*333d2b36SAndroid Build Coastguard Worker } 1444*333d2b36SAndroid Build Coastguard Worker 1445*333d2b36SAndroid Build Coastguard Worker if module.implLibraryModule != nil { 1446*333d2b36SAndroid Build Coastguard Worker if ctx.Device() { 1447*333d2b36SAndroid Build Coastguard Worker module.classesJarPaths = android.Paths{module.implLibraryModule.implementationJarFile} 1448*333d2b36SAndroid Build Coastguard Worker module.bootDexJarPath = module.implLibraryModule.bootDexJarPath 1449*333d2b36SAndroid Build Coastguard Worker module.uncompressDexState = module.implLibraryModule.uncompressDexState 1450*333d2b36SAndroid Build Coastguard Worker module.active = module.implLibraryModule.active 1451*333d2b36SAndroid Build Coastguard Worker } 1452*333d2b36SAndroid Build Coastguard Worker 1453*333d2b36SAndroid Build Coastguard Worker module.outputFile = module.implLibraryModule.outputFile 1454*333d2b36SAndroid Build Coastguard Worker module.dexJarFile = makeDexJarPathFromPath(module.implLibraryModule.dexJarFile.Path()) 1455*333d2b36SAndroid Build Coastguard Worker module.headerJarFile = module.implLibraryModule.headerJarFile 1456*333d2b36SAndroid Build Coastguard Worker module.implementationAndResourcesJar = module.implLibraryModule.implementationAndResourcesJar 1457*333d2b36SAndroid Build Coastguard Worker module.builtInstalledForApex = module.implLibraryModule.builtInstalledForApex 1458*333d2b36SAndroid Build Coastguard Worker module.dexpreopter.configPath = module.implLibraryModule.dexpreopter.configPath 1459*333d2b36SAndroid Build Coastguard Worker module.dexpreopter.outputProfilePathOnHost = module.implLibraryModule.dexpreopter.outputProfilePathOnHost 1460*333d2b36SAndroid Build Coastguard Worker 1461*333d2b36SAndroid Build Coastguard Worker // Properties required for Library.AndroidMkEntries 1462*333d2b36SAndroid Build Coastguard Worker module.logtagsSrcs = module.implLibraryModule.logtagsSrcs 1463*333d2b36SAndroid Build Coastguard Worker module.dexpreopter.builtInstalled = module.implLibraryModule.dexpreopter.builtInstalled 1464*333d2b36SAndroid Build Coastguard Worker module.jacocoReportClassesFile = module.implLibraryModule.jacocoReportClassesFile 1465*333d2b36SAndroid Build Coastguard Worker module.dexer.proguardDictionary = module.implLibraryModule.dexer.proguardDictionary 1466*333d2b36SAndroid Build Coastguard Worker module.dexer.proguardUsageZip = module.implLibraryModule.dexer.proguardUsageZip 1467*333d2b36SAndroid Build Coastguard Worker module.linter.reports = module.implLibraryModule.linter.reports 1468*333d2b36SAndroid Build Coastguard Worker 1469*333d2b36SAndroid Build Coastguard Worker if lintInfo, ok := android.OtherModuleProvider(ctx, module.implLibraryModule, LintProvider); ok { 1470*333d2b36SAndroid Build Coastguard Worker android.SetProvider(ctx, LintProvider, lintInfo) 1471*333d2b36SAndroid Build Coastguard Worker } 1472*333d2b36SAndroid Build Coastguard Worker 1473*333d2b36SAndroid Build Coastguard Worker if !module.Host() { 1474*333d2b36SAndroid Build Coastguard Worker module.hostdexInstallFile = module.implLibraryModule.hostdexInstallFile 1475*333d2b36SAndroid Build Coastguard Worker } 1476*333d2b36SAndroid Build Coastguard Worker 1477*333d2b36SAndroid Build Coastguard Worker if installFilesInfo, ok := android.OtherModuleProvider(ctx, module.implLibraryModule, android.InstallFilesProvider); ok { 1478*333d2b36SAndroid Build Coastguard Worker if installFilesInfo.CheckbuildTarget != nil { 1479*333d2b36SAndroid Build Coastguard Worker ctx.CheckbuildFile(installFilesInfo.CheckbuildTarget) 1480*333d2b36SAndroid Build Coastguard Worker } 1481*333d2b36SAndroid Build Coastguard Worker } 1482*333d2b36SAndroid Build Coastguard Worker android.SetProvider(ctx, blueprint.SrcsFileProviderKey, blueprint.SrcsFileProviderData{SrcPaths: module.implLibraryModule.uniqueSrcFiles.Strings()}) 1483*333d2b36SAndroid Build Coastguard Worker } 1484*333d2b36SAndroid Build Coastguard Worker 1485*333d2b36SAndroid Build Coastguard Worker // Make the set of components exported by this module available for use elsewhere. 1486*333d2b36SAndroid Build Coastguard Worker exportedComponentInfo := android.ExportedComponentsInfo{Components: android.SortedKeys(exportedComponents)} 1487*333d2b36SAndroid Build Coastguard Worker android.SetProvider(ctx, android.ExportedComponentsInfoProvider, exportedComponentInfo) 1488*333d2b36SAndroid Build Coastguard Worker 1489*333d2b36SAndroid Build Coastguard Worker // Provide additional information for inclusion in an sdk's generated .info file. 1490*333d2b36SAndroid Build Coastguard Worker additionalSdkInfo := map[string]interface{}{} 1491*333d2b36SAndroid Build Coastguard Worker additionalSdkInfo["dist_stem"] = module.distStem() 1492*333d2b36SAndroid Build Coastguard Worker baseModuleName := module.distStem() 1493*333d2b36SAndroid Build Coastguard Worker scopes := map[string]interface{}{} 1494*333d2b36SAndroid Build Coastguard Worker additionalSdkInfo["scopes"] = scopes 1495*333d2b36SAndroid Build Coastguard Worker for scope, scopePaths := range module.scopePaths { 1496*333d2b36SAndroid Build Coastguard Worker scopeInfo := map[string]interface{}{} 1497*333d2b36SAndroid Build Coastguard Worker scopes[scope.name] = scopeInfo 1498*333d2b36SAndroid Build Coastguard Worker scopeInfo["current_api"] = scope.snapshotRelativeCurrentApiTxtPath(baseModuleName) 1499*333d2b36SAndroid Build Coastguard Worker scopeInfo["removed_api"] = scope.snapshotRelativeRemovedApiTxtPath(baseModuleName) 1500*333d2b36SAndroid Build Coastguard Worker if p := scopePaths.latestApiPaths; len(p) > 0 { 1501*333d2b36SAndroid Build Coastguard Worker // The last path in the list is the one that applies to this scope, the 1502*333d2b36SAndroid Build Coastguard Worker // preceding ones, if any, are for the scope(s) that it extends. 1503*333d2b36SAndroid Build Coastguard Worker scopeInfo["latest_api"] = p[len(p)-1].String() 1504*333d2b36SAndroid Build Coastguard Worker } 1505*333d2b36SAndroid Build Coastguard Worker if p := scopePaths.latestRemovedApiPaths; len(p) > 0 { 1506*333d2b36SAndroid Build Coastguard Worker // The last path in the list is the one that applies to this scope, the 1507*333d2b36SAndroid Build Coastguard Worker // preceding ones, if any, are for the scope(s) that it extends. 1508*333d2b36SAndroid Build Coastguard Worker scopeInfo["latest_removed_api"] = p[len(p)-1].String() 1509*333d2b36SAndroid Build Coastguard Worker } 1510*333d2b36SAndroid Build Coastguard Worker } 1511*333d2b36SAndroid Build Coastguard Worker android.SetProvider(ctx, android.AdditionalSdkInfoProvider, android.AdditionalSdkInfo{additionalSdkInfo}) 1512*333d2b36SAndroid Build Coastguard Worker module.setOutputFiles(ctx) 1513*333d2b36SAndroid Build Coastguard Worker 1514*333d2b36SAndroid Build Coastguard Worker var generatingLibs []string 1515*333d2b36SAndroid Build Coastguard Worker for _, apiScope := range AllApiScopes { 1516*333d2b36SAndroid Build Coastguard Worker if _, ok := module.scopePaths[apiScope]; ok { 1517*333d2b36SAndroid Build Coastguard Worker generatingLibs = append(generatingLibs, module.stubsLibraryModuleName(apiScope)) 1518*333d2b36SAndroid Build Coastguard Worker } 1519*333d2b36SAndroid Build Coastguard Worker } 1520*333d2b36SAndroid Build Coastguard Worker 1521*333d2b36SAndroid Build Coastguard Worker if module.requiresRuntimeImplementationLibrary() && module.implLibraryModule != nil { 1522*333d2b36SAndroid Build Coastguard Worker generatingLibs = append(generatingLibs, module.implLibraryModuleName()) 1523*333d2b36SAndroid Build Coastguard Worker setOutputFiles(ctx, module.implLibraryModule.Module) 1524*333d2b36SAndroid Build Coastguard Worker } 1525*333d2b36SAndroid Build Coastguard Worker 1526*333d2b36SAndroid Build Coastguard Worker sdkLibInfo.GeneratingLibs = generatingLibs 1527*333d2b36SAndroid Build Coastguard Worker android.SetProvider(ctx, SdkLibraryInfoProvider, sdkLibInfo) 1528*333d2b36SAndroid Build Coastguard Worker} 1529*333d2b36SAndroid Build Coastguard Worker 1530*333d2b36SAndroid Build Coastguard Workerfunc (module *SdkLibrary) BuiltInstalledForApex() []dexpreopterInstall { 1531*333d2b36SAndroid Build Coastguard Worker return module.builtInstalledForApex 1532*333d2b36SAndroid Build Coastguard Worker} 1533*333d2b36SAndroid Build Coastguard Worker 1534*333d2b36SAndroid Build Coastguard Workerfunc (module *SdkLibrary) AndroidMkEntries() []android.AndroidMkEntries { 1535*333d2b36SAndroid Build Coastguard Worker if !module.requiresRuntimeImplementationLibrary() { 1536*333d2b36SAndroid Build Coastguard Worker return nil 1537*333d2b36SAndroid Build Coastguard Worker } 1538*333d2b36SAndroid Build Coastguard Worker entriesList := module.Library.AndroidMkEntries() 1539*333d2b36SAndroid Build Coastguard Worker entries := &entriesList[0] 1540*333d2b36SAndroid Build Coastguard Worker entries.Required = append(entries.Required, module.implLibraryModuleName()) 1541*333d2b36SAndroid Build Coastguard Worker if module.sharedLibrary() { 1542*333d2b36SAndroid Build Coastguard Worker entries.Required = append(entries.Required, module.xmlPermissionsModuleName()) 1543*333d2b36SAndroid Build Coastguard Worker } 1544*333d2b36SAndroid Build Coastguard Worker return entriesList 1545*333d2b36SAndroid Build Coastguard Worker} 1546*333d2b36SAndroid Build Coastguard Worker 1547*333d2b36SAndroid Build Coastguard Worker// The dist path of the stub artifacts 1548*333d2b36SAndroid Build Coastguard Workerfunc (module *SdkLibrary) apiDistPath(apiScope *apiScope) string { 1549*333d2b36SAndroid Build Coastguard Worker return path.Join("apistubs", module.distGroup(), apiScope.name) 1550*333d2b36SAndroid Build Coastguard Worker} 1551*333d2b36SAndroid Build Coastguard Worker 1552*333d2b36SAndroid Build Coastguard Worker// Get the sdk version for use when compiling the stubs library. 1553*333d2b36SAndroid Build Coastguard Workerfunc (module *SdkLibrary) sdkVersionForStubsLibrary(mctx android.EarlyModuleContext, apiScope *apiScope) string { 1554*333d2b36SAndroid Build Coastguard Worker scopeProperties := module.scopeToProperties[apiScope] 1555*333d2b36SAndroid Build Coastguard Worker if scopeProperties.Sdk_version != nil { 1556*333d2b36SAndroid Build Coastguard Worker return proptools.String(scopeProperties.Sdk_version) 1557*333d2b36SAndroid Build Coastguard Worker } 1558*333d2b36SAndroid Build Coastguard Worker 1559*333d2b36SAndroid Build Coastguard Worker sdkDep := decodeSdkDep(mctx, android.SdkContext(&module.Library)) 1560*333d2b36SAndroid Build Coastguard Worker if sdkDep.hasStandardLibs() { 1561*333d2b36SAndroid Build Coastguard Worker // If building against a standard sdk then use the sdk version appropriate for the scope. 1562*333d2b36SAndroid Build Coastguard Worker return apiScope.sdkVersion 1563*333d2b36SAndroid Build Coastguard Worker } else { 1564*333d2b36SAndroid Build Coastguard Worker // Otherwise, use no system module. 1565*333d2b36SAndroid Build Coastguard Worker return "none" 1566*333d2b36SAndroid Build Coastguard Worker } 1567*333d2b36SAndroid Build Coastguard Worker} 1568*333d2b36SAndroid Build Coastguard Worker 1569*333d2b36SAndroid Build Coastguard Workerfunc (module *SdkLibrary) distStem() string { 1570*333d2b36SAndroid Build Coastguard Worker return proptools.StringDefault(module.sdkLibraryProperties.Dist_stem, module.BaseModuleName()) 1571*333d2b36SAndroid Build Coastguard Worker} 1572*333d2b36SAndroid Build Coastguard Worker 1573*333d2b36SAndroid Build Coastguard Worker// distGroup returns the subdirectory of the dist path of the stub artifacts. 1574*333d2b36SAndroid Build Coastguard Workerfunc (module *SdkLibrary) distGroup() string { 1575*333d2b36SAndroid Build Coastguard Worker return proptools.StringDefault(module.sdkLibraryProperties.Dist_group, "unknown") 1576*333d2b36SAndroid Build Coastguard Worker} 1577*333d2b36SAndroid Build Coastguard Worker 1578*333d2b36SAndroid Build Coastguard Workerfunc latestPrebuiltApiModuleName(name string, apiScope *apiScope) string { 1579*333d2b36SAndroid Build Coastguard Worker return PrebuiltApiModuleName(name, apiScope.name, "latest") 1580*333d2b36SAndroid Build Coastguard Worker} 1581*333d2b36SAndroid Build Coastguard Worker 1582*333d2b36SAndroid Build Coastguard Workerfunc latestPrebuiltApiCombinedModuleName(name string, apiScope *apiScope) string { 1583*333d2b36SAndroid Build Coastguard Worker return PrebuiltApiCombinedModuleName(name, apiScope.name, "latest") 1584*333d2b36SAndroid Build Coastguard Worker} 1585*333d2b36SAndroid Build Coastguard Worker 1586*333d2b36SAndroid Build Coastguard Workerfunc (module *SdkLibrary) latestApiFilegroupName(apiScope *apiScope) string { 1587*333d2b36SAndroid Build Coastguard Worker return ":" + module.latestApiModuleName(apiScope) 1588*333d2b36SAndroid Build Coastguard Worker} 1589*333d2b36SAndroid Build Coastguard Worker 1590*333d2b36SAndroid Build Coastguard Workerfunc (module *SdkLibrary) latestApiModuleName(apiScope *apiScope) string { 1591*333d2b36SAndroid Build Coastguard Worker return latestPrebuiltApiCombinedModuleName(module.distStem(), apiScope) 1592*333d2b36SAndroid Build Coastguard Worker} 1593*333d2b36SAndroid Build Coastguard Worker 1594*333d2b36SAndroid Build Coastguard Workerfunc (module *SdkLibrary) latestRemovedApiFilegroupName(apiScope *apiScope) string { 1595*333d2b36SAndroid Build Coastguard Worker return ":" + module.latestRemovedApiModuleName(apiScope) 1596*333d2b36SAndroid Build Coastguard Worker} 1597*333d2b36SAndroid Build Coastguard Worker 1598*333d2b36SAndroid Build Coastguard Workerfunc (module *SdkLibrary) latestRemovedApiModuleName(apiScope *apiScope) string { 1599*333d2b36SAndroid Build Coastguard Worker return latestPrebuiltApiCombinedModuleName(module.distStem()+"-removed", apiScope) 1600*333d2b36SAndroid Build Coastguard Worker} 1601*333d2b36SAndroid Build Coastguard Worker 1602*333d2b36SAndroid Build Coastguard Workerfunc (module *SdkLibrary) latestIncompatibilitiesFilegroupName(apiScope *apiScope) string { 1603*333d2b36SAndroid Build Coastguard Worker return ":" + module.latestIncompatibilitiesModuleName(apiScope) 1604*333d2b36SAndroid Build Coastguard Worker} 1605*333d2b36SAndroid Build Coastguard Worker 1606*333d2b36SAndroid Build Coastguard Workerfunc (module *SdkLibrary) latestIncompatibilitiesModuleName(apiScope *apiScope) string { 1607*333d2b36SAndroid Build Coastguard Worker return latestPrebuiltApiModuleName(module.distStem()+"-incompatibilities", apiScope) 1608*333d2b36SAndroid Build Coastguard Worker} 1609*333d2b36SAndroid Build Coastguard Worker 1610*333d2b36SAndroid Build Coastguard Worker// The listed modules' stubs contents do not match the corresponding txt files, 1611*333d2b36SAndroid Build Coastguard Worker// but require additional api contributions to generate the full stubs. 1612*333d2b36SAndroid Build Coastguard Worker// This method returns the name of the additional api contribution module 1613*333d2b36SAndroid Build Coastguard Worker// for corresponding sdk_library modules. 1614*333d2b36SAndroid Build Coastguard Workerfunc (module *SdkLibrary) apiLibraryAdditionalApiContribution() string { 1615*333d2b36SAndroid Build Coastguard Worker if val, ok := apiLibraryAdditionalProperties[module.Name()]; ok { 1616*333d2b36SAndroid Build Coastguard Worker return val 1617*333d2b36SAndroid Build Coastguard Worker } 1618*333d2b36SAndroid Build Coastguard Worker return "" 1619*333d2b36SAndroid Build Coastguard Worker} 1620*333d2b36SAndroid Build Coastguard Worker 1621*333d2b36SAndroid Build Coastguard Workerfunc childModuleVisibility(childVisibility []string) []string { 1622*333d2b36SAndroid Build Coastguard Worker if childVisibility == nil { 1623*333d2b36SAndroid Build Coastguard Worker // No child visibility set. The child will use the visibility of the sdk_library. 1624*333d2b36SAndroid Build Coastguard Worker return nil 1625*333d2b36SAndroid Build Coastguard Worker } 1626*333d2b36SAndroid Build Coastguard Worker 1627*333d2b36SAndroid Build Coastguard Worker // Prepend an override to ignore the sdk_library's visibility, and rely on the child visibility. 1628*333d2b36SAndroid Build Coastguard Worker var visibility []string 1629*333d2b36SAndroid Build Coastguard Worker visibility = append(visibility, "//visibility:override") 1630*333d2b36SAndroid Build Coastguard Worker visibility = append(visibility, childVisibility...) 1631*333d2b36SAndroid Build Coastguard Worker return visibility 1632*333d2b36SAndroid Build Coastguard Worker} 1633*333d2b36SAndroid Build Coastguard Worker 1634*333d2b36SAndroid Build Coastguard Workerfunc (module *SdkLibrary) compareAgainstLatestApi(apiScope *apiScope) bool { 1635*333d2b36SAndroid Build Coastguard Worker return !(apiScope.unstable || module.sdkLibraryProperties.Unsafe_ignore_missing_latest_api) 1636*333d2b36SAndroid Build Coastguard Worker} 1637*333d2b36SAndroid Build Coastguard Worker 1638*333d2b36SAndroid Build Coastguard Worker// Implements android.ApexModule 1639*333d2b36SAndroid Build Coastguard Workerfunc (module *SdkLibrary) DepIsInSameApex(mctx android.BaseModuleContext, dep android.Module) bool { 1640*333d2b36SAndroid Build Coastguard Worker depTag := mctx.OtherModuleDependencyTag(dep) 1641*333d2b36SAndroid Build Coastguard Worker if depTag == xmlPermissionsFileTag { 1642*333d2b36SAndroid Build Coastguard Worker return true 1643*333d2b36SAndroid Build Coastguard Worker } 1644*333d2b36SAndroid Build Coastguard Worker if dep.Name() == module.implLibraryModuleName() { 1645*333d2b36SAndroid Build Coastguard Worker return true 1646*333d2b36SAndroid Build Coastguard Worker } 1647*333d2b36SAndroid Build Coastguard Worker return module.Library.DepIsInSameApex(mctx, dep) 1648*333d2b36SAndroid Build Coastguard Worker} 1649*333d2b36SAndroid Build Coastguard Worker 1650*333d2b36SAndroid Build Coastguard Worker// Implements android.ApexModule 1651*333d2b36SAndroid Build Coastguard Workerfunc (module *SdkLibrary) UniqueApexVariations() bool { 1652*333d2b36SAndroid Build Coastguard Worker return module.uniqueApexVariations() 1653*333d2b36SAndroid Build Coastguard Worker} 1654*333d2b36SAndroid Build Coastguard Worker 1655*333d2b36SAndroid Build Coastguard Workerfunc (module *SdkLibrary) ModuleBuildFromTextStubs() bool { 1656*333d2b36SAndroid Build Coastguard Worker return proptools.BoolDefault(module.sdkLibraryProperties.Build_from_text_stub, true) 1657*333d2b36SAndroid Build Coastguard Worker} 1658*333d2b36SAndroid Build Coastguard Worker 1659*333d2b36SAndroid Build Coastguard Workervar javaSdkLibrariesKey = android.NewOnceKey("javaSdkLibraries") 1660*333d2b36SAndroid Build Coastguard Worker 1661*333d2b36SAndroid Build Coastguard Workerfunc javaSdkLibraries(config android.Config) *[]string { 1662*333d2b36SAndroid Build Coastguard Worker return config.Once(javaSdkLibrariesKey, func() interface{} { 1663*333d2b36SAndroid Build Coastguard Worker return &[]string{} 1664*333d2b36SAndroid Build Coastguard Worker }).(*[]string) 1665*333d2b36SAndroid Build Coastguard Worker} 1666*333d2b36SAndroid Build Coastguard Worker 1667*333d2b36SAndroid Build Coastguard Workerfunc (module *SdkLibrary) getApiDir() string { 1668*333d2b36SAndroid Build Coastguard Worker return proptools.StringDefault(module.sdkLibraryProperties.Api_dir, "api") 1669*333d2b36SAndroid Build Coastguard Worker} 1670*333d2b36SAndroid Build Coastguard Worker 1671*333d2b36SAndroid Build Coastguard Worker// For a java_sdk_library module, create internal modules for stubs, docs, 1672*333d2b36SAndroid Build Coastguard Worker// runtime libs and xml file. If requested, the stubs and docs are created twice 1673*333d2b36SAndroid Build Coastguard Worker// once for public API level and once for system API level 1674*333d2b36SAndroid Build Coastguard Workerfunc (module *SdkLibrary) CreateInternalModules(mctx android.DefaultableHookContext) { 1675*333d2b36SAndroid Build Coastguard Worker if len(module.properties.Srcs) == 0 { 1676*333d2b36SAndroid Build Coastguard Worker mctx.PropertyErrorf("srcs", "java_sdk_library must specify srcs") 1677*333d2b36SAndroid Build Coastguard Worker return 1678*333d2b36SAndroid Build Coastguard Worker } 1679*333d2b36SAndroid Build Coastguard Worker 1680*333d2b36SAndroid Build Coastguard Worker // If this builds against standard libraries (i.e. is not part of the core libraries) 1681*333d2b36SAndroid Build Coastguard Worker // then assume it provides both system and test apis. 1682*333d2b36SAndroid Build Coastguard Worker sdkDep := decodeSdkDep(mctx, android.SdkContext(&module.Library)) 1683*333d2b36SAndroid Build Coastguard Worker hasSystemAndTestApis := sdkDep.hasStandardLibs() 1684*333d2b36SAndroid Build Coastguard Worker module.sdkLibraryProperties.Generate_system_and_test_apis = hasSystemAndTestApis 1685*333d2b36SAndroid Build Coastguard Worker 1686*333d2b36SAndroid Build Coastguard Worker missingCurrentApi := false 1687*333d2b36SAndroid Build Coastguard Worker 1688*333d2b36SAndroid Build Coastguard Worker generatedScopes := module.getGeneratedApiScopes(mctx) 1689*333d2b36SAndroid Build Coastguard Worker 1690*333d2b36SAndroid Build Coastguard Worker apiDir := module.getApiDir() 1691*333d2b36SAndroid Build Coastguard Worker for _, scope := range generatedScopes { 1692*333d2b36SAndroid Build Coastguard Worker for _, api := range []string{"current.txt", "removed.txt"} { 1693*333d2b36SAndroid Build Coastguard Worker path := path.Join(mctx.ModuleDir(), apiDir, scope.apiFilePrefix+api) 1694*333d2b36SAndroid Build Coastguard Worker p := android.ExistentPathForSource(mctx, path) 1695*333d2b36SAndroid Build Coastguard Worker if !p.Valid() { 1696*333d2b36SAndroid Build Coastguard Worker if mctx.Config().AllowMissingDependencies() { 1697*333d2b36SAndroid Build Coastguard Worker mctx.AddMissingDependencies([]string{path}) 1698*333d2b36SAndroid Build Coastguard Worker } else { 1699*333d2b36SAndroid Build Coastguard Worker mctx.ModuleErrorf("Current api file %#v doesn't exist", path) 1700*333d2b36SAndroid Build Coastguard Worker missingCurrentApi = true 1701*333d2b36SAndroid Build Coastguard Worker } 1702*333d2b36SAndroid Build Coastguard Worker } 1703*333d2b36SAndroid Build Coastguard Worker } 1704*333d2b36SAndroid Build Coastguard Worker } 1705*333d2b36SAndroid Build Coastguard Worker 1706*333d2b36SAndroid Build Coastguard Worker if missingCurrentApi { 1707*333d2b36SAndroid Build Coastguard Worker script := "build/soong/scripts/gen-java-current-api-files.sh" 1708*333d2b36SAndroid Build Coastguard Worker p := android.ExistentPathForSource(mctx, script) 1709*333d2b36SAndroid Build Coastguard Worker 1710*333d2b36SAndroid Build Coastguard Worker if !p.Valid() { 1711*333d2b36SAndroid Build Coastguard Worker panic(fmt.Sprintf("script file %s doesn't exist", script)) 1712*333d2b36SAndroid Build Coastguard Worker } 1713*333d2b36SAndroid Build Coastguard Worker 1714*333d2b36SAndroid Build Coastguard Worker mctx.ModuleErrorf("One or more current api files are missing. "+ 1715*333d2b36SAndroid Build Coastguard Worker "You can update them by:\n"+ 1716*333d2b36SAndroid Build Coastguard Worker "%s %q %s && m update-api", 1717*333d2b36SAndroid Build Coastguard Worker script, filepath.Join(mctx.ModuleDir(), apiDir), 1718*333d2b36SAndroid Build Coastguard Worker strings.Join(generatedScopes.Strings(func(s *apiScope) string { return s.apiFilePrefix }), " ")) 1719*333d2b36SAndroid Build Coastguard Worker return 1720*333d2b36SAndroid Build Coastguard Worker } 1721*333d2b36SAndroid Build Coastguard Worker 1722*333d2b36SAndroid Build Coastguard Worker for _, scope := range generatedScopes { 1723*333d2b36SAndroid Build Coastguard Worker // Use the stubs source name for legacy reasons. 1724*333d2b36SAndroid Build Coastguard Worker module.createDroidstubs(mctx, scope, module.droidstubsModuleName(scope), scope.droidstubsArgs) 1725*333d2b36SAndroid Build Coastguard Worker 1726*333d2b36SAndroid Build Coastguard Worker module.createFromSourceStubsLibrary(mctx, scope) 1727*333d2b36SAndroid Build Coastguard Worker module.createExportableFromSourceStubsLibrary(mctx, scope) 1728*333d2b36SAndroid Build Coastguard Worker 1729*333d2b36SAndroid Build Coastguard Worker if mctx.Config().BuildFromTextStub() && module.ModuleBuildFromTextStubs() { 1730*333d2b36SAndroid Build Coastguard Worker module.createApiLibrary(mctx, scope) 1731*333d2b36SAndroid Build Coastguard Worker } 1732*333d2b36SAndroid Build Coastguard Worker module.createTopLevelStubsLibrary(mctx, scope) 1733*333d2b36SAndroid Build Coastguard Worker module.createTopLevelExportableStubsLibrary(mctx, scope) 1734*333d2b36SAndroid Build Coastguard Worker } 1735*333d2b36SAndroid Build Coastguard Worker 1736*333d2b36SAndroid Build Coastguard Worker if module.requiresRuntimeImplementationLibrary() { 1737*333d2b36SAndroid Build Coastguard Worker // Create child module to create an implementation library. 1738*333d2b36SAndroid Build Coastguard Worker // 1739*333d2b36SAndroid Build Coastguard Worker // This temporarily creates a second implementation library that can be explicitly 1740*333d2b36SAndroid Build Coastguard Worker // referenced. 1741*333d2b36SAndroid Build Coastguard Worker // 1742*333d2b36SAndroid Build Coastguard Worker // TODO(b/156618935) - update comment once only one implementation library is created. 1743*333d2b36SAndroid Build Coastguard Worker module.createImplLibrary(mctx) 1744*333d2b36SAndroid Build Coastguard Worker 1745*333d2b36SAndroid Build Coastguard Worker // Only create an XML permissions file that declares the library as being usable 1746*333d2b36SAndroid Build Coastguard Worker // as a shared library if required. 1747*333d2b36SAndroid Build Coastguard Worker if module.sharedLibrary() { 1748*333d2b36SAndroid Build Coastguard Worker module.createXmlFile(mctx) 1749*333d2b36SAndroid Build Coastguard Worker } 1750*333d2b36SAndroid Build Coastguard Worker 1751*333d2b36SAndroid Build Coastguard Worker // record java_sdk_library modules so that they are exported to make 1752*333d2b36SAndroid Build Coastguard Worker javaSdkLibraries := javaSdkLibraries(mctx.Config()) 1753*333d2b36SAndroid Build Coastguard Worker javaSdkLibrariesLock.Lock() 1754*333d2b36SAndroid Build Coastguard Worker defer javaSdkLibrariesLock.Unlock() 1755*333d2b36SAndroid Build Coastguard Worker *javaSdkLibraries = append(*javaSdkLibraries, module.BaseModuleName()) 1756*333d2b36SAndroid Build Coastguard Worker } 1757*333d2b36SAndroid Build Coastguard Worker 1758*333d2b36SAndroid Build Coastguard Worker // Add the impl_only_libs and impl_only_static_libs *after* we're done using them in submodules. 1759*333d2b36SAndroid Build Coastguard Worker module.properties.Libs = append(module.properties.Libs, module.sdkLibraryProperties.Impl_only_libs...) 1760*333d2b36SAndroid Build Coastguard Worker module.properties.Static_libs.AppendSimpleValue(module.sdkLibraryProperties.Impl_only_static_libs) 1761*333d2b36SAndroid Build Coastguard Worker} 1762*333d2b36SAndroid Build Coastguard Worker 1763*333d2b36SAndroid Build Coastguard Workerfunc (module *SdkLibrary) InitSdkLibraryProperties() { 1764*333d2b36SAndroid Build Coastguard Worker module.addHostAndDeviceProperties() 1765*333d2b36SAndroid Build Coastguard Worker module.AddProperties(&module.sdkLibraryProperties) 1766*333d2b36SAndroid Build Coastguard Worker 1767*333d2b36SAndroid Build Coastguard Worker module.initSdkLibraryComponent(module) 1768*333d2b36SAndroid Build Coastguard Worker 1769*333d2b36SAndroid Build Coastguard Worker module.properties.Installable = proptools.BoolPtr(true) 1770*333d2b36SAndroid Build Coastguard Worker module.deviceProperties.IsSDKLibrary = true 1771*333d2b36SAndroid Build Coastguard Worker} 1772*333d2b36SAndroid Build Coastguard Worker 1773*333d2b36SAndroid Build Coastguard Workerfunc (module *SdkLibrary) requiresRuntimeImplementationLibrary() bool { 1774*333d2b36SAndroid Build Coastguard Worker return !proptools.Bool(module.sdkLibraryProperties.Api_only) 1775*333d2b36SAndroid Build Coastguard Worker} 1776*333d2b36SAndroid Build Coastguard Worker 1777*333d2b36SAndroid Build Coastguard Workerfunc moduleStubLinkType(j *Module) (stub bool, ret sdkLinkType) { 1778*333d2b36SAndroid Build Coastguard Worker kind := android.ToSdkKind(proptools.String(j.properties.Stub_contributing_api)) 1779*333d2b36SAndroid Build Coastguard Worker switch kind { 1780*333d2b36SAndroid Build Coastguard Worker case android.SdkPublic: 1781*333d2b36SAndroid Build Coastguard Worker return true, javaSdk 1782*333d2b36SAndroid Build Coastguard Worker case android.SdkSystem: 1783*333d2b36SAndroid Build Coastguard Worker return true, javaSystem 1784*333d2b36SAndroid Build Coastguard Worker case android.SdkModule: 1785*333d2b36SAndroid Build Coastguard Worker return true, javaModule 1786*333d2b36SAndroid Build Coastguard Worker case android.SdkTest: 1787*333d2b36SAndroid Build Coastguard Worker return true, javaSystem 1788*333d2b36SAndroid Build Coastguard Worker case android.SdkSystemServer: 1789*333d2b36SAndroid Build Coastguard Worker return true, javaSystemServer 1790*333d2b36SAndroid Build Coastguard Worker // Default value for all modules other than java_sdk_library-generated stub submodules 1791*333d2b36SAndroid Build Coastguard Worker case android.SdkInvalid: 1792*333d2b36SAndroid Build Coastguard Worker return false, javaPlatform 1793*333d2b36SAndroid Build Coastguard Worker default: 1794*333d2b36SAndroid Build Coastguard Worker panic(fmt.Sprintf("stub_contributing_api set as an unsupported sdk kind %s", kind.String())) 1795*333d2b36SAndroid Build Coastguard Worker } 1796*333d2b36SAndroid Build Coastguard Worker} 1797*333d2b36SAndroid Build Coastguard Worker 1798*333d2b36SAndroid Build Coastguard Worker// java_sdk_library is a special Java library that provides optional platform APIs to apps. 1799*333d2b36SAndroid Build Coastguard Worker// In practice, it can be viewed as a combination of several modules: 1) stubs library that clients 1800*333d2b36SAndroid Build Coastguard Worker// are linked against to, 2) droiddoc module that internally generates API stubs source files, 1801*333d2b36SAndroid Build Coastguard Worker// 3) the real runtime shared library that implements the APIs, and 4) XML file for adding 1802*333d2b36SAndroid Build Coastguard Worker// the runtime lib to the classpath at runtime if requested via <uses-library>. 1803*333d2b36SAndroid Build Coastguard Workerfunc SdkLibraryFactory() android.Module { 1804*333d2b36SAndroid Build Coastguard Worker module := &SdkLibrary{} 1805*333d2b36SAndroid Build Coastguard Worker 1806*333d2b36SAndroid Build Coastguard Worker // Initialize information common between source and prebuilt. 1807*333d2b36SAndroid Build Coastguard Worker module.initCommon(module) 1808*333d2b36SAndroid Build Coastguard Worker 1809*333d2b36SAndroid Build Coastguard Worker module.InitSdkLibraryProperties() 1810*333d2b36SAndroid Build Coastguard Worker android.InitApexModule(module) 1811*333d2b36SAndroid Build Coastguard Worker InitJavaModule(module, android.HostAndDeviceSupported) 1812*333d2b36SAndroid Build Coastguard Worker 1813*333d2b36SAndroid Build Coastguard Worker // Initialize the map from scope to scope specific properties. 1814*333d2b36SAndroid Build Coastguard Worker scopeToProperties := make(map[*apiScope]*ApiScopeProperties) 1815*333d2b36SAndroid Build Coastguard Worker for _, scope := range AllApiScopes { 1816*333d2b36SAndroid Build Coastguard Worker scopeToProperties[scope] = scope.scopeSpecificProperties(module) 1817*333d2b36SAndroid Build Coastguard Worker } 1818*333d2b36SAndroid Build Coastguard Worker module.scopeToProperties = scopeToProperties 1819*333d2b36SAndroid Build Coastguard Worker 1820*333d2b36SAndroid Build Coastguard Worker // Add the properties containing visibility rules so that they are checked. 1821*333d2b36SAndroid Build Coastguard Worker android.AddVisibilityProperty(module, "impl_library_visibility", &module.sdkLibraryProperties.Impl_library_visibility) 1822*333d2b36SAndroid Build Coastguard Worker android.AddVisibilityProperty(module, "stubs_library_visibility", &module.sdkLibraryProperties.Stubs_library_visibility) 1823*333d2b36SAndroid Build Coastguard Worker android.AddVisibilityProperty(module, "stubs_source_visibility", &module.sdkLibraryProperties.Stubs_source_visibility) 1824*333d2b36SAndroid Build Coastguard Worker 1825*333d2b36SAndroid Build Coastguard Worker module.SetDefaultableHook(func(ctx android.DefaultableHookContext) { 1826*333d2b36SAndroid Build Coastguard Worker // If no implementation is required then it cannot be used as a shared library 1827*333d2b36SAndroid Build Coastguard Worker // either. 1828*333d2b36SAndroid Build Coastguard Worker if !module.requiresRuntimeImplementationLibrary() { 1829*333d2b36SAndroid Build Coastguard Worker // If shared_library has been explicitly set to true then it is incompatible 1830*333d2b36SAndroid Build Coastguard Worker // with api_only: true. 1831*333d2b36SAndroid Build Coastguard Worker if proptools.Bool(module.commonSdkLibraryProperties.Shared_library) { 1832*333d2b36SAndroid Build Coastguard Worker ctx.PropertyErrorf("api_only/shared_library", "inconsistent settings, shared_library and api_only cannot both be true") 1833*333d2b36SAndroid Build Coastguard Worker } 1834*333d2b36SAndroid Build Coastguard Worker // Set shared_library: false. 1835*333d2b36SAndroid Build Coastguard Worker module.commonSdkLibraryProperties.Shared_library = proptools.BoolPtr(false) 1836*333d2b36SAndroid Build Coastguard Worker } 1837*333d2b36SAndroid Build Coastguard Worker 1838*333d2b36SAndroid Build Coastguard Worker if module.initCommonAfterDefaultsApplied() { 1839*333d2b36SAndroid Build Coastguard Worker module.CreateInternalModules(ctx) 1840*333d2b36SAndroid Build Coastguard Worker } 1841*333d2b36SAndroid Build Coastguard Worker }) 1842*333d2b36SAndroid Build Coastguard Worker return module 1843*333d2b36SAndroid Build Coastguard Worker} 1844*333d2b36SAndroid Build Coastguard Worker 1845*333d2b36SAndroid Build Coastguard Worker// 1846*333d2b36SAndroid Build Coastguard Worker// SDK library prebuilts 1847*333d2b36SAndroid Build Coastguard Worker// 1848*333d2b36SAndroid Build Coastguard Worker 1849*333d2b36SAndroid Build Coastguard Worker// Properties associated with each api scope. 1850*333d2b36SAndroid Build Coastguard Workertype sdkLibraryScopeProperties struct { 1851*333d2b36SAndroid Build Coastguard Worker Jars []string `android:"path"` 1852*333d2b36SAndroid Build Coastguard Worker 1853*333d2b36SAndroid Build Coastguard Worker Sdk_version *string 1854*333d2b36SAndroid Build Coastguard Worker 1855*333d2b36SAndroid Build Coastguard Worker // List of shared java libs that this module has dependencies to 1856*333d2b36SAndroid Build Coastguard Worker Libs []string 1857*333d2b36SAndroid Build Coastguard Worker 1858*333d2b36SAndroid Build Coastguard Worker // The stubs source. 1859*333d2b36SAndroid Build Coastguard Worker Stub_srcs []string `android:"path"` 1860*333d2b36SAndroid Build Coastguard Worker 1861*333d2b36SAndroid Build Coastguard Worker // The current.txt 1862*333d2b36SAndroid Build Coastguard Worker Current_api *string `android:"path"` 1863*333d2b36SAndroid Build Coastguard Worker 1864*333d2b36SAndroid Build Coastguard Worker // The removed.txt 1865*333d2b36SAndroid Build Coastguard Worker Removed_api *string `android:"path"` 1866*333d2b36SAndroid Build Coastguard Worker 1867*333d2b36SAndroid Build Coastguard Worker // Annotation zip 1868*333d2b36SAndroid Build Coastguard Worker Annotations *string `android:"path"` 1869*333d2b36SAndroid Build Coastguard Worker} 1870*333d2b36SAndroid Build Coastguard Worker 1871*333d2b36SAndroid Build Coastguard Workertype sdkLibraryImportProperties struct { 1872*333d2b36SAndroid Build Coastguard Worker // List of shared java libs, common to all scopes, that this module has 1873*333d2b36SAndroid Build Coastguard Worker // dependencies to 1874*333d2b36SAndroid Build Coastguard Worker Libs []string 1875*333d2b36SAndroid Build Coastguard Worker 1876*333d2b36SAndroid Build Coastguard Worker // If set to true, compile dex files for the stubs. Defaults to false. 1877*333d2b36SAndroid Build Coastguard Worker Compile_dex *bool 1878*333d2b36SAndroid Build Coastguard Worker 1879*333d2b36SAndroid Build Coastguard Worker // If not empty, classes are restricted to the specified packages and their sub-packages. 1880*333d2b36SAndroid Build Coastguard Worker Permitted_packages []string 1881*333d2b36SAndroid Build Coastguard Worker 1882*333d2b36SAndroid Build Coastguard Worker // Name of the source soong module that gets shadowed by this prebuilt 1883*333d2b36SAndroid Build Coastguard Worker // If unspecified, follows the naming convention that the source module of 1884*333d2b36SAndroid Build Coastguard Worker // the prebuilt is Name() without "prebuilt_" prefix 1885*333d2b36SAndroid Build Coastguard Worker Source_module_name *string 1886*333d2b36SAndroid Build Coastguard Worker} 1887*333d2b36SAndroid Build Coastguard Worker 1888*333d2b36SAndroid Build Coastguard Workertype SdkLibraryImport struct { 1889*333d2b36SAndroid Build Coastguard Worker android.ModuleBase 1890*333d2b36SAndroid Build Coastguard Worker android.DefaultableModuleBase 1891*333d2b36SAndroid Build Coastguard Worker prebuilt android.Prebuilt 1892*333d2b36SAndroid Build Coastguard Worker android.ApexModuleBase 1893*333d2b36SAndroid Build Coastguard Worker 1894*333d2b36SAndroid Build Coastguard Worker hiddenAPI 1895*333d2b36SAndroid Build Coastguard Worker dexpreopter 1896*333d2b36SAndroid Build Coastguard Worker 1897*333d2b36SAndroid Build Coastguard Worker properties sdkLibraryImportProperties 1898*333d2b36SAndroid Build Coastguard Worker 1899*333d2b36SAndroid Build Coastguard Worker // Map from api scope to the scope specific property structure. 1900*333d2b36SAndroid Build Coastguard Worker scopeProperties map[*apiScope]*sdkLibraryScopeProperties 1901*333d2b36SAndroid Build Coastguard Worker 1902*333d2b36SAndroid Build Coastguard Worker commonToSdkLibraryAndImport 1903*333d2b36SAndroid Build Coastguard Worker 1904*333d2b36SAndroid Build Coastguard Worker // The reference to the xml permissions module created by the source module. 1905*333d2b36SAndroid Build Coastguard Worker // Is nil if the source module does not exist. 1906*333d2b36SAndroid Build Coastguard Worker xmlPermissionsFileModule *sdkLibraryXml 1907*333d2b36SAndroid Build Coastguard Worker 1908*333d2b36SAndroid Build Coastguard Worker // Build path to the dex implementation jar obtained from the prebuilt_apex, if any. 1909*333d2b36SAndroid Build Coastguard Worker dexJarFile OptionalDexJarPath 1910*333d2b36SAndroid Build Coastguard Worker dexJarFileErr error 1911*333d2b36SAndroid Build Coastguard Worker 1912*333d2b36SAndroid Build Coastguard Worker // Expected install file path of the source module(sdk_library) 1913*333d2b36SAndroid Build Coastguard Worker // or dex implementation jar obtained from the prebuilt_apex, if any. 1914*333d2b36SAndroid Build Coastguard Worker installFile android.Path 1915*333d2b36SAndroid Build Coastguard Worker} 1916*333d2b36SAndroid Build Coastguard Worker 1917*333d2b36SAndroid Build Coastguard Worker// The type of a structure that contains a field of type sdkLibraryScopeProperties 1918*333d2b36SAndroid Build Coastguard Worker// for each apiscope in allApiScopes, e.g. something like: 1919*333d2b36SAndroid Build Coastguard Worker// 1920*333d2b36SAndroid Build Coastguard Worker// struct { 1921*333d2b36SAndroid Build Coastguard Worker// Public sdkLibraryScopeProperties 1922*333d2b36SAndroid Build Coastguard Worker// System sdkLibraryScopeProperties 1923*333d2b36SAndroid Build Coastguard Worker// ... 1924*333d2b36SAndroid Build Coastguard Worker// } 1925*333d2b36SAndroid Build Coastguard Workervar allScopeStructType = createAllScopePropertiesStructType() 1926*333d2b36SAndroid Build Coastguard Worker 1927*333d2b36SAndroid Build Coastguard Worker// Dynamically create a structure type for each apiscope in allApiScopes. 1928*333d2b36SAndroid Build Coastguard Workerfunc createAllScopePropertiesStructType() reflect.Type { 1929*333d2b36SAndroid Build Coastguard Worker var fields []reflect.StructField 1930*333d2b36SAndroid Build Coastguard Worker for _, apiScope := range AllApiScopes { 1931*333d2b36SAndroid Build Coastguard Worker field := reflect.StructField{ 1932*333d2b36SAndroid Build Coastguard Worker Name: apiScope.fieldName, 1933*333d2b36SAndroid Build Coastguard Worker Type: reflect.TypeOf(sdkLibraryScopeProperties{}), 1934*333d2b36SAndroid Build Coastguard Worker } 1935*333d2b36SAndroid Build Coastguard Worker fields = append(fields, field) 1936*333d2b36SAndroid Build Coastguard Worker } 1937*333d2b36SAndroid Build Coastguard Worker 1938*333d2b36SAndroid Build Coastguard Worker return reflect.StructOf(fields) 1939*333d2b36SAndroid Build Coastguard Worker} 1940*333d2b36SAndroid Build Coastguard Worker 1941*333d2b36SAndroid Build Coastguard Worker// Create an instance of the scope specific structure type and return a map 1942*333d2b36SAndroid Build Coastguard Worker// from apiscope to a pointer to each scope specific field. 1943*333d2b36SAndroid Build Coastguard Workerfunc createPropertiesInstance() (interface{}, map[*apiScope]*sdkLibraryScopeProperties) { 1944*333d2b36SAndroid Build Coastguard Worker allScopePropertiesPtr := reflect.New(allScopeStructType) 1945*333d2b36SAndroid Build Coastguard Worker allScopePropertiesStruct := allScopePropertiesPtr.Elem() 1946*333d2b36SAndroid Build Coastguard Worker scopeProperties := make(map[*apiScope]*sdkLibraryScopeProperties) 1947*333d2b36SAndroid Build Coastguard Worker 1948*333d2b36SAndroid Build Coastguard Worker for _, apiScope := range AllApiScopes { 1949*333d2b36SAndroid Build Coastguard Worker field := allScopePropertiesStruct.FieldByName(apiScope.fieldName) 1950*333d2b36SAndroid Build Coastguard Worker scopeProperties[apiScope] = field.Addr().Interface().(*sdkLibraryScopeProperties) 1951*333d2b36SAndroid Build Coastguard Worker } 1952*333d2b36SAndroid Build Coastguard Worker 1953*333d2b36SAndroid Build Coastguard Worker return allScopePropertiesPtr.Interface(), scopeProperties 1954*333d2b36SAndroid Build Coastguard Worker} 1955*333d2b36SAndroid Build Coastguard Worker 1956*333d2b36SAndroid Build Coastguard Worker// java_sdk_library_import imports a prebuilt java_sdk_library. 1957*333d2b36SAndroid Build Coastguard Workerfunc sdkLibraryImportFactory() android.Module { 1958*333d2b36SAndroid Build Coastguard Worker module := &SdkLibraryImport{} 1959*333d2b36SAndroid Build Coastguard Worker 1960*333d2b36SAndroid Build Coastguard Worker allScopeProperties, scopeToProperties := createPropertiesInstance() 1961*333d2b36SAndroid Build Coastguard Worker module.scopeProperties = scopeToProperties 1962*333d2b36SAndroid Build Coastguard Worker module.AddProperties(&module.properties, allScopeProperties, &module.importDexpreoptProperties) 1963*333d2b36SAndroid Build Coastguard Worker 1964*333d2b36SAndroid Build Coastguard Worker // Initialize information common between source and prebuilt. 1965*333d2b36SAndroid Build Coastguard Worker module.initCommon(module) 1966*333d2b36SAndroid Build Coastguard Worker 1967*333d2b36SAndroid Build Coastguard Worker android.InitPrebuiltModule(module, &[]string{""}) 1968*333d2b36SAndroid Build Coastguard Worker android.InitApexModule(module) 1969*333d2b36SAndroid Build Coastguard Worker InitJavaModule(module, android.HostAndDeviceSupported) 1970*333d2b36SAndroid Build Coastguard Worker 1971*333d2b36SAndroid Build Coastguard Worker module.SetDefaultableHook(func(mctx android.DefaultableHookContext) { 1972*333d2b36SAndroid Build Coastguard Worker if module.initCommonAfterDefaultsApplied() { 1973*333d2b36SAndroid Build Coastguard Worker module.createInternalModules(mctx) 1974*333d2b36SAndroid Build Coastguard Worker } 1975*333d2b36SAndroid Build Coastguard Worker }) 1976*333d2b36SAndroid Build Coastguard Worker return module 1977*333d2b36SAndroid Build Coastguard Worker} 1978*333d2b36SAndroid Build Coastguard Worker 1979*333d2b36SAndroid Build Coastguard Workervar _ PermittedPackagesForUpdatableBootJars = (*SdkLibraryImport)(nil) 1980*333d2b36SAndroid Build Coastguard Worker 1981*333d2b36SAndroid Build Coastguard Workerfunc (module *SdkLibraryImport) PermittedPackagesForUpdatableBootJars() []string { 1982*333d2b36SAndroid Build Coastguard Worker return module.properties.Permitted_packages 1983*333d2b36SAndroid Build Coastguard Worker} 1984*333d2b36SAndroid Build Coastguard Worker 1985*333d2b36SAndroid Build Coastguard Workerfunc (module *SdkLibraryImport) Prebuilt() *android.Prebuilt { 1986*333d2b36SAndroid Build Coastguard Worker return &module.prebuilt 1987*333d2b36SAndroid Build Coastguard Worker} 1988*333d2b36SAndroid Build Coastguard Worker 1989*333d2b36SAndroid Build Coastguard Workerfunc (module *SdkLibraryImport) Name() string { 1990*333d2b36SAndroid Build Coastguard Worker return module.prebuilt.Name(module.ModuleBase.Name()) 1991*333d2b36SAndroid Build Coastguard Worker} 1992*333d2b36SAndroid Build Coastguard Worker 1993*333d2b36SAndroid Build Coastguard Workerfunc (module *SdkLibraryImport) BaseModuleName() string { 1994*333d2b36SAndroid Build Coastguard Worker return proptools.StringDefault(module.properties.Source_module_name, module.ModuleBase.Name()) 1995*333d2b36SAndroid Build Coastguard Worker} 1996*333d2b36SAndroid Build Coastguard Worker 1997*333d2b36SAndroid Build Coastguard Workerfunc (module *SdkLibraryImport) createInternalModules(mctx android.DefaultableHookContext) { 1998*333d2b36SAndroid Build Coastguard Worker 1999*333d2b36SAndroid Build Coastguard Worker // If the build is configured to use prebuilts then force this to be preferred. 2000*333d2b36SAndroid Build Coastguard Worker if mctx.Config().AlwaysUsePrebuiltSdks() { 2001*333d2b36SAndroid Build Coastguard Worker module.prebuilt.ForcePrefer() 2002*333d2b36SAndroid Build Coastguard Worker } 2003*333d2b36SAndroid Build Coastguard Worker 2004*333d2b36SAndroid Build Coastguard Worker for apiScope, scopeProperties := range module.scopeProperties { 2005*333d2b36SAndroid Build Coastguard Worker if len(scopeProperties.Jars) == 0 { 2006*333d2b36SAndroid Build Coastguard Worker continue 2007*333d2b36SAndroid Build Coastguard Worker } 2008*333d2b36SAndroid Build Coastguard Worker 2009*333d2b36SAndroid Build Coastguard Worker module.createJavaImportForStubs(mctx, apiScope, scopeProperties) 2010*333d2b36SAndroid Build Coastguard Worker 2011*333d2b36SAndroid Build Coastguard Worker if len(scopeProperties.Stub_srcs) > 0 { 2012*333d2b36SAndroid Build Coastguard Worker module.createPrebuiltStubsSources(mctx, apiScope, scopeProperties) 2013*333d2b36SAndroid Build Coastguard Worker } 2014*333d2b36SAndroid Build Coastguard Worker 2015*333d2b36SAndroid Build Coastguard Worker if scopeProperties.Current_api != nil { 2016*333d2b36SAndroid Build Coastguard Worker module.createPrebuiltApiContribution(mctx, apiScope, scopeProperties) 2017*333d2b36SAndroid Build Coastguard Worker } 2018*333d2b36SAndroid Build Coastguard Worker } 2019*333d2b36SAndroid Build Coastguard Worker 2020*333d2b36SAndroid Build Coastguard Worker javaSdkLibraries := javaSdkLibraries(mctx.Config()) 2021*333d2b36SAndroid Build Coastguard Worker javaSdkLibrariesLock.Lock() 2022*333d2b36SAndroid Build Coastguard Worker defer javaSdkLibrariesLock.Unlock() 2023*333d2b36SAndroid Build Coastguard Worker *javaSdkLibraries = append(*javaSdkLibraries, module.BaseModuleName()) 2024*333d2b36SAndroid Build Coastguard Worker} 2025*333d2b36SAndroid Build Coastguard Worker 2026*333d2b36SAndroid Build Coastguard Worker// Add the dependencies on the child module in the component deps mutator so that it 2027*333d2b36SAndroid Build Coastguard Worker// creates references to the prebuilt and not the source modules. 2028*333d2b36SAndroid Build Coastguard Workerfunc (module *SdkLibraryImport) ComponentDepsMutator(ctx android.BottomUpMutatorContext) { 2029*333d2b36SAndroid Build Coastguard Worker for apiScope, scopeProperties := range module.scopeProperties { 2030*333d2b36SAndroid Build Coastguard Worker if len(scopeProperties.Jars) == 0 { 2031*333d2b36SAndroid Build Coastguard Worker continue 2032*333d2b36SAndroid Build Coastguard Worker } 2033*333d2b36SAndroid Build Coastguard Worker 2034*333d2b36SAndroid Build Coastguard Worker // Add dependencies to the prebuilt stubs library 2035*333d2b36SAndroid Build Coastguard Worker ctx.AddVariationDependencies(nil, apiScope.prebuiltStubsTag, android.PrebuiltNameFromSource(module.stubsLibraryModuleName(apiScope))) 2036*333d2b36SAndroid Build Coastguard Worker 2037*333d2b36SAndroid Build Coastguard Worker if len(scopeProperties.Stub_srcs) > 0 { 2038*333d2b36SAndroid Build Coastguard Worker // Add dependencies to the prebuilt stubs source library 2039*333d2b36SAndroid Build Coastguard Worker ctx.AddVariationDependencies(nil, apiScope.stubsSourceTag, android.PrebuiltNameFromSource(module.droidstubsModuleName(apiScope))) 2040*333d2b36SAndroid Build Coastguard Worker } 2041*333d2b36SAndroid Build Coastguard Worker } 2042*333d2b36SAndroid Build Coastguard Worker} 2043*333d2b36SAndroid Build Coastguard Worker 2044*333d2b36SAndroid Build Coastguard Worker// Add other dependencies as normal. 2045*333d2b36SAndroid Build Coastguard Workerfunc (module *SdkLibraryImport) DepsMutator(ctx android.BottomUpMutatorContext) { 2046*333d2b36SAndroid Build Coastguard Worker 2047*333d2b36SAndroid Build Coastguard Worker implName := module.implLibraryModuleName() 2048*333d2b36SAndroid Build Coastguard Worker if ctx.OtherModuleExists(implName) { 2049*333d2b36SAndroid Build Coastguard Worker ctx.AddVariationDependencies(nil, implLibraryTag, implName) 2050*333d2b36SAndroid Build Coastguard Worker 2051*333d2b36SAndroid Build Coastguard Worker xmlPermissionsModuleName := module.xmlPermissionsModuleName() 2052*333d2b36SAndroid Build Coastguard Worker if module.sharedLibrary() && ctx.OtherModuleExists(xmlPermissionsModuleName) { 2053*333d2b36SAndroid Build Coastguard Worker // Add dependency to the rule for generating the xml permissions file 2054*333d2b36SAndroid Build Coastguard Worker ctx.AddDependency(module, xmlPermissionsFileTag, xmlPermissionsModuleName) 2055*333d2b36SAndroid Build Coastguard Worker } 2056*333d2b36SAndroid Build Coastguard Worker } 2057*333d2b36SAndroid Build Coastguard Worker} 2058*333d2b36SAndroid Build Coastguard Worker 2059*333d2b36SAndroid Build Coastguard Workervar _ android.ApexModule = (*SdkLibraryImport)(nil) 2060*333d2b36SAndroid Build Coastguard Worker 2061*333d2b36SAndroid Build Coastguard Worker// Implements android.ApexModule 2062*333d2b36SAndroid Build Coastguard Workerfunc (module *SdkLibraryImport) DepIsInSameApex(mctx android.BaseModuleContext, dep android.Module) bool { 2063*333d2b36SAndroid Build Coastguard Worker depTag := mctx.OtherModuleDependencyTag(dep) 2064*333d2b36SAndroid Build Coastguard Worker if depTag == xmlPermissionsFileTag { 2065*333d2b36SAndroid Build Coastguard Worker return true 2066*333d2b36SAndroid Build Coastguard Worker } 2067*333d2b36SAndroid Build Coastguard Worker 2068*333d2b36SAndroid Build Coastguard Worker // None of the other dependencies of the java_sdk_library_import are in the same apex 2069*333d2b36SAndroid Build Coastguard Worker // as the one that references this module. 2070*333d2b36SAndroid Build Coastguard Worker return false 2071*333d2b36SAndroid Build Coastguard Worker} 2072*333d2b36SAndroid Build Coastguard Worker 2073*333d2b36SAndroid Build Coastguard Worker// Implements android.ApexModule 2074*333d2b36SAndroid Build Coastguard Workerfunc (module *SdkLibraryImport) ShouldSupportSdkVersion(ctx android.BaseModuleContext, 2075*333d2b36SAndroid Build Coastguard Worker sdkVersion android.ApiLevel) error { 2076*333d2b36SAndroid Build Coastguard Worker // we don't check prebuilt modules for sdk_version 2077*333d2b36SAndroid Build Coastguard Worker return nil 2078*333d2b36SAndroid Build Coastguard Worker} 2079*333d2b36SAndroid Build Coastguard Worker 2080*333d2b36SAndroid Build Coastguard Worker// Implements android.ApexModule 2081*333d2b36SAndroid Build Coastguard Workerfunc (module *SdkLibraryImport) UniqueApexVariations() bool { 2082*333d2b36SAndroid Build Coastguard Worker return module.uniqueApexVariations() 2083*333d2b36SAndroid Build Coastguard Worker} 2084*333d2b36SAndroid Build Coastguard Worker 2085*333d2b36SAndroid Build Coastguard Worker// MinSdkVersion - Implements hiddenAPIModule 2086*333d2b36SAndroid Build Coastguard Workerfunc (module *SdkLibraryImport) MinSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel { 2087*333d2b36SAndroid Build Coastguard Worker return android.NoneApiLevel 2088*333d2b36SAndroid Build Coastguard Worker} 2089*333d2b36SAndroid Build Coastguard Worker 2090*333d2b36SAndroid Build Coastguard Workervar _ hiddenAPIModule = (*SdkLibraryImport)(nil) 2091*333d2b36SAndroid Build Coastguard Worker 2092*333d2b36SAndroid Build Coastguard Workerfunc (module *SdkLibraryImport) GenerateAndroidBuildActions(ctx android.ModuleContext) { 2093*333d2b36SAndroid Build Coastguard Worker // Assume that source module(sdk_library) is installed in /<sdk_library partition>/framework 2094*333d2b36SAndroid Build Coastguard Worker module.installFile = android.PathForModuleInstall(ctx, "framework", module.Stem()+".jar") 2095*333d2b36SAndroid Build Coastguard Worker 2096*333d2b36SAndroid Build Coastguard Worker // Record the paths to the prebuilt stubs library and stubs source. 2097*333d2b36SAndroid Build Coastguard Worker ctx.VisitDirectDeps(func(to android.Module) { 2098*333d2b36SAndroid Build Coastguard Worker tag := ctx.OtherModuleDependencyTag(to) 2099*333d2b36SAndroid Build Coastguard Worker 2100*333d2b36SAndroid Build Coastguard Worker // Extract information from any of the scope specific dependencies. 2101*333d2b36SAndroid Build Coastguard Worker if scopeTag, ok := tag.(scopeDependencyTag); ok { 2102*333d2b36SAndroid Build Coastguard Worker apiScope := scopeTag.apiScope 2103*333d2b36SAndroid Build Coastguard Worker scopePaths := module.getScopePathsCreateIfNeeded(apiScope) 2104*333d2b36SAndroid Build Coastguard Worker 2105*333d2b36SAndroid Build Coastguard Worker // Extract information from the dependency. The exact information extracted 2106*333d2b36SAndroid Build Coastguard Worker // is determined by the nature of the dependency which is determined by the tag. 2107*333d2b36SAndroid Build Coastguard Worker scopeTag.extractDepInfo(ctx, to, scopePaths) 2108*333d2b36SAndroid Build Coastguard Worker } else if tag == implLibraryTag { 2109*333d2b36SAndroid Build Coastguard Worker if implLibrary, ok := to.(*Library); ok { 2110*333d2b36SAndroid Build Coastguard Worker module.implLibraryModule = implLibrary 2111*333d2b36SAndroid Build Coastguard Worker } else { 2112*333d2b36SAndroid Build Coastguard Worker ctx.ModuleErrorf("implementation library must be of type *java.Library but was %T", to) 2113*333d2b36SAndroid Build Coastguard Worker } 2114*333d2b36SAndroid Build Coastguard Worker } else if tag == xmlPermissionsFileTag { 2115*333d2b36SAndroid Build Coastguard Worker if xmlPermissionsFileModule, ok := to.(*sdkLibraryXml); ok { 2116*333d2b36SAndroid Build Coastguard Worker module.xmlPermissionsFileModule = xmlPermissionsFileModule 2117*333d2b36SAndroid Build Coastguard Worker } else { 2118*333d2b36SAndroid Build Coastguard Worker ctx.ModuleErrorf("xml permissions file module must be of type *sdkLibraryXml but was %T", to) 2119*333d2b36SAndroid Build Coastguard Worker } 2120*333d2b36SAndroid Build Coastguard Worker } 2121*333d2b36SAndroid Build Coastguard Worker }) 2122*333d2b36SAndroid Build Coastguard Worker sdkLibInfo := module.generateCommonBuildActions(ctx) 2123*333d2b36SAndroid Build Coastguard Worker 2124*333d2b36SAndroid Build Coastguard Worker // Populate the scope paths with information from the properties. 2125*333d2b36SAndroid Build Coastguard Worker for apiScope, scopeProperties := range module.scopeProperties { 2126*333d2b36SAndroid Build Coastguard Worker if len(scopeProperties.Jars) == 0 { 2127*333d2b36SAndroid Build Coastguard Worker continue 2128*333d2b36SAndroid Build Coastguard Worker } 2129*333d2b36SAndroid Build Coastguard Worker 2130*333d2b36SAndroid Build Coastguard Worker paths := module.getScopePathsCreateIfNeeded(apiScope) 2131*333d2b36SAndroid Build Coastguard Worker paths.annotationsZip = android.OptionalPathForModuleSrc(ctx, scopeProperties.Annotations) 2132*333d2b36SAndroid Build Coastguard Worker paths.currentApiFilePath = android.OptionalPathForModuleSrc(ctx, scopeProperties.Current_api) 2133*333d2b36SAndroid Build Coastguard Worker paths.removedApiFilePath = android.OptionalPathForModuleSrc(ctx, scopeProperties.Removed_api) 2134*333d2b36SAndroid Build Coastguard Worker } 2135*333d2b36SAndroid Build Coastguard Worker 2136*333d2b36SAndroid Build Coastguard Worker if ctx.Device() { 2137*333d2b36SAndroid Build Coastguard Worker // Shared libraries deapexed from prebuilt apexes are no longer supported. 2138*333d2b36SAndroid Build Coastguard Worker // Set the dexJarBuildPath to a fake path. 2139*333d2b36SAndroid Build Coastguard Worker // This allows soong analysis pass, but will be an error during ninja execution if there are 2140*333d2b36SAndroid Build Coastguard Worker // any rdeps. 2141*333d2b36SAndroid Build Coastguard Worker ai, _ := android.ModuleProvider(ctx, android.ApexInfoProvider) 2142*333d2b36SAndroid Build Coastguard Worker if ai.ForPrebuiltApex { 2143*333d2b36SAndroid Build Coastguard Worker module.dexJarFile = makeDexJarPathFromPath(android.PathForModuleInstall(ctx, "intentionally_no_longer_supported")) 2144*333d2b36SAndroid Build Coastguard Worker module.initHiddenAPI(ctx, module.dexJarFile, module.findScopePaths(apiScopePublic).stubsImplPath[0], nil) 2145*333d2b36SAndroid Build Coastguard Worker } 2146*333d2b36SAndroid Build Coastguard Worker } 2147*333d2b36SAndroid Build Coastguard Worker 2148*333d2b36SAndroid Build Coastguard Worker var generatingLibs []string 2149*333d2b36SAndroid Build Coastguard Worker for _, apiScope := range AllApiScopes { 2150*333d2b36SAndroid Build Coastguard Worker if scopeProperties, ok := module.scopeProperties[apiScope]; ok { 2151*333d2b36SAndroid Build Coastguard Worker if len(scopeProperties.Jars) == 0 { 2152*333d2b36SAndroid Build Coastguard Worker continue 2153*333d2b36SAndroid Build Coastguard Worker } 2154*333d2b36SAndroid Build Coastguard Worker generatingLibs = append(generatingLibs, module.stubsLibraryModuleName(apiScope)) 2155*333d2b36SAndroid Build Coastguard Worker } 2156*333d2b36SAndroid Build Coastguard Worker } 2157*333d2b36SAndroid Build Coastguard Worker 2158*333d2b36SAndroid Build Coastguard Worker module.setOutputFiles(ctx) 2159*333d2b36SAndroid Build Coastguard Worker if module.implLibraryModule != nil { 2160*333d2b36SAndroid Build Coastguard Worker generatingLibs = append(generatingLibs, module.implLibraryModuleName()) 2161*333d2b36SAndroid Build Coastguard Worker setOutputFiles(ctx, module.implLibraryModule.Module) 2162*333d2b36SAndroid Build Coastguard Worker } 2163*333d2b36SAndroid Build Coastguard Worker 2164*333d2b36SAndroid Build Coastguard Worker sdkLibInfo.GeneratingLibs = generatingLibs 2165*333d2b36SAndroid Build Coastguard Worker android.SetProvider(ctx, SdkLibraryInfoProvider, sdkLibInfo) 2166*333d2b36SAndroid Build Coastguard Worker} 2167*333d2b36SAndroid Build Coastguard Worker 2168*333d2b36SAndroid Build Coastguard Workervar _ UsesLibraryDependency = (*SdkLibraryImport)(nil) 2169*333d2b36SAndroid Build Coastguard Worker 2170*333d2b36SAndroid Build Coastguard Worker// to satisfy UsesLibraryDependency interface 2171*333d2b36SAndroid Build Coastguard Workerfunc (module *SdkLibraryImport) DexJarBuildPath(ctx android.ModuleErrorfContext) OptionalDexJarPath { 2172*333d2b36SAndroid Build Coastguard Worker // The dex implementation jar extracted from the .apex file should be used in preference to the 2173*333d2b36SAndroid Build Coastguard Worker // source. 2174*333d2b36SAndroid Build Coastguard Worker if module.dexJarFileErr != nil { 2175*333d2b36SAndroid Build Coastguard Worker ctx.ModuleErrorf(module.dexJarFileErr.Error()) 2176*333d2b36SAndroid Build Coastguard Worker } 2177*333d2b36SAndroid Build Coastguard Worker if module.dexJarFile.IsSet() { 2178*333d2b36SAndroid Build Coastguard Worker return module.dexJarFile 2179*333d2b36SAndroid Build Coastguard Worker } 2180*333d2b36SAndroid Build Coastguard Worker if module.implLibraryModule == nil { 2181*333d2b36SAndroid Build Coastguard Worker return makeUnsetDexJarPath() 2182*333d2b36SAndroid Build Coastguard Worker } else { 2183*333d2b36SAndroid Build Coastguard Worker return module.implLibraryModule.DexJarBuildPath(ctx) 2184*333d2b36SAndroid Build Coastguard Worker } 2185*333d2b36SAndroid Build Coastguard Worker} 2186*333d2b36SAndroid Build Coastguard Worker 2187*333d2b36SAndroid Build Coastguard Worker// to satisfy UsesLibraryDependency interface 2188*333d2b36SAndroid Build Coastguard Workerfunc (module *SdkLibraryImport) DexJarInstallPath() android.Path { 2189*333d2b36SAndroid Build Coastguard Worker return module.installFile 2190*333d2b36SAndroid Build Coastguard Worker} 2191*333d2b36SAndroid Build Coastguard Worker 2192*333d2b36SAndroid Build Coastguard Worker// to satisfy UsesLibraryDependency interface 2193*333d2b36SAndroid Build Coastguard Workerfunc (module *SdkLibraryImport) ClassLoaderContexts() dexpreopt.ClassLoaderContextMap { 2194*333d2b36SAndroid Build Coastguard Worker return nil 2195*333d2b36SAndroid Build Coastguard Worker} 2196*333d2b36SAndroid Build Coastguard Worker 2197*333d2b36SAndroid Build Coastguard Worker// to satisfy apex.javaDependency interface 2198*333d2b36SAndroid Build Coastguard Workerfunc (module *SdkLibraryImport) JacocoReportClassesFile() android.Path { 2199*333d2b36SAndroid Build Coastguard Worker if module.implLibraryModule == nil { 2200*333d2b36SAndroid Build Coastguard Worker return nil 2201*333d2b36SAndroid Build Coastguard Worker } else { 2202*333d2b36SAndroid Build Coastguard Worker return module.implLibraryModule.JacocoReportClassesFile() 2203*333d2b36SAndroid Build Coastguard Worker } 2204*333d2b36SAndroid Build Coastguard Worker} 2205*333d2b36SAndroid Build Coastguard Worker 2206*333d2b36SAndroid Build Coastguard Worker// to satisfy apex.javaDependency interface 2207*333d2b36SAndroid Build Coastguard Workerfunc (module *SdkLibraryImport) Stem() string { 2208*333d2b36SAndroid Build Coastguard Worker return module.BaseModuleName() 2209*333d2b36SAndroid Build Coastguard Worker} 2210*333d2b36SAndroid Build Coastguard Worker 2211*333d2b36SAndroid Build Coastguard Workervar _ ApexDependency = (*SdkLibraryImport)(nil) 2212*333d2b36SAndroid Build Coastguard Worker 2213*333d2b36SAndroid Build Coastguard Worker// to satisfy java.ApexDependency interface 2214*333d2b36SAndroid Build Coastguard Workerfunc (module *SdkLibraryImport) HeaderJars() android.Paths { 2215*333d2b36SAndroid Build Coastguard Worker if module.implLibraryModule == nil { 2216*333d2b36SAndroid Build Coastguard Worker return nil 2217*333d2b36SAndroid Build Coastguard Worker } else { 2218*333d2b36SAndroid Build Coastguard Worker return module.implLibraryModule.HeaderJars() 2219*333d2b36SAndroid Build Coastguard Worker } 2220*333d2b36SAndroid Build Coastguard Worker} 2221*333d2b36SAndroid Build Coastguard Worker 2222*333d2b36SAndroid Build Coastguard Worker// to satisfy java.ApexDependency interface 2223*333d2b36SAndroid Build Coastguard Workerfunc (module *SdkLibraryImport) ImplementationAndResourcesJars() android.Paths { 2224*333d2b36SAndroid Build Coastguard Worker if module.implLibraryModule == nil { 2225*333d2b36SAndroid Build Coastguard Worker return nil 2226*333d2b36SAndroid Build Coastguard Worker } else { 2227*333d2b36SAndroid Build Coastguard Worker return module.implLibraryModule.ImplementationAndResourcesJars() 2228*333d2b36SAndroid Build Coastguard Worker } 2229*333d2b36SAndroid Build Coastguard Worker} 2230*333d2b36SAndroid Build Coastguard Worker 2231*333d2b36SAndroid Build Coastguard Worker// to satisfy java.DexpreopterInterface interface 2232*333d2b36SAndroid Build Coastguard Workerfunc (module *SdkLibraryImport) IsInstallable() bool { 2233*333d2b36SAndroid Build Coastguard Worker return true 2234*333d2b36SAndroid Build Coastguard Worker} 2235*333d2b36SAndroid Build Coastguard Worker 2236*333d2b36SAndroid Build Coastguard Workervar _ android.RequiredFilesFromPrebuiltApex = (*SdkLibraryImport)(nil) 2237*333d2b36SAndroid Build Coastguard Worker 2238*333d2b36SAndroid Build Coastguard Workerfunc (module *SdkLibraryImport) RequiredFilesFromPrebuiltApex(ctx android.BaseModuleContext) []string { 2239*333d2b36SAndroid Build Coastguard Worker name := module.BaseModuleName() 2240*333d2b36SAndroid Build Coastguard Worker return requiredFilesFromPrebuiltApexForImport(name, &module.dexpreopter) 2241*333d2b36SAndroid Build Coastguard Worker} 2242*333d2b36SAndroid Build Coastguard Worker 2243*333d2b36SAndroid Build Coastguard Workerfunc (j *SdkLibraryImport) UseProfileGuidedDexpreopt() bool { 2244*333d2b36SAndroid Build Coastguard Worker return proptools.Bool(j.importDexpreoptProperties.Dex_preopt.Profile_guided) 2245*333d2b36SAndroid Build Coastguard Worker} 2246*333d2b36SAndroid Build Coastguard Worker 2247*333d2b36SAndroid Build Coastguard Workertype sdkLibrarySdkMemberType struct { 2248*333d2b36SAndroid Build Coastguard Worker android.SdkMemberTypeBase 2249*333d2b36SAndroid Build Coastguard Worker} 2250*333d2b36SAndroid Build Coastguard Worker 2251*333d2b36SAndroid Build Coastguard Workerfunc (s *sdkLibrarySdkMemberType) AddDependencies(ctx android.SdkDependencyContext, dependencyTag blueprint.DependencyTag, names []string) { 2252*333d2b36SAndroid Build Coastguard Worker ctx.AddVariationDependencies(nil, dependencyTag, names...) 2253*333d2b36SAndroid Build Coastguard Worker} 2254*333d2b36SAndroid Build Coastguard Worker 2255*333d2b36SAndroid Build Coastguard Workerfunc (s *sdkLibrarySdkMemberType) IsInstance(module android.Module) bool { 2256*333d2b36SAndroid Build Coastguard Worker _, ok := module.(*SdkLibrary) 2257*333d2b36SAndroid Build Coastguard Worker return ok 2258*333d2b36SAndroid Build Coastguard Worker} 2259*333d2b36SAndroid Build Coastguard Worker 2260*333d2b36SAndroid Build Coastguard Workerfunc (s *sdkLibrarySdkMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule { 2261*333d2b36SAndroid Build Coastguard Worker return ctx.SnapshotBuilder().AddPrebuiltModule(member, "java_sdk_library_import") 2262*333d2b36SAndroid Build Coastguard Worker} 2263*333d2b36SAndroid Build Coastguard Worker 2264*333d2b36SAndroid Build Coastguard Workerfunc (s *sdkLibrarySdkMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties { 2265*333d2b36SAndroid Build Coastguard Worker return &sdkLibrarySdkMemberProperties{} 2266*333d2b36SAndroid Build Coastguard Worker} 2267*333d2b36SAndroid Build Coastguard Worker 2268*333d2b36SAndroid Build Coastguard Workervar javaSdkLibrarySdkMemberType = &sdkLibrarySdkMemberType{ 2269*333d2b36SAndroid Build Coastguard Worker android.SdkMemberTypeBase{ 2270*333d2b36SAndroid Build Coastguard Worker PropertyName: "java_sdk_libs", 2271*333d2b36SAndroid Build Coastguard Worker SupportsSdk: true, 2272*333d2b36SAndroid Build Coastguard Worker }, 2273*333d2b36SAndroid Build Coastguard Worker} 2274*333d2b36SAndroid Build Coastguard Worker 2275*333d2b36SAndroid Build Coastguard Workertype sdkLibrarySdkMemberProperties struct { 2276*333d2b36SAndroid Build Coastguard Worker android.SdkMemberPropertiesBase 2277*333d2b36SAndroid Build Coastguard Worker 2278*333d2b36SAndroid Build Coastguard Worker // Stem name for files in the sdk snapshot. 2279*333d2b36SAndroid Build Coastguard Worker // 2280*333d2b36SAndroid Build Coastguard Worker // This is used to construct the path names of various sdk library files in the sdk snapshot to 2281*333d2b36SAndroid Build Coastguard Worker // make sure that they match the finalized versions of those files in prebuilts/sdk. 2282*333d2b36SAndroid Build Coastguard Worker // 2283*333d2b36SAndroid Build Coastguard Worker // This property is marked as keep so that it will be kept in all instances of this struct, will 2284*333d2b36SAndroid Build Coastguard Worker // not be cleared but will be copied to common structs. That is needed because this field is used 2285*333d2b36SAndroid Build Coastguard Worker // to construct many file names for other parts of this struct and so it needs to be present in 2286*333d2b36SAndroid Build Coastguard Worker // all structs. If it was not marked as keep then it would be cleared in some structs and so would 2287*333d2b36SAndroid Build Coastguard Worker // be unavailable for generating file names if there were other properties that were still set. 2288*333d2b36SAndroid Build Coastguard Worker Stem string `sdk:"keep"` 2289*333d2b36SAndroid Build Coastguard Worker 2290*333d2b36SAndroid Build Coastguard Worker // Scope to per scope properties. 2291*333d2b36SAndroid Build Coastguard Worker Scopes map[*apiScope]*scopeProperties 2292*333d2b36SAndroid Build Coastguard Worker 2293*333d2b36SAndroid Build Coastguard Worker // The Java stubs source files. 2294*333d2b36SAndroid Build Coastguard Worker Stub_srcs []string 2295*333d2b36SAndroid Build Coastguard Worker 2296*333d2b36SAndroid Build Coastguard Worker // The naming scheme. 2297*333d2b36SAndroid Build Coastguard Worker Naming_scheme *string 2298*333d2b36SAndroid Build Coastguard Worker 2299*333d2b36SAndroid Build Coastguard Worker // True if the java_sdk_library_import is for a shared library, false 2300*333d2b36SAndroid Build Coastguard Worker // otherwise. 2301*333d2b36SAndroid Build Coastguard Worker Shared_library *bool 2302*333d2b36SAndroid Build Coastguard Worker 2303*333d2b36SAndroid Build Coastguard Worker // True if the stub imports should produce dex jars. 2304*333d2b36SAndroid Build Coastguard Worker Compile_dex *bool 2305*333d2b36SAndroid Build Coastguard Worker 2306*333d2b36SAndroid Build Coastguard Worker // The paths to the doctag files to add to the prebuilt. 2307*333d2b36SAndroid Build Coastguard Worker Doctag_paths android.Paths 2308*333d2b36SAndroid Build Coastguard Worker 2309*333d2b36SAndroid Build Coastguard Worker Permitted_packages []string 2310*333d2b36SAndroid Build Coastguard Worker 2311*333d2b36SAndroid Build Coastguard Worker // Signals that this shared library is part of the bootclasspath starting 2312*333d2b36SAndroid Build Coastguard Worker // on the version indicated in this attribute. 2313*333d2b36SAndroid Build Coastguard Worker // 2314*333d2b36SAndroid Build Coastguard Worker // This will make platforms at this level and above to ignore 2315*333d2b36SAndroid Build Coastguard Worker // <uses-library> tags with this library name because the library is already 2316*333d2b36SAndroid Build Coastguard Worker // available 2317*333d2b36SAndroid Build Coastguard Worker On_bootclasspath_since *string 2318*333d2b36SAndroid Build Coastguard Worker 2319*333d2b36SAndroid Build Coastguard Worker // Signals that this shared library was part of the bootclasspath before 2320*333d2b36SAndroid Build Coastguard Worker // (but not including) the version indicated in this attribute. 2321*333d2b36SAndroid Build Coastguard Worker // 2322*333d2b36SAndroid Build Coastguard Worker // The system will automatically add a <uses-library> tag with this library to 2323*333d2b36SAndroid Build Coastguard Worker // apps that target any SDK less than the version indicated in this attribute. 2324*333d2b36SAndroid Build Coastguard Worker On_bootclasspath_before *string 2325*333d2b36SAndroid Build Coastguard Worker 2326*333d2b36SAndroid Build Coastguard Worker // Indicates that PackageManager should ignore this shared library if the 2327*333d2b36SAndroid Build Coastguard Worker // platform is below the version indicated in this attribute. 2328*333d2b36SAndroid Build Coastguard Worker // 2329*333d2b36SAndroid Build Coastguard Worker // This means that the device won't recognise this library as installed. 2330*333d2b36SAndroid Build Coastguard Worker Min_device_sdk *string 2331*333d2b36SAndroid Build Coastguard Worker 2332*333d2b36SAndroid Build Coastguard Worker // Indicates that PackageManager should ignore this shared library if the 2333*333d2b36SAndroid Build Coastguard Worker // platform is above the version indicated in this attribute. 2334*333d2b36SAndroid Build Coastguard Worker // 2335*333d2b36SAndroid Build Coastguard Worker // This means that the device won't recognise this library as installed. 2336*333d2b36SAndroid Build Coastguard Worker Max_device_sdk *string 2337*333d2b36SAndroid Build Coastguard Worker 2338*333d2b36SAndroid Build Coastguard Worker DexPreoptProfileGuided *bool `supported_build_releases:"UpsideDownCake+"` 2339*333d2b36SAndroid Build Coastguard Worker} 2340*333d2b36SAndroid Build Coastguard Worker 2341*333d2b36SAndroid Build Coastguard Workertype scopeProperties struct { 2342*333d2b36SAndroid Build Coastguard Worker Jars android.Paths 2343*333d2b36SAndroid Build Coastguard Worker StubsSrcJar android.Path 2344*333d2b36SAndroid Build Coastguard Worker CurrentApiFile android.Path 2345*333d2b36SAndroid Build Coastguard Worker RemovedApiFile android.Path 2346*333d2b36SAndroid Build Coastguard Worker AnnotationsZip android.Path `supported_build_releases:"Tiramisu+"` 2347*333d2b36SAndroid Build Coastguard Worker SdkVersion string 2348*333d2b36SAndroid Build Coastguard Worker} 2349*333d2b36SAndroid Build Coastguard Worker 2350*333d2b36SAndroid Build Coastguard Workerfunc (s *sdkLibrarySdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) { 2351*333d2b36SAndroid Build Coastguard Worker sdk := variant.(*SdkLibrary) 2352*333d2b36SAndroid Build Coastguard Worker 2353*333d2b36SAndroid Build Coastguard Worker // Copy the stem name for files in the sdk snapshot. 2354*333d2b36SAndroid Build Coastguard Worker s.Stem = sdk.distStem() 2355*333d2b36SAndroid Build Coastguard Worker 2356*333d2b36SAndroid Build Coastguard Worker s.Scopes = make(map[*apiScope]*scopeProperties) 2357*333d2b36SAndroid Build Coastguard Worker for _, apiScope := range AllApiScopes { 2358*333d2b36SAndroid Build Coastguard Worker paths := sdk.findScopePaths(apiScope) 2359*333d2b36SAndroid Build Coastguard Worker if paths == nil { 2360*333d2b36SAndroid Build Coastguard Worker continue 2361*333d2b36SAndroid Build Coastguard Worker } 2362*333d2b36SAndroid Build Coastguard Worker 2363*333d2b36SAndroid Build Coastguard Worker jars := paths.stubsImplPath 2364*333d2b36SAndroid Build Coastguard Worker if len(jars) > 0 { 2365*333d2b36SAndroid Build Coastguard Worker properties := scopeProperties{} 2366*333d2b36SAndroid Build Coastguard Worker properties.Jars = jars 2367*333d2b36SAndroid Build Coastguard Worker properties.SdkVersion = sdk.sdkVersionForStubsLibrary(ctx.SdkModuleContext(), apiScope) 2368*333d2b36SAndroid Build Coastguard Worker properties.StubsSrcJar = paths.stubsSrcJar.Path() 2369*333d2b36SAndroid Build Coastguard Worker if paths.currentApiFilePath.Valid() { 2370*333d2b36SAndroid Build Coastguard Worker properties.CurrentApiFile = paths.currentApiFilePath.Path() 2371*333d2b36SAndroid Build Coastguard Worker } 2372*333d2b36SAndroid Build Coastguard Worker if paths.removedApiFilePath.Valid() { 2373*333d2b36SAndroid Build Coastguard Worker properties.RemovedApiFile = paths.removedApiFilePath.Path() 2374*333d2b36SAndroid Build Coastguard Worker } 2375*333d2b36SAndroid Build Coastguard Worker // The annotations zip is only available for modules that set annotations_enabled: true. 2376*333d2b36SAndroid Build Coastguard Worker if paths.annotationsZip.Valid() { 2377*333d2b36SAndroid Build Coastguard Worker properties.AnnotationsZip = paths.annotationsZip.Path() 2378*333d2b36SAndroid Build Coastguard Worker } 2379*333d2b36SAndroid Build Coastguard Worker s.Scopes[apiScope] = &properties 2380*333d2b36SAndroid Build Coastguard Worker } 2381*333d2b36SAndroid Build Coastguard Worker } 2382*333d2b36SAndroid Build Coastguard Worker 2383*333d2b36SAndroid Build Coastguard Worker s.Shared_library = proptools.BoolPtr(sdk.sharedLibrary()) 2384*333d2b36SAndroid Build Coastguard Worker s.Compile_dex = sdk.dexProperties.Compile_dex 2385*333d2b36SAndroid Build Coastguard Worker s.Doctag_paths = sdk.doctagPaths 2386*333d2b36SAndroid Build Coastguard Worker s.Permitted_packages = sdk.PermittedPackagesForUpdatableBootJars() 2387*333d2b36SAndroid Build Coastguard Worker s.On_bootclasspath_since = sdk.commonSdkLibraryProperties.On_bootclasspath_since 2388*333d2b36SAndroid Build Coastguard Worker s.On_bootclasspath_before = sdk.commonSdkLibraryProperties.On_bootclasspath_before 2389*333d2b36SAndroid Build Coastguard Worker s.Min_device_sdk = sdk.commonSdkLibraryProperties.Min_device_sdk 2390*333d2b36SAndroid Build Coastguard Worker s.Max_device_sdk = sdk.commonSdkLibraryProperties.Max_device_sdk 2391*333d2b36SAndroid Build Coastguard Worker 2392*333d2b36SAndroid Build Coastguard Worker implLibrary := sdk.implLibraryModule 2393*333d2b36SAndroid Build Coastguard Worker if implLibrary != nil && implLibrary.dexpreopter.dexpreoptProperties.Dex_preopt_result.Profile_guided { 2394*333d2b36SAndroid Build Coastguard Worker s.DexPreoptProfileGuided = proptools.BoolPtr(true) 2395*333d2b36SAndroid Build Coastguard Worker } 2396*333d2b36SAndroid Build Coastguard Worker} 2397*333d2b36SAndroid Build Coastguard Worker 2398*333d2b36SAndroid Build Coastguard Workerfunc (s *sdkLibrarySdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) { 2399*333d2b36SAndroid Build Coastguard Worker if s.Naming_scheme != nil { 2400*333d2b36SAndroid Build Coastguard Worker propertySet.AddProperty("naming_scheme", proptools.String(s.Naming_scheme)) 2401*333d2b36SAndroid Build Coastguard Worker } 2402*333d2b36SAndroid Build Coastguard Worker if s.Shared_library != nil { 2403*333d2b36SAndroid Build Coastguard Worker propertySet.AddProperty("shared_library", *s.Shared_library) 2404*333d2b36SAndroid Build Coastguard Worker } 2405*333d2b36SAndroid Build Coastguard Worker if s.Compile_dex != nil { 2406*333d2b36SAndroid Build Coastguard Worker propertySet.AddProperty("compile_dex", *s.Compile_dex) 2407*333d2b36SAndroid Build Coastguard Worker } 2408*333d2b36SAndroid Build Coastguard Worker if len(s.Permitted_packages) > 0 { 2409*333d2b36SAndroid Build Coastguard Worker propertySet.AddProperty("permitted_packages", s.Permitted_packages) 2410*333d2b36SAndroid Build Coastguard Worker } 2411*333d2b36SAndroid Build Coastguard Worker dexPreoptSet := propertySet.AddPropertySet("dex_preopt") 2412*333d2b36SAndroid Build Coastguard Worker if s.DexPreoptProfileGuided != nil { 2413*333d2b36SAndroid Build Coastguard Worker dexPreoptSet.AddProperty("profile_guided", proptools.Bool(s.DexPreoptProfileGuided)) 2414*333d2b36SAndroid Build Coastguard Worker } 2415*333d2b36SAndroid Build Coastguard Worker 2416*333d2b36SAndroid Build Coastguard Worker stem := s.Stem 2417*333d2b36SAndroid Build Coastguard Worker 2418*333d2b36SAndroid Build Coastguard Worker for _, apiScope := range AllApiScopes { 2419*333d2b36SAndroid Build Coastguard Worker if properties, ok := s.Scopes[apiScope]; ok { 2420*333d2b36SAndroid Build Coastguard Worker scopeSet := propertySet.AddPropertySet(apiScope.propertyName) 2421*333d2b36SAndroid Build Coastguard Worker 2422*333d2b36SAndroid Build Coastguard Worker scopeDir := apiScope.snapshotRelativeDir() 2423*333d2b36SAndroid Build Coastguard Worker 2424*333d2b36SAndroid Build Coastguard Worker var jars []string 2425*333d2b36SAndroid Build Coastguard Worker for _, p := range properties.Jars { 2426*333d2b36SAndroid Build Coastguard Worker dest := filepath.Join(scopeDir, stem+"-stubs.jar") 2427*333d2b36SAndroid Build Coastguard Worker ctx.SnapshotBuilder().CopyToSnapshot(p, dest) 2428*333d2b36SAndroid Build Coastguard Worker jars = append(jars, dest) 2429*333d2b36SAndroid Build Coastguard Worker } 2430*333d2b36SAndroid Build Coastguard Worker scopeSet.AddProperty("jars", jars) 2431*333d2b36SAndroid Build Coastguard Worker 2432*333d2b36SAndroid Build Coastguard Worker if ctx.SdkModuleContext().Config().IsEnvTrue("SOONG_SDK_SNAPSHOT_USE_SRCJAR") { 2433*333d2b36SAndroid Build Coastguard Worker // Copy the stubs source jar into the snapshot zip as is. 2434*333d2b36SAndroid Build Coastguard Worker srcJarSnapshotPath := filepath.Join(scopeDir, stem+".srcjar") 2435*333d2b36SAndroid Build Coastguard Worker ctx.SnapshotBuilder().CopyToSnapshot(properties.StubsSrcJar, srcJarSnapshotPath) 2436*333d2b36SAndroid Build Coastguard Worker scopeSet.AddProperty("stub_srcs", []string{srcJarSnapshotPath}) 2437*333d2b36SAndroid Build Coastguard Worker } else { 2438*333d2b36SAndroid Build Coastguard Worker // Merge the stubs source jar into the snapshot zip so that when it is unpacked 2439*333d2b36SAndroid Build Coastguard Worker // the source files are also unpacked. 2440*333d2b36SAndroid Build Coastguard Worker snapshotRelativeDir := filepath.Join(scopeDir, stem+"_stub_sources") 2441*333d2b36SAndroid Build Coastguard Worker ctx.SnapshotBuilder().UnzipToSnapshot(properties.StubsSrcJar, snapshotRelativeDir) 2442*333d2b36SAndroid Build Coastguard Worker scopeSet.AddProperty("stub_srcs", []string{snapshotRelativeDir}) 2443*333d2b36SAndroid Build Coastguard Worker } 2444*333d2b36SAndroid Build Coastguard Worker 2445*333d2b36SAndroid Build Coastguard Worker if properties.CurrentApiFile != nil { 2446*333d2b36SAndroid Build Coastguard Worker currentApiSnapshotPath := apiScope.snapshotRelativeCurrentApiTxtPath(stem) 2447*333d2b36SAndroid Build Coastguard Worker ctx.SnapshotBuilder().CopyToSnapshot(properties.CurrentApiFile, currentApiSnapshotPath) 2448*333d2b36SAndroid Build Coastguard Worker scopeSet.AddProperty("current_api", currentApiSnapshotPath) 2449*333d2b36SAndroid Build Coastguard Worker } 2450*333d2b36SAndroid Build Coastguard Worker 2451*333d2b36SAndroid Build Coastguard Worker if properties.RemovedApiFile != nil { 2452*333d2b36SAndroid Build Coastguard Worker removedApiSnapshotPath := apiScope.snapshotRelativeRemovedApiTxtPath(stem) 2453*333d2b36SAndroid Build Coastguard Worker ctx.SnapshotBuilder().CopyToSnapshot(properties.RemovedApiFile, removedApiSnapshotPath) 2454*333d2b36SAndroid Build Coastguard Worker scopeSet.AddProperty("removed_api", removedApiSnapshotPath) 2455*333d2b36SAndroid Build Coastguard Worker } 2456*333d2b36SAndroid Build Coastguard Worker 2457*333d2b36SAndroid Build Coastguard Worker if properties.AnnotationsZip != nil { 2458*333d2b36SAndroid Build Coastguard Worker annotationsSnapshotPath := filepath.Join(scopeDir, stem+"_annotations.zip") 2459*333d2b36SAndroid Build Coastguard Worker ctx.SnapshotBuilder().CopyToSnapshot(properties.AnnotationsZip, annotationsSnapshotPath) 2460*333d2b36SAndroid Build Coastguard Worker scopeSet.AddProperty("annotations", annotationsSnapshotPath) 2461*333d2b36SAndroid Build Coastguard Worker } 2462*333d2b36SAndroid Build Coastguard Worker 2463*333d2b36SAndroid Build Coastguard Worker if properties.SdkVersion != "" { 2464*333d2b36SAndroid Build Coastguard Worker scopeSet.AddProperty("sdk_version", properties.SdkVersion) 2465*333d2b36SAndroid Build Coastguard Worker } 2466*333d2b36SAndroid Build Coastguard Worker } 2467*333d2b36SAndroid Build Coastguard Worker } 2468*333d2b36SAndroid Build Coastguard Worker 2469*333d2b36SAndroid Build Coastguard Worker if len(s.Doctag_paths) > 0 { 2470*333d2b36SAndroid Build Coastguard Worker dests := []string{} 2471*333d2b36SAndroid Build Coastguard Worker for _, p := range s.Doctag_paths { 2472*333d2b36SAndroid Build Coastguard Worker dest := filepath.Join("doctags", p.Rel()) 2473*333d2b36SAndroid Build Coastguard Worker ctx.SnapshotBuilder().CopyToSnapshot(p, dest) 2474*333d2b36SAndroid Build Coastguard Worker dests = append(dests, dest) 2475*333d2b36SAndroid Build Coastguard Worker } 2476*333d2b36SAndroid Build Coastguard Worker propertySet.AddProperty("doctag_files", dests) 2477*333d2b36SAndroid Build Coastguard Worker } 2478*333d2b36SAndroid Build Coastguard Worker} 2479