blob: 03b63b9f83bf2cc323022e93ae404be5d9be71ef [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 Duffin6a2bd112020-04-07 19:27:04 +010021 "reflect"
Paul Duffin46fdda82020-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 Duffin6a2bd112020-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 Duffin1c094a02020-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 Duffin5fb82132020-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 Duffin51a2bee2020-05-05 14:40:52 +010078 // The api scope that this scope extends.
79 extends *apiScope
80
Paul Duffin3a254982020-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 Duffin6a2bd112020-04-07 19:27:04 +010093 // The name of the field in the dynamically created structure.
94 fieldName string
95
Paul Duffin0f270632020-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 Duffina377e4c2020-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 Duffin5fb82132020-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 Duffin3c7c3472020-04-07 18:50:10 +0100122
123 // Extra arguments to pass to droidstubs for this scope.
124 droidstubsArgs []string
Anton Hansson5ff28e52020-05-02 11:19:36 +0100125
Paul Duffina377e4c2020-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 Hansson5ff28e52020-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 Duffin5fb82132020-04-29 20:45:27 +0100148 name := scope.name
Paul Duffin46fdda82020-05-14 15:39:10 +0100149 scopeByName[name] = scope
150 allScopeNames = append(allScopeNames, name)
Paul Duffin0f270632020-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 Duffin5fb82132020-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 Duffina377e4c2020-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 Duffin5fb82132020-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 Duffina377e4c2020-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 Duffinb74ee3e2020-05-08 14:16:20 +0100196func (scope *apiScope) stubsLibraryModuleName(baseName string) string {
Paul Duffin1c094a02020-05-08 15:52:37 +0100197 return baseName + ".stubs" + scope.moduleSuffix
Paul Duffind1b3a922020-01-22 11:57:20 +0000198}
199
Paul Duffin5fb82132020-04-29 20:45:27 +0100200func (scope *apiScope) stubsSourceModuleName(baseName string) string {
Paul Duffin1c094a02020-05-08 15:52:37 +0100201 return baseName + ".stubs.source" + scope.moduleSuffix
Paul Duffind1b3a922020-01-22 11:57:20 +0000202}
203
Paul Duffina377e4c2020-04-29 13:30:54 +0100204func (scope *apiScope) apiModuleName(baseName string) string {
Paul Duffin1c094a02020-05-08 15:52:37 +0100205 return baseName + ".api" + scope.moduleSuffix
Paul Duffina377e4c2020-04-29 13:30:54 +0100206}
207
Paul Duffin3a254982020-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 Duffin46fdda82020-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 Duffin3a254982020-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 Duffin3a254982020-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 Hanssone366fff2020-04-28 16:47:41 +0100246 apiFilePrefix: "system-",
Paul Duffin1c094a02020-05-08 15:52:37 +0100247 moduleSuffix: ".system",
Anton Hanssone366fff2020-04-28 16:47:41 +0100248 sdkVersion: "system_current",
Paul Duffin991f2622020-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 Duffin3a254982020-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 Hanssone366fff2020-04-28 16:47:41 +0100258 apiFilePrefix: "test-",
Paul Duffin1c094a02020-05-08 15:52:37 +0100259 moduleSuffix: ".test",
Anton Hanssone366fff2020-04-28 16:47:41 +0100260 sdkVersion: "test_current",
261 droidstubsArgs: []string{"-showAnnotation android.annotation.TestApi"},
Anton Hansson5ff28e52020-05-02 11:19:36 +0100262 unstable: true,
Paul Duffind1b3a922020-01-22 11:57:20 +0000263 })
Paul Duffin6d7f0a72020-04-28 14:13:56 +0100264 apiScopeModuleLib = initApiScope(&apiScope{
Paul Duffin0f270632020-05-13 19:19:49 +0100265 name: "module-lib",
Paul Duffin6d7f0a72020-04-28 14:13:56 +0100266 extends: apiScopeSystem,
267 // Module_lib scope is disabled by default in legacy mode.
268 //
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 Duffind1b3a922020-01-22 11:57:20 +0000283 allApiScopes = apiScopes{
284 apiScopePublic,
285 apiScopeSystem,
286 apiScopeTest,
Paul Duffin6d7f0a72020-04-28 14:13:56 +0100287 apiScopeModuleLib,
Paul Duffind1b3a922020-01-22 11:57:20 +0000288 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900289)
290
Jiyong Park82484c02018-04-23 21:41:26 +0900291var (
292 javaSdkLibrariesLock sync.Mutex
293)
294
Jiyong Parkc678ad32018-04-10 13:07:10 +0900295// TODO: these are big features that are currently missing
Jiyong Park1be96912018-05-28 18:02:19 +0900296// 1) disallowing linking to the runtime shared lib
297// 2) HTML generation
Jiyong Parkc678ad32018-04-10 13:07:10 +0900298
299func init() {
Paul Duffin43dc1cc2019-12-19 11:18:54 +0000300 RegisterSdkLibraryBuildComponents(android.InitRegistrationContext)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900301
Jiyong Park82484c02018-04-23 21:41:26 +0900302 android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) {
303 javaSdkLibraries := javaSdkLibraries(ctx.Config())
304 sort.Strings(*javaSdkLibraries)
305 ctx.Strict("JAVA_SDK_LIBRARIES", strings.Join(*javaSdkLibraries, " "))
306 })
Paul Duffin61871622020-02-10 13:37:10 +0000307
308 // Register sdk member types.
309 android.RegisterSdkMemberType(&sdkLibrarySdkMemberType{
310 android.SdkMemberTypeBase{
311 PropertyName: "java_sdk_libs",
312 SupportsSdk: true,
313 },
314 })
Jiyong Parkc678ad32018-04-10 13:07:10 +0900315}
316
Paul Duffin43dc1cc2019-12-19 11:18:54 +0000317func RegisterSdkLibraryBuildComponents(ctx android.RegistrationContext) {
318 ctx.RegisterModuleType("java_sdk_library", SdkLibraryFactory)
319 ctx.RegisterModuleType("java_sdk_library_import", sdkLibraryImportFactory)
320}
321
Paul Duffin3a254982020-04-28 10:44:03 +0100322// Properties associated with each api scope.
323type ApiScopeProperties struct {
324 // Indicates whether the api surface is generated.
325 //
326 // If this is set for any scope then all scopes must explicitly specify if they
327 // are enabled. This is to prevent new usages from depending on legacy behavior.
328 //
329 // Otherwise, if this is not set for any scope then the default behavior is
330 // scope specific so please refer to the scope specific property documentation.
331 Enabled *bool
Paul Duffin080f5ee2020-05-12 11:50:28 +0100332
333 // The sdk_version to use for building the stubs.
334 //
335 // If not specified then it will use an sdk_version determined as follows:
336 // 1) If the sdk_version specified on the java_sdk_library is none then this
337 // will be none. This is used for java_sdk_library instances that are used
338 // to create stubs that contribute to the core_current sdk version.
339 // 2) Otherwise, it is assumed that this library extends but does not contribute
340 // directly to a specific sdk_version and so this uses the sdk_version appropriate
341 // for the api scope. e.g. public will use sdk_version: current, system will use
342 // sdk_version: system_current, etc.
343 //
344 // This does not affect the sdk_version used for either generating the stubs source
345 // or the API file. They both have to use the same sdk_version as is used for
346 // compiling the implementation library.
347 Sdk_version *string
Paul Duffin3a254982020-04-28 10:44:03 +0100348}
349
Jiyong Parkc678ad32018-04-10 13:07:10 +0900350type sdkLibraryProperties struct {
Paul Duffin9d582cc2020-05-16 15:52:12 +0100351 // Visibility for impl library module. If not specified then defaults to the
352 // visibility property.
353 Impl_library_visibility []string
354
Paul Duffin344c4ee2020-04-29 23:35:13 +0100355 // Visibility for stubs library modules. If not specified then defaults to the
356 // visibility property.
357 Stubs_library_visibility []string
358
359 // Visibility for stubs source modules. If not specified then defaults to the
360 // visibility property.
361 Stubs_source_visibility []string
362
Sundong Ahnf043cf62018-06-25 16:04:37 +0900363 // List of Java libraries that will be in the classpath when building stubs
364 Stub_only_libs []string `android:"arch_variant"`
365
Paul Duffin7a586d32019-12-30 17:09:34 +0000366 // list of package names that will be documented and publicized as API.
367 // This allows the API to be restricted to a subset of the source files provided.
368 // If this is unspecified then all the source files will be treated as being part
369 // of the API.
Jiyong Parkc678ad32018-04-10 13:07:10 +0900370 Api_packages []string
371
Jiyong Park5a2c9d72018-05-01 22:25:41 +0900372 // list of package names that must be hidden from the API
373 Hidden_api_packages []string
374
Paul Duffin749f98f2019-12-30 17:23:46 +0000375 // the relative path to the directory containing the api specification files.
376 // Defaults to "api".
377 Api_dir *string
378
Paul Duffind11e78e2020-05-15 20:37:11 +0100379 // Determines whether a runtime implementation library is built; defaults to false.
380 //
381 // If true then it also prevents the module from being used as a shared module, i.e.
382 // it is as is shared_library: false, was set.
Paul Duffin43db9be2019-12-30 17:35:49 +0000383 Api_only *bool
384
Paul Duffin11512472019-02-11 15:55:17 +0000385 // local files that are used within user customized droiddoc options.
386 Droiddoc_option_files []string
387
388 // additional droiddoc options
389 // Available variables for substitution:
390 //
391 // $(location <label>): the path to the droiddoc_option_files with name <label>
Sundong Ahndd567f92018-07-31 17:19:11 +0900392 Droiddoc_options []string
393
Paul Duffin2ce1e812020-05-20 19:35:27 +0100394 // is set to true, Metalava will allow framework SDK to contain annotations.
395 Annotations_enabled *bool
396
Sundong Ahn054b19a2018-10-19 13:46:09 +0900397 // a list of top-level directories containing files to merge qualifier annotations
398 // (i.e. those intended to be included in the stubs written) from.
399 Merge_annotations_dirs []string
400
401 // a list of top-level directories containing Java stub files to merge show/hide annotations from.
402 Merge_inclusion_annotations_dirs []string
403
404 // If set to true, the path of dist files is apistubs/core. Defaults to false.
405 Core_lib *bool
406
Sundong Ahn80a87b32019-05-13 15:02:50 +0900407 // don't create dist rules.
408 No_dist *bool `blueprint:"mutated"`
409
Paul Duffin3a254982020-04-28 10:44:03 +0100410 // indicates whether system and test apis should be generated.
411 Generate_system_and_test_apis bool `blueprint:"mutated"`
412
413 // The properties specific to the public api scope
414 //
415 // Unless explicitly specified by using public.enabled the public api scope is
416 // enabled by default in both legacy and non-legacy mode.
417 Public ApiScopeProperties
418
419 // The properties specific to the system api scope
420 //
421 // In legacy mode the system api scope is enabled by default when sdk_version
422 // is set to something other than "none".
423 //
424 // In non-legacy mode the system api scope is disabled by default.
425 System ApiScopeProperties
426
427 // The properties specific to the test api scope
428 //
429 // In legacy mode the test api scope is enabled by default when sdk_version
430 // is set to something other than "none".
431 //
432 // In non-legacy mode the test api scope is disabled by default.
433 Test ApiScopeProperties
Paul Duffin37e0b772019-12-30 17:20:10 +0000434
Paul Duffin6d7f0a72020-04-28 14:13:56 +0100435 // The properties specific to the module_lib api scope
436 //
437 // Unless explicitly specified by using test.enabled the module_lib api scope is
438 // disabled by default.
439 Module_lib ApiScopeProperties
440
Jiyong Park27fc4142020-05-28 00:19:53 +0900441 // Determines if the stubs are preferred over the implementation library
442 // for linking, even when the client doesn't specify sdk_version. When this
443 // is set to true, such clients are provided with the widest API surface that
444 // this lib provides. Note however that this option doesn't affect the clients
445 // that are in the same APEX as this library. In that case, the clients are
446 // always linked with the implementation library. Default is false.
447 Default_to_stubs *bool
448
Paul Duffin8986cc92020-05-10 19:32:20 +0100449 // Properties related to api linting.
450 Api_lint struct {
451 // Enable api linting.
452 Enabled *bool
453 }
454
Jiyong Parkc678ad32018-04-10 13:07:10 +0900455 // TODO: determines whether to create HTML doc or not
456 //Html_doc *bool
457}
458
Paul Duffin533f9c72020-05-20 16:18:00 +0100459// Paths to outputs from java_sdk_library and java_sdk_library_import.
460//
461// Fields that are android.Paths are always set (during GenerateAndroidBuildActions).
462// OptionalPaths are always set by java_sdk_library but may not be set by
463// java_sdk_library_import as not all instances provide that information.
Paul Duffind1b3a922020-01-22 11:57:20 +0000464type scopePaths struct {
Paul Duffin533f9c72020-05-20 16:18:00 +0100465 // The path (represented as Paths for convenience when returning) to the stubs header jar.
466 //
467 // That is the jar that is created by turbine.
468 stubsHeaderPath android.Paths
469
470 // The path (represented as Paths for convenience when returning) to the stubs implementation jar.
471 //
472 // This is not the implementation jar, it still only contains stubs.
473 stubsImplPath android.Paths
474
475 // The API specification file, e.g. system_current.txt.
476 currentApiFilePath android.OptionalPath
477
478 // The specification of API elements removed since the last release.
479 removedApiFilePath android.OptionalPath
480
481 // The stubs source jar.
482 stubsSrcJar android.OptionalPath
Paul Duffind1b3a922020-01-22 11:57:20 +0000483}
484
Paul Duffin5fb82132020-04-29 20:45:27 +0100485func (paths *scopePaths) extractStubsLibraryInfoFromDependency(dep android.Module) error {
486 if lib, ok := dep.(Dependency); ok {
487 paths.stubsHeaderPath = lib.HeaderJars()
488 paths.stubsImplPath = lib.ImplementationJars()
489 return nil
490 } else {
491 return fmt.Errorf("expected module that implements Dependency, e.g. java_library")
492 }
493}
494
Paul Duffina377e4c2020-04-29 13:30:54 +0100495func (paths *scopePaths) treatDepAsApiStubsProvider(dep android.Module, action func(provider ApiStubsProvider)) error {
496 if apiStubsProvider, ok := dep.(ApiStubsProvider); ok {
497 action(apiStubsProvider)
Paul Duffin5fb82132020-04-29 20:45:27 +0100498 return nil
499 } else {
500 return fmt.Errorf("expected module that implements ApiStubsProvider, e.g. droidstubs")
501 }
502}
503
Paul Duffin533f9c72020-05-20 16:18:00 +0100504func (paths *scopePaths) treatDepAsApiStubsSrcProvider(dep android.Module, action func(provider ApiStubsSrcProvider)) error {
505 if apiStubsProvider, ok := dep.(ApiStubsSrcProvider); ok {
506 action(apiStubsProvider)
507 return nil
508 } else {
509 return fmt.Errorf("expected module that implements ApiStubsSrcProvider, e.g. droidstubs")
510 }
511}
512
Paul Duffina377e4c2020-04-29 13:30:54 +0100513func (paths *scopePaths) extractApiInfoFromApiStubsProvider(provider ApiStubsProvider) {
Paul Duffin533f9c72020-05-20 16:18:00 +0100514 paths.currentApiFilePath = android.OptionalPathForPath(provider.ApiFilePath())
515 paths.removedApiFilePath = android.OptionalPathForPath(provider.RemovedApiFilePath())
Paul Duffina377e4c2020-04-29 13:30:54 +0100516}
517
518func (paths *scopePaths) extractApiInfoFromDep(dep android.Module) error {
519 return paths.treatDepAsApiStubsProvider(dep, func(provider ApiStubsProvider) {
520 paths.extractApiInfoFromApiStubsProvider(provider)
521 })
522}
523
Paul Duffin533f9c72020-05-20 16:18:00 +0100524func (paths *scopePaths) extractStubsSourceInfoFromApiStubsProviders(provider ApiStubsSrcProvider) {
525 paths.stubsSrcJar = android.OptionalPathForPath(provider.StubsSrcJar())
Paul Duffina377e4c2020-04-29 13:30:54 +0100526}
527
528func (paths *scopePaths) extractStubsSourceInfoFromDep(dep android.Module) error {
Paul Duffin533f9c72020-05-20 16:18:00 +0100529 return paths.treatDepAsApiStubsSrcProvider(dep, func(provider ApiStubsSrcProvider) {
Paul Duffina377e4c2020-04-29 13:30:54 +0100530 paths.extractStubsSourceInfoFromApiStubsProviders(provider)
531 })
532}
533
534func (paths *scopePaths) extractStubsSourceAndApiInfoFromApiStubsProvider(dep android.Module) error {
535 return paths.treatDepAsApiStubsProvider(dep, func(provider ApiStubsProvider) {
536 paths.extractApiInfoFromApiStubsProvider(provider)
537 paths.extractStubsSourceInfoFromApiStubsProviders(provider)
538 })
539}
540
541type commonToSdkLibraryAndImportProperties struct {
Paul Duffin1a724e62020-05-08 13:44:43 +0100542 // The naming scheme to use for the components that this module creates.
543 //
Paul Duffindef8a892020-05-08 15:36:30 +0100544 // If not specified then it defaults to "default". The other allowable value is
545 // "framework-modules" which matches the scheme currently used by framework modules
546 // for the equivalent components represented as separate Soong modules.
Paul Duffin1a724e62020-05-08 13:44:43 +0100547 //
548 // This is a temporary mechanism to simplify conversion from separate modules for each
549 // component that follow a different naming pattern to the default one.
550 //
551 // TODO(b/155480189) - Remove once naming inconsistencies have been resolved.
Paul Duffina377e4c2020-04-29 13:30:54 +0100552 Naming_scheme *string
Paul Duffind11e78e2020-05-15 20:37:11 +0100553
554 // Specifies whether this module can be used as an Android shared library; defaults
555 // to true.
556 //
557 // An Android shared library is one that can be referenced in a <uses-library> element
558 // in an AndroidManifest.xml.
559 Shared_library *bool
Paul Duffina377e4c2020-04-29 13:30:54 +0100560}
561
Paul Duffin56d44902020-01-31 13:36:25 +0000562// Common code between sdk library and sdk library import
563type commonToSdkLibraryAndImport struct {
Paul Duffinb74ee3e2020-05-08 14:16:20 +0100564 moduleBase *android.ModuleBase
565
Paul Duffin56d44902020-01-31 13:36:25 +0000566 scopePaths map[*apiScope]*scopePaths
Paul Duffin1a724e62020-05-08 13:44:43 +0100567
568 namingScheme sdkLibraryComponentNamingScheme
569
Paul Duffind11e78e2020-05-15 20:37:11 +0100570 commonSdkLibraryProperties commonToSdkLibraryAndImportProperties
Paul Duffin64e61992020-05-15 10:20:31 +0100571
572 // Functionality related to this being used as a component of a java_sdk_library.
573 EmbeddableSdkLibraryComponent
Paul Duffin56d44902020-01-31 13:36:25 +0000574}
575
Paul Duffinb74ee3e2020-05-08 14:16:20 +0100576func (c *commonToSdkLibraryAndImport) initCommon(moduleBase *android.ModuleBase) {
577 c.moduleBase = moduleBase
Paul Duffin1a724e62020-05-08 13:44:43 +0100578
Paul Duffind11e78e2020-05-15 20:37:11 +0100579 moduleBase.AddProperties(&c.commonSdkLibraryProperties)
Paul Duffin64e61992020-05-15 10:20:31 +0100580
581 // Initialize this as an sdk library component.
582 c.initSdkLibraryComponent(moduleBase)
Paul Duffin1a724e62020-05-08 13:44:43 +0100583}
584
585func (c *commonToSdkLibraryAndImport) initCommonAfterDefaultsApplied(ctx android.DefaultableHookContext) bool {
Paul Duffind11e78e2020-05-15 20:37:11 +0100586 schemeProperty := proptools.StringDefault(c.commonSdkLibraryProperties.Naming_scheme, "default")
Paul Duffin1a724e62020-05-08 13:44:43 +0100587 switch schemeProperty {
588 case "default":
589 c.namingScheme = &defaultNamingScheme{}
Paul Duffindef8a892020-05-08 15:36:30 +0100590 case "framework-modules":
591 c.namingScheme = &frameworkModulesNamingScheme{}
Paul Duffin1a724e62020-05-08 13:44:43 +0100592 default:
593 ctx.PropertyErrorf("naming_scheme", "expected 'default' but was %q", schemeProperty)
594 return false
595 }
596
Paul Duffind11e78e2020-05-15 20:37:11 +0100597 // Only track this sdk library if this can be used as a shared library.
598 if c.sharedLibrary() {
599 // Use the name specified in the module definition as the owner.
600 c.sdkLibraryComponentProperties.SdkLibraryToImplicitlyTrack = proptools.StringPtr(c.moduleBase.BaseModuleName())
601 }
Paul Duffin64e61992020-05-15 10:20:31 +0100602
Paul Duffin1a724e62020-05-08 13:44:43 +0100603 return true
Paul Duffinb74ee3e2020-05-08 14:16:20 +0100604}
605
606// Name of the java_library module that compiles the stubs source.
607func (c *commonToSdkLibraryAndImport) stubsLibraryModuleName(apiScope *apiScope) string {
Paul Duffin1a724e62020-05-08 13:44:43 +0100608 return c.namingScheme.stubsLibraryModuleName(apiScope, c.moduleBase.BaseModuleName())
Paul Duffinb74ee3e2020-05-08 14:16:20 +0100609}
610
611// Name of the droidstubs module that generates the stubs source and may also
612// generate/check the API.
613func (c *commonToSdkLibraryAndImport) stubsSourceModuleName(apiScope *apiScope) string {
Paul Duffin1a724e62020-05-08 13:44:43 +0100614 return c.namingScheme.stubsSourceModuleName(apiScope, c.moduleBase.BaseModuleName())
Paul Duffinb74ee3e2020-05-08 14:16:20 +0100615}
616
617// Name of the droidstubs module that generates/checks the API. Only used if it
618// requires different arts to the stubs source generating module.
619func (c *commonToSdkLibraryAndImport) apiModuleName(apiScope *apiScope) string {
Paul Duffin1a724e62020-05-08 13:44:43 +0100620 return c.namingScheme.apiModuleName(apiScope, c.moduleBase.BaseModuleName())
Paul Duffinb74ee3e2020-05-08 14:16:20 +0100621}
622
Paul Duffin46fdda82020-05-14 15:39:10 +0100623// The component names for different outputs of the java_sdk_library.
624//
625// They are similar to the names used for the child modules it creates
626const (
627 stubsSourceComponentName = "stubs.source"
628
629 apiTxtComponentName = "api.txt"
630
631 removedApiTxtComponentName = "removed-api.txt"
632)
633
634// A regular expression to match tags that reference a specific stubs component.
635//
636// It will only match if given a valid scope and a valid component. It is verfy strict
637// to ensure it does not accidentally match a similar looking tag that should be processed
638// by the embedded Library.
639var tagSplitter = func() *regexp.Regexp {
640 // Given a list of literal string items returns a regular expression that will
641 // match any one of the items.
642 choice := func(items ...string) string {
643 return `\Q` + strings.Join(items, `\E|\Q`) + `\E`
644 }
645
646 // Regular expression to match one of the scopes.
647 scopesRegexp := choice(allScopeNames...)
648
649 // Regular expression to match one of the components.
650 componentsRegexp := choice(stubsSourceComponentName, apiTxtComponentName, removedApiTxtComponentName)
651
652 // Regular expression to match any combination of one scope and one component.
653 return regexp.MustCompile(fmt.Sprintf(`^\.(%s)\.(%s)$`, scopesRegexp, componentsRegexp))
654}()
655
656// For OutputFileProducer interface
657//
658// .<scope>.stubs.source
659// .<scope>.api.txt
660// .<scope>.removed-api.txt
661func (c *commonToSdkLibraryAndImport) commonOutputFiles(tag string) (android.Paths, error) {
662 if groups := tagSplitter.FindStringSubmatch(tag); groups != nil {
663 scopeName := groups[1]
664 component := groups[2]
665
666 if scope, ok := scopeByName[scopeName]; ok {
667 paths := c.findScopePaths(scope)
668 if paths == nil {
669 return nil, fmt.Errorf("%q does not provide api scope %s", c.moduleBase.BaseModuleName(), scopeName)
670 }
671
672 switch component {
673 case stubsSourceComponentName:
674 if paths.stubsSrcJar.Valid() {
675 return android.Paths{paths.stubsSrcJar.Path()}, nil
676 }
677
678 case apiTxtComponentName:
679 if paths.currentApiFilePath.Valid() {
680 return android.Paths{paths.currentApiFilePath.Path()}, nil
681 }
682
683 case removedApiTxtComponentName:
684 if paths.removedApiFilePath.Valid() {
685 return android.Paths{paths.removedApiFilePath.Path()}, nil
686 }
687 }
688
689 return nil, fmt.Errorf("%s not available for api scope %s", component, scopeName)
690 } else {
691 return nil, fmt.Errorf("unknown scope %s in %s", scope, tag)
692 }
693
694 } else {
695 return nil, nil
696 }
697}
698
Paul Duffin5ae30792020-05-20 11:52:25 +0100699func (c *commonToSdkLibraryAndImport) getScopePathsCreateIfNeeded(scope *apiScope) *scopePaths {
Paul Duffin56d44902020-01-31 13:36:25 +0000700 if c.scopePaths == nil {
701 c.scopePaths = make(map[*apiScope]*scopePaths)
702 }
703 paths := c.scopePaths[scope]
704 if paths == nil {
705 paths = &scopePaths{}
706 c.scopePaths[scope] = paths
707 }
708
709 return paths
710}
711
Paul Duffin5ae30792020-05-20 11:52:25 +0100712func (c *commonToSdkLibraryAndImport) findScopePaths(scope *apiScope) *scopePaths {
713 if c.scopePaths == nil {
714 return nil
715 }
716
717 return c.scopePaths[scope]
718}
719
720// If this does not support the requested api scope then find the closest available
721// scope it does support. Returns nil if no such scope is available.
722func (c *commonToSdkLibraryAndImport) findClosestScopePath(scope *apiScope) *scopePaths {
723 for s := scope; s != nil; s = s.extends {
724 if paths := c.findScopePaths(s); paths != nil {
725 return paths
726 }
727 }
728
729 // This should never happen outside tests as public should be the base scope for every
730 // scope and is enabled by default.
731 return nil
732}
733
Paul Duffina3fb67d2020-05-20 14:20:02 +0100734func (c *commonToSdkLibraryAndImport) selectHeaderJarsForSdkVersion(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths {
Paul Duffin47624362020-05-20 12:19:10 +0100735
736 // If a specific numeric version has been requested then use prebuilt versions of the sdk.
737 if sdkVersion.version.isNumbered() {
738 return PrebuiltJars(ctx, c.moduleBase.BaseModuleName(), sdkVersion)
739 }
740
741 var apiScope *apiScope
742 switch sdkVersion.kind {
743 case sdkSystem:
744 apiScope = apiScopeSystem
Paul Duffin5ae30792020-05-20 11:52:25 +0100745 case sdkModule:
746 apiScope = apiScopeModuleLib
Paul Duffin47624362020-05-20 12:19:10 +0100747 case sdkTest:
748 apiScope = apiScopeTest
749 default:
750 apiScope = apiScopePublic
751 }
752
Paul Duffin5ae30792020-05-20 11:52:25 +0100753 paths := c.findClosestScopePath(apiScope)
754 if paths == nil {
755 var scopes []string
756 for _, s := range allApiScopes {
757 if c.findScopePaths(s) != nil {
758 scopes = append(scopes, s.name)
759 }
760 }
761 ctx.ModuleErrorf("requires api scope %s from %s but it only has %q available", apiScope.name, c.moduleBase.BaseModuleName(), scopes)
762 return nil
763 }
764
Paul Duffina3fb67d2020-05-20 14:20:02 +0100765 return paths.stubsHeaderPath
Paul Duffin47624362020-05-20 12:19:10 +0100766}
767
Paul Duffin64e61992020-05-15 10:20:31 +0100768func (c *commonToSdkLibraryAndImport) sdkComponentPropertiesForChildLibrary() interface{} {
769 componentProps := &struct {
770 SdkLibraryToImplicitlyTrack *string
Paul Duffind11e78e2020-05-15 20:37:11 +0100771 }{}
772
773 if c.sharedLibrary() {
Paul Duffin64e61992020-05-15 10:20:31 +0100774 // Mark the stubs library as being components of this java_sdk_library so that
775 // any app that includes code which depends (directly or indirectly) on the stubs
776 // library will have the appropriate <uses-library> invocation inserted into its
777 // manifest if necessary.
Paul Duffind11e78e2020-05-15 20:37:11 +0100778 componentProps.SdkLibraryToImplicitlyTrack = proptools.StringPtr(c.moduleBase.BaseModuleName())
Paul Duffin64e61992020-05-15 10:20:31 +0100779 }
780
781 return componentProps
782}
783
Paul Duffind11e78e2020-05-15 20:37:11 +0100784// Check if this can be used as a shared library.
785func (c *commonToSdkLibraryAndImport) sharedLibrary() bool {
786 return proptools.BoolDefault(c.commonSdkLibraryProperties.Shared_library, true)
787}
788
Paul Duffin64e61992020-05-15 10:20:31 +0100789// Properties related to the use of a module as an component of a java_sdk_library.
790type SdkLibraryComponentProperties struct {
791
792 // The name of the java_sdk_library/_import to add to a <uses-library> entry
793 // in the AndroidManifest.xml of any Android app that includes code that references
794 // this module. If not set then no java_sdk_library/_import is tracked.
795 SdkLibraryToImplicitlyTrack *string `blueprint:"mutated"`
796}
797
798// Structure to be embedded in a module struct that needs to support the
799// SdkLibraryComponentDependency interface.
800type EmbeddableSdkLibraryComponent struct {
801 sdkLibraryComponentProperties SdkLibraryComponentProperties
802}
803
804func (e *EmbeddableSdkLibraryComponent) initSdkLibraryComponent(moduleBase *android.ModuleBase) {
805 moduleBase.AddProperties(&e.sdkLibraryComponentProperties)
806}
807
808// to satisfy SdkLibraryComponentDependency
809func (e *EmbeddableSdkLibraryComponent) OptionalImplicitSdkLibrary() []string {
810 if e.sdkLibraryComponentProperties.SdkLibraryToImplicitlyTrack != nil {
811 return []string{*e.sdkLibraryComponentProperties.SdkLibraryToImplicitlyTrack}
812 }
813 return nil
814}
815
816// Implemented by modules that are (or possibly could be) a component of a java_sdk_library
817// (including the java_sdk_library) itself.
818type SdkLibraryComponentDependency interface {
819 // The optional name of the sdk library that should be implicitly added to the
820 // AndroidManifest of an app that contains code which references the sdk library.
821 //
822 // Returns an array containing 0 or 1 items rather than a *string to make it easier
823 // to append this to the list of exported sdk libraries.
824 OptionalImplicitSdkLibrary() []string
825}
826
827// Make sure that all the module types that are components of java_sdk_library/_import
828// and which can be referenced (directly or indirectly) from an android app implement
829// the SdkLibraryComponentDependency interface.
830var _ SdkLibraryComponentDependency = (*Library)(nil)
831var _ SdkLibraryComponentDependency = (*Import)(nil)
832var _ SdkLibraryComponentDependency = (*SdkLibrary)(nil)
833var _ SdkLibraryComponentDependency = (*sdkLibraryImport)(nil)
834
835// Provides access to sdk_version related header and implentation jars.
836type SdkLibraryDependency interface {
837 SdkLibraryComponentDependency
838
839 // Get the header jars appropriate for the supplied sdk_version.
840 //
841 // These are turbine generated jars so they only change if the externals of the
842 // class changes but it does not contain and implementation or JavaDoc.
843 SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths
844
845 // Get the implementation jars appropriate for the supplied sdk version.
846 //
847 // These are either the implementation jar for the whole sdk library or the implementation
848 // jars for the stubs. The latter should only be needed when generating JavaDoc as otherwise
849 // they are identical to the corresponding header jars.
850 SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths
851}
852
Inseob Kimc0907f12019-02-08 21:00:45 +0900853type SdkLibrary struct {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900854 Library
Jiyong Parkc678ad32018-04-10 13:07:10 +0900855
Sundong Ahn054b19a2018-10-19 13:46:09 +0900856 sdkLibraryProperties sdkLibraryProperties
Jiyong Parkc678ad32018-04-10 13:07:10 +0900857
Paul Duffin3a254982020-04-28 10:44:03 +0100858 // Map from api scope to the scope specific property structure.
859 scopeToProperties map[*apiScope]*ApiScopeProperties
860
Paul Duffin56d44902020-01-31 13:36:25 +0000861 commonToSdkLibraryAndImport
Jiyong Parkc678ad32018-04-10 13:07:10 +0900862}
863
Inseob Kimc0907f12019-02-08 21:00:45 +0900864var _ Dependency = (*SdkLibrary)(nil)
865var _ SdkLibraryDependency = (*SdkLibrary)(nil)
Colin Cross897d2ed2019-02-11 14:03:51 -0800866
Paul Duffin3a254982020-04-28 10:44:03 +0100867func (module *SdkLibrary) generateTestAndSystemScopesByDefault() bool {
868 return module.sdkLibraryProperties.Generate_system_and_test_apis
869}
870
871func (module *SdkLibrary) getGeneratedApiScopes(ctx android.EarlyModuleContext) apiScopes {
872 // Check to see if any scopes have been explicitly enabled. If any have then all
873 // must be.
874 anyScopesExplicitlyEnabled := false
875 for _, scope := range allApiScopes {
876 scopeProperties := module.scopeToProperties[scope]
877 if scopeProperties.Enabled != nil {
878 anyScopesExplicitlyEnabled = true
879 break
880 }
Paul Duffind1b3a922020-01-22 11:57:20 +0000881 }
Paul Duffin3a254982020-04-28 10:44:03 +0100882
883 var generatedScopes apiScopes
884 enabledScopes := make(map[*apiScope]struct{})
885 for _, scope := range allApiScopes {
886 scopeProperties := module.scopeToProperties[scope]
887 // If any scopes are explicitly enabled then ignore the legacy enabled status.
888 // This is to ensure that any new usages of this module type do not rely on legacy
889 // behaviour.
890 defaultEnabledStatus := false
891 if anyScopesExplicitlyEnabled {
892 defaultEnabledStatus = scope.defaultEnabledStatus
893 } else {
894 defaultEnabledStatus = scope.legacyEnabledStatus(module)
895 }
896 enabled := proptools.BoolDefault(scopeProperties.Enabled, defaultEnabledStatus)
897 if enabled {
898 enabledScopes[scope] = struct{}{}
899 generatedScopes = append(generatedScopes, scope)
900 }
901 }
902
903 // Now check to make sure that any scope that is extended by an enabled scope is also
904 // enabled.
905 for _, scope := range allApiScopes {
906 if _, ok := enabledScopes[scope]; ok {
907 extends := scope.extends
908 if extends != nil {
909 if _, ok := enabledScopes[extends]; !ok {
910 ctx.ModuleErrorf("enabled api scope %q depends on disabled scope %q", scope, extends)
911 }
912 }
913 }
914 }
915
916 return generatedScopes
Paul Duffind1b3a922020-01-22 11:57:20 +0000917}
918
Paul Duffine74ac732020-02-06 13:51:46 +0000919var xmlPermissionsFileTag = dependencyTag{name: "xml-permissions-file"}
920
Jiyong Parke3833882020-02-17 17:28:10 +0900921func IsXmlPermissionsFileDepTag(depTag blueprint.DependencyTag) bool {
922 if dt, ok := depTag.(dependencyTag); ok {
923 return dt == xmlPermissionsFileTag
924 }
925 return false
926}
927
Paul Duffin9d582cc2020-05-16 15:52:12 +0100928var implLibraryTag = dependencyTag{name: "impl-library"}
929
Inseob Kimc0907f12019-02-08 21:00:45 +0900930func (module *SdkLibrary) DepsMutator(ctx android.BottomUpMutatorContext) {
Paul Duffin3a254982020-04-28 10:44:03 +0100931 for _, apiScope := range module.getGeneratedApiScopes(ctx) {
Paul Duffind1b3a922020-01-22 11:57:20 +0000932 // Add dependencies to the stubs library
Paul Duffinb74ee3e2020-05-08 14:16:20 +0100933 ctx.AddVariationDependencies(nil, apiScope.stubsTag, module.stubsLibraryModuleName(apiScope))
Paul Duffind1b3a922020-01-22 11:57:20 +0000934
Paul Duffina377e4c2020-04-29 13:30:54 +0100935 // If the stubs source and API cannot be generated together then add an additional dependency on
936 // the API module.
937 if apiScope.createStubsSourceAndApiTogether {
938 // Add a dependency on the stubs source in order to access both stubs source and api information.
Paul Duffinb74ee3e2020-05-08 14:16:20 +0100939 ctx.AddVariationDependencies(nil, apiScope.stubsSourceAndApiTag, module.stubsSourceModuleName(apiScope))
Paul Duffina377e4c2020-04-29 13:30:54 +0100940 } else {
941 // Add separate dependencies on the creators of the stubs source files and the API.
Paul Duffinb74ee3e2020-05-08 14:16:20 +0100942 ctx.AddVariationDependencies(nil, apiScope.stubsSourceTag, module.stubsSourceModuleName(apiScope))
943 ctx.AddVariationDependencies(nil, apiScope.apiFileTag, module.apiModuleName(apiScope))
Paul Duffina377e4c2020-04-29 13:30:54 +0100944 }
Sundong Ahn054b19a2018-10-19 13:46:09 +0900945 }
946
Paul Duffind11e78e2020-05-15 20:37:11 +0100947 if module.requiresRuntimeImplementationLibrary() {
Paul Duffin9d582cc2020-05-16 15:52:12 +0100948 // Add dependency to the rule for generating the implementation library.
949 ctx.AddDependency(module, implLibraryTag, module.implLibraryModuleName())
950
Paul Duffind11e78e2020-05-15 20:37:11 +0100951 if module.sharedLibrary() {
952 // Add dependency to the rule for generating the xml permissions file
953 ctx.AddDependency(module, xmlPermissionsFileTag, module.xmlFileName())
954 }
Paul Duffine74ac732020-02-06 13:51:46 +0000955
Paul Duffind11e78e2020-05-15 20:37:11 +0100956 // Only add the deps for the library if it is actually going to be built.
957 module.Library.deps(ctx)
958 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900959}
960
Paul Duffin46fdda82020-05-14 15:39:10 +0100961func (module *SdkLibrary) OutputFiles(tag string) (android.Paths, error) {
962 paths, err := module.commonOutputFiles(tag)
963 if paths == nil && err == nil {
964 return module.Library.OutputFiles(tag)
965 } else {
966 return paths, err
967 }
968}
969
Inseob Kimc0907f12019-02-08 21:00:45 +0900970func (module *SdkLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Paul Duffind11e78e2020-05-15 20:37:11 +0100971 // Only build an implementation library if required.
972 if module.requiresRuntimeImplementationLibrary() {
Paul Duffin43db9be2019-12-30 17:35:49 +0000973 module.Library.GenerateAndroidBuildActions(ctx)
974 }
Sundong Ahn054b19a2018-10-19 13:46:09 +0900975
Sundong Ahn57368eb2018-07-06 11:20:23 +0900976 // Record the paths to the header jars of the library (stubs and impl).
Paul Duffind1b3a922020-01-22 11:57:20 +0000977 // When this java_sdk_library is depended upon from others via "libs" property,
Jiyong Parkc678ad32018-04-10 13:07:10 +0900978 // the recorded paths will be returned depending on the link type of the caller.
979 ctx.VisitDirectDeps(func(to android.Module) {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900980 tag := ctx.OtherModuleDependencyTag(to)
981
Paul Duffin5fb82132020-04-29 20:45:27 +0100982 // Extract information from any of the scope specific dependencies.
983 if scopeTag, ok := tag.(scopeDependencyTag); ok {
984 apiScope := scopeTag.apiScope
Paul Duffin5ae30792020-05-20 11:52:25 +0100985 scopePaths := module.getScopePathsCreateIfNeeded(apiScope)
Paul Duffin5fb82132020-04-29 20:45:27 +0100986
987 // Extract information from the dependency. The exact information extracted
988 // is determined by the nature of the dependency which is determined by the tag.
989 scopeTag.extractDepInfo(ctx, to, scopePaths)
Sundong Ahn20e998b2018-07-24 11:19:26 +0900990 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900991 })
992}
993
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900994func (module *SdkLibrary) AndroidMkEntries() []android.AndroidMkEntries {
Paul Duffind11e78e2020-05-15 20:37:11 +0100995 if !module.requiresRuntimeImplementationLibrary() {
Paul Duffin43db9be2019-12-30 17:35:49 +0000996 return nil
997 }
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900998 entriesList := module.Library.AndroidMkEntries()
999 entries := &entriesList[0]
Jaewoong Jungb0c127c2019-08-29 14:56:03 -07001000 entries.Required = append(entries.Required, module.xmlFileName())
Jiyong Park0b0e1b92019-12-03 13:24:29 +09001001 return entriesList
Jiyong Park82484c02018-04-23 21:41:26 +09001002}
1003
Jiyong Parkc678ad32018-04-10 13:07:10 +09001004// Module name of the runtime implementation library
Paul Duffin9d582cc2020-05-16 15:52:12 +01001005func (module *SdkLibrary) implLibraryModuleName() string {
1006 return module.BaseModuleName() + ".impl"
Jiyong Parkc678ad32018-04-10 13:07:10 +09001007}
1008
Jiyong Parkc678ad32018-04-10 13:07:10 +09001009// Module name of the XML file for the lib
Inseob Kimc0907f12019-02-08 21:00:45 +09001010func (module *SdkLibrary) xmlFileName() string {
Jiyong Parkc678ad32018-04-10 13:07:10 +09001011 return module.BaseModuleName() + sdkXmlFileSuffix
1012}
1013
Anton Hansson6bb88102020-03-27 19:43:19 +00001014// The dist path of the stub artifacts
1015func (module *SdkLibrary) apiDistPath(apiScope *apiScope) string {
1016 if module.ModuleBase.Owner() != "" {
1017 return path.Join("apistubs", module.ModuleBase.Owner(), apiScope.name)
1018 } else if Bool(module.sdkLibraryProperties.Core_lib) {
1019 return path.Join("apistubs", "core", apiScope.name)
1020 } else {
1021 return path.Join("apistubs", "android", apiScope.name)
1022 }
1023}
1024
Paul Duffin12ceb462019-12-24 20:31:31 +00001025// Get the sdk version for use when compiling the stubs library.
Paul Duffin153501f2020-05-12 15:52:55 +01001026func (module *SdkLibrary) sdkVersionForStubsLibrary(mctx android.EarlyModuleContext, apiScope *apiScope) string {
Paul Duffin080f5ee2020-05-12 11:50:28 +01001027 scopeProperties := module.scopeToProperties[apiScope]
1028 if scopeProperties.Sdk_version != nil {
1029 return proptools.String(scopeProperties.Sdk_version)
1030 }
1031
Paul Duffin12ceb462019-12-24 20:31:31 +00001032 sdkDep := decodeSdkDep(mctx, sdkContext(&module.Library))
1033 if sdkDep.hasStandardLibs() {
1034 // If building against a standard sdk then use the sdk version appropriate for the scope.
Paul Duffind1b3a922020-01-22 11:57:20 +00001035 return apiScope.sdkVersion
Paul Duffin12ceb462019-12-24 20:31:31 +00001036 } else {
1037 // Otherwise, use no system module.
1038 return "none"
1039 }
1040}
1041
Paul Duffind1b3a922020-01-22 11:57:20 +00001042func (module *SdkLibrary) latestApiFilegroupName(apiScope *apiScope) string {
1043 return ":" + module.BaseModuleName() + ".api." + apiScope.name + ".latest"
Jiyong Park58c518b2018-05-12 22:29:12 +09001044}
Jiyong Parkc678ad32018-04-10 13:07:10 +09001045
Paul Duffind1b3a922020-01-22 11:57:20 +00001046func (module *SdkLibrary) latestRemovedApiFilegroupName(apiScope *apiScope) string {
1047 return ":" + module.BaseModuleName() + "-removed.api." + apiScope.name + ".latest"
Jiyong Parkc678ad32018-04-10 13:07:10 +09001048}
1049
Paul Duffin9d582cc2020-05-16 15:52:12 +01001050// Creates the implementation java library
1051func (module *SdkLibrary) createImplLibrary(mctx android.DefaultableHookContext) {
1052 props := struct {
1053 Name *string
1054 Visibility []string
1055 }{
1056 Name: proptools.StringPtr(module.implLibraryModuleName()),
1057 Visibility: module.sdkLibraryProperties.Impl_library_visibility,
1058 }
1059
1060 properties := []interface{}{
1061 &module.properties,
1062 &module.protoProperties,
1063 &module.deviceProperties,
1064 &module.dexpreoptProperties,
1065 &props,
1066 module.sdkComponentPropertiesForChildLibrary(),
1067 }
1068 mctx.CreateModule(LibraryFactory, properties...)
1069}
1070
Jiyong Parkc678ad32018-04-10 13:07:10 +09001071// Creates a static java library that has API stubs
Paul Duffin2aaef532020-04-29 16:47:28 +01001072func (module *SdkLibrary) createStubsLibrary(mctx android.DefaultableHookContext, apiScope *apiScope) {
Jiyong Parkc678ad32018-04-10 13:07:10 +09001073 props := struct {
Paul Duffind41712d2020-05-16 09:57:59 +01001074 Name *string
1075 Visibility []string
1076 Srcs []string
1077 Installable *bool
1078 Sdk_version *string
1079 System_modules *string
1080 Patch_module *string
1081 Libs []string
1082 Compile_dex *bool
1083 Java_version *string
1084 Product_variables struct {
Jiyong Park82484c02018-04-23 21:41:26 +09001085 Pdk struct {
1086 Enabled *bool
1087 }
Jiyong Parkc678ad32018-04-10 13:07:10 +09001088 }
Sundong Ahn054b19a2018-10-19 13:46:09 +09001089 Openjdk9 struct {
1090 Srcs []string
1091 Javacflags []string
1092 }
Anton Hansson6bb88102020-03-27 19:43:19 +00001093 Dist struct {
1094 Targets []string
1095 Dest *string
1096 Dir *string
1097 Tag *string
1098 }
Jiyong Parkc678ad32018-04-10 13:07:10 +09001099 }{}
1100
Paul Duffinb74ee3e2020-05-08 14:16:20 +01001101 props.Name = proptools.StringPtr(module.stubsLibraryModuleName(apiScope))
Paul Duffin344c4ee2020-04-29 23:35:13 +01001102
1103 // If stubs_library_visibility is not set then the created module will use the
1104 // visibility of this module.
1105 visibility := module.sdkLibraryProperties.Stubs_library_visibility
1106 props.Visibility = visibility
1107
Jiyong Parkc678ad32018-04-10 13:07:10 +09001108 // sources are generated from the droiddoc
Paul Duffinb74ee3e2020-05-08 14:16:20 +01001109 props.Srcs = []string{":" + module.stubsSourceModuleName(apiScope)}
Paul Duffin12ceb462019-12-24 20:31:31 +00001110 sdkVersion := module.sdkVersionForStubsLibrary(mctx, apiScope)
Paul Duffin52d398a2019-06-11 12:31:14 +01001111 props.Sdk_version = proptools.StringPtr(sdkVersion)
Paul Duffinc5d954a2020-05-16 18:54:24 +01001112 props.System_modules = module.deviceProperties.System_modules
1113 props.Patch_module = module.properties.Patch_module
Paul Duffin367ab912019-12-23 19:40:36 +00001114 props.Installable = proptools.BoolPtr(false)
Sundong Ahn054b19a2018-10-19 13:46:09 +09001115 props.Libs = module.sdkLibraryProperties.Stub_only_libs
Paul Duffin2ce1e812020-05-20 19:35:27 +01001116 // The stub-annotations library contains special versions of the annotations
1117 // with CLASS retention policy, so that they're kept.
1118 if proptools.Bool(module.sdkLibraryProperties.Annotations_enabled) {
1119 props.Libs = append(props.Libs, "stub-annotations")
1120 }
Jiyong Park82484c02018-04-23 21:41:26 +09001121 props.Product_variables.Pdk.Enabled = proptools.BoolPtr(false)
Paul Duffinc5d954a2020-05-16 18:54:24 +01001122 props.Openjdk9.Srcs = module.properties.Openjdk9.Srcs
1123 props.Openjdk9.Javacflags = module.properties.Openjdk9.Javacflags
Anton Hanssoncf4dd4c2020-05-21 09:21:57 +01001124 // We compile the stubs for 1.8 in line with the main android.jar stubs, and potential
1125 // interop with older developer tools that don't support 1.9.
1126 props.Java_version = proptools.StringPtr("1.8")
Paul Duffinc5d954a2020-05-16 18:54:24 +01001127 if module.deviceProperties.Compile_dex != nil {
1128 props.Compile_dex = module.deviceProperties.Compile_dex
Sundong Ahndd567f92018-07-31 17:19:11 +09001129 }
Jiyong Parkc678ad32018-04-10 13:07:10 +09001130
Anton Hansson6bb88102020-03-27 19:43:19 +00001131 // Dist the class jar artifact for sdk builds.
1132 if !Bool(module.sdkLibraryProperties.No_dist) {
1133 props.Dist.Targets = []string{"sdk", "win_sdk"}
1134 props.Dist.Dest = proptools.StringPtr(fmt.Sprintf("%v.jar", module.BaseModuleName()))
1135 props.Dist.Dir = proptools.StringPtr(module.apiDistPath(apiScope))
1136 props.Dist.Tag = proptools.StringPtr(".jar")
1137 }
Jiyong Parkc678ad32018-04-10 13:07:10 +09001138
Paul Duffin64e61992020-05-15 10:20:31 +01001139 mctx.CreateModule(LibraryFactory, &props, module.sdkComponentPropertiesForChildLibrary())
Jiyong Parkc678ad32018-04-10 13:07:10 +09001140}
1141
Paul Duffincbcfcaa2020-04-07 18:49:53 +01001142// Creates a droidstubs module that creates stubs source files from the given full source
Paul Duffin5fb82132020-04-29 20:45:27 +01001143// files and also updates and checks the API specification files.
Paul Duffina377e4c2020-04-29 13:30:54 +01001144func (module *SdkLibrary) createStubsSourcesAndApi(mctx android.DefaultableHookContext, apiScope *apiScope, name string, createStubSources, createApi bool, scopeSpecificDroidstubsArgs []string) {
Jiyong Parkc678ad32018-04-10 13:07:10 +09001145 props := struct {
Sundong Ahn054b19a2018-10-19 13:46:09 +09001146 Name *string
Paul Duffin344c4ee2020-04-29 23:35:13 +01001147 Visibility []string
Sundong Ahn054b19a2018-10-19 13:46:09 +09001148 Srcs []string
1149 Installable *bool
Paul Duffin52d398a2019-06-11 12:31:14 +01001150 Sdk_version *string
Paul Duffin12ceb462019-12-24 20:31:31 +00001151 System_modules *string
Sundong Ahn054b19a2018-10-19 13:46:09 +09001152 Libs []string
Paul Duffin11512472019-02-11 15:55:17 +00001153 Arg_files []string
Sundong Ahn054b19a2018-10-19 13:46:09 +09001154 Args *string
Sundong Ahn054b19a2018-10-19 13:46:09 +09001155 Java_version *string
Paul Duffin2ce1e812020-05-20 19:35:27 +01001156 Annotations_enabled *bool
Sundong Ahn054b19a2018-10-19 13:46:09 +09001157 Merge_annotations_dirs []string
1158 Merge_inclusion_annotations_dirs []string
Paul Duffina377e4c2020-04-29 13:30:54 +01001159 Generate_stubs *bool
Sundong Ahn054b19a2018-10-19 13:46:09 +09001160 Check_api struct {
Inseob Kim38449af2019-02-28 14:24:05 +09001161 Current ApiToCheck
1162 Last_released ApiToCheck
1163 Ignore_missing_latest_api *bool
Paul Duffin8986cc92020-05-10 19:32:20 +01001164
1165 Api_lint struct {
1166 Enabled *bool
1167 New_since *string
1168 Baseline_file *string
1169 }
Jiyong Park58c518b2018-05-12 22:29:12 +09001170 }
Sundong Ahn1b92c822018-05-29 11:35:17 +09001171 Aidl struct {
1172 Include_dirs []string
1173 Local_include_dirs []string
1174 }
Anton Hansson6bb88102020-03-27 19:43:19 +00001175 Dist struct {
1176 Targets []string
1177 Dest *string
1178 Dir *string
1179 }
Jiyong Parkc678ad32018-04-10 13:07:10 +09001180 }{}
1181
Paul Duffinda364252020-04-28 14:08:32 +01001182 // The stubs source processing uses the same compile time classpath when extracting the
1183 // API from the implementation library as it does when compiling it. i.e. the same
1184 // * sdk version
1185 // * system_modules
1186 // * libs (static_libs/libs)
Paul Duffin250e6192019-06-07 10:44:37 +01001187
Paul Duffina377e4c2020-04-29 13:30:54 +01001188 props.Name = proptools.StringPtr(name)
Paul Duffin344c4ee2020-04-29 23:35:13 +01001189
1190 // If stubs_source_visibility is not set then the created module will use the
1191 // visibility of this module.
1192 visibility := module.sdkLibraryProperties.Stubs_source_visibility
1193 props.Visibility = visibility
1194
Paul Duffinc5d954a2020-05-16 18:54:24 +01001195 props.Srcs = append(props.Srcs, module.properties.Srcs...)
1196 props.Sdk_version = module.deviceProperties.Sdk_version
1197 props.System_modules = module.deviceProperties.System_modules
Jiyong Parkc678ad32018-04-10 13:07:10 +09001198 props.Installable = proptools.BoolPtr(false)
Sundong Ahne6f0b052018-06-05 16:46:14 +09001199 // A droiddoc module has only one Libs property and doesn't distinguish between
1200 // shared libs and static libs. So we need to add both of these libs to Libs property.
Paul Duffinc5d954a2020-05-16 18:54:24 +01001201 props.Libs = module.properties.Libs
1202 props.Libs = append(props.Libs, module.properties.Static_libs...)
1203 props.Aidl.Include_dirs = module.deviceProperties.Aidl.Include_dirs
1204 props.Aidl.Local_include_dirs = module.deviceProperties.Aidl.Local_include_dirs
1205 props.Java_version = module.properties.Java_version
Jiyong Parkc678ad32018-04-10 13:07:10 +09001206
Paul Duffin2ce1e812020-05-20 19:35:27 +01001207 props.Annotations_enabled = module.sdkLibraryProperties.Annotations_enabled
Sundong Ahn054b19a2018-10-19 13:46:09 +09001208 props.Merge_annotations_dirs = module.sdkLibraryProperties.Merge_annotations_dirs
1209 props.Merge_inclusion_annotations_dirs = module.sdkLibraryProperties.Merge_inclusion_annotations_dirs
1210
Paul Duffincbcfcaa2020-04-07 18:49:53 +01001211 droidstubsArgs := []string{}
Paul Duffin235ffff2019-12-24 10:41:30 +00001212 if len(module.sdkLibraryProperties.Api_packages) != 0 {
Paul Duffincbcfcaa2020-04-07 18:49:53 +01001213 droidstubsArgs = append(droidstubsArgs, "--stub-packages "+strings.Join(module.sdkLibraryProperties.Api_packages, ":"))
Paul Duffin235ffff2019-12-24 10:41:30 +00001214 }
1215 if len(module.sdkLibraryProperties.Hidden_api_packages) != 0 {
Paul Duffincbcfcaa2020-04-07 18:49:53 +01001216 droidstubsArgs = append(droidstubsArgs,
Paul Duffin235ffff2019-12-24 10:41:30 +00001217 android.JoinWithPrefix(module.sdkLibraryProperties.Hidden_api_packages, " --hide-package "))
1218 }
Paul Duffincbcfcaa2020-04-07 18:49:53 +01001219 droidstubsArgs = append(droidstubsArgs, module.sdkLibraryProperties.Droiddoc_options...)
Paul Duffin235ffff2019-12-24 10:41:30 +00001220 disabledWarnings := []string{
1221 "MissingPermission",
1222 "BroadcastBehavior",
1223 "HiddenSuperclass",
1224 "DeprecationMismatch",
1225 "UnavailableSymbol",
1226 "SdkConstant",
1227 "HiddenTypeParameter",
1228 "Todo",
1229 "Typo",
1230 }
Paul Duffincbcfcaa2020-04-07 18:49:53 +01001231 droidstubsArgs = append(droidstubsArgs, android.JoinWithPrefix(disabledWarnings, "--hide "))
Sundong Ahnfb2721f2018-09-17 13:23:09 +09001232
Paul Duffina377e4c2020-04-29 13:30:54 +01001233 if !createStubSources {
1234 // Stubs are not required.
1235 props.Generate_stubs = proptools.BoolPtr(false)
1236 }
1237
Paul Duffin3c7c3472020-04-07 18:50:10 +01001238 // Add in scope specific arguments.
Paul Duffina377e4c2020-04-29 13:30:54 +01001239 droidstubsArgs = append(droidstubsArgs, scopeSpecificDroidstubsArgs...)
Paul Duffin11512472019-02-11 15:55:17 +00001240 props.Arg_files = module.sdkLibraryProperties.Droiddoc_option_files
Paul Duffincbcfcaa2020-04-07 18:49:53 +01001241 props.Args = proptools.StringPtr(strings.Join(droidstubsArgs, " "))
Jiyong Parkc678ad32018-04-10 13:07:10 +09001242
Paul Duffina377e4c2020-04-29 13:30:54 +01001243 if createApi {
1244 // List of APIs identified from the provided source files are created. They are later
1245 // compared against to the not-yet-released (a.k.a current) list of APIs and to the
1246 // last-released (a.k.a numbered) list of API.
1247 currentApiFileName := apiScope.apiFilePrefix + "current.txt"
1248 removedApiFileName := apiScope.apiFilePrefix + "removed.txt"
1249 apiDir := module.getApiDir()
1250 currentApiFileName = path.Join(apiDir, currentApiFileName)
1251 removedApiFileName = path.Join(apiDir, removedApiFileName)
Jiyong Parkc678ad32018-04-10 13:07:10 +09001252
Paul Duffina377e4c2020-04-29 13:30:54 +01001253 // check against the not-yet-release API
1254 props.Check_api.Current.Api_file = proptools.StringPtr(currentApiFileName)
1255 props.Check_api.Current.Removed_api_file = proptools.StringPtr(removedApiFileName)
Jiyong Park58c518b2018-05-12 22:29:12 +09001256
Paul Duffina377e4c2020-04-29 13:30:54 +01001257 if !apiScope.unstable {
1258 // check against the latest released API
1259 latestApiFilegroupName := proptools.StringPtr(module.latestApiFilegroupName(apiScope))
1260 props.Check_api.Last_released.Api_file = latestApiFilegroupName
1261 props.Check_api.Last_released.Removed_api_file = proptools.StringPtr(
1262 module.latestRemovedApiFilegroupName(apiScope))
1263 props.Check_api.Ignore_missing_latest_api = proptools.BoolPtr(true)
Paul Duffin8986cc92020-05-10 19:32:20 +01001264
Paul Duffina377e4c2020-04-29 13:30:54 +01001265 if proptools.Bool(module.sdkLibraryProperties.Api_lint.Enabled) {
1266 // Enable api lint.
1267 props.Check_api.Api_lint.Enabled = proptools.BoolPtr(true)
1268 props.Check_api.Api_lint.New_since = latestApiFilegroupName
Paul Duffin8986cc92020-05-10 19:32:20 +01001269
Paul Duffina377e4c2020-04-29 13:30:54 +01001270 // If it exists then pass a lint-baseline.txt through to droidstubs.
1271 baselinePath := path.Join(apiDir, apiScope.apiFilePrefix+"lint-baseline.txt")
1272 baselinePathRelativeToRoot := path.Join(mctx.ModuleDir(), baselinePath)
1273 paths, err := mctx.GlobWithDeps(baselinePathRelativeToRoot, nil)
1274 if err != nil {
1275 mctx.ModuleErrorf("error checking for presence of %s: %s", baselinePathRelativeToRoot, err)
1276 }
1277 if len(paths) == 1 {
1278 props.Check_api.Api_lint.Baseline_file = proptools.StringPtr(baselinePath)
1279 } else if len(paths) != 0 {
1280 mctx.ModuleErrorf("error checking for presence of %s: expected one path, found: %v", baselinePathRelativeToRoot, paths)
1281 }
Paul Duffin8986cc92020-05-10 19:32:20 +01001282 }
1283 }
Jiyong Park58c518b2018-05-12 22:29:12 +09001284
Paul Duffina377e4c2020-04-29 13:30:54 +01001285 // Dist the api txt artifact for sdk builds.
1286 if !Bool(module.sdkLibraryProperties.No_dist) {
1287 props.Dist.Targets = []string{"sdk", "win_sdk"}
1288 props.Dist.Dest = proptools.StringPtr(fmt.Sprintf("%v.txt", module.BaseModuleName()))
1289 props.Dist.Dir = proptools.StringPtr(path.Join(module.apiDistPath(apiScope), "api"))
1290 }
Anton Hansson6bb88102020-03-27 19:43:19 +00001291 }
1292
Colin Cross84dfc3d2019-09-25 11:33:01 -07001293 mctx.CreateModule(DroidstubsFactory, &props)
Jiyong Parkc678ad32018-04-10 13:07:10 +09001294}
1295
Jooyung Hanb8fa86a2020-03-10 06:23:13 +09001296func (module *SdkLibrary) DepIsInSameApex(mctx android.BaseModuleContext, dep android.Module) bool {
1297 depTag := mctx.OtherModuleDependencyTag(dep)
1298 if depTag == xmlPermissionsFileTag {
1299 return true
1300 }
1301 return module.Library.DepIsInSameApex(mctx, dep)
1302}
1303
Jiyong Parkc678ad32018-04-10 13:07:10 +09001304// Creates the xml file that publicizes the runtime library
Paul Duffin2aaef532020-04-29 16:47:28 +01001305func (module *SdkLibrary) createXmlFile(mctx android.DefaultableHookContext) {
Jiyong Parke3833882020-02-17 17:28:10 +09001306 props := struct {
Paul Duffind41712d2020-05-16 09:57:59 +01001307 Name *string
1308 Lib_name *string
1309 Apex_available []string
Jiyong Parke3833882020-02-17 17:28:10 +09001310 }{
Jooyung Hanb8fa86a2020-03-10 06:23:13 +09001311 Name: proptools.StringPtr(module.xmlFileName()),
1312 Lib_name: proptools.StringPtr(module.BaseModuleName()),
1313 Apex_available: module.ApexProperties.Apex_available,
Jiyong Parkc678ad32018-04-10 13:07:10 +09001314 }
Jiyong Parke3833882020-02-17 17:28:10 +09001315
Jiyong Parke3833882020-02-17 17:28:10 +09001316 mctx.CreateModule(sdkLibraryXmlFactory, &props)
Jiyong Parkc678ad32018-04-10 13:07:10 +09001317}
1318
Paul Duffin50061512020-01-21 16:31:05 +00001319func PrebuiltJars(ctx android.BaseModuleContext, baseName string, s sdkSpec) android.Paths {
Jiyong Park6a927c42020-01-21 02:03:43 +09001320 var ver sdkVersion
1321 var kind sdkKind
1322 if s.usePrebuilt(ctx) {
1323 ver = s.version
1324 kind = s.kind
Jiyong Parkc678ad32018-04-10 13:07:10 +09001325 } else {
Jiyong Park6a927c42020-01-21 02:03:43 +09001326 // We don't have prebuilt SDK for the specific sdkVersion.
1327 // Instead of breaking the build, fallback to use "system_current"
1328 ver = sdkVersionCurrent
1329 kind = sdkSystem
Sundong Ahn054b19a2018-10-19 13:46:09 +09001330 }
Jiyong Park6a927c42020-01-21 02:03:43 +09001331
1332 dir := filepath.Join("prebuilts", "sdk", ver.String(), kind.String())
Paul Duffin50061512020-01-21 16:31:05 +00001333 jar := filepath.Join(dir, baseName+".jar")
Sundong Ahn054b19a2018-10-19 13:46:09 +09001334 jarPath := android.ExistentPathForSource(ctx, jar)
Sundong Ahnae418ac2019-02-28 15:01:28 +09001335 if !jarPath.Valid() {
Colin Cross07c88562020-01-07 09:34:44 -08001336 if ctx.Config().AllowMissingDependencies() {
1337 return android.Paths{android.PathForSource(ctx, jar)}
1338 } else {
Jiyong Park6a927c42020-01-21 02:03:43 +09001339 ctx.PropertyErrorf("sdk_library", "invalid sdk version %q, %q does not exist", s.raw, jar)
Colin Cross07c88562020-01-07 09:34:44 -08001340 }
Sundong Ahnae418ac2019-02-28 15:01:28 +09001341 return nil
1342 }
Sundong Ahn054b19a2018-10-19 13:46:09 +09001343 return android.Paths{jarPath.Path()}
1344}
1345
Paul Duffinbf19a972020-05-26 13:21:35 +01001346// Get the apex name for module, "" if it is for platform.
1347func getApexNameForModule(module android.Module) string {
1348 if apex, ok := module.(android.ApexModule); ok {
1349 return apex.ApexName()
1350 }
1351
1352 return ""
1353}
1354
1355// Check to see if the other module is within the same named APEX as this module.
1356//
1357// If either this or the other module are on the platform then this will return
1358// false.
1359func (module *SdkLibrary) withinSameApexAs(other android.Module) bool {
1360 name := module.ApexName()
1361 return name != "" && getApexNameForModule(other) == name
1362}
1363
Paul Duffin47624362020-05-20 12:19:10 +01001364func (module *SdkLibrary) sdkJars(ctx android.BaseModuleContext, sdkVersion sdkSpec, headerJars bool) android.Paths {
Jiyong Park27fc4142020-05-28 00:19:53 +09001365 // If the client doesn't set sdk_version, but if this library prefers stubs over
1366 // the impl library, let's provide the widest API surface possible. To do so,
1367 // force override sdk_version to module_current so that the closest possible API
1368 // surface could be found in selectHeaderJarsForSdkVersion
1369 if module.defaultsToStubs() && !sdkVersion.specified() {
1370 sdkVersion = sdkSpecFrom("module_current")
1371 }
Paul Duffind1b3a922020-01-22 11:57:20 +00001372
Paul Duffin2e7ed652020-05-26 18:13:57 +01001373 // Only provide access to the implementation library if it is actually built.
1374 if module.requiresRuntimeImplementationLibrary() {
1375 // Check any special cases for java_sdk_library.
1376 //
1377 // Only allow access to the implementation library in the following condition:
1378 // * No sdk_version specified on the referencing module.
Paul Duffinbf19a972020-05-26 13:21:35 +01001379 // * The referencing module is in the same apex as this.
1380 if sdkVersion.kind == sdkPrivate || module.withinSameApexAs(ctx.Module()) {
Paul Duffin2e7ed652020-05-26 18:13:57 +01001381 if headerJars {
1382 return module.HeaderJars()
1383 } else {
1384 return module.ImplementationJars()
1385 }
Sundong Ahn054b19a2018-10-19 13:46:09 +09001386 }
Jiyong Parkc678ad32018-04-10 13:07:10 +09001387 }
Paul Duffin47624362020-05-20 12:19:10 +01001388
Paul Duffina3fb67d2020-05-20 14:20:02 +01001389 return module.selectHeaderJarsForSdkVersion(ctx, sdkVersion)
Jiyong Parkc678ad32018-04-10 13:07:10 +09001390}
1391
Sundong Ahn241cd372018-07-13 16:16:44 +09001392// to satisfy SdkLibraryDependency interface
Paul Duffind1b3a922020-01-22 11:57:20 +00001393func (module *SdkLibrary) SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths {
1394 return module.sdkJars(ctx, sdkVersion, true /*headerJars*/)
1395}
1396
1397// to satisfy SdkLibraryDependency interface
Jiyong Park6a927c42020-01-21 02:03:43 +09001398func (module *SdkLibrary) SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths {
Paul Duffind1b3a922020-01-22 11:57:20 +00001399 return module.sdkJars(ctx, sdkVersion, false /*headerJars*/)
Sundong Ahn241cd372018-07-13 16:16:44 +09001400}
1401
Sundong Ahn80a87b32019-05-13 15:02:50 +09001402func (module *SdkLibrary) SetNoDist() {
1403 module.sdkLibraryProperties.No_dist = proptools.BoolPtr(true)
1404}
1405
Colin Cross571cccf2019-02-04 11:22:08 -08001406var javaSdkLibrariesKey = android.NewOnceKey("javaSdkLibraries")
1407
Jiyong Park82484c02018-04-23 21:41:26 +09001408func javaSdkLibraries(config android.Config) *[]string {
Colin Cross571cccf2019-02-04 11:22:08 -08001409 return config.Once(javaSdkLibrariesKey, func() interface{} {
Jiyong Park82484c02018-04-23 21:41:26 +09001410 return &[]string{}
1411 }).(*[]string)
1412}
1413
Paul Duffin749f98f2019-12-30 17:23:46 +00001414func (module *SdkLibrary) getApiDir() string {
1415 return proptools.StringDefault(module.sdkLibraryProperties.Api_dir, "api")
1416}
1417
Jiyong Parkc678ad32018-04-10 13:07:10 +09001418// For a java_sdk_library module, create internal modules for stubs, docs,
1419// runtime libs and xml file. If requested, the stubs and docs are created twice
1420// once for public API level and once for system API level
Paul Duffin2aaef532020-04-29 16:47:28 +01001421func (module *SdkLibrary) CreateInternalModules(mctx android.DefaultableHookContext) {
1422 // If the module has been disabled then don't create any child modules.
1423 if !module.Enabled() {
1424 return
1425 }
1426
Paul Duffinc5d954a2020-05-16 18:54:24 +01001427 if len(module.properties.Srcs) == 0 {
Inseob Kimc0907f12019-02-08 21:00:45 +09001428 mctx.PropertyErrorf("srcs", "java_sdk_library must specify srcs")
Jooyung Han58f26ab2019-12-18 15:34:32 +09001429 return
Inseob Kimc0907f12019-02-08 21:00:45 +09001430 }
1431
Paul Duffin37e0b772019-12-30 17:20:10 +00001432 // If this builds against standard libraries (i.e. is not part of the core libraries)
1433 // then assume it provides both system and test apis. Otherwise, assume it does not and
1434 // also assume it does not contribute to the dist build.
1435 sdkDep := decodeSdkDep(mctx, sdkContext(&module.Library))
1436 hasSystemAndTestApis := sdkDep.hasStandardLibs()
Paul Duffin3a254982020-04-28 10:44:03 +01001437 module.sdkLibraryProperties.Generate_system_and_test_apis = hasSystemAndTestApis
Paul Duffin37e0b772019-12-30 17:20:10 +00001438 module.sdkLibraryProperties.No_dist = proptools.BoolPtr(!hasSystemAndTestApis)
1439
Inseob Kim8098faa2019-03-18 10:19:51 +09001440 missing_current_api := false
1441
Paul Duffin3a254982020-04-28 10:44:03 +01001442 generatedScopes := module.getGeneratedApiScopes(mctx)
Paul Duffind1b3a922020-01-22 11:57:20 +00001443
Paul Duffin749f98f2019-12-30 17:23:46 +00001444 apiDir := module.getApiDir()
Paul Duffin3a254982020-04-28 10:44:03 +01001445 for _, scope := range generatedScopes {
Inseob Kim8098faa2019-03-18 10:19:51 +09001446 for _, api := range []string{"current.txt", "removed.txt"} {
Paul Duffind1b3a922020-01-22 11:57:20 +00001447 path := path.Join(mctx.ModuleDir(), apiDir, scope.apiFilePrefix+api)
Inseob Kim8098faa2019-03-18 10:19:51 +09001448 p := android.ExistentPathForSource(mctx, path)
1449 if !p.Valid() {
1450 mctx.ModuleErrorf("Current api file %#v doesn't exist", path)
1451 missing_current_api = true
1452 }
1453 }
1454 }
1455
1456 if missing_current_api {
1457 script := "build/soong/scripts/gen-java-current-api-files.sh"
1458 p := android.ExistentPathForSource(mctx, script)
1459
1460 if !p.Valid() {
1461 panic(fmt.Sprintf("script file %s doesn't exist", script))
1462 }
1463
1464 mctx.ModuleErrorf("One or more current api files are missing. "+
1465 "You can update them by:\n"+
Paul Duffin37e0b772019-12-30 17:20:10 +00001466 "%s %q %s && m update-api",
Paul Duffind1b3a922020-01-22 11:57:20 +00001467 script, filepath.Join(mctx.ModuleDir(), apiDir),
Paul Duffin3a254982020-04-28 10:44:03 +01001468 strings.Join(generatedScopes.Strings(func(s *apiScope) string { return s.apiFilePrefix }), " "))
Inseob Kim8098faa2019-03-18 10:19:51 +09001469 return
1470 }
1471
Paul Duffin3a254982020-04-28 10:44:03 +01001472 for _, scope := range generatedScopes {
Paul Duffina377e4c2020-04-29 13:30:54 +01001473 stubsSourceArgs := scope.droidstubsArgsForGeneratingStubsSource
Paul Duffinb74ee3e2020-05-08 14:16:20 +01001474 stubsSourceModuleName := module.stubsSourceModuleName(scope)
Paul Duffina377e4c2020-04-29 13:30:54 +01001475
1476 // If the args needed to generate the stubs and API are the same then they
1477 // can be generated in a single invocation of metalava, otherwise they will
1478 // need separate invocations.
1479 if scope.createStubsSourceAndApiTogether {
1480 // Use the stubs source name for legacy reasons.
1481 module.createStubsSourcesAndApi(mctx, scope, stubsSourceModuleName, true, true, stubsSourceArgs)
1482 } else {
1483 module.createStubsSourcesAndApi(mctx, scope, stubsSourceModuleName, true, false, stubsSourceArgs)
1484
1485 apiArgs := scope.droidstubsArgsForGeneratingApi
Paul Duffinb74ee3e2020-05-08 14:16:20 +01001486 apiName := module.apiModuleName(scope)
Paul Duffina377e4c2020-04-29 13:30:54 +01001487 module.createStubsSourcesAndApi(mctx, scope, apiName, false, true, apiArgs)
1488 }
1489
Paul Duffind1b3a922020-01-22 11:57:20 +00001490 module.createStubsLibrary(mctx, scope)
Inseob Kimc0907f12019-02-08 21:00:45 +09001491 }
1492
Paul Duffind11e78e2020-05-15 20:37:11 +01001493 if module.requiresRuntimeImplementationLibrary() {
Paul Duffin9d582cc2020-05-16 15:52:12 +01001494 // Create child module to create an implementation library.
1495 //
1496 // This temporarily creates a second implementation library that can be explicitly
1497 // referenced.
1498 //
1499 // TODO(b/156618935) - update comment once only one implementation library is created.
1500 module.createImplLibrary(mctx)
1501
Paul Duffind11e78e2020-05-15 20:37:11 +01001502 // Only create an XML permissions file that declares the library as being usable
1503 // as a shared library if required.
1504 if module.sharedLibrary() {
1505 module.createXmlFile(mctx)
1506 }
Paul Duffin43db9be2019-12-30 17:35:49 +00001507
1508 // record java_sdk_library modules so that they are exported to make
1509 javaSdkLibraries := javaSdkLibraries(mctx.Config())
1510 javaSdkLibrariesLock.Lock()
1511 defer javaSdkLibrariesLock.Unlock()
1512 *javaSdkLibraries = append(*javaSdkLibraries, module.BaseModuleName())
1513 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001514}
1515
1516func (module *SdkLibrary) InitSdkLibraryProperties() {
Sundong Ahn054b19a2018-10-19 13:46:09 +09001517 module.AddProperties(
1518 &module.sdkLibraryProperties,
Paul Duffinc5d954a2020-05-16 18:54:24 +01001519 &module.properties,
1520 &module.dexpreoptProperties,
1521 &module.deviceProperties,
1522 &module.protoProperties,
Sundong Ahn054b19a2018-10-19 13:46:09 +09001523 )
1524
Paul Duffin64e61992020-05-15 10:20:31 +01001525 module.initSdkLibraryComponent(&module.ModuleBase)
1526
Paul Duffinc5d954a2020-05-16 18:54:24 +01001527 module.properties.Installable = proptools.BoolPtr(true)
1528 module.deviceProperties.IsSDKLibrary = true
Inseob Kimc0907f12019-02-08 21:00:45 +09001529}
Sundong Ahn054b19a2018-10-19 13:46:09 +09001530
Paul Duffind11e78e2020-05-15 20:37:11 +01001531func (module *SdkLibrary) requiresRuntimeImplementationLibrary() bool {
1532 return !proptools.Bool(module.sdkLibraryProperties.Api_only)
1533}
1534
Jiyong Park27fc4142020-05-28 00:19:53 +09001535func (module *SdkLibrary) defaultsToStubs() bool {
1536 return proptools.Bool(module.sdkLibraryProperties.Default_to_stubs)
1537}
1538
Paul Duffin1a724e62020-05-08 13:44:43 +01001539// Defines how to name the individual component modules the sdk library creates.
1540type sdkLibraryComponentNamingScheme interface {
1541 stubsLibraryModuleName(scope *apiScope, baseName string) string
1542
1543 stubsSourceModuleName(scope *apiScope, baseName string) string
1544
1545 apiModuleName(scope *apiScope, baseName string) string
1546}
1547
1548type defaultNamingScheme struct {
1549}
1550
1551func (s *defaultNamingScheme) stubsLibraryModuleName(scope *apiScope, baseName string) string {
1552 return scope.stubsLibraryModuleName(baseName)
1553}
1554
1555func (s *defaultNamingScheme) stubsSourceModuleName(scope *apiScope, baseName string) string {
1556 return scope.stubsSourceModuleName(baseName)
1557}
1558
1559func (s *defaultNamingScheme) apiModuleName(scope *apiScope, baseName string) string {
1560 return scope.apiModuleName(baseName)
1561}
1562
1563var _ sdkLibraryComponentNamingScheme = (*defaultNamingScheme)(nil)
1564
Paul Duffindef8a892020-05-08 15:36:30 +01001565type frameworkModulesNamingScheme struct {
1566}
1567
1568func (s *frameworkModulesNamingScheme) moduleSuffix(scope *apiScope) string {
1569 suffix := scope.name
1570 if scope == apiScopeModuleLib {
1571 suffix = "module_libs_"
1572 }
1573 return suffix
1574}
1575
1576func (s *frameworkModulesNamingScheme) stubsLibraryModuleName(scope *apiScope, baseName string) string {
1577 return fmt.Sprintf("%s-stubs-%sapi", baseName, s.moduleSuffix(scope))
1578}
1579
1580func (s *frameworkModulesNamingScheme) stubsSourceModuleName(scope *apiScope, baseName string) string {
1581 return fmt.Sprintf("%s-stubs-srcs-%sapi", baseName, s.moduleSuffix(scope))
1582}
1583
1584func (s *frameworkModulesNamingScheme) apiModuleName(scope *apiScope, baseName string) string {
1585 return fmt.Sprintf("%s-api-%sapi", baseName, s.moduleSuffix(scope))
1586}
1587
1588var _ sdkLibraryComponentNamingScheme = (*frameworkModulesNamingScheme)(nil)
1589
Anton Hansson0bd88d02020-05-25 12:20:51 +01001590func moduleStubLinkType(name string) (stub bool, ret linkType) {
1591 // This suffix-based approach is fragile and could potentially mis-trigger.
1592 // TODO(b/155164730): Clean this up when modules no longer reference sdk_lib stubs directly.
1593 if strings.HasSuffix(name, ".stubs.public") || strings.HasSuffix(name, "-stubs-publicapi") {
1594 return true, javaSdk
1595 }
1596 if strings.HasSuffix(name, ".stubs.system") || strings.HasSuffix(name, "-stubs-systemapi") {
1597 return true, javaSystem
1598 }
1599 if strings.HasSuffix(name, ".stubs.module_lib") || strings.HasSuffix(name, "-stubs-module_libs_api") {
1600 return true, javaModule
1601 }
1602 if strings.HasSuffix(name, ".stubs.test") {
1603 return true, javaSystem
1604 }
1605 return false, javaPlatform
1606}
1607
Jaewoong Jung4f158ee2019-07-11 10:05:35 -07001608// java_sdk_library is a special Java library that provides optional platform APIs to apps.
1609// In practice, it can be viewed as a combination of several modules: 1) stubs library that clients
1610// are linked against to, 2) droiddoc module that internally generates API stubs source files,
1611// 3) the real runtime shared library that implements the APIs, and 4) XML file for adding
1612// the runtime lib to the classpath at runtime if requested via <uses-library>.
Inseob Kimc0907f12019-02-08 21:00:45 +09001613func SdkLibraryFactory() android.Module {
1614 module := &SdkLibrary{}
Paul Duffinb74ee3e2020-05-08 14:16:20 +01001615
1616 // Initialize information common between source and prebuilt.
1617 module.initCommon(&module.ModuleBase)
1618
Inseob Kimc0907f12019-02-08 21:00:45 +09001619 module.InitSdkLibraryProperties()
Jooyung Han58f26ab2019-12-18 15:34:32 +09001620 android.InitApexModule(module)
Sundong Ahn054b19a2018-10-19 13:46:09 +09001621 InitJavaModule(module, android.HostAndDeviceSupported)
Paul Duffin3a254982020-04-28 10:44:03 +01001622
1623 // Initialize the map from scope to scope specific properties.
1624 scopeToProperties := make(map[*apiScope]*ApiScopeProperties)
1625 for _, scope := range allApiScopes {
1626 scopeToProperties[scope] = scope.scopeSpecificProperties(module)
1627 }
1628 module.scopeToProperties = scopeToProperties
1629
Paul Duffin344c4ee2020-04-29 23:35:13 +01001630 // Add the properties containing visibility rules so that they are checked.
Paul Duffin9d582cc2020-05-16 15:52:12 +01001631 android.AddVisibilityProperty(module, "impl_library_visibility", &module.sdkLibraryProperties.Impl_library_visibility)
Paul Duffin344c4ee2020-04-29 23:35:13 +01001632 android.AddVisibilityProperty(module, "stubs_library_visibility", &module.sdkLibraryProperties.Stubs_library_visibility)
1633 android.AddVisibilityProperty(module, "stubs_source_visibility", &module.sdkLibraryProperties.Stubs_source_visibility)
1634
Paul Duffin1a724e62020-05-08 13:44:43 +01001635 module.SetDefaultableHook(func(ctx android.DefaultableHookContext) {
Paul Duffind11e78e2020-05-15 20:37:11 +01001636 // If no implementation is required then it cannot be used as a shared library
1637 // either.
1638 if !module.requiresRuntimeImplementationLibrary() {
1639 // If shared_library has been explicitly set to true then it is incompatible
1640 // with api_only: true.
1641 if proptools.Bool(module.commonSdkLibraryProperties.Shared_library) {
1642 ctx.PropertyErrorf("api_only/shared_library", "inconsistent settings, shared_library and api_only cannot both be true")
1643 }
1644 // Set shared_library: false.
1645 module.commonSdkLibraryProperties.Shared_library = proptools.BoolPtr(false)
1646 }
1647
Paul Duffin1a724e62020-05-08 13:44:43 +01001648 if module.initCommonAfterDefaultsApplied(ctx) {
1649 module.CreateInternalModules(ctx)
1650 }
1651 })
Jiyong Parkc678ad32018-04-10 13:07:10 +09001652 return module
1653}
Colin Cross79c7c262019-04-17 11:11:46 -07001654
1655//
1656// SDK library prebuilts
1657//
1658
Paul Duffin56d44902020-01-31 13:36:25 +00001659// Properties associated with each api scope.
1660type sdkLibraryScopeProperties struct {
Colin Cross79c7c262019-04-17 11:11:46 -07001661 Jars []string `android:"path"`
1662
1663 Sdk_version *string
1664
Colin Cross79c7c262019-04-17 11:11:46 -07001665 // List of shared java libs that this module has dependencies to
1666 Libs []string
Paul Duffinf488ef22020-04-09 00:10:17 +01001667
Paul Duffin5fb82132020-04-29 20:45:27 +01001668 // The stubs source.
Paul Duffinf488ef22020-04-09 00:10:17 +01001669 Stub_srcs []string `android:"path"`
Paul Duffin75dcc802020-04-09 01:08:11 +01001670
1671 // The current.txt
Paul Duffin533f9c72020-05-20 16:18:00 +01001672 Current_api *string `android:"path"`
Paul Duffin75dcc802020-04-09 01:08:11 +01001673
1674 // The removed.txt
Paul Duffin533f9c72020-05-20 16:18:00 +01001675 Removed_api *string `android:"path"`
Colin Cross79c7c262019-04-17 11:11:46 -07001676}
1677
Paul Duffin56d44902020-01-31 13:36:25 +00001678type sdkLibraryImportProperties struct {
Paul Duffinfcfd7912020-01-31 17:54:30 +00001679 // List of shared java libs, common to all scopes, that this module has
1680 // dependencies to
1681 Libs []string
Paul Duffin56d44902020-01-31 13:36:25 +00001682}
1683
Colin Cross79c7c262019-04-17 11:11:46 -07001684type sdkLibraryImport struct {
1685 android.ModuleBase
1686 android.DefaultableModuleBase
1687 prebuilt android.Prebuilt
Paul Duffin61871622020-02-10 13:37:10 +00001688 android.ApexModuleBase
1689 android.SdkBase
Colin Cross79c7c262019-04-17 11:11:46 -07001690
1691 properties sdkLibraryImportProperties
1692
Paul Duffin6a2bd112020-04-07 19:27:04 +01001693 // Map from api scope to the scope specific property structure.
1694 scopeProperties map[*apiScope]*sdkLibraryScopeProperties
1695
Paul Duffin56d44902020-01-31 13:36:25 +00001696 commonToSdkLibraryAndImport
Colin Cross79c7c262019-04-17 11:11:46 -07001697}
1698
1699var _ SdkLibraryDependency = (*sdkLibraryImport)(nil)
1700
Paul Duffin6a2bd112020-04-07 19:27:04 +01001701// The type of a structure that contains a field of type sdkLibraryScopeProperties
1702// for each apiscope in allApiScopes, e.g. something like:
1703// struct {
1704// Public sdkLibraryScopeProperties
1705// System sdkLibraryScopeProperties
1706// ...
1707// }
1708var allScopeStructType = createAllScopePropertiesStructType()
1709
1710// Dynamically create a structure type for each apiscope in allApiScopes.
1711func createAllScopePropertiesStructType() reflect.Type {
1712 var fields []reflect.StructField
1713 for _, apiScope := range allApiScopes {
1714 field := reflect.StructField{
1715 Name: apiScope.fieldName,
1716 Type: reflect.TypeOf(sdkLibraryScopeProperties{}),
1717 }
1718 fields = append(fields, field)
1719 }
1720
1721 return reflect.StructOf(fields)
1722}
1723
1724// Create an instance of the scope specific structure type and return a map
1725// from apiscope to a pointer to each scope specific field.
1726func createPropertiesInstance() (interface{}, map[*apiScope]*sdkLibraryScopeProperties) {
1727 allScopePropertiesPtr := reflect.New(allScopeStructType)
1728 allScopePropertiesStruct := allScopePropertiesPtr.Elem()
1729 scopeProperties := make(map[*apiScope]*sdkLibraryScopeProperties)
1730
1731 for _, apiScope := range allApiScopes {
1732 field := allScopePropertiesStruct.FieldByName(apiScope.fieldName)
1733 scopeProperties[apiScope] = field.Addr().Interface().(*sdkLibraryScopeProperties)
1734 }
1735
1736 return allScopePropertiesPtr.Interface(), scopeProperties
1737}
1738
Jaewoong Jung4f158ee2019-07-11 10:05:35 -07001739// java_sdk_library_import imports a prebuilt java_sdk_library.
Colin Cross79c7c262019-04-17 11:11:46 -07001740func sdkLibraryImportFactory() android.Module {
1741 module := &sdkLibraryImport{}
1742
Paul Duffin6a2bd112020-04-07 19:27:04 +01001743 allScopeProperties, scopeToProperties := createPropertiesInstance()
1744 module.scopeProperties = scopeToProperties
1745 module.AddProperties(&module.properties, allScopeProperties)
Colin Cross79c7c262019-04-17 11:11:46 -07001746
Paul Duffinb74ee3e2020-05-08 14:16:20 +01001747 // Initialize information common between source and prebuilt.
1748 module.initCommon(&module.ModuleBase)
1749
Paul Duffin0bdcb272020-02-06 15:24:57 +00001750 android.InitPrebuiltModule(module, &[]string{""})
Paul Duffin61871622020-02-10 13:37:10 +00001751 android.InitApexModule(module)
1752 android.InitSdkAwareModule(module)
Colin Cross79c7c262019-04-17 11:11:46 -07001753 InitJavaModule(module, android.HostAndDeviceSupported)
1754
Paul Duffin1a724e62020-05-08 13:44:43 +01001755 module.SetDefaultableHook(func(mctx android.DefaultableHookContext) {
1756 if module.initCommonAfterDefaultsApplied(mctx) {
1757 module.createInternalModules(mctx)
1758 }
1759 })
Colin Cross79c7c262019-04-17 11:11:46 -07001760 return module
1761}
1762
1763func (module *sdkLibraryImport) Prebuilt() *android.Prebuilt {
1764 return &module.prebuilt
1765}
1766
1767func (module *sdkLibraryImport) Name() string {
1768 return module.prebuilt.Name(module.ModuleBase.Name())
1769}
1770
Paul Duffinbf735aa2020-05-08 15:01:19 +01001771func (module *sdkLibraryImport) createInternalModules(mctx android.DefaultableHookContext) {
Colin Cross79c7c262019-04-17 11:11:46 -07001772
Paul Duffin50061512020-01-21 16:31:05 +00001773 // If the build is configured to use prebuilts then force this to be preferred.
1774 if mctx.Config().UnbundledBuildUsePrebuiltSdks() {
1775 module.prebuilt.ForcePrefer()
1776 }
1777
Paul Duffin6a2bd112020-04-07 19:27:04 +01001778 for apiScope, scopeProperties := range module.scopeProperties {
Paul Duffin56d44902020-01-31 13:36:25 +00001779 if len(scopeProperties.Jars) == 0 {
1780 continue
1781 }
1782
Paul Duffinf6155722020-04-09 00:07:11 +01001783 module.createJavaImportForStubs(mctx, apiScope, scopeProperties)
Paul Duffinf488ef22020-04-09 00:10:17 +01001784
Paul Duffin533f9c72020-05-20 16:18:00 +01001785 if len(scopeProperties.Stub_srcs) > 0 {
1786 module.createPrebuiltStubsSources(mctx, apiScope, scopeProperties)
1787 }
Paul Duffin56d44902020-01-31 13:36:25 +00001788 }
Colin Cross79c7c262019-04-17 11:11:46 -07001789
1790 javaSdkLibraries := javaSdkLibraries(mctx.Config())
1791 javaSdkLibrariesLock.Lock()
1792 defer javaSdkLibrariesLock.Unlock()
1793 *javaSdkLibraries = append(*javaSdkLibraries, module.BaseModuleName())
1794}
1795
Paul Duffinbf735aa2020-05-08 15:01:19 +01001796func (module *sdkLibraryImport) createJavaImportForStubs(mctx android.DefaultableHookContext, apiScope *apiScope, scopeProperties *sdkLibraryScopeProperties) {
Paul Duffinf6155722020-04-09 00:07:11 +01001797 // Creates a java import for the jar with ".stubs" suffix
1798 props := struct {
Paul Duffind41712d2020-05-16 09:57:59 +01001799 Name *string
1800 Sdk_version *string
1801 Libs []string
1802 Jars []string
1803 Prefer *bool
Paul Duffinf6155722020-04-09 00:07:11 +01001804 }{}
Paul Duffinb74ee3e2020-05-08 14:16:20 +01001805 props.Name = proptools.StringPtr(module.stubsLibraryModuleName(apiScope))
Paul Duffinf6155722020-04-09 00:07:11 +01001806 props.Sdk_version = scopeProperties.Sdk_version
1807 // Prepend any of the libs from the legacy public properties to the libs for each of the
1808 // scopes to avoid having to duplicate them in each scope.
1809 props.Libs = append(module.properties.Libs, scopeProperties.Libs...)
1810 props.Jars = scopeProperties.Jars
Paul Duffind41712d2020-05-16 09:57:59 +01001811
Paul Duffindd89a282020-05-13 16:08:09 +01001812 // The imports are preferred if the java_sdk_library_import is preferred.
1813 props.Prefer = proptools.BoolPtr(module.prebuilt.Prefer())
Paul Duffin64e61992020-05-15 10:20:31 +01001814
1815 mctx.CreateModule(ImportFactory, &props, module.sdkComponentPropertiesForChildLibrary())
Paul Duffinf6155722020-04-09 00:07:11 +01001816}
1817
Paul Duffinbf735aa2020-05-08 15:01:19 +01001818func (module *sdkLibraryImport) createPrebuiltStubsSources(mctx android.DefaultableHookContext, apiScope *apiScope, scopeProperties *sdkLibraryScopeProperties) {
Paul Duffinf488ef22020-04-09 00:10:17 +01001819 props := struct {
Paul Duffindd89a282020-05-13 16:08:09 +01001820 Name *string
1821 Srcs []string
1822 Prefer *bool
Paul Duffinf488ef22020-04-09 00:10:17 +01001823 }{}
Paul Duffinb74ee3e2020-05-08 14:16:20 +01001824 props.Name = proptools.StringPtr(module.stubsSourceModuleName(apiScope))
Paul Duffinf488ef22020-04-09 00:10:17 +01001825 props.Srcs = scopeProperties.Stub_srcs
1826 mctx.CreateModule(PrebuiltStubsSourcesFactory, &props)
Paul Duffindd89a282020-05-13 16:08:09 +01001827
1828 // The stubs source is preferred if the java_sdk_library_import is preferred.
1829 props.Prefer = proptools.BoolPtr(module.prebuilt.Prefer())
Paul Duffinf488ef22020-04-09 00:10:17 +01001830}
1831
Colin Cross79c7c262019-04-17 11:11:46 -07001832func (module *sdkLibraryImport) DepsMutator(ctx android.BottomUpMutatorContext) {
Paul Duffin6a2bd112020-04-07 19:27:04 +01001833 for apiScope, scopeProperties := range module.scopeProperties {
Paul Duffin56d44902020-01-31 13:36:25 +00001834 if len(scopeProperties.Jars) == 0 {
1835 continue
1836 }
1837
1838 // Add dependencies to the prebuilt stubs library
Paul Duffinb74ee3e2020-05-08 14:16:20 +01001839 ctx.AddVariationDependencies(nil, apiScope.stubsTag, module.stubsLibraryModuleName(apiScope))
Paul Duffin533f9c72020-05-20 16:18:00 +01001840
1841 if len(scopeProperties.Stub_srcs) > 0 {
1842 // Add dependencies to the prebuilt stubs source library
1843 ctx.AddVariationDependencies(nil, apiScope.stubsSourceTag, module.stubsSourceModuleName(apiScope))
1844 }
Paul Duffin56d44902020-01-31 13:36:25 +00001845 }
Colin Cross79c7c262019-04-17 11:11:46 -07001846}
1847
Paul Duffin46fdda82020-05-14 15:39:10 +01001848func (module *sdkLibraryImport) OutputFiles(tag string) (android.Paths, error) {
1849 return module.commonOutputFiles(tag)
1850}
1851
Colin Cross79c7c262019-04-17 11:11:46 -07001852func (module *sdkLibraryImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Paul Duffin533f9c72020-05-20 16:18:00 +01001853 // Record the paths to the prebuilt stubs library and stubs source.
Colin Cross79c7c262019-04-17 11:11:46 -07001854 ctx.VisitDirectDeps(func(to android.Module) {
1855 tag := ctx.OtherModuleDependencyTag(to)
1856
Paul Duffin533f9c72020-05-20 16:18:00 +01001857 // Extract information from any of the scope specific dependencies.
1858 if scopeTag, ok := tag.(scopeDependencyTag); ok {
1859 apiScope := scopeTag.apiScope
1860 scopePaths := module.getScopePathsCreateIfNeeded(apiScope)
1861
1862 // Extract information from the dependency. The exact information extracted
1863 // is determined by the nature of the dependency which is determined by the tag.
1864 scopeTag.extractDepInfo(ctx, to, scopePaths)
Colin Cross79c7c262019-04-17 11:11:46 -07001865 }
1866 })
Paul Duffin533f9c72020-05-20 16:18:00 +01001867
1868 // Populate the scope paths with information from the properties.
1869 for apiScope, scopeProperties := range module.scopeProperties {
1870 if len(scopeProperties.Jars) == 0 {
1871 continue
1872 }
1873
1874 paths := module.getScopePathsCreateIfNeeded(apiScope)
1875 paths.currentApiFilePath = android.OptionalPathForModuleSrc(ctx, scopeProperties.Current_api)
1876 paths.removedApiFilePath = android.OptionalPathForModuleSrc(ctx, scopeProperties.Removed_api)
1877 }
Colin Cross79c7c262019-04-17 11:11:46 -07001878}
1879
Paul Duffin47624362020-05-20 12:19:10 +01001880func (module *sdkLibraryImport) sdkJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths {
Paul Duffina3fb67d2020-05-20 14:20:02 +01001881 return module.selectHeaderJarsForSdkVersion(ctx, sdkVersion)
Paul Duffin56d44902020-01-31 13:36:25 +00001882}
1883
Colin Cross79c7c262019-04-17 11:11:46 -07001884// to satisfy SdkLibraryDependency interface
Jiyong Park6a927c42020-01-21 02:03:43 +09001885func (module *sdkLibraryImport) SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths {
Colin Cross79c7c262019-04-17 11:11:46 -07001886 // This module is just a wrapper for the prebuilt stubs.
Paul Duffin56d44902020-01-31 13:36:25 +00001887 return module.sdkJars(ctx, sdkVersion)
Colin Cross79c7c262019-04-17 11:11:46 -07001888}
1889
1890// to satisfy SdkLibraryDependency interface
Jiyong Park6a927c42020-01-21 02:03:43 +09001891func (module *sdkLibraryImport) SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths {
Colin Cross79c7c262019-04-17 11:11:46 -07001892 // This module is just a wrapper for the stubs.
Paul Duffin56d44902020-01-31 13:36:25 +00001893 return module.sdkJars(ctx, sdkVersion)
Colin Cross79c7c262019-04-17 11:11:46 -07001894}
Jiyong Parke3833882020-02-17 17:28:10 +09001895
1896//
1897// java_sdk_library_xml
1898//
1899type sdkLibraryXml struct {
1900 android.ModuleBase
1901 android.DefaultableModuleBase
1902 android.ApexModuleBase
1903
1904 properties sdkLibraryXmlProperties
1905
1906 outputFilePath android.OutputPath
1907 installDirPath android.InstallPath
1908}
1909
1910type sdkLibraryXmlProperties struct {
1911 // canonical name of the lib
1912 Lib_name *string
1913}
1914
1915// java_sdk_library_xml builds the permission xml file for a java_sdk_library.
1916// Not to be used directly by users. java_sdk_library internally uses this.
1917func sdkLibraryXmlFactory() android.Module {
1918 module := &sdkLibraryXml{}
1919
1920 module.AddProperties(&module.properties)
1921
1922 android.InitApexModule(module)
1923 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibCommon)
1924
1925 return module
1926}
1927
1928// from android.PrebuiltEtcModule
1929func (module *sdkLibraryXml) SubDir() string {
1930 return "permissions"
1931}
1932
1933// from android.PrebuiltEtcModule
1934func (module *sdkLibraryXml) OutputFile() android.OutputPath {
1935 return module.outputFilePath
1936}
1937
1938// from android.ApexModule
1939func (module *sdkLibraryXml) AvailableFor(what string) bool {
1940 return true
1941}
1942
1943func (module *sdkLibraryXml) DepsMutator(ctx android.BottomUpMutatorContext) {
1944 // do nothing
1945}
1946
1947// File path to the runtime implementation library
1948func (module *sdkLibraryXml) implPath() string {
1949 implName := proptools.String(module.properties.Lib_name)
1950 if apexName := module.ApexName(); apexName != "" {
1951 // TODO(b/146468504): ApexName() is only a soong module name, not apex name.
1952 // In most cases, this works fine. But when apex_name is set or override_apex is used
1953 // this can be wrong.
1954 return fmt.Sprintf("/apex/%s/javalib/%s.jar", apexName, implName)
1955 }
1956 partition := "system"
1957 if module.SocSpecific() {
1958 partition = "vendor"
1959 } else if module.DeviceSpecific() {
1960 partition = "odm"
1961 } else if module.ProductSpecific() {
1962 partition = "product"
1963 } else if module.SystemExtSpecific() {
1964 partition = "system_ext"
1965 }
1966 return "/" + partition + "/framework/" + implName + ".jar"
1967}
1968
1969func (module *sdkLibraryXml) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1970 libName := proptools.String(module.properties.Lib_name)
1971 xmlContent := fmt.Sprintf(permissionsTemplate, libName, module.implPath())
1972
1973 module.outputFilePath = android.PathForModuleOut(ctx, libName+".xml").OutputPath
1974 rule := android.NewRuleBuilder()
1975 rule.Command().
1976 Text("/bin/bash -c \"echo -e '" + xmlContent + "'\" > ").
1977 Output(module.outputFilePath)
1978
1979 rule.Build(pctx, ctx, "java_sdk_xml", "Permission XML")
1980
1981 module.installDirPath = android.PathForModuleInstall(ctx, "etc", module.SubDir())
1982}
1983
1984func (module *sdkLibraryXml) AndroidMkEntries() []android.AndroidMkEntries {
1985 if !module.IsForPlatform() {
1986 return []android.AndroidMkEntries{android.AndroidMkEntries{
1987 Disabled: true,
1988 }}
1989 }
1990
1991 return []android.AndroidMkEntries{android.AndroidMkEntries{
1992 Class: "ETC",
1993 OutputFile: android.OptionalPathForPath(module.outputFilePath),
1994 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
1995 func(entries *android.AndroidMkEntries) {
1996 entries.SetString("LOCAL_MODULE_TAGS", "optional")
1997 entries.SetString("LOCAL_MODULE_PATH", module.installDirPath.ToMakePath().String())
1998 entries.SetString("LOCAL_INSTALLED_MODULE_STEM", module.outputFilePath.Base())
1999 },
2000 },
2001 }}
2002}
Paul Duffin61871622020-02-10 13:37:10 +00002003
2004type sdkLibrarySdkMemberType struct {
2005 android.SdkMemberTypeBase
2006}
2007
2008func (s *sdkLibrarySdkMemberType) AddDependencies(mctx android.BottomUpMutatorContext, dependencyTag blueprint.DependencyTag, names []string) {
2009 mctx.AddVariationDependencies(nil, dependencyTag, names...)
2010}
2011
2012func (s *sdkLibrarySdkMemberType) IsInstance(module android.Module) bool {
2013 _, ok := module.(*SdkLibrary)
2014 return ok
2015}
2016
2017func (s *sdkLibrarySdkMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule {
2018 return ctx.SnapshotBuilder().AddPrebuiltModule(member, "java_sdk_library_import")
2019}
2020
2021func (s *sdkLibrarySdkMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties {
2022 return &sdkLibrarySdkMemberProperties{}
2023}
2024
2025type sdkLibrarySdkMemberProperties struct {
2026 android.SdkMemberPropertiesBase
2027
2028 // Scope to per scope properties.
2029 Scopes map[*apiScope]scopeProperties
2030
2031 // Additional libraries that the exported stubs libraries depend upon.
2032 Libs []string
Paul Duffinf488ef22020-04-09 00:10:17 +01002033
2034 // The Java stubs source files.
2035 Stub_srcs []string
Paul Duffinf8e08b22020-05-13 16:54:55 +01002036
2037 // The naming scheme.
2038 Naming_scheme *string
Paul Duffina84756c2020-05-26 20:57:10 +01002039
2040 // True if the java_sdk_library_import is for a shared library, false
2041 // otherwise.
2042 Shared_library *bool
Paul Duffin61871622020-02-10 13:37:10 +00002043}
2044
2045type scopeProperties struct {
Paul Duffin75dcc802020-04-09 01:08:11 +01002046 Jars android.Paths
2047 StubsSrcJar android.Path
2048 CurrentApiFile android.Path
2049 RemovedApiFile android.Path
2050 SdkVersion string
Paul Duffin61871622020-02-10 13:37:10 +00002051}
2052
2053func (s *sdkLibrarySdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) {
2054 sdk := variant.(*SdkLibrary)
2055
2056 s.Scopes = make(map[*apiScope]scopeProperties)
2057 for _, apiScope := range allApiScopes {
Paul Duffin5ae30792020-05-20 11:52:25 +01002058 paths := sdk.findScopePaths(apiScope)
2059 if paths == nil {
2060 continue
2061 }
2062
Paul Duffin61871622020-02-10 13:37:10 +00002063 jars := paths.stubsImplPath
2064 if len(jars) > 0 {
2065 properties := scopeProperties{}
2066 properties.Jars = jars
Paul Duffin153501f2020-05-12 15:52:55 +01002067 properties.SdkVersion = sdk.sdkVersionForStubsLibrary(ctx.SdkModuleContext(), apiScope)
Paul Duffin533f9c72020-05-20 16:18:00 +01002068 properties.StubsSrcJar = paths.stubsSrcJar.Path()
2069 properties.CurrentApiFile = paths.currentApiFilePath.Path()
2070 properties.RemovedApiFile = paths.removedApiFilePath.Path()
Paul Duffin61871622020-02-10 13:37:10 +00002071 s.Scopes[apiScope] = properties
2072 }
2073 }
2074
2075 s.Libs = sdk.properties.Libs
Paul Duffind11e78e2020-05-15 20:37:11 +01002076 s.Naming_scheme = sdk.commonSdkLibraryProperties.Naming_scheme
Paul Duffina84756c2020-05-26 20:57:10 +01002077 s.Shared_library = proptools.BoolPtr(sdk.sharedLibrary())
Paul Duffin61871622020-02-10 13:37:10 +00002078}
2079
2080func (s *sdkLibrarySdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) {
Paul Duffinf8e08b22020-05-13 16:54:55 +01002081 if s.Naming_scheme != nil {
2082 propertySet.AddProperty("naming_scheme", proptools.String(s.Naming_scheme))
2083 }
Paul Duffina84756c2020-05-26 20:57:10 +01002084 if s.Shared_library != nil {
2085 propertySet.AddProperty("shared_library", *s.Shared_library)
2086 }
Paul Duffinf8e08b22020-05-13 16:54:55 +01002087
Paul Duffin61871622020-02-10 13:37:10 +00002088 for _, apiScope := range allApiScopes {
2089 if properties, ok := s.Scopes[apiScope]; ok {
Paul Duffin0f270632020-05-13 19:19:49 +01002090 scopeSet := propertySet.AddPropertySet(apiScope.propertyName)
Paul Duffin61871622020-02-10 13:37:10 +00002091
Paul Duffinf488ef22020-04-09 00:10:17 +01002092 scopeDir := filepath.Join("sdk_library", s.OsPrefix(), apiScope.name)
2093
Paul Duffin61871622020-02-10 13:37:10 +00002094 var jars []string
2095 for _, p := range properties.Jars {
Paul Duffinf488ef22020-04-09 00:10:17 +01002096 dest := filepath.Join(scopeDir, ctx.Name()+"-stubs.jar")
Paul Duffin61871622020-02-10 13:37:10 +00002097 ctx.SnapshotBuilder().CopyToSnapshot(p, dest)
2098 jars = append(jars, dest)
2099 }
2100 scopeSet.AddProperty("jars", jars)
2101
Paul Duffinf488ef22020-04-09 00:10:17 +01002102 // Merge the stubs source jar into the snapshot zip so that when it is unpacked
2103 // the source files are also unpacked.
2104 snapshotRelativeDir := filepath.Join(scopeDir, ctx.Name()+"_stub_sources")
2105 ctx.SnapshotBuilder().UnzipToSnapshot(properties.StubsSrcJar, snapshotRelativeDir)
2106 scopeSet.AddProperty("stub_srcs", []string{snapshotRelativeDir})
2107
Paul Duffin75dcc802020-04-09 01:08:11 +01002108 if properties.CurrentApiFile != nil {
2109 currentApiSnapshotPath := filepath.Join(scopeDir, ctx.Name()+".txt")
2110 ctx.SnapshotBuilder().CopyToSnapshot(properties.CurrentApiFile, currentApiSnapshotPath)
2111 scopeSet.AddProperty("current_api", currentApiSnapshotPath)
2112 }
2113
2114 if properties.RemovedApiFile != nil {
2115 removedApiSnapshotPath := filepath.Join(scopeDir, ctx.Name()+"-removed.txt")
2116 ctx.SnapshotBuilder().CopyToSnapshot(properties.CurrentApiFile, removedApiSnapshotPath)
2117 scopeSet.AddProperty("removed_api", removedApiSnapshotPath)
2118 }
2119
Paul Duffin61871622020-02-10 13:37:10 +00002120 if properties.SdkVersion != "" {
2121 scopeSet.AddProperty("sdk_version", properties.SdkVersion)
2122 }
2123 }
2124 }
2125
2126 if len(s.Libs) > 0 {
2127 propertySet.AddPropertyWithTag("libs", s.Libs, ctx.SnapshotBuilder().SdkMemberReferencePropertyTag(false))
2128 }
2129}