| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1 | // Copyright 2018 Google Inc. All rights reserved. | 
 | 2 | // | 
 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); | 
 | 4 | // you may not use this file except in compliance with the License. | 
 | 5 | // You may obtain a copy of the License at | 
 | 6 | // | 
 | 7 | //     http://www.apache.org/licenses/LICENSE-2.0 | 
 | 8 | // | 
 | 9 | // Unless required by applicable law or agreed to in writing, software | 
 | 10 | // distributed under the License is distributed on an "AS IS" BASIS, | 
 | 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
 | 12 | // See the License for the specific language governing permissions and | 
 | 13 | // limitations under the License. | 
 | 14 |  | 
 | 15 | package java | 
 | 16 |  | 
 | 17 | import ( | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 18 | 	"fmt" | 
 | 19 | 	"path" | 
| Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 20 | 	"path/filepath" | 
| Paul Duffin | 46a26a8 | 2020-04-07 19:27:04 +0100 | [diff] [blame] | 21 | 	"reflect" | 
| Paul Duffin | 46dc45a | 2020-05-14 15:39:10 +0100 | [diff] [blame] | 22 | 	"regexp" | 
| Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 23 | 	"sort" | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 24 | 	"strings" | 
| Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 25 | 	"sync" | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 26 |  | 
| Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 27 | 	"github.com/google/blueprint" | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 28 | 	"github.com/google/blueprint/proptools" | 
| Paul Duffin | 46a26a8 | 2020-04-07 19:27:04 +0100 | [diff] [blame] | 29 |  | 
 | 30 | 	"android/soong/android" | 
| Ulya Trafimovich | dbf3166 | 2020-12-17 12:07:54 +0000 | [diff] [blame] | 31 | 	"android/soong/dexpreopt" | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 32 | ) | 
 | 33 |  | 
| Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 34 | const ( | 
| Pedro Loureiro | 9956e5e | 2021-09-07 17:21:59 +0000 | [diff] [blame] | 35 | 	sdkXmlFileSuffix = ".xml" | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 36 | ) | 
 | 37 |  | 
| Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 38 | // A tag to associated a dependency with a specific api scope. | 
 | 39 | type scopeDependencyTag struct { | 
 | 40 | 	blueprint.BaseDependencyTag | 
 | 41 | 	name     string | 
 | 42 | 	apiScope *apiScope | 
| Paul Duffin | c878250 | 2020-04-29 20:45:27 +0100 | [diff] [blame] | 43 |  | 
 | 44 | 	// Function for extracting appropriate path information from the dependency. | 
| Colin Cross | dcf71b2 | 2021-02-01 13:59:03 -0800 | [diff] [blame] | 45 | 	depInfoExtractor func(paths *scopePaths, ctx android.ModuleContext, dep android.Module) error | 
| Paul Duffin | c878250 | 2020-04-29 20:45:27 +0100 | [diff] [blame] | 46 | } | 
 | 47 |  | 
 | 48 | // Extract tag specific information from the dependency. | 
 | 49 | func (tag scopeDependencyTag) extractDepInfo(ctx android.ModuleContext, dep android.Module, paths *scopePaths) { | 
| Colin Cross | dcf71b2 | 2021-02-01 13:59:03 -0800 | [diff] [blame] | 50 | 	err := tag.depInfoExtractor(paths, ctx, dep) | 
| Paul Duffin | c878250 | 2020-04-29 20:45:27 +0100 | [diff] [blame] | 51 | 	if err != nil { | 
 | 52 | 		ctx.ModuleErrorf("has an invalid {scopeDependencyTag: %s} dependency on module %s: %s", tag.name, ctx.OtherModuleName(dep), err.Error()) | 
 | 53 | 	} | 
| Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 54 | } | 
 | 55 |  | 
| Paul Duffin | 80342d7 | 2020-06-26 22:08:43 +0100 | [diff] [blame] | 56 | var _ android.ReplaceSourceWithPrebuilt = (*scopeDependencyTag)(nil) | 
 | 57 |  | 
 | 58 | func (tag scopeDependencyTag) ReplaceSourceWithPrebuilt() bool { | 
 | 59 | 	return false | 
 | 60 | } | 
 | 61 |  | 
| Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 62 | // Provides information about an api scope, e.g. public, system, test. | 
 | 63 | type apiScope struct { | 
 | 64 | 	// The name of the api scope, e.g. public, system, test | 
 | 65 | 	name string | 
 | 66 |  | 
| Paul Duffin | 97b53b8 | 2020-05-05 14:40:52 +0100 | [diff] [blame] | 67 | 	// The api scope that this scope extends. | 
| Paul Duffin | d0b9fca | 2022-09-30 18:11:41 +0100 | [diff] [blame] | 68 | 	// | 
 | 69 | 	// This organizes the scopes into an extension hierarchy. | 
 | 70 | 	// | 
 | 71 | 	// If set this means that the API provided by this scope includes the API provided by the scope | 
 | 72 | 	// set in this field. | 
| Paul Duffin | 97b53b8 | 2020-05-05 14:40:52 +0100 | [diff] [blame] | 73 | 	extends *apiScope | 
 | 74 |  | 
| Paul Duffin | d0b9fca | 2022-09-30 18:11:41 +0100 | [diff] [blame] | 75 | 	// The next api scope that a library that uses this scope can access. | 
 | 76 | 	// | 
 | 77 | 	// This organizes the scopes into an access hierarchy. | 
 | 78 | 	// | 
 | 79 | 	// If set this means that a library that can access this API can also access the API provided by | 
 | 80 | 	// the scope set in this field. | 
 | 81 | 	// | 
 | 82 | 	// A module that sets sdk_version: "<scope>_current" should have access to the <scope> API of | 
 | 83 | 	// every java_sdk_library that it depends on. If the library does not provide an API for <scope> | 
 | 84 | 	// then it will traverse up this access hierarchy to find an API that it does provide. | 
 | 85 | 	// | 
 | 86 | 	// If this is not set then it defaults to the scope set in extends. | 
 | 87 | 	canAccess *apiScope | 
 | 88 |  | 
| Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 89 | 	// The legacy enabled status for a specific scope can be dependent on other | 
 | 90 | 	// properties that have been specified on the library so it is provided by | 
 | 91 | 	// a function that can determine the status by examining those properties. | 
 | 92 | 	legacyEnabledStatus func(module *SdkLibrary) bool | 
 | 93 |  | 
 | 94 | 	// The default enabled status for non-legacy behavior, which is triggered by | 
 | 95 | 	// explicitly enabling at least one api scope. | 
 | 96 | 	defaultEnabledStatus bool | 
 | 97 |  | 
 | 98 | 	// Gets a pointer to the scope specific properties. | 
 | 99 | 	scopeSpecificProperties func(module *SdkLibrary) *ApiScopeProperties | 
 | 100 |  | 
| Paul Duffin | 46a26a8 | 2020-04-07 19:27:04 +0100 | [diff] [blame] | 101 | 	// The name of the field in the dynamically created structure. | 
 | 102 | 	fieldName string | 
 | 103 |  | 
| Paul Duffin | 6b836ba | 2020-05-13 19:19:49 +0100 | [diff] [blame] | 104 | 	// The name of the property in the java_sdk_library_import | 
 | 105 | 	propertyName string | 
 | 106 |  | 
| Jihoon Kang | bd09345 | 2023-12-26 19:08:01 +0000 | [diff] [blame] | 107 | 	// The tag to use to depend on the stubs library module if the parent module | 
 | 108 | 	// does not differentiate everything and exportable stubs (e.g. sdk_library_import). | 
| Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 109 | 	stubsTag scopeDependencyTag | 
 | 110 |  | 
| Jihoon Kang | bd09345 | 2023-12-26 19:08:01 +0000 | [diff] [blame] | 111 | 	// The tag to use to depend on the everything stubs library module. | 
 | 112 | 	everythingStubsTag scopeDependencyTag | 
 | 113 |  | 
 | 114 | 	// The tag to use to depend on the exportable stubs library module. | 
 | 115 | 	exportableStubsTag scopeDependencyTag | 
 | 116 |  | 
| Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 117 | 	// The tag to use to depend on the stubs source module (if separate from the API module). | 
 | 118 | 	stubsSourceTag scopeDependencyTag | 
 | 119 |  | 
 | 120 | 	// The tag to use to depend on the API file generating module (if separate from the stubs source module). | 
 | 121 | 	apiFileTag scopeDependencyTag | 
 | 122 |  | 
| Paul Duffin | c878250 | 2020-04-29 20:45:27 +0100 | [diff] [blame] | 123 | 	// The tag to use to depend on the stubs source and API module. | 
 | 124 | 	stubsSourceAndApiTag scopeDependencyTag | 
| Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 125 |  | 
| Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 126 | 	// The tag to use to depend on the module that provides the latest version of the API .txt file. | 
 | 127 | 	latestApiModuleTag scopeDependencyTag | 
 | 128 |  | 
 | 129 | 	// The tag to use to depend on the module that provides the latest version of the API removed.txt | 
 | 130 | 	// file. | 
 | 131 | 	latestRemovedApiModuleTag scopeDependencyTag | 
 | 132 |  | 
| Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 133 | 	// The scope specific prefix to add to the api file base of "current.txt" or "removed.txt". | 
 | 134 | 	apiFilePrefix string | 
 | 135 |  | 
| Paul Duffin | d0b9fca | 2022-09-30 18:11:41 +0100 | [diff] [blame] | 136 | 	// The scope specific suffix to add to the sdk library module name to construct a scope specific | 
| Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 137 | 	// module name. | 
 | 138 | 	moduleSuffix string | 
 | 139 |  | 
| Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 140 | 	// SDK version that the stubs library is built against. Note that this is always | 
 | 141 | 	// *current. Older stubs library built with a numbered SDK version is created from | 
 | 142 | 	// the prebuilt jar. | 
 | 143 | 	sdkVersion string | 
| Paul Duffin | 1fb487d | 2020-04-07 18:50:10 +0100 | [diff] [blame] | 144 |  | 
| Paul Duffin | 15f34ef | 2020-07-20 18:04:44 +0100 | [diff] [blame] | 145 | 	// The annotation that identifies this API level, empty for the public API scope. | 
 | 146 | 	annotation string | 
 | 147 |  | 
| Paul Duffin | 1fb487d | 2020-04-07 18:50:10 +0100 | [diff] [blame] | 148 | 	// Extra arguments to pass to droidstubs for this scope. | 
| Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 149 | 	// | 
| Paul Duffin | 15f34ef | 2020-07-20 18:04:44 +0100 | [diff] [blame] | 150 | 	// This is not used directly but is used to construct the droidstubsArgs. | 
 | 151 | 	extraArgs []string | 
| Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 152 |  | 
| Paul Duffin | 15f34ef | 2020-07-20 18:04:44 +0100 | [diff] [blame] | 153 | 	// The args that must be passed to droidstubs to generate the API and stubs source | 
 | 154 | 	// for this scope, constructed dynamically by initApiScope(). | 
| Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 155 | 	// | 
 | 156 | 	// The API only includes the additional members that this scope adds over the scope | 
 | 157 | 	// that it extends. | 
| Paul Duffin | 15f34ef | 2020-07-20 18:04:44 +0100 | [diff] [blame] | 158 | 	// | 
 | 159 | 	// The stubs source must include the definitions of everything that is in this | 
 | 160 | 	// api scope and all the scopes that this one extends. | 
 | 161 | 	droidstubsArgs []string | 
| Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 162 |  | 
| Anton Hansson | 6478ac1 | 2020-05-02 11:19:36 +0100 | [diff] [blame] | 163 | 	// Whether the api scope can be treated as unstable, and should skip compat checks. | 
 | 164 | 	unstable bool | 
| Jihoon Kang | 1c92c3e | 2023-03-23 17:44:51 +0000 | [diff] [blame] | 165 |  | 
 | 166 | 	// Represents the SDK kind of this scope. | 
 | 167 | 	kind android.SdkKind | 
| Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 168 | } | 
 | 169 |  | 
 | 170 | // Initialize a scope, creating and adding appropriate dependency tags | 
 | 171 | func initApiScope(scope *apiScope) *apiScope { | 
| Paul Duffin | c878250 | 2020-04-29 20:45:27 +0100 | [diff] [blame] | 172 | 	name := scope.name | 
| Paul Duffin | 46dc45a | 2020-05-14 15:39:10 +0100 | [diff] [blame] | 173 | 	scopeByName[name] = scope | 
 | 174 | 	allScopeNames = append(allScopeNames, name) | 
| Paul Duffin | 6b836ba | 2020-05-13 19:19:49 +0100 | [diff] [blame] | 175 | 	scope.propertyName = strings.ReplaceAll(name, "-", "_") | 
 | 176 | 	scope.fieldName = proptools.FieldNameForProperty(scope.propertyName) | 
| Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 177 | 	scope.stubsTag = scopeDependencyTag{ | 
| Paul Duffin | c878250 | 2020-04-29 20:45:27 +0100 | [diff] [blame] | 178 | 		name:             name + "-stubs", | 
 | 179 | 		apiScope:         scope, | 
 | 180 | 		depInfoExtractor: (*scopePaths).extractStubsLibraryInfoFromDependency, | 
| Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 181 | 	} | 
| Jihoon Kang | bd09345 | 2023-12-26 19:08:01 +0000 | [diff] [blame] | 182 | 	scope.everythingStubsTag = scopeDependencyTag{ | 
 | 183 | 		name:             name + "-stubs-everything", | 
 | 184 | 		apiScope:         scope, | 
 | 185 | 		depInfoExtractor: (*scopePaths).extractEverythingStubsLibraryInfoFromDependency, | 
 | 186 | 	} | 
 | 187 | 	scope.exportableStubsTag = scopeDependencyTag{ | 
 | 188 | 		name:             name + "-stubs-exportable", | 
 | 189 | 		apiScope:         scope, | 
 | 190 | 		depInfoExtractor: (*scopePaths).extractExportableStubsLibraryInfoFromDependency, | 
 | 191 | 	} | 
| Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 192 | 	scope.stubsSourceTag = scopeDependencyTag{ | 
 | 193 | 		name:             name + "-stubs-source", | 
 | 194 | 		apiScope:         scope, | 
 | 195 | 		depInfoExtractor: (*scopePaths).extractStubsSourceInfoFromDep, | 
 | 196 | 	} | 
 | 197 | 	scope.apiFileTag = scopeDependencyTag{ | 
 | 198 | 		name:             name + "-api", | 
 | 199 | 		apiScope:         scope, | 
 | 200 | 		depInfoExtractor: (*scopePaths).extractApiInfoFromDep, | 
 | 201 | 	} | 
| Paul Duffin | c878250 | 2020-04-29 20:45:27 +0100 | [diff] [blame] | 202 | 	scope.stubsSourceAndApiTag = scopeDependencyTag{ | 
 | 203 | 		name:             name + "-stubs-source-and-api", | 
 | 204 | 		apiScope:         scope, | 
 | 205 | 		depInfoExtractor: (*scopePaths).extractStubsSourceAndApiInfoFromApiStubsProvider, | 
| Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 206 | 	} | 
| Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 207 | 	scope.latestApiModuleTag = scopeDependencyTag{ | 
 | 208 | 		name:             name + "-latest-api", | 
 | 209 | 		apiScope:         scope, | 
 | 210 | 		depInfoExtractor: (*scopePaths).extractLatestApiPath, | 
 | 211 | 	} | 
 | 212 | 	scope.latestRemovedApiModuleTag = scopeDependencyTag{ | 
 | 213 | 		name:             name + "-latest-removed-api", | 
 | 214 | 		apiScope:         scope, | 
 | 215 | 		depInfoExtractor: (*scopePaths).extractLatestRemovedApiPath, | 
 | 216 | 	} | 
| Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 217 |  | 
 | 218 | 	// To get the args needed to generate the stubs source append all the args from | 
 | 219 | 	// this scope and all the scopes it extends as each set of args adds additional | 
 | 220 | 	// members to the stubs. | 
| Paul Duffin | 15f34ef | 2020-07-20 18:04:44 +0100 | [diff] [blame] | 221 | 	var scopeSpecificArgs []string | 
 | 222 | 	if scope.annotation != "" { | 
 | 223 | 		scopeSpecificArgs = []string{"--show-annotation", scope.annotation} | 
| Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 224 | 	} | 
| Paul Duffin | 15f34ef | 2020-07-20 18:04:44 +0100 | [diff] [blame] | 225 | 	for s := scope; s != nil; s = s.extends { | 
 | 226 | 		scopeSpecificArgs = append(scopeSpecificArgs, s.extraArgs...) | 
| Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 227 |  | 
| Paul Duffin | 15f34ef | 2020-07-20 18:04:44 +0100 | [diff] [blame] | 228 | 		// Ensure that the generated stubs includes all the API elements from the API scope | 
 | 229 | 		// that this scope extends. | 
 | 230 | 		if s != scope && s.annotation != "" { | 
 | 231 | 			scopeSpecificArgs = append(scopeSpecificArgs, "--show-for-stub-purposes-annotation", s.annotation) | 
 | 232 | 		} | 
 | 233 | 	} | 
| Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 234 |  | 
| Paul Duffin | d0b9fca | 2022-09-30 18:11:41 +0100 | [diff] [blame] | 235 | 	// By default, a library that can access a scope can also access the scope it extends. | 
 | 236 | 	if scope.canAccess == nil { | 
 | 237 | 		scope.canAccess = scope.extends | 
 | 238 | 	} | 
 | 239 |  | 
| Paul Duffin | 15f34ef | 2020-07-20 18:04:44 +0100 | [diff] [blame] | 240 | 	// Escape any special characters in the arguments. This is needed because droidstubs | 
 | 241 | 	// passes these directly to the shell command. | 
 | 242 | 	scope.droidstubsArgs = proptools.ShellEscapeList(scopeSpecificArgs) | 
| Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 243 |  | 
| Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 244 | 	return scope | 
 | 245 | } | 
 | 246 |  | 
| Anton Hansson | 08f476b | 2021-04-07 15:32:19 +0100 | [diff] [blame] | 247 | func (scope *apiScope) stubsLibraryModuleNameSuffix() string { | 
 | 248 | 	return ".stubs" + scope.moduleSuffix | 
 | 249 | } | 
 | 250 |  | 
| Jihoon Kang | fa4a90d | 2023-12-20 02:53:38 +0000 | [diff] [blame] | 251 | func (scope *apiScope) exportableStubsLibraryModuleNameSuffix() string { | 
 | 252 | 	return ".stubs.exportable" + scope.moduleSuffix | 
 | 253 | } | 
 | 254 |  | 
| Jihoon Kang | 1c92c3e | 2023-03-23 17:44:51 +0000 | [diff] [blame] | 255 | func (scope *apiScope) apiLibraryModuleName(baseName string) string { | 
 | 256 | 	return scope.stubsLibraryModuleName(baseName) + ".from-text" | 
 | 257 | } | 
 | 258 |  | 
| Jihoon Kang | 1147b31 | 2023-06-08 23:25:57 +0000 | [diff] [blame] | 259 | func (scope *apiScope) sourceStubLibraryModuleName(baseName string) string { | 
 | 260 | 	return scope.stubsLibraryModuleName(baseName) + ".from-source" | 
 | 261 | } | 
 | 262 |  | 
| Jihoon Kang | fa4a90d | 2023-12-20 02:53:38 +0000 | [diff] [blame] | 263 | func (scope *apiScope) exportableSourceStubsLibraryModuleName(baseName string) string { | 
 | 264 | 	return scope.exportableStubsLibraryModuleName(baseName) + ".from-source" | 
 | 265 | } | 
 | 266 |  | 
| Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame] | 267 | func (scope *apiScope) stubsLibraryModuleName(baseName string) string { | 
| Anton Hansson | 08f476b | 2021-04-07 15:32:19 +0100 | [diff] [blame] | 268 | 	return baseName + scope.stubsLibraryModuleNameSuffix() | 
| Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 269 | } | 
 | 270 |  | 
| Jihoon Kang | fa4a90d | 2023-12-20 02:53:38 +0000 | [diff] [blame] | 271 | func (scope *apiScope) exportableStubsLibraryModuleName(baseName string) string { | 
 | 272 | 	return baseName + scope.exportableStubsLibraryModuleNameSuffix() | 
 | 273 | } | 
 | 274 |  | 
| Paul Duffin | c878250 | 2020-04-29 20:45:27 +0100 | [diff] [blame] | 275 | func (scope *apiScope) stubsSourceModuleName(baseName string) string { | 
| Paul Duffin | dd9d074 | 2020-05-08 15:52:37 +0100 | [diff] [blame] | 276 | 	return baseName + ".stubs.source" + scope.moduleSuffix | 
| Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 277 | } | 
 | 278 |  | 
| Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 279 | func (scope *apiScope) apiModuleName(baseName string) string { | 
| Paul Duffin | dd9d074 | 2020-05-08 15:52:37 +0100 | [diff] [blame] | 280 | 	return baseName + ".api" + scope.moduleSuffix | 
| Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 281 | } | 
 | 282 |  | 
| Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 283 | func (scope *apiScope) String() string { | 
 | 284 | 	return scope.name | 
 | 285 | } | 
 | 286 |  | 
| Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 287 | // snapshotRelativeDir returns the snapshot directory into which the files related to scopes will | 
 | 288 | // be stored. | 
 | 289 | func (scope *apiScope) snapshotRelativeDir() string { | 
 | 290 | 	return filepath.Join("sdk_library", scope.name) | 
 | 291 | } | 
 | 292 |  | 
 | 293 | // snapshotRelativeCurrentApiTxtPath returns the snapshot path to the API .txt file for the named | 
 | 294 | // library. | 
 | 295 | func (scope *apiScope) snapshotRelativeCurrentApiTxtPath(name string) string { | 
 | 296 | 	return filepath.Join(scope.snapshotRelativeDir(), name+".txt") | 
 | 297 | } | 
 | 298 |  | 
 | 299 | // snapshotRelativeRemovedApiTxtPath returns the snapshot path to the removed API .txt file for the | 
 | 300 | // named library. | 
 | 301 | func (scope *apiScope) snapshotRelativeRemovedApiTxtPath(name string) string { | 
 | 302 | 	return filepath.Join(scope.snapshotRelativeDir(), name+"-removed.txt") | 
 | 303 | } | 
 | 304 |  | 
| Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 305 | type apiScopes []*apiScope | 
 | 306 |  | 
 | 307 | func (scopes apiScopes) Strings(accessor func(*apiScope) string) []string { | 
 | 308 | 	var list []string | 
 | 309 | 	for _, scope := range scopes { | 
 | 310 | 		list = append(list, accessor(scope)) | 
 | 311 | 	} | 
 | 312 | 	return list | 
 | 313 | } | 
 | 314 |  | 
| Jihoon Kang | a96a7b1 | 2023-09-20 23:43:32 +0000 | [diff] [blame] | 315 | // Method that maps the apiScopes properties to the index of each apiScopes elements. | 
 | 316 | // apiScopes property to be used as the key can be specified with the input accessor. | 
 | 317 | // Only a string property of apiScope can be used as the key of the map. | 
 | 318 | func (scopes apiScopes) MapToIndex(accessor func(*apiScope) string) map[string]int { | 
 | 319 | 	ret := make(map[string]int) | 
 | 320 | 	for i, scope := range scopes { | 
 | 321 | 		ret[accessor(scope)] = i | 
 | 322 | 	} | 
 | 323 | 	return ret | 
 | 324 | } | 
 | 325 |  | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 326 | var ( | 
| Paul Duffin | 46dc45a | 2020-05-14 15:39:10 +0100 | [diff] [blame] | 327 | 	scopeByName    = make(map[string]*apiScope) | 
 | 328 | 	allScopeNames  []string | 
| Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 329 | 	apiScopePublic = initApiScope(&apiScope{ | 
| Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 330 | 		name: "public", | 
 | 331 |  | 
 | 332 | 		// Public scope is enabled by default for both legacy and non-legacy modes. | 
 | 333 | 		legacyEnabledStatus: func(module *SdkLibrary) bool { | 
 | 334 | 			return true | 
 | 335 | 		}, | 
 | 336 | 		defaultEnabledStatus: true, | 
 | 337 |  | 
 | 338 | 		scopeSpecificProperties: func(module *SdkLibrary) *ApiScopeProperties { | 
 | 339 | 			return &module.sdkLibraryProperties.Public | 
 | 340 | 		}, | 
| Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 341 | 		sdkVersion: "current", | 
| Jihoon Kang | 1c92c3e | 2023-03-23 17:44:51 +0000 | [diff] [blame] | 342 | 		kind:       android.SdkPublic, | 
| Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 343 | 	}) | 
 | 344 | 	apiScopeSystem = initApiScope(&apiScope{ | 
| Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 345 | 		name:                "system", | 
 | 346 | 		extends:             apiScopePublic, | 
 | 347 | 		legacyEnabledStatus: (*SdkLibrary).generateTestAndSystemScopesByDefault, | 
 | 348 | 		scopeSpecificProperties: func(module *SdkLibrary) *ApiScopeProperties { | 
 | 349 | 			return &module.sdkLibraryProperties.System | 
 | 350 | 		}, | 
| Paul Duffin | 15f34ef | 2020-07-20 18:04:44 +0100 | [diff] [blame] | 351 | 		apiFilePrefix: "system-", | 
 | 352 | 		moduleSuffix:  ".system", | 
 | 353 | 		sdkVersion:    "system_current", | 
 | 354 | 		annotation:    "android.annotation.SystemApi(client=android.annotation.SystemApi.Client.PRIVILEGED_APPS)", | 
| Jihoon Kang | 1c92c3e | 2023-03-23 17:44:51 +0000 | [diff] [blame] | 355 | 		kind:          android.SdkSystem, | 
| Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 356 | 	}) | 
 | 357 | 	apiScopeTest = initApiScope(&apiScope{ | 
| Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 358 | 		name:                "test", | 
| Anton Hansson | 4fe970f | 2020-10-09 10:16:49 +0100 | [diff] [blame] | 359 | 		extends:             apiScopeSystem, | 
| Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 360 | 		legacyEnabledStatus: (*SdkLibrary).generateTestAndSystemScopesByDefault, | 
 | 361 | 		scopeSpecificProperties: func(module *SdkLibrary) *ApiScopeProperties { | 
 | 362 | 			return &module.sdkLibraryProperties.Test | 
 | 363 | 		}, | 
| Paul Duffin | 15f34ef | 2020-07-20 18:04:44 +0100 | [diff] [blame] | 364 | 		apiFilePrefix: "test-", | 
 | 365 | 		moduleSuffix:  ".test", | 
 | 366 | 		sdkVersion:    "test_current", | 
 | 367 | 		annotation:    "android.annotation.TestApi", | 
 | 368 | 		unstable:      true, | 
| Jihoon Kang | 1c92c3e | 2023-03-23 17:44:51 +0000 | [diff] [blame] | 369 | 		kind:          android.SdkTest, | 
| Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 370 | 	}) | 
| Paul Duffin | 8f265b9 | 2020-04-28 14:13:56 +0100 | [diff] [blame] | 371 | 	apiScopeModuleLib = initApiScope(&apiScope{ | 
| Paul Duffin | 6b836ba | 2020-05-13 19:19:49 +0100 | [diff] [blame] | 372 | 		name:    "module-lib", | 
| Paul Duffin | 8f265b9 | 2020-04-28 14:13:56 +0100 | [diff] [blame] | 373 | 		extends: apiScopeSystem, | 
| Paul Duffin | 0c5bae5 | 2020-06-02 13:00:08 +0100 | [diff] [blame] | 374 | 		// The module-lib scope is disabled by default in legacy mode. | 
| Paul Duffin | 8f265b9 | 2020-04-28 14:13:56 +0100 | [diff] [blame] | 375 | 		// | 
 | 376 | 		// Enabling this would break existing usages. | 
 | 377 | 		legacyEnabledStatus: func(module *SdkLibrary) bool { | 
 | 378 | 			return false | 
 | 379 | 		}, | 
 | 380 | 		scopeSpecificProperties: func(module *SdkLibrary) *ApiScopeProperties { | 
 | 381 | 			return &module.sdkLibraryProperties.Module_lib | 
 | 382 | 		}, | 
 | 383 | 		apiFilePrefix: "module-lib-", | 
 | 384 | 		moduleSuffix:  ".module_lib", | 
 | 385 | 		sdkVersion:    "module_current", | 
| Paul Duffin | 15f34ef | 2020-07-20 18:04:44 +0100 | [diff] [blame] | 386 | 		annotation:    "android.annotation.SystemApi(client=android.annotation.SystemApi.Client.MODULE_LIBRARIES)", | 
| Jihoon Kang | 1c92c3e | 2023-03-23 17:44:51 +0000 | [diff] [blame] | 387 | 		kind:          android.SdkModule, | 
| Paul Duffin | 8f265b9 | 2020-04-28 14:13:56 +0100 | [diff] [blame] | 388 | 	}) | 
| Paul Duffin | 0c5bae5 | 2020-06-02 13:00:08 +0100 | [diff] [blame] | 389 | 	apiScopeSystemServer = initApiScope(&apiScope{ | 
 | 390 | 		name:    "system-server", | 
 | 391 | 		extends: apiScopePublic, | 
| Paul Duffin | d0b9fca | 2022-09-30 18:11:41 +0100 | [diff] [blame] | 392 |  | 
 | 393 | 		// The system-server scope can access the module-lib scope. | 
 | 394 | 		// | 
 | 395 | 		// A module that provides a system-server API is appended to the standard bootclasspath that is | 
 | 396 | 		// used by the system server. So, it should be able to access module-lib APIs provided by | 
 | 397 | 		// libraries on the bootclasspath. | 
 | 398 | 		canAccess: apiScopeModuleLib, | 
 | 399 |  | 
| Paul Duffin | 0c5bae5 | 2020-06-02 13:00:08 +0100 | [diff] [blame] | 400 | 		// The system-server scope is disabled by default in legacy mode. | 
 | 401 | 		// | 
 | 402 | 		// Enabling this would break existing usages. | 
 | 403 | 		legacyEnabledStatus: func(module *SdkLibrary) bool { | 
 | 404 | 			return false | 
 | 405 | 		}, | 
 | 406 | 		scopeSpecificProperties: func(module *SdkLibrary) *ApiScopeProperties { | 
 | 407 | 			return &module.sdkLibraryProperties.System_server | 
 | 408 | 		}, | 
 | 409 | 		apiFilePrefix: "system-server-", | 
 | 410 | 		moduleSuffix:  ".system_server", | 
 | 411 | 		sdkVersion:    "system_server_current", | 
| Paul Duffin | 15f34ef | 2020-07-20 18:04:44 +0100 | [diff] [blame] | 412 | 		annotation:    "android.annotation.SystemApi(client=android.annotation.SystemApi.Client.SYSTEM_SERVER)", | 
 | 413 | 		extraArgs: []string{ | 
 | 414 | 			"--hide-annotation", "android.annotation.Hide", | 
| Paul Duffin | 0c5bae5 | 2020-06-02 13:00:08 +0100 | [diff] [blame] | 415 | 			// com.android.* classes are okay in this interface" | 
| Paul Duffin | 15f34ef | 2020-07-20 18:04:44 +0100 | [diff] [blame] | 416 | 			"--hide", "InternalClasses", | 
| Paul Duffin | 0c5bae5 | 2020-06-02 13:00:08 +0100 | [diff] [blame] | 417 | 		}, | 
| Jihoon Kang | 1c92c3e | 2023-03-23 17:44:51 +0000 | [diff] [blame] | 418 | 		kind: android.SdkSystemServer, | 
| Paul Duffin | 0c5bae5 | 2020-06-02 13:00:08 +0100 | [diff] [blame] | 419 | 	}) | 
| Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 420 | 	allApiScopes = apiScopes{ | 
 | 421 | 		apiScopePublic, | 
 | 422 | 		apiScopeSystem, | 
 | 423 | 		apiScopeTest, | 
| Paul Duffin | 8f265b9 | 2020-04-28 14:13:56 +0100 | [diff] [blame] | 424 | 		apiScopeModuleLib, | 
| Paul Duffin | 0c5bae5 | 2020-06-02 13:00:08 +0100 | [diff] [blame] | 425 | 		apiScopeSystemServer, | 
| Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 426 | 	} | 
| Jihoon Kang | 0c705a4 | 2023-08-02 06:44:57 +0000 | [diff] [blame] | 427 | 	apiLibraryAdditionalProperties = map[string]struct { | 
 | 428 | 		FullApiSurfaceStubLib     string | 
 | 429 | 		AdditionalApiContribution string | 
 | 430 | 	}{ | 
 | 431 | 		"legacy.i18n.module.platform.api": { | 
 | 432 | 			FullApiSurfaceStubLib:     "legacy.core.platform.api.stubs", | 
 | 433 | 			AdditionalApiContribution: "i18n.module.public.api.stubs.source.api.contribution", | 
 | 434 | 		}, | 
 | 435 | 		"stable.i18n.module.platform.api": { | 
 | 436 | 			FullApiSurfaceStubLib:     "stable.core.platform.api.stubs", | 
 | 437 | 			AdditionalApiContribution: "i18n.module.public.api.stubs.source.api.contribution", | 
 | 438 | 		}, | 
 | 439 | 		"conscrypt.module.platform.api": { | 
 | 440 | 			FullApiSurfaceStubLib:     "stable.core.platform.api.stubs", | 
 | 441 | 			AdditionalApiContribution: "conscrypt.module.public.api.stubs.source.api.contribution", | 
 | 442 | 		}, | 
 | 443 | 	} | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 444 | ) | 
 | 445 |  | 
| Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 446 | var ( | 
 | 447 | 	javaSdkLibrariesLock sync.Mutex | 
 | 448 | ) | 
 | 449 |  | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 450 | // TODO: these are big features that are currently missing | 
| Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 451 | // 1) disallowing linking to the runtime shared lib | 
 | 452 | // 2) HTML generation | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 453 |  | 
 | 454 | func init() { | 
| Paul Duffin | 43dc1cc | 2019-12-19 11:18:54 +0000 | [diff] [blame] | 455 | 	RegisterSdkLibraryBuildComponents(android.InitRegistrationContext) | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 456 |  | 
| Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 457 | 	android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) { | 
 | 458 | 		javaSdkLibraries := javaSdkLibraries(ctx.Config()) | 
 | 459 | 		sort.Strings(*javaSdkLibraries) | 
 | 460 | 		ctx.Strict("JAVA_SDK_LIBRARIES", strings.Join(*javaSdkLibraries, " ")) | 
 | 461 | 	}) | 
| Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 462 |  | 
 | 463 | 	// Register sdk member types. | 
| Paul Duffin | 976b0e5 | 2021-04-27 23:20:26 +0100 | [diff] [blame] | 464 | 	android.RegisterSdkMemberType(javaSdkLibrarySdkMemberType) | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 465 | } | 
 | 466 |  | 
| Paul Duffin | 43dc1cc | 2019-12-19 11:18:54 +0000 | [diff] [blame] | 467 | func RegisterSdkLibraryBuildComponents(ctx android.RegistrationContext) { | 
 | 468 | 	ctx.RegisterModuleType("java_sdk_library", SdkLibraryFactory) | 
 | 469 | 	ctx.RegisterModuleType("java_sdk_library_import", sdkLibraryImportFactory) | 
 | 470 | } | 
 | 471 |  | 
| Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 472 | // Properties associated with each api scope. | 
 | 473 | type ApiScopeProperties struct { | 
 | 474 | 	// Indicates whether the api surface is generated. | 
 | 475 | 	// | 
 | 476 | 	// If this is set for any scope then all scopes must explicitly specify if they | 
 | 477 | 	// are enabled. This is to prevent new usages from depending on legacy behavior. | 
 | 478 | 	// | 
 | 479 | 	// Otherwise, if this is not set for any scope then the default  behavior is | 
 | 480 | 	// scope specific so please refer to the scope specific property documentation. | 
 | 481 | 	Enabled *bool | 
| Paul Duffin | 87a05a3 | 2020-05-12 11:50:28 +0100 | [diff] [blame] | 482 |  | 
 | 483 | 	// The sdk_version to use for building the stubs. | 
 | 484 | 	// | 
 | 485 | 	// If not specified then it will use an sdk_version determined as follows: | 
| Trevor Radcliffe | df8aa1f | 2021-11-04 14:25:39 +0000 | [diff] [blame] | 486 | 	// | 
| Paul Duffin | 87a05a3 | 2020-05-12 11:50:28 +0100 | [diff] [blame] | 487 | 	// 1) If the sdk_version specified on the java_sdk_library is none then this | 
| Trevor Radcliffe | df8aa1f | 2021-11-04 14:25:39 +0000 | [diff] [blame] | 488 | 	// will be none. This is used for java_sdk_library instances that are used | 
 | 489 | 	// to create stubs that contribute to the core_current sdk version. | 
 | 490 | 	// 2) Otherwise, it is assumed that this library extends but does not | 
 | 491 | 	// contribute directly to a specific sdk_version and so this uses the | 
 | 492 | 	// sdk_version appropriate for the api scope. e.g. public will use | 
 | 493 | 	// sdk_version: current, system will use sdk_version: system_current, etc. | 
| Paul Duffin | 87a05a3 | 2020-05-12 11:50:28 +0100 | [diff] [blame] | 494 | 	// | 
 | 495 | 	// This does not affect the sdk_version used for either generating the stubs source | 
 | 496 | 	// or the API file. They both have to use the same sdk_version as is used for | 
 | 497 | 	// compiling the implementation library. | 
 | 498 | 	Sdk_version *string | 
| Mark White | 9421c4c | 2023-08-10 00:07:03 +0000 | [diff] [blame] | 499 |  | 
 | 500 | 	// Extra libs used when compiling stubs for this scope. | 
 | 501 | 	Libs []string | 
| Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 502 | } | 
 | 503 |  | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 504 | type sdkLibraryProperties struct { | 
| Anton Hansson | f8ea372 | 2021-09-16 14:24:13 +0100 | [diff] [blame] | 505 | 	// List of source files that are needed to compile the API, but are not part of runtime library. | 
 | 506 | 	Api_srcs []string `android:"arch_variant"` | 
 | 507 |  | 
| Paul Duffin | 5df7930 | 2020-05-16 15:52:12 +0100 | [diff] [blame] | 508 | 	// Visibility for impl library module. If not specified then defaults to the | 
 | 509 | 	// visibility property. | 
 | 510 | 	Impl_library_visibility []string | 
 | 511 |  | 
| Paul Duffin | 4911a89 | 2020-04-29 23:35:13 +0100 | [diff] [blame] | 512 | 	// Visibility for stubs library modules. If not specified then defaults to the | 
 | 513 | 	// visibility property. | 
 | 514 | 	Stubs_library_visibility []string | 
 | 515 |  | 
 | 516 | 	// Visibility for stubs source modules. If not specified then defaults to the | 
 | 517 | 	// visibility property. | 
 | 518 | 	Stubs_source_visibility []string | 
 | 519 |  | 
| Anton Hansson | 7f66efa | 2020-10-08 14:47:23 +0100 | [diff] [blame] | 520 | 	// List of Java libraries that will be in the classpath when building the implementation lib | 
 | 521 | 	Impl_only_libs []string `android:"arch_variant"` | 
 | 522 |  | 
| Paul Duffin | 77590a8 | 2022-04-28 14:13:30 +0000 | [diff] [blame] | 523 | 	// List of Java libraries that will included in the implementation lib. | 
 | 524 | 	Impl_only_static_libs []string `android:"arch_variant"` | 
 | 525 |  | 
| Sundong Ahn | f043cf6 | 2018-06-25 16:04:37 +0900 | [diff] [blame] | 526 | 	// List of Java libraries that will be in the classpath when building stubs | 
 | 527 | 	Stub_only_libs []string `android:"arch_variant"` | 
 | 528 |  | 
| Anton Hansson | dae54cd | 2021-04-21 16:30:10 +0100 | [diff] [blame] | 529 | 	// List of Java libraries that will included in stub libraries | 
 | 530 | 	Stub_only_static_libs []string `android:"arch_variant"` | 
 | 531 |  | 
| Paul Duffin | 7a586d3 | 2019-12-30 17:09:34 +0000 | [diff] [blame] | 532 | 	// list of package names that will be documented and publicized as API. | 
 | 533 | 	// This allows the API to be restricted to a subset of the source files provided. | 
 | 534 | 	// If this is unspecified then all the source files will be treated as being part | 
 | 535 | 	// of the API. | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 536 | 	Api_packages []string | 
 | 537 |  | 
| Jiyong Park | 5a2c9d7 | 2018-05-01 22:25:41 +0900 | [diff] [blame] | 538 | 	// list of package names that must be hidden from the API | 
 | 539 | 	Hidden_api_packages []string | 
 | 540 |  | 
| Paul Duffin | 749f98f | 2019-12-30 17:23:46 +0000 | [diff] [blame] | 541 | 	// the relative path to the directory containing the api specification files. | 
 | 542 | 	// Defaults to "api". | 
 | 543 | 	Api_dir *string | 
 | 544 |  | 
| Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 545 | 	// Determines whether a runtime implementation library is built; defaults to false. | 
 | 546 | 	// | 
 | 547 | 	// If true then it also prevents the module from being used as a shared module, i.e. | 
| MÃ¥rten Kongstad | 81d9095 | 2022-05-25 16:27:11 +0200 | [diff] [blame] | 548 | 	// it is as if shared_library: false, was set. | 
| Paul Duffin | 43db9be | 2019-12-30 17:35:49 +0000 | [diff] [blame] | 549 | 	Api_only *bool | 
 | 550 |  | 
| Paul Duffin | 1151247 | 2019-02-11 15:55:17 +0000 | [diff] [blame] | 551 | 	// local files that are used within user customized droiddoc options. | 
 | 552 | 	Droiddoc_option_files []string | 
 | 553 |  | 
| Spandan Das | 93e9599 | 2021-07-29 18:26:39 +0000 | [diff] [blame] | 554 | 	// additional droiddoc options. | 
| Paul Duffin | 1151247 | 2019-02-11 15:55:17 +0000 | [diff] [blame] | 555 | 	// Available variables for substitution: | 
 | 556 | 	// | 
 | 557 | 	//  $(location <label>): the path to the droiddoc_option_files with name <label> | 
| Sundong Ahn | dd567f9 | 2018-07-31 17:19:11 +0900 | [diff] [blame] | 558 | 	Droiddoc_options []string | 
 | 559 |  | 
| Paul Duffin | e22c2ab | 2020-05-20 19:35:27 +0100 | [diff] [blame] | 560 | 	// is set to true, Metalava will allow framework SDK to contain annotations. | 
 | 561 | 	Annotations_enabled *bool | 
 | 562 |  | 
| Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 563 | 	// a list of top-level directories containing files to merge qualifier annotations | 
 | 564 | 	// (i.e. those intended to be included in the stubs written) from. | 
 | 565 | 	Merge_annotations_dirs []string | 
 | 566 |  | 
 | 567 | 	// a list of top-level directories containing Java stub files to merge show/hide annotations from. | 
 | 568 | 	Merge_inclusion_annotations_dirs []string | 
 | 569 |  | 
| Paul Duffin | 4f5c1ef | 2020-11-19 14:53:43 +0000 | [diff] [blame] | 570 | 	// If set to true then don't create dist rules. | 
 | 571 | 	No_dist *bool | 
| Sundong Ahn | 80a87b3 | 2019-05-13 15:02:50 +0900 | [diff] [blame] | 572 |  | 
| Paul Duffin | 3131025 | 2020-11-20 21:26:20 +0000 | [diff] [blame] | 573 | 	// The stem for the artifacts that are copied to the dist, if not specified | 
 | 574 | 	// then defaults to the base module name. | 
 | 575 | 	// | 
 | 576 | 	// For each scope the following artifacts are copied to the apistubs/<scope> | 
 | 577 | 	// directory in the dist. | 
 | 578 | 	// * stubs impl jar -> <dist-stem>.jar | 
 | 579 | 	// * API specification file -> api/<dist-stem>.txt | 
 | 580 | 	// * Removed API specification file -> api/<dist-stem>-removed.txt | 
 | 581 | 	// | 
 | 582 | 	// Also used to construct the name of the filegroup (created by prebuilt_apis) | 
 | 583 | 	// that references the latest released API and remove API specification files. | 
 | 584 | 	// * API specification filegroup -> <dist-stem>.api.<scope>.latest | 
 | 585 | 	// * Removed API specification filegroup -> <dist-stem>-removed.api.<scope>.latest | 
| Jaewoong Jung | 1a97ee0 | 2021-03-09 13:25:02 -0800 | [diff] [blame] | 586 | 	// * API incompatibilities baseline filegroup -> <dist-stem>-incompatibilities.api.<scope>.latest | 
| Paul Duffin | 3131025 | 2020-11-20 21:26:20 +0000 | [diff] [blame] | 587 | 	Dist_stem *string | 
 | 588 |  | 
| Colin Cross | 986b69a | 2021-06-01 13:13:40 -0700 | [diff] [blame] | 589 | 	// The subdirectory for the artifacts that are copied to the dist directory.  If not specified | 
| Colin Cross | 3dd6625 | 2021-06-01 14:05:09 -0700 | [diff] [blame] | 590 | 	// then defaults to "unknown".  Should be set to "android" for anything that should be published | 
| Colin Cross | 986b69a | 2021-06-01 13:13:40 -0700 | [diff] [blame] | 591 | 	// in the public Android SDK. | 
 | 592 | 	Dist_group *string | 
 | 593 |  | 
| Anton Hansson | dff2c78 | 2020-12-21 17:10:01 +0000 | [diff] [blame] | 594 | 	// A compatibility mode that allows historical API-tracking files to not exist. | 
 | 595 | 	// Do not use. | 
 | 596 | 	Unsafe_ignore_missing_latest_api bool | 
 | 597 |  | 
| Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 598 | 	// indicates whether system and test apis should be generated. | 
 | 599 | 	Generate_system_and_test_apis bool `blueprint:"mutated"` | 
 | 600 |  | 
 | 601 | 	// The properties specific to the public api scope | 
 | 602 | 	// | 
 | 603 | 	// Unless explicitly specified by using public.enabled the public api scope is | 
 | 604 | 	// enabled by default in both legacy and non-legacy mode. | 
 | 605 | 	Public ApiScopeProperties | 
 | 606 |  | 
 | 607 | 	// The properties specific to the system api scope | 
 | 608 | 	// | 
 | 609 | 	// In legacy mode the system api scope is enabled by default when sdk_version | 
 | 610 | 	// is set to something other than "none". | 
 | 611 | 	// | 
 | 612 | 	// In non-legacy mode the system api scope is disabled by default. | 
 | 613 | 	System ApiScopeProperties | 
 | 614 |  | 
 | 615 | 	// The properties specific to the test api scope | 
 | 616 | 	// | 
 | 617 | 	// In legacy mode the test api scope is enabled by default when sdk_version | 
 | 618 | 	// is set to something other than "none". | 
 | 619 | 	// | 
 | 620 | 	// In non-legacy mode the test api scope is disabled by default. | 
 | 621 | 	Test ApiScopeProperties | 
| Paul Duffin | 37e0b77 | 2019-12-30 17:20:10 +0000 | [diff] [blame] | 622 |  | 
| Paul Duffin | 0c5bae5 | 2020-06-02 13:00:08 +0100 | [diff] [blame] | 623 | 	// The properties specific to the module-lib api scope | 
| Paul Duffin | 8f265b9 | 2020-04-28 14:13:56 +0100 | [diff] [blame] | 624 | 	// | 
| Zi Wang | b2179e3 | 2023-01-31 15:53:30 -0800 | [diff] [blame] | 625 | 	// Unless explicitly specified by using module_lib.enabled the module_lib api | 
 | 626 | 	// scope is disabled by default. | 
| Paul Duffin | 8f265b9 | 2020-04-28 14:13:56 +0100 | [diff] [blame] | 627 | 	Module_lib ApiScopeProperties | 
 | 628 |  | 
| Paul Duffin | 0c5bae5 | 2020-06-02 13:00:08 +0100 | [diff] [blame] | 629 | 	// The properties specific to the system-server api scope | 
 | 630 | 	// | 
| Zi Wang | b2179e3 | 2023-01-31 15:53:30 -0800 | [diff] [blame] | 631 | 	// Unless explicitly specified by using system_server.enabled the | 
 | 632 | 	// system_server api scope is disabled by default. | 
| Paul Duffin | 0c5bae5 | 2020-06-02 13:00:08 +0100 | [diff] [blame] | 633 | 	System_server ApiScopeProperties | 
 | 634 |  | 
| Jiyong Park | 932cdfe | 2020-05-28 00:19:53 +0900 | [diff] [blame] | 635 | 	// Determines if the stubs are preferred over the implementation library | 
 | 636 | 	// for linking, even when the client doesn't specify sdk_version. When this | 
 | 637 | 	// is set to true, such clients are provided with the widest API surface that | 
 | 638 | 	// this lib provides. Note however that this option doesn't affect the clients | 
 | 639 | 	// that are in the same APEX as this library. In that case, the clients are | 
 | 640 | 	// always linked with the implementation library. Default is false. | 
 | 641 | 	Default_to_stubs *bool | 
 | 642 |  | 
| Paul Duffin | 160fe41 | 2020-05-10 19:32:20 +0100 | [diff] [blame] | 643 | 	// Properties related to api linting. | 
 | 644 | 	Api_lint struct { | 
 | 645 | 		// Enable api linting. | 
 | 646 | 		Enabled *bool | 
| Anton Hansson | fd1c0d2 | 2023-11-02 15:18:09 +0000 | [diff] [blame] | 647 |  | 
 | 648 | 		// If API lint is enabled, this flag controls whether a set of legitimate lint errors | 
 | 649 | 		// are turned off. The default is true. | 
 | 650 | 		Legacy_errors_allowed *bool | 
| Paul Duffin | 160fe41 | 2020-05-10 19:32:20 +0100 | [diff] [blame] | 651 | 	} | 
 | 652 |  | 
| Jihoon Kang | 80456fd | 2023-11-15 19:22:14 +0000 | [diff] [blame] | 653 | 	// Determines if the module contributes to any api surfaces. | 
 | 654 | 	// This property should be set to true only if the module is listed under | 
 | 655 | 	// frameworks-base-api.bootclasspath in frameworks/base/api/Android.bp. | 
 | 656 | 	// Otherwise, this property should be set to false. | 
 | 657 | 	// Defaults to false. | 
 | 658 | 	Contribute_to_android_api *bool | 
 | 659 |  | 
| Jihoon Kang | 6592e87 | 2023-12-19 01:13:16 +0000 | [diff] [blame] | 660 | 	// a list of aconfig_declarations module names that the stubs generated in this module | 
 | 661 | 	// depend on. | 
 | 662 | 	Aconfig_declarations []string | 
 | 663 |  | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 664 | 	// TODO: determines whether to create HTML doc or not | 
| Paul Duffin | e840995 | 2022-09-22 16:24:46 +0100 | [diff] [blame] | 665 | 	// Html_doc *bool | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 666 | } | 
 | 667 |  | 
| Paul Duffin | 0f8faff | 2020-05-20 16:18:00 +0100 | [diff] [blame] | 668 | // Paths to outputs from java_sdk_library and java_sdk_library_import. | 
 | 669 | // | 
 | 670 | // Fields that are android.Paths are always set (during GenerateAndroidBuildActions). | 
 | 671 | // OptionalPaths are always set by java_sdk_library but may not be set by | 
 | 672 | // java_sdk_library_import as not all instances provide that information. | 
| Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 673 | type scopePaths struct { | 
| Paul Duffin | 0f8faff | 2020-05-20 16:18:00 +0100 | [diff] [blame] | 674 | 	// The path (represented as Paths for convenience when returning) to the stubs header jar. | 
 | 675 | 	// | 
 | 676 | 	// That is the jar that is created by turbine. | 
 | 677 | 	stubsHeaderPath android.Paths | 
 | 678 |  | 
 | 679 | 	// The path (represented as Paths for convenience when returning) to the stubs implementation jar. | 
 | 680 | 	// | 
 | 681 | 	// This is not the implementation jar, it still only contains stubs. | 
 | 682 | 	stubsImplPath android.Paths | 
 | 683 |  | 
| Paul Duffin | 1267d87 | 2021-04-16 17:21:36 +0100 | [diff] [blame] | 684 | 	// The dex jar for the stubs. | 
 | 685 | 	// | 
 | 686 | 	// This is not the implementation jar, it still only contains stubs. | 
| Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 687 | 	stubsDexJarPath OptionalDexJarPath | 
| Paul Duffin | 1267d87 | 2021-04-16 17:21:36 +0100 | [diff] [blame] | 688 |  | 
| Jihoon Kang | bd09345 | 2023-12-26 19:08:01 +0000 | [diff] [blame] | 689 | 	// The exportable dex jar for the stubs. | 
 | 690 | 	// This is not the implementation jar, it still only contains stubs. | 
 | 691 | 	// Includes unflagged apis and flagged apis enabled by release configurations. | 
 | 692 | 	exportableStubsDexJarPath OptionalDexJarPath | 
 | 693 |  | 
| Paul Duffin | 0f8faff | 2020-05-20 16:18:00 +0100 | [diff] [blame] | 694 | 	// The API specification file, e.g. system_current.txt. | 
 | 695 | 	currentApiFilePath android.OptionalPath | 
 | 696 |  | 
 | 697 | 	// The specification of API elements removed since the last release. | 
 | 698 | 	removedApiFilePath android.OptionalPath | 
 | 699 |  | 
 | 700 | 	// The stubs source jar. | 
 | 701 | 	stubsSrcJar android.OptionalPath | 
| Anton Hansson | d78eb76 | 2021-09-21 15:25:12 +0100 | [diff] [blame] | 702 |  | 
 | 703 | 	// Extracted annotations. | 
 | 704 | 	annotationsZip android.OptionalPath | 
| Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 705 |  | 
 | 706 | 	// The path to the latest API file. | 
 | 707 | 	latestApiPath android.OptionalPath | 
 | 708 |  | 
 | 709 | 	// The path to the latest removed API file. | 
 | 710 | 	latestRemovedApiPath android.OptionalPath | 
| Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 711 | } | 
 | 712 |  | 
| Colin Cross | dcf71b2 | 2021-02-01 13:59:03 -0800 | [diff] [blame] | 713 | func (paths *scopePaths) extractStubsLibraryInfoFromDependency(ctx android.ModuleContext, dep android.Module) error { | 
| Colin Cross | 313aa54 | 2023-12-13 13:47:44 -0800 | [diff] [blame] | 714 | 	if lib, ok := android.OtherModuleProvider(ctx, dep, JavaInfoProvider); ok { | 
| Colin Cross | dcf71b2 | 2021-02-01 13:59:03 -0800 | [diff] [blame] | 715 | 		paths.stubsHeaderPath = lib.HeaderJars | 
 | 716 | 		paths.stubsImplPath = lib.ImplementationJars | 
| Paul Duffin | 1267d87 | 2021-04-16 17:21:36 +0100 | [diff] [blame] | 717 |  | 
 | 718 | 		libDep := dep.(UsesLibraryDependency) | 
| Spandan Das | 59a4a2b | 2024-01-09 21:35:56 +0000 | [diff] [blame] | 719 | 		paths.stubsDexJarPath = libDep.DexJarBuildPath(ctx) | 
| Jihoon Kang | bd09345 | 2023-12-26 19:08:01 +0000 | [diff] [blame] | 720 | 		paths.exportableStubsDexJarPath = libDep.DexJarBuildPath(ctx) | 
 | 721 | 		return nil | 
 | 722 | 	} else { | 
 | 723 | 		return fmt.Errorf("expected module that has JavaInfoProvider, e.g. java_library") | 
 | 724 | 	} | 
 | 725 | } | 
 | 726 |  | 
 | 727 | func (paths *scopePaths) extractEverythingStubsLibraryInfoFromDependency(ctx android.ModuleContext, dep android.Module) error { | 
 | 728 | 	if lib, ok := android.OtherModuleProvider(ctx, dep, JavaInfoProvider); ok { | 
 | 729 | 		paths.stubsHeaderPath = lib.HeaderJars | 
| Jihoon Kang | f55a5f7 | 2024-01-08 08:56:20 +0000 | [diff] [blame] | 730 | 		if !ctx.Config().ReleaseHiddenApiExportableStubs() { | 
 | 731 | 			paths.stubsImplPath = lib.ImplementationJars | 
 | 732 | 		} | 
| Jihoon Kang | bd09345 | 2023-12-26 19:08:01 +0000 | [diff] [blame] | 733 |  | 
 | 734 | 		libDep := dep.(UsesLibraryDependency) | 
 | 735 | 		paths.stubsDexJarPath = libDep.DexJarBuildPath(ctx) | 
 | 736 | 		return nil | 
 | 737 | 	} else { | 
 | 738 | 		return fmt.Errorf("expected module that has JavaInfoProvider, e.g. java_library") | 
 | 739 | 	} | 
 | 740 | } | 
 | 741 |  | 
 | 742 | func (paths *scopePaths) extractExportableStubsLibraryInfoFromDependency(ctx android.ModuleContext, dep android.Module) error { | 
| Jihoon Kang | f55a5f7 | 2024-01-08 08:56:20 +0000 | [diff] [blame] | 743 | 	if lib, ok := android.OtherModuleProvider(ctx, dep, JavaInfoProvider); ok { | 
 | 744 | 		if ctx.Config().ReleaseHiddenApiExportableStubs() { | 
 | 745 | 			paths.stubsImplPath = lib.ImplementationJars | 
 | 746 | 		} | 
 | 747 |  | 
| Jihoon Kang | bd09345 | 2023-12-26 19:08:01 +0000 | [diff] [blame] | 748 | 		libDep := dep.(UsesLibraryDependency) | 
 | 749 | 		paths.exportableStubsDexJarPath = libDep.DexJarBuildPath(ctx) | 
| Paul Duffin | c878250 | 2020-04-29 20:45:27 +0100 | [diff] [blame] | 750 | 		return nil | 
 | 751 | 	} else { | 
| Colin Cross | dcf71b2 | 2021-02-01 13:59:03 -0800 | [diff] [blame] | 752 | 		return fmt.Errorf("expected module that has JavaInfoProvider, e.g. java_library") | 
| Paul Duffin | c878250 | 2020-04-29 20:45:27 +0100 | [diff] [blame] | 753 | 	} | 
 | 754 | } | 
 | 755 |  | 
| Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 756 | func (paths *scopePaths) treatDepAsApiStubsProvider(dep android.Module, action func(provider ApiStubsProvider)) error { | 
 | 757 | 	if apiStubsProvider, ok := dep.(ApiStubsProvider); ok { | 
 | 758 | 		action(apiStubsProvider) | 
| Paul Duffin | c878250 | 2020-04-29 20:45:27 +0100 | [diff] [blame] | 759 | 		return nil | 
 | 760 | 	} else { | 
 | 761 | 		return fmt.Errorf("expected module that implements ApiStubsProvider, e.g. droidstubs") | 
 | 762 | 	} | 
 | 763 | } | 
 | 764 |  | 
| Jihoon Kang | f55a5f7 | 2024-01-08 08:56:20 +0000 | [diff] [blame] | 765 | func (paths *scopePaths) treatDepAsExportableApiStubsProvider(dep android.Module, action func(provider ExportableApiStubsProvider)) error { | 
 | 766 | 	if exportableApiStubsProvider, ok := dep.(ExportableApiStubsProvider); ok { | 
 | 767 | 		action(exportableApiStubsProvider) | 
 | 768 | 		return nil | 
 | 769 | 	} else { | 
 | 770 | 		return fmt.Errorf("expected module that implements ExportableApiStubsSrcProvider, e.g. droidstubs") | 
 | 771 | 	} | 
 | 772 | } | 
 | 773 |  | 
| Paul Duffin | 0f8faff | 2020-05-20 16:18:00 +0100 | [diff] [blame] | 774 | func (paths *scopePaths) treatDepAsApiStubsSrcProvider(dep android.Module, action func(provider ApiStubsSrcProvider)) error { | 
 | 775 | 	if apiStubsProvider, ok := dep.(ApiStubsSrcProvider); ok { | 
 | 776 | 		action(apiStubsProvider) | 
 | 777 | 		return nil | 
 | 778 | 	} else { | 
 | 779 | 		return fmt.Errorf("expected module that implements ApiStubsSrcProvider, e.g. droidstubs") | 
 | 780 | 	} | 
 | 781 | } | 
 | 782 |  | 
| Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 783 | func (paths *scopePaths) extractApiInfoFromApiStubsProvider(provider ApiStubsProvider) { | 
| Anton Hansson | d78eb76 | 2021-09-21 15:25:12 +0100 | [diff] [blame] | 784 | 	paths.annotationsZip = android.OptionalPathForPath(provider.AnnotationsZip()) | 
| Paul Duffin | 0f8faff | 2020-05-20 16:18:00 +0100 | [diff] [blame] | 785 | 	paths.currentApiFilePath = android.OptionalPathForPath(provider.ApiFilePath()) | 
 | 786 | 	paths.removedApiFilePath = android.OptionalPathForPath(provider.RemovedApiFilePath()) | 
| Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 787 | } | 
 | 788 |  | 
| Jihoon Kang | f55a5f7 | 2024-01-08 08:56:20 +0000 | [diff] [blame] | 789 | func (paths *scopePaths) extractApiInfoFromExportableApiStubsProvider(provider ExportableApiStubsProvider) { | 
 | 790 | 	paths.annotationsZip = android.OptionalPathForPath(provider.ExportableAnnotationsZip()) | 
 | 791 | 	paths.currentApiFilePath = android.OptionalPathForPath(provider.ExportableApiFilePath()) | 
 | 792 | 	paths.removedApiFilePath = android.OptionalPathForPath(provider.ExportableRemovedApiFilePath()) | 
 | 793 | } | 
 | 794 |  | 
| Colin Cross | dcf71b2 | 2021-02-01 13:59:03 -0800 | [diff] [blame] | 795 | func (paths *scopePaths) extractApiInfoFromDep(ctx android.ModuleContext, dep android.Module) error { | 
| Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 796 | 	return paths.treatDepAsApiStubsProvider(dep, func(provider ApiStubsProvider) { | 
 | 797 | 		paths.extractApiInfoFromApiStubsProvider(provider) | 
 | 798 | 	}) | 
 | 799 | } | 
 | 800 |  | 
| Paul Duffin | 0f8faff | 2020-05-20 16:18:00 +0100 | [diff] [blame] | 801 | func (paths *scopePaths) extractStubsSourceInfoFromApiStubsProviders(provider ApiStubsSrcProvider) { | 
 | 802 | 	paths.stubsSrcJar = android.OptionalPathForPath(provider.StubsSrcJar()) | 
| Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 803 | } | 
 | 804 |  | 
| Jihoon Kang | f55a5f7 | 2024-01-08 08:56:20 +0000 | [diff] [blame] | 805 | func (paths *scopePaths) extractStubsSourceInfoFromExportableApiStubsProviders(provider ExportableApiStubsSrcProvider) { | 
 | 806 | 	paths.stubsSrcJar = android.OptionalPathForPath(provider.ExportableStubsSrcJar()) | 
 | 807 | } | 
 | 808 |  | 
| Colin Cross | dcf71b2 | 2021-02-01 13:59:03 -0800 | [diff] [blame] | 809 | func (paths *scopePaths) extractStubsSourceInfoFromDep(ctx android.ModuleContext, dep android.Module) error { | 
| Paul Duffin | 0f8faff | 2020-05-20 16:18:00 +0100 | [diff] [blame] | 810 | 	return paths.treatDepAsApiStubsSrcProvider(dep, func(provider ApiStubsSrcProvider) { | 
| Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 811 | 		paths.extractStubsSourceInfoFromApiStubsProviders(provider) | 
 | 812 | 	}) | 
 | 813 | } | 
 | 814 |  | 
| Colin Cross | dcf71b2 | 2021-02-01 13:59:03 -0800 | [diff] [blame] | 815 | func (paths *scopePaths) extractStubsSourceAndApiInfoFromApiStubsProvider(ctx android.ModuleContext, dep android.Module) error { | 
| Jihoon Kang | f55a5f7 | 2024-01-08 08:56:20 +0000 | [diff] [blame] | 816 | 	if ctx.Config().ReleaseHiddenApiExportableStubs() { | 
 | 817 | 		return paths.treatDepAsExportableApiStubsProvider(dep, func(provider ExportableApiStubsProvider) { | 
 | 818 | 			paths.extractApiInfoFromExportableApiStubsProvider(provider) | 
 | 819 | 			paths.extractStubsSourceInfoFromExportableApiStubsProviders(provider) | 
 | 820 | 		}) | 
 | 821 | 	} | 
| Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 822 | 	return paths.treatDepAsApiStubsProvider(dep, func(provider ApiStubsProvider) { | 
 | 823 | 		paths.extractApiInfoFromApiStubsProvider(provider) | 
 | 824 | 		paths.extractStubsSourceInfoFromApiStubsProviders(provider) | 
 | 825 | 	}) | 
 | 826 | } | 
 | 827 |  | 
| Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 828 | func extractSingleOptionalOutputPath(dep android.Module) (android.OptionalPath, error) { | 
 | 829 | 	var paths android.Paths | 
 | 830 | 	if sourceFileProducer, ok := dep.(android.SourceFileProducer); ok { | 
 | 831 | 		paths = sourceFileProducer.Srcs() | 
 | 832 | 	} else { | 
 | 833 | 		return android.OptionalPath{}, fmt.Errorf("module %q does not produce source files", dep) | 
 | 834 | 	} | 
 | 835 | 	if len(paths) != 1 { | 
 | 836 | 		return android.OptionalPath{}, fmt.Errorf("expected one path from %q, got %q", dep, paths) | 
 | 837 | 	} | 
 | 838 | 	return android.OptionalPathForPath(paths[0]), nil | 
 | 839 | } | 
 | 840 |  | 
 | 841 | func (paths *scopePaths) extractLatestApiPath(ctx android.ModuleContext, dep android.Module) error { | 
 | 842 | 	outputPath, err := extractSingleOptionalOutputPath(dep) | 
 | 843 | 	paths.latestApiPath = outputPath | 
 | 844 | 	return err | 
 | 845 | } | 
 | 846 |  | 
 | 847 | func (paths *scopePaths) extractLatestRemovedApiPath(ctx android.ModuleContext, dep android.Module) error { | 
 | 848 | 	outputPath, err := extractSingleOptionalOutputPath(dep) | 
 | 849 | 	paths.latestRemovedApiPath = outputPath | 
 | 850 | 	return err | 
 | 851 | } | 
 | 852 |  | 
| Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 853 | type commonToSdkLibraryAndImportProperties struct { | 
| Paul Duffin | 1b1e806 | 2020-05-08 13:44:43 +0100 | [diff] [blame] | 854 | 	// The naming scheme to use for the components that this module creates. | 
 | 855 | 	// | 
| Paul Duffin | ee9ad5d | 2020-09-11 13:04:05 +0100 | [diff] [blame] | 856 | 	// If not specified then it defaults to "default". | 
| Paul Duffin | 1b1e806 | 2020-05-08 13:44:43 +0100 | [diff] [blame] | 857 | 	// | 
 | 858 | 	// This is a temporary mechanism to simplify conversion from separate modules for each | 
 | 859 | 	// component that follow a different naming pattern to the default one. | 
 | 860 | 	// | 
 | 861 | 	// TODO(b/155480189) - Remove once naming inconsistencies have been resolved. | 
| Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 862 | 	Naming_scheme *string | 
| Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 863 |  | 
 | 864 | 	// Specifies whether this module can be used as an Android shared library; defaults | 
 | 865 | 	// to true. | 
 | 866 | 	// | 
 | 867 | 	// An Android shared library is one that can be referenced in a <uses-library> element | 
 | 868 | 	// in an AndroidManifest.xml. | 
 | 869 | 	Shared_library *bool | 
| Paul Duffin | a2ae7e0 | 2020-09-11 11:55:00 +0100 | [diff] [blame] | 870 |  | 
 | 871 | 	// Files containing information about supported java doc tags. | 
 | 872 | 	Doctag_files []string `android:"path"` | 
| Pedro Loureiro | 9956e5e | 2021-09-07 17:21:59 +0000 | [diff] [blame] | 873 |  | 
 | 874 | 	// Signals that this shared library is part of the bootclasspath starting | 
 | 875 | 	// on the version indicated in this attribute. | 
 | 876 | 	// | 
 | 877 | 	// This will make platforms at this level and above to ignore | 
 | 878 | 	// <uses-library> tags with this library name because the library is already | 
 | 879 | 	// available | 
 | 880 | 	On_bootclasspath_since *string | 
 | 881 |  | 
 | 882 | 	// Signals that this shared library was part of the bootclasspath before | 
 | 883 | 	// (but not including) the version indicated in this attribute. | 
 | 884 | 	// | 
 | 885 | 	// The system will automatically add a <uses-library> tag with this library to | 
 | 886 | 	// apps that target any SDK less than the version indicated in this attribute. | 
 | 887 | 	On_bootclasspath_before *string | 
 | 888 |  | 
 | 889 | 	// Indicates that PackageManager should ignore this shared library if the | 
 | 890 | 	// platform is below the version indicated in this attribute. | 
 | 891 | 	// | 
 | 892 | 	// This means that the device won't recognise this library as installed. | 
 | 893 | 	Min_device_sdk *string | 
 | 894 |  | 
 | 895 | 	// Indicates that PackageManager should ignore this shared library if the | 
 | 896 | 	// platform is above the version indicated in this attribute. | 
 | 897 | 	// | 
 | 898 | 	// This means that the device won't recognise this library as installed. | 
 | 899 | 	Max_device_sdk *string | 
| Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 900 | } | 
 | 901 |  | 
| Paul Duffin | 71b33cc | 2021-06-23 11:39:47 +0100 | [diff] [blame] | 902 | // commonSdkLibraryAndImportModule defines the interface that must be provided by a module that | 
 | 903 | // embeds the commonToSdkLibraryAndImport struct. | 
 | 904 | type commonSdkLibraryAndImportModule interface { | 
| Paul Duffin | d796f6f | 2022-11-23 23:06:05 +0000 | [diff] [blame] | 905 | 	android.Module | 
| Paul Duffin | 71b33cc | 2021-06-23 11:39:47 +0100 | [diff] [blame] | 906 |  | 
 | 907 | 	BaseModuleName() string | 
 | 908 | } | 
 | 909 |  | 
| Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 910 | // Common code between sdk library and sdk library import | 
 | 911 | type commonToSdkLibraryAndImport struct { | 
| Paul Duffin | 71b33cc | 2021-06-23 11:39:47 +0100 | [diff] [blame] | 912 | 	module commonSdkLibraryAndImportModule | 
| Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame] | 913 |  | 
| Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 914 | 	scopePaths map[*apiScope]*scopePaths | 
| Paul Duffin | 1b1e806 | 2020-05-08 13:44:43 +0100 | [diff] [blame] | 915 |  | 
 | 916 | 	namingScheme sdkLibraryComponentNamingScheme | 
 | 917 |  | 
| Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 918 | 	commonSdkLibraryProperties commonToSdkLibraryAndImportProperties | 
| Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 919 |  | 
| Paul Duffin | a2ae7e0 | 2020-09-11 11:55:00 +0100 | [diff] [blame] | 920 | 	// Paths to commonSdkLibraryProperties.Doctag_files | 
 | 921 | 	doctagPaths android.Paths | 
 | 922 |  | 
| Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 923 | 	// Functionality related to this being used as a component of a java_sdk_library. | 
 | 924 | 	EmbeddableSdkLibraryComponent | 
| Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 925 | } | 
 | 926 |  | 
| Paul Duffin | 71b33cc | 2021-06-23 11:39:47 +0100 | [diff] [blame] | 927 | func (c *commonToSdkLibraryAndImport) initCommon(module commonSdkLibraryAndImportModule) { | 
 | 928 | 	c.module = module | 
| Paul Duffin | 1b1e806 | 2020-05-08 13:44:43 +0100 | [diff] [blame] | 929 |  | 
| Paul Duffin | 71b33cc | 2021-06-23 11:39:47 +0100 | [diff] [blame] | 930 | 	module.AddProperties(&c.commonSdkLibraryProperties) | 
| Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 931 |  | 
 | 932 | 	// Initialize this as an sdk library component. | 
| Paul Duffin | 71b33cc | 2021-06-23 11:39:47 +0100 | [diff] [blame] | 933 | 	c.initSdkLibraryComponent(module) | 
| Paul Duffin | 1b1e806 | 2020-05-08 13:44:43 +0100 | [diff] [blame] | 934 | } | 
 | 935 |  | 
 | 936 | func (c *commonToSdkLibraryAndImport) initCommonAfterDefaultsApplied(ctx android.DefaultableHookContext) bool { | 
| Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 937 | 	schemeProperty := proptools.StringDefault(c.commonSdkLibraryProperties.Naming_scheme, "default") | 
| Paul Duffin | 1b1e806 | 2020-05-08 13:44:43 +0100 | [diff] [blame] | 938 | 	switch schemeProperty { | 
 | 939 | 	case "default": | 
 | 940 | 		c.namingScheme = &defaultNamingScheme{} | 
 | 941 | 	default: | 
 | 942 | 		ctx.PropertyErrorf("naming_scheme", "expected 'default' but was %q", schemeProperty) | 
 | 943 | 		return false | 
 | 944 | 	} | 
 | 945 |  | 
| Paul Duffin | 3f0290e | 2021-06-30 18:25:36 +0100 | [diff] [blame] | 946 | 	namePtr := proptools.StringPtr(c.module.BaseModuleName()) | 
 | 947 | 	c.sdkLibraryComponentProperties.SdkLibraryName = namePtr | 
 | 948 |  | 
| Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 949 | 	// Only track this sdk library if this can be used as a shared library. | 
 | 950 | 	if c.sharedLibrary() { | 
 | 951 | 		// Use the name specified in the module definition as the owner. | 
| Paul Duffin | 3f0290e | 2021-06-30 18:25:36 +0100 | [diff] [blame] | 952 | 		c.sdkLibraryComponentProperties.SdkLibraryToImplicitlyTrack = namePtr | 
| Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 953 | 	} | 
| Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 954 |  | 
| Paul Duffin | 1b1e806 | 2020-05-08 13:44:43 +0100 | [diff] [blame] | 955 | 	return true | 
| Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame] | 956 | } | 
 | 957 |  | 
| Paul Duffin | ea8f808 | 2021-06-24 13:25:57 +0100 | [diff] [blame] | 958 | // uniqueApexVariations provides common implementation of the ApexModule.UniqueApexVariations | 
 | 959 | // method. | 
 | 960 | func (c *commonToSdkLibraryAndImport) uniqueApexVariations() bool { | 
 | 961 | 	// A java_sdk_library that is a shared library produces an XML file that makes the shared library | 
 | 962 | 	// usable from an AndroidManifest.xml's <uses-library> entry. That XML file contains the name of | 
 | 963 | 	// the APEX and so it needs a unique variation per APEX. | 
 | 964 | 	return c.sharedLibrary() | 
 | 965 | } | 
 | 966 |  | 
