blob: 68623e95829bd5e8a1458e8cb3114a3bdb0b12aa [file] [log] [blame]
Jiyong Parkc678ad32018-04-10 13:07:10 +09001// Copyright 2018 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package java
16
17import (
Jiyong Parkc678ad32018-04-10 13:07:10 +090018 "fmt"
19 "path"
Sundong Ahn054b19a2018-10-19 13:46:09 +090020 "path/filepath"
Paul Duffin46a26a82020-04-07 19:27:04 +010021 "reflect"
Jiyong Park82484c02018-04-23 21:41:26 +090022 "sort"
Jiyong Parkc678ad32018-04-10 13:07:10 +090023 "strings"
Jiyong Park82484c02018-04-23 21:41:26 +090024 "sync"
Jiyong Parkc678ad32018-04-10 13:07:10 +090025
Paul Duffind1b3a922020-01-22 11:57:20 +000026 "github.com/google/blueprint"
Jiyong Parkc678ad32018-04-10 13:07:10 +090027 "github.com/google/blueprint/proptools"
Paul Duffin46a26a82020-04-07 19:27:04 +010028
29 "android/soong/android"
Jiyong Parkc678ad32018-04-10 13:07:10 +090030)
31
Jooyung Han58f26ab2019-12-18 15:34:32 +090032const (
Jiyong Parkc678ad32018-04-10 13:07:10 +090033 sdkStubsLibrarySuffix = ".stubs"
34 sdkSystemApiSuffix = ".system"
Jiyong Parkdf130542018-04-27 16:29:21 +090035 sdkTestApiSuffix = ".test"
Paul Duffin91b883d2020-02-11 13:05:28 +000036 sdkStubsSourceSuffix = ".stubs.source"
Paul Duffin0ff08bd2020-04-29 13:30:54 +010037 sdkApiSuffix = ".api"
Jiyong Parkc678ad32018-04-10 13:07:10 +090038 sdkXmlFileSuffix = ".xml"
Jiyong Parke3833882020-02-17 17:28:10 +090039 permissionsTemplate = `<?xml version=\"1.0\" encoding=\"utf-8\"?>\n` +
Jooyung Han624058e2019-12-24 18:38:06 +090040 `<!-- Copyright (C) 2018 The Android Open Source Project\n` +
41 `\n` +
Jiyong Parke3833882020-02-17 17:28:10 +090042 ` Licensed under the Apache License, Version 2.0 (the \"License\");\n` +
Jooyung Han624058e2019-12-24 18:38:06 +090043 ` you may not use this file except in compliance with the License.\n` +
44 ` You may obtain a copy of the License at\n` +
45 `\n` +
46 ` http://www.apache.org/licenses/LICENSE-2.0\n` +
47 `\n` +
48 ` Unless required by applicable law or agreed to in writing, software\n` +
Jiyong Parke3833882020-02-17 17:28:10 +090049 ` distributed under the License is distributed on an \"AS IS\" BASIS,\n` +
Jooyung Han624058e2019-12-24 18:38:06 +090050 ` WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n` +
51 ` See the License for the specific language governing permissions and\n` +
52 ` limitations under the License.\n` +
53 `-->\n` +
54 `<permissions>\n` +
Jiyong Parke3833882020-02-17 17:28:10 +090055 ` <library name=\"%s\" file=\"%s\"/>\n` +
Jooyung Han624058e2019-12-24 18:38:06 +090056 `</permissions>\n`
Jiyong Parkc678ad32018-04-10 13:07:10 +090057)
58
Paul Duffind1b3a922020-01-22 11:57:20 +000059// A tag to associated a dependency with a specific api scope.
60type scopeDependencyTag struct {
61 blueprint.BaseDependencyTag
62 name string
63 apiScope *apiScope
Paul Duffinc8782502020-04-29 20:45:27 +010064
65 // Function for extracting appropriate path information from the dependency.
66 depInfoExtractor func(paths *scopePaths, dep android.Module) error
67}
68
69// Extract tag specific information from the dependency.
70func (tag scopeDependencyTag) extractDepInfo(ctx android.ModuleContext, dep android.Module, paths *scopePaths) {
71 err := tag.depInfoExtractor(paths, dep)
72 if err != nil {
73 ctx.ModuleErrorf("has an invalid {scopeDependencyTag: %s} dependency on module %s: %s", tag.name, ctx.OtherModuleName(dep), err.Error())
74 }
Paul Duffind1b3a922020-01-22 11:57:20 +000075}
76
77// Provides information about an api scope, e.g. public, system, test.
78type apiScope struct {
79 // The name of the api scope, e.g. public, system, test
80 name string
81
Paul Duffin97b53b82020-05-05 14:40:52 +010082 // The api scope that this scope extends.
83 extends *apiScope
84
Paul Duffin3375e352020-04-28 10:44:03 +010085 // The legacy enabled status for a specific scope can be dependent on other
86 // properties that have been specified on the library so it is provided by
87 // a function that can determine the status by examining those properties.
88 legacyEnabledStatus func(module *SdkLibrary) bool
89
90 // The default enabled status for non-legacy behavior, which is triggered by
91 // explicitly enabling at least one api scope.
92 defaultEnabledStatus bool
93
94 // Gets a pointer to the scope specific properties.
95 scopeSpecificProperties func(module *SdkLibrary) *ApiScopeProperties
96
Paul Duffin46a26a82020-04-07 19:27:04 +010097 // The name of the field in the dynamically created structure.
98 fieldName string
99
Paul Duffind1b3a922020-01-22 11:57:20 +0000100 // The tag to use to depend on the stubs library module.
101 stubsTag scopeDependencyTag
102
Paul Duffin0ff08bd2020-04-29 13:30:54 +0100103 // The tag to use to depend on the stubs source module (if separate from the API module).
104 stubsSourceTag scopeDependencyTag
105
106 // The tag to use to depend on the API file generating module (if separate from the stubs source module).
107 apiFileTag scopeDependencyTag
108
Paul Duffinc8782502020-04-29 20:45:27 +0100109 // The tag to use to depend on the stubs source and API module.
110 stubsSourceAndApiTag scopeDependencyTag
Paul Duffind1b3a922020-01-22 11:57:20 +0000111
112 // The scope specific prefix to add to the api file base of "current.txt" or "removed.txt".
113 apiFilePrefix string
114
115 // The scope specific prefix to add to the sdk library module name to construct a scope specific
116 // module name.
117 moduleSuffix string
118
Paul Duffind1b3a922020-01-22 11:57:20 +0000119 // SDK version that the stubs library is built against. Note that this is always
120 // *current. Older stubs library built with a numbered SDK version is created from
121 // the prebuilt jar.
122 sdkVersion string
Paul Duffin1fb487d2020-04-07 18:50:10 +0100123
124 // Extra arguments to pass to droidstubs for this scope.
125 droidstubsArgs []string
Anton Hansson6478ac12020-05-02 11:19:36 +0100126
Paul Duffin0ff08bd2020-04-29 13:30:54 +0100127 // The args that must be passed to droidstubs to generate the stubs source
128 // for this scope.
129 //
130 // The stubs source must include the definitions of everything that is in this
131 // api scope and all the scopes that this one extends.
132 droidstubsArgsForGeneratingStubsSource []string
133
134 // The args that must be passed to droidstubs to generate the API for this scope.
135 //
136 // The API only includes the additional members that this scope adds over the scope
137 // that it extends.
138 droidstubsArgsForGeneratingApi []string
139
140 // True if the stubs source and api can be created by the same metalava invocation.
141 createStubsSourceAndApiTogether bool
142
Anton Hansson6478ac12020-05-02 11:19:36 +0100143 // Whether the api scope can be treated as unstable, and should skip compat checks.
144 unstable bool
Paul Duffind1b3a922020-01-22 11:57:20 +0000145}
146
147// Initialize a scope, creating and adding appropriate dependency tags
148func initApiScope(scope *apiScope) *apiScope {
Paul Duffinc8782502020-04-29 20:45:27 +0100149 name := scope.name
150 scope.fieldName = proptools.FieldNameForProperty(name)
Paul Duffind1b3a922020-01-22 11:57:20 +0000151 scope.stubsTag = scopeDependencyTag{
Paul Duffinc8782502020-04-29 20:45:27 +0100152 name: name + "-stubs",
153 apiScope: scope,
154 depInfoExtractor: (*scopePaths).extractStubsLibraryInfoFromDependency,
Paul Duffind1b3a922020-01-22 11:57:20 +0000155 }
Paul Duffin0ff08bd2020-04-29 13:30:54 +0100156 scope.stubsSourceTag = scopeDependencyTag{
157 name: name + "-stubs-source",
158 apiScope: scope,
159 depInfoExtractor: (*scopePaths).extractStubsSourceInfoFromDep,
160 }
161 scope.apiFileTag = scopeDependencyTag{
162 name: name + "-api",
163 apiScope: scope,
164 depInfoExtractor: (*scopePaths).extractApiInfoFromDep,
165 }
Paul Duffinc8782502020-04-29 20:45:27 +0100166 scope.stubsSourceAndApiTag = scopeDependencyTag{
167 name: name + "-stubs-source-and-api",
168 apiScope: scope,
169 depInfoExtractor: (*scopePaths).extractStubsSourceAndApiInfoFromApiStubsProvider,
Paul Duffind1b3a922020-01-22 11:57:20 +0000170 }
Paul Duffin0ff08bd2020-04-29 13:30:54 +0100171
172 // To get the args needed to generate the stubs source append all the args from
173 // this scope and all the scopes it extends as each set of args adds additional
174 // members to the stubs.
175 var stubsSourceArgs []string
176 for s := scope; s != nil; s = s.extends {
177 stubsSourceArgs = append(stubsSourceArgs, s.droidstubsArgs...)
178 }
179 scope.droidstubsArgsForGeneratingStubsSource = stubsSourceArgs
180
181 // Currently the args needed to generate the API are the same as the args
182 // needed to add additional members.
183 apiArgs := scope.droidstubsArgs
184 scope.droidstubsArgsForGeneratingApi = apiArgs
185
186 // If the args needed to generate the stubs and API are the same then they
187 // can be generated in a single invocation of metalava, otherwise they will
188 // need separate invocations.
189 scope.createStubsSourceAndApiTogether = reflect.DeepEqual(stubsSourceArgs, apiArgs)
190
Paul Duffind1b3a922020-01-22 11:57:20 +0000191 return scope
192}
193
Paul Duffinc3091c82020-05-08 14:16:20 +0100194func (scope *apiScope) stubsLibraryModuleName(baseName string) string {
Paul Duffind1b3a922020-01-22 11:57:20 +0000195 return baseName + sdkStubsLibrarySuffix + scope.moduleSuffix
196}
197
Paul Duffinc8782502020-04-29 20:45:27 +0100198func (scope *apiScope) stubsSourceModuleName(baseName string) string {
Paul Duffin91b883d2020-02-11 13:05:28 +0000199 return baseName + sdkStubsSourceSuffix + scope.moduleSuffix
Paul Duffind1b3a922020-01-22 11:57:20 +0000200}
201
Paul Duffin0ff08bd2020-04-29 13:30:54 +0100202func (scope *apiScope) apiModuleName(baseName string) string {
203 return baseName + sdkApiSuffix + scope.moduleSuffix
204}
205
Paul Duffin3375e352020-04-28 10:44:03 +0100206func (scope *apiScope) String() string {
207 return scope.name
208}
209
Paul Duffind1b3a922020-01-22 11:57:20 +0000210type apiScopes []*apiScope
211
212func (scopes apiScopes) Strings(accessor func(*apiScope) string) []string {
213 var list []string
214 for _, scope := range scopes {
215 list = append(list, accessor(scope))
216 }
217 return list
218}
219
Jiyong Parkc678ad32018-04-10 13:07:10 +0900220var (
Paul Duffind1b3a922020-01-22 11:57:20 +0000221 apiScopePublic = initApiScope(&apiScope{
Paul Duffin3375e352020-04-28 10:44:03 +0100222 name: "public",
223
224 // Public scope is enabled by default for both legacy and non-legacy modes.
225 legacyEnabledStatus: func(module *SdkLibrary) bool {
226 return true
227 },
228 defaultEnabledStatus: true,
229
230 scopeSpecificProperties: func(module *SdkLibrary) *ApiScopeProperties {
231 return &module.sdkLibraryProperties.Public
232 },
Paul Duffind1b3a922020-01-22 11:57:20 +0000233 sdkVersion: "current",
234 })
235 apiScopeSystem = initApiScope(&apiScope{
Paul Duffin3375e352020-04-28 10:44:03 +0100236 name: "system",
237 extends: apiScopePublic,
238 legacyEnabledStatus: (*SdkLibrary).generateTestAndSystemScopesByDefault,
239 scopeSpecificProperties: func(module *SdkLibrary) *ApiScopeProperties {
240 return &module.sdkLibraryProperties.System
241 },
Anton Hansson6affb1f2020-04-28 16:47:41 +0100242 apiFilePrefix: "system-",
243 moduleSuffix: sdkSystemApiSuffix,
244 sdkVersion: "system_current",
Paul Duffin0d543642020-04-29 22:18:41 +0100245 droidstubsArgs: []string{"-showAnnotation android.annotation.SystemApi\\(client=android.annotation.SystemApi.Client.PRIVILEGED_APPS\\)"},
Paul Duffind1b3a922020-01-22 11:57:20 +0000246 })
247 apiScopeTest = initApiScope(&apiScope{
Paul Duffin3375e352020-04-28 10:44:03 +0100248 name: "test",
249 extends: apiScopePublic,
250 legacyEnabledStatus: (*SdkLibrary).generateTestAndSystemScopesByDefault,
251 scopeSpecificProperties: func(module *SdkLibrary) *ApiScopeProperties {
252 return &module.sdkLibraryProperties.Test
253 },
Anton Hansson6affb1f2020-04-28 16:47:41 +0100254 apiFilePrefix: "test-",
255 moduleSuffix: sdkTestApiSuffix,
256 sdkVersion: "test_current",
257 droidstubsArgs: []string{"-showAnnotation android.annotation.TestApi"},
Anton Hansson6478ac12020-05-02 11:19:36 +0100258 unstable: true,
Paul Duffind1b3a922020-01-22 11:57:20 +0000259 })
Paul Duffin8f265b92020-04-28 14:13:56 +0100260 apiScopeModuleLib = initApiScope(&apiScope{
261 name: "module_lib",
262 extends: apiScopeSystem,
263 // Module_lib scope is disabled by default in legacy mode.
264 //
265 // Enabling this would break existing usages.
266 legacyEnabledStatus: func(module *SdkLibrary) bool {
267 return false
268 },
269 scopeSpecificProperties: func(module *SdkLibrary) *ApiScopeProperties {
270 return &module.sdkLibraryProperties.Module_lib
271 },
272 apiFilePrefix: "module-lib-",
273 moduleSuffix: ".module_lib",
274 sdkVersion: "module_current",
275 droidstubsArgs: []string{
276 "--show-annotation android.annotation.SystemApi\\(client=android.annotation.SystemApi.Client.MODULE_LIBRARIES\\)",
277 },
278 })
Paul Duffind1b3a922020-01-22 11:57:20 +0000279 allApiScopes = apiScopes{
280 apiScopePublic,
281 apiScopeSystem,
282 apiScopeTest,
Paul Duffin8f265b92020-04-28 14:13:56 +0100283 apiScopeModuleLib,
Paul Duffind1b3a922020-01-22 11:57:20 +0000284 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900285)
286
Jiyong Park82484c02018-04-23 21:41:26 +0900287var (
288 javaSdkLibrariesLock sync.Mutex
289)
290
Jiyong Parkc678ad32018-04-10 13:07:10 +0900291// TODO: these are big features that are currently missing
Jiyong Park1be96912018-05-28 18:02:19 +0900292// 1) disallowing linking to the runtime shared lib
293// 2) HTML generation
Jiyong Parkc678ad32018-04-10 13:07:10 +0900294
295func init() {
Paul Duffin43dc1cc2019-12-19 11:18:54 +0000296 RegisterSdkLibraryBuildComponents(android.InitRegistrationContext)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900297
Jiyong Park82484c02018-04-23 21:41:26 +0900298 android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) {
299 javaSdkLibraries := javaSdkLibraries(ctx.Config())
300 sort.Strings(*javaSdkLibraries)
301 ctx.Strict("JAVA_SDK_LIBRARIES", strings.Join(*javaSdkLibraries, " "))
302 })
Paul Duffindd46f712020-02-10 13:37:10 +0000303
304 // Register sdk member types.
305 android.RegisterSdkMemberType(&sdkLibrarySdkMemberType{
306 android.SdkMemberTypeBase{
307 PropertyName: "java_sdk_libs",
308 SupportsSdk: true,
309 },
310 })
Jiyong Parkc678ad32018-04-10 13:07:10 +0900311}
312
Paul Duffin43dc1cc2019-12-19 11:18:54 +0000313func RegisterSdkLibraryBuildComponents(ctx android.RegistrationContext) {
314 ctx.RegisterModuleType("java_sdk_library", SdkLibraryFactory)
315 ctx.RegisterModuleType("java_sdk_library_import", sdkLibraryImportFactory)
316}
317
Paul Duffin3375e352020-04-28 10:44:03 +0100318// Properties associated with each api scope.
319type ApiScopeProperties struct {
320 // Indicates whether the api surface is generated.
321 //
322 // If this is set for any scope then all scopes must explicitly specify if they
323 // are enabled. This is to prevent new usages from depending on legacy behavior.
324 //
325 // Otherwise, if this is not set for any scope then the default behavior is
326 // scope specific so please refer to the scope specific property documentation.
327 Enabled *bool
328}
329
Jiyong Parkc678ad32018-04-10 13:07:10 +0900330type sdkLibraryProperties struct {
Paul Duffin4911a892020-04-29 23:35:13 +0100331 // Visibility for stubs library modules. If not specified then defaults to the
332 // visibility property.
333 Stubs_library_visibility []string
334
335 // Visibility for stubs source modules. If not specified then defaults to the
336 // visibility property.
337 Stubs_source_visibility []string
338
Sundong Ahnf043cf62018-06-25 16:04:37 +0900339 // List of Java libraries that will be in the classpath when building stubs
340 Stub_only_libs []string `android:"arch_variant"`
341
Paul Duffin7a586d32019-12-30 17:09:34 +0000342 // list of package names that will be documented and publicized as API.
343 // This allows the API to be restricted to a subset of the source files provided.
344 // If this is unspecified then all the source files will be treated as being part
345 // of the API.
Jiyong Parkc678ad32018-04-10 13:07:10 +0900346 Api_packages []string
347
Jiyong Park5a2c9d72018-05-01 22:25:41 +0900348 // list of package names that must be hidden from the API
349 Hidden_api_packages []string
350
Paul Duffin749f98f2019-12-30 17:23:46 +0000351 // the relative path to the directory containing the api specification files.
352 // Defaults to "api".
353 Api_dir *string
354
Paul Duffin43db9be2019-12-30 17:35:49 +0000355 // If set to true there is no runtime library.
356 Api_only *bool
357
Paul Duffin11512472019-02-11 15:55:17 +0000358 // local files that are used within user customized droiddoc options.
359 Droiddoc_option_files []string
360
361 // additional droiddoc options
362 // Available variables for substitution:
363 //
364 // $(location <label>): the path to the droiddoc_option_files with name <label>
Sundong Ahndd567f92018-07-31 17:19:11 +0900365 Droiddoc_options []string
366
Sundong Ahn054b19a2018-10-19 13:46:09 +0900367 // a list of top-level directories containing files to merge qualifier annotations
368 // (i.e. those intended to be included in the stubs written) from.
369 Merge_annotations_dirs []string
370
371 // a list of top-level directories containing Java stub files to merge show/hide annotations from.
372 Merge_inclusion_annotations_dirs []string
373
374 // If set to true, the path of dist files is apistubs/core. Defaults to false.
375 Core_lib *bool
376
Sundong Ahn80a87b32019-05-13 15:02:50 +0900377 // don't create dist rules.
378 No_dist *bool `blueprint:"mutated"`
379
Paul Duffin3375e352020-04-28 10:44:03 +0100380 // indicates whether system and test apis should be generated.
381 Generate_system_and_test_apis bool `blueprint:"mutated"`
382
383 // The properties specific to the public api scope
384 //
385 // Unless explicitly specified by using public.enabled the public api scope is
386 // enabled by default in both legacy and non-legacy mode.
387 Public ApiScopeProperties
388
389 // The properties specific to the system api scope
390 //
391 // In legacy mode the system api scope is enabled by default when sdk_version
392 // is set to something other than "none".
393 //
394 // In non-legacy mode the system api scope is disabled by default.
395 System ApiScopeProperties
396
397 // The properties specific to the test api scope
398 //
399 // In legacy mode the test api scope is enabled by default when sdk_version
400 // is set to something other than "none".
401 //
402 // In non-legacy mode the test api scope is disabled by default.
403 Test ApiScopeProperties
Paul Duffin37e0b772019-12-30 17:20:10 +0000404
Paul Duffin8f265b92020-04-28 14:13:56 +0100405 // The properties specific to the module_lib api scope
406 //
407 // Unless explicitly specified by using test.enabled the module_lib api scope is
408 // disabled by default.
409 Module_lib ApiScopeProperties
410
Paul Duffin160fe412020-05-10 19:32:20 +0100411 // Properties related to api linting.
412 Api_lint struct {
413 // Enable api linting.
414 Enabled *bool
415 }
416
Jiyong Parkc678ad32018-04-10 13:07:10 +0900417 // TODO: determines whether to create HTML doc or not
418 //Html_doc *bool
419}
420
Paul Duffind1b3a922020-01-22 11:57:20 +0000421type scopePaths struct {
Paul Duffin1fd005d2020-04-09 01:08:11 +0100422 stubsHeaderPath android.Paths
423 stubsImplPath android.Paths
424 currentApiFilePath android.Path
425 removedApiFilePath android.Path
426 stubsSrcJar android.Path
Paul Duffind1b3a922020-01-22 11:57:20 +0000427}
428
Paul Duffinc8782502020-04-29 20:45:27 +0100429func (paths *scopePaths) extractStubsLibraryInfoFromDependency(dep android.Module) error {
430 if lib, ok := dep.(Dependency); ok {
431 paths.stubsHeaderPath = lib.HeaderJars()
432 paths.stubsImplPath = lib.ImplementationJars()
433 return nil
434 } else {
435 return fmt.Errorf("expected module that implements Dependency, e.g. java_library")
436 }
437}
438
Paul Duffin0ff08bd2020-04-29 13:30:54 +0100439func (paths *scopePaths) treatDepAsApiStubsProvider(dep android.Module, action func(provider ApiStubsProvider)) error {
440 if apiStubsProvider, ok := dep.(ApiStubsProvider); ok {
441 action(apiStubsProvider)
Paul Duffinc8782502020-04-29 20:45:27 +0100442 return nil
443 } else {
444 return fmt.Errorf("expected module that implements ApiStubsProvider, e.g. droidstubs")
445 }
446}
447
Paul Duffin0ff08bd2020-04-29 13:30:54 +0100448func (paths *scopePaths) extractApiInfoFromApiStubsProvider(provider ApiStubsProvider) {
449 paths.currentApiFilePath = provider.ApiFilePath()
450 paths.removedApiFilePath = provider.RemovedApiFilePath()
451}
452
453func (paths *scopePaths) extractApiInfoFromDep(dep android.Module) error {
454 return paths.treatDepAsApiStubsProvider(dep, func(provider ApiStubsProvider) {
455 paths.extractApiInfoFromApiStubsProvider(provider)
456 })
457}
458
459func (paths *scopePaths) extractStubsSourceInfoFromApiStubsProviders(provider ApiStubsProvider) {
460 paths.stubsSrcJar = provider.StubsSrcJar()
461}
462
463func (paths *scopePaths) extractStubsSourceInfoFromDep(dep android.Module) error {
464 return paths.treatDepAsApiStubsProvider(dep, func(provider ApiStubsProvider) {
465 paths.extractStubsSourceInfoFromApiStubsProviders(provider)
466 })
467}
468
469func (paths *scopePaths) extractStubsSourceAndApiInfoFromApiStubsProvider(dep android.Module) error {
470 return paths.treatDepAsApiStubsProvider(dep, func(provider ApiStubsProvider) {
471 paths.extractApiInfoFromApiStubsProvider(provider)
472 paths.extractStubsSourceInfoFromApiStubsProviders(provider)
473 })
474}
475
476type commonToSdkLibraryAndImportProperties struct {
Paul Duffin1b1e8062020-05-08 13:44:43 +0100477 // The naming scheme to use for the components that this module creates.
478 //
479 // If not specified then it defaults to "default", which is currently the only
480 // allowable value.
481 //
482 // This is a temporary mechanism to simplify conversion from separate modules for each
483 // component that follow a different naming pattern to the default one.
484 //
485 // TODO(b/155480189) - Remove once naming inconsistencies have been resolved.
Paul Duffin0ff08bd2020-04-29 13:30:54 +0100486 Naming_scheme *string
487}
488
Paul Duffin56d44902020-01-31 13:36:25 +0000489// Common code between sdk library and sdk library import
490type commonToSdkLibraryAndImport struct {
Paul Duffinc3091c82020-05-08 14:16:20 +0100491 moduleBase *android.ModuleBase
492
Paul Duffin56d44902020-01-31 13:36:25 +0000493 scopePaths map[*apiScope]*scopePaths
Paul Duffin1b1e8062020-05-08 13:44:43 +0100494
495 namingScheme sdkLibraryComponentNamingScheme
496
497 commonProperties commonToSdkLibraryAndImportProperties
Paul Duffin56d44902020-01-31 13:36:25 +0000498}
499
Paul Duffinc3091c82020-05-08 14:16:20 +0100500func (c *commonToSdkLibraryAndImport) initCommon(moduleBase *android.ModuleBase) {
501 c.moduleBase = moduleBase
Paul Duffin1b1e8062020-05-08 13:44:43 +0100502
503 moduleBase.AddProperties(&c.commonProperties)
504}
505
506func (c *commonToSdkLibraryAndImport) initCommonAfterDefaultsApplied(ctx android.DefaultableHookContext) bool {
507 schemeProperty := proptools.StringDefault(c.commonProperties.Naming_scheme, "default")
508 switch schemeProperty {
509 case "default":
510 c.namingScheme = &defaultNamingScheme{}
511 default:
512 ctx.PropertyErrorf("naming_scheme", "expected 'default' but was %q", schemeProperty)
513 return false
514 }
515
516 return true
Paul Duffinc3091c82020-05-08 14:16:20 +0100517}
518
519// Name of the java_library module that compiles the stubs source.
520func (c *commonToSdkLibraryAndImport) stubsLibraryModuleName(apiScope *apiScope) string {
Paul Duffin1b1e8062020-05-08 13:44:43 +0100521 return c.namingScheme.stubsLibraryModuleName(apiScope, c.moduleBase.BaseModuleName())
Paul Duffinc3091c82020-05-08 14:16:20 +0100522}
523
524// Name of the droidstubs module that generates the stubs source and may also
525// generate/check the API.
526func (c *commonToSdkLibraryAndImport) stubsSourceModuleName(apiScope *apiScope) string {
Paul Duffin1b1e8062020-05-08 13:44:43 +0100527 return c.namingScheme.stubsSourceModuleName(apiScope, c.moduleBase.BaseModuleName())
Paul Duffinc3091c82020-05-08 14:16:20 +0100528}
529
530// Name of the droidstubs module that generates/checks the API. Only used if it
531// requires different arts to the stubs source generating module.
532func (c *commonToSdkLibraryAndImport) apiModuleName(apiScope *apiScope) string {
Paul Duffin1b1e8062020-05-08 13:44:43 +0100533 return c.namingScheme.apiModuleName(apiScope, c.moduleBase.BaseModuleName())
Paul Duffinc3091c82020-05-08 14:16:20 +0100534}
535
Paul Duffin56d44902020-01-31 13:36:25 +0000536func (c *commonToSdkLibraryAndImport) getScopePaths(scope *apiScope) *scopePaths {
537 if c.scopePaths == nil {
538 c.scopePaths = make(map[*apiScope]*scopePaths)
539 }
540 paths := c.scopePaths[scope]
541 if paths == nil {
542 paths = &scopePaths{}
543 c.scopePaths[scope] = paths
544 }
545
546 return paths
547}
548
Inseob Kimc0907f12019-02-08 21:00:45 +0900549type SdkLibrary struct {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900550 Library
Jiyong Parkc678ad32018-04-10 13:07:10 +0900551
Sundong Ahn054b19a2018-10-19 13:46:09 +0900552 sdkLibraryProperties sdkLibraryProperties
Jiyong Parkc678ad32018-04-10 13:07:10 +0900553
Paul Duffin3375e352020-04-28 10:44:03 +0100554 // Map from api scope to the scope specific property structure.
555 scopeToProperties map[*apiScope]*ApiScopeProperties
556
Paul Duffin56d44902020-01-31 13:36:25 +0000557 commonToSdkLibraryAndImport
Jiyong Parkc678ad32018-04-10 13:07:10 +0900558}
559
Inseob Kimc0907f12019-02-08 21:00:45 +0900560var _ Dependency = (*SdkLibrary)(nil)
561var _ SdkLibraryDependency = (*SdkLibrary)(nil)
Colin Cross897d2ed2019-02-11 14:03:51 -0800562
Paul Duffin3375e352020-04-28 10:44:03 +0100563func (module *SdkLibrary) generateTestAndSystemScopesByDefault() bool {
564 return module.sdkLibraryProperties.Generate_system_and_test_apis
565}
566
567func (module *SdkLibrary) getGeneratedApiScopes(ctx android.EarlyModuleContext) apiScopes {
568 // Check to see if any scopes have been explicitly enabled. If any have then all
569 // must be.
570 anyScopesExplicitlyEnabled := false
571 for _, scope := range allApiScopes {
572 scopeProperties := module.scopeToProperties[scope]
573 if scopeProperties.Enabled != nil {
574 anyScopesExplicitlyEnabled = true
575 break
576 }
Paul Duffind1b3a922020-01-22 11:57:20 +0000577 }
Paul Duffin3375e352020-04-28 10:44:03 +0100578
579 var generatedScopes apiScopes
580 enabledScopes := make(map[*apiScope]struct{})
581 for _, scope := range allApiScopes {
582 scopeProperties := module.scopeToProperties[scope]
583 // If any scopes are explicitly enabled then ignore the legacy enabled status.
584 // This is to ensure that any new usages of this module type do not rely on legacy
585 // behaviour.
586 defaultEnabledStatus := false
587 if anyScopesExplicitlyEnabled {
588 defaultEnabledStatus = scope.defaultEnabledStatus
589 } else {
590 defaultEnabledStatus = scope.legacyEnabledStatus(module)
591 }
592 enabled := proptools.BoolDefault(scopeProperties.Enabled, defaultEnabledStatus)
593 if enabled {
594 enabledScopes[scope] = struct{}{}
595 generatedScopes = append(generatedScopes, scope)
596 }
597 }
598
599 // Now check to make sure that any scope that is extended by an enabled scope is also
600 // enabled.
601 for _, scope := range allApiScopes {
602 if _, ok := enabledScopes[scope]; ok {
603 extends := scope.extends
604 if extends != nil {
605 if _, ok := enabledScopes[extends]; !ok {
606 ctx.ModuleErrorf("enabled api scope %q depends on disabled scope %q", scope, extends)
607 }
608 }
609 }
610 }
611
612 return generatedScopes
Paul Duffind1b3a922020-01-22 11:57:20 +0000613}
614
Paul Duffine74ac732020-02-06 13:51:46 +0000615var xmlPermissionsFileTag = dependencyTag{name: "xml-permissions-file"}
616
Jiyong Parke3833882020-02-17 17:28:10 +0900617func IsXmlPermissionsFileDepTag(depTag blueprint.DependencyTag) bool {
618 if dt, ok := depTag.(dependencyTag); ok {
619 return dt == xmlPermissionsFileTag
620 }
621 return false
622}
623
Inseob Kimc0907f12019-02-08 21:00:45 +0900624func (module *SdkLibrary) DepsMutator(ctx android.BottomUpMutatorContext) {
Paul Duffin3375e352020-04-28 10:44:03 +0100625 for _, apiScope := range module.getGeneratedApiScopes(ctx) {
Paul Duffind1b3a922020-01-22 11:57:20 +0000626 // Add dependencies to the stubs library
Paul Duffinc3091c82020-05-08 14:16:20 +0100627 ctx.AddVariationDependencies(nil, apiScope.stubsTag, module.stubsLibraryModuleName(apiScope))
Paul Duffind1b3a922020-01-22 11:57:20 +0000628
Paul Duffin0ff08bd2020-04-29 13:30:54 +0100629 // If the stubs source and API cannot be generated together then add an additional dependency on
630 // the API module.
631 if apiScope.createStubsSourceAndApiTogether {
632 // Add a dependency on the stubs source in order to access both stubs source and api information.
Paul Duffinc3091c82020-05-08 14:16:20 +0100633 ctx.AddVariationDependencies(nil, apiScope.stubsSourceAndApiTag, module.stubsSourceModuleName(apiScope))
Paul Duffin0ff08bd2020-04-29 13:30:54 +0100634 } else {
635 // Add separate dependencies on the creators of the stubs source files and the API.
Paul Duffinc3091c82020-05-08 14:16:20 +0100636 ctx.AddVariationDependencies(nil, apiScope.stubsSourceTag, module.stubsSourceModuleName(apiScope))
637 ctx.AddVariationDependencies(nil, apiScope.apiFileTag, module.apiModuleName(apiScope))
Paul Duffin0ff08bd2020-04-29 13:30:54 +0100638 }
Sundong Ahn054b19a2018-10-19 13:46:09 +0900639 }
640
Paul Duffine74ac732020-02-06 13:51:46 +0000641 if !proptools.Bool(module.sdkLibraryProperties.Api_only) {
642 // Add dependency to the rule for generating the xml permissions file
Jiyong Parke3833882020-02-17 17:28:10 +0900643 ctx.AddDependency(module, xmlPermissionsFileTag, module.xmlFileName())
Paul Duffine74ac732020-02-06 13:51:46 +0000644 }
645
Sundong Ahn054b19a2018-10-19 13:46:09 +0900646 module.Library.deps(ctx)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900647}
648
Inseob Kimc0907f12019-02-08 21:00:45 +0900649func (module *SdkLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Paul Duffin43db9be2019-12-30 17:35:49 +0000650 // Don't build an implementation library if this is api only.
651 if !proptools.Bool(module.sdkLibraryProperties.Api_only) {
652 module.Library.GenerateAndroidBuildActions(ctx)
653 }
Sundong Ahn054b19a2018-10-19 13:46:09 +0900654
Sundong Ahn57368eb2018-07-06 11:20:23 +0900655 // Record the paths to the header jars of the library (stubs and impl).
Paul Duffind1b3a922020-01-22 11:57:20 +0000656 // When this java_sdk_library is depended upon from others via "libs" property,
Jiyong Parkc678ad32018-04-10 13:07:10 +0900657 // the recorded paths will be returned depending on the link type of the caller.
658 ctx.VisitDirectDeps(func(to android.Module) {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900659 tag := ctx.OtherModuleDependencyTag(to)
660
Paul Duffinc8782502020-04-29 20:45:27 +0100661 // Extract information from any of the scope specific dependencies.
662 if scopeTag, ok := tag.(scopeDependencyTag); ok {
663 apiScope := scopeTag.apiScope
664 scopePaths := module.getScopePaths(apiScope)
665
666 // Extract information from the dependency. The exact information extracted
667 // is determined by the nature of the dependency which is determined by the tag.
668 scopeTag.extractDepInfo(ctx, to, scopePaths)
Sundong Ahn20e998b2018-07-24 11:19:26 +0900669 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900670 })
671}
672
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900673func (module *SdkLibrary) AndroidMkEntries() []android.AndroidMkEntries {
Paul Duffin43db9be2019-12-30 17:35:49 +0000674 if proptools.Bool(module.sdkLibraryProperties.Api_only) {
675 return nil
676 }
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900677 entriesList := module.Library.AndroidMkEntries()
678 entries := &entriesList[0]
Jaewoong Jungb0c127c2019-08-29 14:56:03 -0700679 entries.Required = append(entries.Required, module.xmlFileName())
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900680 return entriesList
Jiyong Park82484c02018-04-23 21:41:26 +0900681}
682
Jiyong Parkc678ad32018-04-10 13:07:10 +0900683// Module name of the runtime implementation library
Inseob Kimc0907f12019-02-08 21:00:45 +0900684func (module *SdkLibrary) implName() string {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900685 return module.BaseModuleName()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900686}
687
Jiyong Parkc678ad32018-04-10 13:07:10 +0900688// Module name of the XML file for the lib
Inseob Kimc0907f12019-02-08 21:00:45 +0900689func (module *SdkLibrary) xmlFileName() string {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900690 return module.BaseModuleName() + sdkXmlFileSuffix
691}
692
Anton Hansson5fd5d242020-03-27 19:43:19 +0000693// The dist path of the stub artifacts
694func (module *SdkLibrary) apiDistPath(apiScope *apiScope) string {
695 if module.ModuleBase.Owner() != "" {
696 return path.Join("apistubs", module.ModuleBase.Owner(), apiScope.name)
697 } else if Bool(module.sdkLibraryProperties.Core_lib) {
698 return path.Join("apistubs", "core", apiScope.name)
699 } else {
700 return path.Join("apistubs", "android", apiScope.name)
701 }
702}
703
Paul Duffin12ceb462019-12-24 20:31:31 +0000704// Get the sdk version for use when compiling the stubs library.
Paul Duffin780c5f42020-05-12 15:52:55 +0100705func (module *SdkLibrary) sdkVersionForStubsLibrary(mctx android.EarlyModuleContext, apiScope *apiScope) string {
Paul Duffin12ceb462019-12-24 20:31:31 +0000706 sdkDep := decodeSdkDep(mctx, sdkContext(&module.Library))
707 if sdkDep.hasStandardLibs() {
708 // If building against a standard sdk then use the sdk version appropriate for the scope.
Paul Duffind1b3a922020-01-22 11:57:20 +0000709 return apiScope.sdkVersion
Paul Duffin12ceb462019-12-24 20:31:31 +0000710 } else {
711 // Otherwise, use no system module.
712 return "none"
713 }
714}
715
Paul Duffind1b3a922020-01-22 11:57:20 +0000716func (module *SdkLibrary) latestApiFilegroupName(apiScope *apiScope) string {
717 return ":" + module.BaseModuleName() + ".api." + apiScope.name + ".latest"
Jiyong Park58c518b2018-05-12 22:29:12 +0900718}
Jiyong Parkc678ad32018-04-10 13:07:10 +0900719
Paul Duffind1b3a922020-01-22 11:57:20 +0000720func (module *SdkLibrary) latestRemovedApiFilegroupName(apiScope *apiScope) string {
721 return ":" + module.BaseModuleName() + "-removed.api." + apiScope.name + ".latest"
Jiyong Parkc678ad32018-04-10 13:07:10 +0900722}
723
724// Creates a static java library that has API stubs
Paul Duffinf0229202020-04-29 16:47:28 +0100725func (module *SdkLibrary) createStubsLibrary(mctx android.DefaultableHookContext, apiScope *apiScope) {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900726 props := struct {
Sundong Ahn0d7dff42019-12-04 12:53:44 +0900727 Name *string
Paul Duffin4911a892020-04-29 23:35:13 +0100728 Visibility []string
Sundong Ahn0d7dff42019-12-04 12:53:44 +0900729 Srcs []string
Paul Duffin367ab912019-12-23 19:40:36 +0000730 Installable *bool
Sundong Ahn0d7dff42019-12-04 12:53:44 +0900731 Sdk_version *string
Paul Duffin12ceb462019-12-24 20:31:31 +0000732 System_modules *string
Paul Duffinab8da5d2020-02-07 16:12:04 +0000733 Patch_module *string
Sundong Ahn0d7dff42019-12-04 12:53:44 +0900734 Libs []string
735 Soc_specific *bool
736 Device_specific *bool
737 Product_specific *bool
738 System_ext_specific *bool
739 Compile_dex *bool
Sundong Ahn0d7dff42019-12-04 12:53:44 +0900740 Java_version *string
741 Product_variables struct {
Jiyong Park82484c02018-04-23 21:41:26 +0900742 Pdk struct {
743 Enabled *bool
744 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900745 }
Sundong Ahn054b19a2018-10-19 13:46:09 +0900746 Openjdk9 struct {
747 Srcs []string
748 Javacflags []string
749 }
Anton Hansson5fd5d242020-03-27 19:43:19 +0000750 Dist struct {
751 Targets []string
752 Dest *string
753 Dir *string
754 Tag *string
755 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900756 }{}
757
Paul Duffinc3091c82020-05-08 14:16:20 +0100758 props.Name = proptools.StringPtr(module.stubsLibraryModuleName(apiScope))
Paul Duffin4911a892020-04-29 23:35:13 +0100759
760 // If stubs_library_visibility is not set then the created module will use the
761 // visibility of this module.
762 visibility := module.sdkLibraryProperties.Stubs_library_visibility
763 props.Visibility = visibility
764
Jiyong Parkc678ad32018-04-10 13:07:10 +0900765 // sources are generated from the droiddoc
Paul Duffinc3091c82020-05-08 14:16:20 +0100766 props.Srcs = []string{":" + module.stubsSourceModuleName(apiScope)}
Paul Duffin12ceb462019-12-24 20:31:31 +0000767 sdkVersion := module.sdkVersionForStubsLibrary(mctx, apiScope)
Paul Duffin52d398a2019-06-11 12:31:14 +0100768 props.Sdk_version = proptools.StringPtr(sdkVersion)
Paul Duffin12ceb462019-12-24 20:31:31 +0000769 props.System_modules = module.Library.Module.deviceProperties.System_modules
Paul Duffinab8da5d2020-02-07 16:12:04 +0000770 props.Patch_module = module.Library.Module.properties.Patch_module
Paul Duffin367ab912019-12-23 19:40:36 +0000771 props.Installable = proptools.BoolPtr(false)
Sundong Ahn054b19a2018-10-19 13:46:09 +0900772 props.Libs = module.sdkLibraryProperties.Stub_only_libs
Jiyong Park82484c02018-04-23 21:41:26 +0900773 props.Product_variables.Pdk.Enabled = proptools.BoolPtr(false)
Sundong Ahn054b19a2018-10-19 13:46:09 +0900774 props.Openjdk9.Srcs = module.Library.Module.properties.Openjdk9.Srcs
775 props.Openjdk9.Javacflags = module.Library.Module.properties.Openjdk9.Javacflags
776 props.Java_version = module.Library.Module.properties.Java_version
777 if module.Library.Module.deviceProperties.Compile_dex != nil {
778 props.Compile_dex = module.Library.Module.deviceProperties.Compile_dex
Sundong Ahndd567f92018-07-31 17:19:11 +0900779 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900780
781 if module.SocSpecific() {
782 props.Soc_specific = proptools.BoolPtr(true)
783 } else if module.DeviceSpecific() {
784 props.Device_specific = proptools.BoolPtr(true)
785 } else if module.ProductSpecific() {
786 props.Product_specific = proptools.BoolPtr(true)
Sundong Ahn0d7dff42019-12-04 12:53:44 +0900787 } else if module.SystemExtSpecific() {
788 props.System_ext_specific = proptools.BoolPtr(true)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900789 }
Anton Hansson5fd5d242020-03-27 19:43:19 +0000790 // Dist the class jar artifact for sdk builds.
791 if !Bool(module.sdkLibraryProperties.No_dist) {
792 props.Dist.Targets = []string{"sdk", "win_sdk"}
793 props.Dist.Dest = proptools.StringPtr(fmt.Sprintf("%v.jar", module.BaseModuleName()))
794 props.Dist.Dir = proptools.StringPtr(module.apiDistPath(apiScope))
795 props.Dist.Tag = proptools.StringPtr(".jar")
796 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900797
Colin Cross84dfc3d2019-09-25 11:33:01 -0700798 mctx.CreateModule(LibraryFactory, &props)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900799}
800
Paul Duffin6d0886e2020-04-07 18:49:53 +0100801// Creates a droidstubs module that creates stubs source files from the given full source
Paul Duffinc8782502020-04-29 20:45:27 +0100802// files and also updates and checks the API specification files.
Paul Duffin0ff08bd2020-04-29 13:30:54 +0100803func (module *SdkLibrary) createStubsSourcesAndApi(mctx android.DefaultableHookContext, apiScope *apiScope, name string, createStubSources, createApi bool, scopeSpecificDroidstubsArgs []string) {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900804 props := struct {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900805 Name *string
Paul Duffin4911a892020-04-29 23:35:13 +0100806 Visibility []string
Sundong Ahn054b19a2018-10-19 13:46:09 +0900807 Srcs []string
808 Installable *bool
Paul Duffin52d398a2019-06-11 12:31:14 +0100809 Sdk_version *string
Paul Duffin12ceb462019-12-24 20:31:31 +0000810 System_modules *string
Sundong Ahn054b19a2018-10-19 13:46:09 +0900811 Libs []string
Paul Duffin11512472019-02-11 15:55:17 +0000812 Arg_files []string
Sundong Ahn054b19a2018-10-19 13:46:09 +0900813 Args *string
Sundong Ahn054b19a2018-10-19 13:46:09 +0900814 Java_version *string
815 Merge_annotations_dirs []string
816 Merge_inclusion_annotations_dirs []string
Paul Duffin0ff08bd2020-04-29 13:30:54 +0100817 Generate_stubs *bool
Sundong Ahn054b19a2018-10-19 13:46:09 +0900818 Check_api struct {
Inseob Kim38449af2019-02-28 14:24:05 +0900819 Current ApiToCheck
820 Last_released ApiToCheck
821 Ignore_missing_latest_api *bool
Paul Duffin160fe412020-05-10 19:32:20 +0100822
823 Api_lint struct {
824 Enabled *bool
825 New_since *string
826 Baseline_file *string
827 }
Jiyong Park58c518b2018-05-12 22:29:12 +0900828 }
Sundong Ahn1b92c822018-05-29 11:35:17 +0900829 Aidl struct {
830 Include_dirs []string
831 Local_include_dirs []string
832 }
Anton Hansson5fd5d242020-03-27 19:43:19 +0000833 Dist struct {
834 Targets []string
835 Dest *string
836 Dir *string
837 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900838 }{}
839
Paul Duffin7b78b4d2020-04-28 14:08:32 +0100840 // The stubs source processing uses the same compile time classpath when extracting the
841 // API from the implementation library as it does when compiling it. i.e. the same
842 // * sdk version
843 // * system_modules
844 // * libs (static_libs/libs)
Paul Duffin250e6192019-06-07 10:44:37 +0100845
Paul Duffin0ff08bd2020-04-29 13:30:54 +0100846 props.Name = proptools.StringPtr(name)
Paul Duffin4911a892020-04-29 23:35:13 +0100847
848 // If stubs_source_visibility is not set then the created module will use the
849 // visibility of this module.
850 visibility := module.sdkLibraryProperties.Stubs_source_visibility
851 props.Visibility = visibility
852
Sundong Ahn054b19a2018-10-19 13:46:09 +0900853 props.Srcs = append(props.Srcs, module.Library.Module.properties.Srcs...)
Paul Duffin7b78b4d2020-04-28 14:08:32 +0100854 props.Sdk_version = module.Library.Module.deviceProperties.Sdk_version
Paul Duffin12ceb462019-12-24 20:31:31 +0000855 props.System_modules = module.Library.Module.deviceProperties.System_modules
Jiyong Parkc678ad32018-04-10 13:07:10 +0900856 props.Installable = proptools.BoolPtr(false)
Sundong Ahne6f0b052018-06-05 16:46:14 +0900857 // A droiddoc module has only one Libs property and doesn't distinguish between
858 // shared libs and static libs. So we need to add both of these libs to Libs property.
Sundong Ahn054b19a2018-10-19 13:46:09 +0900859 props.Libs = module.Library.Module.properties.Libs
860 props.Libs = append(props.Libs, module.Library.Module.properties.Static_libs...)
861 props.Aidl.Include_dirs = module.Library.Module.deviceProperties.Aidl.Include_dirs
862 props.Aidl.Local_include_dirs = module.Library.Module.deviceProperties.Aidl.Local_include_dirs
Sundong Ahn054b19a2018-10-19 13:46:09 +0900863 props.Java_version = module.Library.Module.properties.Java_version
Jiyong Parkc678ad32018-04-10 13:07:10 +0900864
Sundong Ahn054b19a2018-10-19 13:46:09 +0900865 props.Merge_annotations_dirs = module.sdkLibraryProperties.Merge_annotations_dirs
866 props.Merge_inclusion_annotations_dirs = module.sdkLibraryProperties.Merge_inclusion_annotations_dirs
867
Paul Duffin6d0886e2020-04-07 18:49:53 +0100868 droidstubsArgs := []string{}
Paul Duffin235ffff2019-12-24 10:41:30 +0000869 if len(module.sdkLibraryProperties.Api_packages) != 0 {
Paul Duffin6d0886e2020-04-07 18:49:53 +0100870 droidstubsArgs = append(droidstubsArgs, "--stub-packages "+strings.Join(module.sdkLibraryProperties.Api_packages, ":"))
Paul Duffin235ffff2019-12-24 10:41:30 +0000871 }
872 if len(module.sdkLibraryProperties.Hidden_api_packages) != 0 {
Paul Duffin6d0886e2020-04-07 18:49:53 +0100873 droidstubsArgs = append(droidstubsArgs,
Paul Duffin235ffff2019-12-24 10:41:30 +0000874 android.JoinWithPrefix(module.sdkLibraryProperties.Hidden_api_packages, " --hide-package "))
875 }
Paul Duffin6d0886e2020-04-07 18:49:53 +0100876 droidstubsArgs = append(droidstubsArgs, module.sdkLibraryProperties.Droiddoc_options...)
Paul Duffin235ffff2019-12-24 10:41:30 +0000877 disabledWarnings := []string{
878 "MissingPermission",
879 "BroadcastBehavior",
880 "HiddenSuperclass",
881 "DeprecationMismatch",
882 "UnavailableSymbol",
883 "SdkConstant",
884 "HiddenTypeParameter",
885 "Todo",
886 "Typo",
887 }
Paul Duffin6d0886e2020-04-07 18:49:53 +0100888 droidstubsArgs = append(droidstubsArgs, android.JoinWithPrefix(disabledWarnings, "--hide "))
Sundong Ahnfb2721f2018-09-17 13:23:09 +0900889
Paul Duffin0ff08bd2020-04-29 13:30:54 +0100890 if !createStubSources {
891 // Stubs are not required.
892 props.Generate_stubs = proptools.BoolPtr(false)
893 }
894
Paul Duffin1fb487d2020-04-07 18:50:10 +0100895 // Add in scope specific arguments.
Paul Duffin0ff08bd2020-04-29 13:30:54 +0100896 droidstubsArgs = append(droidstubsArgs, scopeSpecificDroidstubsArgs...)
Paul Duffin11512472019-02-11 15:55:17 +0000897 props.Arg_files = module.sdkLibraryProperties.Droiddoc_option_files
Paul Duffin6d0886e2020-04-07 18:49:53 +0100898 props.Args = proptools.StringPtr(strings.Join(droidstubsArgs, " "))
Jiyong Parkc678ad32018-04-10 13:07:10 +0900899
Paul Duffin0ff08bd2020-04-29 13:30:54 +0100900 if createApi {
901 // List of APIs identified from the provided source files are created. They are later
902 // compared against to the not-yet-released (a.k.a current) list of APIs and to the
903 // last-released (a.k.a numbered) list of API.
904 currentApiFileName := apiScope.apiFilePrefix + "current.txt"
905 removedApiFileName := apiScope.apiFilePrefix + "removed.txt"
906 apiDir := module.getApiDir()
907 currentApiFileName = path.Join(apiDir, currentApiFileName)
908 removedApiFileName = path.Join(apiDir, removedApiFileName)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900909
Paul Duffin0ff08bd2020-04-29 13:30:54 +0100910 // check against the not-yet-release API
911 props.Check_api.Current.Api_file = proptools.StringPtr(currentApiFileName)
912 props.Check_api.Current.Removed_api_file = proptools.StringPtr(removedApiFileName)
Jiyong Park58c518b2018-05-12 22:29:12 +0900913
Paul Duffin0ff08bd2020-04-29 13:30:54 +0100914 if !apiScope.unstable {
915 // check against the latest released API
916 latestApiFilegroupName := proptools.StringPtr(module.latestApiFilegroupName(apiScope))
917 props.Check_api.Last_released.Api_file = latestApiFilegroupName
918 props.Check_api.Last_released.Removed_api_file = proptools.StringPtr(
919 module.latestRemovedApiFilegroupName(apiScope))
920 props.Check_api.Ignore_missing_latest_api = proptools.BoolPtr(true)
Paul Duffin160fe412020-05-10 19:32:20 +0100921
Paul Duffin0ff08bd2020-04-29 13:30:54 +0100922 if proptools.Bool(module.sdkLibraryProperties.Api_lint.Enabled) {
923 // Enable api lint.
924 props.Check_api.Api_lint.Enabled = proptools.BoolPtr(true)
925 props.Check_api.Api_lint.New_since = latestApiFilegroupName
Paul Duffin160fe412020-05-10 19:32:20 +0100926
Paul Duffin0ff08bd2020-04-29 13:30:54 +0100927 // If it exists then pass a lint-baseline.txt through to droidstubs.
928 baselinePath := path.Join(apiDir, apiScope.apiFilePrefix+"lint-baseline.txt")
929 baselinePathRelativeToRoot := path.Join(mctx.ModuleDir(), baselinePath)
930 paths, err := mctx.GlobWithDeps(baselinePathRelativeToRoot, nil)
931 if err != nil {
932 mctx.ModuleErrorf("error checking for presence of %s: %s", baselinePathRelativeToRoot, err)
933 }
934 if len(paths) == 1 {
935 props.Check_api.Api_lint.Baseline_file = proptools.StringPtr(baselinePath)
936 } else if len(paths) != 0 {
937 mctx.ModuleErrorf("error checking for presence of %s: expected one path, found: %v", baselinePathRelativeToRoot, paths)
938 }
Paul Duffin160fe412020-05-10 19:32:20 +0100939 }
940 }
Jiyong Park58c518b2018-05-12 22:29:12 +0900941
Paul Duffin0ff08bd2020-04-29 13:30:54 +0100942 // Dist the api txt artifact for sdk builds.
943 if !Bool(module.sdkLibraryProperties.No_dist) {
944 props.Dist.Targets = []string{"sdk", "win_sdk"}
945 props.Dist.Dest = proptools.StringPtr(fmt.Sprintf("%v.txt", module.BaseModuleName()))
946 props.Dist.Dir = proptools.StringPtr(path.Join(module.apiDistPath(apiScope), "api"))
947 }
Anton Hansson5fd5d242020-03-27 19:43:19 +0000948 }
949
Colin Cross84dfc3d2019-09-25 11:33:01 -0700950 mctx.CreateModule(DroidstubsFactory, &props)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900951}
952
Jooyung Han5e9013b2020-03-10 06:23:13 +0900953func (module *SdkLibrary) DepIsInSameApex(mctx android.BaseModuleContext, dep android.Module) bool {
954 depTag := mctx.OtherModuleDependencyTag(dep)
955 if depTag == xmlPermissionsFileTag {
956 return true
957 }
958 return module.Library.DepIsInSameApex(mctx, dep)
959}
960
Jiyong Parkc678ad32018-04-10 13:07:10 +0900961// Creates the xml file that publicizes the runtime library
Paul Duffinf0229202020-04-29 16:47:28 +0100962func (module *SdkLibrary) createXmlFile(mctx android.DefaultableHookContext) {
Jiyong Parke3833882020-02-17 17:28:10 +0900963 props := struct {
Sundong Ahn0d7dff42019-12-04 12:53:44 +0900964 Name *string
Jiyong Parke3833882020-02-17 17:28:10 +0900965 Lib_name *string
Sundong Ahn0d7dff42019-12-04 12:53:44 +0900966 Soc_specific *bool
967 Device_specific *bool
968 Product_specific *bool
969 System_ext_specific *bool
Jooyung Han5e9013b2020-03-10 06:23:13 +0900970 Apex_available []string
Jiyong Parke3833882020-02-17 17:28:10 +0900971 }{
Jooyung Han5e9013b2020-03-10 06:23:13 +0900972 Name: proptools.StringPtr(module.xmlFileName()),
973 Lib_name: proptools.StringPtr(module.BaseModuleName()),
974 Apex_available: module.ApexProperties.Apex_available,
Jiyong Parkc678ad32018-04-10 13:07:10 +0900975 }
Jiyong Parke3833882020-02-17 17:28:10 +0900976
977 if module.SocSpecific() {
978 props.Soc_specific = proptools.BoolPtr(true)
979 } else if module.DeviceSpecific() {
980 props.Device_specific = proptools.BoolPtr(true)
981 } else if module.ProductSpecific() {
982 props.Product_specific = proptools.BoolPtr(true)
983 } else if module.SystemExtSpecific() {
984 props.System_ext_specific = proptools.BoolPtr(true)
985 }
986
987 mctx.CreateModule(sdkLibraryXmlFactory, &props)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900988}
989
Paul Duffin50061512020-01-21 16:31:05 +0000990func PrebuiltJars(ctx android.BaseModuleContext, baseName string, s sdkSpec) android.Paths {
Jiyong Park6a927c42020-01-21 02:03:43 +0900991 var ver sdkVersion
992 var kind sdkKind
993 if s.usePrebuilt(ctx) {
994 ver = s.version
995 kind = s.kind
Jiyong Parkc678ad32018-04-10 13:07:10 +0900996 } else {
Jiyong Park6a927c42020-01-21 02:03:43 +0900997 // We don't have prebuilt SDK for the specific sdkVersion.
998 // Instead of breaking the build, fallback to use "system_current"
999 ver = sdkVersionCurrent
1000 kind = sdkSystem
Sundong Ahn054b19a2018-10-19 13:46:09 +09001001 }
Jiyong Park6a927c42020-01-21 02:03:43 +09001002
1003 dir := filepath.Join("prebuilts", "sdk", ver.String(), kind.String())
Paul Duffin50061512020-01-21 16:31:05 +00001004 jar := filepath.Join(dir, baseName+".jar")
Sundong Ahn054b19a2018-10-19 13:46:09 +09001005 jarPath := android.ExistentPathForSource(ctx, jar)
Sundong Ahnae418ac2019-02-28 15:01:28 +09001006 if !jarPath.Valid() {
Colin Cross07c88562020-01-07 09:34:44 -08001007 if ctx.Config().AllowMissingDependencies() {
1008 return android.Paths{android.PathForSource(ctx, jar)}
1009 } else {
Jiyong Park6a927c42020-01-21 02:03:43 +09001010 ctx.PropertyErrorf("sdk_library", "invalid sdk version %q, %q does not exist", s.raw, jar)
Colin Cross07c88562020-01-07 09:34:44 -08001011 }
Sundong Ahnae418ac2019-02-28 15:01:28 +09001012 return nil
1013 }
Sundong Ahn054b19a2018-10-19 13:46:09 +09001014 return android.Paths{jarPath.Path()}
1015}
1016
Paul Duffind1b3a922020-01-22 11:57:20 +00001017func (module *SdkLibrary) sdkJars(
1018 ctx android.BaseModuleContext,
1019 sdkVersion sdkSpec,
1020 headerJars bool) android.Paths {
1021
Paul Duffin50061512020-01-21 16:31:05 +00001022 // If a specific numeric version has been requested then use prebuilt versions of the sdk.
1023 if sdkVersion.version.isNumbered() {
1024 return PrebuiltJars(ctx, module.BaseModuleName(), sdkVersion)
Sundong Ahn054b19a2018-10-19 13:46:09 +09001025 } else {
Paul Duffind1b3a922020-01-22 11:57:20 +00001026 if !sdkVersion.specified() {
1027 if headerJars {
1028 return module.Library.HeaderJars()
1029 } else {
1030 return module.Library.ImplementationJars()
1031 }
1032 }
Paul Duffin726d23c2020-01-22 16:30:37 +00001033 var apiScope *apiScope
Jiyong Park6a927c42020-01-21 02:03:43 +09001034 switch sdkVersion.kind {
1035 case sdkSystem:
Paul Duffin726d23c2020-01-22 16:30:37 +00001036 apiScope = apiScopeSystem
1037 case sdkTest:
1038 apiScope = apiScopeTest
Jiyong Park6a927c42020-01-21 02:03:43 +09001039 case sdkPrivate:
Sundong Ahn054b19a2018-10-19 13:46:09 +09001040 return module.Library.HeaderJars()
Jiyong Park6a927c42020-01-21 02:03:43 +09001041 default:
Paul Duffin726d23c2020-01-22 16:30:37 +00001042 apiScope = apiScopePublic
Paul Duffind1b3a922020-01-22 11:57:20 +00001043 }
1044
Paul Duffin726d23c2020-01-22 16:30:37 +00001045 paths := module.getScopePaths(apiScope)
Paul Duffind1b3a922020-01-22 11:57:20 +00001046 if headerJars {
1047 return paths.stubsHeaderPath
1048 } else {
1049 return paths.stubsImplPath
Sundong Ahn054b19a2018-10-19 13:46:09 +09001050 }
Jiyong Parkc678ad32018-04-10 13:07:10 +09001051 }
1052}
1053
Sundong Ahn241cd372018-07-13 16:16:44 +09001054// to satisfy SdkLibraryDependency interface
Paul Duffind1b3a922020-01-22 11:57:20 +00001055func (module *SdkLibrary) SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths {
1056 return module.sdkJars(ctx, sdkVersion, true /*headerJars*/)
1057}
1058
1059// to satisfy SdkLibraryDependency interface
Jiyong Park6a927c42020-01-21 02:03:43 +09001060func (module *SdkLibrary) SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths {
Paul Duffind1b3a922020-01-22 11:57:20 +00001061 return module.sdkJars(ctx, sdkVersion, false /*headerJars*/)
Sundong Ahn241cd372018-07-13 16:16:44 +09001062}
1063
Sundong Ahn80a87b32019-05-13 15:02:50 +09001064func (module *SdkLibrary) SetNoDist() {
1065 module.sdkLibraryProperties.No_dist = proptools.BoolPtr(true)
1066}
1067
Colin Cross571cccf2019-02-04 11:22:08 -08001068var javaSdkLibrariesKey = android.NewOnceKey("javaSdkLibraries")
1069
Jiyong Park82484c02018-04-23 21:41:26 +09001070func javaSdkLibraries(config android.Config) *[]string {
Colin Cross571cccf2019-02-04 11:22:08 -08001071 return config.Once(javaSdkLibrariesKey, func() interface{} {
Jiyong Park82484c02018-04-23 21:41:26 +09001072 return &[]string{}
1073 }).(*[]string)
1074}
1075
Paul Duffin749f98f2019-12-30 17:23:46 +00001076func (module *SdkLibrary) getApiDir() string {
1077 return proptools.StringDefault(module.sdkLibraryProperties.Api_dir, "api")
1078}
1079
Jiyong Parkc678ad32018-04-10 13:07:10 +09001080// For a java_sdk_library module, create internal modules for stubs, docs,
1081// runtime libs and xml file. If requested, the stubs and docs are created twice
1082// once for public API level and once for system API level
Paul Duffinf0229202020-04-29 16:47:28 +01001083func (module *SdkLibrary) CreateInternalModules(mctx android.DefaultableHookContext) {
1084 // If the module has been disabled then don't create any child modules.
1085 if !module.Enabled() {
1086 return
1087 }
1088
Inseob Kim6e93ac92019-03-21 17:43:49 +09001089 if len(module.Library.Module.properties.Srcs) == 0 {
Inseob Kimc0907f12019-02-08 21:00:45 +09001090 mctx.PropertyErrorf("srcs", "java_sdk_library must specify srcs")
Jooyung Han58f26ab2019-12-18 15:34:32 +09001091 return
Inseob Kimc0907f12019-02-08 21:00:45 +09001092 }
1093
Paul Duffin37e0b772019-12-30 17:20:10 +00001094 // If this builds against standard libraries (i.e. is not part of the core libraries)
1095 // then assume it provides both system and test apis. Otherwise, assume it does not and
1096 // also assume it does not contribute to the dist build.
1097 sdkDep := decodeSdkDep(mctx, sdkContext(&module.Library))
1098 hasSystemAndTestApis := sdkDep.hasStandardLibs()
Paul Duffin3375e352020-04-28 10:44:03 +01001099 module.sdkLibraryProperties.Generate_system_and_test_apis = hasSystemAndTestApis
Paul Duffin37e0b772019-12-30 17:20:10 +00001100 module.sdkLibraryProperties.No_dist = proptools.BoolPtr(!hasSystemAndTestApis)
1101
Inseob Kim8098faa2019-03-18 10:19:51 +09001102 missing_current_api := false
1103
Paul Duffin3375e352020-04-28 10:44:03 +01001104 generatedScopes := module.getGeneratedApiScopes(mctx)
Paul Duffind1b3a922020-01-22 11:57:20 +00001105
Paul Duffin749f98f2019-12-30 17:23:46 +00001106 apiDir := module.getApiDir()
Paul Duffin3375e352020-04-28 10:44:03 +01001107 for _, scope := range generatedScopes {
Inseob Kim8098faa2019-03-18 10:19:51 +09001108 for _, api := range []string{"current.txt", "removed.txt"} {
Paul Duffind1b3a922020-01-22 11:57:20 +00001109 path := path.Join(mctx.ModuleDir(), apiDir, scope.apiFilePrefix+api)
Inseob Kim8098faa2019-03-18 10:19:51 +09001110 p := android.ExistentPathForSource(mctx, path)
1111 if !p.Valid() {
1112 mctx.ModuleErrorf("Current api file %#v doesn't exist", path)
1113 missing_current_api = true
1114 }
1115 }
1116 }
1117
1118 if missing_current_api {
1119 script := "build/soong/scripts/gen-java-current-api-files.sh"
1120 p := android.ExistentPathForSource(mctx, script)
1121
1122 if !p.Valid() {
1123 panic(fmt.Sprintf("script file %s doesn't exist", script))
1124 }
1125
1126 mctx.ModuleErrorf("One or more current api files are missing. "+
1127 "You can update them by:\n"+
Paul Duffin37e0b772019-12-30 17:20:10 +00001128 "%s %q %s && m update-api",
Paul Duffind1b3a922020-01-22 11:57:20 +00001129 script, filepath.Join(mctx.ModuleDir(), apiDir),
Paul Duffin3375e352020-04-28 10:44:03 +01001130 strings.Join(generatedScopes.Strings(func(s *apiScope) string { return s.apiFilePrefix }), " "))
Inseob Kim8098faa2019-03-18 10:19:51 +09001131 return
1132 }
1133
Paul Duffin3375e352020-04-28 10:44:03 +01001134 for _, scope := range generatedScopes {
Paul Duffin0ff08bd2020-04-29 13:30:54 +01001135 stubsSourceArgs := scope.droidstubsArgsForGeneratingStubsSource
Paul Duffinc3091c82020-05-08 14:16:20 +01001136 stubsSourceModuleName := module.stubsSourceModuleName(scope)
Paul Duffin0ff08bd2020-04-29 13:30:54 +01001137
1138 // If the args needed to generate the stubs and API are the same then they
1139 // can be generated in a single invocation of metalava, otherwise they will
1140 // need separate invocations.
1141 if scope.createStubsSourceAndApiTogether {
1142 // Use the stubs source name for legacy reasons.
1143 module.createStubsSourcesAndApi(mctx, scope, stubsSourceModuleName, true, true, stubsSourceArgs)
1144 } else {
1145 module.createStubsSourcesAndApi(mctx, scope, stubsSourceModuleName, true, false, stubsSourceArgs)
1146
1147 apiArgs := scope.droidstubsArgsForGeneratingApi
Paul Duffinc3091c82020-05-08 14:16:20 +01001148 apiName := module.apiModuleName(scope)
Paul Duffin0ff08bd2020-04-29 13:30:54 +01001149 module.createStubsSourcesAndApi(mctx, scope, apiName, false, true, apiArgs)
1150 }
1151
Paul Duffind1b3a922020-01-22 11:57:20 +00001152 module.createStubsLibrary(mctx, scope)
Inseob Kimc0907f12019-02-08 21:00:45 +09001153 }
1154
Paul Duffin43db9be2019-12-30 17:35:49 +00001155 if !proptools.Bool(module.sdkLibraryProperties.Api_only) {
1156 // for runtime
1157 module.createXmlFile(mctx)
1158
1159 // record java_sdk_library modules so that they are exported to make
1160 javaSdkLibraries := javaSdkLibraries(mctx.Config())
1161 javaSdkLibrariesLock.Lock()
1162 defer javaSdkLibrariesLock.Unlock()
1163 *javaSdkLibraries = append(*javaSdkLibraries, module.BaseModuleName())
1164 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001165}
1166
1167func (module *SdkLibrary) InitSdkLibraryProperties() {
Sundong Ahn054b19a2018-10-19 13:46:09 +09001168 module.AddProperties(
1169 &module.sdkLibraryProperties,
1170 &module.Library.Module.properties,
1171 &module.Library.Module.dexpreoptProperties,
1172 &module.Library.Module.deviceProperties,
1173 &module.Library.Module.protoProperties,
1174 )
1175
1176 module.Library.Module.properties.Installable = proptools.BoolPtr(true)
1177 module.Library.Module.deviceProperties.IsSDKLibrary = true
Inseob Kimc0907f12019-02-08 21:00:45 +09001178}
Sundong Ahn054b19a2018-10-19 13:46:09 +09001179
Paul Duffin1b1e8062020-05-08 13:44:43 +01001180// Defines how to name the individual component modules the sdk library creates.
1181type sdkLibraryComponentNamingScheme interface {
1182 stubsLibraryModuleName(scope *apiScope, baseName string) string
1183
1184 stubsSourceModuleName(scope *apiScope, baseName string) string
1185
1186 apiModuleName(scope *apiScope, baseName string) string
1187}
1188
1189type defaultNamingScheme struct {
1190}
1191
1192func (s *defaultNamingScheme) stubsLibraryModuleName(scope *apiScope, baseName string) string {
1193 return scope.stubsLibraryModuleName(baseName)
1194}
1195
1196func (s *defaultNamingScheme) stubsSourceModuleName(scope *apiScope, baseName string) string {
1197 return scope.stubsSourceModuleName(baseName)
1198}
1199
1200func (s *defaultNamingScheme) apiModuleName(scope *apiScope, baseName string) string {
1201 return scope.apiModuleName(baseName)
1202}
1203
1204var _ sdkLibraryComponentNamingScheme = (*defaultNamingScheme)(nil)
1205
Jaewoong Jung4f158ee2019-07-11 10:05:35 -07001206// java_sdk_library is a special Java library that provides optional platform APIs to apps.
1207// In practice, it can be viewed as a combination of several modules: 1) stubs library that clients
1208// are linked against to, 2) droiddoc module that internally generates API stubs source files,
1209// 3) the real runtime shared library that implements the APIs, and 4) XML file for adding
1210// the runtime lib to the classpath at runtime if requested via <uses-library>.
Inseob Kimc0907f12019-02-08 21:00:45 +09001211func SdkLibraryFactory() android.Module {
1212 module := &SdkLibrary{}
Paul Duffinc3091c82020-05-08 14:16:20 +01001213
1214 // Initialize information common between source and prebuilt.
1215 module.initCommon(&module.ModuleBase)
1216
Inseob Kimc0907f12019-02-08 21:00:45 +09001217 module.InitSdkLibraryProperties()
Jooyung Han58f26ab2019-12-18 15:34:32 +09001218 android.InitApexModule(module)
Sundong Ahn054b19a2018-10-19 13:46:09 +09001219 InitJavaModule(module, android.HostAndDeviceSupported)
Paul Duffin3375e352020-04-28 10:44:03 +01001220
1221 // Initialize the map from scope to scope specific properties.
1222 scopeToProperties := make(map[*apiScope]*ApiScopeProperties)
1223 for _, scope := range allApiScopes {
1224 scopeToProperties[scope] = scope.scopeSpecificProperties(module)
1225 }
1226 module.scopeToProperties = scopeToProperties
1227
Paul Duffin4911a892020-04-29 23:35:13 +01001228 // Add the properties containing visibility rules so that they are checked.
1229 android.AddVisibilityProperty(module, "stubs_library_visibility", &module.sdkLibraryProperties.Stubs_library_visibility)
1230 android.AddVisibilityProperty(module, "stubs_source_visibility", &module.sdkLibraryProperties.Stubs_source_visibility)
1231
Paul Duffin1b1e8062020-05-08 13:44:43 +01001232 module.SetDefaultableHook(func(ctx android.DefaultableHookContext) {
1233 if module.initCommonAfterDefaultsApplied(ctx) {
1234 module.CreateInternalModules(ctx)
1235 }
1236 })
Jiyong Parkc678ad32018-04-10 13:07:10 +09001237 return module
1238}
Colin Cross79c7c262019-04-17 11:11:46 -07001239
1240//
1241// SDK library prebuilts
1242//
1243
Paul Duffin56d44902020-01-31 13:36:25 +00001244// Properties associated with each api scope.
1245type sdkLibraryScopeProperties struct {
Colin Cross79c7c262019-04-17 11:11:46 -07001246 Jars []string `android:"path"`
1247
1248 Sdk_version *string
1249
Colin Cross79c7c262019-04-17 11:11:46 -07001250 // List of shared java libs that this module has dependencies to
1251 Libs []string
Paul Duffin3d1248c2020-04-09 00:10:17 +01001252
Paul Duffinc8782502020-04-29 20:45:27 +01001253 // The stubs source.
Paul Duffin3d1248c2020-04-09 00:10:17 +01001254 Stub_srcs []string `android:"path"`
Paul Duffin1fd005d2020-04-09 01:08:11 +01001255
1256 // The current.txt
1257 Current_api string `android:"path"`
1258
1259 // The removed.txt
1260 Removed_api string `android:"path"`
Colin Cross79c7c262019-04-17 11:11:46 -07001261}
1262
Paul Duffin56d44902020-01-31 13:36:25 +00001263type sdkLibraryImportProperties struct {
Paul Duffinfcfd7912020-01-31 17:54:30 +00001264 // List of shared java libs, common to all scopes, that this module has
1265 // dependencies to
1266 Libs []string
Paul Duffin56d44902020-01-31 13:36:25 +00001267}
1268
Colin Cross79c7c262019-04-17 11:11:46 -07001269type sdkLibraryImport struct {
1270 android.ModuleBase
1271 android.DefaultableModuleBase
1272 prebuilt android.Prebuilt
Paul Duffindd46f712020-02-10 13:37:10 +00001273 android.ApexModuleBase
1274 android.SdkBase
Colin Cross79c7c262019-04-17 11:11:46 -07001275
1276 properties sdkLibraryImportProperties
1277
Paul Duffin46a26a82020-04-07 19:27:04 +01001278 // Map from api scope to the scope specific property structure.
1279 scopeProperties map[*apiScope]*sdkLibraryScopeProperties
1280
Paul Duffin56d44902020-01-31 13:36:25 +00001281 commonToSdkLibraryAndImport
Colin Cross79c7c262019-04-17 11:11:46 -07001282}
1283
1284var _ SdkLibraryDependency = (*sdkLibraryImport)(nil)
1285
Paul Duffin46a26a82020-04-07 19:27:04 +01001286// The type of a structure that contains a field of type sdkLibraryScopeProperties
1287// for each apiscope in allApiScopes, e.g. something like:
1288// struct {
1289// Public sdkLibraryScopeProperties
1290// System sdkLibraryScopeProperties
1291// ...
1292// }
1293var allScopeStructType = createAllScopePropertiesStructType()
1294
1295// Dynamically create a structure type for each apiscope in allApiScopes.
1296func createAllScopePropertiesStructType() reflect.Type {
1297 var fields []reflect.StructField
1298 for _, apiScope := range allApiScopes {
1299 field := reflect.StructField{
1300 Name: apiScope.fieldName,
1301 Type: reflect.TypeOf(sdkLibraryScopeProperties{}),
1302 }
1303 fields = append(fields, field)
1304 }
1305
1306 return reflect.StructOf(fields)
1307}
1308
1309// Create an instance of the scope specific structure type and return a map
1310// from apiscope to a pointer to each scope specific field.
1311func createPropertiesInstance() (interface{}, map[*apiScope]*sdkLibraryScopeProperties) {
1312 allScopePropertiesPtr := reflect.New(allScopeStructType)
1313 allScopePropertiesStruct := allScopePropertiesPtr.Elem()
1314 scopeProperties := make(map[*apiScope]*sdkLibraryScopeProperties)
1315
1316 for _, apiScope := range allApiScopes {
1317 field := allScopePropertiesStruct.FieldByName(apiScope.fieldName)
1318 scopeProperties[apiScope] = field.Addr().Interface().(*sdkLibraryScopeProperties)
1319 }
1320
1321 return allScopePropertiesPtr.Interface(), scopeProperties
1322}
1323
Jaewoong Jung4f158ee2019-07-11 10:05:35 -07001324// java_sdk_library_import imports a prebuilt java_sdk_library.
Colin Cross79c7c262019-04-17 11:11:46 -07001325func sdkLibraryImportFactory() android.Module {
1326 module := &sdkLibraryImport{}
1327
Paul Duffin46a26a82020-04-07 19:27:04 +01001328 allScopeProperties, scopeToProperties := createPropertiesInstance()
1329 module.scopeProperties = scopeToProperties
1330 module.AddProperties(&module.properties, allScopeProperties)
Colin Cross79c7c262019-04-17 11:11:46 -07001331
Paul Duffinc3091c82020-05-08 14:16:20 +01001332 // Initialize information common between source and prebuilt.
1333 module.initCommon(&module.ModuleBase)
1334
Paul Duffin0bdcb272020-02-06 15:24:57 +00001335 android.InitPrebuiltModule(module, &[]string{""})
Paul Duffindd46f712020-02-10 13:37:10 +00001336 android.InitApexModule(module)
1337 android.InitSdkAwareModule(module)
Colin Cross79c7c262019-04-17 11:11:46 -07001338 InitJavaModule(module, android.HostAndDeviceSupported)
1339
Paul Duffin1b1e8062020-05-08 13:44:43 +01001340 module.SetDefaultableHook(func(mctx android.DefaultableHookContext) {
1341 if module.initCommonAfterDefaultsApplied(mctx) {
1342 module.createInternalModules(mctx)
1343 }
1344 })
Colin Cross79c7c262019-04-17 11:11:46 -07001345 return module
1346}
1347
1348func (module *sdkLibraryImport) Prebuilt() *android.Prebuilt {
1349 return &module.prebuilt
1350}
1351
1352func (module *sdkLibraryImport) Name() string {
1353 return module.prebuilt.Name(module.ModuleBase.Name())
1354}
1355
Paul Duffin6e7ecbf2020-05-08 15:01:19 +01001356func (module *sdkLibraryImport) createInternalModules(mctx android.DefaultableHookContext) {
Colin Cross79c7c262019-04-17 11:11:46 -07001357
Paul Duffin50061512020-01-21 16:31:05 +00001358 // If the build is configured to use prebuilts then force this to be preferred.
1359 if mctx.Config().UnbundledBuildUsePrebuiltSdks() {
1360 module.prebuilt.ForcePrefer()
1361 }
1362
Paul Duffin46a26a82020-04-07 19:27:04 +01001363 for apiScope, scopeProperties := range module.scopeProperties {
Paul Duffin56d44902020-01-31 13:36:25 +00001364 if len(scopeProperties.Jars) == 0 {
1365 continue
1366 }
1367
Paul Duffinbbb546b2020-04-09 00:07:11 +01001368 module.createJavaImportForStubs(mctx, apiScope, scopeProperties)
Paul Duffin3d1248c2020-04-09 00:10:17 +01001369
1370 module.createPrebuiltStubsSources(mctx, apiScope, scopeProperties)
Paul Duffin56d44902020-01-31 13:36:25 +00001371 }
Colin Cross79c7c262019-04-17 11:11:46 -07001372
1373 javaSdkLibraries := javaSdkLibraries(mctx.Config())
1374 javaSdkLibrariesLock.Lock()
1375 defer javaSdkLibrariesLock.Unlock()
1376 *javaSdkLibraries = append(*javaSdkLibraries, module.BaseModuleName())
1377}
1378
Paul Duffin6e7ecbf2020-05-08 15:01:19 +01001379func (module *sdkLibraryImport) createJavaImportForStubs(mctx android.DefaultableHookContext, apiScope *apiScope, scopeProperties *sdkLibraryScopeProperties) {
Paul Duffinbbb546b2020-04-09 00:07:11 +01001380 // Creates a java import for the jar with ".stubs" suffix
1381 props := struct {
1382 Name *string
1383 Soc_specific *bool
1384 Device_specific *bool
1385 Product_specific *bool
1386 System_ext_specific *bool
1387 Sdk_version *string
1388 Libs []string
1389 Jars []string
1390 Prefer *bool
1391 }{}
Paul Duffinc3091c82020-05-08 14:16:20 +01001392 props.Name = proptools.StringPtr(module.stubsLibraryModuleName(apiScope))
Paul Duffinbbb546b2020-04-09 00:07:11 +01001393 props.Sdk_version = scopeProperties.Sdk_version
1394 // Prepend any of the libs from the legacy public properties to the libs for each of the
1395 // scopes to avoid having to duplicate them in each scope.
1396 props.Libs = append(module.properties.Libs, scopeProperties.Libs...)
1397 props.Jars = scopeProperties.Jars
1398 if module.SocSpecific() {
1399 props.Soc_specific = proptools.BoolPtr(true)
1400 } else if module.DeviceSpecific() {
1401 props.Device_specific = proptools.BoolPtr(true)
1402 } else if module.ProductSpecific() {
1403 props.Product_specific = proptools.BoolPtr(true)
1404 } else if module.SystemExtSpecific() {
1405 props.System_ext_specific = proptools.BoolPtr(true)
1406 }
1407 // If the build should use prebuilt sdks then set prefer to true on the stubs library.
1408 // That will cause the prebuilt version of the stubs to override the source version.
1409 if mctx.Config().UnbundledBuildUsePrebuiltSdks() {
1410 props.Prefer = proptools.BoolPtr(true)
1411 }
1412 mctx.CreateModule(ImportFactory, &props)
1413}
1414
Paul Duffin6e7ecbf2020-05-08 15:01:19 +01001415func (module *sdkLibraryImport) createPrebuiltStubsSources(mctx android.DefaultableHookContext, apiScope *apiScope, scopeProperties *sdkLibraryScopeProperties) {
Paul Duffin3d1248c2020-04-09 00:10:17 +01001416 props := struct {
1417 Name *string
1418 Srcs []string
1419 }{}
Paul Duffinc3091c82020-05-08 14:16:20 +01001420 props.Name = proptools.StringPtr(module.stubsSourceModuleName(apiScope))
Paul Duffin3d1248c2020-04-09 00:10:17 +01001421 props.Srcs = scopeProperties.Stub_srcs
1422 mctx.CreateModule(PrebuiltStubsSourcesFactory, &props)
1423}
1424
Colin Cross79c7c262019-04-17 11:11:46 -07001425func (module *sdkLibraryImport) DepsMutator(ctx android.BottomUpMutatorContext) {
Paul Duffin46a26a82020-04-07 19:27:04 +01001426 for apiScope, scopeProperties := range module.scopeProperties {
Paul Duffin56d44902020-01-31 13:36:25 +00001427 if len(scopeProperties.Jars) == 0 {
1428 continue
1429 }
1430
1431 // Add dependencies to the prebuilt stubs library
Paul Duffinc3091c82020-05-08 14:16:20 +01001432 ctx.AddVariationDependencies(nil, apiScope.stubsTag, module.stubsLibraryModuleName(apiScope))
Paul Duffin56d44902020-01-31 13:36:25 +00001433 }
Colin Cross79c7c262019-04-17 11:11:46 -07001434}
1435
1436func (module *sdkLibraryImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1437 // Record the paths to the prebuilt stubs library.
1438 ctx.VisitDirectDeps(func(to android.Module) {
1439 tag := ctx.OtherModuleDependencyTag(to)
1440
Paul Duffin56d44902020-01-31 13:36:25 +00001441 if lib, ok := to.(Dependency); ok {
1442 if scopeTag, ok := tag.(scopeDependencyTag); ok {
1443 apiScope := scopeTag.apiScope
1444 scopePaths := module.getScopePaths(apiScope)
1445 scopePaths.stubsHeaderPath = lib.HeaderJars()
1446 }
Colin Cross79c7c262019-04-17 11:11:46 -07001447 }
1448 })
1449}
1450
Paul Duffin56d44902020-01-31 13:36:25 +00001451func (module *sdkLibraryImport) sdkJars(
1452 ctx android.BaseModuleContext,
1453 sdkVersion sdkSpec) android.Paths {
1454
Paul Duffin50061512020-01-21 16:31:05 +00001455 // If a specific numeric version has been requested then use prebuilt versions of the sdk.
1456 if sdkVersion.version.isNumbered() {
1457 return PrebuiltJars(ctx, module.BaseModuleName(), sdkVersion)
1458 }
1459
Paul Duffin56d44902020-01-31 13:36:25 +00001460 var apiScope *apiScope
1461 switch sdkVersion.kind {
1462 case sdkSystem:
1463 apiScope = apiScopeSystem
1464 case sdkTest:
1465 apiScope = apiScopeTest
1466 default:
1467 apiScope = apiScopePublic
1468 }
1469
1470 paths := module.getScopePaths(apiScope)
1471 return paths.stubsHeaderPath
1472}
1473
Colin Cross79c7c262019-04-17 11:11:46 -07001474// to satisfy SdkLibraryDependency interface
Jiyong Park6a927c42020-01-21 02:03:43 +09001475func (module *sdkLibraryImport) SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths {
Colin Cross79c7c262019-04-17 11:11:46 -07001476 // This module is just a wrapper for the prebuilt stubs.
Paul Duffin56d44902020-01-31 13:36:25 +00001477 return module.sdkJars(ctx, sdkVersion)
Colin Cross79c7c262019-04-17 11:11:46 -07001478}
1479
1480// to satisfy SdkLibraryDependency interface
Jiyong Park6a927c42020-01-21 02:03:43 +09001481func (module *sdkLibraryImport) SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths {
Colin Cross79c7c262019-04-17 11:11:46 -07001482 // This module is just a wrapper for the stubs.
Paul Duffin56d44902020-01-31 13:36:25 +00001483 return module.sdkJars(ctx, sdkVersion)
Colin Cross79c7c262019-04-17 11:11:46 -07001484}
Jiyong Parke3833882020-02-17 17:28:10 +09001485
1486//
1487// java_sdk_library_xml
1488//
1489type sdkLibraryXml struct {
1490 android.ModuleBase
1491 android.DefaultableModuleBase
1492 android.ApexModuleBase
1493
1494 properties sdkLibraryXmlProperties
1495
1496 outputFilePath android.OutputPath
1497 installDirPath android.InstallPath
1498}
1499
1500type sdkLibraryXmlProperties struct {
1501 // canonical name of the lib
1502 Lib_name *string
1503}
1504
1505// java_sdk_library_xml builds the permission xml file for a java_sdk_library.
1506// Not to be used directly by users. java_sdk_library internally uses this.
1507func sdkLibraryXmlFactory() android.Module {
1508 module := &sdkLibraryXml{}
1509
1510 module.AddProperties(&module.properties)
1511
1512 android.InitApexModule(module)
1513 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibCommon)
1514
1515 return module
1516}
1517
1518// from android.PrebuiltEtcModule
1519func (module *sdkLibraryXml) SubDir() string {
1520 return "permissions"
1521}
1522
1523// from android.PrebuiltEtcModule
1524func (module *sdkLibraryXml) OutputFile() android.OutputPath {
1525 return module.outputFilePath
1526}
1527
1528// from android.ApexModule
1529func (module *sdkLibraryXml) AvailableFor(what string) bool {
1530 return true
1531}
1532
1533func (module *sdkLibraryXml) DepsMutator(ctx android.BottomUpMutatorContext) {
1534 // do nothing
1535}
1536
1537// File path to the runtime implementation library
1538func (module *sdkLibraryXml) implPath() string {
1539 implName := proptools.String(module.properties.Lib_name)
1540 if apexName := module.ApexName(); apexName != "" {
1541 // TODO(b/146468504): ApexName() is only a soong module name, not apex name.
1542 // In most cases, this works fine. But when apex_name is set or override_apex is used
1543 // this can be wrong.
1544 return fmt.Sprintf("/apex/%s/javalib/%s.jar", apexName, implName)
1545 }
1546 partition := "system"
1547 if module.SocSpecific() {
1548 partition = "vendor"
1549 } else if module.DeviceSpecific() {
1550 partition = "odm"
1551 } else if module.ProductSpecific() {
1552 partition = "product"
1553 } else if module.SystemExtSpecific() {
1554 partition = "system_ext"
1555 }
1556 return "/" + partition + "/framework/" + implName + ".jar"
1557}
1558
1559func (module *sdkLibraryXml) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1560 libName := proptools.String(module.properties.Lib_name)
1561 xmlContent := fmt.Sprintf(permissionsTemplate, libName, module.implPath())
1562
1563 module.outputFilePath = android.PathForModuleOut(ctx, libName+".xml").OutputPath
1564 rule := android.NewRuleBuilder()
1565 rule.Command().
1566 Text("/bin/bash -c \"echo -e '" + xmlContent + "'\" > ").
1567 Output(module.outputFilePath)
1568
1569 rule.Build(pctx, ctx, "java_sdk_xml", "Permission XML")
1570
1571 module.installDirPath = android.PathForModuleInstall(ctx, "etc", module.SubDir())
1572}
1573
1574func (module *sdkLibraryXml) AndroidMkEntries() []android.AndroidMkEntries {
1575 if !module.IsForPlatform() {
1576 return []android.AndroidMkEntries{android.AndroidMkEntries{
1577 Disabled: true,
1578 }}
1579 }
1580
1581 return []android.AndroidMkEntries{android.AndroidMkEntries{
1582 Class: "ETC",
1583 OutputFile: android.OptionalPathForPath(module.outputFilePath),
1584 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
1585 func(entries *android.AndroidMkEntries) {
1586 entries.SetString("LOCAL_MODULE_TAGS", "optional")
1587 entries.SetString("LOCAL_MODULE_PATH", module.installDirPath.ToMakePath().String())
1588 entries.SetString("LOCAL_INSTALLED_MODULE_STEM", module.outputFilePath.Base())
1589 },
1590 },
1591 }}
1592}
Paul Duffindd46f712020-02-10 13:37:10 +00001593
1594type sdkLibrarySdkMemberType struct {
1595 android.SdkMemberTypeBase
1596}
1597
1598func (s *sdkLibrarySdkMemberType) AddDependencies(mctx android.BottomUpMutatorContext, dependencyTag blueprint.DependencyTag, names []string) {
1599 mctx.AddVariationDependencies(nil, dependencyTag, names...)
1600}
1601
1602func (s *sdkLibrarySdkMemberType) IsInstance(module android.Module) bool {
1603 _, ok := module.(*SdkLibrary)
1604 return ok
1605}
1606
1607func (s *sdkLibrarySdkMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule {
1608 return ctx.SnapshotBuilder().AddPrebuiltModule(member, "java_sdk_library_import")
1609}
1610
1611func (s *sdkLibrarySdkMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties {
1612 return &sdkLibrarySdkMemberProperties{}
1613}
1614
1615type sdkLibrarySdkMemberProperties struct {
1616 android.SdkMemberPropertiesBase
1617
1618 // Scope to per scope properties.
1619 Scopes map[*apiScope]scopeProperties
1620
1621 // Additional libraries that the exported stubs libraries depend upon.
1622 Libs []string
Paul Duffin3d1248c2020-04-09 00:10:17 +01001623
1624 // The Java stubs source files.
1625 Stub_srcs []string
Paul Duffindd46f712020-02-10 13:37:10 +00001626}
1627
1628type scopeProperties struct {
Paul Duffin1fd005d2020-04-09 01:08:11 +01001629 Jars android.Paths
1630 StubsSrcJar android.Path
1631 CurrentApiFile android.Path
1632 RemovedApiFile android.Path
1633 SdkVersion string
Paul Duffindd46f712020-02-10 13:37:10 +00001634}
1635
1636func (s *sdkLibrarySdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) {
1637 sdk := variant.(*SdkLibrary)
1638
1639 s.Scopes = make(map[*apiScope]scopeProperties)
1640 for _, apiScope := range allApiScopes {
1641 paths := sdk.getScopePaths(apiScope)
1642 jars := paths.stubsImplPath
1643 if len(jars) > 0 {
1644 properties := scopeProperties{}
1645 properties.Jars = jars
Paul Duffin780c5f42020-05-12 15:52:55 +01001646 properties.SdkVersion = sdk.sdkVersionForStubsLibrary(ctx.SdkModuleContext(), apiScope)
Paul Duffin3d1248c2020-04-09 00:10:17 +01001647 properties.StubsSrcJar = paths.stubsSrcJar
Paul Duffin1fd005d2020-04-09 01:08:11 +01001648 properties.CurrentApiFile = paths.currentApiFilePath
1649 properties.RemovedApiFile = paths.removedApiFilePath
Paul Duffindd46f712020-02-10 13:37:10 +00001650 s.Scopes[apiScope] = properties
1651 }
1652 }
1653
1654 s.Libs = sdk.properties.Libs
1655}
1656
1657func (s *sdkLibrarySdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) {
1658 for _, apiScope := range allApiScopes {
1659 if properties, ok := s.Scopes[apiScope]; ok {
1660 scopeSet := propertySet.AddPropertySet(apiScope.name)
1661
Paul Duffin3d1248c2020-04-09 00:10:17 +01001662 scopeDir := filepath.Join("sdk_library", s.OsPrefix(), apiScope.name)
1663
Paul Duffindd46f712020-02-10 13:37:10 +00001664 var jars []string
1665 for _, p := range properties.Jars {
Paul Duffin3d1248c2020-04-09 00:10:17 +01001666 dest := filepath.Join(scopeDir, ctx.Name()+"-stubs.jar")
Paul Duffindd46f712020-02-10 13:37:10 +00001667 ctx.SnapshotBuilder().CopyToSnapshot(p, dest)
1668 jars = append(jars, dest)
1669 }
1670 scopeSet.AddProperty("jars", jars)
1671
Paul Duffin3d1248c2020-04-09 00:10:17 +01001672 // Merge the stubs source jar into the snapshot zip so that when it is unpacked
1673 // the source files are also unpacked.
1674 snapshotRelativeDir := filepath.Join(scopeDir, ctx.Name()+"_stub_sources")
1675 ctx.SnapshotBuilder().UnzipToSnapshot(properties.StubsSrcJar, snapshotRelativeDir)
1676 scopeSet.AddProperty("stub_srcs", []string{snapshotRelativeDir})
1677
Paul Duffin1fd005d2020-04-09 01:08:11 +01001678 if properties.CurrentApiFile != nil {
1679 currentApiSnapshotPath := filepath.Join(scopeDir, ctx.Name()+".txt")
1680 ctx.SnapshotBuilder().CopyToSnapshot(properties.CurrentApiFile, currentApiSnapshotPath)
1681 scopeSet.AddProperty("current_api", currentApiSnapshotPath)
1682 }
1683
1684 if properties.RemovedApiFile != nil {
1685 removedApiSnapshotPath := filepath.Join(scopeDir, ctx.Name()+"-removed.txt")
1686 ctx.SnapshotBuilder().CopyToSnapshot(properties.CurrentApiFile, removedApiSnapshotPath)
1687 scopeSet.AddProperty("removed_api", removedApiSnapshotPath)
1688 }
1689
Paul Duffindd46f712020-02-10 13:37:10 +00001690 if properties.SdkVersion != "" {
1691 scopeSet.AddProperty("sdk_version", properties.SdkVersion)
1692 }
1693 }
1694 }
1695
1696 if len(s.Libs) > 0 {
1697 propertySet.AddPropertyWithTag("libs", s.Libs, ctx.SnapshotBuilder().SdkMemberReferencePropertyTag(false))
1698 }
1699}