blob: 83bc04eb8efb3e6154ff9760ed14e5818e903462 [file] [log] [blame]
Jiyong Parkc678ad32018-04-10 13:07:10 +09001// 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
15package java
16
17import (
Jiyong Parkc678ad32018-04-10 13:07:10 +090018 "fmt"
19 "path"
Sundong Ahn054b19a2018-10-19 13:46:09 +090020 "path/filepath"
Paul Duffin46a26a82020-04-07 19:27:04 +010021 "reflect"
Paul Duffin46dc45a2020-05-14 15:39:10 +010022 "regexp"
Jiyong Park82484c02018-04-23 21:41:26 +090023 "sort"
Jiyong Parkc678ad32018-04-10 13:07:10 +090024 "strings"
Jiyong Park82484c02018-04-23 21:41:26 +090025 "sync"
Jiyong Parkc678ad32018-04-10 13:07:10 +090026
Paul Duffind1b3a922020-01-22 11:57:20 +000027 "github.com/google/blueprint"
Jiyong Parkc678ad32018-04-10 13:07:10 +090028 "github.com/google/blueprint/proptools"
Paul Duffin46a26a82020-04-07 19:27:04 +010029
30 "android/soong/android"
Jiyong Parkc678ad32018-04-10 13:07:10 +090031)
32
Jooyung Han58f26ab2019-12-18 15:34:32 +090033const (
Paul Duffindd9d0742020-05-08 15:52:37 +010034 sdkXmlFileSuffix = ".xml"
35 permissionsTemplate = `<?xml version=\"1.0\" encoding=\"utf-8\"?>\n` +
Jooyung Han624058e2019-12-24 18:38:06 +090036 `<!-- Copyright (C) 2018 The Android Open Source Project\n` +
37 `\n` +
Jiyong Parke3833882020-02-17 17:28:10 +090038 ` Licensed under the Apache License, Version 2.0 (the \"License\");\n` +
Jooyung Han624058e2019-12-24 18:38:06 +090039 ` you may not use this file except in compliance with the License.\n` +
40 ` You may obtain a copy of the License at\n` +
41 `\n` +
42 ` http://www.apache.org/licenses/LICENSE-2.0\n` +
43 `\n` +
44 ` Unless required by applicable law or agreed to in writing, software\n` +
Jiyong Parke3833882020-02-17 17:28:10 +090045 ` distributed under the License is distributed on an \"AS IS\" BASIS,\n` +
Jooyung Han624058e2019-12-24 18:38:06 +090046 ` WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n` +
47 ` See the License for the specific language governing permissions and\n` +
48 ` limitations under the License.\n` +
49 `-->\n` +
50 `<permissions>\n` +
Jiyong Parke3833882020-02-17 17:28:10 +090051 ` <library name=\"%s\" file=\"%s\"/>\n` +
Jooyung Han624058e2019-12-24 18:38:06 +090052 `</permissions>\n`
Jiyong Parkc678ad32018-04-10 13:07:10 +090053)
54
Paul Duffind1b3a922020-01-22 11:57:20 +000055// A tag to associated a dependency with a specific api scope.
56type scopeDependencyTag struct {
57 blueprint.BaseDependencyTag
58 name string
59 apiScope *apiScope
Paul Duffinc8782502020-04-29 20:45:27 +010060
61 // Function for extracting appropriate path information from the dependency.
62 depInfoExtractor func(paths *scopePaths, dep android.Module) error
63}
64
65// Extract tag specific information from the dependency.
66func (tag scopeDependencyTag) extractDepInfo(ctx android.ModuleContext, dep android.Module, paths *scopePaths) {
67 err := tag.depInfoExtractor(paths, dep)
68 if err != nil {
69 ctx.ModuleErrorf("has an invalid {scopeDependencyTag: %s} dependency on module %s: %s", tag.name, ctx.OtherModuleName(dep), err.Error())
70 }
Paul Duffind1b3a922020-01-22 11:57:20 +000071}
72
73// Provides information about an api scope, e.g. public, system, test.
74type apiScope struct {
75 // The name of the api scope, e.g. public, system, test
76 name string
77
Paul Duffin97b53b82020-05-05 14:40:52 +010078 // The api scope that this scope extends.
79 extends *apiScope
80
Paul Duffin3375e352020-04-28 10:44:03 +010081 // The legacy enabled status for a specific scope can be dependent on other
82 // properties that have been specified on the library so it is provided by
83 // a function that can determine the status by examining those properties.
84 legacyEnabledStatus func(module *SdkLibrary) bool
85
86 // The default enabled status for non-legacy behavior, which is triggered by
87 // explicitly enabling at least one api scope.
88 defaultEnabledStatus bool
89
90 // Gets a pointer to the scope specific properties.
91 scopeSpecificProperties func(module *SdkLibrary) *ApiScopeProperties
92
Paul Duffin46a26a82020-04-07 19:27:04 +010093 // The name of the field in the dynamically created structure.
94 fieldName string
95
Paul Duffin6b836ba2020-05-13 19:19:49 +010096 // The name of the property in the java_sdk_library_import
97 propertyName string
98
Paul Duffind1b3a922020-01-22 11:57:20 +000099 // The tag to use to depend on the stubs library module.
100 stubsTag scopeDependencyTag
101
Paul Duffin0ff08bd2020-04-29 13:30:54 +0100102 // The tag to use to depend on the stubs source module (if separate from the API module).
103 stubsSourceTag scopeDependencyTag
104
105 // The tag to use to depend on the API file generating module (if separate from the stubs source module).
106 apiFileTag scopeDependencyTag
107
Paul Duffinc8782502020-04-29 20:45:27 +0100108 // The tag to use to depend on the stubs source and API module.
109 stubsSourceAndApiTag scopeDependencyTag
Paul Duffind1b3a922020-01-22 11:57:20 +0000110
111 // The scope specific prefix to add to the api file base of "current.txt" or "removed.txt".
112 apiFilePrefix string
113
114 // The scope specific prefix to add to the sdk library module name to construct a scope specific
115 // module name.
116 moduleSuffix string
117
Paul Duffind1b3a922020-01-22 11:57:20 +0000118 // SDK version that the stubs library is built against. Note that this is always
119 // *current. Older stubs library built with a numbered SDK version is created from
120 // the prebuilt jar.
121 sdkVersion string
Paul Duffin1fb487d2020-04-07 18:50:10 +0100122
123 // Extra arguments to pass to droidstubs for this scope.
124 droidstubsArgs []string
Anton Hansson6478ac12020-05-02 11:19:36 +0100125
Paul Duffin0ff08bd2020-04-29 13:30:54 +0100126 // The args that must be passed to droidstubs to generate the stubs source
127 // for this scope.
128 //
129 // The stubs source must include the definitions of everything that is in this
130 // api scope and all the scopes that this one extends.
131 droidstubsArgsForGeneratingStubsSource []string
132
133 // The args that must be passed to droidstubs to generate the API for this scope.
134 //
135 // The API only includes the additional members that this scope adds over the scope
136 // that it extends.
137 droidstubsArgsForGeneratingApi []string
138
139 // True if the stubs source and api can be created by the same metalava invocation.
140 createStubsSourceAndApiTogether bool
141
Anton Hansson6478ac12020-05-02 11:19:36 +0100142 // Whether the api scope can be treated as unstable, and should skip compat checks.
143 unstable bool
Paul Duffind1b3a922020-01-22 11:57:20 +0000144}
145
146// Initialize a scope, creating and adding appropriate dependency tags
147func initApiScope(scope *apiScope) *apiScope {
Paul Duffinc8782502020-04-29 20:45:27 +0100148 name := scope.name
Paul Duffin46dc45a2020-05-14 15:39:10 +0100149 scopeByName[name] = scope
150 allScopeNames = append(allScopeNames, name)
Paul Duffin6b836ba2020-05-13 19:19:49 +0100151 scope.propertyName = strings.ReplaceAll(name, "-", "_")
152 scope.fieldName = proptools.FieldNameForProperty(scope.propertyName)
Paul Duffind1b3a922020-01-22 11:57:20 +0000153 scope.stubsTag = scopeDependencyTag{
Paul Duffinc8782502020-04-29 20:45:27 +0100154 name: name + "-stubs",
155 apiScope: scope,
156 depInfoExtractor: (*scopePaths).extractStubsLibraryInfoFromDependency,
Paul Duffind1b3a922020-01-22 11:57:20 +0000157 }
Paul Duffin0ff08bd2020-04-29 13:30:54 +0100158 scope.stubsSourceTag = scopeDependencyTag{
159 name: name + "-stubs-source",
160 apiScope: scope,
161 depInfoExtractor: (*scopePaths).extractStubsSourceInfoFromDep,
162 }
163 scope.apiFileTag = scopeDependencyTag{
164 name: name + "-api",
165 apiScope: scope,
166 depInfoExtractor: (*scopePaths).extractApiInfoFromDep,
167 }
Paul Duffinc8782502020-04-29 20:45:27 +0100168 scope.stubsSourceAndApiTag = scopeDependencyTag{
169 name: name + "-stubs-source-and-api",
170 apiScope: scope,
171 depInfoExtractor: (*scopePaths).extractStubsSourceAndApiInfoFromApiStubsProvider,
Paul Duffind1b3a922020-01-22 11:57:20 +0000172 }
Paul Duffin0ff08bd2020-04-29 13:30:54 +0100173
174 // To get the args needed to generate the stubs source append all the args from
175 // this scope and all the scopes it extends as each set of args adds additional
176 // members to the stubs.
177 var stubsSourceArgs []string
178 for s := scope; s != nil; s = s.extends {
179 stubsSourceArgs = append(stubsSourceArgs, s.droidstubsArgs...)
180 }
181 scope.droidstubsArgsForGeneratingStubsSource = stubsSourceArgs
182
183 // Currently the args needed to generate the API are the same as the args
184 // needed to add additional members.
185 apiArgs := scope.droidstubsArgs
186 scope.droidstubsArgsForGeneratingApi = apiArgs
187
188 // If the args needed to generate the stubs and API are the same then they
189 // can be generated in a single invocation of metalava, otherwise they will
190 // need separate invocations.
191 scope.createStubsSourceAndApiTogether = reflect.DeepEqual(stubsSourceArgs, apiArgs)
192
Paul Duffind1b3a922020-01-22 11:57:20 +0000193 return scope
194}
195
Paul Duffinc3091c82020-05-08 14:16:20 +0100196func (scope *apiScope) stubsLibraryModuleName(baseName string) string {
Paul Duffindd9d0742020-05-08 15:52:37 +0100197 return baseName + ".stubs" + scope.moduleSuffix
Paul Duffind1b3a922020-01-22 11:57:20 +0000198}
199
Paul Duffinc8782502020-04-29 20:45:27 +0100200func (scope *apiScope) stubsSourceModuleName(baseName string) string {
Paul Duffindd9d0742020-05-08 15:52:37 +0100201 return baseName + ".stubs.source" + scope.moduleSuffix
Paul Duffind1b3a922020-01-22 11:57:20 +0000202}
203
Paul Duffin0ff08bd2020-04-29 13:30:54 +0100204func (scope *apiScope) apiModuleName(baseName string) string {
Paul Duffindd9d0742020-05-08 15:52:37 +0100205 return baseName + ".api" + scope.moduleSuffix
Paul Duffin0ff08bd2020-04-29 13:30:54 +0100206}
207
Paul Duffin3375e352020-04-28 10:44:03 +0100208func (scope *apiScope) String() string {
209 return scope.name
210}
211
Paul Duffind1b3a922020-01-22 11:57:20 +0000212type apiScopes []*apiScope
213
214func (scopes apiScopes) Strings(accessor func(*apiScope) string) []string {
215 var list []string
216 for _, scope := range scopes {
217 list = append(list, accessor(scope))
218 }
219 return list
220}
221
Jiyong Parkc678ad32018-04-10 13:07:10 +0900222var (
Paul Duffin46dc45a2020-05-14 15:39:10 +0100223 scopeByName = make(map[string]*apiScope)
224 allScopeNames []string
Paul Duffind1b3a922020-01-22 11:57:20 +0000225 apiScopePublic = initApiScope(&apiScope{
Paul Duffin3375e352020-04-28 10:44:03 +0100226 name: "public",
227
228 // Public scope is enabled by default for both legacy and non-legacy modes.
229 legacyEnabledStatus: func(module *SdkLibrary) bool {
230 return true
231 },
232 defaultEnabledStatus: true,
233
234 scopeSpecificProperties: func(module *SdkLibrary) *ApiScopeProperties {
235 return &module.sdkLibraryProperties.Public
236 },
Paul Duffind1b3a922020-01-22 11:57:20 +0000237 sdkVersion: "current",
238 })
239 apiScopeSystem = initApiScope(&apiScope{
Paul Duffin3375e352020-04-28 10:44:03 +0100240 name: "system",
241 extends: apiScopePublic,
242 legacyEnabledStatus: (*SdkLibrary).generateTestAndSystemScopesByDefault,
243 scopeSpecificProperties: func(module *SdkLibrary) *ApiScopeProperties {
244 return &module.sdkLibraryProperties.System
245 },
Anton Hansson6affb1f2020-04-28 16:47:41 +0100246 apiFilePrefix: "system-",
Paul Duffindd9d0742020-05-08 15:52:37 +0100247 moduleSuffix: ".system",
Anton Hansson6affb1f2020-04-28 16:47:41 +0100248 sdkVersion: "system_current",
Paul Duffin0d543642020-04-29 22:18:41 +0100249 droidstubsArgs: []string{"-showAnnotation android.annotation.SystemApi\\(client=android.annotation.SystemApi.Client.PRIVILEGED_APPS\\)"},
Paul Duffind1b3a922020-01-22 11:57:20 +0000250 })
251 apiScopeTest = initApiScope(&apiScope{
Paul Duffin3375e352020-04-28 10:44:03 +0100252 name: "test",
253 extends: apiScopePublic,
254 legacyEnabledStatus: (*SdkLibrary).generateTestAndSystemScopesByDefault,
255 scopeSpecificProperties: func(module *SdkLibrary) *ApiScopeProperties {
256 return &module.sdkLibraryProperties.Test
257 },
Anton Hansson6affb1f2020-04-28 16:47:41 +0100258 apiFilePrefix: "test-",
Paul Duffindd9d0742020-05-08 15:52:37 +0100259 moduleSuffix: ".test",
Anton Hansson6affb1f2020-04-28 16:47:41 +0100260 sdkVersion: "test_current",
261 droidstubsArgs: []string{"-showAnnotation android.annotation.TestApi"},
Anton Hansson6478ac12020-05-02 11:19:36 +0100262 unstable: true,
Paul Duffind1b3a922020-01-22 11:57:20 +0000263 })
Paul Duffin8f265b92020-04-28 14:13:56 +0100264 apiScopeModuleLib = initApiScope(&apiScope{
Paul Duffin6b836ba2020-05-13 19:19:49 +0100265 name: "module-lib",
Paul Duffin8f265b92020-04-28 14:13:56 +0100266 extends: apiScopeSystem,
Paul Duffin0c5bae52020-06-02 13:00:08 +0100267 // The module-lib scope is disabled by default in legacy mode.
Paul Duffin8f265b92020-04-28 14:13:56 +0100268 //
269 // Enabling this would break existing usages.
270 legacyEnabledStatus: func(module *SdkLibrary) bool {
271 return false
272 },
273 scopeSpecificProperties: func(module *SdkLibrary) *ApiScopeProperties {
274 return &module.sdkLibraryProperties.Module_lib
275 },
276 apiFilePrefix: "module-lib-",
277 moduleSuffix: ".module_lib",
278 sdkVersion: "module_current",
279 droidstubsArgs: []string{
280 "--show-annotation android.annotation.SystemApi\\(client=android.annotation.SystemApi.Client.MODULE_LIBRARIES\\)",
281 },
282 })
Paul Duffin0c5bae52020-06-02 13:00:08 +0100283 apiScopeSystemServer = initApiScope(&apiScope{
284 name: "system-server",
285 extends: apiScopePublic,
286 // The system-server scope is disabled by default in legacy mode.
287 //
288 // Enabling this would break existing usages.
289 legacyEnabledStatus: func(module *SdkLibrary) bool {
290 return false
291 },
292 scopeSpecificProperties: func(module *SdkLibrary) *ApiScopeProperties {
293 return &module.sdkLibraryProperties.System_server
294 },
295 apiFilePrefix: "system-server-",
296 moduleSuffix: ".system_server",
297 sdkVersion: "system_server_current",
298 droidstubsArgs: []string{
299 "--show-annotation android.annotation.SystemApi\\(client=android.annotation.SystemApi.Client.SYSTEM_SERVER\\) ",
300 "--hide-annotation android.annotation.Hide",
301 // com.android.* classes are okay in this interface"
302 "--hide InternalClasses",
303 },
304 })
Paul Duffind1b3a922020-01-22 11:57:20 +0000305 allApiScopes = apiScopes{
306 apiScopePublic,
307 apiScopeSystem,
308 apiScopeTest,
Paul Duffin8f265b92020-04-28 14:13:56 +0100309 apiScopeModuleLib,
Paul Duffin0c5bae52020-06-02 13:00:08 +0100310 apiScopeSystemServer,
Paul Duffind1b3a922020-01-22 11:57:20 +0000311 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900312)
313
Jiyong Park82484c02018-04-23 21:41:26 +0900314var (
315 javaSdkLibrariesLock sync.Mutex
316)
317
Jiyong Parkc678ad32018-04-10 13:07:10 +0900318// TODO: these are big features that are currently missing
Jiyong Park1be96912018-05-28 18:02:19 +0900319// 1) disallowing linking to the runtime shared lib
320// 2) HTML generation
Jiyong Parkc678ad32018-04-10 13:07:10 +0900321
322func init() {
Paul Duffin43dc1cc2019-12-19 11:18:54 +0000323 RegisterSdkLibraryBuildComponents(android.InitRegistrationContext)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900324
Jiyong Park82484c02018-04-23 21:41:26 +0900325 android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) {
326 javaSdkLibraries := javaSdkLibraries(ctx.Config())
327 sort.Strings(*javaSdkLibraries)
328 ctx.Strict("JAVA_SDK_LIBRARIES", strings.Join(*javaSdkLibraries, " "))
329 })
Paul Duffindd46f712020-02-10 13:37:10 +0000330
331 // Register sdk member types.
332 android.RegisterSdkMemberType(&sdkLibrarySdkMemberType{
333 android.SdkMemberTypeBase{
334 PropertyName: "java_sdk_libs",
335 SupportsSdk: true,
336 },
337 })
Jiyong Parkc678ad32018-04-10 13:07:10 +0900338}
339
Paul Duffin43dc1cc2019-12-19 11:18:54 +0000340func RegisterSdkLibraryBuildComponents(ctx android.RegistrationContext) {
341 ctx.RegisterModuleType("java_sdk_library", SdkLibraryFactory)
342 ctx.RegisterModuleType("java_sdk_library_import", sdkLibraryImportFactory)
343}
344
Paul Duffin3375e352020-04-28 10:44:03 +0100345// Properties associated with each api scope.
346type ApiScopeProperties struct {
347 // Indicates whether the api surface is generated.
348 //
349 // If this is set for any scope then all scopes must explicitly specify if they
350 // are enabled. This is to prevent new usages from depending on legacy behavior.
351 //
352 // Otherwise, if this is not set for any scope then the default behavior is
353 // scope specific so please refer to the scope specific property documentation.
354 Enabled *bool
Paul Duffin87a05a32020-05-12 11:50:28 +0100355
356 // The sdk_version to use for building the stubs.
357 //
358 // If not specified then it will use an sdk_version determined as follows:
359 // 1) If the sdk_version specified on the java_sdk_library is none then this
360 // will be none. This is used for java_sdk_library instances that are used
361 // to create stubs that contribute to the core_current sdk version.
362 // 2) Otherwise, it is assumed that this library extends but does not contribute
363 // directly to a specific sdk_version and so this uses the sdk_version appropriate
364 // for the api scope. e.g. public will use sdk_version: current, system will use
365 // sdk_version: system_current, etc.
366 //
367 // This does not affect the sdk_version used for either generating the stubs source
368 // or the API file. They both have to use the same sdk_version as is used for
369 // compiling the implementation library.
370 Sdk_version *string
Paul Duffin3375e352020-04-28 10:44:03 +0100371}
372
Jiyong Parkc678ad32018-04-10 13:07:10 +0900373type sdkLibraryProperties struct {
Paul Duffin5df79302020-05-16 15:52:12 +0100374 // Visibility for impl library module. If not specified then defaults to the
375 // visibility property.
376 Impl_library_visibility []string
377
Paul Duffin4911a892020-04-29 23:35:13 +0100378 // Visibility for stubs library modules. If not specified then defaults to the
379 // visibility property.
380 Stubs_library_visibility []string
381
382 // Visibility for stubs source modules. If not specified then defaults to the
383 // visibility property.
384 Stubs_source_visibility []string
385
Sundong Ahnf043cf62018-06-25 16:04:37 +0900386 // List of Java libraries that will be in the classpath when building stubs
387 Stub_only_libs []string `android:"arch_variant"`
388
Paul Duffin7a586d32019-12-30 17:09:34 +0000389 // list of package names that will be documented and publicized as API.
390 // This allows the API to be restricted to a subset of the source files provided.
391 // If this is unspecified then all the source files will be treated as being part
392 // of the API.
Jiyong Parkc678ad32018-04-10 13:07:10 +0900393 Api_packages []string
394
Jiyong Park5a2c9d72018-05-01 22:25:41 +0900395 // list of package names that must be hidden from the API
396 Hidden_api_packages []string
397
Paul Duffin749f98f2019-12-30 17:23:46 +0000398 // the relative path to the directory containing the api specification files.
399 // Defaults to "api".
400 Api_dir *string
401
Paul Duffindfa131e2020-05-15 20:37:11 +0100402 // Determines whether a runtime implementation library is built; defaults to false.
403 //
404 // If true then it also prevents the module from being used as a shared module, i.e.
405 // it is as is shared_library: false, was set.
Paul Duffin43db9be2019-12-30 17:35:49 +0000406 Api_only *bool
407
Paul Duffin11512472019-02-11 15:55:17 +0000408 // local files that are used within user customized droiddoc options.
409 Droiddoc_option_files []string
410
411 // additional droiddoc options
412 // Available variables for substitution:
413 //
414 // $(location <label>): the path to the droiddoc_option_files with name <label>
Sundong Ahndd567f92018-07-31 17:19:11 +0900415 Droiddoc_options []string
416
Sundong Ahn054b19a2018-10-19 13:46:09 +0900417 // a list of top-level directories containing files to merge qualifier annotations
418 // (i.e. those intended to be included in the stubs written) from.
419 Merge_annotations_dirs []string
420
421 // a list of top-level directories containing Java stub files to merge show/hide annotations from.
422 Merge_inclusion_annotations_dirs []string
423
424 // If set to true, the path of dist files is apistubs/core. Defaults to false.
425 Core_lib *bool
426
Sundong Ahn80a87b32019-05-13 15:02:50 +0900427 // don't create dist rules.
428 No_dist *bool `blueprint:"mutated"`
429
Paul Duffin3375e352020-04-28 10:44:03 +0100430 // indicates whether system and test apis should be generated.
431 Generate_system_and_test_apis bool `blueprint:"mutated"`
432
433 // The properties specific to the public api scope
434 //
435 // Unless explicitly specified by using public.enabled the public api scope is
436 // enabled by default in both legacy and non-legacy mode.
437 Public ApiScopeProperties
438
439 // The properties specific to the system api scope
440 //
441 // In legacy mode the system api scope is enabled by default when sdk_version
442 // is set to something other than "none".
443 //
444 // In non-legacy mode the system api scope is disabled by default.
445 System ApiScopeProperties
446
447 // The properties specific to the test api scope
448 //
449 // In legacy mode the test api scope is enabled by default when sdk_version
450 // is set to something other than "none".
451 //
452 // In non-legacy mode the test api scope is disabled by default.
453 Test ApiScopeProperties
Paul Duffin37e0b772019-12-30 17:20:10 +0000454
Paul Duffin0c5bae52020-06-02 13:00:08 +0100455 // The properties specific to the module-lib api scope
Paul Duffin8f265b92020-04-28 14:13:56 +0100456 //
Paul Duffin0c5bae52020-06-02 13:00:08 +0100457 // Unless explicitly specified by using test.enabled the module-lib api scope is
Paul Duffin8f265b92020-04-28 14:13:56 +0100458 // disabled by default.
459 Module_lib ApiScopeProperties
460
Paul Duffin0c5bae52020-06-02 13:00:08 +0100461 // The properties specific to the system-server api scope
462 //
463 // Unless explicitly specified by using test.enabled the module-lib api scope is
464 // disabled by default.
465 System_server ApiScopeProperties
466
Jiyong Park932cdfe2020-05-28 00:19:53 +0900467 // Determines if the stubs are preferred over the implementation library
468 // for linking, even when the client doesn't specify sdk_version. When this
469 // is set to true, such clients are provided with the widest API surface that
470 // this lib provides. Note however that this option doesn't affect the clients
471 // that are in the same APEX as this library. In that case, the clients are
472 // always linked with the implementation library. Default is false.
473 Default_to_stubs *bool
474
Paul Duffin160fe412020-05-10 19:32:20 +0100475 // Properties related to api linting.
476 Api_lint struct {
477 // Enable api linting.
478 Enabled *bool
479 }
480
Jiyong Parkc678ad32018-04-10 13:07:10 +0900481 // TODO: determines whether to create HTML doc or not
482 //Html_doc *bool
483}
484
Paul Duffin0f8faff2020-05-20 16:18:00 +0100485// Paths to outputs from java_sdk_library and java_sdk_library_import.
486//
487// Fields that are android.Paths are always set (during GenerateAndroidBuildActions).
488// OptionalPaths are always set by java_sdk_library but may not be set by
489// java_sdk_library_import as not all instances provide that information.
Paul Duffind1b3a922020-01-22 11:57:20 +0000490type scopePaths struct {
Paul Duffin0f8faff2020-05-20 16:18:00 +0100491 // The path (represented as Paths for convenience when returning) to the stubs header jar.
492 //
493 // That is the jar that is created by turbine.
494 stubsHeaderPath android.Paths
495
496 // The path (represented as Paths for convenience when returning) to the stubs implementation jar.
497 //
498 // This is not the implementation jar, it still only contains stubs.
499 stubsImplPath android.Paths
500
501 // The API specification file, e.g. system_current.txt.
502 currentApiFilePath android.OptionalPath
503
504 // The specification of API elements removed since the last release.
505 removedApiFilePath android.OptionalPath
506
507 // The stubs source jar.
508 stubsSrcJar android.OptionalPath
Paul Duffind1b3a922020-01-22 11:57:20 +0000509}
510
Paul Duffinc8782502020-04-29 20:45:27 +0100511func (paths *scopePaths) extractStubsLibraryInfoFromDependency(dep android.Module) error {
512 if lib, ok := dep.(Dependency); ok {
513 paths.stubsHeaderPath = lib.HeaderJars()
514 paths.stubsImplPath = lib.ImplementationJars()
515 return nil
516 } else {
517 return fmt.Errorf("expected module that implements Dependency, e.g. java_library")
518 }
519}
520
Paul Duffin0ff08bd2020-04-29 13:30:54 +0100521func (paths *scopePaths) treatDepAsApiStubsProvider(dep android.Module, action func(provider ApiStubsProvider)) error {
522 if apiStubsProvider, ok := dep.(ApiStubsProvider); ok {
523 action(apiStubsProvider)
Paul Duffinc8782502020-04-29 20:45:27 +0100524 return nil
525 } else {
526 return fmt.Errorf("expected module that implements ApiStubsProvider, e.g. droidstubs")
527 }
528}
529
Paul Duffin0f8faff2020-05-20 16:18:00 +0100530func (paths *scopePaths) treatDepAsApiStubsSrcProvider(dep android.Module, action func(provider ApiStubsSrcProvider)) error {
531 if apiStubsProvider, ok := dep.(ApiStubsSrcProvider); ok {
532 action(apiStubsProvider)
533 return nil
534 } else {
535 return fmt.Errorf("expected module that implements ApiStubsSrcProvider, e.g. droidstubs")
536 }
537}
538
Paul Duffin0ff08bd2020-04-29 13:30:54 +0100539func (paths *scopePaths) extractApiInfoFromApiStubsProvider(provider ApiStubsProvider) {
Paul Duffin0f8faff2020-05-20 16:18:00 +0100540 paths.currentApiFilePath = android.OptionalPathForPath(provider.ApiFilePath())
541 paths.removedApiFilePath = android.OptionalPathForPath(provider.RemovedApiFilePath())
Paul Duffin0ff08bd2020-04-29 13:30:54 +0100542}
543
544func (paths *scopePaths) extractApiInfoFromDep(dep android.Module) error {
545 return paths.treatDepAsApiStubsProvider(dep, func(provider ApiStubsProvider) {
546 paths.extractApiInfoFromApiStubsProvider(provider)
547 })
548}
549
Paul Duffin0f8faff2020-05-20 16:18:00 +0100550func (paths *scopePaths) extractStubsSourceInfoFromApiStubsProviders(provider ApiStubsSrcProvider) {
551 paths.stubsSrcJar = android.OptionalPathForPath(provider.StubsSrcJar())
Paul Duffin0ff08bd2020-04-29 13:30:54 +0100552}
553
554func (paths *scopePaths) extractStubsSourceInfoFromDep(dep android.Module) error {
Paul Duffin0f8faff2020-05-20 16:18:00 +0100555 return paths.treatDepAsApiStubsSrcProvider(dep, func(provider ApiStubsSrcProvider) {
Paul Duffin0ff08bd2020-04-29 13:30:54 +0100556 paths.extractStubsSourceInfoFromApiStubsProviders(provider)
557 })
558}
559
560func (paths *scopePaths) extractStubsSourceAndApiInfoFromApiStubsProvider(dep android.Module) error {
561 return paths.treatDepAsApiStubsProvider(dep, func(provider ApiStubsProvider) {
562 paths.extractApiInfoFromApiStubsProvider(provider)
563 paths.extractStubsSourceInfoFromApiStubsProviders(provider)
564 })
565}
566
567type commonToSdkLibraryAndImportProperties struct {
Paul Duffin1b1e8062020-05-08 13:44:43 +0100568 // The naming scheme to use for the components that this module creates.
569 //
Paul Duffin6c9c5fc2020-05-08 15:36:30 +0100570 // If not specified then it defaults to "default". The other allowable value is
571 // "framework-modules" which matches the scheme currently used by framework modules
572 // for the equivalent components represented as separate Soong modules.
Paul Duffin1b1e8062020-05-08 13:44:43 +0100573 //
574 // This is a temporary mechanism to simplify conversion from separate modules for each
575 // component that follow a different naming pattern to the default one.
576 //
577 // TODO(b/155480189) - Remove once naming inconsistencies have been resolved.
Paul Duffin0ff08bd2020-04-29 13:30:54 +0100578 Naming_scheme *string
Paul Duffindfa131e2020-05-15 20:37:11 +0100579
580 // Specifies whether this module can be used as an Android shared library; defaults
581 // to true.
582 //
583 // An Android shared library is one that can be referenced in a <uses-library> element
584 // in an AndroidManifest.xml.
585 Shared_library *bool
Paul Duffin0ff08bd2020-04-29 13:30:54 +0100586}
587
Paul Duffin56d44902020-01-31 13:36:25 +0000588// Common code between sdk library and sdk library import
589type commonToSdkLibraryAndImport struct {
Paul Duffinc3091c82020-05-08 14:16:20 +0100590 moduleBase *android.ModuleBase
591
Paul Duffin56d44902020-01-31 13:36:25 +0000592 scopePaths map[*apiScope]*scopePaths
Paul Duffin1b1e8062020-05-08 13:44:43 +0100593
594 namingScheme sdkLibraryComponentNamingScheme
595
Paul Duffindfa131e2020-05-15 20:37:11 +0100596 commonSdkLibraryProperties commonToSdkLibraryAndImportProperties
Paul Duffin859fe962020-05-15 10:20:31 +0100597
598 // Functionality related to this being used as a component of a java_sdk_library.
599 EmbeddableSdkLibraryComponent
Paul Duffin56d44902020-01-31 13:36:25 +0000600}
601
Paul Duffinc3091c82020-05-08 14:16:20 +0100602func (c *commonToSdkLibraryAndImport) initCommon(moduleBase *android.ModuleBase) {
603 c.moduleBase = moduleBase
Paul Duffin1b1e8062020-05-08 13:44:43 +0100604
Paul Duffindfa131e2020-05-15 20:37:11 +0100605 moduleBase.AddProperties(&c.commonSdkLibraryProperties)
Paul Duffin859fe962020-05-15 10:20:31 +0100606
607 // Initialize this as an sdk library component.
608 c.initSdkLibraryComponent(moduleBase)
Paul Duffin1b1e8062020-05-08 13:44:43 +0100609}
610
611func (c *commonToSdkLibraryAndImport) initCommonAfterDefaultsApplied(ctx android.DefaultableHookContext) bool {
Paul Duffindfa131e2020-05-15 20:37:11 +0100612 schemeProperty := proptools.StringDefault(c.commonSdkLibraryProperties.Naming_scheme, "default")
Paul Duffin1b1e8062020-05-08 13:44:43 +0100613 switch schemeProperty {
614 case "default":
615 c.namingScheme = &defaultNamingScheme{}
Paul Duffin6c9c5fc2020-05-08 15:36:30 +0100616 case "framework-modules":
617 c.namingScheme = &frameworkModulesNamingScheme{}
Paul Duffin1b1e8062020-05-08 13:44:43 +0100618 default:
619 ctx.PropertyErrorf("naming_scheme", "expected 'default' but was %q", schemeProperty)
620 return false
621 }
622
Paul Duffindfa131e2020-05-15 20:37:11 +0100623 // Only track this sdk library if this can be used as a shared library.
624 if c.sharedLibrary() {
625 // Use the name specified in the module definition as the owner.
626 c.sdkLibraryComponentProperties.SdkLibraryToImplicitlyTrack = proptools.StringPtr(c.moduleBase.BaseModuleName())
627 }
Paul Duffin859fe962020-05-15 10:20:31 +0100628
Paul Duffin1b1e8062020-05-08 13:44:43 +0100629 return true
Paul Duffinc3091c82020-05-08 14:16:20 +0100630}
631
632// Name of the java_library module that compiles the stubs source.
633func (c *commonToSdkLibraryAndImport) stubsLibraryModuleName(apiScope *apiScope) string {
Paul Duffin1b1e8062020-05-08 13:44:43 +0100634 return c.namingScheme.stubsLibraryModuleName(apiScope, c.moduleBase.BaseModuleName())
Paul Duffinc3091c82020-05-08 14:16:20 +0100635}
636
637// Name of the droidstubs module that generates the stubs source and may also
638// generate/check the API.
639func (c *commonToSdkLibraryAndImport) stubsSourceModuleName(apiScope *apiScope) string {
Paul Duffin1b1e8062020-05-08 13:44:43 +0100640 return c.namingScheme.stubsSourceModuleName(apiScope, c.moduleBase.BaseModuleName())
Paul Duffinc3091c82020-05-08 14:16:20 +0100641}
642
643// Name of the droidstubs module that generates/checks the API. Only used if it
644// requires different arts to the stubs source generating module.
645func (c *commonToSdkLibraryAndImport) apiModuleName(apiScope *apiScope) string {
Paul Duffin1b1e8062020-05-08 13:44:43 +0100646 return c.namingScheme.apiModuleName(apiScope, c.moduleBase.BaseModuleName())
Paul Duffinc3091c82020-05-08 14:16:20 +0100647}
648
Paul Duffin46dc45a2020-05-14 15:39:10 +0100649// The component names for different outputs of the java_sdk_library.
650//
651// They are similar to the names used for the child modules it creates
652const (
653 stubsSourceComponentName = "stubs.source"
654
655 apiTxtComponentName = "api.txt"
656
657 removedApiTxtComponentName = "removed-api.txt"
658)
659
660// A regular expression to match tags that reference a specific stubs component.
661//
662// It will only match if given a valid scope and a valid component. It is verfy strict
663// to ensure it does not accidentally match a similar looking tag that should be processed
664// by the embedded Library.
665var tagSplitter = func() *regexp.Regexp {
666 // Given a list of literal string items returns a regular expression that will
667 // match any one of the items.
668 choice := func(items ...string) string {
669 return `\Q` + strings.Join(items, `\E|\Q`) + `\E`
670 }
671
672 // Regular expression to match one of the scopes.
673 scopesRegexp := choice(allScopeNames...)
674
675 // Regular expression to match one of the components.
676 componentsRegexp := choice(stubsSourceComponentName, apiTxtComponentName, removedApiTxtComponentName)
677
678 // Regular expression to match any combination of one scope and one component.
679 return regexp.MustCompile(fmt.Sprintf(`^\.(%s)\.(%s)$`, scopesRegexp, componentsRegexp))
680}()
681
682// For OutputFileProducer interface
683//
684// .<scope>.stubs.source
685// .<scope>.api.txt
686// .<scope>.removed-api.txt
687func (c *commonToSdkLibraryAndImport) commonOutputFiles(tag string) (android.Paths, error) {
688 if groups := tagSplitter.FindStringSubmatch(tag); groups != nil {
689 scopeName := groups[1]
690 component := groups[2]
691
692 if scope, ok := scopeByName[scopeName]; ok {
693 paths := c.findScopePaths(scope)
694 if paths == nil {
695 return nil, fmt.Errorf("%q does not provide api scope %s", c.moduleBase.BaseModuleName(), scopeName)
696 }
697
698 switch component {
699 case stubsSourceComponentName:
700 if paths.stubsSrcJar.Valid() {
701 return android.Paths{paths.stubsSrcJar.Path()}, nil
702 }
703
704 case apiTxtComponentName:
705 if paths.currentApiFilePath.Valid() {
706 return android.Paths{paths.currentApiFilePath.Path()}, nil
707 }
708
709 case removedApiTxtComponentName:
710 if paths.removedApiFilePath.Valid() {
711 return android.Paths{paths.removedApiFilePath.Path()}, nil
712 }
713 }
714
715 return nil, fmt.Errorf("%s not available for api scope %s", component, scopeName)
716 } else {
717 return nil, fmt.Errorf("unknown scope %s in %s", scope, tag)
718 }
719
720 } else {
721 return nil, nil
722 }
723}
724
Paul Duffin803a9562020-05-20 11:52:25 +0100725func (c *commonToSdkLibraryAndImport) getScopePathsCreateIfNeeded(scope *apiScope) *scopePaths {
Paul Duffin56d44902020-01-31 13:36:25 +0000726 if c.scopePaths == nil {
727 c.scopePaths = make(map[*apiScope]*scopePaths)
728 }
729 paths := c.scopePaths[scope]
730 if paths == nil {
731 paths = &scopePaths{}
732 c.scopePaths[scope] = paths
733 }
734
735 return paths
736}
737
Paul Duffin803a9562020-05-20 11:52:25 +0100738func (c *commonToSdkLibraryAndImport) findScopePaths(scope *apiScope) *scopePaths {
739 if c.scopePaths == nil {
740 return nil
741 }
742
743 return c.scopePaths[scope]
744}
745
746// If this does not support the requested api scope then find the closest available
747// scope it does support. Returns nil if no such scope is available.
748func (c *commonToSdkLibraryAndImport) findClosestScopePath(scope *apiScope) *scopePaths {
749 for s := scope; s != nil; s = s.extends {
750 if paths := c.findScopePaths(s); paths != nil {
751 return paths
752 }
753 }
754
755 // This should never happen outside tests as public should be the base scope for every
756 // scope and is enabled by default.
757 return nil
758}
759
Paul Duffin23970f42020-05-20 14:20:02 +0100760func (c *commonToSdkLibraryAndImport) selectHeaderJarsForSdkVersion(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths {
Paul Duffinb05d4292020-05-20 12:19:10 +0100761
762 // If a specific numeric version has been requested then use prebuilt versions of the sdk.
763 if sdkVersion.version.isNumbered() {
764 return PrebuiltJars(ctx, c.moduleBase.BaseModuleName(), sdkVersion)
765 }
766
767 var apiScope *apiScope
768 switch sdkVersion.kind {
769 case sdkSystem:
770 apiScope = apiScopeSystem
Paul Duffin803a9562020-05-20 11:52:25 +0100771 case sdkModule:
772 apiScope = apiScopeModuleLib
Paul Duffinb05d4292020-05-20 12:19:10 +0100773 case sdkTest:
774 apiScope = apiScopeTest
Paul Duffin0c5bae52020-06-02 13:00:08 +0100775 case sdkSystemServer:
776 apiScope = apiScopeSystemServer
Paul Duffinb05d4292020-05-20 12:19:10 +0100777 default:
778 apiScope = apiScopePublic
779 }
780
Paul Duffin803a9562020-05-20 11:52:25 +0100781 paths := c.findClosestScopePath(apiScope)
782 if paths == nil {
783 var scopes []string
784 for _, s := range allApiScopes {
785 if c.findScopePaths(s) != nil {
786 scopes = append(scopes, s.name)
787 }
788 }
789 ctx.ModuleErrorf("requires api scope %s from %s but it only has %q available", apiScope.name, c.moduleBase.BaseModuleName(), scopes)
790 return nil
791 }
792
Paul Duffin23970f42020-05-20 14:20:02 +0100793 return paths.stubsHeaderPath
Paul Duffinb05d4292020-05-20 12:19:10 +0100794}
795
Paul Duffin859fe962020-05-15 10:20:31 +0100796func (c *commonToSdkLibraryAndImport) sdkComponentPropertiesForChildLibrary() interface{} {
797 componentProps := &struct {
798 SdkLibraryToImplicitlyTrack *string
Paul Duffindfa131e2020-05-15 20:37:11 +0100799 }{}
800
801 if c.sharedLibrary() {
Paul Duffin859fe962020-05-15 10:20:31 +0100802 // Mark the stubs library as being components of this java_sdk_library so that
803 // any app that includes code which depends (directly or indirectly) on the stubs
804 // library will have the appropriate <uses-library> invocation inserted into its
805 // manifest if necessary.
Paul Duffindfa131e2020-05-15 20:37:11 +0100806 componentProps.SdkLibraryToImplicitlyTrack = proptools.StringPtr(c.moduleBase.BaseModuleName())
Paul Duffin859fe962020-05-15 10:20:31 +0100807 }
808
809 return componentProps
810}
811
Paul Duffindfa131e2020-05-15 20:37:11 +0100812// Check if this can be used as a shared library.
813func (c *commonToSdkLibraryAndImport) sharedLibrary() bool {
814 return proptools.BoolDefault(c.commonSdkLibraryProperties.Shared_library, true)
815}
816
Paul Duffin859fe962020-05-15 10:20:31 +0100817// Properties related to the use of a module as an component of a java_sdk_library.
818type SdkLibraryComponentProperties struct {
819
820 // The name of the java_sdk_library/_import to add to a <uses-library> entry
821 // in the AndroidManifest.xml of any Android app that includes code that references
822 // this module. If not set then no java_sdk_library/_import is tracked.
823 SdkLibraryToImplicitlyTrack *string `blueprint:"mutated"`
824}
825
826// Structure to be embedded in a module struct that needs to support the
827// SdkLibraryComponentDependency interface.
828type EmbeddableSdkLibraryComponent struct {
829 sdkLibraryComponentProperties SdkLibraryComponentProperties
830}
831
832func (e *EmbeddableSdkLibraryComponent) initSdkLibraryComponent(moduleBase *android.ModuleBase) {
833 moduleBase.AddProperties(&e.sdkLibraryComponentProperties)
834}
835
836// to satisfy SdkLibraryComponentDependency
837func (e *EmbeddableSdkLibraryComponent) OptionalImplicitSdkLibrary() []string {
838 if e.sdkLibraryComponentProperties.SdkLibraryToImplicitlyTrack != nil {
839 return []string{*e.sdkLibraryComponentProperties.SdkLibraryToImplicitlyTrack}
840 }
841 return nil
842}
843
844// Implemented by modules that are (or possibly could be) a component of a java_sdk_library
845// (including the java_sdk_library) itself.
846type SdkLibraryComponentDependency interface {
847 // The optional name of the sdk library that should be implicitly added to the
848 // AndroidManifest of an app that contains code which references the sdk library.
849 //
850 // Returns an array containing 0 or 1 items rather than a *string to make it easier
851 // to append this to the list of exported sdk libraries.
852 OptionalImplicitSdkLibrary() []string
853}
854
855// Make sure that all the module types that are components of java_sdk_library/_import
856// and which can be referenced (directly or indirectly) from an android app implement
857// the SdkLibraryComponentDependency interface.
858var _ SdkLibraryComponentDependency = (*Library)(nil)
859var _ SdkLibraryComponentDependency = (*Import)(nil)
860var _ SdkLibraryComponentDependency = (*SdkLibrary)(nil)
861var _ SdkLibraryComponentDependency = (*sdkLibraryImport)(nil)
862
863// Provides access to sdk_version related header and implentation jars.
864type SdkLibraryDependency interface {
865 SdkLibraryComponentDependency
866
867 // Get the header jars appropriate for the supplied sdk_version.
868 //
869 // These are turbine generated jars so they only change if the externals of the
870 // class changes but it does not contain and implementation or JavaDoc.
871 SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths
872
873 // Get the implementation jars appropriate for the supplied sdk version.
874 //
875 // These are either the implementation jar for the whole sdk library or the implementation
876 // jars for the stubs. The latter should only be needed when generating JavaDoc as otherwise
877 // they are identical to the corresponding header jars.
878 SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths
879}
880
Inseob Kimc0907f12019-02-08 21:00:45 +0900881type SdkLibrary struct {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900882 Library
Jiyong Parkc678ad32018-04-10 13:07:10 +0900883
Sundong Ahn054b19a2018-10-19 13:46:09 +0900884 sdkLibraryProperties sdkLibraryProperties
Jiyong Parkc678ad32018-04-10 13:07:10 +0900885
Paul Duffin3375e352020-04-28 10:44:03 +0100886 // Map from api scope to the scope specific property structure.
887 scopeToProperties map[*apiScope]*ApiScopeProperties
888
Paul Duffin56d44902020-01-31 13:36:25 +0000889 commonToSdkLibraryAndImport
Jiyong Parkc678ad32018-04-10 13:07:10 +0900890}
891
Inseob Kimc0907f12019-02-08 21:00:45 +0900892var _ Dependency = (*SdkLibrary)(nil)
893var _ SdkLibraryDependency = (*SdkLibrary)(nil)
Colin Cross897d2ed2019-02-11 14:03:51 -0800894
Paul Duffin3375e352020-04-28 10:44:03 +0100895func (module *SdkLibrary) generateTestAndSystemScopesByDefault() bool {
896 return module.sdkLibraryProperties.Generate_system_and_test_apis
897}
898
899func (module *SdkLibrary) getGeneratedApiScopes(ctx android.EarlyModuleContext) apiScopes {
900 // Check to see if any scopes have been explicitly enabled. If any have then all
901 // must be.
902 anyScopesExplicitlyEnabled := false
903 for _, scope := range allApiScopes {
904 scopeProperties := module.scopeToProperties[scope]
905 if scopeProperties.Enabled != nil {
906 anyScopesExplicitlyEnabled = true
907 break
908 }
Paul Duffind1b3a922020-01-22 11:57:20 +0000909 }
Paul Duffin3375e352020-04-28 10:44:03 +0100910
911 var generatedScopes apiScopes
912 enabledScopes := make(map[*apiScope]struct{})
913 for _, scope := range allApiScopes {
914 scopeProperties := module.scopeToProperties[scope]
915 // If any scopes are explicitly enabled then ignore the legacy enabled status.
916 // This is to ensure that any new usages of this module type do not rely on legacy
917 // behaviour.
918 defaultEnabledStatus := false
919 if anyScopesExplicitlyEnabled {
920 defaultEnabledStatus = scope.defaultEnabledStatus
921 } else {
922 defaultEnabledStatus = scope.legacyEnabledStatus(module)
923 }
924 enabled := proptools.BoolDefault(scopeProperties.Enabled, defaultEnabledStatus)
925 if enabled {
926 enabledScopes[scope] = struct{}{}
927 generatedScopes = append(generatedScopes, scope)
928 }
929 }
930
931 // Now check to make sure that any scope that is extended by an enabled scope is also
932 // enabled.
933 for _, scope := range allApiScopes {
934 if _, ok := enabledScopes[scope]; ok {
935 extends := scope.extends
936 if extends != nil {
937 if _, ok := enabledScopes[extends]; !ok {
938 ctx.ModuleErrorf("enabled api scope %q depends on disabled scope %q", scope, extends)
939 }
940 }
941 }
942 }
943
944 return generatedScopes
Paul Duffind1b3a922020-01-22 11:57:20 +0000945}
946
Paul Duffine74ac732020-02-06 13:51:46 +0000947var xmlPermissionsFileTag = dependencyTag{name: "xml-permissions-file"}
948
Jiyong Parke3833882020-02-17 17:28:10 +0900949func IsXmlPermissionsFileDepTag(depTag blueprint.DependencyTag) bool {
950 if dt, ok := depTag.(dependencyTag); ok {
951 return dt == xmlPermissionsFileTag
952 }
953 return false
954}
955
Paul Duffin5df79302020-05-16 15:52:12 +0100956var implLibraryTag = dependencyTag{name: "impl-library"}
957
Inseob Kimc0907f12019-02-08 21:00:45 +0900958func (module *SdkLibrary) DepsMutator(ctx android.BottomUpMutatorContext) {
Paul Duffin3375e352020-04-28 10:44:03 +0100959 for _, apiScope := range module.getGeneratedApiScopes(ctx) {
Paul Duffind1b3a922020-01-22 11:57:20 +0000960 // Add dependencies to the stubs library
Paul Duffinc3091c82020-05-08 14:16:20 +0100961 ctx.AddVariationDependencies(nil, apiScope.stubsTag, module.stubsLibraryModuleName(apiScope))
Paul Duffind1b3a922020-01-22 11:57:20 +0000962
Paul Duffin0ff08bd2020-04-29 13:30:54 +0100963 // If the stubs source and API cannot be generated together then add an additional dependency on
964 // the API module.
965 if apiScope.createStubsSourceAndApiTogether {
966 // Add a dependency on the stubs source in order to access both stubs source and api information.
Paul Duffinc3091c82020-05-08 14:16:20 +0100967 ctx.AddVariationDependencies(nil, apiScope.stubsSourceAndApiTag, module.stubsSourceModuleName(apiScope))
Paul Duffin0ff08bd2020-04-29 13:30:54 +0100968 } else {
969 // Add separate dependencies on the creators of the stubs source files and the API.
Paul Duffinc3091c82020-05-08 14:16:20 +0100970 ctx.AddVariationDependencies(nil, apiScope.stubsSourceTag, module.stubsSourceModuleName(apiScope))
971 ctx.AddVariationDependencies(nil, apiScope.apiFileTag, module.apiModuleName(apiScope))
Paul Duffin0ff08bd2020-04-29 13:30:54 +0100972 }
Sundong Ahn054b19a2018-10-19 13:46:09 +0900973 }
974
Paul Duffindfa131e2020-05-15 20:37:11 +0100975 if module.requiresRuntimeImplementationLibrary() {
Paul Duffin5df79302020-05-16 15:52:12 +0100976 // Add dependency to the rule for generating the implementation library.
977 ctx.AddDependency(module, implLibraryTag, module.implLibraryModuleName())
978
Paul Duffindfa131e2020-05-15 20:37:11 +0100979 if module.sharedLibrary() {
980 // Add dependency to the rule for generating the xml permissions file
981 ctx.AddDependency(module, xmlPermissionsFileTag, module.xmlFileName())
982 }
Paul Duffine74ac732020-02-06 13:51:46 +0000983
Paul Duffindfa131e2020-05-15 20:37:11 +0100984 // Only add the deps for the library if it is actually going to be built.
985 module.Library.deps(ctx)
986 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900987}
988
Paul Duffin46dc45a2020-05-14 15:39:10 +0100989func (module *SdkLibrary) OutputFiles(tag string) (android.Paths, error) {
990 paths, err := module.commonOutputFiles(tag)
991 if paths == nil && err == nil {
992 return module.Library.OutputFiles(tag)
993 } else {
994 return paths, err
995 }
996}
997
Inseob Kimc0907f12019-02-08 21:00:45 +0900998func (module *SdkLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Paul Duffindfa131e2020-05-15 20:37:11 +0100999 // Only build an implementation library if required.
1000 if module.requiresRuntimeImplementationLibrary() {
Paul Duffin43db9be2019-12-30 17:35:49 +00001001 module.Library.GenerateAndroidBuildActions(ctx)
1002 }
Sundong Ahn054b19a2018-10-19 13:46:09 +09001003
Sundong Ahn57368eb2018-07-06 11:20:23 +09001004 // Record the paths to the header jars of the library (stubs and impl).
Paul Duffind1b3a922020-01-22 11:57:20 +00001005 // When this java_sdk_library is depended upon from others via "libs" property,
Jiyong Parkc678ad32018-04-10 13:07:10 +09001006 // the recorded paths will be returned depending on the link type of the caller.
1007 ctx.VisitDirectDeps(func(to android.Module) {
Jiyong Parkc678ad32018-04-10 13:07:10 +09001008 tag := ctx.OtherModuleDependencyTag(to)
1009
Paul Duffinc8782502020-04-29 20:45:27 +01001010 // Extract information from any of the scope specific dependencies.
1011 if scopeTag, ok := tag.(scopeDependencyTag); ok {
1012 apiScope := scopeTag.apiScope
Paul Duffin803a9562020-05-20 11:52:25 +01001013 scopePaths := module.getScopePathsCreateIfNeeded(apiScope)
Paul Duffinc8782502020-04-29 20:45:27 +01001014
1015 // Extract information from the dependency. The exact information extracted
1016 // is determined by the nature of the dependency which is determined by the tag.
1017 scopeTag.extractDepInfo(ctx, to, scopePaths)
Sundong Ahn20e998b2018-07-24 11:19:26 +09001018 }
Jiyong Parkc678ad32018-04-10 13:07:10 +09001019 })
1020}
1021
Jiyong Park0b0e1b92019-12-03 13:24:29 +09001022func (module *SdkLibrary) AndroidMkEntries() []android.AndroidMkEntries {
Paul Duffindfa131e2020-05-15 20:37:11 +01001023 if !module.requiresRuntimeImplementationLibrary() {
Paul Duffin43db9be2019-12-30 17:35:49 +00001024 return nil
1025 }
Jiyong Park0b0e1b92019-12-03 13:24:29 +09001026 entriesList := module.Library.AndroidMkEntries()
1027 entries := &entriesList[0]
Jaewoong Jungb0c127c2019-08-29 14:56:03 -07001028 entries.Required = append(entries.Required, module.xmlFileName())
Jiyong Park0b0e1b92019-12-03 13:24:29 +09001029 return entriesList
Jiyong Park82484c02018-04-23 21:41:26 +09001030}
1031
Jiyong Parkc678ad32018-04-10 13:07:10 +09001032// Module name of the runtime implementation library
Paul Duffin5df79302020-05-16 15:52:12 +01001033func (module *SdkLibrary) implLibraryModuleName() string {
1034 return module.BaseModuleName() + ".impl"
Jiyong Parkc678ad32018-04-10 13:07:10 +09001035}
1036
Jiyong Parkc678ad32018-04-10 13:07:10 +09001037// Module name of the XML file for the lib
Inseob Kimc0907f12019-02-08 21:00:45 +09001038func (module *SdkLibrary) xmlFileName() string {
Jiyong Parkc678ad32018-04-10 13:07:10 +09001039 return module.BaseModuleName() + sdkXmlFileSuffix
1040}
1041
Anton Hansson5fd5d242020-03-27 19:43:19 +00001042// The dist path of the stub artifacts
1043func (module *SdkLibrary) apiDistPath(apiScope *apiScope) string {
1044 if module.ModuleBase.Owner() != "" {
1045 return path.Join("apistubs", module.ModuleBase.Owner(), apiScope.name)
1046 } else if Bool(module.sdkLibraryProperties.Core_lib) {
1047 return path.Join("apistubs", "core", apiScope.name)
1048 } else {
1049 return path.Join("apistubs", "android", apiScope.name)
1050 }
1051}
1052
Paul Duffin12ceb462019-12-24 20:31:31 +00001053// Get the sdk version for use when compiling the stubs library.
Paul Duffin780c5f42020-05-12 15:52:55 +01001054func (module *SdkLibrary) sdkVersionForStubsLibrary(mctx android.EarlyModuleContext, apiScope *apiScope) string {
Paul Duffin87a05a32020-05-12 11:50:28 +01001055 scopeProperties := module.scopeToProperties[apiScope]
1056 if scopeProperties.Sdk_version != nil {
1057 return proptools.String(scopeProperties.Sdk_version)
1058 }
1059
Paul Duffin12ceb462019-12-24 20:31:31 +00001060 sdkDep := decodeSdkDep(mctx, sdkContext(&module.Library))
1061 if sdkDep.hasStandardLibs() {
1062 // If building against a standard sdk then use the sdk version appropriate for the scope.
Paul Duffind1b3a922020-01-22 11:57:20 +00001063 return apiScope.sdkVersion
Paul Duffin12ceb462019-12-24 20:31:31 +00001064 } else {
1065 // Otherwise, use no system module.
1066 return "none"
1067 }
1068}
1069
Paul Duffind1b3a922020-01-22 11:57:20 +00001070func (module *SdkLibrary) latestApiFilegroupName(apiScope *apiScope) string {
1071 return ":" + module.BaseModuleName() + ".api." + apiScope.name + ".latest"
Jiyong Park58c518b2018-05-12 22:29:12 +09001072}
Jiyong Parkc678ad32018-04-10 13:07:10 +09001073
Paul Duffind1b3a922020-01-22 11:57:20 +00001074func (module *SdkLibrary) latestRemovedApiFilegroupName(apiScope *apiScope) string {
1075 return ":" + module.BaseModuleName() + "-removed.api." + apiScope.name + ".latest"
Jiyong Parkc678ad32018-04-10 13:07:10 +09001076}
1077
Paul Duffin5df79302020-05-16 15:52:12 +01001078// Creates the implementation java library
1079func (module *SdkLibrary) createImplLibrary(mctx android.DefaultableHookContext) {
1080 props := struct {
1081 Name *string
1082 Visibility []string
1083 }{
1084 Name: proptools.StringPtr(module.implLibraryModuleName()),
1085 Visibility: module.sdkLibraryProperties.Impl_library_visibility,
1086 }
1087
1088 properties := []interface{}{
1089 &module.properties,
1090 &module.protoProperties,
1091 &module.deviceProperties,
1092 &module.dexpreoptProperties,
1093 &props,
1094 module.sdkComponentPropertiesForChildLibrary(),
1095 }
1096 mctx.CreateModule(LibraryFactory, properties...)
1097}
1098
Jiyong Parkc678ad32018-04-10 13:07:10 +09001099// Creates a static java library that has API stubs
Paul Duffinf0229202020-04-29 16:47:28 +01001100func (module *SdkLibrary) createStubsLibrary(mctx android.DefaultableHookContext, apiScope *apiScope) {
Jiyong Parkc678ad32018-04-10 13:07:10 +09001101 props := struct {
Paul Duffin1dbe3ca2020-05-16 09:57:59 +01001102 Name *string
1103 Visibility []string
1104 Srcs []string
1105 Installable *bool
1106 Sdk_version *string
1107 System_modules *string
1108 Patch_module *string
1109 Libs []string
1110 Compile_dex *bool
1111 Java_version *string
1112 Product_variables struct {
Jiyong Park82484c02018-04-23 21:41:26 +09001113 Pdk struct {
1114 Enabled *bool
1115 }
Jiyong Parkc678ad32018-04-10 13:07:10 +09001116 }
Sundong Ahn054b19a2018-10-19 13:46:09 +09001117 Openjdk9 struct {
1118 Srcs []string
1119 Javacflags []string
1120 }
Anton Hansson5fd5d242020-03-27 19:43:19 +00001121 Dist struct {
1122 Targets []string
1123 Dest *string
1124 Dir *string
1125 Tag *string
1126 }
Jiyong Parkc678ad32018-04-10 13:07:10 +09001127 }{}
1128
Paul Duffinc3091c82020-05-08 14:16:20 +01001129 props.Name = proptools.StringPtr(module.stubsLibraryModuleName(apiScope))
Paul Duffin4911a892020-04-29 23:35:13 +01001130
1131 // If stubs_library_visibility is not set then the created module will use the
1132 // visibility of this module.
1133 visibility := module.sdkLibraryProperties.Stubs_library_visibility
1134 props.Visibility = visibility
1135
Jiyong Parkc678ad32018-04-10 13:07:10 +09001136 // sources are generated from the droiddoc
Paul Duffinc3091c82020-05-08 14:16:20 +01001137 props.Srcs = []string{":" + module.stubsSourceModuleName(apiScope)}
Paul Duffin12ceb462019-12-24 20:31:31 +00001138 sdkVersion := module.sdkVersionForStubsLibrary(mctx, apiScope)
Paul Duffin52d398a2019-06-11 12:31:14 +01001139 props.Sdk_version = proptools.StringPtr(sdkVersion)
Paul Duffina18abc22020-05-16 18:54:24 +01001140 props.System_modules = module.deviceProperties.System_modules
1141 props.Patch_module = module.properties.Patch_module
Paul Duffin367ab912019-12-23 19:40:36 +00001142 props.Installable = proptools.BoolPtr(false)
Sundong Ahn054b19a2018-10-19 13:46:09 +09001143 props.Libs = module.sdkLibraryProperties.Stub_only_libs
Jiyong Park82484c02018-04-23 21:41:26 +09001144 props.Product_variables.Pdk.Enabled = proptools.BoolPtr(false)
Paul Duffina18abc22020-05-16 18:54:24 +01001145 props.Openjdk9.Srcs = module.properties.Openjdk9.Srcs
1146 props.Openjdk9.Javacflags = module.properties.Openjdk9.Javacflags
Anton Hansson83509b52020-05-21 09:21:57 +01001147 // We compile the stubs for 1.8 in line with the main android.jar stubs, and potential
1148 // interop with older developer tools that don't support 1.9.
1149 props.Java_version = proptools.StringPtr("1.8")
Paul Duffina18abc22020-05-16 18:54:24 +01001150 if module.deviceProperties.Compile_dex != nil {
1151 props.Compile_dex = module.deviceProperties.Compile_dex
Sundong Ahndd567f92018-07-31 17:19:11 +09001152 }
Jiyong Parkc678ad32018-04-10 13:07:10 +09001153
Anton Hansson5fd5d242020-03-27 19:43:19 +00001154 // Dist the class jar artifact for sdk builds.
1155 if !Bool(module.sdkLibraryProperties.No_dist) {
1156 props.Dist.Targets = []string{"sdk", "win_sdk"}
1157 props.Dist.Dest = proptools.StringPtr(fmt.Sprintf("%v.jar", module.BaseModuleName()))
1158 props.Dist.Dir = proptools.StringPtr(module.apiDistPath(apiScope))
1159 props.Dist.Tag = proptools.StringPtr(".jar")
1160 }
Jiyong Parkc678ad32018-04-10 13:07:10 +09001161
Paul Duffin859fe962020-05-15 10:20:31 +01001162 mctx.CreateModule(LibraryFactory, &props, module.sdkComponentPropertiesForChildLibrary())
Jiyong Parkc678ad32018-04-10 13:07:10 +09001163}
1164
Paul Duffin6d0886e2020-04-07 18:49:53 +01001165// Creates a droidstubs module that creates stubs source files from the given full source
Paul Duffinc8782502020-04-29 20:45:27 +01001166// files and also updates and checks the API specification files.
Paul Duffin0ff08bd2020-04-29 13:30:54 +01001167func (module *SdkLibrary) createStubsSourcesAndApi(mctx android.DefaultableHookContext, apiScope *apiScope, name string, createStubSources, createApi bool, scopeSpecificDroidstubsArgs []string) {
Jiyong Parkc678ad32018-04-10 13:07:10 +09001168 props := struct {
Sundong Ahn054b19a2018-10-19 13:46:09 +09001169 Name *string
Paul Duffin4911a892020-04-29 23:35:13 +01001170 Visibility []string
Sundong Ahn054b19a2018-10-19 13:46:09 +09001171 Srcs []string
1172 Installable *bool
Paul Duffin52d398a2019-06-11 12:31:14 +01001173 Sdk_version *string
Paul Duffin12ceb462019-12-24 20:31:31 +00001174 System_modules *string
Sundong Ahn054b19a2018-10-19 13:46:09 +09001175 Libs []string
Paul Duffin11512472019-02-11 15:55:17 +00001176 Arg_files []string
Sundong Ahn054b19a2018-10-19 13:46:09 +09001177 Args *string
Sundong Ahn054b19a2018-10-19 13:46:09 +09001178 Java_version *string
1179 Merge_annotations_dirs []string
1180 Merge_inclusion_annotations_dirs []string
Paul Duffin0ff08bd2020-04-29 13:30:54 +01001181 Generate_stubs *bool
Sundong Ahn054b19a2018-10-19 13:46:09 +09001182 Check_api struct {
Inseob Kim38449af2019-02-28 14:24:05 +09001183 Current ApiToCheck
1184 Last_released ApiToCheck
1185 Ignore_missing_latest_api *bool
Paul Duffin160fe412020-05-10 19:32:20 +01001186
1187 Api_lint struct {
1188 Enabled *bool
1189 New_since *string
1190 Baseline_file *string
1191 }
Jiyong Park58c518b2018-05-12 22:29:12 +09001192 }
Sundong Ahn1b92c822018-05-29 11:35:17 +09001193 Aidl struct {
1194 Include_dirs []string
1195 Local_include_dirs []string
1196 }
Anton Hansson5fd5d242020-03-27 19:43:19 +00001197 Dist struct {
1198 Targets []string
1199 Dest *string
1200 Dir *string
1201 }
Jiyong Parkc678ad32018-04-10 13:07:10 +09001202 }{}
1203
Paul Duffin7b78b4d2020-04-28 14:08:32 +01001204 // The stubs source processing uses the same compile time classpath when extracting the
1205 // API from the implementation library as it does when compiling it. i.e. the same
1206 // * sdk version
1207 // * system_modules
1208 // * libs (static_libs/libs)
Paul Duffin250e6192019-06-07 10:44:37 +01001209
Paul Duffin0ff08bd2020-04-29 13:30:54 +01001210 props.Name = proptools.StringPtr(name)
Paul Duffin4911a892020-04-29 23:35:13 +01001211
1212 // If stubs_source_visibility is not set then the created module will use the
1213 // visibility of this module.
1214 visibility := module.sdkLibraryProperties.Stubs_source_visibility
1215 props.Visibility = visibility
1216
Paul Duffina18abc22020-05-16 18:54:24 +01001217 props.Srcs = append(props.Srcs, module.properties.Srcs...)
1218 props.Sdk_version = module.deviceProperties.Sdk_version
1219 props.System_modules = module.deviceProperties.System_modules
Jiyong Parkc678ad32018-04-10 13:07:10 +09001220 props.Installable = proptools.BoolPtr(false)
Sundong Ahne6f0b052018-06-05 16:46:14 +09001221 // A droiddoc module has only one Libs property and doesn't distinguish between
1222 // shared libs and static libs. So we need to add both of these libs to Libs property.
Paul Duffina18abc22020-05-16 18:54:24 +01001223 props.Libs = module.properties.Libs
1224 props.Libs = append(props.Libs, module.properties.Static_libs...)
1225 props.Aidl.Include_dirs = module.deviceProperties.Aidl.Include_dirs
1226 props.Aidl.Local_include_dirs = module.deviceProperties.Aidl.Local_include_dirs
1227 props.Java_version = module.properties.Java_version
Jiyong Parkc678ad32018-04-10 13:07:10 +09001228
Sundong Ahn054b19a2018-10-19 13:46:09 +09001229 props.Merge_annotations_dirs = module.sdkLibraryProperties.Merge_annotations_dirs
1230 props.Merge_inclusion_annotations_dirs = module.sdkLibraryProperties.Merge_inclusion_annotations_dirs
1231
Paul Duffin6d0886e2020-04-07 18:49:53 +01001232 droidstubsArgs := []string{}
Paul Duffin235ffff2019-12-24 10:41:30 +00001233 if len(module.sdkLibraryProperties.Api_packages) != 0 {
Paul Duffin6d0886e2020-04-07 18:49:53 +01001234 droidstubsArgs = append(droidstubsArgs, "--stub-packages "+strings.Join(module.sdkLibraryProperties.Api_packages, ":"))
Paul Duffin235ffff2019-12-24 10:41:30 +00001235 }
1236 if len(module.sdkLibraryProperties.Hidden_api_packages) != 0 {
Paul Duffin6d0886e2020-04-07 18:49:53 +01001237 droidstubsArgs = append(droidstubsArgs,
Paul Duffin235ffff2019-12-24 10:41:30 +00001238 android.JoinWithPrefix(module.sdkLibraryProperties.Hidden_api_packages, " --hide-package "))
1239 }
Paul Duffin6d0886e2020-04-07 18:49:53 +01001240 droidstubsArgs = append(droidstubsArgs, module.sdkLibraryProperties.Droiddoc_options...)
Paul Duffin235ffff2019-12-24 10:41:30 +00001241 disabledWarnings := []string{
1242 "MissingPermission",
1243 "BroadcastBehavior",
1244 "HiddenSuperclass",
1245 "DeprecationMismatch",
1246 "UnavailableSymbol",
1247 "SdkConstant",
1248 "HiddenTypeParameter",
1249 "Todo",
1250 "Typo",
1251 }
Paul Duffin6d0886e2020-04-07 18:49:53 +01001252 droidstubsArgs = append(droidstubsArgs, android.JoinWithPrefix(disabledWarnings, "--hide "))
Sundong Ahnfb2721f2018-09-17 13:23:09 +09001253
Paul Duffin0ff08bd2020-04-29 13:30:54 +01001254 if !createStubSources {
1255 // Stubs are not required.
1256 props.Generate_stubs = proptools.BoolPtr(false)
1257 }
1258
Paul Duffin1fb487d2020-04-07 18:50:10 +01001259 // Add in scope specific arguments.
Paul Duffin0ff08bd2020-04-29 13:30:54 +01001260 droidstubsArgs = append(droidstubsArgs, scopeSpecificDroidstubsArgs...)
Paul Duffin11512472019-02-11 15:55:17 +00001261 props.Arg_files = module.sdkLibraryProperties.Droiddoc_option_files
Paul Duffin6d0886e2020-04-07 18:49:53 +01001262 props.Args = proptools.StringPtr(strings.Join(droidstubsArgs, " "))
Jiyong Parkc678ad32018-04-10 13:07:10 +09001263
Paul Duffin0ff08bd2020-04-29 13:30:54 +01001264 if createApi {
1265 // List of APIs identified from the provided source files are created. They are later
1266 // compared against to the not-yet-released (a.k.a current) list of APIs and to the
1267 // last-released (a.k.a numbered) list of API.
1268 currentApiFileName := apiScope.apiFilePrefix + "current.txt"
1269 removedApiFileName := apiScope.apiFilePrefix + "removed.txt"
1270 apiDir := module.getApiDir()
1271 currentApiFileName = path.Join(apiDir, currentApiFileName)
1272 removedApiFileName = path.Join(apiDir, removedApiFileName)
Jiyong Parkc678ad32018-04-10 13:07:10 +09001273
Paul Duffin0ff08bd2020-04-29 13:30:54 +01001274 // check against the not-yet-release API
1275 props.Check_api.Current.Api_file = proptools.StringPtr(currentApiFileName)
1276 props.Check_api.Current.Removed_api_file = proptools.StringPtr(removedApiFileName)
Jiyong Park58c518b2018-05-12 22:29:12 +09001277
Paul Duffin0ff08bd2020-04-29 13:30:54 +01001278 if !apiScope.unstable {
1279 // check against the latest released API
1280 latestApiFilegroupName := proptools.StringPtr(module.latestApiFilegroupName(apiScope))
1281 props.Check_api.Last_released.Api_file = latestApiFilegroupName
1282 props.Check_api.Last_released.Removed_api_file = proptools.StringPtr(
1283 module.latestRemovedApiFilegroupName(apiScope))
1284 props.Check_api.Ignore_missing_latest_api = proptools.BoolPtr(true)
Paul Duffin160fe412020-05-10 19:32:20 +01001285
Paul Duffin0ff08bd2020-04-29 13:30:54 +01001286 if proptools.Bool(module.sdkLibraryProperties.Api_lint.Enabled) {
1287 // Enable api lint.
1288 props.Check_api.Api_lint.Enabled = proptools.BoolPtr(true)
1289 props.Check_api.Api_lint.New_since = latestApiFilegroupName
Paul Duffin160fe412020-05-10 19:32:20 +01001290
Paul Duffin0ff08bd2020-04-29 13:30:54 +01001291 // If it exists then pass a lint-baseline.txt through to droidstubs.
1292 baselinePath := path.Join(apiDir, apiScope.apiFilePrefix+"lint-baseline.txt")
1293 baselinePathRelativeToRoot := path.Join(mctx.ModuleDir(), baselinePath)
1294 paths, err := mctx.GlobWithDeps(baselinePathRelativeToRoot, nil)
1295 if err != nil {
1296 mctx.ModuleErrorf("error checking for presence of %s: %s", baselinePathRelativeToRoot, err)
1297 }
1298 if len(paths) == 1 {
1299 props.Check_api.Api_lint.Baseline_file = proptools.StringPtr(baselinePath)
1300 } else if len(paths) != 0 {
1301 mctx.ModuleErrorf("error checking for presence of %s: expected one path, found: %v", baselinePathRelativeToRoot, paths)
1302 }
Paul Duffin160fe412020-05-10 19:32:20 +01001303 }
1304 }
Jiyong Park58c518b2018-05-12 22:29:12 +09001305
Paul Duffin0ff08bd2020-04-29 13:30:54 +01001306 // Dist the api txt artifact for sdk builds.
1307 if !Bool(module.sdkLibraryProperties.No_dist) {
1308 props.Dist.Targets = []string{"sdk", "win_sdk"}
1309 props.Dist.Dest = proptools.StringPtr(fmt.Sprintf("%v.txt", module.BaseModuleName()))
1310 props.Dist.Dir = proptools.StringPtr(path.Join(module.apiDistPath(apiScope), "api"))
1311 }
Anton Hansson5fd5d242020-03-27 19:43:19 +00001312 }
1313
Colin Cross84dfc3d2019-09-25 11:33:01 -07001314 mctx.CreateModule(DroidstubsFactory, &props)
Jiyong Parkc678ad32018-04-10 13:07:10 +09001315}
1316
Jooyung Han5e9013b2020-03-10 06:23:13 +09001317func (module *SdkLibrary) DepIsInSameApex(mctx android.BaseModuleContext, dep android.Module) bool {
1318 depTag := mctx.OtherModuleDependencyTag(dep)
1319 if depTag == xmlPermissionsFileTag {
1320 return true
1321 }
1322 return module.Library.DepIsInSameApex(mctx, dep)
1323}
1324
Jiyong Parkc678ad32018-04-10 13:07:10 +09001325// Creates the xml file that publicizes the runtime library
Paul Duffinf0229202020-04-29 16:47:28 +01001326func (module *SdkLibrary) createXmlFile(mctx android.DefaultableHookContext) {
Jiyong Parke3833882020-02-17 17:28:10 +09001327 props := struct {
Paul Duffin1dbe3ca2020-05-16 09:57:59 +01001328 Name *string
1329 Lib_name *string
1330 Apex_available []string
Jiyong Parke3833882020-02-17 17:28:10 +09001331 }{
Jooyung Han5e9013b2020-03-10 06:23:13 +09001332 Name: proptools.StringPtr(module.xmlFileName()),
1333 Lib_name: proptools.StringPtr(module.BaseModuleName()),
1334 Apex_available: module.ApexProperties.Apex_available,
Jiyong Parkc678ad32018-04-10 13:07:10 +09001335 }
Jiyong Parke3833882020-02-17 17:28:10 +09001336
Jiyong Parke3833882020-02-17 17:28:10 +09001337 mctx.CreateModule(sdkLibraryXmlFactory, &props)
Jiyong Parkc678ad32018-04-10 13:07:10 +09001338}
1339
Paul Duffin50061512020-01-21 16:31:05 +00001340func PrebuiltJars(ctx android.BaseModuleContext, baseName string, s sdkSpec) android.Paths {
Jiyong Park6a927c42020-01-21 02:03:43 +09001341 var ver sdkVersion
1342 var kind sdkKind
1343 if s.usePrebuilt(ctx) {
1344 ver = s.version
1345 kind = s.kind
Jiyong Parkc678ad32018-04-10 13:07:10 +09001346 } else {
Jiyong Park6a927c42020-01-21 02:03:43 +09001347 // We don't have prebuilt SDK for the specific sdkVersion.
1348 // Instead of breaking the build, fallback to use "system_current"
1349 ver = sdkVersionCurrent
1350 kind = sdkSystem
Sundong Ahn054b19a2018-10-19 13:46:09 +09001351 }
Jiyong Park6a927c42020-01-21 02:03:43 +09001352
1353 dir := filepath.Join("prebuilts", "sdk", ver.String(), kind.String())
Paul Duffin50061512020-01-21 16:31:05 +00001354 jar := filepath.Join(dir, baseName+".jar")
Sundong Ahn054b19a2018-10-19 13:46:09 +09001355 jarPath := android.ExistentPathForSource(ctx, jar)
Sundong Ahnae418ac2019-02-28 15:01:28 +09001356 if !jarPath.Valid() {
Colin Cross07c88562020-01-07 09:34:44 -08001357 if ctx.Config().AllowMissingDependencies() {
1358 return android.Paths{android.PathForSource(ctx, jar)}
1359 } else {
Jiyong Park6a927c42020-01-21 02:03:43 +09001360 ctx.PropertyErrorf("sdk_library", "invalid sdk version %q, %q does not exist", s.raw, jar)
Colin Cross07c88562020-01-07 09:34:44 -08001361 }
Sundong Ahnae418ac2019-02-28 15:01:28 +09001362 return nil
1363 }
Sundong Ahn054b19a2018-10-19 13:46:09 +09001364 return android.Paths{jarPath.Path()}
1365}
1366
Paul Duffin9b879592020-05-26 13:21:35 +01001367// Get the apex name for module, "" if it is for platform.
1368func getApexNameForModule(module android.Module) string {
1369 if apex, ok := module.(android.ApexModule); ok {
1370 return apex.ApexName()
1371 }
1372
1373 return ""
1374}
1375
1376// Check to see if the other module is within the same named APEX as this module.
1377//
1378// If either this or the other module are on the platform then this will return
1379// false.
1380func (module *SdkLibrary) withinSameApexAs(other android.Module) bool {
1381 name := module.ApexName()
1382 return name != "" && getApexNameForModule(other) == name
1383}
1384
Paul Duffinb05d4292020-05-20 12:19:10 +01001385func (module *SdkLibrary) sdkJars(ctx android.BaseModuleContext, sdkVersion sdkSpec, headerJars bool) android.Paths {
Jiyong Park932cdfe2020-05-28 00:19:53 +09001386 // If the client doesn't set sdk_version, but if this library prefers stubs over
1387 // the impl library, let's provide the widest API surface possible. To do so,
1388 // force override sdk_version to module_current so that the closest possible API
1389 // surface could be found in selectHeaderJarsForSdkVersion
1390 if module.defaultsToStubs() && !sdkVersion.specified() {
1391 sdkVersion = sdkSpecFrom("module_current")
1392 }
Paul Duffind1b3a922020-01-22 11:57:20 +00001393
Paul Duffindaaa3322020-05-26 18:13:57 +01001394 // Only provide access to the implementation library if it is actually built.
1395 if module.requiresRuntimeImplementationLibrary() {
1396 // Check any special cases for java_sdk_library.
1397 //
1398 // Only allow access to the implementation library in the following condition:
1399 // * No sdk_version specified on the referencing module.
Paul Duffin9b879592020-05-26 13:21:35 +01001400 // * The referencing module is in the same apex as this.
1401 if sdkVersion.kind == sdkPrivate || module.withinSameApexAs(ctx.Module()) {
Paul Duffindaaa3322020-05-26 18:13:57 +01001402 if headerJars {
1403 return module.HeaderJars()
1404 } else {
1405 return module.ImplementationJars()
1406 }
Sundong Ahn054b19a2018-10-19 13:46:09 +09001407 }
Jiyong Parkc678ad32018-04-10 13:07:10 +09001408 }
Paul Duffinb05d4292020-05-20 12:19:10 +01001409
Paul Duffin23970f42020-05-20 14:20:02 +01001410 return module.selectHeaderJarsForSdkVersion(ctx, sdkVersion)
Jiyong Parkc678ad32018-04-10 13:07:10 +09001411}
1412
Sundong Ahn241cd372018-07-13 16:16:44 +09001413// to satisfy SdkLibraryDependency interface
Paul Duffind1b3a922020-01-22 11:57:20 +00001414func (module *SdkLibrary) SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths {
1415 return module.sdkJars(ctx, sdkVersion, true /*headerJars*/)
1416}
1417
1418// to satisfy SdkLibraryDependency interface
Jiyong Park6a927c42020-01-21 02:03:43 +09001419func (module *SdkLibrary) SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths {
Paul Duffind1b3a922020-01-22 11:57:20 +00001420 return module.sdkJars(ctx, sdkVersion, false /*headerJars*/)
Sundong Ahn241cd372018-07-13 16:16:44 +09001421}
1422
Sundong Ahn80a87b32019-05-13 15:02:50 +09001423func (module *SdkLibrary) SetNoDist() {
1424 module.sdkLibraryProperties.No_dist = proptools.BoolPtr(true)
1425}
1426
Colin Cross571cccf2019-02-04 11:22:08 -08001427var javaSdkLibrariesKey = android.NewOnceKey("javaSdkLibraries")
1428
Jiyong Park82484c02018-04-23 21:41:26 +09001429func javaSdkLibraries(config android.Config) *[]string {
Colin Cross571cccf2019-02-04 11:22:08 -08001430 return config.Once(javaSdkLibrariesKey, func() interface{} {
Jiyong Park82484c02018-04-23 21:41:26 +09001431 return &[]string{}
1432 }).(*[]string)
1433}
1434
Paul Duffin749f98f2019-12-30 17:23:46 +00001435func (module *SdkLibrary) getApiDir() string {
1436 return proptools.StringDefault(module.sdkLibraryProperties.Api_dir, "api")
1437}
1438
Jiyong Parkc678ad32018-04-10 13:07:10 +09001439// For a java_sdk_library module, create internal modules for stubs, docs,
1440// runtime libs and xml file. If requested, the stubs and docs are created twice
1441// once for public API level and once for system API level
Paul Duffinf0229202020-04-29 16:47:28 +01001442func (module *SdkLibrary) CreateInternalModules(mctx android.DefaultableHookContext) {
1443 // If the module has been disabled then don't create any child modules.
1444 if !module.Enabled() {
1445 return
1446 }
1447
Paul Duffina18abc22020-05-16 18:54:24 +01001448 if len(module.properties.Srcs) == 0 {
Inseob Kimc0907f12019-02-08 21:00:45 +09001449 mctx.PropertyErrorf("srcs", "java_sdk_library must specify srcs")
Jooyung Han58f26ab2019-12-18 15:34:32 +09001450 return
Inseob Kimc0907f12019-02-08 21:00:45 +09001451 }
1452
Paul Duffin37e0b772019-12-30 17:20:10 +00001453 // If this builds against standard libraries (i.e. is not part of the core libraries)
1454 // then assume it provides both system and test apis. Otherwise, assume it does not and
1455 // also assume it does not contribute to the dist build.
1456 sdkDep := decodeSdkDep(mctx, sdkContext(&module.Library))
1457 hasSystemAndTestApis := sdkDep.hasStandardLibs()
Paul Duffin3375e352020-04-28 10:44:03 +01001458 module.sdkLibraryProperties.Generate_system_and_test_apis = hasSystemAndTestApis
Paul Duffin37e0b772019-12-30 17:20:10 +00001459 module.sdkLibraryProperties.No_dist = proptools.BoolPtr(!hasSystemAndTestApis)
1460
Inseob Kim8098faa2019-03-18 10:19:51 +09001461 missing_current_api := false
1462
Paul Duffin3375e352020-04-28 10:44:03 +01001463 generatedScopes := module.getGeneratedApiScopes(mctx)
Paul Duffind1b3a922020-01-22 11:57:20 +00001464
Paul Duffin749f98f2019-12-30 17:23:46 +00001465 apiDir := module.getApiDir()
Paul Duffin3375e352020-04-28 10:44:03 +01001466 for _, scope := range generatedScopes {
Inseob Kim8098faa2019-03-18 10:19:51 +09001467 for _, api := range []string{"current.txt", "removed.txt"} {
Paul Duffind1b3a922020-01-22 11:57:20 +00001468 path := path.Join(mctx.ModuleDir(), apiDir, scope.apiFilePrefix+api)
Inseob Kim8098faa2019-03-18 10:19:51 +09001469 p := android.ExistentPathForSource(mctx, path)
1470 if !p.Valid() {
1471 mctx.ModuleErrorf("Current api file %#v doesn't exist", path)
1472 missing_current_api = true
1473 }
1474 }
1475 }
1476
1477 if missing_current_api {
1478 script := "build/soong/scripts/gen-java-current-api-files.sh"
1479 p := android.ExistentPathForSource(mctx, script)
1480
1481 if !p.Valid() {
1482 panic(fmt.Sprintf("script file %s doesn't exist", script))
1483 }
1484
1485 mctx.ModuleErrorf("One or more current api files are missing. "+
1486 "You can update them by:\n"+
Paul Duffin37e0b772019-12-30 17:20:10 +00001487 "%s %q %s && m update-api",
Paul Duffind1b3a922020-01-22 11:57:20 +00001488 script, filepath.Join(mctx.ModuleDir(), apiDir),
Paul Duffin3375e352020-04-28 10:44:03 +01001489 strings.Join(generatedScopes.Strings(func(s *apiScope) string { return s.apiFilePrefix }), " "))
Inseob Kim8098faa2019-03-18 10:19:51 +09001490 return
1491 }
1492
Paul Duffin3375e352020-04-28 10:44:03 +01001493 for _, scope := range generatedScopes {
Paul Duffin0ff08bd2020-04-29 13:30:54 +01001494 stubsSourceArgs := scope.droidstubsArgsForGeneratingStubsSource
Paul Duffinc3091c82020-05-08 14:16:20 +01001495 stubsSourceModuleName := module.stubsSourceModuleName(scope)
Paul Duffin0ff08bd2020-04-29 13:30:54 +01001496
1497 // If the args needed to generate the stubs and API are the same then they
1498 // can be generated in a single invocation of metalava, otherwise they will
1499 // need separate invocations.
1500 if scope.createStubsSourceAndApiTogether {
1501 // Use the stubs source name for legacy reasons.
1502 module.createStubsSourcesAndApi(mctx, scope, stubsSourceModuleName, true, true, stubsSourceArgs)
1503 } else {
1504 module.createStubsSourcesAndApi(mctx, scope, stubsSourceModuleName, true, false, stubsSourceArgs)
1505
1506 apiArgs := scope.droidstubsArgsForGeneratingApi
Paul Duffinc3091c82020-05-08 14:16:20 +01001507 apiName := module.apiModuleName(scope)
Paul Duffin0ff08bd2020-04-29 13:30:54 +01001508 module.createStubsSourcesAndApi(mctx, scope, apiName, false, true, apiArgs)
1509 }
1510
Paul Duffind1b3a922020-01-22 11:57:20 +00001511 module.createStubsLibrary(mctx, scope)
Inseob Kimc0907f12019-02-08 21:00:45 +09001512 }
1513
Paul Duffindfa131e2020-05-15 20:37:11 +01001514 if module.requiresRuntimeImplementationLibrary() {
Paul Duffin5df79302020-05-16 15:52:12 +01001515 // Create child module to create an implementation library.
1516 //
1517 // This temporarily creates a second implementation library that can be explicitly
1518 // referenced.
1519 //
1520 // TODO(b/156618935) - update comment once only one implementation library is created.
1521 module.createImplLibrary(mctx)
1522
Paul Duffindfa131e2020-05-15 20:37:11 +01001523 // Only create an XML permissions file that declares the library as being usable
1524 // as a shared library if required.
1525 if module.sharedLibrary() {
1526 module.createXmlFile(mctx)
1527 }
Paul Duffin43db9be2019-12-30 17:35:49 +00001528
1529 // record java_sdk_library modules so that they are exported to make
1530 javaSdkLibraries := javaSdkLibraries(mctx.Config())
1531 javaSdkLibrariesLock.Lock()
1532 defer javaSdkLibrariesLock.Unlock()
1533 *javaSdkLibraries = append(*javaSdkLibraries, module.BaseModuleName())
1534 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001535}
1536
1537func (module *SdkLibrary) InitSdkLibraryProperties() {
Colin Crossce6734e2020-06-15 16:09:53 -07001538 module.addHostAndDeviceProperties()
1539 module.AddProperties(&module.sdkLibraryProperties)
Sundong Ahn054b19a2018-10-19 13:46:09 +09001540
Paul Duffin859fe962020-05-15 10:20:31 +01001541 module.initSdkLibraryComponent(&module.ModuleBase)
1542
Paul Duffina18abc22020-05-16 18:54:24 +01001543 module.properties.Installable = proptools.BoolPtr(true)
1544 module.deviceProperties.IsSDKLibrary = true
Inseob Kimc0907f12019-02-08 21:00:45 +09001545}
Sundong Ahn054b19a2018-10-19 13:46:09 +09001546
Paul Duffindfa131e2020-05-15 20:37:11 +01001547func (module *SdkLibrary) requiresRuntimeImplementationLibrary() bool {
1548 return !proptools.Bool(module.sdkLibraryProperties.Api_only)
1549}
1550
Jiyong Park932cdfe2020-05-28 00:19:53 +09001551func (module *SdkLibrary) defaultsToStubs() bool {
1552 return proptools.Bool(module.sdkLibraryProperties.Default_to_stubs)
1553}
1554
Paul Duffin1b1e8062020-05-08 13:44:43 +01001555// Defines how to name the individual component modules the sdk library creates.
1556type sdkLibraryComponentNamingScheme interface {
1557 stubsLibraryModuleName(scope *apiScope, baseName string) string
1558
1559 stubsSourceModuleName(scope *apiScope, baseName string) string
1560
1561 apiModuleName(scope *apiScope, baseName string) string
1562}
1563
1564type defaultNamingScheme struct {
1565}
1566
1567func (s *defaultNamingScheme) stubsLibraryModuleName(scope *apiScope, baseName string) string {
1568 return scope.stubsLibraryModuleName(baseName)
1569}
1570
1571func (s *defaultNamingScheme) stubsSourceModuleName(scope *apiScope, baseName string) string {
1572 return scope.stubsSourceModuleName(baseName)
1573}
1574
1575func (s *defaultNamingScheme) apiModuleName(scope *apiScope, baseName string) string {
1576 return scope.apiModuleName(baseName)
1577}
1578
1579var _ sdkLibraryComponentNamingScheme = (*defaultNamingScheme)(nil)
1580
Paul Duffin6c9c5fc2020-05-08 15:36:30 +01001581type frameworkModulesNamingScheme struct {
1582}
1583
1584func (s *frameworkModulesNamingScheme) moduleSuffix(scope *apiScope) string {
1585 suffix := scope.name
1586 if scope == apiScopeModuleLib {
1587 suffix = "module_libs_"
1588 }
1589 return suffix
1590}
1591
1592func (s *frameworkModulesNamingScheme) stubsLibraryModuleName(scope *apiScope, baseName string) string {
1593 return fmt.Sprintf("%s-stubs-%sapi", baseName, s.moduleSuffix(scope))
1594}
1595
1596func (s *frameworkModulesNamingScheme) stubsSourceModuleName(scope *apiScope, baseName string) string {
1597 return fmt.Sprintf("%s-stubs-srcs-%sapi", baseName, s.moduleSuffix(scope))
1598}
1599
1600func (s *frameworkModulesNamingScheme) apiModuleName(scope *apiScope, baseName string) string {
1601 return fmt.Sprintf("%s-api-%sapi", baseName, s.moduleSuffix(scope))
1602}
1603
1604var _ sdkLibraryComponentNamingScheme = (*frameworkModulesNamingScheme)(nil)
1605
Anton Hansson2d0c1942020-05-25 12:20:51 +01001606func moduleStubLinkType(name string) (stub bool, ret linkType) {
1607 // This suffix-based approach is fragile and could potentially mis-trigger.
1608 // TODO(b/155164730): Clean this up when modules no longer reference sdk_lib stubs directly.
1609 if strings.HasSuffix(name, ".stubs.public") || strings.HasSuffix(name, "-stubs-publicapi") {
1610 return true, javaSdk
1611 }
1612 if strings.HasSuffix(name, ".stubs.system") || strings.HasSuffix(name, "-stubs-systemapi") {
1613 return true, javaSystem
1614 }
1615 if strings.HasSuffix(name, ".stubs.module_lib") || strings.HasSuffix(name, "-stubs-module_libs_api") {
1616 return true, javaModule
1617 }
1618 if strings.HasSuffix(name, ".stubs.test") {
1619 return true, javaSystem
1620 }
1621 return false, javaPlatform
1622}
1623
Jaewoong Jung4f158ee2019-07-11 10:05:35 -07001624// java_sdk_library is a special Java library that provides optional platform APIs to apps.
1625// In practice, it can be viewed as a combination of several modules: 1) stubs library that clients
1626// are linked against to, 2) droiddoc module that internally generates API stubs source files,
1627// 3) the real runtime shared library that implements the APIs, and 4) XML file for adding
1628// the runtime lib to the classpath at runtime if requested via <uses-library>.
Inseob Kimc0907f12019-02-08 21:00:45 +09001629func SdkLibraryFactory() android.Module {
1630 module := &SdkLibrary{}
Paul Duffinc3091c82020-05-08 14:16:20 +01001631
1632 // Initialize information common between source and prebuilt.
1633 module.initCommon(&module.ModuleBase)
1634
Inseob Kimc0907f12019-02-08 21:00:45 +09001635 module.InitSdkLibraryProperties()
Jooyung Han58f26ab2019-12-18 15:34:32 +09001636 android.InitApexModule(module)
Sundong Ahn054b19a2018-10-19 13:46:09 +09001637 InitJavaModule(module, android.HostAndDeviceSupported)
Paul Duffin3375e352020-04-28 10:44:03 +01001638
1639 // Initialize the map from scope to scope specific properties.
1640 scopeToProperties := make(map[*apiScope]*ApiScopeProperties)
1641 for _, scope := range allApiScopes {
1642 scopeToProperties[scope] = scope.scopeSpecificProperties(module)
1643 }
1644 module.scopeToProperties = scopeToProperties
1645
Paul Duffin4911a892020-04-29 23:35:13 +01001646 // Add the properties containing visibility rules so that they are checked.
Paul Duffin5df79302020-05-16 15:52:12 +01001647 android.AddVisibilityProperty(module, "impl_library_visibility", &module.sdkLibraryProperties.Impl_library_visibility)
Paul Duffin4911a892020-04-29 23:35:13 +01001648 android.AddVisibilityProperty(module, "stubs_library_visibility", &module.sdkLibraryProperties.Stubs_library_visibility)
1649 android.AddVisibilityProperty(module, "stubs_source_visibility", &module.sdkLibraryProperties.Stubs_source_visibility)
1650
Paul Duffin1b1e8062020-05-08 13:44:43 +01001651 module.SetDefaultableHook(func(ctx android.DefaultableHookContext) {
Paul Duffindfa131e2020-05-15 20:37:11 +01001652 // If no implementation is required then it cannot be used as a shared library
1653 // either.
1654 if !module.requiresRuntimeImplementationLibrary() {
1655 // If shared_library has been explicitly set to true then it is incompatible
1656 // with api_only: true.
1657 if proptools.Bool(module.commonSdkLibraryProperties.Shared_library) {
1658 ctx.PropertyErrorf("api_only/shared_library", "inconsistent settings, shared_library and api_only cannot both be true")
1659 }
1660 // Set shared_library: false.
1661 module.commonSdkLibraryProperties.Shared_library = proptools.BoolPtr(false)
1662 }
1663
Paul Duffin1b1e8062020-05-08 13:44:43 +01001664 if module.initCommonAfterDefaultsApplied(ctx) {
1665 module.CreateInternalModules(ctx)
1666 }
1667 })
Jiyong Parkc678ad32018-04-10 13:07:10 +09001668 return module
1669}
Colin Cross79c7c262019-04-17 11:11:46 -07001670
1671//
1672// SDK library prebuilts
1673//
1674
Paul Duffin56d44902020-01-31 13:36:25 +00001675// Properties associated with each api scope.
1676type sdkLibraryScopeProperties struct {
Colin Cross79c7c262019-04-17 11:11:46 -07001677 Jars []string `android:"path"`
1678
1679 Sdk_version *string
1680
Colin Cross79c7c262019-04-17 11:11:46 -07001681 // List of shared java libs that this module has dependencies to
1682 Libs []string
Paul Duffin3d1248c2020-04-09 00:10:17 +01001683
Paul Duffinc8782502020-04-29 20:45:27 +01001684 // The stubs source.
Paul Duffin3d1248c2020-04-09 00:10:17 +01001685 Stub_srcs []string `android:"path"`
Paul Duffin1fd005d2020-04-09 01:08:11 +01001686
1687 // The current.txt
Paul Duffin0f8faff2020-05-20 16:18:00 +01001688 Current_api *string `android:"path"`
Paul Duffin1fd005d2020-04-09 01:08:11 +01001689
1690 // The removed.txt
Paul Duffin0f8faff2020-05-20 16:18:00 +01001691 Removed_api *string `android:"path"`
Colin Cross79c7c262019-04-17 11:11:46 -07001692}
1693
Paul Duffin56d44902020-01-31 13:36:25 +00001694type sdkLibraryImportProperties struct {
Paul Duffinfcfd7912020-01-31 17:54:30 +00001695 // List of shared java libs, common to all scopes, that this module has
1696 // dependencies to
1697 Libs []string
Paul Duffin56d44902020-01-31 13:36:25 +00001698}
1699
Colin Cross79c7c262019-04-17 11:11:46 -07001700type sdkLibraryImport struct {
1701 android.ModuleBase
1702 android.DefaultableModuleBase
1703 prebuilt android.Prebuilt
Paul Duffindd46f712020-02-10 13:37:10 +00001704 android.ApexModuleBase
1705 android.SdkBase
Colin Cross79c7c262019-04-17 11:11:46 -07001706
1707 properties sdkLibraryImportProperties
1708
Paul Duffin46a26a82020-04-07 19:27:04 +01001709 // Map from api scope to the scope specific property structure.
1710 scopeProperties map[*apiScope]*sdkLibraryScopeProperties
1711
Paul Duffin56d44902020-01-31 13:36:25 +00001712 commonToSdkLibraryAndImport
Colin Cross79c7c262019-04-17 11:11:46 -07001713}
1714
1715var _ SdkLibraryDependency = (*sdkLibraryImport)(nil)
1716
Paul Duffin46a26a82020-04-07 19:27:04 +01001717// The type of a structure that contains a field of type sdkLibraryScopeProperties
1718// for each apiscope in allApiScopes, e.g. something like:
1719// struct {
1720// Public sdkLibraryScopeProperties
1721// System sdkLibraryScopeProperties
1722// ...
1723// }
1724var allScopeStructType = createAllScopePropertiesStructType()
1725
1726// Dynamically create a structure type for each apiscope in allApiScopes.
1727func createAllScopePropertiesStructType() reflect.Type {
1728 var fields []reflect.StructField
1729 for _, apiScope := range allApiScopes {
1730 field := reflect.StructField{
1731 Name: apiScope.fieldName,
1732 Type: reflect.TypeOf(sdkLibraryScopeProperties{}),
1733 }
1734 fields = append(fields, field)
1735 }
1736
1737 return reflect.StructOf(fields)
1738}
1739
1740// Create an instance of the scope specific structure type and return a map
1741// from apiscope to a pointer to each scope specific field.
1742func createPropertiesInstance() (interface{}, map[*apiScope]*sdkLibraryScopeProperties) {
1743 allScopePropertiesPtr := reflect.New(allScopeStructType)
1744 allScopePropertiesStruct := allScopePropertiesPtr.Elem()
1745 scopeProperties := make(map[*apiScope]*sdkLibraryScopeProperties)
1746
1747 for _, apiScope := range allApiScopes {
1748 field := allScopePropertiesStruct.FieldByName(apiScope.fieldName)
1749 scopeProperties[apiScope] = field.Addr().Interface().(*sdkLibraryScopeProperties)
1750 }
1751
1752 return allScopePropertiesPtr.Interface(), scopeProperties
1753}
1754
Jaewoong Jung4f158ee2019-07-11 10:05:35 -07001755// java_sdk_library_import imports a prebuilt java_sdk_library.
Colin Cross79c7c262019-04-17 11:11:46 -07001756func sdkLibraryImportFactory() android.Module {
1757 module := &sdkLibraryImport{}
1758
Paul Duffin46a26a82020-04-07 19:27:04 +01001759 allScopeProperties, scopeToProperties := createPropertiesInstance()
1760 module.scopeProperties = scopeToProperties
1761 module.AddProperties(&module.properties, allScopeProperties)
Colin Cross79c7c262019-04-17 11:11:46 -07001762
Paul Duffinc3091c82020-05-08 14:16:20 +01001763 // Initialize information common between source and prebuilt.
1764 module.initCommon(&module.ModuleBase)
1765
Paul Duffin0bdcb272020-02-06 15:24:57 +00001766 android.InitPrebuiltModule(module, &[]string{""})
Paul Duffindd46f712020-02-10 13:37:10 +00001767 android.InitApexModule(module)
1768 android.InitSdkAwareModule(module)
Colin Cross79c7c262019-04-17 11:11:46 -07001769 InitJavaModule(module, android.HostAndDeviceSupported)
1770
Paul Duffin1b1e8062020-05-08 13:44:43 +01001771 module.SetDefaultableHook(func(mctx android.DefaultableHookContext) {
1772 if module.initCommonAfterDefaultsApplied(mctx) {
1773 module.createInternalModules(mctx)
1774 }
1775 })
Colin Cross79c7c262019-04-17 11:11:46 -07001776 return module
1777}
1778
1779func (module *sdkLibraryImport) Prebuilt() *android.Prebuilt {
1780 return &module.prebuilt
1781}
1782
1783func (module *sdkLibraryImport) Name() string {
1784 return module.prebuilt.Name(module.ModuleBase.Name())
1785}
1786
Paul Duffin6e7ecbf2020-05-08 15:01:19 +01001787func (module *sdkLibraryImport) createInternalModules(mctx android.DefaultableHookContext) {
Colin Cross79c7c262019-04-17 11:11:46 -07001788
Paul Duffin50061512020-01-21 16:31:05 +00001789 // If the build is configured to use prebuilts then force this to be preferred.
1790 if mctx.Config().UnbundledBuildUsePrebuiltSdks() {
1791 module.prebuilt.ForcePrefer()
1792 }
1793
Paul Duffin46a26a82020-04-07 19:27:04 +01001794 for apiScope, scopeProperties := range module.scopeProperties {
Paul Duffin56d44902020-01-31 13:36:25 +00001795 if len(scopeProperties.Jars) == 0 {
1796 continue
1797 }
1798
Paul Duffinbbb546b2020-04-09 00:07:11 +01001799 module.createJavaImportForStubs(mctx, apiScope, scopeProperties)
Paul Duffin3d1248c2020-04-09 00:10:17 +01001800
Paul Duffin0f8faff2020-05-20 16:18:00 +01001801 if len(scopeProperties.Stub_srcs) > 0 {
1802 module.createPrebuiltStubsSources(mctx, apiScope, scopeProperties)
1803 }
Paul Duffin56d44902020-01-31 13:36:25 +00001804 }
Colin Cross79c7c262019-04-17 11:11:46 -07001805
1806 javaSdkLibraries := javaSdkLibraries(mctx.Config())
1807 javaSdkLibrariesLock.Lock()
1808 defer javaSdkLibrariesLock.Unlock()
1809 *javaSdkLibraries = append(*javaSdkLibraries, module.BaseModuleName())
1810}
1811
Paul Duffin6e7ecbf2020-05-08 15:01:19 +01001812func (module *sdkLibraryImport) createJavaImportForStubs(mctx android.DefaultableHookContext, apiScope *apiScope, scopeProperties *sdkLibraryScopeProperties) {
Paul Duffinbbb546b2020-04-09 00:07:11 +01001813 // Creates a java import for the jar with ".stubs" suffix
1814 props := struct {
Paul Duffin1dbe3ca2020-05-16 09:57:59 +01001815 Name *string
1816 Sdk_version *string
1817 Libs []string
1818 Jars []string
1819 Prefer *bool
Paul Duffinbbb546b2020-04-09 00:07:11 +01001820 }{}
Paul Duffinc3091c82020-05-08 14:16:20 +01001821 props.Name = proptools.StringPtr(module.stubsLibraryModuleName(apiScope))
Paul Duffinbbb546b2020-04-09 00:07:11 +01001822 props.Sdk_version = scopeProperties.Sdk_version
1823 // Prepend any of the libs from the legacy public properties to the libs for each of the
1824 // scopes to avoid having to duplicate them in each scope.
1825 props.Libs = append(module.properties.Libs, scopeProperties.Libs...)
1826 props.Jars = scopeProperties.Jars
Paul Duffin1dbe3ca2020-05-16 09:57:59 +01001827
Paul Duffin38b57852020-05-13 16:08:09 +01001828 // The imports are preferred if the java_sdk_library_import is preferred.
1829 props.Prefer = proptools.BoolPtr(module.prebuilt.Prefer())
Paul Duffin859fe962020-05-15 10:20:31 +01001830
1831 mctx.CreateModule(ImportFactory, &props, module.sdkComponentPropertiesForChildLibrary())
Paul Duffinbbb546b2020-04-09 00:07:11 +01001832}
1833
Paul Duffin6e7ecbf2020-05-08 15:01:19 +01001834func (module *sdkLibraryImport) createPrebuiltStubsSources(mctx android.DefaultableHookContext, apiScope *apiScope, scopeProperties *sdkLibraryScopeProperties) {
Paul Duffin3d1248c2020-04-09 00:10:17 +01001835 props := struct {
Paul Duffin38b57852020-05-13 16:08:09 +01001836 Name *string
1837 Srcs []string
1838 Prefer *bool
Paul Duffin3d1248c2020-04-09 00:10:17 +01001839 }{}
Paul Duffinc3091c82020-05-08 14:16:20 +01001840 props.Name = proptools.StringPtr(module.stubsSourceModuleName(apiScope))
Paul Duffin3d1248c2020-04-09 00:10:17 +01001841 props.Srcs = scopeProperties.Stub_srcs
1842 mctx.CreateModule(PrebuiltStubsSourcesFactory, &props)
Paul Duffin38b57852020-05-13 16:08:09 +01001843
1844 // The stubs source is preferred if the java_sdk_library_import is preferred.
1845 props.Prefer = proptools.BoolPtr(module.prebuilt.Prefer())
Paul Duffin3d1248c2020-04-09 00:10:17 +01001846}
1847
Colin Cross79c7c262019-04-17 11:11:46 -07001848func (module *sdkLibraryImport) DepsMutator(ctx android.BottomUpMutatorContext) {
Paul Duffin46a26a82020-04-07 19:27:04 +01001849 for apiScope, scopeProperties := range module.scopeProperties {
Paul Duffin56d44902020-01-31 13:36:25 +00001850 if len(scopeProperties.Jars) == 0 {
1851 continue
1852 }
1853
1854 // Add dependencies to the prebuilt stubs library
Paul Duffinc3091c82020-05-08 14:16:20 +01001855 ctx.AddVariationDependencies(nil, apiScope.stubsTag, module.stubsLibraryModuleName(apiScope))
Paul Duffin0f8faff2020-05-20 16:18:00 +01001856
1857 if len(scopeProperties.Stub_srcs) > 0 {
1858 // Add dependencies to the prebuilt stubs source library
1859 ctx.AddVariationDependencies(nil, apiScope.stubsSourceTag, module.stubsSourceModuleName(apiScope))
1860 }
Paul Duffin56d44902020-01-31 13:36:25 +00001861 }
Colin Cross79c7c262019-04-17 11:11:46 -07001862}
1863
Paul Duffin46dc45a2020-05-14 15:39:10 +01001864func (module *sdkLibraryImport) OutputFiles(tag string) (android.Paths, error) {
1865 return module.commonOutputFiles(tag)
1866}
1867
Colin Cross79c7c262019-04-17 11:11:46 -07001868func (module *sdkLibraryImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Paul Duffin0f8faff2020-05-20 16:18:00 +01001869 // Record the paths to the prebuilt stubs library and stubs source.
Colin Cross79c7c262019-04-17 11:11:46 -07001870 ctx.VisitDirectDeps(func(to android.Module) {
1871 tag := ctx.OtherModuleDependencyTag(to)
1872
Paul Duffin0f8faff2020-05-20 16:18:00 +01001873 // Extract information from any of the scope specific dependencies.
1874 if scopeTag, ok := tag.(scopeDependencyTag); ok {
1875 apiScope := scopeTag.apiScope
1876 scopePaths := module.getScopePathsCreateIfNeeded(apiScope)
1877
1878 // Extract information from the dependency. The exact information extracted
1879 // is determined by the nature of the dependency which is determined by the tag.
1880 scopeTag.extractDepInfo(ctx, to, scopePaths)
Colin Cross79c7c262019-04-17 11:11:46 -07001881 }
1882 })
Paul Duffin0f8faff2020-05-20 16:18:00 +01001883
1884 // Populate the scope paths with information from the properties.
1885 for apiScope, scopeProperties := range module.scopeProperties {
1886 if len(scopeProperties.Jars) == 0 {
1887 continue
1888 }
1889
1890 paths := module.getScopePathsCreateIfNeeded(apiScope)
1891 paths.currentApiFilePath = android.OptionalPathForModuleSrc(ctx, scopeProperties.Current_api)
1892 paths.removedApiFilePath = android.OptionalPathForModuleSrc(ctx, scopeProperties.Removed_api)
1893 }
Colin Cross79c7c262019-04-17 11:11:46 -07001894}
1895
Paul Duffinb05d4292020-05-20 12:19:10 +01001896func (module *sdkLibraryImport) sdkJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths {
Paul Duffin23970f42020-05-20 14:20:02 +01001897 return module.selectHeaderJarsForSdkVersion(ctx, sdkVersion)
Paul Duffin56d44902020-01-31 13:36:25 +00001898}
1899
Colin Cross79c7c262019-04-17 11:11:46 -07001900// to satisfy SdkLibraryDependency interface
Jiyong Park6a927c42020-01-21 02:03:43 +09001901func (module *sdkLibraryImport) SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths {
Colin Cross79c7c262019-04-17 11:11:46 -07001902 // This module is just a wrapper for the prebuilt stubs.
Paul Duffin56d44902020-01-31 13:36:25 +00001903 return module.sdkJars(ctx, sdkVersion)
Colin Cross79c7c262019-04-17 11:11:46 -07001904}
1905
1906// to satisfy SdkLibraryDependency interface
Jiyong Park6a927c42020-01-21 02:03:43 +09001907func (module *sdkLibraryImport) SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths {
Colin Cross79c7c262019-04-17 11:11:46 -07001908 // This module is just a wrapper for the stubs.
Paul Duffin56d44902020-01-31 13:36:25 +00001909 return module.sdkJars(ctx, sdkVersion)
Colin Cross79c7c262019-04-17 11:11:46 -07001910}
Jiyong Parke3833882020-02-17 17:28:10 +09001911
1912//
1913// java_sdk_library_xml
1914//
1915type sdkLibraryXml struct {
1916 android.ModuleBase
1917 android.DefaultableModuleBase
1918 android.ApexModuleBase
1919
1920 properties sdkLibraryXmlProperties
1921
1922 outputFilePath android.OutputPath
1923 installDirPath android.InstallPath
1924}
1925
1926type sdkLibraryXmlProperties struct {
1927 // canonical name of the lib
1928 Lib_name *string
1929}
1930
1931// java_sdk_library_xml builds the permission xml file for a java_sdk_library.
1932// Not to be used directly by users. java_sdk_library internally uses this.
1933func sdkLibraryXmlFactory() android.Module {
1934 module := &sdkLibraryXml{}
1935
1936 module.AddProperties(&module.properties)
1937
1938 android.InitApexModule(module)
1939 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibCommon)
1940
1941 return module
1942}
1943
1944// from android.PrebuiltEtcModule
1945func (module *sdkLibraryXml) SubDir() string {
1946 return "permissions"
1947}
1948
1949// from android.PrebuiltEtcModule
1950func (module *sdkLibraryXml) OutputFile() android.OutputPath {
1951 return module.outputFilePath
1952}
1953
1954// from android.ApexModule
1955func (module *sdkLibraryXml) AvailableFor(what string) bool {
1956 return true
1957}
1958
1959func (module *sdkLibraryXml) DepsMutator(ctx android.BottomUpMutatorContext) {
1960 // do nothing
1961}
1962
1963// File path to the runtime implementation library
1964func (module *sdkLibraryXml) implPath() string {
1965 implName := proptools.String(module.properties.Lib_name)
1966 if apexName := module.ApexName(); apexName != "" {
1967 // TODO(b/146468504): ApexName() is only a soong module name, not apex name.
1968 // In most cases, this works fine. But when apex_name is set or override_apex is used
1969 // this can be wrong.
1970 return fmt.Sprintf("/apex/%s/javalib/%s.jar", apexName, implName)
1971 }
1972 partition := "system"
1973 if module.SocSpecific() {
1974 partition = "vendor"
1975 } else if module.DeviceSpecific() {
1976 partition = "odm"
1977 } else if module.ProductSpecific() {
1978 partition = "product"
1979 } else if module.SystemExtSpecific() {
1980 partition = "system_ext"
1981 }
1982 return "/" + partition + "/framework/" + implName + ".jar"
1983}
1984
1985func (module *sdkLibraryXml) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1986 libName := proptools.String(module.properties.Lib_name)
1987 xmlContent := fmt.Sprintf(permissionsTemplate, libName, module.implPath())
1988
1989 module.outputFilePath = android.PathForModuleOut(ctx, libName+".xml").OutputPath
1990 rule := android.NewRuleBuilder()
1991 rule.Command().
1992 Text("/bin/bash -c \"echo -e '" + xmlContent + "'\" > ").
1993 Output(module.outputFilePath)
1994
1995 rule.Build(pctx, ctx, "java_sdk_xml", "Permission XML")
1996
1997 module.installDirPath = android.PathForModuleInstall(ctx, "etc", module.SubDir())
1998}
1999
2000func (module *sdkLibraryXml) AndroidMkEntries() []android.AndroidMkEntries {
2001 if !module.IsForPlatform() {
2002 return []android.AndroidMkEntries{android.AndroidMkEntries{
2003 Disabled: true,
2004 }}
2005 }
2006
2007 return []android.AndroidMkEntries{android.AndroidMkEntries{
2008 Class: "ETC",
2009 OutputFile: android.OptionalPathForPath(module.outputFilePath),
2010 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
2011 func(entries *android.AndroidMkEntries) {
2012 entries.SetString("LOCAL_MODULE_TAGS", "optional")
2013 entries.SetString("LOCAL_MODULE_PATH", module.installDirPath.ToMakePath().String())
2014 entries.SetString("LOCAL_INSTALLED_MODULE_STEM", module.outputFilePath.Base())
2015 },
2016 },
2017 }}
2018}
Paul Duffindd46f712020-02-10 13:37:10 +00002019
2020type sdkLibrarySdkMemberType struct {
2021 android.SdkMemberTypeBase
2022}
2023
2024func (s *sdkLibrarySdkMemberType) AddDependencies(mctx android.BottomUpMutatorContext, dependencyTag blueprint.DependencyTag, names []string) {
2025 mctx.AddVariationDependencies(nil, dependencyTag, names...)
2026}
2027
2028func (s *sdkLibrarySdkMemberType) IsInstance(module android.Module) bool {
2029 _, ok := module.(*SdkLibrary)
2030 return ok
2031}
2032
2033func (s *sdkLibrarySdkMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule {
2034 return ctx.SnapshotBuilder().AddPrebuiltModule(member, "java_sdk_library_import")
2035}
2036
2037func (s *sdkLibrarySdkMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties {
2038 return &sdkLibrarySdkMemberProperties{}
2039}
2040
2041type sdkLibrarySdkMemberProperties struct {
2042 android.SdkMemberPropertiesBase
2043
2044 // Scope to per scope properties.
2045 Scopes map[*apiScope]scopeProperties
2046
2047 // Additional libraries that the exported stubs libraries depend upon.
2048 Libs []string
Paul Duffin3d1248c2020-04-09 00:10:17 +01002049
2050 // The Java stubs source files.
2051 Stub_srcs []string
Paul Duffinf7a64332020-05-13 16:54:55 +01002052
2053 // The naming scheme.
2054 Naming_scheme *string
Paul Duffind7eb1c22020-05-26 20:57:10 +01002055
2056 // True if the java_sdk_library_import is for a shared library, false
2057 // otherwise.
2058 Shared_library *bool
Paul Duffindd46f712020-02-10 13:37:10 +00002059}
2060
2061type scopeProperties struct {
Paul Duffin1fd005d2020-04-09 01:08:11 +01002062 Jars android.Paths
2063 StubsSrcJar android.Path
2064 CurrentApiFile android.Path
2065 RemovedApiFile android.Path
2066 SdkVersion string
Paul Duffindd46f712020-02-10 13:37:10 +00002067}
2068
2069func (s *sdkLibrarySdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) {
2070 sdk := variant.(*SdkLibrary)
2071
2072 s.Scopes = make(map[*apiScope]scopeProperties)
2073 for _, apiScope := range allApiScopes {
Paul Duffin803a9562020-05-20 11:52:25 +01002074 paths := sdk.findScopePaths(apiScope)
2075 if paths == nil {
2076 continue
2077 }
2078
Paul Duffindd46f712020-02-10 13:37:10 +00002079 jars := paths.stubsImplPath
2080 if len(jars) > 0 {
2081 properties := scopeProperties{}
2082 properties.Jars = jars
Paul Duffin780c5f42020-05-12 15:52:55 +01002083 properties.SdkVersion = sdk.sdkVersionForStubsLibrary(ctx.SdkModuleContext(), apiScope)
Paul Duffin0f8faff2020-05-20 16:18:00 +01002084 properties.StubsSrcJar = paths.stubsSrcJar.Path()
2085 properties.CurrentApiFile = paths.currentApiFilePath.Path()
2086 properties.RemovedApiFile = paths.removedApiFilePath.Path()
Paul Duffindd46f712020-02-10 13:37:10 +00002087 s.Scopes[apiScope] = properties
2088 }
2089 }
2090
2091 s.Libs = sdk.properties.Libs
Paul Duffindfa131e2020-05-15 20:37:11 +01002092 s.Naming_scheme = sdk.commonSdkLibraryProperties.Naming_scheme
Paul Duffind7eb1c22020-05-26 20:57:10 +01002093 s.Shared_library = proptools.BoolPtr(sdk.sharedLibrary())
Paul Duffindd46f712020-02-10 13:37:10 +00002094}
2095
2096func (s *sdkLibrarySdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) {
Paul Duffinf7a64332020-05-13 16:54:55 +01002097 if s.Naming_scheme != nil {
2098 propertySet.AddProperty("naming_scheme", proptools.String(s.Naming_scheme))
2099 }
Paul Duffind7eb1c22020-05-26 20:57:10 +01002100 if s.Shared_library != nil {
2101 propertySet.AddProperty("shared_library", *s.Shared_library)
2102 }
Paul Duffinf7a64332020-05-13 16:54:55 +01002103
Paul Duffindd46f712020-02-10 13:37:10 +00002104 for _, apiScope := range allApiScopes {
2105 if properties, ok := s.Scopes[apiScope]; ok {
Paul Duffin6b836ba2020-05-13 19:19:49 +01002106 scopeSet := propertySet.AddPropertySet(apiScope.propertyName)
Paul Duffindd46f712020-02-10 13:37:10 +00002107
Paul Duffin3d1248c2020-04-09 00:10:17 +01002108 scopeDir := filepath.Join("sdk_library", s.OsPrefix(), apiScope.name)
2109
Paul Duffindd46f712020-02-10 13:37:10 +00002110 var jars []string
2111 for _, p := range properties.Jars {
Paul Duffin3d1248c2020-04-09 00:10:17 +01002112 dest := filepath.Join(scopeDir, ctx.Name()+"-stubs.jar")
Paul Duffindd46f712020-02-10 13:37:10 +00002113 ctx.SnapshotBuilder().CopyToSnapshot(p, dest)
2114 jars = append(jars, dest)
2115 }
2116 scopeSet.AddProperty("jars", jars)
2117
Paul Duffin3d1248c2020-04-09 00:10:17 +01002118 // Merge the stubs source jar into the snapshot zip so that when it is unpacked
2119 // the source files are also unpacked.
2120 snapshotRelativeDir := filepath.Join(scopeDir, ctx.Name()+"_stub_sources")
2121 ctx.SnapshotBuilder().UnzipToSnapshot(properties.StubsSrcJar, snapshotRelativeDir)
2122 scopeSet.AddProperty("stub_srcs", []string{snapshotRelativeDir})
2123
Paul Duffin1fd005d2020-04-09 01:08:11 +01002124 if properties.CurrentApiFile != nil {
2125 currentApiSnapshotPath := filepath.Join(scopeDir, ctx.Name()+".txt")
2126 ctx.SnapshotBuilder().CopyToSnapshot(properties.CurrentApiFile, currentApiSnapshotPath)
2127 scopeSet.AddProperty("current_api", currentApiSnapshotPath)
2128 }
2129
2130 if properties.RemovedApiFile != nil {
2131 removedApiSnapshotPath := filepath.Join(scopeDir, ctx.Name()+"-removed.txt")
Paul Duffin3dbf9fd2020-06-02 13:00:02 +01002132 ctx.SnapshotBuilder().CopyToSnapshot(properties.RemovedApiFile, removedApiSnapshotPath)
Paul Duffin1fd005d2020-04-09 01:08:11 +01002133 scopeSet.AddProperty("removed_api", removedApiSnapshotPath)
2134 }
2135
Paul Duffindd46f712020-02-10 13:37:10 +00002136 if properties.SdkVersion != "" {
2137 scopeSet.AddProperty("sdk_version", properties.SdkVersion)
2138 }
2139 }
2140 }
2141
2142 if len(s.Libs) > 0 {
2143 propertySet.AddPropertyWithTag("libs", s.Libs, ctx.SnapshotBuilder().SdkMemberReferencePropertyTag(false))
2144 }
2145}