| Paul Duffin | a2ae7e0 | 2020-09-11 11:55:00 +0100 | [diff] [blame] | 967 | func (c *commonToSdkLibraryAndImport) generateCommonBuildActions(ctx android.ModuleContext) { | 
 | 968 | 	c.doctagPaths = android.PathsForModuleSrc(ctx, c.commonSdkLibraryProperties.Doctag_files) | 
 | 969 | } | 
 | 970 |  | 
| Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 971 | // Module name of the runtime implementation library | 
 | 972 | func (c *commonToSdkLibraryAndImport) implLibraryModuleName() string { | 
| Paul Duffin | 71b33cc | 2021-06-23 11:39:47 +0100 | [diff] [blame] | 973 | 	return c.module.BaseModuleName() + ".impl" | 
| Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 974 | } | 
 | 975 |  | 
 | 976 | // Module name of the XML file for the lib | 
 | 977 | func (c *commonToSdkLibraryAndImport) xmlPermissionsModuleName() string { | 
| Paul Duffin | 71b33cc | 2021-06-23 11:39:47 +0100 | [diff] [blame] | 978 | 	return c.module.BaseModuleName() + sdkXmlFileSuffix | 
| Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 979 | } | 
 | 980 |  | 
| Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame] | 981 | // Name of the java_library module that compiles the stubs source. | 
 | 982 | func (c *commonToSdkLibraryAndImport) stubsLibraryModuleName(apiScope *apiScope) string { | 
| Paul Duffin | b97b157 | 2021-04-29 21:50:40 +0100 | [diff] [blame] | 983 | 	baseName := c.module.BaseModuleName() | 
| Paul Duffin | 2178762 | 2022-11-25 12:48:20 +0000 | [diff] [blame] | 984 | 	return c.namingScheme.stubsLibraryModuleName(apiScope, baseName) | 
| Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame] | 985 | } | 
 | 986 |  | 
| Jihoon Kang | fa4a90d | 2023-12-20 02:53:38 +0000 | [diff] [blame] | 987 | // Name of the java_library module that compiles the exportable stubs source. | 
 | 988 | func (c *commonToSdkLibraryAndImport) exportableStubsLibraryModuleName(apiScope *apiScope) string { | 
 | 989 | 	baseName := c.module.BaseModuleName() | 
 | 990 | 	return c.namingScheme.exportableStubsLibraryModuleName(apiScope, baseName) | 
 | 991 | } | 
 | 992 |  | 
| Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame] | 993 | // Name of the droidstubs module that generates the stubs source and may also | 
 | 994 | // generate/check the API. | 
 | 995 | func (c *commonToSdkLibraryAndImport) stubsSourceModuleName(apiScope *apiScope) string { | 
| Paul Duffin | b97b157 | 2021-04-29 21:50:40 +0100 | [diff] [blame] | 996 | 	baseName := c.module.BaseModuleName() | 
| Paul Duffin | 2178762 | 2022-11-25 12:48:20 +0000 | [diff] [blame] | 997 | 	return c.namingScheme.stubsSourceModuleName(apiScope, baseName) | 
| Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame] | 998 | } | 
 | 999 |  | 
| Jihoon Kang | 1c92c3e | 2023-03-23 17:44:51 +0000 | [diff] [blame] | 1000 | // Name of the java_api_library module that generates the from-text stubs source | 
 | 1001 | // and compiles to a jar file. | 
 | 1002 | func (c *commonToSdkLibraryAndImport) apiLibraryModuleName(apiScope *apiScope) string { | 
 | 1003 | 	baseName := c.module.BaseModuleName() | 
 | 1004 | 	return c.namingScheme.apiLibraryModuleName(apiScope, baseName) | 
 | 1005 | } | 
 | 1006 |  | 
| Jihoon Kang | 1147b31 | 2023-06-08 23:25:57 +0000 | [diff] [blame] | 1007 | // Name of the java_library module that compiles the stubs | 
 | 1008 | // generated from source Java files. | 
| Jihoon Kang | fa4a90d | 2023-12-20 02:53:38 +0000 | [diff] [blame] | 1009 | func (c *commonToSdkLibraryAndImport) sourceStubsLibraryModuleName(apiScope *apiScope) string { | 
| Jihoon Kang | 1147b31 | 2023-06-08 23:25:57 +0000 | [diff] [blame] | 1010 | 	baseName := c.module.BaseModuleName() | 
| Jihoon Kang | fa4a90d | 2023-12-20 02:53:38 +0000 | [diff] [blame] | 1011 | 	return c.namingScheme.sourceStubsLibraryModuleName(apiScope, baseName) | 
 | 1012 | } | 
 | 1013 |  | 
 | 1014 | // Name of the java_library module that compiles the exportable stubs | 
 | 1015 | // generated from source Java files. | 
 | 1016 | func (c *commonToSdkLibraryAndImport) exportableSourceStubsLibraryModuleName(apiScope *apiScope) string { | 
 | 1017 | 	baseName := c.module.BaseModuleName() | 
 | 1018 | 	return c.namingScheme.exportableSourceStubsLibraryModuleName(apiScope, baseName) | 
| Jihoon Kang | 1147b31 | 2023-06-08 23:25:57 +0000 | [diff] [blame] | 1019 | } | 
 | 1020 |  | 
| Paul Duffin | 46dc45a | 2020-05-14 15:39:10 +0100 | [diff] [blame] | 1021 | // The component names for different outputs of the java_sdk_library. | 
 | 1022 | // | 
 | 1023 | // They are similar to the names used for the child modules it creates | 
 | 1024 | const ( | 
 | 1025 | 	stubsSourceComponentName = "stubs.source" | 
 | 1026 |  | 
 | 1027 | 	apiTxtComponentName = "api.txt" | 
 | 1028 |  | 
 | 1029 | 	removedApiTxtComponentName = "removed-api.txt" | 
| Anton Hansson | d78eb76 | 2021-09-21 15:25:12 +0100 | [diff] [blame] | 1030 |  | 
 | 1031 | 	annotationsComponentName = "annotations.zip" | 
| Paul Duffin | 46dc45a | 2020-05-14 15:39:10 +0100 | [diff] [blame] | 1032 | ) | 
 | 1033 |  | 
 | 1034 | // A regular expression to match tags that reference a specific stubs component. | 
 | 1035 | // | 
 | 1036 | // It will only match if given a valid scope and a valid component. It is verfy strict | 
 | 1037 | // to ensure it does not accidentally match a similar looking tag that should be processed | 
 | 1038 | // by the embedded Library. | 
 | 1039 | var tagSplitter = func() *regexp.Regexp { | 
 | 1040 | 	// Given a list of literal string items returns a regular expression that will | 
 | 1041 | 	// match any one of the items. | 
 | 1042 | 	choice := func(items ...string) string { | 
 | 1043 | 		return `\Q` + strings.Join(items, `\E|\Q`) + `\E` | 
 | 1044 | 	} | 
 | 1045 |  | 
 | 1046 | 	// Regular expression to match one of the scopes. | 
 | 1047 | 	scopesRegexp := choice(allScopeNames...) | 
 | 1048 |  | 
 | 1049 | 	// Regular expression to match one of the components. | 
| Anton Hansson | d78eb76 | 2021-09-21 15:25:12 +0100 | [diff] [blame] | 1050 | 	componentsRegexp := choice(stubsSourceComponentName, apiTxtComponentName, removedApiTxtComponentName, annotationsComponentName) | 
| Paul Duffin | 46dc45a | 2020-05-14 15:39:10 +0100 | [diff] [blame] | 1051 |  | 
 | 1052 | 	// Regular expression to match any combination of one scope and one component. | 
 | 1053 | 	return regexp.MustCompile(fmt.Sprintf(`^\.(%s)\.(%s)$`, scopesRegexp, componentsRegexp)) | 
 | 1054 | }() | 
 | 1055 |  | 
 | 1056 | // For OutputFileProducer interface | 
 | 1057 | // | 
| Anton Hansson | d78eb76 | 2021-09-21 15:25:12 +0100 | [diff] [blame] | 1058 | // .<scope>.<component name>, for all ComponentNames (for example: .public.removed-api.txt) | 
| Paul Duffin | 46dc45a | 2020-05-14 15:39:10 +0100 | [diff] [blame] | 1059 | func (c *commonToSdkLibraryAndImport) commonOutputFiles(tag string) (android.Paths, error) { | 
 | 1060 | 	if groups := tagSplitter.FindStringSubmatch(tag); groups != nil { | 
 | 1061 | 		scopeName := groups[1] | 
 | 1062 | 		component := groups[2] | 
 | 1063 |  | 
 | 1064 | 		if scope, ok := scopeByName[scopeName]; ok { | 
 | 1065 | 			paths := c.findScopePaths(scope) | 
 | 1066 | 			if paths == nil { | 
| Paul Duffin | 71b33cc | 2021-06-23 11:39:47 +0100 | [diff] [blame] | 1067 | 				return nil, fmt.Errorf("%q does not provide api scope %s", c.module.BaseModuleName(), scopeName) | 
| Paul Duffin | 46dc45a | 2020-05-14 15:39:10 +0100 | [diff] [blame] | 1068 | 			} | 
 | 1069 |  | 
 | 1070 | 			switch component { | 
 | 1071 | 			case stubsSourceComponentName: | 
 | 1072 | 				if paths.stubsSrcJar.Valid() { | 
 | 1073 | 					return android.Paths{paths.stubsSrcJar.Path()}, nil | 
 | 1074 | 				} | 
 | 1075 |  | 
 | 1076 | 			case apiTxtComponentName: | 
 | 1077 | 				if paths.currentApiFilePath.Valid() { | 
 | 1078 | 					return android.Paths{paths.currentApiFilePath.Path()}, nil | 
 | 1079 | 				} | 
 | 1080 |  | 
 | 1081 | 			case removedApiTxtComponentName: | 
 | 1082 | 				if paths.removedApiFilePath.Valid() { | 
 | 1083 | 					return android.Paths{paths.removedApiFilePath.Path()}, nil | 
 | 1084 | 				} | 
| Anton Hansson | d78eb76 | 2021-09-21 15:25:12 +0100 | [diff] [blame] | 1085 |  | 
 | 1086 | 			case annotationsComponentName: | 
 | 1087 | 				if paths.annotationsZip.Valid() { | 
 | 1088 | 					return android.Paths{paths.annotationsZip.Path()}, nil | 
 | 1089 | 				} | 
| Paul Duffin | 46dc45a | 2020-05-14 15:39:10 +0100 | [diff] [blame] | 1090 | 			} | 
 | 1091 |  | 
 | 1092 | 			return nil, fmt.Errorf("%s not available for api scope %s", component, scopeName) | 
 | 1093 | 		} else { | 
 | 1094 | 			return nil, fmt.Errorf("unknown scope %s in %s", scope, tag) | 
 | 1095 | 		} | 
 | 1096 |  | 
 | 1097 | 	} else { | 
| Paul Duffin | a2ae7e0 | 2020-09-11 11:55:00 +0100 | [diff] [blame] | 1098 | 		switch tag { | 
 | 1099 | 		case ".doctags": | 
 | 1100 | 			if c.doctagPaths != nil { | 
 | 1101 | 				return c.doctagPaths, nil | 
 | 1102 | 			} else { | 
| Paul Duffin | 71b33cc | 2021-06-23 11:39:47 +0100 | [diff] [blame] | 1103 | 				return nil, fmt.Errorf("no doctag_files specified on %s", c.module.BaseModuleName()) | 
| Paul Duffin | a2ae7e0 | 2020-09-11 11:55:00 +0100 | [diff] [blame] | 1104 | 			} | 
 | 1105 | 		} | 
| Paul Duffin | 46dc45a | 2020-05-14 15:39:10 +0100 | [diff] [blame] | 1106 | 		return nil, nil | 
 | 1107 | 	} | 
 | 1108 | } | 
 | 1109 |  | 
| Paul Duffin | 803a956 | 2020-05-20 11:52:25 +0100 | [diff] [blame] | 1110 | func (c *commonToSdkLibraryAndImport) getScopePathsCreateIfNeeded(scope *apiScope) *scopePaths { | 
| Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 1111 | 	if c.scopePaths == nil { | 
 | 1112 | 		c.scopePaths = make(map[*apiScope]*scopePaths) | 
 | 1113 | 	} | 
 | 1114 | 	paths := c.scopePaths[scope] | 
 | 1115 | 	if paths == nil { | 
 | 1116 | 		paths = &scopePaths{} | 
 | 1117 | 		c.scopePaths[scope] = paths | 
 | 1118 | 	} | 
 | 1119 |  | 
 | 1120 | 	return paths | 
 | 1121 | } | 
 | 1122 |  | 
| Paul Duffin | 803a956 | 2020-05-20 11:52:25 +0100 | [diff] [blame] | 1123 | func (c *commonToSdkLibraryAndImport) findScopePaths(scope *apiScope) *scopePaths { | 
 | 1124 | 	if c.scopePaths == nil { | 
 | 1125 | 		return nil | 
 | 1126 | 	} | 
 | 1127 |  | 
 | 1128 | 	return c.scopePaths[scope] | 
 | 1129 | } | 
 | 1130 |  | 
 | 1131 | // If this does not support the requested api scope then find the closest available | 
 | 1132 | // scope it does support. Returns nil if no such scope is available. | 
 | 1133 | func (c *commonToSdkLibraryAndImport) findClosestScopePath(scope *apiScope) *scopePaths { | 
| Paul Duffin | d0b9fca | 2022-09-30 18:11:41 +0100 | [diff] [blame] | 1134 | 	for s := scope; s != nil; s = s.canAccess { | 
| Paul Duffin | 803a956 | 2020-05-20 11:52:25 +0100 | [diff] [blame] | 1135 | 		if paths := c.findScopePaths(s); paths != nil { | 
 | 1136 | 			return paths | 
 | 1137 | 		} | 
 | 1138 | 	} | 
 | 1139 |  | 
 | 1140 | 	// This should never happen outside tests as public should be the base scope for every | 
 | 1141 | 	// scope and is enabled by default. | 
 | 1142 | 	return nil | 
 | 1143 | } | 
 | 1144 |  | 
| Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 1145 | func (c *commonToSdkLibraryAndImport) selectHeaderJarsForSdkVersion(ctx android.BaseModuleContext, sdkVersion android.SdkSpec) android.Paths { | 
| Paul Duffin | b05d429 | 2020-05-20 12:19:10 +0100 | [diff] [blame] | 1146 |  | 
 | 1147 | 	// If a specific numeric version has been requested then use prebuilt versions of the sdk. | 
| Jiyong Park | 54105c4 | 2021-03-31 18:17:53 +0900 | [diff] [blame] | 1148 | 	if !sdkVersion.ApiLevel.IsPreview() { | 
| Paul Duffin | 71b33cc | 2021-06-23 11:39:47 +0100 | [diff] [blame] | 1149 | 		return PrebuiltJars(ctx, c.module.BaseModuleName(), sdkVersion) | 
| Paul Duffin | b05d429 | 2020-05-20 12:19:10 +0100 | [diff] [blame] | 1150 | 	} | 
 | 1151 |  | 
| Paul Duffin | 1267d87 | 2021-04-16 17:21:36 +0100 | [diff] [blame] | 1152 | 	paths := c.selectScopePaths(ctx, sdkVersion.Kind) | 
 | 1153 | 	if paths == nil { | 
 | 1154 | 		return nil | 
 | 1155 | 	} | 
 | 1156 |  | 
 | 1157 | 	return paths.stubsHeaderPath | 
 | 1158 | } | 
 | 1159 |  | 
 | 1160 | // selectScopePaths returns the *scopePaths appropriate for the specific kind. | 
 | 1161 | // | 
 | 1162 | // If the module does not support the specific kind then it will return the *scopePaths for the | 
 | 1163 | // closest kind which is a subset of the requested kind. e.g. if requesting android.SdkModule then | 
 | 1164 | // it will return *scopePaths for android.SdkSystem if available or android.SdkPublic of not. | 
 | 1165 | func (c *commonToSdkLibraryAndImport) selectScopePaths(ctx android.BaseModuleContext, kind android.SdkKind) *scopePaths { | 
| Paul Duffin | 32cf58a | 2021-05-18 16:32:50 +0100 | [diff] [blame] | 1166 | 	apiScope := sdkKindToApiScope(kind) | 
| Paul Duffin | b05d429 | 2020-05-20 12:19:10 +0100 | [diff] [blame] | 1167 |  | 
| Paul Duffin | 803a956 | 2020-05-20 11:52:25 +0100 | [diff] [blame] | 1168 | 	paths := c.findClosestScopePath(apiScope) | 
 | 1169 | 	if paths == nil { | 
 | 1170 | 		var scopes []string | 
 | 1171 | 		for _, s := range allApiScopes { | 
 | 1172 | 			if c.findScopePaths(s) != nil { | 
 | 1173 | 				scopes = append(scopes, s.name) | 
 | 1174 | 			} | 
 | 1175 | 		} | 
| Paul Duffin | 71b33cc | 2021-06-23 11:39:47 +0100 | [diff] [blame] | 1176 | 		ctx.ModuleErrorf("requires api scope %s from %s but it only has %q available", apiScope.name, c.module.BaseModuleName(), scopes) | 
| Paul Duffin | 803a956 | 2020-05-20 11:52:25 +0100 | [diff] [blame] | 1177 | 		return nil | 
 | 1178 | 	} | 
 | 1179 |  | 
| Paul Duffin | 1267d87 | 2021-04-16 17:21:36 +0100 | [diff] [blame] | 1180 | 	return paths | 
 | 1181 | } | 
 | 1182 |  | 
| Paul Duffin | 32cf58a | 2021-05-18 16:32:50 +0100 | [diff] [blame] | 1183 | // sdkKindToApiScope maps from android.SdkKind to apiScope. | 
 | 1184 | func sdkKindToApiScope(kind android.SdkKind) *apiScope { | 
 | 1185 | 	var apiScope *apiScope | 
 | 1186 | 	switch kind { | 
 | 1187 | 	case android.SdkSystem: | 
 | 1188 | 		apiScope = apiScopeSystem | 
 | 1189 | 	case android.SdkModule: | 
 | 1190 | 		apiScope = apiScopeModuleLib | 
 | 1191 | 	case android.SdkTest: | 
 | 1192 | 		apiScope = apiScopeTest | 
 | 1193 | 	case android.SdkSystemServer: | 
 | 1194 | 		apiScope = apiScopeSystemServer | 
 | 1195 | 	default: | 
 | 1196 | 		apiScope = apiScopePublic | 
 | 1197 | 	} | 
 | 1198 | 	return apiScope | 
 | 1199 | } | 
 | 1200 |  | 
| Paul Duffin | 1267d87 | 2021-04-16 17:21:36 +0100 | [diff] [blame] | 1201 | // to satisfy SdkLibraryDependency interface | 
| Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 1202 | func (c *commonToSdkLibraryAndImport) SdkApiStubDexJar(ctx android.BaseModuleContext, kind android.SdkKind) OptionalDexJarPath { | 
| Paul Duffin | 1267d87 | 2021-04-16 17:21:36 +0100 | [diff] [blame] | 1203 | 	paths := c.selectScopePaths(ctx, kind) | 
 | 1204 | 	if paths == nil { | 
| Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 1205 | 		return makeUnsetDexJarPath() | 
| Paul Duffin | 1267d87 | 2021-04-16 17:21:36 +0100 | [diff] [blame] | 1206 | 	} | 
 | 1207 |  | 
 | 1208 | 	return paths.stubsDexJarPath | 
| Paul Duffin | b05d429 | 2020-05-20 12:19:10 +0100 | [diff] [blame] | 1209 | } | 
 | 1210 |  | 
| Paul Duffin | 32cf58a | 2021-05-18 16:32:50 +0100 | [diff] [blame] | 1211 | // to satisfy SdkLibraryDependency interface | 
| Jihoon Kang | bd09345 | 2023-12-26 19:08:01 +0000 | [diff] [blame] | 1212 | func (c *commonToSdkLibraryAndImport) SdkApiExportableStubDexJar(ctx android.BaseModuleContext, kind android.SdkKind) OptionalDexJarPath { | 
 | 1213 | 	paths := c.selectScopePaths(ctx, kind) | 
 | 1214 | 	if paths == nil { | 
 | 1215 | 		return makeUnsetDexJarPath() | 
 | 1216 | 	} | 
 | 1217 |  | 
 | 1218 | 	return paths.exportableStubsDexJarPath | 
 | 1219 | } | 
 | 1220 |  | 
 | 1221 | // to satisfy SdkLibraryDependency interface | 
| Paul Duffin | 32cf58a | 2021-05-18 16:32:50 +0100 | [diff] [blame] | 1222 | func (c *commonToSdkLibraryAndImport) SdkRemovedTxtFile(ctx android.BaseModuleContext, kind android.SdkKind) android.OptionalPath { | 
 | 1223 | 	apiScope := sdkKindToApiScope(kind) | 
 | 1224 | 	paths := c.findScopePaths(apiScope) | 
 | 1225 | 	if paths == nil { | 
 | 1226 | 		return android.OptionalPath{} | 
 | 1227 | 	} | 
 | 1228 |  | 
 | 1229 | 	return paths.removedApiFilePath | 
 | 1230 | } | 
 | 1231 |  | 
| Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 1232 | func (c *commonToSdkLibraryAndImport) sdkComponentPropertiesForChildLibrary() interface{} { | 
 | 1233 | 	componentProps := &struct { | 
| Paul Duffin | 3f0290e | 2021-06-30 18:25:36 +0100 | [diff] [blame] | 1234 | 		SdkLibraryName              *string | 
| Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 1235 | 		SdkLibraryToImplicitlyTrack *string | 
| Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 1236 | 	}{} | 
 | 1237 |  | 
| Paul Duffin | 3f0290e | 2021-06-30 18:25:36 +0100 | [diff] [blame] | 1238 | 	namePtr := proptools.StringPtr(c.module.BaseModuleName()) | 
 | 1239 | 	componentProps.SdkLibraryName = namePtr | 
 | 1240 |  | 
| Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 1241 | 	if c.sharedLibrary() { | 
| Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 1242 | 		// Mark the stubs library as being components of this java_sdk_library so that | 
 | 1243 | 		// any app that includes code which depends (directly or indirectly) on the stubs | 
 | 1244 | 		// library will have the appropriate <uses-library> invocation inserted into its | 
 | 1245 | 		// manifest if necessary. | 
| Paul Duffin | 3f0290e | 2021-06-30 18:25:36 +0100 | [diff] [blame] | 1246 | 		componentProps.SdkLibraryToImplicitlyTrack = namePtr | 
| Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 1247 | 	} | 
 | 1248 |  | 
 | 1249 | 	return componentProps | 
 | 1250 | } | 
 | 1251 |  | 
| Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 1252 | func (c *commonToSdkLibraryAndImport) sharedLibrary() bool { | 
 | 1253 | 	return proptools.BoolDefault(c.commonSdkLibraryProperties.Shared_library, true) | 
 | 1254 | } | 
 | 1255 |  | 
| Paul Duffin | f4600f6 | 2021-05-13 22:34:45 +0100 | [diff] [blame] | 1256 | // Check if the stub libraries should be compiled for dex | 
 | 1257 | func (c *commonToSdkLibraryAndImport) stubLibrariesCompiledForDex() bool { | 
 | 1258 | 	// Always compile the dex file files for the stub libraries if they will be used on the | 
 | 1259 | 	// bootclasspath. | 
 | 1260 | 	return !c.sharedLibrary() | 
 | 1261 | } | 
 | 1262 |  | 
| Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 1263 | // Properties related to the use of a module as an component of a java_sdk_library. | 
 | 1264 | type SdkLibraryComponentProperties struct { | 
| Paul Duffin | 3f0290e | 2021-06-30 18:25:36 +0100 | [diff] [blame] | 1265 | 	// The name of the java_sdk_library/_import module. | 
 | 1266 | 	SdkLibraryName *string `blueprint:"mutated"` | 
| Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 1267 |  | 
 | 1268 | 	// The name of the java_sdk_library/_import to add to a <uses-library> entry | 
 | 1269 | 	// in the AndroidManifest.xml of any Android app that includes code that references | 
 | 1270 | 	// this module. If not set then no java_sdk_library/_import is tracked. | 
 | 1271 | 	SdkLibraryToImplicitlyTrack *string `blueprint:"mutated"` | 
 | 1272 | } | 
 | 1273 |  | 
 | 1274 | // Structure to be embedded in a module struct that needs to support the | 
 | 1275 | // SdkLibraryComponentDependency interface. | 
 | 1276 | type EmbeddableSdkLibraryComponent struct { | 
 | 1277 | 	sdkLibraryComponentProperties SdkLibraryComponentProperties | 
 | 1278 | } | 
 | 1279 |  | 
| Paul Duffin | 71b33cc | 2021-06-23 11:39:47 +0100 | [diff] [blame] | 1280 | func (e *EmbeddableSdkLibraryComponent) initSdkLibraryComponent(module android.Module) { | 
 | 1281 | 	module.AddProperties(&e.sdkLibraryComponentProperties) | 
| Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 1282 | } | 
 | 1283 |  | 
 | 1284 | // to satisfy SdkLibraryComponentDependency | 
| Paul Duffin | 3f0290e | 2021-06-30 18:25:36 +0100 | [diff] [blame] | 1285 | func (e *EmbeddableSdkLibraryComponent) SdkLibraryName() *string { | 
 | 1286 | 	return e.sdkLibraryComponentProperties.SdkLibraryName | 
 | 1287 | } | 
 | 1288 |  | 
 | 1289 | // to satisfy SdkLibraryComponentDependency | 
| Ulya Trafimovich | 39b437b | 2020-09-23 16:42:35 +0100 | [diff] [blame] | 1290 | func (e *EmbeddableSdkLibraryComponent) OptionalSdkLibraryImplementation() *string { | 
| Ulya Trafimovich | 78645fb | 2021-07-16 15:29:25 +0100 | [diff] [blame] | 1291 | 	// For shared libraries, this is the same as the SDK library name. If a Java library or app | 
 | 1292 | 	// depends on a component library (e.g. a stub library) it still needs to know the name of the | 
 | 1293 | 	// run-time library and the corresponding module that provides the implementation. This name is | 
 | 1294 | 	// passed to manifest_fixer (to be added to AndroidManifest.xml) and added to CLC (to be used | 
 | 1295 | 	// in dexpreopt). | 
 | 1296 | 	// | 
 | 1297 | 	// For non-shared SDK (component or not) libraries this returns `nil`, as they are not | 
 | 1298 | 	// <uses-library> and should not be added to the manifest or to CLC. | 
| Ulya Trafimovich | 39b437b | 2020-09-23 16:42:35 +0100 | [diff] [blame] | 1299 | 	return e.sdkLibraryComponentProperties.SdkLibraryToImplicitlyTrack | 
 | 1300 | } | 
 | 1301 |  | 
| Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 1302 | // Implemented by modules that are (or possibly could be) a component of a java_sdk_library | 
 | 1303 | // (including the java_sdk_library) itself. | 
 | 1304 | type SdkLibraryComponentDependency interface { | 
| Ulya Trafimovich | 31e444e | 2020-08-14 17:32:16 +0100 | [diff] [blame] | 1305 | 	UsesLibraryDependency | 
 | 1306 |  | 
| Paul Duffin | 3f0290e | 2021-06-30 18:25:36 +0100 | [diff] [blame] | 1307 | 	// SdkLibraryName returns the name of the java_sdk_library/_import module. | 
 | 1308 | 	SdkLibraryName() *string | 
 | 1309 |  | 
| Ulya Trafimovich | 39b437b | 2020-09-23 16:42:35 +0100 | [diff] [blame] | 1310 | 	// The name of the implementation library for the optional SDK library or nil, if there isn't one. | 
 | 1311 | 	OptionalSdkLibraryImplementation() *string | 
| Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 1312 | } | 
 | 1313 |  | 
 | 1314 | // Make sure that all the module types that are components of java_sdk_library/_import | 
 | 1315 | // and which can be referenced (directly or indirectly) from an android app implement | 
 | 1316 | // the SdkLibraryComponentDependency interface. | 
 | 1317 | var _ SdkLibraryComponentDependency = (*Library)(nil) | 
 | 1318 | var _ SdkLibraryComponentDependency = (*Import)(nil) | 
 | 1319 | var _ SdkLibraryComponentDependency = (*SdkLibrary)(nil) | 
| Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 1320 | var _ SdkLibraryComponentDependency = (*SdkLibraryImport)(nil) | 
| Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 1321 |  | 
| Paul Duffin | 32cf58a | 2021-05-18 16:32:50 +0100 | [diff] [blame] | 1322 | // Provides access to sdk_version related files, e.g. header and implementation jars. | 
| Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 1323 | type SdkLibraryDependency interface { | 
 | 1324 | 	SdkLibraryComponentDependency | 
 | 1325 |  | 
 | 1326 | 	// Get the header jars appropriate for the supplied sdk_version. | 
 | 1327 | 	// | 
 | 1328 | 	// These are turbine generated jars so they only change if the externals of the | 
 | 1329 | 	// class changes but it does not contain and implementation or JavaDoc. | 
| Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 1330 | 	SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion android.SdkSpec) android.Paths | 
| Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 1331 |  | 
 | 1332 | 	// Get the implementation jars appropriate for the supplied sdk version. | 
 | 1333 | 	// | 
 | 1334 | 	// These are either the implementation jar for the whole sdk library or the implementation | 
 | 1335 | 	// jars for the stubs. The latter should only be needed when generating JavaDoc as otherwise | 
 | 1336 | 	// they are identical to the corresponding header jars. | 
| Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 1337 | 	SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion android.SdkSpec) android.Paths | 
| Paul Duffin | 1267d87 | 2021-04-16 17:21:36 +0100 | [diff] [blame] | 1338 |  | 
| Jihoon Kang | bd09345 | 2023-12-26 19:08:01 +0000 | [diff] [blame] | 1339 | 	// SdkApiStubDexJar returns the dex jar for the stubs for the prebuilt | 
 | 1340 | 	// java_sdk_library_import module. It is needed by the hiddenapi processing tool which | 
 | 1341 | 	// processes dex files. | 
| Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 1342 | 	SdkApiStubDexJar(ctx android.BaseModuleContext, kind android.SdkKind) OptionalDexJarPath | 
| Paul Duffin | f4600f6 | 2021-05-13 22:34:45 +0100 | [diff] [blame] | 1343 |  | 
| Jihoon Kang | bd09345 | 2023-12-26 19:08:01 +0000 | [diff] [blame] | 1344 | 	// SdkApiExportableStubDexJar returns the exportable dex jar for the stubs for | 
 | 1345 | 	// java_sdk_library module. It is needed by the hiddenapi processing tool which processes | 
 | 1346 | 	// dex files. | 
 | 1347 | 	SdkApiExportableStubDexJar(ctx android.BaseModuleContext, kind android.SdkKind) OptionalDexJarPath | 
 | 1348 |  | 
| Paul Duffin | 32cf58a | 2021-05-18 16:32:50 +0100 | [diff] [blame] | 1349 | 	// SdkRemovedTxtFile returns the optional path to the removed.txt file for the specified sdk kind. | 
 | 1350 | 	SdkRemovedTxtFile(ctx android.BaseModuleContext, kind android.SdkKind) android.OptionalPath | 
 | 1351 |  | 
| Paul Duffin | f4600f6 | 2021-05-13 22:34:45 +0100 | [diff] [blame] | 1352 | 	// sharedLibrary returns true if this can be used as a shared library. | 
 | 1353 | 	sharedLibrary() bool | 
| Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 1354 | } | 
 | 1355 |  | 
| Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 1356 | type SdkLibrary struct { | 
| Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1357 | 	Library | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1358 |  | 
| Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1359 | 	sdkLibraryProperties sdkLibraryProperties | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1360 |  | 
| Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 1361 | 	// Map from api scope to the scope specific property structure. | 
 | 1362 | 	scopeToProperties map[*apiScope]*ApiScopeProperties | 
 | 1363 |  | 
| Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 1364 | 	commonToSdkLibraryAndImport | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1365 | } | 
 | 1366 |  | 
| Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 1367 | var _ SdkLibraryDependency = (*SdkLibrary)(nil) | 
| Colin Cross | 897d2ed | 2019-02-11 14:03:51 -0800 | [diff] [blame] | 1368 |  | 
| Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 1369 | func (module *SdkLibrary) generateTestAndSystemScopesByDefault() bool { | 
 | 1370 | 	return module.sdkLibraryProperties.Generate_system_and_test_apis | 
 | 1371 | } | 
 | 1372 |  | 
 | 1373 | func (module *SdkLibrary) getGeneratedApiScopes(ctx android.EarlyModuleContext) apiScopes { | 
 | 1374 | 	// Check to see if any scopes have been explicitly enabled. If any have then all | 
 | 1375 | 	// must be. | 
 | 1376 | 	anyScopesExplicitlyEnabled := false | 
 | 1377 | 	for _, scope := range allApiScopes { | 
 | 1378 | 		scopeProperties := module.scopeToProperties[scope] | 
 | 1379 | 		if scopeProperties.Enabled != nil { | 
 | 1380 | 			anyScopesExplicitlyEnabled = true | 
 | 1381 | 			break | 
 | 1382 | 		} | 
| Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 1383 | 	} | 
| Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 1384 |  | 
 | 1385 | 	var generatedScopes apiScopes | 
 | 1386 | 	enabledScopes := make(map[*apiScope]struct{}) | 
 | 1387 | 	for _, scope := range allApiScopes { | 
 | 1388 | 		scopeProperties := module.scopeToProperties[scope] | 
 | 1389 | 		// If any scopes are explicitly enabled then ignore the legacy enabled status. | 
 | 1390 | 		// This is to ensure that any new usages of this module type do not rely on legacy | 
 | 1391 | 		// behaviour. | 
 | 1392 | 		defaultEnabledStatus := false | 
 | 1393 | 		if anyScopesExplicitlyEnabled { | 
 | 1394 | 			defaultEnabledStatus = scope.defaultEnabledStatus | 
 | 1395 | 		} else { | 
 | 1396 | 			defaultEnabledStatus = scope.legacyEnabledStatus(module) | 
 | 1397 | 		} | 
 | 1398 | 		enabled := proptools.BoolDefault(scopeProperties.Enabled, defaultEnabledStatus) | 
 | 1399 | 		if enabled { | 
 | 1400 | 			enabledScopes[scope] = struct{}{} | 
 | 1401 | 			generatedScopes = append(generatedScopes, scope) | 
 | 1402 | 		} | 
 | 1403 | 	} | 
 | 1404 |  | 
 | 1405 | 	// Now check to make sure that any scope that is extended by an enabled scope is also | 
 | 1406 | 	// enabled. | 
 | 1407 | 	for _, scope := range allApiScopes { | 
 | 1408 | 		if _, ok := enabledScopes[scope]; ok { | 
 | 1409 | 			extends := scope.extends | 
 | 1410 | 			if extends != nil { | 
 | 1411 | 				if _, ok := enabledScopes[extends]; !ok { | 
 | 1412 | 					ctx.ModuleErrorf("enabled api scope %q depends on disabled scope %q", scope, extends) | 
 | 1413 | 				} | 
 | 1414 | 			} | 
 | 1415 | 		} | 
 | 1416 | 	} | 
 | 1417 |  | 
 | 1418 | 	return generatedScopes | 
| Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 1419 | } | 
 | 1420 |  | 
| satayev | 758968a | 2021-12-06 11:42:40 +0000 | [diff] [blame] | 1421 | var _ android.ModuleWithMinSdkVersionCheck = (*SdkLibrary)(nil) | 
 | 1422 |  | 
| satayev | 8f088b0 | 2021-12-06 11:40:46 +0000 | [diff] [blame] | 1423 | func (module *SdkLibrary) CheckMinSdkVersion(ctx android.ModuleContext) { | 
| Spandan Das | 8c9ae7e | 2023-03-03 21:20:36 +0000 | [diff] [blame] | 1424 | 	android.CheckMinSdkVersion(ctx, module.MinSdkVersion(ctx), func(c android.ModuleContext, do android.PayloadDepsCallback) { | 
| satayev | 8f088b0 | 2021-12-06 11:40:46 +0000 | [diff] [blame] | 1425 | 		ctx.WalkDeps(func(child android.Module, parent android.Module) bool { | 
 | 1426 | 			isExternal := !module.depIsInSameApex(ctx, child) | 
 | 1427 | 			if am, ok := child.(android.ApexModule); ok { | 
 | 1428 | 				if !do(ctx, parent, am, isExternal) { | 
 | 1429 | 					return false | 
 | 1430 | 				} | 
 | 1431 | 			} | 
 | 1432 | 			return !isExternal | 
 | 1433 | 		}) | 
 | 1434 | 	}) | 
 | 1435 | } | 
 | 1436 |  | 
| Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 1437 | type sdkLibraryComponentTag struct { | 
 | 1438 | 	blueprint.BaseDependencyTag | 
 | 1439 | 	name string | 
 | 1440 | } | 
 | 1441 |  | 
 | 1442 | // Mark this tag so dependencies that use it are excluded from visibility enforcement. | 
 | 1443 | func (t sdkLibraryComponentTag) ExcludeFromVisibilityEnforcement() {} | 
 | 1444 |  | 
 | 1445 | var xmlPermissionsFileTag = sdkLibraryComponentTag{name: "xml-permissions-file"} | 
| Paul Duffin | e74ac73 | 2020-02-06 13:51:46 +0000 | [diff] [blame] | 1446 |  | 
| Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 1447 | func IsXmlPermissionsFileDepTag(depTag blueprint.DependencyTag) bool { | 
| Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 1448 | 	if dt, ok := depTag.(sdkLibraryComponentTag); ok { | 
| Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 1449 | 		return dt == xmlPermissionsFileTag | 
 | 1450 | 	} | 
 | 1451 | 	return false | 
 | 1452 | } | 
 | 1453 |  | 
| Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 1454 | var implLibraryTag = sdkLibraryComponentTag{name: "impl-library"} | 
| Paul Duffin | 5df7930 | 2020-05-16 15:52:12 +0100 | [diff] [blame] | 1455 |  | 
| Paul Duffin | 44f1d84 | 2020-06-26 20:17:02 +0100 | [diff] [blame] | 1456 | // Add the dependencies on the child modules in the component deps mutator. | 
 | 1457 | func (module *SdkLibrary) ComponentDepsMutator(ctx android.BottomUpMutatorContext) { | 
| Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 1458 | 	for _, apiScope := range module.getGeneratedApiScopes(ctx) { | 
| Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 1459 | 		// Add dependencies to the stubs library | 
| Spandan Das | 877f39d | 2023-03-29 16:19:51 +0000 | [diff] [blame] | 1460 | 		stubModuleName := module.stubsLibraryModuleName(apiScope) | 
| Jihoon Kang | bd09345 | 2023-12-26 19:08:01 +0000 | [diff] [blame] | 1461 | 		ctx.AddVariationDependencies(nil, apiScope.everythingStubsTag, stubModuleName) | 
| Jihoon Kang | 1147b31 | 2023-06-08 23:25:57 +0000 | [diff] [blame] | 1462 |  | 
| Jihoon Kang | bd09345 | 2023-12-26 19:08:01 +0000 | [diff] [blame] | 1463 | 		exportableStubModuleName := module.exportableStubsLibraryModuleName(apiScope) | 
 | 1464 | 		ctx.AddVariationDependencies(nil, apiScope.exportableStubsTag, exportableStubModuleName) | 
| Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 1465 |  | 
| Paul Duffin | 15f34ef | 2020-07-20 18:04:44 +0100 | [diff] [blame] | 1466 | 		// Add a dependency on the stubs source in order to access both stubs source and api information. | 
 | 1467 | 		ctx.AddVariationDependencies(nil, apiScope.stubsSourceAndApiTag, module.stubsSourceModuleName(apiScope)) | 
| Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 1468 |  | 
 | 1469 | 		if module.compareAgainstLatestApi(apiScope) { | 
 | 1470 | 			// Add dependencies on the latest finalized version of the API .txt file. | 
 | 1471 | 			latestApiModuleName := module.latestApiModuleName(apiScope) | 
 | 1472 | 			ctx.AddDependency(module, apiScope.latestApiModuleTag, latestApiModuleName) | 
 | 1473 |  | 
 | 1474 | 			// Add dependencies on the latest finalized version of the remove API .txt file. | 
 | 1475 | 			latestRemovedApiModuleName := module.latestRemovedApiModuleName(apiScope) | 
 | 1476 | 			ctx.AddDependency(module, apiScope.latestRemovedApiModuleTag, latestRemovedApiModuleName) | 
 | 1477 | 		} | 
| Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1478 | 	} | 
 | 1479 |  | 
| Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 1480 | 	if module.requiresRuntimeImplementationLibrary() { | 
| Paul Duffin | 5df7930 | 2020-05-16 15:52:12 +0100 | [diff] [blame] | 1481 | 		// Add dependency to the rule for generating the implementation library. | 
 | 1482 | 		ctx.AddDependency(module, implLibraryTag, module.implLibraryModuleName()) | 
 | 1483 |  | 
| Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 1484 | 		if module.sharedLibrary() { | 
 | 1485 | 			// Add dependency to the rule for generating the xml permissions file | 
| Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 1486 | 			ctx.AddDependency(module, xmlPermissionsFileTag, module.xmlPermissionsModuleName()) | 
| Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 1487 | 		} | 
| Paul Duffin | 44f1d84 | 2020-06-26 20:17:02 +0100 | [diff] [blame] | 1488 | 	} | 
 | 1489 | } | 
| Paul Duffin | e74ac73 | 2020-02-06 13:51:46 +0000 | [diff] [blame] | 1490 |  | 
| Paul Duffin | 44f1d84 | 2020-06-26 20:17:02 +0100 | [diff] [blame] | 1491 | // Add other dependencies as normal. | 
 | 1492 | func (module *SdkLibrary) DepsMutator(ctx android.BottomUpMutatorContext) { | 
| Anton Hansson | e77fccc | 2021-01-20 16:52:41 +0000 | [diff] [blame] | 1493 | 	var missingApiModules []string | 
 | 1494 | 	for _, apiScope := range module.getGeneratedApiScopes(ctx) { | 
 | 1495 | 		if apiScope.unstable { | 
 | 1496 | 			continue | 
 | 1497 | 		} | 
| Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 1498 | 		if m := module.latestApiModuleName(apiScope); !ctx.OtherModuleExists(m) { | 
| Anton Hansson | e77fccc | 2021-01-20 16:52:41 +0000 | [diff] [blame] | 1499 | 			missingApiModules = append(missingApiModules, m) | 
 | 1500 | 		} | 
| Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 1501 | 		if m := module.latestRemovedApiModuleName(apiScope); !ctx.OtherModuleExists(m) { | 
| Anton Hansson | e77fccc | 2021-01-20 16:52:41 +0000 | [diff] [blame] | 1502 | 			missingApiModules = append(missingApiModules, m) | 
 | 1503 | 		} | 
| Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 1504 | 		if m := module.latestIncompatibilitiesModuleName(apiScope); !ctx.OtherModuleExists(m) { | 
| Jaewoong Jung | 1a97ee0 | 2021-03-09 13:25:02 -0800 | [diff] [blame] | 1505 | 			missingApiModules = append(missingApiModules, m) | 
 | 1506 | 		} | 
| Anton Hansson | e77fccc | 2021-01-20 16:52:41 +0000 | [diff] [blame] | 1507 | 	} | 
 | 1508 | 	if len(missingApiModules) != 0 && !module.sdkLibraryProperties.Unsafe_ignore_missing_latest_api { | 
 | 1509 | 		m := module.Name() + " is missing tracking files for previously released library versions.\n" | 
 | 1510 | 		m += "You need to do one of the following:\n" | 
 | 1511 | 		m += "- Add `unsafe_ignore_missing_latest_api: true` to your blueprint (to disable compat tracking)\n" | 
 | 1512 | 		m += "- Add a set of prebuilt txt files representing the last released version of this library for compat checking.\n" | 
 | 1513 | 		m += "  (the current set of API files can be used as a seed for this compatibility tracking\n" | 
 | 1514 | 		m += "\n" | 
 | 1515 | 		m += "The following filegroup modules are missing:\n  " | 
 | 1516 | 		m += strings.Join(missingApiModules, "\n  ") + "\n" | 
 | 1517 | 		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." | 
 | 1518 | 		ctx.ModuleErrorf(m) | 
 | 1519 | 	} | 
| Paul Duffin | 44f1d84 | 2020-06-26 20:17:02 +0100 | [diff] [blame] | 1520 | 	if module.requiresRuntimeImplementationLibrary() { | 
| Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 1521 | 		// Only add the deps for the library if it is actually going to be built. | 
 | 1522 | 		module.Library.deps(ctx) | 
 | 1523 | 	} | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1524 | } | 
 | 1525 |  | 
| Paul Duffin | 46dc45a | 2020-05-14 15:39:10 +0100 | [diff] [blame] | 1526 | func (module *SdkLibrary) OutputFiles(tag string) (android.Paths, error) { | 
 | 1527 | 	paths, err := module.commonOutputFiles(tag) | 
| Colin Cross | 4acaea9 | 2021-12-10 23:05:02 +0000 | [diff] [blame] | 1528 | 	if paths != nil || err != nil { | 
| Paul Duffin | 46dc45a | 2020-05-14 15:39:10 +0100 | [diff] [blame] | 1529 | 		return paths, err | 
 | 1530 | 	} | 
| Colin Cross | 4acaea9 | 2021-12-10 23:05:02 +0000 | [diff] [blame] | 1531 | 	if module.requiresRuntimeImplementationLibrary() { | 
 | 1532 | 		return module.Library.OutputFiles(tag) | 
 | 1533 | 	} | 
 | 1534 | 	if tag == "" { | 
 | 1535 | 		return nil, nil | 
 | 1536 | 	} | 
 | 1537 | 	return nil, fmt.Errorf("unsupported module reference tag %q", tag) | 
| Paul Duffin | 46dc45a | 2020-05-14 15:39:10 +0100 | [diff] [blame] | 1538 | } | 
 | 1539 |  | 
| Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 1540 | func (module *SdkLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) { | 
| satayev | 8f088b0 | 2021-12-06 11:40:46 +0000 | [diff] [blame] | 1541 | 	if proptools.String(module.deviceProperties.Min_sdk_version) != "" { | 
 | 1542 | 		module.CheckMinSdkVersion(ctx) | 
 | 1543 | 	} | 
 | 1544 |  | 
| Paul Duffin | a2ae7e0 | 2020-09-11 11:55:00 +0100 | [diff] [blame] | 1545 | 	module.generateCommonBuildActions(ctx) | 
 | 1546 |  | 
| Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 1547 | 	// Only build an implementation library if required. | 
 | 1548 | 	if module.requiresRuntimeImplementationLibrary() { | 
| Paul Duffin | 43db9be | 2019-12-30 17:35:49 +0000 | [diff] [blame] | 1549 | 		module.Library.GenerateAndroidBuildActions(ctx) | 
 | 1550 | 	} | 
| Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1551 |  | 
| Paul Duffin | b97b157 | 2021-04-29 21:50:40 +0100 | [diff] [blame] | 1552 | 	// Collate the components exported by this module. All scope specific modules are exported but | 
 | 1553 | 	// the impl and xml component modules are not. | 
 | 1554 | 	exportedComponents := map[string]struct{}{} | 
 | 1555 |  | 
| Sundong Ahn | 57368eb | 2018-07-06 11:20:23 +0900 | [diff] [blame] | 1556 | 	// Record the paths to the header jars of the library (stubs and impl). | 
| Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 1557 | 	// When this java_sdk_library is depended upon from others via "libs" property, | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1558 | 	// the recorded paths will be returned depending on the link type of the caller. | 
 | 1559 | 	ctx.VisitDirectDeps(func(to android.Module) { | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1560 | 		tag := ctx.OtherModuleDependencyTag(to) | 
 | 1561 |  | 
| Paul Duffin | c878250 | 2020-04-29 20:45:27 +0100 | [diff] [blame] | 1562 | 		// Extract information from any of the scope specific dependencies. | 
 | 1563 | 		if scopeTag, ok := tag.(scopeDependencyTag); ok { | 
 | 1564 | 			apiScope := scopeTag.apiScope | 
| Paul Duffin | 803a956 | 2020-05-20 11:52:25 +0100 | [diff] [blame] | 1565 | 			scopePaths := module.getScopePathsCreateIfNeeded(apiScope) | 
| Paul Duffin | c878250 | 2020-04-29 20:45:27 +0100 | [diff] [blame] | 1566 |  | 
 | 1567 | 			// Extract information from the dependency. The exact information extracted | 
 | 1568 | 			// is determined by the nature of the dependency which is determined by the tag. | 
 | 1569 | 			scopeTag.extractDepInfo(ctx, to, scopePaths) | 
| Paul Duffin | b97b157 | 2021-04-29 21:50:40 +0100 | [diff] [blame] | 1570 |  | 
 | 1571 | 			exportedComponents[ctx.OtherModuleName(to)] = struct{}{} | 
| Sundong Ahn | 20e998b | 2018-07-24 11:19:26 +0900 | [diff] [blame] | 1572 | 		} | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1573 | 	}) | 
| Paul Duffin | b97b157 | 2021-04-29 21:50:40 +0100 | [diff] [blame] | 1574 |  | 
 | 1575 | 	// Make the set of components exported by this module available for use elsewhere. | 
| Cole Faust | 18994c7 | 2023-02-28 16:02:16 -0800 | [diff] [blame] | 1576 | 	exportedComponentInfo := android.ExportedComponentsInfo{Components: android.SortedKeys(exportedComponents)} | 
| Colin Cross | 4021302 | 2023-12-13 15:19:49 -0800 | [diff] [blame] | 1577 | 	android.SetProvider(ctx, android.ExportedComponentsInfoProvider, exportedComponentInfo) | 
| Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 1578 |  | 
 | 1579 | 	// Provide additional information for inclusion in an sdk's generated .info file. | 
 | 1580 | 	additionalSdkInfo := map[string]interface{}{} | 
 | 1581 | 	additionalSdkInfo["dist_stem"] = module.distStem() | 
| Paul Duffin | e840995 | 2022-09-22 16:24:46 +0100 | [diff] [blame] | 1582 | 	baseModuleName := module.distStem() | 
| Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 1583 | 	scopes := map[string]interface{}{} | 
 | 1584 | 	additionalSdkInfo["scopes"] = scopes | 
 | 1585 | 	for scope, scopePaths := range module.scopePaths { | 
 | 1586 | 		scopeInfo := map[string]interface{}{} | 
 | 1587 | 		scopes[scope.name] = scopeInfo | 
 | 1588 | 		scopeInfo["current_api"] = scope.snapshotRelativeCurrentApiTxtPath(baseModuleName) | 
 | 1589 | 		scopeInfo["removed_api"] = scope.snapshotRelativeRemovedApiTxtPath(baseModuleName) | 
 | 1590 | 		if p := scopePaths.latestApiPath; p.Valid() { | 
 | 1591 | 			scopeInfo["latest_api"] = p.Path().String() | 
 | 1592 | 		} | 
 | 1593 | 		if p := scopePaths.latestRemovedApiPath; p.Valid() { | 
 | 1594 | 			scopeInfo["latest_removed_api"] = p.Path().String() | 
 | 1595 | 		} | 
 | 1596 | 	} | 
| Colin Cross | 4021302 | 2023-12-13 15:19:49 -0800 | [diff] [blame] | 1597 | 	android.SetProvider(ctx, android.AdditionalSdkInfoProvider, android.AdditionalSdkInfo{additionalSdkInfo}) | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1598 | } | 
 | 1599 |  | 
| Jiyong Park | 0b0e1b9 | 2019-12-03 13:24:29 +0900 | [diff] [blame] | 1600 | func (module *SdkLibrary) AndroidMkEntries() []android.AndroidMkEntries { | 
| Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 1601 | 	if !module.requiresRuntimeImplementationLibrary() { | 
| Paul Duffin | 43db9be | 2019-12-30 17:35:49 +0000 | [diff] [blame] | 1602 | 		return nil | 
 | 1603 | 	} | 
| Jiyong Park | 0b0e1b9 | 2019-12-03 13:24:29 +0900 | [diff] [blame] | 1604 | 	entriesList := module.Library.AndroidMkEntries() | 
| Yo Chiang | 07d7507 | 2020-06-05 17:43:19 +0800 | [diff] [blame] | 1605 | 	if module.sharedLibrary() { | 
 | 1606 | 		entries := &entriesList[0] | 
 | 1607 | 		entries.Required = append(entries.Required, module.xmlPermissionsModuleName()) | 
 | 1608 | 	} | 
| Jiyong Park | 0b0e1b9 | 2019-12-03 13:24:29 +0900 | [diff] [blame] | 1609 | 	return entriesList | 
| Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 1610 | } | 
 | 1611 |  | 
| Anton Hansson | 5fd5d24 | 2020-03-27 19:43:19 +0000 | [diff] [blame] | 1612 | // The dist path of the stub artifacts | 
 | 1613 | func (module *SdkLibrary) apiDistPath(apiScope *apiScope) string { | 
| Colin Cross | f0eace9 | 2021-06-02 13:02:23 -0700 | [diff] [blame] | 1614 | 	return path.Join("apistubs", module.distGroup(), apiScope.name) | 
| Anton Hansson | 5fd5d24 | 2020-03-27 19:43:19 +0000 | [diff] [blame] | 1615 | } | 
 | 1616 |  | 
| Paul Duffin | 12ceb46 | 2019-12-24 20:31:31 +0000 | [diff] [blame] | 1617 | // Get the sdk version for use when compiling the stubs library. | 
| Paul Duffin | 780c5f4 | 2020-05-12 15:52:55 +0100 | [diff] [blame] | 1618 | func (module *SdkLibrary) sdkVersionForStubsLibrary(mctx android.EarlyModuleContext, apiScope *apiScope) string { | 
| Paul Duffin | 87a05a3 | 2020-05-12 11:50:28 +0100 | [diff] [blame] | 1619 | 	scopeProperties := module.scopeToProperties[apiScope] | 
 | 1620 | 	if scopeProperties.Sdk_version != nil { | 
 | 1621 | 		return proptools.String(scopeProperties.Sdk_version) | 
 | 1622 | 	} | 
 | 1623 |  | 
| Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 1624 | 	sdkDep := decodeSdkDep(mctx, android.SdkContext(&module.Library)) | 
| Paul Duffin | 12ceb46 | 2019-12-24 20:31:31 +0000 | [diff] [blame] | 1625 | 	if sdkDep.hasStandardLibs() { | 
 | 1626 | 		// If building against a standard sdk then use the sdk version appropriate for the scope. | 
| Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 1627 | 		return apiScope.sdkVersion | 
| Paul Duffin | 12ceb46 | 2019-12-24 20:31:31 +0000 | [diff] [blame] | 1628 | 	} else { | 
 | 1629 | 		// Otherwise, use no system module. | 
 | 1630 | 		return "none" | 
 | 1631 | 	} | 
 | 1632 | } | 
 | 1633 |  | 
| Paul Duffin | 3131025 | 2020-11-20 21:26:20 +0000 | [diff] [blame] | 1634 | func (module *SdkLibrary) distStem() string { | 
 | 1635 | 	return proptools.StringDefault(module.sdkLibraryProperties.Dist_stem, module.BaseModuleName()) | 
 | 1636 | } | 
 | 1637 |  | 
| Colin Cross | 986b69a | 2021-06-01 13:13:40 -0700 | [diff] [blame] | 1638 | // distGroup returns the subdirectory of the dist path of the stub artifacts. | 
 | 1639 | func (module *SdkLibrary) distGroup() string { | 
| Colin Cross | 59b92bf | 2021-06-01 14:07:56 -0700 | [diff] [blame] | 1640 | 	return proptools.StringDefault(module.sdkLibraryProperties.Dist_group, "unknown") | 
| Colin Cross | 986b69a | 2021-06-01 13:13:40 -0700 | [diff] [blame] | 1641 | } | 
 | 1642 |  | 
| Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 1643 | func latestPrebuiltApiModuleName(name string, apiScope *apiScope) string { | 
 | 1644 | 	return PrebuiltApiModuleName(name, apiScope.name, "latest") | 
 | 1645 | } | 
 | 1646 |  | 
| Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 1647 | func (module *SdkLibrary) latestApiFilegroupName(apiScope *apiScope) string { | 
| Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 1648 | 	return ":" + module.latestApiModuleName(apiScope) | 
 | 1649 | } | 
 | 1650 |  | 
 | 1651 | func (module *SdkLibrary) latestApiModuleName(apiScope *apiScope) string { | 
 | 1652 | 	return latestPrebuiltApiModuleName(module.distStem(), apiScope) | 
| Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 1653 | } | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1654 |  | 
| Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 1655 | func (module *SdkLibrary) latestRemovedApiFilegroupName(apiScope *apiScope) string { | 
| Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 1656 | 	return ":" + module.latestRemovedApiModuleName(apiScope) | 
 | 1657 | } | 
 | 1658 |  | 
 | 1659 | func (module *SdkLibrary) latestRemovedApiModuleName(apiScope *apiScope) string { | 
 | 1660 | 	return latestPrebuiltApiModuleName(module.distStem()+"-removed", apiScope) | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1661 | } | 
 | 1662 |  | 
| Jaewoong Jung | 1a97ee0 | 2021-03-09 13:25:02 -0800 | [diff] [blame] | 1663 | func (module *SdkLibrary) latestIncompatibilitiesFilegroupName(apiScope *apiScope) string { | 
| Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 1664 | 	return ":" + module.latestIncompatibilitiesModuleName(apiScope) | 
 | 1665 | } | 
 | 1666 |  | 
 | 1667 | func (module *SdkLibrary) latestIncompatibilitiesModuleName(apiScope *apiScope) string { | 
 | 1668 | 	return latestPrebuiltApiModuleName(module.distStem()+"-incompatibilities", apiScope) | 
| Jaewoong Jung | 1a97ee0 | 2021-03-09 13:25:02 -0800 | [diff] [blame] | 1669 | } | 
 | 1670 |  | 
| Jihoon Kang | 1c92c3e | 2023-03-23 17:44:51 +0000 | [diff] [blame] | 1671 | func (module *SdkLibrary) contributesToApiSurface(c android.Config) bool { | 
 | 1672 | 	_, exists := c.GetApiLibraries()[module.Name()] | 
 | 1673 | 	return exists | 
 | 1674 | } | 
 | 1675 |  | 
| Jihoon Kang | 0c705a4 | 2023-08-02 06:44:57 +0000 | [diff] [blame] | 1676 | // The listed modules are the special java_sdk_libraries where apiScope.kind do not match the | 
 | 1677 | // api surface that the module contribute to. For example, the public droidstubs and java_library | 
 | 1678 | // do not contribute to the public api surface, but contributes to the core platform api surface. | 
 | 1679 | // This method returns the full api surface stub lib that | 
 | 1680 | // the generated java_api_library should depend on. | 
 | 1681 | func (module *SdkLibrary) alternativeFullApiSurfaceStubLib() string { | 
 | 1682 | 	if val, ok := apiLibraryAdditionalProperties[module.Name()]; ok { | 
 | 1683 | 		return val.FullApiSurfaceStubLib | 
 | 1684 | 	} | 
 | 1685 | 	return "" | 
 | 1686 | } | 
 | 1687 |  | 
 | 1688 | // The listed modules' stubs contents do not match the corresponding txt files, | 
 | 1689 | // but require additional api contributions to generate the full stubs. | 
 | 1690 | // This method returns the name of the additional api contribution module | 
 | 1691 | // for corresponding sdk_library modules. | 
 | 1692 | func (module *SdkLibrary) apiLibraryAdditionalApiContribution() string { | 
 | 1693 | 	if val, ok := apiLibraryAdditionalProperties[module.Name()]; ok { | 
 | 1694 | 		return val.AdditionalApiContribution | 
 | 1695 | 	} | 
 | 1696 | 	return "" | 
 | 1697 | } | 
 | 1698 |  | 
| Anton Hansson | 944e77d | 2020-08-19 11:40:22 +0100 | [diff] [blame] | 1699 | func childModuleVisibility(childVisibility []string) []string { | 
 | 1700 | 	if childVisibility == nil { | 
 | 1701 | 		// No child visibility set. The child will use the visibility of the sdk_library. | 
 | 1702 | 		return nil | 
 | 1703 | 	} | 
 | 1704 |  | 
 | 1705 | 	// Prepend an override to ignore the sdk_library's visibility, and rely on the child visibility. | 
 | 1706 | 	var visibility []string | 
 | 1707 | 	visibility = append(visibility, "//visibility:override") | 
 | 1708 | 	visibility = append(visibility, childVisibility...) | 
 | 1709 | 	return visibility | 
 | 1710 | } | 
 | 1711 |  | 
| Paul Duffin | 5df7930 | 2020-05-16 15:52:12 +0100 | [diff] [blame] | 1712 | // Creates the implementation java library | 
 | 1713 | func (module *SdkLibrary) createImplLibrary(mctx android.DefaultableHookContext) { | 
| Anton Hansson | 944e77d | 2020-08-19 11:40:22 +0100 | [diff] [blame] | 1714 | 	visibility := childModuleVisibility(module.sdkLibraryProperties.Impl_library_visibility) | 
 | 1715 |  | 
| Paul Duffin | 5df7930 | 2020-05-16 15:52:12 +0100 | [diff] [blame] | 1716 | 	props := struct { | 
| Paul Duffin | 77590a8 | 2022-04-28 14:13:30 +0000 | [diff] [blame] | 1717 | 		Name           *string | 
 | 1718 | 		Visibility     []string | 
 | 1719 | 		Instrument     bool | 
 | 1720 | 		Libs           []string | 
 | 1721 | 		Static_libs    []string | 
 | 1722 | 		Apex_available []string | 
| Paul Duffin | 5df7930 | 2020-05-16 15:52:12 +0100 | [diff] [blame] | 1723 | 	}{ | 
 | 1724 | 		Name:       proptools.StringPtr(module.implLibraryModuleName()), | 
| Anton Hansson | 944e77d | 2020-08-19 11:40:22 +0100 | [diff] [blame] | 1725 | 		Visibility: visibility, | 
| Paul Duffin | 296cf33 | 2020-06-18 21:09:55 +0100 | [diff] [blame] | 1726 | 		// Set the instrument property to ensure it is instrumented when instrumentation is required. | 
 | 1727 | 		Instrument: true, | 
| Anton Hansson | 7f66efa | 2020-10-08 14:47:23 +0100 | [diff] [blame] | 1728 | 		// Set the impl_only libs. Note that the module's "Libs" get appended as well, via the | 
 | 1729 | 		// addition of &module.properties below. | 
 | 1730 | 		Libs: module.sdkLibraryProperties.Impl_only_libs, | 
| Paul Duffin | 77590a8 | 2022-04-28 14:13:30 +0000 | [diff] [blame] | 1731 | 		// Set the impl_only static libs. Note that the module's "static_libs" get appended as well, via the | 
 | 1732 | 		// addition of &module.properties below. | 
 | 1733 | 		Static_libs: module.sdkLibraryProperties.Impl_only_static_libs, | 
 | 1734 | 		// Pass the apex_available settings down so that the impl library can be statically | 
 | 1735 | 		// embedded within a library that is added to an APEX. Needed for updatable-media. | 
 | 1736 | 		Apex_available: module.ApexAvailable(), | 
| Paul Duffin | 5df7930 | 2020-05-16 15:52:12 +0100 | [diff] [blame] | 1737 | 	} | 
 | 1738 |  | 
 | 1739 | 	properties := []interface{}{ | 
 | 1740 | 		&module.properties, | 
 | 1741 | 		&module.protoProperties, | 
 | 1742 | 		&module.deviceProperties, | 
| Liz Kammer | a7a64f3 | 2020-07-09 15:16:41 -0700 | [diff] [blame] | 1743 | 		&module.dexProperties, | 
| Paul Duffin | 5df7930 | 2020-05-16 15:52:12 +0100 | [diff] [blame] | 1744 | 		&module.dexpreoptProperties, | 
| Colin Cross | 014489c | 2020-06-02 20:09:13 -0700 | [diff] [blame] | 1745 | 		&module.linter.properties, | 
| Paul Duffin | 5df7930 | 2020-05-16 15:52:12 +0100 | [diff] [blame] | 1746 | 		&props, | 
 | 1747 | 		module.sdkComponentPropertiesForChildLibrary(), | 
 | 1748 | 	} | 
 | 1749 | 	mctx.CreateModule(LibraryFactory, properties...) | 
 | 1750 | } | 
 | 1751 |  | 
| Jihoon Kang | fa4a90d | 2023-12-20 02:53:38 +0000 | [diff] [blame] | 1752 | type libraryProperties struct { | 
 | 1753 | 	Name           *string | 
 | 1754 | 	Visibility     []string | 
 | 1755 | 	Srcs           []string | 
 | 1756 | 	Installable    *bool | 
 | 1757 | 	Sdk_version    *string | 
 | 1758 | 	System_modules *string | 
 | 1759 | 	Patch_module   *string | 
 | 1760 | 	Libs           []string | 
 | 1761 | 	Static_libs    []string | 
 | 1762 | 	Compile_dex    *bool | 
 | 1763 | 	Java_version   *string | 
 | 1764 | 	Openjdk9       struct { | 
 | 1765 | 		Srcs       []string | 
 | 1766 | 		Javacflags []string | 
 | 1767 | 	} | 
 | 1768 | 	Dist struct { | 
 | 1769 | 		Targets []string | 
 | 1770 | 		Dest    *string | 
 | 1771 | 		Dir     *string | 
 | 1772 | 		Tag     *string | 
 | 1773 | 	} | 
 | 1774 | } | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1775 |  | 
| Jihoon Kang | fa4a90d | 2023-12-20 02:53:38 +0000 | [diff] [blame] | 1776 | func (module *SdkLibrary) stubsLibraryProps(mctx android.DefaultableHookContext, apiScope *apiScope) libraryProperties { | 
 | 1777 | 	props := libraryProperties{} | 
| Jihoon Kang | 786df93 | 2023-09-07 01:18:31 +0000 | [diff] [blame] | 1778 | 	props.Visibility = []string{"//visibility:override", "//visibility:private"} | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1779 | 	// sources are generated from the droiddoc | 
| Paul Duffin | 12ceb46 | 2019-12-24 20:31:31 +0000 | [diff] [blame] | 1780 | 	sdkVersion := module.sdkVersionForStubsLibrary(mctx, apiScope) | 
| Paul Duffin | 52d398a | 2019-06-11 12:31:14 +0100 | [diff] [blame] | 1781 | 	props.Sdk_version = proptools.StringPtr(sdkVersion) | 
| Paul Duffin | a18abc2 | 2020-05-16 18:54:24 +0100 | [diff] [blame] | 1782 | 	props.System_modules = module.deviceProperties.System_modules | 
 | 1783 | 	props.Patch_module = module.properties.Patch_module | 
| Paul Duffin | 367ab91 | 2019-12-23 19:40:36 +0000 | [diff] [blame] | 1784 | 	props.Installable = proptools.BoolPtr(false) | 
| Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1785 | 	props.Libs = module.sdkLibraryProperties.Stub_only_libs | 
| Mark White | 9421c4c | 2023-08-10 00:07:03 +0000 | [diff] [blame] | 1786 | 	props.Libs = append(props.Libs, module.scopeToProperties[apiScope].Libs...) | 
| Anton Hansson | dae54cd | 2021-04-21 16:30:10 +0100 | [diff] [blame] | 1787 | 	props.Static_libs = module.sdkLibraryProperties.Stub_only_static_libs | 
| Paul Duffin | e22c2ab | 2020-05-20 19:35:27 +0100 | [diff] [blame] | 1788 | 	// The stub-annotations library contains special versions of the annotations | 
 | 1789 | 	// with CLASS retention policy, so that they're kept. | 
 | 1790 | 	if proptools.Bool(module.sdkLibraryProperties.Annotations_enabled) { | 
 | 1791 | 		props.Libs = append(props.Libs, "stub-annotations") | 
 | 1792 | 	} | 
| Paul Duffin | a18abc2 | 2020-05-16 18:54:24 +0100 | [diff] [blame] | 1793 | 	props.Openjdk9.Srcs = module.properties.Openjdk9.Srcs | 
 | 1794 | 	props.Openjdk9.Javacflags = module.properties.Openjdk9.Javacflags | 
| Anton Hansson | 83509b5 | 2020-05-21 09:21:57 +0100 | [diff] [blame] | 1795 | 	// We compile the stubs for 1.8 in line with the main android.jar stubs, and potential | 
 | 1796 | 	// interop with older developer tools that don't support 1.9. | 
 | 1797 | 	props.Java_version = proptools.StringPtr("1.8") | 
| Paul Duffin | f4600f6 | 2021-05-13 22:34:45 +0100 | [diff] [blame] | 1798 |  | 
| Jihoon Kang | fa4a90d | 2023-12-20 02:53:38 +0000 | [diff] [blame] | 1799 | 	return props | 
 | 1800 | } | 
 | 1801 |  | 
 | 1802 | // Creates a static java library that has API stubs | 
 | 1803 | func (module *SdkLibrary) createStubsLibrary(mctx android.DefaultableHookContext, apiScope *apiScope) { | 
 | 1804 |  | 
 | 1805 | 	props := module.stubsLibraryProps(mctx, apiScope) | 
 | 1806 | 	props.Name = proptools.StringPtr(module.sourceStubsLibraryModuleName(apiScope)) | 
 | 1807 | 	props.Srcs = []string{":" + module.stubsSourceModuleName(apiScope)} | 
 | 1808 |  | 
 | 1809 | 	mctx.CreateModule(LibraryFactory, &props, module.sdkComponentPropertiesForChildLibrary()) | 
 | 1810 | } | 
 | 1811 |  | 
 | 1812 | // Create a static java library that compiles the "exportable" stubs | 
 | 1813 | func (module *SdkLibrary) createExportableStubsLibrary(mctx android.DefaultableHookContext, apiScope *apiScope) { | 
 | 1814 | 	props := module.stubsLibraryProps(mctx, apiScope) | 
 | 1815 | 	props.Name = proptools.StringPtr(module.exportableSourceStubsLibraryModuleName(apiScope)) | 
 | 1816 | 	props.Srcs = []string{":" + module.stubsSourceModuleName(apiScope) + "{.exportable}"} | 
 | 1817 |  | 
| Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 1818 | 	mctx.CreateModule(LibraryFactory, &props, module.sdkComponentPropertiesForChildLibrary()) | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1819 | } | 
 | 1820 |  | 
| Paul Duffin | 6d0886e | 2020-04-07 18:49:53 +0100 | [diff] [blame] | 1821 | // Creates a droidstubs module that creates stubs source files from the given full source | 
| Paul Duffin | c878250 | 2020-04-29 20:45:27 +0100 | [diff] [blame] | 1822 | // files and also updates and checks the API specification files. | 
| Paul Duffin | 15f34ef | 2020-07-20 18:04:44 +0100 | [diff] [blame] | 1823 | func (module *SdkLibrary) createStubsSourcesAndApi(mctx android.DefaultableHookContext, apiScope *apiScope, name string, scopeSpecificDroidstubsArgs []string) { | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1824 | 	props := struct { | 
| Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1825 | 		Name                             *string | 
| Paul Duffin | 4911a89 | 2020-04-29 23:35:13 +0100 | [diff] [blame] | 1826 | 		Visibility                       []string | 
| Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1827 | 		Srcs                             []string | 
 | 1828 | 		Installable                      *bool | 
| Paul Duffin | 52d398a | 2019-06-11 12:31:14 +0100 | [diff] [blame] | 1829 | 		Sdk_version                      *string | 
| Jihoon Kang | 3198f3c | 2023-01-26 08:08:52 +0000 | [diff] [blame] | 1830 | 		Api_surface                      *string | 
| Paul Duffin | 12ceb46 | 2019-12-24 20:31:31 +0000 | [diff] [blame] | 1831 | 		System_modules                   *string | 
| Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1832 | 		Libs                             []string | 
| Paul Duffin | 6877e6d | 2020-09-25 19:59:14 +0100 | [diff] [blame] | 1833 | 		Output_javadoc_comments          *bool | 
| Paul Duffin | 1151247 | 2019-02-11 15:55:17 +0000 | [diff] [blame] | 1834 | 		Arg_files                        []string | 
| Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1835 | 		Args                             *string | 
| Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1836 | 		Java_version                     *string | 
| Paul Duffin | e22c2ab | 2020-05-20 19:35:27 +0100 | [diff] [blame] | 1837 | 		Annotations_enabled              *bool | 
| Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1838 | 		Merge_annotations_dirs           []string | 
 | 1839 | 		Merge_inclusion_annotations_dirs []string | 
| Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 1840 | 		Generate_stubs                   *bool | 
| Anton Hansson | e87b03d | 2020-12-21 15:29:34 +0000 | [diff] [blame] | 1841 | 		Previous_api                     *string | 
| Jihoon Kang | 6592e87 | 2023-12-19 01:13:16 +0000 | [diff] [blame] | 1842 | 		Aconfig_declarations             []string | 
| Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1843 | 		Check_api                        struct { | 
| Anton Hansson | e605615 | 2020-12-31 10:37:27 +0000 | [diff] [blame] | 1844 | 			Current       ApiToCheck | 
 | 1845 | 			Last_released ApiToCheck | 
| Paul Duffin | 160fe41 | 2020-05-10 19:32:20 +0100 | [diff] [blame] | 1846 |  | 
 | 1847 | 			Api_lint struct { | 
 | 1848 | 				Enabled       *bool | 
 | 1849 | 				New_since     *string | 
 | 1850 | 				Baseline_file *string | 
 | 1851 | 			} | 
| Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 1852 | 		} | 
| Sundong Ahn | 1b92c82 | 2018-05-29 11:35:17 +0900 | [diff] [blame] | 1853 | 		Aidl struct { | 
 | 1854 | 			Include_dirs       []string | 
 | 1855 | 			Local_include_dirs []string | 
 | 1856 | 		} | 
| Paul Duffin | 040e906 | 2020-11-23 17:41:36 +0000 | [diff] [blame] | 1857 | 		Dists []android.Dist | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1858 | 	}{} | 
 | 1859 |  | 
| Paul Duffin | 7b78b4d | 2020-04-28 14:08:32 +0100 | [diff] [blame] | 1860 | 	// The stubs source processing uses the same compile time classpath when extracting the | 
 | 1861 | 	// API from the implementation library as it does when compiling it. i.e. the same | 
 | 1862 | 	// * sdk version | 
 | 1863 | 	// * system_modules | 
 | 1864 | 	// * libs (static_libs/libs) | 
| Paul Duffin | 250e619 | 2019-06-07 10:44:37 +0100 | [diff] [blame] | 1865 |  | 
| Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 1866 | 	props.Name = proptools.StringPtr(name) | 
| Anton Hansson | 944e77d | 2020-08-19 11:40:22 +0100 | [diff] [blame] | 1867 | 	props.Visibility = childModuleVisibility(module.sdkLibraryProperties.Stubs_source_visibility) | 
| Paul Duffin | a18abc2 | 2020-05-16 18:54:24 +0100 | [diff] [blame] | 1868 | 	props.Srcs = append(props.Srcs, module.properties.Srcs...) | 
| Anton Hansson | f8ea372 | 2021-09-16 14:24:13 +0100 | [diff] [blame] | 1869 | 	props.Srcs = append(props.Srcs, module.sdkLibraryProperties.Api_srcs...) | 
| Paul Duffin | a18abc2 | 2020-05-16 18:54:24 +0100 | [diff] [blame] | 1870 | 	props.Sdk_version = module.deviceProperties.Sdk_version | 
| Jihoon Kang | 3198f3c | 2023-01-26 08:08:52 +0000 | [diff] [blame] | 1871 | 	props.Api_surface = &apiScope.name | 
| Paul Duffin | a18abc2 | 2020-05-16 18:54:24 +0100 | [diff] [blame] | 1872 | 	props.System_modules = module.deviceProperties.System_modules | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1873 | 	props.Installable = proptools.BoolPtr(false) | 
| Sundong Ahn | e6f0b05 | 2018-06-05 16:46:14 +0900 | [diff] [blame] | 1874 | 	// A droiddoc module has only one Libs property and doesn't distinguish between | 
 | 1875 | 	// shared libs and static libs. So we need to add both of these libs to Libs property. | 
| Paul Duffin | a18abc2 | 2020-05-16 18:54:24 +0100 | [diff] [blame] | 1876 | 	props.Libs = module.properties.Libs | 
 | 1877 | 	props.Libs = append(props.Libs, module.properties.Static_libs...) | 
| Nikita Ioffe | d732da7 | 2022-11-21 12:38:25 +0000 | [diff] [blame] | 1878 | 	props.Libs = append(props.Libs, module.sdkLibraryProperties.Stub_only_libs...) | 
| Mark White | 9421c4c | 2023-08-10 00:07:03 +0000 | [diff] [blame] | 1879 | 	props.Libs = append(props.Libs, module.scopeToProperties[apiScope].Libs...) | 
| Paul Duffin | a18abc2 | 2020-05-16 18:54:24 +0100 | [diff] [blame] | 1880 | 	props.Aidl.Include_dirs = module.deviceProperties.Aidl.Include_dirs | 
 | 1881 | 	props.Aidl.Local_include_dirs = module.deviceProperties.Aidl.Local_include_dirs | 
 | 1882 | 	props.Java_version = module.properties.Java_version | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1883 |  | 
| Paul Duffin | e22c2ab | 2020-05-20 19:35:27 +0100 | [diff] [blame] | 1884 | 	props.Annotations_enabled = module.sdkLibraryProperties.Annotations_enabled | 
| Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1885 | 	props.Merge_annotations_dirs = module.sdkLibraryProperties.Merge_annotations_dirs | 
 | 1886 | 	props.Merge_inclusion_annotations_dirs = module.sdkLibraryProperties.Merge_inclusion_annotations_dirs | 
| Jihoon Kang | 6592e87 | 2023-12-19 01:13:16 +0000 | [diff] [blame] | 1887 | 	props.Aconfig_declarations = module.sdkLibraryProperties.Aconfig_declarations | 
| Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1888 |  | 
| Paul Duffin | 6d0886e | 2020-04-07 18:49:53 +0100 | [diff] [blame] | 1889 | 	droidstubsArgs := []string{} | 
| Paul Duffin | 235ffff | 2019-12-24 10:41:30 +0000 | [diff] [blame] | 1890 | 	if len(module.sdkLibraryProperties.Api_packages) != 0 { | 
| Paul Duffin | 6d0886e | 2020-04-07 18:49:53 +0100 | [diff] [blame] | 1891 | 		droidstubsArgs = append(droidstubsArgs, "--stub-packages "+strings.Join(module.sdkLibraryProperties.Api_packages, ":")) | 
| Paul Duffin | 235ffff | 2019-12-24 10:41:30 +0000 | [diff] [blame] | 1892 | 	} | 
 | 1893 | 	if len(module.sdkLibraryProperties.Hidden_api_packages) != 0 { | 
| Paul Duffin | 6d0886e | 2020-04-07 18:49:53 +0100 | [diff] [blame] | 1894 | 		droidstubsArgs = append(droidstubsArgs, | 
| Paul Duffin | 235ffff | 2019-12-24 10:41:30 +0000 | [diff] [blame] | 1895 | 			android.JoinWithPrefix(module.sdkLibraryProperties.Hidden_api_packages, " --hide-package ")) | 
 | 1896 | 	} | 
| Paul Duffin | 6d0886e | 2020-04-07 18:49:53 +0100 | [diff] [blame] | 1897 | 	droidstubsArgs = append(droidstubsArgs, module.sdkLibraryProperties.Droiddoc_options...) | 
| Anton Hansson | fd1c0d2 | 2023-11-02 15:18:09 +0000 | [diff] [blame] | 1898 | 	disabledWarnings := []string{"HiddenSuperclass"} | 
 | 1899 | 	if proptools.BoolDefault(module.sdkLibraryProperties.Api_lint.Legacy_errors_allowed, true) { | 
 | 1900 | 		disabledWarnings = append(disabledWarnings, | 
 | 1901 | 			"BroadcastBehavior", | 
 | 1902 | 			"DeprecationMismatch", | 
 | 1903 | 			"MissingPermission", | 
 | 1904 | 			"SdkConstant", | 
 | 1905 | 			"Todo", | 
 | 1906 | 		) | 
| Paul Duffin | 235ffff | 2019-12-24 10:41:30 +0000 | [diff] [blame] | 1907 | 	} | 
| Paul Duffin | 6d0886e | 2020-04-07 18:49:53 +0100 | [diff] [blame] | 1908 | 	droidstubsArgs = append(droidstubsArgs, android.JoinWithPrefix(disabledWarnings, "--hide ")) | 
| Sundong Ahn | fb2721f | 2018-09-17 13:23:09 +0900 | [diff] [blame] | 1909 |  | 
| Paul Duffin | 6877e6d | 2020-09-25 19:59:14 +0100 | [diff] [blame] | 1910 | 	// Output Javadoc comments for public scope. | 
 | 1911 | 	if apiScope == apiScopePublic { | 
 | 1912 | 		props.Output_javadoc_comments = proptools.BoolPtr(true) | 
 | 1913 | 	} | 
 | 1914 |  | 
| Paul Duffin | 1fb487d | 2020-04-07 18:50:10 +0100 | [diff] [blame] | 1915 | 	// Add in scope specific arguments. | 
| Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 1916 | 	droidstubsArgs = append(droidstubsArgs, scopeSpecificDroidstubsArgs...) | 
| Paul Duffin | 1151247 | 2019-02-11 15:55:17 +0000 | [diff] [blame] | 1917 | 	props.Arg_files = module.sdkLibraryProperties.Droiddoc_option_files | 
| Paul Duffin | 6d0886e | 2020-04-07 18:49:53 +0100 | [diff] [blame] | 1918 | 	props.Args = proptools.StringPtr(strings.Join(droidstubsArgs, " ")) | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1919 |  | 
| Paul Duffin | 15f34ef | 2020-07-20 18:04:44 +0100 | [diff] [blame] | 1920 | 	// List of APIs identified from the provided source files are created. They are later | 
 | 1921 | 	// compared against to the not-yet-released (a.k.a current) list of APIs and to the | 
 | 1922 | 	// last-released (a.k.a numbered) list of API. | 
 | 1923 | 	currentApiFileName := apiScope.apiFilePrefix + "current.txt" | 
 | 1924 | 	removedApiFileName := apiScope.apiFilePrefix + "removed.txt" | 
 | 1925 | 	apiDir := module.getApiDir() | 
 | 1926 | 	currentApiFileName = path.Join(apiDir, currentApiFileName) | 
 | 1927 | 	removedApiFileName = path.Join(apiDir, removedApiFileName) | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1928 |  | 
| Paul Duffin | 15f34ef | 2020-07-20 18:04:44 +0100 | [diff] [blame] | 1929 | 	// check against the not-yet-release API | 
 | 1930 | 	props.Check_api.Current.Api_file = proptools.StringPtr(currentApiFileName) | 
 | 1931 | 	props.Check_api.Current.Removed_api_file = proptools.StringPtr(removedApiFileName) | 
| Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 1932 |  | 
| Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 1933 | 	if module.compareAgainstLatestApi(apiScope) { | 
| Paul Duffin | 15f34ef | 2020-07-20 18:04:44 +0100 | [diff] [blame] | 1934 | 		// check against the latest released API | 
 | 1935 | 		latestApiFilegroupName := proptools.StringPtr(module.latestApiFilegroupName(apiScope)) | 
| Anton Hansson | e87b03d | 2020-12-21 15:29:34 +0000 | [diff] [blame] | 1936 | 		props.Previous_api = latestApiFilegroupName | 
| Paul Duffin | 15f34ef | 2020-07-20 18:04:44 +0100 | [diff] [blame] | 1937 | 		props.Check_api.Last_released.Api_file = latestApiFilegroupName | 
 | 1938 | 		props.Check_api.Last_released.Removed_api_file = proptools.StringPtr( | 
 | 1939 | 			module.latestRemovedApiFilegroupName(apiScope)) | 
| Jaewoong Jung | 1a97ee0 | 2021-03-09 13:25:02 -0800 | [diff] [blame] | 1940 | 		props.Check_api.Last_released.Baseline_file = proptools.StringPtr( | 
 | 1941 | 			module.latestIncompatibilitiesFilegroupName(apiScope)) | 
| Paul Duffin | 160fe41 | 2020-05-10 19:32:20 +0100 | [diff] [blame] | 1942 |  | 
| Paul Duffin | 15f34ef | 2020-07-20 18:04:44 +0100 | [diff] [blame] | 1943 | 		if proptools.Bool(module.sdkLibraryProperties.Api_lint.Enabled) { | 
 | 1944 | 			// Enable api lint. | 
 | 1945 | 			props.Check_api.Api_lint.Enabled = proptools.BoolPtr(true) | 
 | 1946 | 			props.Check_api.Api_lint.New_since = latestApiFilegroupName | 
| Paul Duffin | 160fe41 | 2020-05-10 19:32:20 +0100 | [diff] [blame] | 1947 |  | 
| Paul Duffin | 15f34ef | 2020-07-20 18:04:44 +0100 | [diff] [blame] | 1948 | 			// If it exists then pass a lint-baseline.txt through to droidstubs. | 
 | 1949 | 			baselinePath := path.Join(apiDir, apiScope.apiFilePrefix+"lint-baseline.txt") | 
 | 1950 | 			baselinePathRelativeToRoot := path.Join(mctx.ModuleDir(), baselinePath) | 
 | 1951 | 			paths, err := mctx.GlobWithDeps(baselinePathRelativeToRoot, nil) | 
 | 1952 | 			if err != nil { | 
 | 1953 | 				mctx.ModuleErrorf("error checking for presence of %s: %s", baselinePathRelativeToRoot, err) | 
 | 1954 | 			} | 
 | 1955 | 			if len(paths) == 1 { | 
 | 1956 | 				props.Check_api.Api_lint.Baseline_file = proptools.StringPtr(baselinePath) | 
 | 1957 | 			} else if len(paths) != 0 { | 
 | 1958 | 				mctx.ModuleErrorf("error checking for presence of %s: expected one path, found: %v", baselinePathRelativeToRoot, paths) | 
| Paul Duffin | 160fe41 | 2020-05-10 19:32:20 +0100 | [diff] [blame] | 1959 | 			} | 
 | 1960 | 		} | 
| Paul Duffin | 15f34ef | 2020-07-20 18:04:44 +0100 | [diff] [blame] | 1961 | 	} | 
| Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 1962 |  | 
| Paul Duffin | 15f34ef | 2020-07-20 18:04:44 +0100 | [diff] [blame] | 1963 | 	if !Bool(module.sdkLibraryProperties.No_dist) { | 
| Paul Duffin | 040e906 | 2020-11-23 17:41:36 +0000 | [diff] [blame] | 1964 | 		// Dist the api txt and removed api txt artifacts for sdk builds. | 
 | 1965 | 		distDir := proptools.StringPtr(path.Join(module.apiDistPath(apiScope), "api")) | 
 | 1966 | 		for _, p := range []struct { | 
 | 1967 | 			tag     string | 
 | 1968 | 			pattern string | 
 | 1969 | 		}{ | 
 | 1970 | 			{tag: ".api.txt", pattern: "%s.txt"}, | 
 | 1971 | 			{tag: ".removed-api.txt", pattern: "%s-removed.txt"}, | 
 | 1972 | 		} { | 
 | 1973 | 			props.Dists = append(props.Dists, android.Dist{ | 
 | 1974 | 				Targets: []string{"sdk", "win_sdk"}, | 
 | 1975 | 				Dir:     distDir, | 
 | 1976 | 				Dest:    proptools.StringPtr(fmt.Sprintf(p.pattern, module.distStem())), | 
 | 1977 | 				Tag:     proptools.StringPtr(p.tag), | 
 | 1978 | 			}) | 
 | 1979 | 		} | 
| Anton Hansson | 5fd5d24 | 2020-03-27 19:43:19 +0000 | [diff] [blame] | 1980 | 	} | 
 | 1981 |  | 
| Spandan Das | 2cc80ba | 2023-10-27 17:21:52 +0000 | [diff] [blame] | 1982 | 	mctx.CreateModule(DroidstubsFactory, &props, module.sdkComponentPropertiesForChildLibrary()).(*Droidstubs).CallHookIfAvailable(mctx) | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1983 | } | 
 | 1984 |  | 
| Jihoon Kang | 0c705a4 | 2023-08-02 06:44:57 +0000 | [diff] [blame] | 1985 | func (module *SdkLibrary) createApiLibrary(mctx android.DefaultableHookContext, apiScope *apiScope, alternativeFullApiSurfaceStub string) { | 
| Jihoon Kang | 1c92c3e | 2023-03-23 17:44:51 +0000 | [diff] [blame] | 1986 | 	props := struct { | 
| Jihoon Kang | ca198c2 | 2023-06-22 23:13:51 +0000 | [diff] [blame] | 1987 | 		Name                  *string | 
 | 1988 | 		Visibility            []string | 
 | 1989 | 		Api_contributions     []string | 
 | 1990 | 		Libs                  []string | 
 | 1991 | 		Static_libs           []string | 
 | 1992 | 		Full_api_surface_stub *string | 
| Jihoon Kang | 4ec2487 | 2023-10-05 17:26:09 +0000 | [diff] [blame] | 1993 | 		System_modules        *string | 
| Jihoon Kang | 063ec00 | 2023-06-28 01:16:23 +0000 | [diff] [blame] | 1994 | 		Enable_validation     *bool | 
| Jihoon Kang | 1c92c3e | 2023-03-23 17:44:51 +0000 | [diff] [blame] | 1995 | 	}{} | 
 | 1996 |  | 
 | 1997 | 	props.Name = proptools.StringPtr(module.apiLibraryModuleName(apiScope)) | 
| Jihoon Kang | 786df93 | 2023-09-07 01:18:31 +0000 | [diff] [blame] | 1998 | 	props.Visibility = []string{"//visibility:override", "//visibility:private"} | 
| Jihoon Kang | 1c92c3e | 2023-03-23 17:44:51 +0000 | [diff] [blame] | 1999 |  | 
 | 2000 | 	apiContributions := []string{} | 
 | 2001 |  | 
 | 2002 | 	// Api surfaces are not independent of each other, but have subset relationships, | 
 | 2003 | 	// and so does the api files. To generate from-text stubs for api surfaces other than public, | 
 | 2004 | 	// all subset api domains' api_contriubtions must be added as well. | 
 | 2005 | 	scope := apiScope | 
 | 2006 | 	for scope != nil { | 
 | 2007 | 		apiContributions = append(apiContributions, module.stubsSourceModuleName(scope)+".api.contribution") | 
 | 2008 | 		scope = scope.extends | 
 | 2009 | 	} | 
| Jihoon Kang | 0c705a4 | 2023-08-02 06:44:57 +0000 | [diff] [blame] | 2010 | 	if apiScope == apiScopePublic { | 
 | 2011 | 		additionalApiContribution := module.apiLibraryAdditionalApiContribution() | 
 | 2012 | 		if additionalApiContribution != "" { | 
 | 2013 | 			apiContributions = append(apiContributions, additionalApiContribution) | 
 | 2014 | 		} | 
 | 2015 | 	} | 
| Jihoon Kang | 1c92c3e | 2023-03-23 17:44:51 +0000 | [diff] [blame] | 2016 |  | 
 | 2017 | 	props.Api_contributions = apiContributions | 
 | 2018 | 	props.Libs = module.properties.Libs | 
 | 2019 | 	props.Libs = append(props.Libs, module.sdkLibraryProperties.Stub_only_libs...) | 
| Mark White | 9421c4c | 2023-08-10 00:07:03 +0000 | [diff] [blame] | 2020 | 	props.Libs = append(props.Libs, module.scopeToProperties[apiScope].Libs...) | 
| Jihoon Kang | 1c92c3e | 2023-03-23 17:44:51 +0000 | [diff] [blame] | 2021 | 	props.Libs = append(props.Libs, "stub-annotations") | 
 | 2022 | 	props.Static_libs = module.sdkLibraryProperties.Stub_only_static_libs | 
| Jihoon Kang | e7ee256 | 2023-07-25 05:51:46 +0000 | [diff] [blame] | 2023 | 	props.Full_api_surface_stub = proptools.StringPtr(apiScope.kind.DefaultJavaLibraryName()) | 
| Jihoon Kang | 0c705a4 | 2023-08-02 06:44:57 +0000 | [diff] [blame] | 2024 | 	if alternativeFullApiSurfaceStub != "" { | 
 | 2025 | 		props.Full_api_surface_stub = proptools.StringPtr(alternativeFullApiSurfaceStub) | 
 | 2026 | 	} | 
| Jihoon Kang | 1c92c3e | 2023-03-23 17:44:51 +0000 | [diff] [blame] | 2027 |  | 
 | 2028 | 	// android_module_lib_stubs_current.from-text only comprises api contributions from art, conscrypt and i18n. | 
 | 2029 | 	// Thus, replace with android_module_lib_stubs_current_full.from-text, which comprises every api domains. | 
 | 2030 | 	if apiScope.kind == android.SdkModule { | 
| Jihoon Kang | ca198c2 | 2023-06-22 23:13:51 +0000 | [diff] [blame] | 2031 | 		props.Full_api_surface_stub = proptools.StringPtr(apiScope.kind.DefaultJavaLibraryName() + "_full.from-text") | 
| Jihoon Kang | 1c92c3e | 2023-03-23 17:44:51 +0000 | [diff] [blame] | 2032 | 	} | 
 | 2033 |  | 
| Jihoon Kang | d30ac8a | 2023-10-09 18:00:17 +0000 | [diff] [blame] | 2034 | 	// java_sdk_library modules that set sdk_version as none does not depend on other api | 
 | 2035 | 	// domains. Therefore, java_api_library created from such modules should not depend on | 
 | 2036 | 	// full_api_surface_stubs but create and compile stubs by the java_api_library module | 
 | 2037 | 	// itself. | 
 | 2038 | 	if module.SdkVersion(mctx).Kind == android.SdkNone { | 
 | 2039 | 		props.Full_api_surface_stub = nil | 
 | 2040 | 	} | 
 | 2041 |  | 
| Jihoon Kang | 4ec2487 | 2023-10-05 17:26:09 +0000 | [diff] [blame] | 2042 | 	props.System_modules = module.deviceProperties.System_modules | 
| Jihoon Kang | 063ec00 | 2023-06-28 01:16:23 +0000 | [diff] [blame] | 2043 | 	props.Enable_validation = proptools.BoolPtr(true) | 
| Jihoon Kang | 4ec2487 | 2023-10-05 17:26:09 +0000 | [diff] [blame] | 2044 |  | 
| Spandan Das | 2cc80ba | 2023-10-27 17:21:52 +0000 | [diff] [blame] | 2045 | 	mctx.CreateModule(ApiLibraryFactory, &props, module.sdkComponentPropertiesForChildLibrary()) | 
| Jihoon Kang | 1c92c3e | 2023-03-23 17:44:51 +0000 | [diff] [blame] | 2046 | } | 
 | 2047 |  | 
| Jihoon Kang | fa4a90d | 2023-12-20 02:53:38 +0000 | [diff] [blame] | 2048 | func (module *SdkLibrary) topLevelStubsLibraryProps(mctx android.DefaultableHookContext, apiScope *apiScope) libraryProperties { | 
 | 2049 | 	props := libraryProperties{} | 
 | 2050 |  | 
| Jihoon Kang | 1147b31 | 2023-06-08 23:25:57 +0000 | [diff] [blame] | 2051 | 	props.Visibility = childModuleVisibility(module.sdkLibraryProperties.Stubs_library_visibility) | 
 | 2052 | 	sdkVersion := module.sdkVersionForStubsLibrary(mctx, apiScope) | 
 | 2053 | 	props.Sdk_version = proptools.StringPtr(sdkVersion) | 
 | 2054 |  | 
| Jihoon Kang | 1147b31 | 2023-06-08 23:25:57 +0000 | [diff] [blame] | 2055 | 	props.System_modules = module.deviceProperties.System_modules | 
 | 2056 |  | 
| Jihoon Kang | 1147b31 | 2023-06-08 23:25:57 +0000 | [diff] [blame] | 2057 | 	// The imports need to be compiled to dex if the java_sdk_library requests it. | 
 | 2058 | 	compileDex := module.dexProperties.Compile_dex | 
 | 2059 | 	if module.stubLibrariesCompiledForDex() { | 
 | 2060 | 		compileDex = proptools.BoolPtr(true) | 
 | 2061 | 	} | 
 | 2062 | 	props.Compile_dex = compileDex | 
 | 2063 |  | 
| Jihoon Kang | fa4a90d | 2023-12-20 02:53:38 +0000 | [diff] [blame] | 2064 | 	return props | 
 | 2065 | } | 
 | 2066 |  | 
 | 2067 | func (module *SdkLibrary) createTopLevelStubsLibrary( | 
 | 2068 | 	mctx android.DefaultableHookContext, apiScope *apiScope, contributesToApiSurface bool) { | 
 | 2069 |  | 
 | 2070 | 	props := module.topLevelStubsLibraryProps(mctx, apiScope) | 
 | 2071 | 	props.Name = proptools.StringPtr(module.stubsLibraryModuleName(apiScope)) | 
 | 2072 |  | 
 | 2073 | 	// Add the stub compiling java_library/java_api_library as static lib based on build config | 
 | 2074 | 	staticLib := module.sourceStubsLibraryModuleName(apiScope) | 
 | 2075 | 	if mctx.Config().BuildFromTextStub() && contributesToApiSurface { | 
 | 2076 | 		staticLib = module.apiLibraryModuleName(apiScope) | 
 | 2077 | 	} | 
 | 2078 | 	props.Static_libs = append(props.Static_libs, staticLib) | 
 | 2079 |  | 
 | 2080 | 	mctx.CreateModule(LibraryFactory, &props, module.sdkComponentPropertiesForChildLibrary()) | 
 | 2081 | } | 
 | 2082 |  | 
 | 2083 | func (module *SdkLibrary) createTopLevelExportableStubsLibrary( | 
 | 2084 | 	mctx android.DefaultableHookContext, apiScope *apiScope) { | 
 | 2085 |  | 
 | 2086 | 	props := module.topLevelStubsLibraryProps(mctx, apiScope) | 
 | 2087 | 	props.Name = proptools.StringPtr(module.exportableStubsLibraryModuleName(apiScope)) | 
 | 2088 |  | 
 | 2089 | 	// Dist the class jar artifact for sdk builds. | 
 | 2090 | 	// "exportable" stubs are copied to dist for sdk builds instead of the "everything" stubs. | 
 | 2091 | 	if !Bool(module.sdkLibraryProperties.No_dist) { | 
 | 2092 | 		props.Dist.Targets = []string{"sdk", "win_sdk"} | 
 | 2093 | 		props.Dist.Dest = proptools.StringPtr(fmt.Sprintf("%v.jar", module.distStem())) | 
 | 2094 | 		props.Dist.Dir = proptools.StringPtr(module.apiDistPath(apiScope)) | 
 | 2095 | 		props.Dist.Tag = proptools.StringPtr(".jar") | 
 | 2096 | 	} | 
 | 2097 |  | 
 | 2098 | 	staticLib := module.exportableSourceStubsLibraryModuleName(apiScope) | 
 | 2099 | 	props.Static_libs = append(props.Static_libs, staticLib) | 
 | 2100 |  | 
| Jihoon Kang | 1147b31 | 2023-06-08 23:25:57 +0000 | [diff] [blame] | 2101 | 	mctx.CreateModule(LibraryFactory, &props, module.sdkComponentPropertiesForChildLibrary()) | 
 | 2102 | } | 
 | 2103 |  | 
| Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 2104 | func (module *SdkLibrary) compareAgainstLatestApi(apiScope *apiScope) bool { | 
 | 2105 | 	return !(apiScope.unstable || module.sdkLibraryProperties.Unsafe_ignore_missing_latest_api) | 
 | 2106 | } | 
 | 2107 |  | 
| Paul Duffin | ea8f808 | 2021-06-24 13:25:57 +0100 | [diff] [blame] | 2108 | // Implements android.ApexModule | 
| Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 2109 | func (module *SdkLibrary) DepIsInSameApex(mctx android.BaseModuleContext, dep android.Module) bool { | 
 | 2110 | 	depTag := mctx.OtherModuleDependencyTag(dep) | 
 | 2111 | 	if depTag == xmlPermissionsFileTag { | 
 | 2112 | 		return true | 
 | 2113 | 	} | 
 | 2114 | 	return module.Library.DepIsInSameApex(mctx, dep) | 
 | 2115 | } | 
 | 2116 |  | 
| Paul Duffin | ea8f808 | 2021-06-24 13:25:57 +0100 | [diff] [blame] | 2117 | // Implements android.ApexModule | 
 | 2118 | func (module *SdkLibrary) UniqueApexVariations() bool { | 
 | 2119 | 	return module.uniqueApexVariations() | 
 | 2120 | } | 
 | 2121 |  | 
| Jihoon Kang | 80456fd | 2023-11-15 19:22:14 +0000 | [diff] [blame] | 2122 | func (module *SdkLibrary) ContributeToApi() bool { | 
 | 2123 | 	return proptools.BoolDefault(module.sdkLibraryProperties.Contribute_to_android_api, false) | 
 | 2124 | } | 
 | 2125 |  | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 2126 | // Creates the xml file that publicizes the runtime library | 
| Paul Duffin | f022920 | 2020-04-29 16:47:28 +0100 | [diff] [blame] | 2127 | func (module *SdkLibrary) createXmlFile(mctx android.DefaultableHookContext) { | 
| Spandan Das | 8c9ae7e | 2023-03-03 21:20:36 +0000 | [diff] [blame] | 2128 | 	moduleMinApiLevel := module.Library.MinSdkVersion(mctx) | 
| Pedro Loureiro | c362142 | 2021-09-28 15:40:23 +0000 | [diff] [blame] | 2129 | 	var moduleMinApiLevelStr = moduleMinApiLevel.String() | 
 | 2130 | 	if moduleMinApiLevel == android.NoneApiLevel { | 
 | 2131 | 		moduleMinApiLevelStr = "current" | 
 | 2132 | 	} | 
| Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 2133 | 	props := struct { | 
| Pedro Loureiro | c362142 | 2021-09-28 15:40:23 +0000 | [diff] [blame] | 2134 | 		Name                      *string | 
 | 2135 | 		Lib_name                  *string | 
 | 2136 | 		Apex_available            []string | 
 | 2137 | 		On_bootclasspath_since    *string | 
 | 2138 | 		On_bootclasspath_before   *string | 
 | 2139 | 		Min_device_sdk            *string | 
 | 2140 | 		Max_device_sdk            *string | 
 | 2141 | 		Sdk_library_min_api_level *string | 
| Jamie Garside | e570ace | 2023-11-27 12:07:36 +0000 | [diff] [blame] | 2142 | 		Uses_libs_dependencies    []string | 
| Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 2143 | 	}{ | 
| Pedro Loureiro | c362142 | 2021-09-28 15:40:23 +0000 | [diff] [blame] | 2144 | 		Name:                      proptools.StringPtr(module.xmlPermissionsModuleName()), | 
 | 2145 | 		Lib_name:                  proptools.StringPtr(module.BaseModuleName()), | 
 | 2146 | 		Apex_available:            module.ApexProperties.Apex_available, | 
 | 2147 | 		On_bootclasspath_since:    module.commonSdkLibraryProperties.On_bootclasspath_since, | 
 | 2148 | 		On_bootclasspath_before:   module.commonSdkLibraryProperties.On_bootclasspath_before, | 
 | 2149 | 		Min_device_sdk:            module.commonSdkLibraryProperties.Min_device_sdk, | 
 | 2150 | 		Max_device_sdk:            module.commonSdkLibraryProperties.Max_device_sdk, | 
 | 2151 | 		Sdk_library_min_api_level: &moduleMinApiLevelStr, | 
| Jamie Garside | e570ace | 2023-11-27 12:07:36 +0000 | [diff] [blame] | 2152 | 		Uses_libs_dependencies:    module.usesLibraryProperties.Uses_libs, | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 2153 | 	} | 
| Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 2154 |  | 
| Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 2155 | 	mctx.CreateModule(sdkLibraryXmlFactory, &props) | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 2156 | } | 
 | 2157 |  | 
| Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 2158 | func PrebuiltJars(ctx android.BaseModuleContext, baseName string, s android.SdkSpec) android.Paths { | 
| Jiyong Park | 54105c4 | 2021-03-31 18:17:53 +0900 | [diff] [blame] | 2159 | 	var ver android.ApiLevel | 
| Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 2160 | 	var kind android.SdkKind | 
 | 2161 | 	if s.UsePrebuilt(ctx) { | 
| Jiyong Park | 54105c4 | 2021-03-31 18:17:53 +0900 | [diff] [blame] | 2162 | 		ver = s.ApiLevel | 
| Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 2163 | 		kind = s.Kind | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 2164 | 	} else { | 
| Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 2165 | 		// We don't have prebuilt SDK for the specific sdkVersion. | 
 | 2166 | 		// Instead of breaking the build, fallback to use "system_current" | 
| Jiyong Park | 54105c4 | 2021-03-31 18:17:53 +0900 | [diff] [blame] | 2167 | 		ver = android.FutureApiLevel | 
| Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 2168 | 		kind = android.SdkSystem | 
| Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 2169 | 	} | 
| Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 2170 |  | 
 | 2171 | 	dir := filepath.Join("prebuilts", "sdk", ver.String(), kind.String()) | 
| Paul Duffin | 5006151 | 2020-01-21 16:31:05 +0000 | [diff] [blame] | 2172 | 	jar := filepath.Join(dir, baseName+".jar") | 
| Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 2173 | 	jarPath := android.ExistentPathForSource(ctx, jar) | 
| Sundong Ahn | ae418ac | 2019-02-28 15:01:28 +0900 | [diff] [blame] | 2174 | 	if !jarPath.Valid() { | 
| Colin Cross | 07c8856 | 2020-01-07 09:34:44 -0800 | [diff] [blame] | 2175 | 		if ctx.Config().AllowMissingDependencies() { | 
 | 2176 | 			return android.Paths{android.PathForSource(ctx, jar)} | 
 | 2177 | 		} else { | 
| Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 2178 | 			ctx.PropertyErrorf("sdk_library", "invalid sdk version %q, %q does not exist", s.Raw, jar) | 
| Colin Cross | 07c8856 | 2020-01-07 09:34:44 -0800 | [diff] [blame] | 2179 | 		} | 
| Sundong Ahn | ae418ac | 2019-02-28 15:01:28 +0900 | [diff] [blame] | 2180 | 		return nil | 
 | 2181 | 	} | 
| Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 2182 | 	return android.Paths{jarPath.Path()} | 
 | 2183 | } | 
 | 2184 |  | 
| Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 2185 | // Check to see if the other module is within the same set of named APEXes as this module. | 
| Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 2186 | // | 
 | 2187 | // If either this or the other module are on the platform then this will return | 
 | 2188 | // false. | 
| Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 2189 | func withinSameApexesAs(ctx android.BaseModuleContext, other android.Module) bool { | 
| Colin Cross | ff694a8 | 2023-12-13 15:54:49 -0800 | [diff] [blame] | 2190 | 	apexInfo, _ := android.ModuleProvider(ctx, android.ApexInfoProvider) | 
| Colin Cross | 313aa54 | 2023-12-13 13:47:44 -0800 | [diff] [blame] | 2191 | 	otherApexInfo, _ := android.OtherModuleProvider(ctx, other, android.ApexInfoProvider) | 
| Jiyong Park | ab50b07 | 2021-05-12 17:13:56 +0900 | [diff] [blame] | 2192 | 	return len(otherApexInfo.InApexVariants) > 0 && reflect.DeepEqual(apexInfo.InApexVariants, otherApexInfo.InApexVariants) | 
| Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 2193 | } | 
 | 2194 |  | 
| Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 2195 | func (module *SdkLibrary) sdkJars(ctx android.BaseModuleContext, sdkVersion android.SdkSpec, headerJars bool) android.Paths { | 
| Jiyong Park | 932cdfe | 2020-05-28 00:19:53 +0900 | [diff] [blame] | 2196 | 	// If the client doesn't set sdk_version, but if this library prefers stubs over | 
 | 2197 | 	// the impl library, let's provide the widest API surface possible. To do so, | 
 | 2198 | 	// force override sdk_version to module_current so that the closest possible API | 
 | 2199 | 	// surface could be found in selectHeaderJarsForSdkVersion | 
| Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 2200 | 	if module.defaultsToStubs() && !sdkVersion.Specified() { | 
| Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 2201 | 		sdkVersion = android.SdkSpecFrom(ctx, "module_current") | 
| Jiyong Park | 932cdfe | 2020-05-28 00:19:53 +0900 | [diff] [blame] | 2202 | 	} | 
| Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 2203 |  | 
| Paul Duffin | daaa332 | 2020-05-26 18:13:57 +0100 | [diff] [blame] | 2204 | 	// Only provide access to the implementation library if it is actually built. | 
 | 2205 | 	if module.requiresRuntimeImplementationLibrary() { | 
 | 2206 | 		// Check any special cases for java_sdk_library. | 
 | 2207 | 		// | 
 | 2208 | 		// Only allow access to the implementation library in the following condition: | 
 | 2209 | 		// * No sdk_version specified on the referencing module. | 
| Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 2210 | 		// * The referencing module is in the same apex as this. | 
| Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 2211 | 		if sdkVersion.Kind == android.SdkPrivate || withinSameApexesAs(ctx, module) { | 
| Paul Duffin | daaa332 | 2020-05-26 18:13:57 +0100 | [diff] [blame] | 2212 | 			if headerJars { | 
 | 2213 | 				return module.HeaderJars() | 
 | 2214 | 			} else { | 
 | 2215 | 				return module.ImplementationJars() | 
 | 2216 | 			} | 
| Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 2217 | 		} | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 2218 | 	} | 
| Paul Duffin | b05d429 | 2020-05-20 12:19:10 +0100 | [diff] [blame] | 2219 |  | 
| Paul Duffin | 23970f4 | 2020-05-20 14:20:02 +0100 | [diff] [blame] | 2220 | 	return module.selectHeaderJarsForSdkVersion(ctx, sdkVersion) | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 2221 | } | 
 | 2222 |  | 
| Sundong Ahn | 241cd37 | 2018-07-13 16:16:44 +0900 | [diff] [blame] | 2223 | // to satisfy SdkLibraryDependency interface | 
| Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 2224 | func (module *SdkLibrary) SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion android.SdkSpec) android.Paths { | 
| Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 2225 | 	return module.sdkJars(ctx, sdkVersion, true /*headerJars*/) | 
 | 2226 | } | 
 | 2227 |  | 
 | 2228 | // to satisfy SdkLibraryDependency interface | 
| Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 2229 | func (module *SdkLibrary) SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion android.SdkSpec) android.Paths { | 
| Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 2230 | 	return module.sdkJars(ctx, sdkVersion, false /*headerJars*/) | 
| Sundong Ahn | 241cd37 | 2018-07-13 16:16:44 +0900 | [diff] [blame] | 2231 | } | 
 | 2232 |  | 
| Colin Cross | 571cccf | 2019-02-04 11:22:08 -0800 | [diff] [blame] | 2233 | var javaSdkLibrariesKey = android.NewOnceKey("javaSdkLibraries") | 
 | 2234 |  | 
| Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 2235 | func javaSdkLibraries(config android.Config) *[]string { | 
| Colin Cross | 571cccf | 2019-02-04 11:22:08 -0800 | [diff] [blame] | 2236 | 	return config.Once(javaSdkLibrariesKey, func() interface{} { | 
| Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 2237 | 		return &[]string{} | 
 | 2238 | 	}).(*[]string) | 
 | 2239 | } | 
 | 2240 |  | 
| Paul Duffin | 749f98f | 2019-12-30 17:23:46 +0000 | [diff] [blame] | 2241 | func (module *SdkLibrary) getApiDir() string { | 
 | 2242 | 	return proptools.StringDefault(module.sdkLibraryProperties.Api_dir, "api") | 
 | 2243 | } | 
 | 2244 |  | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 2245 | // For a java_sdk_library module, create internal modules for stubs, docs, | 
 | 2246 | // runtime libs and xml file. If requested, the stubs and docs are created twice | 
 | 2247 | // once for public API level and once for system API level | 
| Paul Duffin | f022920 | 2020-04-29 16:47:28 +0100 | [diff] [blame] | 2248 | func (module *SdkLibrary) CreateInternalModules(mctx android.DefaultableHookContext) { | 
 | 2249 | 	// If the module has been disabled then don't create any child modules. | 
 | 2250 | 	if !module.Enabled() { | 
 | 2251 | 		return | 
 | 2252 | 	} | 
 | 2253 |  | 
| Paul Duffin | a18abc2 | 2020-05-16 18:54:24 +0100 | [diff] [blame] | 2254 | 	if len(module.properties.Srcs) == 0 { | 
| Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 2255 | 		mctx.PropertyErrorf("srcs", "java_sdk_library must specify srcs") | 
| Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 2256 | 		return | 
| Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 2257 | 	} | 
 | 2258 |  | 
| Paul Duffin | 37e0b77 | 2019-12-30 17:20:10 +0000 | [diff] [blame] | 2259 | 	// If this builds against standard libraries (i.e. is not part of the core libraries) | 
| Paul Duffin | 4f5c1ef | 2020-11-19 14:53:43 +0000 | [diff] [blame] | 2260 | 	// then assume it provides both system and test apis. | 
| Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 2261 | 	sdkDep := decodeSdkDep(mctx, android.SdkContext(&module.Library)) | 
| Paul Duffin | 37e0b77 | 2019-12-30 17:20:10 +0000 | [diff] [blame] | 2262 | 	hasSystemAndTestApis := sdkDep.hasStandardLibs() | 
| Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 2263 | 	module.sdkLibraryProperties.Generate_system_and_test_apis = hasSystemAndTestApis | 
| Paul Duffin | 4f5c1ef | 2020-11-19 14:53:43 +0000 | [diff] [blame] | 2264 |  | 
| Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 2265 | 	missingCurrentApi := false | 
| Inseob Kim | 8098faa | 2019-03-18 10:19:51 +0900 | [diff] [blame] | 2266 |  | 
| Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 2267 | 	generatedScopes := module.getGeneratedApiScopes(mctx) | 
| Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 2268 |  | 
| Paul Duffin | 749f98f | 2019-12-30 17:23:46 +0000 | [diff] [blame] | 2269 | 	apiDir := module.getApiDir() | 
| Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 2270 | 	for _, scope := range generatedScopes { | 
| Inseob Kim | 8098faa | 2019-03-18 10:19:51 +0900 | [diff] [blame] | 2271 | 		for _, api := range []string{"current.txt", "removed.txt"} { | 
| Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 2272 | 			path := path.Join(mctx.ModuleDir(), apiDir, scope.apiFilePrefix+api) | 
| Inseob Kim | 8098faa | 2019-03-18 10:19:51 +0900 | [diff] [blame] | 2273 | 			p := android.ExistentPathForSource(mctx, path) | 
 | 2274 | 			if !p.Valid() { | 
| Colin Cross | 18f840c | 2021-05-20 17:56:54 -0700 | [diff] [blame] | 2275 | 				if mctx.Config().AllowMissingDependencies() { | 
 | 2276 | 					mctx.AddMissingDependencies([]string{path}) | 
 | 2277 | 				} else { | 
 | 2278 | 					mctx.ModuleErrorf("Current api file %#v doesn't exist", path) | 
 | 2279 | 					missingCurrentApi = true | 
 | 2280 | 				} | 
| Inseob Kim | 8098faa | 2019-03-18 10:19:51 +0900 | [diff] [blame] | 2281 | 			} | 
 | 2282 | 		} | 
 | 2283 | 	} | 
 | 2284 |  | 
| Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 2285 | 	if missingCurrentApi { | 
| Inseob Kim | 8098faa | 2019-03-18 10:19:51 +0900 | [diff] [blame] | 2286 | 		script := "build/soong/scripts/gen-java-current-api-files.sh" | 
 | 2287 | 		p := android.ExistentPathForSource(mctx, script) | 
 | 2288 |  | 
 | 2289 | 		if !p.Valid() { | 
 | 2290 | 			panic(fmt.Sprintf("script file %s doesn't exist", script)) | 
 | 2291 | 		} | 
 | 2292 |  | 
 | 2293 | 		mctx.ModuleErrorf("One or more current api files are missing. "+ | 
 | 2294 | 			"You can update them by:\n"+ | 
| Paul Duffin | 37e0b77 | 2019-12-30 17:20:10 +0000 | [diff] [blame] | 2295 | 			"%s %q %s && m update-api", | 
| Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 2296 | 			script, filepath.Join(mctx.ModuleDir(), apiDir), | 
| Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 2297 | 			strings.Join(generatedScopes.Strings(func(s *apiScope) string { return s.apiFilePrefix }), " ")) | 
| Inseob Kim | 8098faa | 2019-03-18 10:19:51 +0900 | [diff] [blame] | 2298 | 		return | 
 | 2299 | 	} | 
 | 2300 |  | 
| Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 2301 | 	for _, scope := range generatedScopes { | 
| Paul Duffin | 15f34ef | 2020-07-20 18:04:44 +0100 | [diff] [blame] | 2302 | 		// Use the stubs source name for legacy reasons. | 
 | 2303 | 		module.createStubsSourcesAndApi(mctx, scope, module.stubsSourceModuleName(scope), scope.droidstubsArgs) | 
| Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 2304 |  | 
| Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 2305 | 		module.createStubsLibrary(mctx, scope) | 
| Jihoon Kang | fa4a90d | 2023-12-20 02:53:38 +0000 | [diff] [blame] | 2306 | 		module.createExportableStubsLibrary(mctx, scope) | 
| Jihoon Kang | 1c92c3e | 2023-03-23 17:44:51 +0000 | [diff] [blame] | 2307 |  | 
| Jihoon Kang | 0c705a4 | 2023-08-02 06:44:57 +0000 | [diff] [blame] | 2308 | 		alternativeFullApiSurfaceStubLib := "" | 
 | 2309 | 		if scope == apiScopePublic { | 
 | 2310 | 			alternativeFullApiSurfaceStubLib = module.alternativeFullApiSurfaceStubLib() | 
 | 2311 | 		} | 
 | 2312 | 		contributesToApiSurface := module.contributesToApiSurface(mctx.Config()) || alternativeFullApiSurfaceStubLib != "" | 
| Jihoon Kang | 1147b31 | 2023-06-08 23:25:57 +0000 | [diff] [blame] | 2313 | 		if contributesToApiSurface { | 
| Jihoon Kang | 0c705a4 | 2023-08-02 06:44:57 +0000 | [diff] [blame] | 2314 | 			module.createApiLibrary(mctx, scope, alternativeFullApiSurfaceStubLib) | 
| Jihoon Kang | 1c92c3e | 2023-03-23 17:44:51 +0000 | [diff] [blame] | 2315 | 		} | 
| Jihoon Kang | 1147b31 | 2023-06-08 23:25:57 +0000 | [diff] [blame] | 2316 |  | 
 | 2317 | 		module.createTopLevelStubsLibrary(mctx, scope, contributesToApiSurface) | 
| Jihoon Kang | fa4a90d | 2023-12-20 02:53:38 +0000 | [diff] [blame] | 2318 | 		module.createTopLevelExportableStubsLibrary(mctx, scope) | 
| Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 2319 | 	} | 
 | 2320 |  | 
| Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 2321 | 	if module.requiresRuntimeImplementationLibrary() { | 
| Paul Duffin | 5df7930 | 2020-05-16 15:52:12 +0100 | [diff] [blame] | 2322 | 		// Create child module to create an implementation library. | 
 | 2323 | 		// | 
 | 2324 | 		// This temporarily creates a second implementation library that can be explicitly | 
 | 2325 | 		// referenced. | 
 | 2326 | 		// | 
 | 2327 | 		// TODO(b/156618935) - update comment once only one implementation library is created. | 
 | 2328 | 		module.createImplLibrary(mctx) | 
 | 2329 |  | 
| Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 2330 | 		// Only create an XML permissions file that declares the library as being usable | 
 | 2331 | 		// as a shared library if required. | 
 | 2332 | 		if module.sharedLibrary() { | 
 | 2333 | 			module.createXmlFile(mctx) | 
 | 2334 | 		} | 
| Paul Duffin | 43db9be | 2019-12-30 17:35:49 +0000 | [diff] [blame] | 2335 |  | 
 | 2336 | 		// record java_sdk_library modules so that they are exported to make | 
 | 2337 | 		javaSdkLibraries := javaSdkLibraries(mctx.Config()) | 
 | 2338 | 		javaSdkLibrariesLock.Lock() | 
 | 2339 | 		defer javaSdkLibrariesLock.Unlock() | 
 | 2340 | 		*javaSdkLibraries = append(*javaSdkLibraries, module.BaseModuleName()) | 
 | 2341 | 	} | 
| Anton Hansson | 7f66efa | 2020-10-08 14:47:23 +0100 | [diff] [blame] | 2342 |  | 
| Paul Duffin | 77590a8 | 2022-04-28 14:13:30 +0000 | [diff] [blame] | 2343 | 	// Add the impl_only_libs and impl_only_static_libs *after* we're done using them in submodules. | 
| Anton Hansson | 7f66efa | 2020-10-08 14:47:23 +0100 | [diff] [blame] | 2344 | 	module.properties.Libs = append(module.properties.Libs, module.sdkLibraryProperties.Impl_only_libs...) | 
| Paul Duffin | 77590a8 | 2022-04-28 14:13:30 +0000 | [diff] [blame] | 2345 | 	module.properties.Static_libs = append(module.properties.Static_libs, module.sdkLibraryProperties.Impl_only_static_libs...) | 
| Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 2346 | } | 
 | 2347 |  | 
 | 2348 | func (module *SdkLibrary) InitSdkLibraryProperties() { | 
| Colin Cross | ce6734e | 2020-06-15 16:09:53 -0700 | [diff] [blame] | 2349 | 	module.addHostAndDeviceProperties() | 
 | 2350 | 	module.AddProperties(&module.sdkLibraryProperties) | 
| Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 2351 |  | 
| Paul Duffin | 71b33cc | 2021-06-23 11:39:47 +0100 | [diff] [blame] | 2352 | 	module.initSdkLibraryComponent(module) | 
| Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 2353 |  | 
| Paul Duffin | a18abc2 | 2020-05-16 18:54:24 +0100 | [diff] [blame] | 2354 | 	module.properties.Installable = proptools.BoolPtr(true) | 
 | 2355 | 	module.deviceProperties.IsSDKLibrary = true | 
| Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 2356 | } | 
| Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 2357 |  | 
| Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 2358 | func (module *SdkLibrary) requiresRuntimeImplementationLibrary() bool { | 
 | 2359 | 	return !proptools.Bool(module.sdkLibraryProperties.Api_only) | 
 | 2360 | } | 
 | 2361 |  | 
| Jiyong Park | 932cdfe | 2020-05-28 00:19:53 +0900 | [diff] [blame] | 2362 | func (module *SdkLibrary) defaultsToStubs() bool { | 
 | 2363 | 	return proptools.Bool(module.sdkLibraryProperties.Default_to_stubs) | 
 | 2364 | } | 
 | 2365 |  | 
| Paul Duffin | 1b1e806 | 2020-05-08 13:44:43 +0100 | [diff] [blame] | 2366 | // Defines how to name the individual component modules the sdk library creates. | 
 | 2367 | type sdkLibraryComponentNamingScheme interface { | 
 | 2368 | 	stubsLibraryModuleName(scope *apiScope, baseName string) string | 
 | 2369 |  | 
 | 2370 | 	stubsSourceModuleName(scope *apiScope, baseName string) string | 
| Jihoon Kang | 1c92c3e | 2023-03-23 17:44:51 +0000 | [diff] [blame] | 2371 |  | 
 | 2372 | 	apiLibraryModuleName(scope *apiScope, baseName string) string | 
| Jihoon Kang | 1147b31 | 2023-06-08 23:25:57 +0000 | [diff] [blame] | 2373 |  | 
| Jihoon Kang | fa4a90d | 2023-12-20 02:53:38 +0000 | [diff] [blame] | 2374 | 	sourceStubsLibraryModuleName(scope *apiScope, baseName string) string | 
 | 2375 |  | 
 | 2376 | 	exportableStubsLibraryModuleName(scope *apiScope, baseName string) string | 
 | 2377 |  | 
 | 2378 | 	exportableSourceStubsLibraryModuleName(scope *apiScope, baseName string) string | 
| Paul Duffin | 1b1e806 | 2020-05-08 13:44:43 +0100 | [diff] [blame] | 2379 | } | 
 | 2380 |  | 
 | 2381 | type defaultNamingScheme struct { | 
 | 2382 | } | 
 | 2383 |  | 
 | 2384 | func (s *defaultNamingScheme) stubsLibraryModuleName(scope *apiScope, baseName string) string { | 
 | 2385 | 	return scope.stubsLibraryModuleName(baseName) | 
 | 2386 | } | 
 | 2387 |  | 
 | 2388 | func (s *defaultNamingScheme) stubsSourceModuleName(scope *apiScope, baseName string) string { | 
 | 2389 | 	return scope.stubsSourceModuleName(baseName) | 
 | 2390 | } | 
 | 2391 |  | 
| Jihoon Kang | 1c92c3e | 2023-03-23 17:44:51 +0000 | [diff] [blame] | 2392 | func (s *defaultNamingScheme) apiLibraryModuleName(scope *apiScope, baseName string) string { | 
 | 2393 | 	return scope.apiLibraryModuleName(baseName) | 
 | 2394 | } | 
 | 2395 |  | 
| Jihoon Kang | fa4a90d | 2023-12-20 02:53:38 +0000 | [diff] [blame] | 2396 | func (s *defaultNamingScheme) sourceStubsLibraryModuleName(scope *apiScope, baseName string) string { | 
| Jihoon Kang | 1147b31 | 2023-06-08 23:25:57 +0000 | [diff] [blame] | 2397 | 	return scope.sourceStubLibraryModuleName(baseName) | 
 | 2398 | } | 
 | 2399 |  | 
| Jihoon Kang | fa4a90d | 2023-12-20 02:53:38 +0000 | [diff] [blame] | 2400 | func (s *defaultNamingScheme) exportableStubsLibraryModuleName(scope *apiScope, baseName string) string { | 
 | 2401 | 	return scope.exportableStubsLibraryModuleName(baseName) | 
 | 2402 | } | 
 | 2403 |  | 
 | 2404 | func (s *defaultNamingScheme) exportableSourceStubsLibraryModuleName(scope *apiScope, baseName string) string { | 
 | 2405 | 	return scope.exportableSourceStubsLibraryModuleName(baseName) | 
 | 2406 | } | 
 | 2407 |  | 
| Paul Duffin | 1b1e806 | 2020-05-08 13:44:43 +0100 | [diff] [blame] | 2408 | var _ sdkLibraryComponentNamingScheme = (*defaultNamingScheme)(nil) | 
 | 2409 |  | 
| Jihoon Kang | fa4a90d | 2023-12-20 02:53:38 +0000 | [diff] [blame] | 2410 | func hasStubsLibrarySuffix(name string, apiScope *apiScope) bool { | 
 | 2411 | 	return strings.HasSuffix(name, apiScope.stubsLibraryModuleNameSuffix()) || | 
 | 2412 | 		strings.HasSuffix(name, apiScope.exportableStubsLibraryModuleNameSuffix()) | 
 | 2413 | } | 
 | 2414 |  | 
| Jaewoong Jung | bc15e3a | 2021-03-10 17:02:43 -0800 | [diff] [blame] | 2415 | func moduleStubLinkType(name string) (stub bool, ret sdkLinkType) { | 
| Jihoon Kang | 1147b31 | 2023-06-08 23:25:57 +0000 | [diff] [blame] | 2416 | 	name = strings.TrimSuffix(name, ".from-source") | 
 | 2417 |  | 
| Anton Hansson | 2d0c194 | 2020-05-25 12:20:51 +0100 | [diff] [blame] | 2418 | 	// This suffix-based approach is fragile and could potentially mis-trigger. | 
 | 2419 | 	// TODO(b/155164730): Clean this up when modules no longer reference sdk_lib stubs directly. | 
| Jihoon Kang | fa4a90d | 2023-12-20 02:53:38 +0000 | [diff] [blame] | 2420 | 	if hasStubsLibrarySuffix(name, apiScopePublic) { | 
| Anton Hansson | 08f476b | 2021-04-07 15:32:19 +0100 | [diff] [blame] | 2421 | 		if name == "hwbinder.stubs" || name == "libcore_private.stubs" { | 
 | 2422 | 			// Due to a previous bug, these modules were not considered stubs, so we retain that. | 
 | 2423 | 			return false, javaPlatform | 
 | 2424 | 		} | 
| Anton Hansson | 2d0c194 | 2020-05-25 12:20:51 +0100 | [diff] [blame] | 2425 | 		return true, javaSdk | 
 | 2426 | 	} | 
| Jihoon Kang | fa4a90d | 2023-12-20 02:53:38 +0000 | [diff] [blame] | 2427 | 	if hasStubsLibrarySuffix(name, apiScopeSystem) { | 
| Anton Hansson | 2d0c194 | 2020-05-25 12:20:51 +0100 | [diff] [blame] | 2428 | 		return true, javaSystem | 
 | 2429 | 	} | 
| Jihoon Kang | fa4a90d | 2023-12-20 02:53:38 +0000 | [diff] [blame] | 2430 | 	if hasStubsLibrarySuffix(name, apiScopeModuleLib) { | 
| Anton Hansson | 2d0c194 | 2020-05-25 12:20:51 +0100 | [diff] [blame] | 2431 | 		return true, javaModule | 
 | 2432 | 	} | 
| Jihoon Kang | fa4a90d | 2023-12-20 02:53:38 +0000 | [diff] [blame] | 2433 | 	if hasStubsLibrarySuffix(name, apiScopeTest) { | 
| Anton Hansson | 2d0c194 | 2020-05-25 12:20:51 +0100 | [diff] [blame] | 2434 | 		return true, javaSystem | 
 | 2435 | 	} | 
| Jihoon Kang | fa4a90d | 2023-12-20 02:53:38 +0000 | [diff] [blame] | 2436 | 	if hasStubsLibrarySuffix(name, apiScopeSystemServer) { | 
| Jihoon Kang | 1147b31 | 2023-06-08 23:25:57 +0000 | [diff] [blame] | 2437 | 		return true, javaSystemServer | 
 | 2438 | 	} | 
| Anton Hansson | 2d0c194 | 2020-05-25 12:20:51 +0100 | [diff] [blame] | 2439 | 	return false, javaPlatform | 
 | 2440 | } | 
 | 2441 |  | 
| Jaewoong Jung | 4f158ee | 2019-07-11 10:05:35 -0700 | [diff] [blame] | 2442 | // java_sdk_library is a special Java library that provides optional platform APIs to apps. | 
 | 2443 | // In practice, it can be viewed as a combination of several modules: 1) stubs library that clients | 
 | 2444 | // are linked against to, 2) droiddoc module that internally generates API stubs source files, | 
 | 2445 | // 3) the real runtime shared library that implements the APIs, and 4) XML file for adding | 
 | 2446 | // the runtime lib to the classpath at runtime if requested via <uses-library>. | 
| Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 2447 | func SdkLibraryFactory() android.Module { | 
 | 2448 | 	module := &SdkLibrary{} | 
| Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame] | 2449 |  | 
 | 2450 | 	// Initialize information common between source and prebuilt. | 
| Paul Duffin | 71b33cc | 2021-06-23 11:39:47 +0100 | [diff] [blame] | 2451 | 	module.initCommon(module) | 
| Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame] | 2452 |  | 
| Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 2453 | 	module.InitSdkLibraryProperties() | 
| Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 2454 | 	android.InitApexModule(module) | 
| Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 2455 | 	InitJavaModule(module, android.HostAndDeviceSupported) | 
| Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 2456 |  | 
 | 2457 | 	// Initialize the map from scope to scope specific properties. | 
 | 2458 | 	scopeToProperties := make(map[*apiScope]*ApiScopeProperties) | 
 | 2459 | 	for _, scope := range allApiScopes { | 
 | 2460 | 		scopeToProperties[scope] = scope.scopeSpecificProperties(module) | 
 | 2461 | 	} | 
 | 2462 | 	module.scopeToProperties = scopeToProperties | 
 | 2463 |  | 
| Paul Duffin | 4911a89 | 2020-04-29 23:35:13 +0100 | [diff] [blame] | 2464 | 	// Add the properties containing visibility rules so that they are checked. | 
| Paul Duffin | 5df7930 | 2020-05-16 15:52:12 +0100 | [diff] [blame] | 2465 | 	android.AddVisibilityProperty(module, "impl_library_visibility", &module.sdkLibraryProperties.Impl_library_visibility) | 
| Paul Duffin | 4911a89 | 2020-04-29 23:35:13 +0100 | [diff] [blame] | 2466 | 	android.AddVisibilityProperty(module, "stubs_library_visibility", &module.sdkLibraryProperties.Stubs_library_visibility) | 
 | 2467 | 	android.AddVisibilityProperty(module, "stubs_source_visibility", &module.sdkLibraryProperties.Stubs_source_visibility) | 
 | 2468 |  | 
| Paul Duffin | 1b1e806 | 2020-05-08 13:44:43 +0100 | [diff] [blame] | 2469 | 	module.SetDefaultableHook(func(ctx android.DefaultableHookContext) { | 
| Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 2470 | 		// If no implementation is required then it cannot be used as a shared library | 
 | 2471 | 		// either. | 
 | 2472 | 		if !module.requiresRuntimeImplementationLibrary() { | 
 | 2473 | 			// If shared_library has been explicitly set to true then it is incompatible | 
 | 2474 | 			// with api_only: true. | 
 | 2475 | 			if proptools.Bool(module.commonSdkLibraryProperties.Shared_library) { | 
 | 2476 | 				ctx.PropertyErrorf("api_only/shared_library", "inconsistent settings, shared_library and api_only cannot both be true") | 
 | 2477 | 			} | 
 | 2478 | 			// Set shared_library: false. | 
 | 2479 | 			module.commonSdkLibraryProperties.Shared_library = proptools.BoolPtr(false) | 
 | 2480 | 		} | 
 | 2481 |  | 
| Paul Duffin | 1b1e806 | 2020-05-08 13:44:43 +0100 | [diff] [blame] | 2482 | 		if module.initCommonAfterDefaultsApplied(ctx) { | 
 | 2483 | 			module.CreateInternalModules(ctx) | 
 | 2484 | 		} | 
 | 2485 | 	}) | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 2486 | 	return module | 
 | 2487 | } | 
| Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2488 |  | 
 | 2489 | // | 
 | 2490 | // SDK library prebuilts | 
 | 2491 | // | 
 | 2492 |  | 
| Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 2493 | // Properties associated with each api scope. | 
 | 2494 | type sdkLibraryScopeProperties struct { | 
| Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2495 | 	Jars []string `android:"path"` | 
 | 2496 |  | 
 | 2497 | 	Sdk_version *string | 
 | 2498 |  | 
| Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2499 | 	// List of shared java libs that this module has dependencies to | 
 | 2500 | 	Libs []string | 
| Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 2501 |  | 
| Paul Duffin | c878250 | 2020-04-29 20:45:27 +0100 | [diff] [blame] | 2502 | 	// The stubs source. | 
| Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 2503 | 	Stub_srcs []string `android:"path"` | 
| Paul Duffin | 1fd005d | 2020-04-09 01:08:11 +0100 | [diff] [blame] | 2504 |  | 
 | 2505 | 	// The current.txt | 
| Paul Duffin | 0f8faff | 2020-05-20 16:18:00 +0100 | [diff] [blame] | 2506 | 	Current_api *string `android:"path"` | 
| Paul Duffin | 1fd005d | 2020-04-09 01:08:11 +0100 | [diff] [blame] | 2507 |  | 
 | 2508 | 	// The removed.txt | 
| Paul Duffin | 0f8faff | 2020-05-20 16:18:00 +0100 | [diff] [blame] | 2509 | 	Removed_api *string `android:"path"` | 
| Anton Hansson | d78eb76 | 2021-09-21 15:25:12 +0100 | [diff] [blame] | 2510 |  | 
 | 2511 | 	// Annotation zip | 
 | 2512 | 	Annotations *string `android:"path"` | 
| Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2513 | } | 
 | 2514 |  | 
| Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 2515 | type sdkLibraryImportProperties struct { | 
| Paul Duffin | fcfd791 | 2020-01-31 17:54:30 +0000 | [diff] [blame] | 2516 | 	// List of shared java libs, common to all scopes, that this module has | 
 | 2517 | 	// dependencies to | 
 | 2518 | 	Libs []string | 
| Paul Duffin | 1267d87 | 2021-04-16 17:21:36 +0100 | [diff] [blame] | 2519 |  | 
 | 2520 | 	// If set to true, compile dex files for the stubs. Defaults to false. | 
 | 2521 | 	Compile_dex *bool | 
| Paul Duffin | 869de14 | 2021-07-15 14:14:41 +0100 | [diff] [blame] | 2522 |  | 
 | 2523 | 	// If not empty, classes are restricted to the specified packages and their sub-packages. | 
| Paul Duffin | 869de14 | 2021-07-15 14:14:41 +0100 | [diff] [blame] | 2524 | 	Permitted_packages []string | 
| Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 2525 | } | 
 | 2526 |  | 
| Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 2527 | type SdkLibraryImport struct { | 
| Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2528 | 	android.ModuleBase | 
 | 2529 | 	android.DefaultableModuleBase | 
 | 2530 | 	prebuilt android.Prebuilt | 
| Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 2531 | 	android.ApexModuleBase | 
| Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2532 |  | 
| Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 2533 | 	hiddenAPI | 
| Jiakai Zhang | 204356f | 2021-09-09 08:12:46 +0000 | [diff] [blame] | 2534 | 	dexpreopter | 
| Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 2535 |  | 
| Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2536 | 	properties sdkLibraryImportProperties | 
 | 2537 |  | 
| Paul Duffin | 46a26a8 | 2020-04-07 19:27:04 +0100 | [diff] [blame] | 2538 | 	// Map from api scope to the scope specific property structure. | 
 | 2539 | 	scopeProperties map[*apiScope]*sdkLibraryScopeProperties | 
 | 2540 |  | 
| Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 2541 | 	commonToSdkLibraryAndImport | 
| Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 2542 |  | 
 | 2543 | 	// The reference to the implementation library created by the source module. | 
 | 2544 | 	// Is nil if the source module does not exist. | 
 | 2545 | 	implLibraryModule *Library | 
 | 2546 |  | 
 | 2547 | 	// The reference to the xml permissions module created by the source module. | 
 | 2548 | 	// Is nil if the source module does not exist. | 
 | 2549 | 	xmlPermissionsFileModule *sdkLibraryXml | 
| Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 2550 |  | 
| Jeongik Cha | d5fe878 | 2021-07-08 01:13:11 +0900 | [diff] [blame] | 2551 | 	// Build path to the dex implementation jar obtained from the prebuilt_apex, if any. | 
| Spandan Das | fae468e | 2023-12-12 23:23:53 +0000 | [diff] [blame] | 2552 | 	dexJarFile    OptionalDexJarPath | 
 | 2553 | 	dexJarFileErr error | 
| Jeongik Cha | d5fe878 | 2021-07-08 01:13:11 +0900 | [diff] [blame] | 2554 |  | 
 | 2555 | 	// Expected install file path of the source module(sdk_library) | 
 | 2556 | 	// or dex implementation jar obtained from the prebuilt_apex, if any. | 
 | 2557 | 	installFile android.Path | 
| Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2558 | } | 
 | 2559 |  | 
| Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 2560 | var _ SdkLibraryDependency = (*SdkLibraryImport)(nil) | 
| Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2561 |  | 
| Paul Duffin | 46a26a8 | 2020-04-07 19:27:04 +0100 | [diff] [blame] | 2562 | // The type of a structure that contains a field of type sdkLibraryScopeProperties | 
 | 2563 | // for each apiscope in allApiScopes, e.g. something like: | 
| Colin Cross | d079e0b | 2022-08-16 10:27:33 -0700 | [diff] [blame] | 2564 | // | 
 | 2565 | //	struct { | 
 | 2566 | //	  Public sdkLibraryScopeProperties | 
 | 2567 | //	  System sdkLibraryScopeProperties | 
 | 2568 | //	  ... | 
 | 2569 | //	} | 
| Paul Duffin | 46a26a8 | 2020-04-07 19:27:04 +0100 | [diff] [blame] | 2570 | var allScopeStructType = createAllScopePropertiesStructType() | 
 | 2571 |  | 
 | 2572 | // Dynamically create a structure type for each apiscope in allApiScopes. | 
 | 2573 | func createAllScopePropertiesStructType() reflect.Type { | 
 | 2574 | 	var fields []reflect.StructField | 
 | 2575 | 	for _, apiScope := range allApiScopes { | 
 | 2576 | 		field := reflect.StructField{ | 
 | 2577 | 			Name: apiScope.fieldName, | 
 | 2578 | 			Type: reflect.TypeOf(sdkLibraryScopeProperties{}), | 
 | 2579 | 		} | 
 | 2580 | 		fields = append(fields, field) | 
 | 2581 | 	} | 
 | 2582 |  | 
 | 2583 | 	return reflect.StructOf(fields) | 
 | 2584 | } | 
 | 2585 |  | 
 | 2586 | // Create an instance of the scope specific structure type and return a map | 
 | 2587 | // from apiscope to a pointer to each scope specific field. | 
 | 2588 | func createPropertiesInstance() (interface{}, map[*apiScope]*sdkLibraryScopeProperties) { | 
 | 2589 | 	allScopePropertiesPtr := reflect.New(allScopeStructType) | 
 | 2590 | 	allScopePropertiesStruct := allScopePropertiesPtr.Elem() | 
 | 2591 | 	scopeProperties := make(map[*apiScope]*sdkLibraryScopeProperties) | 
 | 2592 |  | 
 | 2593 | 	for _, apiScope := range allApiScopes { | 
 | 2594 | 		field := allScopePropertiesStruct.FieldByName(apiScope.fieldName) | 
 | 2595 | 		scopeProperties[apiScope] = field.Addr().Interface().(*sdkLibraryScopeProperties) | 
 | 2596 | 	} | 
 | 2597 |  | 
 | 2598 | 	return allScopePropertiesPtr.Interface(), scopeProperties | 
 | 2599 | } | 
 | 2600 |  | 
| Jaewoong Jung | 4f158ee | 2019-07-11 10:05:35 -0700 | [diff] [blame] | 2601 | // java_sdk_library_import imports a prebuilt java_sdk_library. | 
| Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2602 | func sdkLibraryImportFactory() android.Module { | 
| Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 2603 | 	module := &SdkLibraryImport{} | 
| Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2604 |  | 
| Paul Duffin | 46a26a8 | 2020-04-07 19:27:04 +0100 | [diff] [blame] | 2605 | 	allScopeProperties, scopeToProperties := createPropertiesInstance() | 
 | 2606 | 	module.scopeProperties = scopeToProperties | 
| Jiakai Zhang | 9c4dc19 | 2023-02-09 00:09:24 +0800 | [diff] [blame] | 2607 | 	module.AddProperties(&module.properties, allScopeProperties, &module.importDexpreoptProperties) | 
| Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2608 |  | 
| Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame] | 2609 | 	// Initialize information common between source and prebuilt. | 
| Paul Duffin | 71b33cc | 2021-06-23 11:39:47 +0100 | [diff] [blame] | 2610 | 	module.initCommon(module) | 
| Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame] | 2611 |  | 
| Paul Duffin | 0bdcb27 | 2020-02-06 15:24:57 +0000 | [diff] [blame] | 2612 | 	android.InitPrebuiltModule(module, &[]string{""}) | 
| Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 2613 | 	android.InitApexModule(module) | 
| Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2614 | 	InitJavaModule(module, android.HostAndDeviceSupported) | 
 | 2615 |  | 
| Paul Duffin | 1b1e806 | 2020-05-08 13:44:43 +0100 | [diff] [blame] | 2616 | 	module.SetDefaultableHook(func(mctx android.DefaultableHookContext) { | 
 | 2617 | 		if module.initCommonAfterDefaultsApplied(mctx) { | 
 | 2618 | 			module.createInternalModules(mctx) | 
 | 2619 | 		} | 
 | 2620 | 	}) | 
| Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2621 | 	return module | 
 | 2622 | } | 
 | 2623 |  | 
| Paul Duffin | 630b11e | 2021-07-15 13:35:26 +0100 | [diff] [blame] | 2624 | var _ PermittedPackagesForUpdatableBootJars = (*SdkLibraryImport)(nil) | 
 | 2625 |  | 
 | 2626 | func (module *SdkLibraryImport) PermittedPackagesForUpdatableBootJars() []string { | 
 | 2627 | 	return module.properties.Permitted_packages | 
 | 2628 | } | 
 | 2629 |  | 
| Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 2630 | func (module *SdkLibraryImport) Prebuilt() *android.Prebuilt { | 
| Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2631 | 	return &module.prebuilt | 
 | 2632 | } | 
 | 2633 |  | 
| Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 2634 | func (module *SdkLibraryImport) Name() string { | 
| Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2635 | 	return module.prebuilt.Name(module.ModuleBase.Name()) | 
 | 2636 | } | 
 | 2637 |  | 
| Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 2638 | func (module *SdkLibraryImport) createInternalModules(mctx android.DefaultableHookContext) { | 
| Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2639 |  | 
| Paul Duffin | 5006151 | 2020-01-21 16:31:05 +0000 | [diff] [blame] | 2640 | 	// If the build is configured to use prebuilts then force this to be preferred. | 
| Jeongik Cha | 816a23a | 2020-07-08 01:09:23 +0900 | [diff] [blame] | 2641 | 	if mctx.Config().AlwaysUsePrebuiltSdks() { | 
| Paul Duffin | 5006151 | 2020-01-21 16:31:05 +0000 | [diff] [blame] | 2642 | 		module.prebuilt.ForcePrefer() | 
 | 2643 | 	} | 
 | 2644 |  | 
| Paul Duffin | 46a26a8 | 2020-04-07 19:27:04 +0100 | [diff] [blame] | 2645 | 	for apiScope, scopeProperties := range module.scopeProperties { | 
| Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 2646 | 		if len(scopeProperties.Jars) == 0 { | 
 | 2647 | 			continue | 
 | 2648 | 		} | 
 | 2649 |  | 
| Paul Duffin | bbb546b | 2020-04-09 00:07:11 +0100 | [diff] [blame] | 2650 | 		module.createJavaImportForStubs(mctx, apiScope, scopeProperties) | 
| Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 2651 |  | 
| Paul Duffin | 0f8faff | 2020-05-20 16:18:00 +0100 | [diff] [blame] | 2652 | 		if len(scopeProperties.Stub_srcs) > 0 { | 
 | 2653 | 			module.createPrebuiltStubsSources(mctx, apiScope, scopeProperties) | 
 | 2654 | 		} | 
| Jihoon Kang | 71c8683 | 2023-09-13 01:01:53 +0000 | [diff] [blame] | 2655 |  | 
 | 2656 | 		if scopeProperties.Current_api != nil { | 
 | 2657 | 			module.createPrebuiltApiContribution(mctx, apiScope, scopeProperties) | 
 | 2658 | 		} | 
| Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 2659 | 	} | 
| Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2660 |  | 
 | 2661 | 	javaSdkLibraries := javaSdkLibraries(mctx.Config()) | 
 | 2662 | 	javaSdkLibrariesLock.Lock() | 
 | 2663 | 	defer javaSdkLibrariesLock.Unlock() | 
 | 2664 | 	*javaSdkLibraries = append(*javaSdkLibraries, module.BaseModuleName()) | 
 | 2665 | } | 
 | 2666 |  | 
| Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 2667 | func (module *SdkLibraryImport) createJavaImportForStubs(mctx android.DefaultableHookContext, apiScope *apiScope, scopeProperties *sdkLibraryScopeProperties) { | 
| Paul Duffin | bbb546b | 2020-04-09 00:07:11 +0100 | [diff] [blame] | 2668 | 	// Creates a java import for the jar with ".stubs" suffix | 
 | 2669 | 	props := struct { | 
| Paul Duffin | 1dbe3ca | 2020-05-16 09:57:59 +0100 | [diff] [blame] | 2670 | 		Name        *string | 
 | 2671 | 		Sdk_version *string | 
 | 2672 | 		Libs        []string | 
 | 2673 | 		Jars        []string | 
| Paul Duffin | 1267d87 | 2021-04-16 17:21:36 +0100 | [diff] [blame] | 2674 | 		Compile_dex *bool | 
| Paul Duffin | bf4de04 | 2022-09-27 12:41:52 +0100 | [diff] [blame] | 2675 |  | 
 | 2676 | 		android.UserSuppliedPrebuiltProperties | 
| Paul Duffin | bbb546b | 2020-04-09 00:07:11 +0100 | [diff] [blame] | 2677 | 	}{} | 
| Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame] | 2678 | 	props.Name = proptools.StringPtr(module.stubsLibraryModuleName(apiScope)) | 
| Paul Duffin | bbb546b | 2020-04-09 00:07:11 +0100 | [diff] [blame] | 2679 | 	props.Sdk_version = scopeProperties.Sdk_version | 
 | 2680 | 	// Prepend any of the libs from the legacy public properties to the libs for each of the | 
 | 2681 | 	// scopes to avoid having to duplicate them in each scope. | 
 | 2682 | 	props.Libs = append(module.properties.Libs, scopeProperties.Libs...) | 
 | 2683 | 	props.Jars = scopeProperties.Jars | 
| Paul Duffin | 1dbe3ca | 2020-05-16 09:57:59 +0100 | [diff] [blame] | 2684 |  | 
| Paul Duffin | 38b5785 | 2020-05-13 16:08:09 +0100 | [diff] [blame] | 2685 | 	// The imports are preferred if the java_sdk_library_import is preferred. | 
| Paul Duffin | bf4de04 | 2022-09-27 12:41:52 +0100 | [diff] [blame] | 2686 | 	props.CopyUserSuppliedPropertiesFromPrebuilt(&module.prebuilt) | 
| Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 2687 |  | 
| Paul Duffin | 1267d87 | 2021-04-16 17:21:36 +0100 | [diff] [blame] | 2688 | 	// The imports need to be compiled to dex if the java_sdk_library_import requests it. | 
| Paul Duffin | f4600f6 | 2021-05-13 22:34:45 +0100 | [diff] [blame] | 2689 | 	compileDex := module.properties.Compile_dex | 
 | 2690 | 	if module.stubLibrariesCompiledForDex() { | 
 | 2691 | 		compileDex = proptools.BoolPtr(true) | 
 | 2692 | 	} | 
 | 2693 | 	props.Compile_dex = compileDex | 
| Paul Duffin | 1267d87 | 2021-04-16 17:21:36 +0100 | [diff] [blame] | 2694 |  | 
| Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 2695 | 	mctx.CreateModule(ImportFactory, &props, module.sdkComponentPropertiesForChildLibrary()) | 
| Paul Duffin | bbb546b | 2020-04-09 00:07:11 +0100 | [diff] [blame] | 2696 | } | 
 | 2697 |  | 
| Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 2698 | func (module *SdkLibraryImport) createPrebuiltStubsSources(mctx android.DefaultableHookContext, apiScope *apiScope, scopeProperties *sdkLibraryScopeProperties) { | 
| Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 2699 | 	props := struct { | 
| Paul Duffin | bf4de04 | 2022-09-27 12:41:52 +0100 | [diff] [blame] | 2700 | 		Name *string | 
 | 2701 | 		Srcs []string | 
 | 2702 |  | 
 | 2703 | 		android.UserSuppliedPrebuiltProperties | 
| Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 2704 | 	}{} | 
| Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame] | 2705 | 	props.Name = proptools.StringPtr(module.stubsSourceModuleName(apiScope)) | 
| Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 2706 | 	props.Srcs = scopeProperties.Stub_srcs | 
| Paul Duffin | 38b5785 | 2020-05-13 16:08:09 +0100 | [diff] [blame] | 2707 |  | 
 | 2708 | 	// The stubs source is preferred if the java_sdk_library_import is preferred. | 
| Paul Duffin | bf4de04 | 2022-09-27 12:41:52 +0100 | [diff] [blame] | 2709 | 	props.CopyUserSuppliedPropertiesFromPrebuilt(&module.prebuilt) | 
 | 2710 |  | 
| Spandan Das | 2cc80ba | 2023-10-27 17:21:52 +0000 | [diff] [blame] | 2711 | 	mctx.CreateModule(PrebuiltStubsSourcesFactory, &props, module.sdkComponentPropertiesForChildLibrary()) | 
| Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 2712 | } | 
 | 2713 |  | 
| Jihoon Kang | 71c8683 | 2023-09-13 01:01:53 +0000 | [diff] [blame] | 2714 | func (module *SdkLibraryImport) createPrebuiltApiContribution(mctx android.DefaultableHookContext, apiScope *apiScope, scopeProperties *sdkLibraryScopeProperties) { | 
 | 2715 | 	api_file := scopeProperties.Current_api | 
 | 2716 | 	api_surface := &apiScope.name | 
 | 2717 |  | 
 | 2718 | 	props := struct { | 
 | 2719 | 		Name        *string | 
 | 2720 | 		Api_surface *string | 
 | 2721 | 		Api_file    *string | 
 | 2722 | 		Visibility  []string | 
 | 2723 | 	}{} | 
 | 2724 |  | 
 | 2725 | 	props.Name = proptools.StringPtr(module.stubsSourceModuleName(apiScope) + ".api.contribution") | 
 | 2726 | 	props.Api_surface = api_surface | 
 | 2727 | 	props.Api_file = api_file | 
 | 2728 | 	props.Visibility = []string{"//visibility:override", "//visibility:public"} | 
 | 2729 |  | 
| Spandan Das | 2cc80ba | 2023-10-27 17:21:52 +0000 | [diff] [blame] | 2730 | 	mctx.CreateModule(ApiContributionImportFactory, &props, module.sdkComponentPropertiesForChildLibrary()) | 
| Jihoon Kang | 71c8683 | 2023-09-13 01:01:53 +0000 | [diff] [blame] | 2731 | } | 
 | 2732 |  | 
| Paul Duffin | 44f1d84 | 2020-06-26 20:17:02 +0100 | [diff] [blame] | 2733 | // Add the dependencies on the child module in the component deps mutator so that it | 
 | 2734 | // creates references to the prebuilt and not the source modules. | 
 | 2735 | func (module *SdkLibraryImport) ComponentDepsMutator(ctx android.BottomUpMutatorContext) { | 
| Paul Duffin | 46a26a8 | 2020-04-07 19:27:04 +0100 | [diff] [blame] | 2736 | 	for apiScope, scopeProperties := range module.scopeProperties { | 
| Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 2737 | 		if len(scopeProperties.Jars) == 0 { | 
 | 2738 | 			continue | 
 | 2739 | 		} | 
 | 2740 |  | 
 | 2741 | 		// Add dependencies to the prebuilt stubs library | 
| Paul Duffin | 864116c | 2021-04-02 10:24:13 +0100 | [diff] [blame] | 2742 | 		ctx.AddVariationDependencies(nil, apiScope.stubsTag, android.PrebuiltNameFromSource(module.stubsLibraryModuleName(apiScope))) | 
| Paul Duffin | 0f8faff | 2020-05-20 16:18:00 +0100 | [diff] [blame] | 2743 |  | 
 | 2744 | 		if len(scopeProperties.Stub_srcs) > 0 { | 
 | 2745 | 			// Add dependencies to the prebuilt stubs source library | 
| Paul Duffin | 864116c | 2021-04-02 10:24:13 +0100 | [diff] [blame] | 2746 | 			ctx.AddVariationDependencies(nil, apiScope.stubsSourceTag, android.PrebuiltNameFromSource(module.stubsSourceModuleName(apiScope))) | 
| Paul Duffin | 0f8faff | 2020-05-20 16:18:00 +0100 | [diff] [blame] | 2747 | 		} | 
| Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 2748 | 	} | 
| Paul Duffin | 44f1d84 | 2020-06-26 20:17:02 +0100 | [diff] [blame] | 2749 | } | 
 | 2750 |  | 
 | 2751 | // Add other dependencies as normal. | 
 | 2752 | func (module *SdkLibraryImport) DepsMutator(ctx android.BottomUpMutatorContext) { | 
| Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 2753 |  | 
 | 2754 | 	implName := module.implLibraryModuleName() | 
 | 2755 | 	if ctx.OtherModuleExists(implName) { | 
 | 2756 | 		ctx.AddVariationDependencies(nil, implLibraryTag, implName) | 
 | 2757 |  | 
 | 2758 | 		xmlPermissionsModuleName := module.xmlPermissionsModuleName() | 
 | 2759 | 		if module.sharedLibrary() && ctx.OtherModuleExists(xmlPermissionsModuleName) { | 
 | 2760 | 			// Add dependency to the rule for generating the xml permissions file | 
 | 2761 | 			ctx.AddDependency(module, xmlPermissionsFileTag, xmlPermissionsModuleName) | 
 | 2762 | 		} | 
 | 2763 | 	} | 
| Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2764 | } | 
 | 2765 |  | 
| Jiyong Park | 45bf82e | 2020-12-15 22:29:02 +0900 | [diff] [blame] | 2766 | var _ android.ApexModule = (*SdkLibraryImport)(nil) | 
 | 2767 |  | 
 | 2768 | // Implements android.ApexModule | 
| Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 2769 | func (module *SdkLibraryImport) DepIsInSameApex(mctx android.BaseModuleContext, dep android.Module) bool { | 
 | 2770 | 	depTag := mctx.OtherModuleDependencyTag(dep) | 
 | 2771 | 	if depTag == xmlPermissionsFileTag { | 
 | 2772 | 		return true | 
 | 2773 | 	} | 
 | 2774 |  | 
 | 2775 | 	// None of the other dependencies of the java_sdk_library_import are in the same apex | 
 | 2776 | 	// as the one that references this module. | 
 | 2777 | 	return false | 
 | 2778 | } | 
 | 2779 |  | 
| Jiyong Park | 45bf82e | 2020-12-15 22:29:02 +0900 | [diff] [blame] | 2780 | // Implements android.ApexModule | 
| Dan Albert | c806053 | 2020-07-22 22:32:17 -0700 | [diff] [blame] | 2781 | func (module *SdkLibraryImport) ShouldSupportSdkVersion(ctx android.BaseModuleContext, | 
 | 2782 | 	sdkVersion android.ApiLevel) error { | 
| Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 2783 | 	// we don't check prebuilt modules for sdk_version | 
 | 2784 | 	return nil | 
 | 2785 | } | 
 | 2786 |  | 
| Paul Duffin | ea8f808 | 2021-06-24 13:25:57 +0100 | [diff] [blame] | 2787 | // Implements android.ApexModule | 
 | 2788 | func (module *SdkLibraryImport) UniqueApexVariations() bool { | 
 | 2789 | 	return module.uniqueApexVariations() | 
 | 2790 | } | 
 | 2791 |  | 
| Paul Duffin | 09817d6 | 2022-04-28 17:45:11 +0100 | [diff] [blame] | 2792 | // MinSdkVersion - Implements hiddenAPIModule | 
| Spandan Das | 8c9ae7e | 2023-03-03 21:20:36 +0000 | [diff] [blame] | 2793 | func (module *SdkLibraryImport) MinSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel { | 
 | 2794 | 	return android.NoneApiLevel | 
| Paul Duffin | 09817d6 | 2022-04-28 17:45:11 +0100 | [diff] [blame] | 2795 | } | 
 | 2796 |  | 
 | 2797 | var _ hiddenAPIModule = (*SdkLibraryImport)(nil) | 
 | 2798 |  | 
| Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 2799 | func (module *SdkLibraryImport) OutputFiles(tag string) (android.Paths, error) { | 
| Paul Duffin | 1e940d5 | 2022-04-29 14:21:25 +0100 | [diff] [blame] | 2800 | 	paths, err := module.commonOutputFiles(tag) | 
 | 2801 | 	if paths != nil || err != nil { | 
 | 2802 | 		return paths, err | 
 | 2803 | 	} | 
 | 2804 | 	if module.implLibraryModule != nil { | 
 | 2805 | 		return module.implLibraryModule.OutputFiles(tag) | 
 | 2806 | 	} else { | 
 | 2807 | 		return nil, nil | 
 | 2808 | 	} | 
| Paul Duffin | 46dc45a | 2020-05-14 15:39:10 +0100 | [diff] [blame] | 2809 | } | 
 | 2810 |  | 
| Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 2811 | func (module *SdkLibraryImport) GenerateAndroidBuildActions(ctx android.ModuleContext) { | 
| Paul Duffin | a2ae7e0 | 2020-09-11 11:55:00 +0100 | [diff] [blame] | 2812 | 	module.generateCommonBuildActions(ctx) | 
 | 2813 |  | 
| Jeongik Cha | d5fe878 | 2021-07-08 01:13:11 +0900 | [diff] [blame] | 2814 | 	// Assume that source module(sdk_library) is installed in /<sdk_library partition>/framework | 
 | 2815 | 	module.installFile = android.PathForModuleInstall(ctx, "framework", module.Stem()+".jar") | 
 | 2816 |  | 
| Paul Duffin | 0f8faff | 2020-05-20 16:18:00 +0100 | [diff] [blame] | 2817 | 	// Record the paths to the prebuilt stubs library and stubs source. | 
| Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2818 | 	ctx.VisitDirectDeps(func(to android.Module) { | 
 | 2819 | 		tag := ctx.OtherModuleDependencyTag(to) | 
 | 2820 |  | 
| Paul Duffin | 0f8faff | 2020-05-20 16:18:00 +0100 | [diff] [blame] | 2821 | 		// Extract information from any of the scope specific dependencies. | 
 | 2822 | 		if scopeTag, ok := tag.(scopeDependencyTag); ok { | 
 | 2823 | 			apiScope := scopeTag.apiScope | 
 | 2824 | 			scopePaths := module.getScopePathsCreateIfNeeded(apiScope) | 
 | 2825 |  | 
 | 2826 | 			// Extract information from the dependency. The exact information extracted | 
 | 2827 | 			// is determined by the nature of the dependency which is determined by the tag. | 
 | 2828 | 			scopeTag.extractDepInfo(ctx, to, scopePaths) | 
| Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 2829 | 		} else if tag == implLibraryTag { | 
 | 2830 | 			if implLibrary, ok := to.(*Library); ok { | 
 | 2831 | 				module.implLibraryModule = implLibrary | 
 | 2832 | 			} else { | 
 | 2833 | 				ctx.ModuleErrorf("implementation library must be of type *java.Library but was %T", to) | 
 | 2834 | 			} | 
 | 2835 | 		} else if tag == xmlPermissionsFileTag { | 
 | 2836 | 			if xmlPermissionsFileModule, ok := to.(*sdkLibraryXml); ok { | 
 | 2837 | 				module.xmlPermissionsFileModule = xmlPermissionsFileModule | 
 | 2838 | 			} else { | 
 | 2839 | 				ctx.ModuleErrorf("xml permissions file module must be of type *sdkLibraryXml but was %T", to) | 
 | 2840 | 			} | 
| Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2841 | 		} | 
 | 2842 | 	}) | 
| Paul Duffin | 0f8faff | 2020-05-20 16:18:00 +0100 | [diff] [blame] | 2843 |  | 
 | 2844 | 	// Populate the scope paths with information from the properties. | 
 | 2845 | 	for apiScope, scopeProperties := range module.scopeProperties { | 
 | 2846 | 		if len(scopeProperties.Jars) == 0 { | 
 | 2847 | 			continue | 
 | 2848 | 		} | 
 | 2849 |  | 
 | 2850 | 		paths := module.getScopePathsCreateIfNeeded(apiScope) | 
| Anton Hansson | d78eb76 | 2021-09-21 15:25:12 +0100 | [diff] [blame] | 2851 | 		paths.annotationsZip = android.OptionalPathForModuleSrc(ctx, scopeProperties.Annotations) | 
| Paul Duffin | 0f8faff | 2020-05-20 16:18:00 +0100 | [diff] [blame] | 2852 | 		paths.currentApiFilePath = android.OptionalPathForModuleSrc(ctx, scopeProperties.Current_api) | 
 | 2853 | 		paths.removedApiFilePath = android.OptionalPathForModuleSrc(ctx, scopeProperties.Removed_api) | 
 | 2854 | 	} | 
| Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 2855 |  | 
 | 2856 | 	if ctx.Device() { | 
 | 2857 | 		// If this is a variant created for a prebuilt_apex then use the dex implementation jar | 
 | 2858 | 		// obtained from the associated deapexer module. | 
| Colin Cross | ff694a8 | 2023-12-13 15:54:49 -0800 | [diff] [blame] | 2859 | 		ai, _ := android.ModuleProvider(ctx, android.ApexInfoProvider) | 
| Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 2860 | 		if ai.ForPrebuiltApex { | 
| Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 2861 | 			// Get the path of the dex implementation jar from the `deapexer` module. | 
| Spandan Das | fae468e | 2023-12-12 23:23:53 +0000 | [diff] [blame] | 2862 | 			di, err := android.FindDeapexerProviderForModule(ctx) | 
 | 2863 | 			if err != nil { | 
 | 2864 | 				// An error was found, possibly due to multiple apexes in the tree that export this library | 
 | 2865 | 				// Defer the error till a client tries to call DexJarBuildPath | 
 | 2866 | 				module.dexJarFileErr = err | 
| Spandan Das | 3a39201 | 2024-01-17 18:26:27 +0000 | [diff] [blame] | 2867 | 				module.initHiddenAPIError(err) | 
| Spandan Das | fae468e | 2023-12-12 23:23:53 +0000 | [diff] [blame] | 2868 | 				return | 
| Martin Stjernholm | 4482560 | 2021-09-17 01:44:12 +0100 | [diff] [blame] | 2869 | 			} | 
| Spandan Das | 5be6333 | 2023-12-13 00:06:32 +0000 | [diff] [blame] | 2870 | 			dexJarFileApexRootRelative := ApexRootRelativePathToJavaLib(module.BaseModuleName()) | 
| Jiakai Zhang | 81e4681 | 2023-02-08 21:56:07 +0800 | [diff] [blame] | 2871 | 			if dexOutputPath := di.PrebuiltExportPath(dexJarFileApexRootRelative); dexOutputPath != nil { | 
| Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 2872 | 				dexJarFile := makeDexJarPathFromPath(dexOutputPath) | 
 | 2873 | 				module.dexJarFile = dexJarFile | 
| Jiakai Zhang | 204356f | 2021-09-09 08:12:46 +0000 | [diff] [blame] | 2874 | 				installPath := android.PathForModuleInPartitionInstall( | 
| Jiakai Zhang | 81e4681 | 2023-02-08 21:56:07 +0800 | [diff] [blame] | 2875 | 					ctx, "apex", ai.ApexVariationName, dexJarFileApexRootRelative) | 
| Jiakai Zhang | 204356f | 2021-09-09 08:12:46 +0000 | [diff] [blame] | 2876 | 				module.installFile = installPath | 
| Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 2877 | 				module.initHiddenAPI(ctx, dexJarFile, module.findScopePaths(apiScopePublic).stubsImplPath[0], nil) | 
| Jiakai Zhang | 204356f | 2021-09-09 08:12:46 +0000 | [diff] [blame] | 2878 |  | 
| Jiakai Zhang | 204356f | 2021-09-09 08:12:46 +0000 | [diff] [blame] | 2879 | 				module.dexpreopter.installPath = module.dexpreopter.getInstallPath(ctx, installPath) | 
 | 2880 | 				module.dexpreopter.isSDKLibrary = true | 
 | 2881 | 				module.dexpreopter.uncompressedDex = shouldUncompressDex(ctx, &module.dexpreopter) | 
| Jiakai Zhang | 81e4681 | 2023-02-08 21:56:07 +0800 | [diff] [blame] | 2882 |  | 
 | 2883 | 				if profilePath := di.PrebuiltExportPath(dexJarFileApexRootRelative + ".prof"); profilePath != nil { | 
 | 2884 | 					module.dexpreopter.inputProfilePathOnHost = profilePath | 
 | 2885 | 				} | 
 | 2886 |  | 
 | 2887 | 				// Dexpreopting. | 
| Jiakai Zhang | 204356f | 2021-09-09 08:12:46 +0000 | [diff] [blame] | 2888 | 				module.dexpreopt(ctx, dexOutputPath) | 
| Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 2889 | 			} else { | 
 | 2890 | 				// This should never happen as a variant for a prebuilt_apex is only created if the | 
 | 2891 | 				// prebuilt_apex has been configured to export the java library dex file. | 
| Martin Stjernholm | 4482560 | 2021-09-17 01:44:12 +0100 | [diff] [blame] | 2892 | 				ctx.ModuleErrorf("internal error: no dex implementation jar available from prebuilt APEX %s", di.ApexModuleName()) | 
| Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 2893 | 			} | 
 | 2894 | 		} | 
 | 2895 | 	} | 
| Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2896 | } | 
 | 2897 |  | 
| Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 2898 | func (module *SdkLibraryImport) sdkJars(ctx android.BaseModuleContext, sdkVersion android.SdkSpec, headerJars bool) android.Paths { | 
| Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 2899 |  | 
 | 2900 | 	// For consistency with SdkLibrary make the implementation jar available to libraries that | 
 | 2901 | 	// are within the same APEX. | 
 | 2902 | 	implLibraryModule := module.implLibraryModule | 
| Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 2903 | 	if implLibraryModule != nil && withinSameApexesAs(ctx, module) { | 
| Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 2904 | 		if headerJars { | 
 | 2905 | 			return implLibraryModule.HeaderJars() | 
 | 2906 | 		} else { | 
 | 2907 | 			return implLibraryModule.ImplementationJars() | 
 | 2908 | 		} | 
 | 2909 | 	} | 
 | 2910 |  | 
| Paul Duffin | 23970f4 | 2020-05-20 14:20:02 +0100 | [diff] [blame] | 2911 | 	return module.selectHeaderJarsForSdkVersion(ctx, sdkVersion) | 
| Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 2912 | } | 
 | 2913 |  | 
| Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2914 | // to satisfy SdkLibraryDependency interface | 
| Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 2915 | func (module *SdkLibraryImport) SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion android.SdkSpec) android.Paths { | 
| Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2916 | 	// This module is just a wrapper for the prebuilt stubs. | 
| Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 2917 | 	return module.sdkJars(ctx, sdkVersion, true) | 
| Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2918 | } | 
 | 2919 |  | 
 | 2920 | // to satisfy SdkLibraryDependency interface | 
| Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 2921 | func (module *SdkLibraryImport) SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion android.SdkSpec) android.Paths { | 
| Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2922 | 	// This module is just a wrapper for the stubs. | 
| Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 2923 | 	return module.sdkJars(ctx, sdkVersion, false) | 
 | 2924 | } | 
 | 2925 |  | 
| Ulya Trafimovich | dbf3166 | 2020-12-17 12:07:54 +0000 | [diff] [blame] | 2926 | // to satisfy UsesLibraryDependency interface | 
| Spandan Das | 59a4a2b | 2024-01-09 21:35:56 +0000 | [diff] [blame] | 2927 | func (module *SdkLibraryImport) DexJarBuildPath(ctx android.ModuleErrorfContext) OptionalDexJarPath { | 
| Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 2928 | 	// The dex implementation jar extracted from the .apex file should be used in preference to the | 
 | 2929 | 	// source. | 
| Spandan Das | fae468e | 2023-12-12 23:23:53 +0000 | [diff] [blame] | 2930 | 	if module.dexJarFileErr != nil { | 
| Spandan Das | 59a4a2b | 2024-01-09 21:35:56 +0000 | [diff] [blame] | 2931 | 		ctx.ModuleErrorf(module.dexJarFileErr.Error()) | 
| Spandan Das | fae468e | 2023-12-12 23:23:53 +0000 | [diff] [blame] | 2932 | 	} | 
| Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 2933 | 	if module.dexJarFile.IsSet() { | 
| Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 2934 | 		return module.dexJarFile | 
 | 2935 | 	} | 
| Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 2936 | 	if module.implLibraryModule == nil { | 
| Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 2937 | 		return makeUnsetDexJarPath() | 
| Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 2938 | 	} else { | 
| Spandan Das | 59a4a2b | 2024-01-09 21:35:56 +0000 | [diff] [blame] | 2939 | 		return module.implLibraryModule.DexJarBuildPath(ctx) | 
| Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 2940 | 	} | 
 | 2941 | } | 
 | 2942 |  | 
| Ulya Trafimovich | dbf3166 | 2020-12-17 12:07:54 +0000 | [diff] [blame] | 2943 | // to satisfy UsesLibraryDependency interface | 
| Ulya Trafimovich | 31e444e | 2020-08-14 17:32:16 +0100 | [diff] [blame] | 2944 | func (module *SdkLibraryImport) DexJarInstallPath() android.Path { | 
| Jeongik Cha | d5fe878 | 2021-07-08 01:13:11 +0900 | [diff] [blame] | 2945 | 	return module.installFile | 
| Ulya Trafimovich | 31e444e | 2020-08-14 17:32:16 +0100 | [diff] [blame] | 2946 | } | 
 | 2947 |  | 
| Ulya Trafimovich | dbf3166 | 2020-12-17 12:07:54 +0000 | [diff] [blame] | 2948 | // to satisfy UsesLibraryDependency interface | 
 | 2949 | func (module *SdkLibraryImport) ClassLoaderContexts() dexpreopt.ClassLoaderContextMap { | 
 | 2950 | 	return nil | 
 | 2951 | } | 
 | 2952 |  | 
| Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 2953 | // to satisfy apex.javaDependency interface | 
 | 2954 | func (module *SdkLibraryImport) JacocoReportClassesFile() android.Path { | 
 | 2955 | 	if module.implLibraryModule == nil { | 
 | 2956 | 		return nil | 
 | 2957 | 	} else { | 
 | 2958 | 		return module.implLibraryModule.JacocoReportClassesFile() | 
 | 2959 | 	} | 
 | 2960 | } | 
 | 2961 |  | 
 | 2962 | // to satisfy apex.javaDependency interface | 
| Colin Cross | 08dca38 | 2020-07-21 20:31:17 -0700 | [diff] [blame] | 2963 | func (module *SdkLibraryImport) LintDepSets() LintDepSets { | 
 | 2964 | 	if module.implLibraryModule == nil { | 
 | 2965 | 		return LintDepSets{} | 
 | 2966 | 	} else { | 
 | 2967 | 		return module.implLibraryModule.LintDepSets() | 
 | 2968 | 	} | 
 | 2969 | } | 
 | 2970 |  | 
| Spandan Das | 17854f5 | 2022-01-14 21:19:14 +0000 | [diff] [blame] | 2971 | func (module *SdkLibraryImport) GetStrictUpdatabilityLinting() bool { | 
| Jaewoong Jung | 476b9d6 | 2021-05-10 15:30:00 -0700 | [diff] [blame] | 2972 | 	if module.implLibraryModule == nil { | 
 | 2973 | 		return false | 
 | 2974 | 	} else { | 
| Spandan Das | 17854f5 | 2022-01-14 21:19:14 +0000 | [diff] [blame] | 2975 | 		return module.implLibraryModule.GetStrictUpdatabilityLinting() | 
| Jaewoong Jung | 476b9d6 | 2021-05-10 15:30:00 -0700 | [diff] [blame] | 2976 | 	} | 
 | 2977 | } | 
 | 2978 |  | 
| Spandan Das | 17854f5 | 2022-01-14 21:19:14 +0000 | [diff] [blame] | 2979 | func (module *SdkLibraryImport) SetStrictUpdatabilityLinting(strictLinting bool) { | 
| Jaewoong Jung | 476b9d6 | 2021-05-10 15:30:00 -0700 | [diff] [blame] | 2980 | 	if module.implLibraryModule != nil { | 
| Spandan Das | 17854f5 | 2022-01-14 21:19:14 +0000 | [diff] [blame] | 2981 | 		module.implLibraryModule.SetStrictUpdatabilityLinting(strictLinting) | 
| Jaewoong Jung | 476b9d6 | 2021-05-10 15:30:00 -0700 | [diff] [blame] | 2982 | 	} | 
 | 2983 | } | 
 | 2984 |  | 
| Colin Cross | 08dca38 | 2020-07-21 20:31:17 -0700 | [diff] [blame] | 2985 | // to satisfy apex.javaDependency interface | 
| Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 2986 | func (module *SdkLibraryImport) Stem() string { | 
 | 2987 | 	return module.BaseModuleName() | 
| Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2988 | } | 
| Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 2989 |  | 
| Paul Duffin | 44b481b | 2020-06-17 16:59:43 +0100 | [diff] [blame] | 2990 | var _ ApexDependency = (*SdkLibraryImport)(nil) | 
 | 2991 |  | 
 | 2992 | // to satisfy java.ApexDependency interface | 
 | 2993 | func (module *SdkLibraryImport) HeaderJars() android.Paths { | 
 | 2994 | 	if module.implLibraryModule == nil { | 
 | 2995 | 		return nil | 
 | 2996 | 	} else { | 
 | 2997 | 		return module.implLibraryModule.HeaderJars() | 
 | 2998 | 	} | 
 | 2999 | } | 
 | 3000 |  | 
 | 3001 | // to satisfy java.ApexDependency interface | 
 | 3002 | func (module *SdkLibraryImport) ImplementationAndResourcesJars() android.Paths { | 
 | 3003 | 	if module.implLibraryModule == nil { | 
 | 3004 | 		return nil | 
 | 3005 | 	} else { | 
 | 3006 | 		return module.implLibraryModule.ImplementationAndResourcesJars() | 
 | 3007 | 	} | 
 | 3008 | } | 
 | 3009 |  | 
| Jiakai Zhang | 204356f | 2021-09-09 08:12:46 +0000 | [diff] [blame] | 3010 | // to satisfy java.DexpreopterInterface interface | 
 | 3011 | func (module *SdkLibraryImport) IsInstallable() bool { | 
 | 3012 | 	return true | 
 | 3013 | } | 
 | 3014 |  | 
| Paul Duffin | fef5500 | 2021-06-17 14:56:05 +0100 | [diff] [blame] | 3015 | var _ android.RequiredFilesFromPrebuiltApex = (*SdkLibraryImport)(nil) | 
 | 3016 |  | 
| Paul Duffin | b4bbf2c | 2021-06-17 15:59:07 +0100 | [diff] [blame] | 3017 | func (module *SdkLibraryImport) RequiredFilesFromPrebuiltApex(ctx android.BaseModuleContext) []string { | 
| Paul Duffin | fef5500 | 2021-06-17 14:56:05 +0100 | [diff] [blame] | 3018 | 	name := module.BaseModuleName() | 
| Jiakai Zhang | 81e4681 | 2023-02-08 21:56:07 +0800 | [diff] [blame] | 3019 | 	return requiredFilesFromPrebuiltApexForImport(name, &module.dexpreopter) | 
| Paul Duffin | fef5500 | 2021-06-17 14:56:05 +0100 | [diff] [blame] | 3020 | } | 
 | 3021 |  | 
| Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 3022 | // java_sdk_library_xml | 
| Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 3023 | type sdkLibraryXml struct { | 
 | 3024 | 	android.ModuleBase | 
 | 3025 | 	android.DefaultableModuleBase | 
 | 3026 | 	android.ApexModuleBase | 
 | 3027 |  | 
 | 3028 | 	properties sdkLibraryXmlProperties | 
 | 3029 |  | 
 | 3030 | 	outputFilePath android.OutputPath | 
 | 3031 | 	installDirPath android.InstallPath | 
| Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 3032 |  | 
 | 3033 | 	hideApexVariantFromMake bool | 
| Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 3034 | } | 
 | 3035 |  | 
 | 3036 | type sdkLibraryXmlProperties struct { | 
 | 3037 | 	// canonical name of the lib | 
 | 3038 | 	Lib_name *string | 
| Pedro Loureiro | 9956e5e | 2021-09-07 17:21:59 +0000 | [diff] [blame] | 3039 |  | 
 | 3040 | 	// Signals that this shared library is part of the bootclasspath starting | 
 | 3041 | 	// on the version indicated in this attribute. | 
 | 3042 | 	// | 
 | 3043 | 	// This will make platforms at this level and above to ignore | 
 | 3044 | 	// <uses-library> tags with this library name because the library is already | 
 | 3045 | 	// available | 
 | 3046 | 	On_bootclasspath_since *string | 
 | 3047 |  | 
 | 3048 | 	// Signals that this shared library was part of the bootclasspath before | 
 | 3049 | 	// (but not including) the version indicated in this attribute. | 
 | 3050 | 	// | 
 | 3051 | 	// The system will automatically add a <uses-library> tag with this library to | 
 | 3052 | 	// apps that target any SDK less than the version indicated in this attribute. | 
 | 3053 | 	On_bootclasspath_before *string | 
 | 3054 |  | 
 | 3055 | 	// Indicates that PackageManager should ignore this shared library if the | 
 | 3056 | 	// platform is below the version indicated in this attribute. | 
 | 3057 | 	// | 
 | 3058 | 	// This means that the device won't recognise this library as installed. | 
 | 3059 | 	Min_device_sdk *string | 
 | 3060 |  | 
 | 3061 | 	// Indicates that PackageManager should ignore this shared library if the | 
 | 3062 | 	// platform is above the version indicated in this attribute. | 
 | 3063 | 	// | 
 | 3064 | 	// This means that the device won't recognise this library as installed. | 
 | 3065 | 	Max_device_sdk *string | 
| Pedro Loureiro | c362142 | 2021-09-28 15:40:23 +0000 | [diff] [blame] | 3066 |  | 
 | 3067 | 	// The SdkLibrary's min api level as a string | 
 | 3068 | 	// | 
 | 3069 | 	// This value comes from the ApiLevel of the MinSdkVersion property. | 
 | 3070 | 	Sdk_library_min_api_level *string | 
| Jamie Garside | e570ace | 2023-11-27 12:07:36 +0000 | [diff] [blame] | 3071 |  | 
 | 3072 | 	// Uses-libs dependencies that the shared library requires to work correctly. | 
 | 3073 | 	// | 
 | 3074 | 	// This will add dependency="foo:bar" to the <library> section. | 
 | 3075 | 	Uses_libs_dependencies []string | 
| Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 3076 | } | 
 | 3077 |  | 
 | 3078 | // java_sdk_library_xml builds the permission xml file for a java_sdk_library. | 
 | 3079 | // Not to be used directly by users. java_sdk_library internally uses this. | 
 | 3080 | func sdkLibraryXmlFactory() android.Module { | 
 | 3081 | 	module := &sdkLibraryXml{} | 
 | 3082 |  | 
 | 3083 | 	module.AddProperties(&module.properties) | 
 | 3084 |  | 
 | 3085 | 	android.InitApexModule(module) | 
 | 3086 | 	android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibCommon) | 
 | 3087 |  | 
 | 3088 | 	return module | 
 | 3089 | } | 
 | 3090 |  | 
| Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3091 | func (module *sdkLibraryXml) UniqueApexVariations() bool { | 
 | 3092 | 	// sdkLibraryXml needs a unique variation per APEX because the generated XML file contains the path to the | 
 | 3093 | 	// mounted APEX, which contains the name of the APEX. | 
 | 3094 | 	return true | 
 | 3095 | } | 
 | 3096 |  | 
| Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 3097 | // from android.PrebuiltEtcModule | 
| Jooyung Han | 0703fd8 | 2020-08-26 22:11:53 +0900 | [diff] [blame] | 3098 | func (module *sdkLibraryXml) BaseDir() string { | 
 | 3099 | 	return "etc" | 
 | 3100 | } | 
 | 3101 |  | 
 | 3102 | // from android.PrebuiltEtcModule | 
| Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 3103 | func (module *sdkLibraryXml) SubDir() string { | 
 | 3104 | 	return "permissions" | 
 | 3105 | } | 
 | 3106 |  | 
 | 3107 | // from android.PrebuiltEtcModule | 
 | 3108 | func (module *sdkLibraryXml) OutputFile() android.OutputPath { | 
 | 3109 | 	return module.outputFilePath | 
 | 3110 | } | 
 | 3111 |  | 
 | 3112 | // from android.ApexModule | 
 | 3113 | func (module *sdkLibraryXml) AvailableFor(what string) bool { | 
 | 3114 | 	return true | 
 | 3115 | } | 
 | 3116 |  | 
 | 3117 | func (module *sdkLibraryXml) DepsMutator(ctx android.BottomUpMutatorContext) { | 
 | 3118 | 	// do nothing | 
 | 3119 | } | 
 | 3120 |  | 
| Jiyong Park | 45bf82e | 2020-12-15 22:29:02 +0900 | [diff] [blame] | 3121 | var _ android.ApexModule = (*sdkLibraryXml)(nil) | 
 | 3122 |  | 
 | 3123 | // Implements android.ApexModule | 
| Dan Albert | c806053 | 2020-07-22 22:32:17 -0700 | [diff] [blame] | 3124 | func (module *sdkLibraryXml) ShouldSupportSdkVersion(ctx android.BaseModuleContext, | 
 | 3125 | 	sdkVersion android.ApiLevel) error { | 
| Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 3126 | 	// sdkLibraryXml doesn't need to be checked separately because java_sdk_library is checked | 
 | 3127 | 	return nil | 
 | 3128 | } | 
 | 3129 |  | 
| Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 3130 | // File path to the runtime implementation library | 
| Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 3131 | func (module *sdkLibraryXml) implPath(ctx android.ModuleContext) string { | 
| Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 3132 | 	implName := proptools.String(module.properties.Lib_name) | 
| Colin Cross | ff694a8 | 2023-12-13 15:54:49 -0800 | [diff] [blame] | 3133 | 	if apexInfo, _ := android.ModuleProvider(ctx, android.ApexInfoProvider); !apexInfo.IsForPlatform() { | 
| Colin Cross | e07f231 | 2020-08-13 11:24:56 -0700 | [diff] [blame] | 3134 | 		// TODO(b/146468504): ApexVariationName() is only a soong module name, not apex name. | 
| Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 3135 | 		// In most cases, this works fine. But when apex_name is set or override_apex is used | 
 | 3136 | 		// this can be wrong. | 
| Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 3137 | 		return fmt.Sprintf("/apex/%s/javalib/%s.jar", apexInfo.ApexVariationName, implName) | 
| Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 3138 | 	} | 
 | 3139 | 	partition := "system" | 
 | 3140 | 	if module.SocSpecific() { | 
 | 3141 | 		partition = "vendor" | 
 | 3142 | 	} else if module.DeviceSpecific() { | 
 | 3143 | 		partition = "odm" | 
 | 3144 | 	} else if module.ProductSpecific() { | 
 | 3145 | 		partition = "product" | 
 | 3146 | 	} else if module.SystemExtSpecific() { | 
 | 3147 | 		partition = "system_ext" | 
 | 3148 | 	} | 
 | 3149 | 	return "/" + partition + "/framework/" + implName + ".jar" | 
 | 3150 | } | 
 | 3151 |  | 
| Pedro Loureiro | 9956e5e | 2021-09-07 17:21:59 +0000 | [diff] [blame] | 3152 | func formattedOptionalSdkLevelAttribute(ctx android.ModuleContext, attrName string, value *string) string { | 
 | 3153 | 	if value == nil { | 
 | 3154 | 		return "" | 
 | 3155 | 	} | 
 | 3156 | 	apiLevel, err := android.ApiLevelFromUser(ctx, *value) | 
 | 3157 | 	if err != nil { | 
| Pedro Loureiro | ba6682f | 2021-10-29 09:32:32 +0000 | [diff] [blame] | 3158 | 		// attributes in bp files have underscores but in the xml have dashes. | 
 | 3159 | 		ctx.PropertyErrorf(strings.ReplaceAll(attrName, "-", "_"), err.Error()) | 
| Pedro Loureiro | 9956e5e | 2021-09-07 17:21:59 +0000 | [diff] [blame] | 3160 | 		return "" | 
 | 3161 | 	} | 
| Pedro Loureiro | b638c62 | 2021-12-22 15:28:05 +0000 | [diff] [blame] | 3162 | 	if apiLevel.IsCurrent() { | 
 | 3163 | 		// passing "current" would always mean a future release, never the current (or the current in | 
 | 3164 | 		// progress) which means some conditions would never be triggered. | 
 | 3165 | 		ctx.PropertyErrorf(strings.ReplaceAll(attrName, "-", "_"), | 
 | 3166 | 			`"current" is not an allowed value for this attribute`) | 
 | 3167 | 		return "" | 
 | 3168 | 	} | 
| Pedro Loureiro | 4899122 | 2022-06-17 20:01:21 +0000 | [diff] [blame] | 3169 | 	// "safeValue" is safe because it translates finalized codenames to a string | 
 | 3170 | 	// with their SDK int. | 
 | 3171 | 	safeValue := apiLevel.String() | 
 | 3172 | 	return formattedOptionalAttribute(attrName, &safeValue) | 
| Pedro Loureiro | 9956e5e | 2021-09-07 17:21:59 +0000 | [diff] [blame] | 3173 | } | 
 | 3174 |  | 
 | 3175 | // formats an attribute for the xml permissions file if the value is not null | 
 | 3176 | // returns empty string otherwise | 
 | 3177 | func formattedOptionalAttribute(attrName string, value *string) string { | 
 | 3178 | 	if value == nil { | 
 | 3179 | 		return "" | 
 | 3180 | 	} | 
 | 3181 | 	return fmt.Sprintf(`        %s=\"%s\"\n`, attrName, *value) | 
 | 3182 | } | 
 | 3183 |  | 
| Jamie Garside | e570ace | 2023-11-27 12:07:36 +0000 | [diff] [blame] | 3184 | func formattedDependenciesAttribute(dependencies []string) string { | 
 | 3185 | 	if dependencies == nil { | 
 | 3186 | 		return "" | 
 | 3187 | 	} | 
 | 3188 | 	return fmt.Sprintf(`        dependency=\"%s\"\n`, strings.Join(dependencies, ":")) | 
 | 3189 | } | 
 | 3190 |  | 
| Pedro Loureiro | 9956e5e | 2021-09-07 17:21:59 +0000 | [diff] [blame] | 3191 | func (module *sdkLibraryXml) permissionsContents(ctx android.ModuleContext) string { | 
 | 3192 | 	libName := proptools.String(module.properties.Lib_name) | 
 | 3193 | 	libNameAttr := formattedOptionalAttribute("name", &libName) | 
 | 3194 | 	filePath := module.implPath(ctx) | 
 | 3195 | 	filePathAttr := formattedOptionalAttribute("file", &filePath) | 
| Pedro Loureiro | ba6682f | 2021-10-29 09:32:32 +0000 | [diff] [blame] | 3196 | 	implicitFromAttr := formattedOptionalSdkLevelAttribute(ctx, "on-bootclasspath-since", module.properties.On_bootclasspath_since) | 
 | 3197 | 	implicitUntilAttr := formattedOptionalSdkLevelAttribute(ctx, "on-bootclasspath-before", module.properties.On_bootclasspath_before) | 
 | 3198 | 	minSdkAttr := formattedOptionalSdkLevelAttribute(ctx, "min-device-sdk", module.properties.Min_device_sdk) | 
 | 3199 | 	maxSdkAttr := formattedOptionalSdkLevelAttribute(ctx, "max-device-sdk", module.properties.Max_device_sdk) | 
| Jamie Garside | e570ace | 2023-11-27 12:07:36 +0000 | [diff] [blame] | 3200 | 	dependenciesAttr := formattedDependenciesAttribute(module.properties.Uses_libs_dependencies) | 
| Pedro Loureiro | 196d3e6 | 2021-12-22 19:53:01 +0000 | [diff] [blame] | 3201 | 	// <library> is understood in all android versions whereas <apex-library> is only understood from API T (and ignored before that). | 
 | 3202 | 	// similarly, min_device_sdk is only understood from T. So if a library is using that, we need to use the apex-library to make sure this library is not loaded before T | 
| Pedro Loureiro | c362142 | 2021-09-28 15:40:23 +0000 | [diff] [blame] | 3203 | 	var libraryTag string | 
 | 3204 | 	if module.properties.Min_device_sdk != nil { | 
| Pedro Loureiro | 196d3e6 | 2021-12-22 19:53:01 +0000 | [diff] [blame] | 3205 | 		libraryTag = `    <apex-library\n` | 
| Pedro Loureiro | c362142 | 2021-09-28 15:40:23 +0000 | [diff] [blame] | 3206 | 	} else { | 
 | 3207 | 		libraryTag = `    <library\n` | 
 | 3208 | 	} | 
| Pedro Loureiro | 9956e5e | 2021-09-07 17:21:59 +0000 | [diff] [blame] | 3209 |  | 
 | 3210 | 	return strings.Join([]string{ | 
 | 3211 | 		`<?xml version=\"1.0\" encoding=\"utf-8\"?>\n`, | 
 | 3212 | 		`<!-- Copyright (C) 2018 The Android Open Source Project\n`, | 
 | 3213 | 		`\n`, | 
 | 3214 | 		`    Licensed under the Apache License, Version 2.0 (the \"License\");\n`, | 
 | 3215 | 		`    you may not use this file except in compliance with the License.\n`, | 
 | 3216 | 		`    You may obtain a copy of the License at\n`, | 
 | 3217 | 		`\n`, | 
 | 3218 | 		`        http://www.apache.org/licenses/LICENSE-2.0\n`, | 
 | 3219 | 		`\n`, | 
 | 3220 | 		`    Unless required by applicable law or agreed to in writing, software\n`, | 
 | 3221 | 		`    distributed under the License is distributed on an \"AS IS\" BASIS,\n`, | 
 | 3222 | 		`    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n`, | 
 | 3223 | 		`    See the License for the specific language governing permissions and\n`, | 
 | 3224 | 		`    limitations under the License.\n`, | 
 | 3225 | 		`-->\n`, | 
 | 3226 | 		`<permissions>\n`, | 
| Pedro Loureiro | c362142 | 2021-09-28 15:40:23 +0000 | [diff] [blame] | 3227 | 		libraryTag, | 
| Pedro Loureiro | 9956e5e | 2021-09-07 17:21:59 +0000 | [diff] [blame] | 3228 | 		libNameAttr, | 
 | 3229 | 		filePathAttr, | 
 | 3230 | 		implicitFromAttr, | 
 | 3231 | 		implicitUntilAttr, | 
 | 3232 | 		minSdkAttr, | 
 | 3233 | 		maxSdkAttr, | 
| Jamie Garside | e570ace | 2023-11-27 12:07:36 +0000 | [diff] [blame] | 3234 | 		dependenciesAttr, | 
| Pedro Loureiro | 9956e5e | 2021-09-07 17:21:59 +0000 | [diff] [blame] | 3235 | 		`    />\n`, | 
 | 3236 | 		`</permissions>\n`}, "") | 
 | 3237 | } | 
 | 3238 |  | 
| Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 3239 | func (module *sdkLibraryXml) GenerateAndroidBuildActions(ctx android.ModuleContext) { | 
| Colin Cross | ff694a8 | 2023-12-13 15:54:49 -0800 | [diff] [blame] | 3240 | 	apexInfo, _ := android.ModuleProvider(ctx, android.ApexInfoProvider) | 
 | 3241 | 	module.hideApexVariantFromMake = !apexInfo.IsForPlatform() | 
| Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 3242 |  | 
| Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 3243 | 	libName := proptools.String(module.properties.Lib_name) | 
| Pedro Loureiro | c362142 | 2021-09-28 15:40:23 +0000 | [diff] [blame] | 3244 | 	module.selfValidate(ctx) | 
| Pedro Loureiro | 9956e5e | 2021-09-07 17:21:59 +0000 | [diff] [blame] | 3245 | 	xmlContent := module.permissionsContents(ctx) | 
| Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 3246 |  | 
 | 3247 | 	module.outputFilePath = android.PathForModuleOut(ctx, libName+".xml").OutputPath | 
| Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 3248 | 	rule := android.NewRuleBuilder(pctx, ctx) | 
| Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 3249 | 	rule.Command(). | 
 | 3250 | 		Text("/bin/bash -c \"echo -e '" + xmlContent + "'\" > "). | 
 | 3251 | 		Output(module.outputFilePath) | 
 | 3252 |  | 
| Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 3253 | 	rule.Build("java_sdk_xml", "Permission XML") | 
| Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 3254 |  | 
 | 3255 | 	module.installDirPath = android.PathForModuleInstall(ctx, "etc", module.SubDir()) | 
 | 3256 | } | 
 | 3257 |  | 
 | 3258 | func (module *sdkLibraryXml) AndroidMkEntries() []android.AndroidMkEntries { | 
| Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 3259 | 	if module.hideApexVariantFromMake { | 
| satayev | 8f088b0 | 2021-12-06 11:40:46 +0000 | [diff] [blame] | 3260 | 		return []android.AndroidMkEntries{{ | 
| Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 3261 | 			Disabled: true, | 
 | 3262 | 		}} | 
 | 3263 | 	} | 
 | 3264 |  | 
| satayev | 8f088b0 | 2021-12-06 11:40:46 +0000 | [diff] [blame] | 3265 | 	return []android.AndroidMkEntries{{ | 
| Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 3266 | 		Class:      "ETC", | 
 | 3267 | 		OutputFile: android.OptionalPathForPath(module.outputFilePath), | 
 | 3268 | 		ExtraEntries: []android.AndroidMkExtraEntriesFunc{ | 
| Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 3269 | 			func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { | 
| Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 3270 | 				entries.SetString("LOCAL_MODULE_TAGS", "optional") | 
| Colin Cross | c68db4b | 2021-11-11 18:59:15 -0800 | [diff] [blame] | 3271 | 				entries.SetString("LOCAL_MODULE_PATH", module.installDirPath.String()) | 
| Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 3272 | 				entries.SetString("LOCAL_INSTALLED_MODULE_STEM", module.outputFilePath.Base()) | 
 | 3273 | 			}, | 
 | 3274 | 		}, | 
 | 3275 | 	}} | 
 | 3276 | } | 
| Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 3277 |  | 
| Pedro Loureiro | c362142 | 2021-09-28 15:40:23 +0000 | [diff] [blame] | 3278 | func (module *sdkLibraryXml) selfValidate(ctx android.ModuleContext) { | 
 | 3279 | 	module.validateAtLeastTAttributes(ctx) | 
 | 3280 | 	module.validateMinAndMaxDeviceSdk(ctx) | 
 | 3281 | 	module.validateMinMaxDeviceSdkAndModuleMinSdk(ctx) | 
 | 3282 | 	module.validateOnBootclasspathBeforeRequirements(ctx) | 
 | 3283 | } | 
 | 3284 |  | 
 | 3285 | func (module *sdkLibraryXml) validateAtLeastTAttributes(ctx android.ModuleContext) { | 
 | 3286 | 	t := android.ApiLevelOrPanic(ctx, "Tiramisu") | 
 | 3287 | 	module.attrAtLeastT(ctx, t, module.properties.Min_device_sdk, "min_device_sdk") | 
 | 3288 | 	module.attrAtLeastT(ctx, t, module.properties.Max_device_sdk, "max_device_sdk") | 
 | 3289 | 	module.attrAtLeastT(ctx, t, module.properties.On_bootclasspath_before, "on_bootclasspath_before") | 
 | 3290 | 	module.attrAtLeastT(ctx, t, module.properties.On_bootclasspath_since, "on_bootclasspath_since") | 
 | 3291 | } | 
 | 3292 |  | 
 | 3293 | func (module *sdkLibraryXml) attrAtLeastT(ctx android.ModuleContext, t android.ApiLevel, attr *string, attrName string) { | 
 | 3294 | 	if attr != nil { | 
 | 3295 | 		if level, err := android.ApiLevelFromUser(ctx, *attr); err == nil { | 
 | 3296 | 			// we will inform the user of invalid inputs when we try to write the | 
 | 3297 | 			// permissions xml file so we don't need to do it here | 
 | 3298 | 			if t.GreaterThan(level) { | 
 | 3299 | 				ctx.PropertyErrorf(attrName, "Attribute value needs to be at least T") | 
 | 3300 | 			} | 
 | 3301 | 		} | 
 | 3302 | 	} | 
 | 3303 | } | 
 | 3304 |  | 
 | 3305 | func (module *sdkLibraryXml) validateMinAndMaxDeviceSdk(ctx android.ModuleContext) { | 
 | 3306 | 	if module.properties.Min_device_sdk != nil && module.properties.Max_device_sdk != nil { | 
 | 3307 | 		min, minErr := android.ApiLevelFromUser(ctx, *module.properties.Min_device_sdk) | 
 | 3308 | 		max, maxErr := android.ApiLevelFromUser(ctx, *module.properties.Max_device_sdk) | 
 | 3309 | 		if minErr == nil && maxErr == nil { | 
 | 3310 | 			// we will inform the user of invalid inputs when we try to write the | 
 | 3311 | 			// permissions xml file so we don't need to do it here | 
 | 3312 | 			if min.GreaterThan(max) { | 
 | 3313 | 				ctx.ModuleErrorf("min_device_sdk can't be greater than max_device_sdk") | 
 | 3314 | 			} | 
 | 3315 | 		} | 
 | 3316 | 	} | 
 | 3317 | } | 
 | 3318 |  | 
 | 3319 | func (module *sdkLibraryXml) validateMinMaxDeviceSdkAndModuleMinSdk(ctx android.ModuleContext) { | 
 | 3320 | 	moduleMinApi := android.ApiLevelOrPanic(ctx, *module.properties.Sdk_library_min_api_level) | 
 | 3321 | 	if module.properties.Min_device_sdk != nil { | 
 | 3322 | 		api, err := android.ApiLevelFromUser(ctx, *module.properties.Min_device_sdk) | 
 | 3323 | 		if err == nil { | 
 | 3324 | 			if moduleMinApi.GreaterThan(api) { | 
 | 3325 | 				ctx.PropertyErrorf("min_device_sdk", "Can't be less than module's min sdk (%s)", moduleMinApi) | 
 | 3326 | 			} | 
 | 3327 | 		} | 
 | 3328 | 	} | 
 | 3329 | 	if module.properties.Max_device_sdk != nil { | 
 | 3330 | 		api, err := android.ApiLevelFromUser(ctx, *module.properties.Max_device_sdk) | 
 | 3331 | 		if err == nil { | 
 | 3332 | 			if moduleMinApi.GreaterThan(api) { | 
 | 3333 | 				ctx.PropertyErrorf("max_device_sdk", "Can't be less than module's min sdk (%s)", moduleMinApi) | 
 | 3334 | 			} | 
 | 3335 | 		} | 
 | 3336 | 	} | 
 | 3337 | } | 
 | 3338 |  | 
 | 3339 | func (module *sdkLibraryXml) validateOnBootclasspathBeforeRequirements(ctx android.ModuleContext) { | 
 | 3340 | 	moduleMinApi := android.ApiLevelOrPanic(ctx, *module.properties.Sdk_library_min_api_level) | 
 | 3341 | 	if module.properties.On_bootclasspath_before != nil { | 
 | 3342 | 		t := android.ApiLevelOrPanic(ctx, "Tiramisu") | 
 | 3343 | 		// if we use the attribute, then we need to do this validation | 
 | 3344 | 		if moduleMinApi.LessThan(t) { | 
 | 3345 | 			// if minAPi is < T, then we need to have min_device_sdk (which only accepts T+) | 
 | 3346 | 			if module.properties.Min_device_sdk == nil { | 
 | 3347 | 				ctx.PropertyErrorf("on_bootclasspath_before", "Using this property requires that the module's min_sdk_version or the shared library's min_device_sdk is at least T") | 
 | 3348 | 			} | 
 | 3349 | 		} | 
 | 3350 | 	} | 
 | 3351 | } | 
 | 3352 |  | 
| Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 3353 | type sdkLibrarySdkMemberType struct { | 
 | 3354 | 	android.SdkMemberTypeBase | 
 | 3355 | } | 
 | 3356 |  | 
| Paul Duffin | 296701e | 2021-07-14 10:29:36 +0100 | [diff] [blame] | 3357 | func (s *sdkLibrarySdkMemberType) AddDependencies(ctx android.SdkDependencyContext, dependencyTag blueprint.DependencyTag, names []string) { | 
 | 3358 | 	ctx.AddVariationDependencies(nil, dependencyTag, names...) | 
| Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 3359 | } | 
 | 3360 |  | 
 | 3361 | func (s *sdkLibrarySdkMemberType) IsInstance(module android.Module) bool { | 
 | 3362 | 	_, ok := module.(*SdkLibrary) | 
 | 3363 | 	return ok | 
 | 3364 | } | 
 | 3365 |  | 
 | 3366 | func (s *sdkLibrarySdkMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule { | 
 | 3367 | 	return ctx.SnapshotBuilder().AddPrebuiltModule(member, "java_sdk_library_import") | 
 | 3368 | } | 
 | 3369 |  | 
 | 3370 | func (s *sdkLibrarySdkMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties { | 
 | 3371 | 	return &sdkLibrarySdkMemberProperties{} | 
 | 3372 | } | 
 | 3373 |  | 
| Paul Duffin | 976b0e5 | 2021-04-27 23:20:26 +0100 | [diff] [blame] | 3374 | var javaSdkLibrarySdkMemberType = &sdkLibrarySdkMemberType{ | 
 | 3375 | 	android.SdkMemberTypeBase{ | 
 | 3376 | 		PropertyName: "java_sdk_libs", | 
 | 3377 | 		SupportsSdk:  true, | 
 | 3378 | 	}, | 
 | 3379 | } | 
 | 3380 |  | 
| Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 3381 | type sdkLibrarySdkMemberProperties struct { | 
 | 3382 | 	android.SdkMemberPropertiesBase | 
 | 3383 |  | 
| Paul Duffin | e840995 | 2022-09-22 16:24:46 +0100 | [diff] [blame] | 3384 | 	// Stem name for files in the sdk snapshot. | 
 | 3385 | 	// | 
 | 3386 | 	// This is used to construct the path names of various sdk library files in the sdk snapshot to | 
 | 3387 | 	// make sure that they match the finalized versions of those files in prebuilts/sdk. | 
 | 3388 | 	// | 
 | 3389 | 	// This property is marked as keep so that it will be kept in all instances of this struct, will | 
 | 3390 | 	// not be cleared but will be copied to common structs. That is needed because this field is used | 
 | 3391 | 	// to construct many file names for other parts of this struct and so it needs to be present in | 
 | 3392 | 	// all structs. If it was not marked as keep then it would be cleared in some structs and so would | 
 | 3393 | 	// be unavailable for generating file names if there were other properties that were still set. | 
 | 3394 | 	Stem string `sdk:"keep"` | 
 | 3395 |  | 
| Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 3396 | 	// Scope to per scope properties. | 
| Paul Duffin | 106a3a4 | 2022-01-27 16:39:06 +0000 | [diff] [blame] | 3397 | 	Scopes map[*apiScope]*scopeProperties | 
| Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 3398 |  | 
| Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 3399 | 	// The Java stubs source files. | 
 | 3400 | 	Stub_srcs []string | 
| Paul Duffin | f7a6433 | 2020-05-13 16:54:55 +0100 | [diff] [blame] | 3401 |  | 
 | 3402 | 	// The naming scheme. | 
 | 3403 | 	Naming_scheme *string | 
| Paul Duffin | d7eb1c2 | 2020-05-26 20:57:10 +0100 | [diff] [blame] | 3404 |  | 
 | 3405 | 	// True if the java_sdk_library_import is for a shared library, false | 
 | 3406 | 	// otherwise. | 
 | 3407 | 	Shared_library *bool | 
| Paul Duffin | a2ae7e0 | 2020-09-11 11:55:00 +0100 | [diff] [blame] | 3408 |  | 
| Paul Duffin | 1267d87 | 2021-04-16 17:21:36 +0100 | [diff] [blame] | 3409 | 	// True if the stub imports should produce dex jars. | 
 | 3410 | 	Compile_dex *bool | 
 | 3411 |  | 
| Paul Duffin | a2ae7e0 | 2020-09-11 11:55:00 +0100 | [diff] [blame] | 3412 | 	// The paths to the doctag files to add to the prebuilt. | 
 | 3413 | 	Doctag_paths android.Paths | 
| Paul Duffin | 869de14 | 2021-07-15 14:14:41 +0100 | [diff] [blame] | 3414 |  | 
 | 3415 | 	Permitted_packages []string | 
| Pedro Loureiro | 9956e5e | 2021-09-07 17:21:59 +0000 | [diff] [blame] | 3416 |  | 
 | 3417 | 	// Signals that this shared library is part of the bootclasspath starting | 
 | 3418 | 	// on the version indicated in this attribute. | 
 | 3419 | 	// | 
 | 3420 | 	// This will make platforms at this level and above to ignore | 
 | 3421 | 	// <uses-library> tags with this library name because the library is already | 
 | 3422 | 	// available | 
 | 3423 | 	On_bootclasspath_since *string | 
 | 3424 |  | 
 | 3425 | 	// Signals that this shared library was part of the bootclasspath before | 
 | 3426 | 	// (but not including) the version indicated in this attribute. | 
 | 3427 | 	// | 
 | 3428 | 	// The system will automatically add a <uses-library> tag with this library to | 
 | 3429 | 	// apps that target any SDK less than the version indicated in this attribute. | 
 | 3430 | 	On_bootclasspath_before *string | 
 | 3431 |  | 
 | 3432 | 	// Indicates that PackageManager should ignore this shared library if the | 
 | 3433 | 	// platform is below the version indicated in this attribute. | 
 | 3434 | 	// | 
 | 3435 | 	// This means that the device won't recognise this library as installed. | 
 | 3436 | 	Min_device_sdk *string | 
 | 3437 |  | 
 | 3438 | 	// Indicates that PackageManager should ignore this shared library if the | 
 | 3439 | 	// platform is above the version indicated in this attribute. | 
 | 3440 | 	// | 
 | 3441 | 	// This means that the device won't recognise this library as installed. | 
 | 3442 | 	Max_device_sdk *string | 
| Jiakai Zhang | 9c4dc19 | 2023-02-09 00:09:24 +0800 | [diff] [blame] | 3443 |  | 
 | 3444 | 	DexPreoptProfileGuided *bool `supported_build_releases:"UpsideDownCake+"` | 
| Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 3445 | } | 
 | 3446 |  | 
 | 3447 | type scopeProperties struct { | 
| Paul Duffin | 1fd005d | 2020-04-09 01:08:11 +0100 | [diff] [blame] | 3448 | 	Jars           android.Paths | 
 | 3449 | 	StubsSrcJar    android.Path | 
 | 3450 | 	CurrentApiFile android.Path | 
 | 3451 | 	RemovedApiFile android.Path | 
| Paul Duffin | e7babdb | 2022-02-10 13:06:54 +0000 | [diff] [blame] | 3452 | 	AnnotationsZip android.Path `supported_build_releases:"Tiramisu+"` | 
| Paul Duffin | 1fd005d | 2020-04-09 01:08:11 +0100 | [diff] [blame] | 3453 | 	SdkVersion     string | 
| Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 3454 | } | 
 | 3455 |  | 
 | 3456 | func (s *sdkLibrarySdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) { | 
 | 3457 | 	sdk := variant.(*SdkLibrary) | 
 | 3458 |  | 
| Paul Duffin | e840995 | 2022-09-22 16:24:46 +0100 | [diff] [blame] | 3459 | 	// Copy the stem name for files in the sdk snapshot. | 
 | 3460 | 	s.Stem = sdk.distStem() | 
 | 3461 |  | 
| Paul Duffin | 106a3a4 | 2022-01-27 16:39:06 +0000 | [diff] [blame] | 3462 | 	s.Scopes = make(map[*apiScope]*scopeProperties) | 
| Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 3463 | 	for _, apiScope := range allApiScopes { | 
| Paul Duffin | 803a956 | 2020-05-20 11:52:25 +0100 | [diff] [blame] | 3464 | 		paths := sdk.findScopePaths(apiScope) | 
 | 3465 | 		if paths == nil { | 
 | 3466 | 			continue | 
 | 3467 | 		} | 
 | 3468 |  | 
| Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 3469 | 		jars := paths.stubsImplPath | 
 | 3470 | 		if len(jars) > 0 { | 
 | 3471 | 			properties := scopeProperties{} | 
 | 3472 | 			properties.Jars = jars | 
| Paul Duffin | 780c5f4 | 2020-05-12 15:52:55 +0100 | [diff] [blame] | 3473 | 			properties.SdkVersion = sdk.sdkVersionForStubsLibrary(ctx.SdkModuleContext(), apiScope) | 
| Paul Duffin | 0f8faff | 2020-05-20 16:18:00 +0100 | [diff] [blame] | 3474 | 			properties.StubsSrcJar = paths.stubsSrcJar.Path() | 
| Paul Duffin | 10269f1 | 2020-06-19 18:39:55 +0100 | [diff] [blame] | 3475 | 			if paths.currentApiFilePath.Valid() { | 
 | 3476 | 				properties.CurrentApiFile = paths.currentApiFilePath.Path() | 
 | 3477 | 			} | 
 | 3478 | 			if paths.removedApiFilePath.Valid() { | 
 | 3479 | 				properties.RemovedApiFile = paths.removedApiFilePath.Path() | 
 | 3480 | 			} | 
| Anton Hansson | d78eb76 | 2021-09-21 15:25:12 +0100 | [diff] [blame] | 3481 | 			// The annotations zip is only available for modules that set annotations_enabled: true. | 
 | 3482 | 			if paths.annotationsZip.Valid() { | 
 | 3483 | 				properties.AnnotationsZip = paths.annotationsZip.Path() | 
 | 3484 | 			} | 
| Paul Duffin | 106a3a4 | 2022-01-27 16:39:06 +0000 | [diff] [blame] | 3485 | 			s.Scopes[apiScope] = &properties | 
| Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 3486 | 		} | 
 | 3487 | 	} | 
 | 3488 |  | 
| Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 3489 | 	s.Naming_scheme = sdk.commonSdkLibraryProperties.Naming_scheme | 
| Paul Duffin | d7eb1c2 | 2020-05-26 20:57:10 +0100 | [diff] [blame] | 3490 | 	s.Shared_library = proptools.BoolPtr(sdk.sharedLibrary()) | 
| Paul Duffin | 1267d87 | 2021-04-16 17:21:36 +0100 | [diff] [blame] | 3491 | 	s.Compile_dex = sdk.dexProperties.Compile_dex | 
| Paul Duffin | a2ae7e0 | 2020-09-11 11:55:00 +0100 | [diff] [blame] | 3492 | 	s.Doctag_paths = sdk.doctagPaths | 
| Paul Duffin | 869de14 | 2021-07-15 14:14:41 +0100 | [diff] [blame] | 3493 | 	s.Permitted_packages = sdk.PermittedPackagesForUpdatableBootJars() | 
| Pedro Loureiro | 9956e5e | 2021-09-07 17:21:59 +0000 | [diff] [blame] | 3494 | 	s.On_bootclasspath_since = sdk.commonSdkLibraryProperties.On_bootclasspath_since | 
 | 3495 | 	s.On_bootclasspath_before = sdk.commonSdkLibraryProperties.On_bootclasspath_before | 
 | 3496 | 	s.Min_device_sdk = sdk.commonSdkLibraryProperties.Min_device_sdk | 
 | 3497 | 	s.Max_device_sdk = sdk.commonSdkLibraryProperties.Max_device_sdk | 
| Jiakai Zhang | 9c4dc19 | 2023-02-09 00:09:24 +0800 | [diff] [blame] | 3498 |  | 
 | 3499 | 	if sdk.dexpreopter.dexpreoptProperties.Dex_preopt_result.Profile_guided { | 
 | 3500 | 		s.DexPreoptProfileGuided = proptools.BoolPtr(true) | 
 | 3501 | 	} | 
| Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 3502 | } | 
 | 3503 |  | 
 | 3504 | func (s *sdkLibrarySdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) { | 
| Paul Duffin | f7a6433 | 2020-05-13 16:54:55 +0100 | [diff] [blame] | 3505 | 	if s.Naming_scheme != nil { | 
 | 3506 | 		propertySet.AddProperty("naming_scheme", proptools.String(s.Naming_scheme)) | 
 | 3507 | 	} | 
| Paul Duffin | d7eb1c2 | 2020-05-26 20:57:10 +0100 | [diff] [blame] | 3508 | 	if s.Shared_library != nil { | 
 | 3509 | 		propertySet.AddProperty("shared_library", *s.Shared_library) | 
 | 3510 | 	} | 
| Paul Duffin | 1267d87 | 2021-04-16 17:21:36 +0100 | [diff] [blame] | 3511 | 	if s.Compile_dex != nil { | 
 | 3512 | 		propertySet.AddProperty("compile_dex", *s.Compile_dex) | 
 | 3513 | 	} | 
| Paul Duffin | 869de14 | 2021-07-15 14:14:41 +0100 | [diff] [blame] | 3514 | 	if len(s.Permitted_packages) > 0 { | 
 | 3515 | 		propertySet.AddProperty("permitted_packages", s.Permitted_packages) | 
 | 3516 | 	} | 
| Jiakai Zhang | 9c4dc19 | 2023-02-09 00:09:24 +0800 | [diff] [blame] | 3517 | 	dexPreoptSet := propertySet.AddPropertySet("dex_preopt") | 
 | 3518 | 	if s.DexPreoptProfileGuided != nil { | 
 | 3519 | 		dexPreoptSet.AddProperty("profile_guided", proptools.Bool(s.DexPreoptProfileGuided)) | 
 | 3520 | 	} | 
| Paul Duffin | f7a6433 | 2020-05-13 16:54:55 +0100 | [diff] [blame] | 3521 |  | 
| Paul Duffin | e840995 | 2022-09-22 16:24:46 +0100 | [diff] [blame] | 3522 | 	stem := s.Stem | 
 | 3523 |  | 
| Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 3524 | 	for _, apiScope := range allApiScopes { | 
 | 3525 | 		if properties, ok := s.Scopes[apiScope]; ok { | 
| Paul Duffin | 6b836ba | 2020-05-13 19:19:49 +0100 | [diff] [blame] | 3526 | 			scopeSet := propertySet.AddPropertySet(apiScope.propertyName) | 
| Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 3527 |  | 
| Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 3528 | 			scopeDir := apiScope.snapshotRelativeDir() | 
| Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 3529 |  | 
| Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 3530 | 			var jars []string | 
 | 3531 | 			for _, p := range properties.Jars { | 
| Paul Duffin | e840995 | 2022-09-22 16:24:46 +0100 | [diff] [blame] | 3532 | 				dest := filepath.Join(scopeDir, stem+"-stubs.jar") | 
| Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 3533 | 				ctx.SnapshotBuilder().CopyToSnapshot(p, dest) | 
 | 3534 | 				jars = append(jars, dest) | 
 | 3535 | 			} | 
 | 3536 | 			scopeSet.AddProperty("jars", jars) | 
 | 3537 |  | 
| Paul Duffin | 22628d5 | 2021-05-12 23:13:22 +0100 | [diff] [blame] | 3538 | 			if ctx.SdkModuleContext().Config().IsEnvTrue("SOONG_SDK_SNAPSHOT_USE_SRCJAR") { | 
 | 3539 | 				// Copy the stubs source jar into the snapshot zip as is. | 
| Paul Duffin | e840995 | 2022-09-22 16:24:46 +0100 | [diff] [blame] | 3540 | 				srcJarSnapshotPath := filepath.Join(scopeDir, stem+".srcjar") | 
| Paul Duffin | 22628d5 | 2021-05-12 23:13:22 +0100 | [diff] [blame] | 3541 | 				ctx.SnapshotBuilder().CopyToSnapshot(properties.StubsSrcJar, srcJarSnapshotPath) | 
 | 3542 | 				scopeSet.AddProperty("stub_srcs", []string{srcJarSnapshotPath}) | 
 | 3543 | 			} else { | 
 | 3544 | 				// Merge the stubs source jar into the snapshot zip so that when it is unpacked | 
 | 3545 | 				// the source files are also unpacked. | 
| Paul Duffin | e840995 | 2022-09-22 16:24:46 +0100 | [diff] [blame] | 3546 | 				snapshotRelativeDir := filepath.Join(scopeDir, stem+"_stub_sources") | 
| Paul Duffin | 22628d5 | 2021-05-12 23:13:22 +0100 | [diff] [blame] | 3547 | 				ctx.SnapshotBuilder().UnzipToSnapshot(properties.StubsSrcJar, snapshotRelativeDir) | 
 | 3548 | 				scopeSet.AddProperty("stub_srcs", []string{snapshotRelativeDir}) | 
 | 3549 | 			} | 
| Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 3550 |  | 
| Paul Duffin | 1fd005d | 2020-04-09 01:08:11 +0100 | [diff] [blame] | 3551 | 			if properties.CurrentApiFile != nil { | 
| Paul Duffin | e840995 | 2022-09-22 16:24:46 +0100 | [diff] [blame] | 3552 | 				currentApiSnapshotPath := apiScope.snapshotRelativeCurrentApiTxtPath(stem) | 
| Paul Duffin | 1fd005d | 2020-04-09 01:08:11 +0100 | [diff] [blame] | 3553 | 				ctx.SnapshotBuilder().CopyToSnapshot(properties.CurrentApiFile, currentApiSnapshotPath) | 
 | 3554 | 				scopeSet.AddProperty("current_api", currentApiSnapshotPath) | 
 | 3555 | 			} | 
 | 3556 |  | 
 | 3557 | 			if properties.RemovedApiFile != nil { | 
| Paul Duffin | e840995 | 2022-09-22 16:24:46 +0100 | [diff] [blame] | 3558 | 				removedApiSnapshotPath := apiScope.snapshotRelativeRemovedApiTxtPath(stem) | 
| Paul Duffin | 3dbf9fd | 2020-06-02 13:00:02 +0100 | [diff] [blame] | 3559 | 				ctx.SnapshotBuilder().CopyToSnapshot(properties.RemovedApiFile, removedApiSnapshotPath) | 
| Paul Duffin | 1fd005d | 2020-04-09 01:08:11 +0100 | [diff] [blame] | 3560 | 				scopeSet.AddProperty("removed_api", removedApiSnapshotPath) | 
 | 3561 | 			} | 
 | 3562 |  | 
| Anton Hansson | d78eb76 | 2021-09-21 15:25:12 +0100 | [diff] [blame] | 3563 | 			if properties.AnnotationsZip != nil { | 
| Paul Duffin | e840995 | 2022-09-22 16:24:46 +0100 | [diff] [blame] | 3564 | 				annotationsSnapshotPath := filepath.Join(scopeDir, stem+"_annotations.zip") | 
| Anton Hansson | d78eb76 | 2021-09-21 15:25:12 +0100 | [diff] [blame] | 3565 | 				ctx.SnapshotBuilder().CopyToSnapshot(properties.AnnotationsZip, annotationsSnapshotPath) | 
 | 3566 | 				scopeSet.AddProperty("annotations", annotationsSnapshotPath) | 
 | 3567 | 			} | 
 | 3568 |  | 
| Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 3569 | 			if properties.SdkVersion != "" { | 
 | 3570 | 				scopeSet.AddProperty("sdk_version", properties.SdkVersion) | 
 | 3571 | 			} | 
 | 3572 | 		} | 
 | 3573 | 	} | 
 | 3574 |  | 
| Paul Duffin | a2ae7e0 | 2020-09-11 11:55:00 +0100 | [diff] [blame] | 3575 | 	if len(s.Doctag_paths) > 0 { | 
 | 3576 | 		dests := []string{} | 
 | 3577 | 		for _, p := range s.Doctag_paths { | 
 | 3578 | 			dest := filepath.Join("doctags", p.Rel()) | 
 | 3579 | 			ctx.SnapshotBuilder().CopyToSnapshot(p, dest) | 
 | 3580 | 			dests = append(dests, dest) | 
 | 3581 | 		} | 
 | 3582 | 		propertySet.AddProperty("doctag_files", dests) | 
 | 3583 | 	} | 
| Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 3584 | } |