blob: 6d3309de40d01d5f43d2695fff066c9ab7c67be3 [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 (
Paul Duffindd9d0742020-05-08 15:52:37 +010033 sdkXmlFileSuffix = ".xml"
34 permissionsTemplate = `<?xml version=\"1.0\" encoding=\"utf-8\"?>\n` +
Jooyung Han624058e2019-12-24 18:38:06 +090035 `<!-- Copyright (C) 2018 The Android Open Source Project\n` +
36 `\n` +
Jiyong Parke3833882020-02-17 17:28:10 +090037 ` Licensed under the Apache License, Version 2.0 (the \"License\");\n` +
Jooyung Han624058e2019-12-24 18:38:06 +090038 ` you may not use this file except in compliance with the License.\n` +
39 ` You may obtain a copy of the License at\n` +
40 `\n` +
41 ` http://www.apache.org/licenses/LICENSE-2.0\n` +
42 `\n` +
43 ` Unless required by applicable law or agreed to in writing, software\n` +
Jiyong Parke3833882020-02-17 17:28:10 +090044 ` distributed under the License is distributed on an \"AS IS\" BASIS,\n` +
Jooyung Han624058e2019-12-24 18:38:06 +090045 ` WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n` +
46 ` See the License for the specific language governing permissions and\n` +
47 ` limitations under the License.\n` +
48 `-->\n` +
49 `<permissions>\n` +
Jiyong Parke3833882020-02-17 17:28:10 +090050 ` <library name=\"%s\" file=\"%s\"/>\n` +
Jooyung Han624058e2019-12-24 18:38:06 +090051 `</permissions>\n`
Jiyong Parkc678ad32018-04-10 13:07:10 +090052)
53
Paul Duffind1b3a922020-01-22 11:57:20 +000054// A tag to associated a dependency with a specific api scope.
55type scopeDependencyTag struct {
56 blueprint.BaseDependencyTag
57 name string
58 apiScope *apiScope
Paul Duffinc8782502020-04-29 20:45:27 +010059
60 // Function for extracting appropriate path information from the dependency.
61 depInfoExtractor func(paths *scopePaths, dep android.Module) error
62}
63
64// Extract tag specific information from the dependency.
65func (tag scopeDependencyTag) extractDepInfo(ctx android.ModuleContext, dep android.Module, paths *scopePaths) {
66 err := tag.depInfoExtractor(paths, dep)
67 if err != nil {
68 ctx.ModuleErrorf("has an invalid {scopeDependencyTag: %s} dependency on module %s: %s", tag.name, ctx.OtherModuleName(dep), err.Error())
69 }
Paul Duffind1b3a922020-01-22 11:57:20 +000070}
71
72// Provides information about an api scope, e.g. public, system, test.
73type apiScope struct {
74 // The name of the api scope, e.g. public, system, test
75 name string
76
Paul Duffin97b53b82020-05-05 14:40:52 +010077 // The api scope that this scope extends.
78 extends *apiScope
79
Paul Duffin3375e352020-04-28 10:44:03 +010080 // The legacy enabled status for a specific scope can be dependent on other
81 // properties that have been specified on the library so it is provided by
82 // a function that can determine the status by examining those properties.
83 legacyEnabledStatus func(module *SdkLibrary) bool
84
85 // The default enabled status for non-legacy behavior, which is triggered by
86 // explicitly enabling at least one api scope.
87 defaultEnabledStatus bool
88
89 // Gets a pointer to the scope specific properties.
90 scopeSpecificProperties func(module *SdkLibrary) *ApiScopeProperties
91
Paul Duffin46a26a82020-04-07 19:27:04 +010092 // The name of the field in the dynamically created structure.
93 fieldName string
94
Paul Duffind1b3a922020-01-22 11:57:20 +000095 // The tag to use to depend on the stubs library module.
96 stubsTag scopeDependencyTag
97
Paul Duffin0ff08bd2020-04-29 13:30:54 +010098 // The tag to use to depend on the stubs source module (if separate from the API module).
99 stubsSourceTag scopeDependencyTag
100
101 // The tag to use to depend on the API file generating module (if separate from the stubs source module).
102 apiFileTag scopeDependencyTag
103
Paul Duffinc8782502020-04-29 20:45:27 +0100104 // The tag to use to depend on the stubs source and API module.
105 stubsSourceAndApiTag scopeDependencyTag
Paul Duffind1b3a922020-01-22 11:57:20 +0000106
107 // The scope specific prefix to add to the api file base of "current.txt" or "removed.txt".
108 apiFilePrefix string
109
110 // The scope specific prefix to add to the sdk library module name to construct a scope specific
111 // module name.
112 moduleSuffix string
113
Paul Duffind1b3a922020-01-22 11:57:20 +0000114 // SDK version that the stubs library is built against. Note that this is always
115 // *current. Older stubs library built with a numbered SDK version is created from
116 // the prebuilt jar.
117 sdkVersion string
Paul Duffin1fb487d2020-04-07 18:50:10 +0100118
119 // Extra arguments to pass to droidstubs for this scope.
120 droidstubsArgs []string
Anton Hansson6478ac12020-05-02 11:19:36 +0100121
Paul Duffin0ff08bd2020-04-29 13:30:54 +0100122 // The args that must be passed to droidstubs to generate the stubs source
123 // for this scope.
124 //
125 // The stubs source must include the definitions of everything that is in this
126 // api scope and all the scopes that this one extends.
127 droidstubsArgsForGeneratingStubsSource []string
128
129 // The args that must be passed to droidstubs to generate the API for this scope.
130 //
131 // The API only includes the additional members that this scope adds over the scope
132 // that it extends.
133 droidstubsArgsForGeneratingApi []string
134
135 // True if the stubs source and api can be created by the same metalava invocation.
136 createStubsSourceAndApiTogether bool
137
Anton Hansson6478ac12020-05-02 11:19:36 +0100138 // Whether the api scope can be treated as unstable, and should skip compat checks.
139 unstable bool
Paul Duffind1b3a922020-01-22 11:57:20 +0000140}
141
142// Initialize a scope, creating and adding appropriate dependency tags
143func initApiScope(scope *apiScope) *apiScope {
Paul Duffinc8782502020-04-29 20:45:27 +0100144 name := scope.name
145 scope.fieldName = proptools.FieldNameForProperty(name)
Paul Duffind1b3a922020-01-22 11:57:20 +0000146 scope.stubsTag = scopeDependencyTag{
Paul Duffinc8782502020-04-29 20:45:27 +0100147 name: name + "-stubs",
148 apiScope: scope,
149 depInfoExtractor: (*scopePaths).extractStubsLibraryInfoFromDependency,
Paul Duffind1b3a922020-01-22 11:57:20 +0000150 }
Paul Duffin0ff08bd2020-04-29 13:30:54 +0100151 scope.stubsSourceTag = scopeDependencyTag{
152 name: name + "-stubs-source",
153 apiScope: scope,
154 depInfoExtractor: (*scopePaths).extractStubsSourceInfoFromDep,
155 }
156 scope.apiFileTag = scopeDependencyTag{
157 name: name + "-api",
158 apiScope: scope,
159 depInfoExtractor: (*scopePaths).extractApiInfoFromDep,
160 }
Paul Duffinc8782502020-04-29 20:45:27 +0100161 scope.stubsSourceAndApiTag = scopeDependencyTag{
162 name: name + "-stubs-source-and-api",
163 apiScope: scope,
164 depInfoExtractor: (*scopePaths).extractStubsSourceAndApiInfoFromApiStubsProvider,
Paul Duffind1b3a922020-01-22 11:57:20 +0000165 }
Paul Duffin0ff08bd2020-04-29 13:30:54 +0100166
167 // To get the args needed to generate the stubs source append all the args from
168 // this scope and all the scopes it extends as each set of args adds additional
169 // members to the stubs.
170 var stubsSourceArgs []string
171 for s := scope; s != nil; s = s.extends {
172 stubsSourceArgs = append(stubsSourceArgs, s.droidstubsArgs...)
173 }
174 scope.droidstubsArgsForGeneratingStubsSource = stubsSourceArgs
175
176 // Currently the args needed to generate the API are the same as the args
177 // needed to add additional members.
178 apiArgs := scope.droidstubsArgs
179 scope.droidstubsArgsForGeneratingApi = apiArgs
180
181 // If the args needed to generate the stubs and API are the same then they
182 // can be generated in a single invocation of metalava, otherwise they will
183 // need separate invocations.
184 scope.createStubsSourceAndApiTogether = reflect.DeepEqual(stubsSourceArgs, apiArgs)
185
Paul Duffind1b3a922020-01-22 11:57:20 +0000186 return scope
187}
188
Paul Duffinc3091c82020-05-08 14:16:20 +0100189func (scope *apiScope) stubsLibraryModuleName(baseName string) string {
Paul Duffindd9d0742020-05-08 15:52:37 +0100190 return baseName + ".stubs" + scope.moduleSuffix
Paul Duffind1b3a922020-01-22 11:57:20 +0000191}
192
Paul Duffinc8782502020-04-29 20:45:27 +0100193func (scope *apiScope) stubsSourceModuleName(baseName string) string {
Paul Duffindd9d0742020-05-08 15:52:37 +0100194 return baseName + ".stubs.source" + scope.moduleSuffix
Paul Duffind1b3a922020-01-22 11:57:20 +0000195}
196
Paul Duffin0ff08bd2020-04-29 13:30:54 +0100197func (scope *apiScope) apiModuleName(baseName string) string {
Paul Duffindd9d0742020-05-08 15:52:37 +0100198 return baseName + ".api" + scope.moduleSuffix
Paul Duffin0ff08bd2020-04-29 13:30:54 +0100199}
200
Paul Duffin3375e352020-04-28 10:44:03 +0100201func (scope *apiScope) String() string {
202 return scope.name
203}
204
Paul Duffind1b3a922020-01-22 11:57:20 +0000205type apiScopes []*apiScope
206
207func (scopes apiScopes) Strings(accessor func(*apiScope) string) []string {
208 var list []string
209 for _, scope := range scopes {
210 list = append(list, accessor(scope))
211 }
212 return list
213}
214
Jiyong Parkc678ad32018-04-10 13:07:10 +0900215var (
Paul Duffind1b3a922020-01-22 11:57:20 +0000216 apiScopePublic = initApiScope(&apiScope{
Paul Duffin3375e352020-04-28 10:44:03 +0100217 name: "public",
218
219 // Public scope is enabled by default for both legacy and non-legacy modes.
220 legacyEnabledStatus: func(module *SdkLibrary) bool {
221 return true
222 },
223 defaultEnabledStatus: true,
224
225 scopeSpecificProperties: func(module *SdkLibrary) *ApiScopeProperties {
226 return &module.sdkLibraryProperties.Public
227 },
Paul Duffind1b3a922020-01-22 11:57:20 +0000228 sdkVersion: "current",
229 })
230 apiScopeSystem = initApiScope(&apiScope{
Paul Duffin3375e352020-04-28 10:44:03 +0100231 name: "system",
232 extends: apiScopePublic,
233 legacyEnabledStatus: (*SdkLibrary).generateTestAndSystemScopesByDefault,
234 scopeSpecificProperties: func(module *SdkLibrary) *ApiScopeProperties {
235 return &module.sdkLibraryProperties.System
236 },
Anton Hansson6affb1f2020-04-28 16:47:41 +0100237 apiFilePrefix: "system-",
Paul Duffindd9d0742020-05-08 15:52:37 +0100238 moduleSuffix: ".system",
Anton Hansson6affb1f2020-04-28 16:47:41 +0100239 sdkVersion: "system_current",
Paul Duffin0d543642020-04-29 22:18:41 +0100240 droidstubsArgs: []string{"-showAnnotation android.annotation.SystemApi\\(client=android.annotation.SystemApi.Client.PRIVILEGED_APPS\\)"},
Paul Duffind1b3a922020-01-22 11:57:20 +0000241 })
242 apiScopeTest = initApiScope(&apiScope{
Paul Duffin3375e352020-04-28 10:44:03 +0100243 name: "test",
244 extends: apiScopePublic,
245 legacyEnabledStatus: (*SdkLibrary).generateTestAndSystemScopesByDefault,
246 scopeSpecificProperties: func(module *SdkLibrary) *ApiScopeProperties {
247 return &module.sdkLibraryProperties.Test
248 },
Anton Hansson6affb1f2020-04-28 16:47:41 +0100249 apiFilePrefix: "test-",
Paul Duffindd9d0742020-05-08 15:52:37 +0100250 moduleSuffix: ".test",
Anton Hansson6affb1f2020-04-28 16:47:41 +0100251 sdkVersion: "test_current",
252 droidstubsArgs: []string{"-showAnnotation android.annotation.TestApi"},
Anton Hansson6478ac12020-05-02 11:19:36 +0100253 unstable: true,
Paul Duffind1b3a922020-01-22 11:57:20 +0000254 })
Paul Duffin8f265b92020-04-28 14:13:56 +0100255 apiScopeModuleLib = initApiScope(&apiScope{
256 name: "module_lib",
257 extends: apiScopeSystem,
258 // Module_lib scope is disabled by default in legacy mode.
259 //
260 // Enabling this would break existing usages.
261 legacyEnabledStatus: func(module *SdkLibrary) bool {
262 return false
263 },
264 scopeSpecificProperties: func(module *SdkLibrary) *ApiScopeProperties {
265 return &module.sdkLibraryProperties.Module_lib
266 },
267 apiFilePrefix: "module-lib-",
268 moduleSuffix: ".module_lib",
269 sdkVersion: "module_current",
270 droidstubsArgs: []string{
271 "--show-annotation android.annotation.SystemApi\\(client=android.annotation.SystemApi.Client.MODULE_LIBRARIES\\)",
272 },
273 })
Paul Duffind1b3a922020-01-22 11:57:20 +0000274 allApiScopes = apiScopes{
275 apiScopePublic,
276 apiScopeSystem,
277 apiScopeTest,
Paul Duffin8f265b92020-04-28 14:13:56 +0100278 apiScopeModuleLib,
Paul Duffind1b3a922020-01-22 11:57:20 +0000279 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900280)
281
Jiyong Park82484c02018-04-23 21:41:26 +0900282var (
283 javaSdkLibrariesLock sync.Mutex
284)
285
Jiyong Parkc678ad32018-04-10 13:07:10 +0900286// TODO: these are big features that are currently missing
Jiyong Park1be96912018-05-28 18:02:19 +0900287// 1) disallowing linking to the runtime shared lib
288// 2) HTML generation
Jiyong Parkc678ad32018-04-10 13:07:10 +0900289
290func init() {
Paul Duffin43dc1cc2019-12-19 11:18:54 +0000291 RegisterSdkLibraryBuildComponents(android.InitRegistrationContext)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900292
Jiyong Park82484c02018-04-23 21:41:26 +0900293 android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) {
294 javaSdkLibraries := javaSdkLibraries(ctx.Config())
295 sort.Strings(*javaSdkLibraries)
296 ctx.Strict("JAVA_SDK_LIBRARIES", strings.Join(*javaSdkLibraries, " "))
297 })
Paul Duffindd46f712020-02-10 13:37:10 +0000298
299 // Register sdk member types.
300 android.RegisterSdkMemberType(&sdkLibrarySdkMemberType{
301 android.SdkMemberTypeBase{
302 PropertyName: "java_sdk_libs",
303 SupportsSdk: true,
304 },
305 })
Jiyong Parkc678ad32018-04-10 13:07:10 +0900306}
307
Paul Duffin43dc1cc2019-12-19 11:18:54 +0000308func RegisterSdkLibraryBuildComponents(ctx android.RegistrationContext) {
309 ctx.RegisterModuleType("java_sdk_library", SdkLibraryFactory)
310 ctx.RegisterModuleType("java_sdk_library_import", sdkLibraryImportFactory)
311}
312
Paul Duffin3375e352020-04-28 10:44:03 +0100313// Properties associated with each api scope.
314type ApiScopeProperties struct {
315 // Indicates whether the api surface is generated.
316 //
317 // If this is set for any scope then all scopes must explicitly specify if they
318 // are enabled. This is to prevent new usages from depending on legacy behavior.
319 //
320 // Otherwise, if this is not set for any scope then the default behavior is
321 // scope specific so please refer to the scope specific property documentation.
322 Enabled *bool
323}
324
Jiyong Parkc678ad32018-04-10 13:07:10 +0900325type sdkLibraryProperties struct {
Paul Duffin4911a892020-04-29 23:35:13 +0100326 // Visibility for stubs library modules. If not specified then defaults to the
327 // visibility property.
328 Stubs_library_visibility []string
329
330 // Visibility for stubs source modules. If not specified then defaults to the
331 // visibility property.
332 Stubs_source_visibility []string
333
Sundong Ahnf043cf62018-06-25 16:04:37 +0900334 // List of Java libraries that will be in the classpath when building stubs
335 Stub_only_libs []string `android:"arch_variant"`
336
Paul Duffin7a586d32019-12-30 17:09:34 +0000337 // list of package names that will be documented and publicized as API.
338 // This allows the API to be restricted to a subset of the source files provided.
339 // If this is unspecified then all the source files will be treated as being part
340 // of the API.
Jiyong Parkc678ad32018-04-10 13:07:10 +0900341 Api_packages []string
342
Jiyong Park5a2c9d72018-05-01 22:25:41 +0900343 // list of package names that must be hidden from the API
344 Hidden_api_packages []string
345
Paul Duffin749f98f2019-12-30 17:23:46 +0000346 // the relative path to the directory containing the api specification files.
347 // Defaults to "api".
348 Api_dir *string
349
Paul Duffin43db9be2019-12-30 17:35:49 +0000350 // If set to true there is no runtime library.
351 Api_only *bool
352
Paul Duffin11512472019-02-11 15:55:17 +0000353 // local files that are used within user customized droiddoc options.
354 Droiddoc_option_files []string
355
356 // additional droiddoc options
357 // Available variables for substitution:
358 //
359 // $(location <label>): the path to the droiddoc_option_files with name <label>
Sundong Ahndd567f92018-07-31 17:19:11 +0900360 Droiddoc_options []string
361
Sundong Ahn054b19a2018-10-19 13:46:09 +0900362 // a list of top-level directories containing files to merge qualifier annotations
363 // (i.e. those intended to be included in the stubs written) from.
364 Merge_annotations_dirs []string
365
366 // a list of top-level directories containing Java stub files to merge show/hide annotations from.
367 Merge_inclusion_annotations_dirs []string
368
369 // If set to true, the path of dist files is apistubs/core. Defaults to false.
370 Core_lib *bool
371
Sundong Ahn80a87b32019-05-13 15:02:50 +0900372 // don't create dist rules.
373 No_dist *bool `blueprint:"mutated"`
374
Paul Duffin3375e352020-04-28 10:44:03 +0100375 // indicates whether system and test apis should be generated.
376 Generate_system_and_test_apis bool `blueprint:"mutated"`
377
378 // The properties specific to the public api scope
379 //
380 // Unless explicitly specified by using public.enabled the public api scope is
381 // enabled by default in both legacy and non-legacy mode.
382 Public ApiScopeProperties
383
384 // The properties specific to the system api scope
385 //
386 // In legacy mode the system api scope is enabled by default when sdk_version
387 // is set to something other than "none".
388 //
389 // In non-legacy mode the system api scope is disabled by default.
390 System ApiScopeProperties
391
392 // The properties specific to the test api scope
393 //
394 // In legacy mode the test api scope is enabled by default when sdk_version
395 // is set to something other than "none".
396 //
397 // In non-legacy mode the test api scope is disabled by default.
398 Test ApiScopeProperties
Paul Duffin37e0b772019-12-30 17:20:10 +0000399
Paul Duffin8f265b92020-04-28 14:13:56 +0100400 // The properties specific to the module_lib api scope
401 //
402 // Unless explicitly specified by using test.enabled the module_lib api scope is
403 // disabled by default.
404 Module_lib ApiScopeProperties
405
Paul Duffin160fe412020-05-10 19:32:20 +0100406 // Properties related to api linting.
407 Api_lint struct {
408 // Enable api linting.
409 Enabled *bool
410 }
411
Jiyong Parkc678ad32018-04-10 13:07:10 +0900412 // TODO: determines whether to create HTML doc or not
413 //Html_doc *bool
414}
415
Paul Duffind1b3a922020-01-22 11:57:20 +0000416type scopePaths struct {
Paul Duffin1fd005d2020-04-09 01:08:11 +0100417 stubsHeaderPath android.Paths
418 stubsImplPath android.Paths
419 currentApiFilePath android.Path
420 removedApiFilePath android.Path
421 stubsSrcJar android.Path
Paul Duffind1b3a922020-01-22 11:57:20 +0000422}
423
Paul Duffinc8782502020-04-29 20:45:27 +0100424func (paths *scopePaths) extractStubsLibraryInfoFromDependency(dep android.Module) error {
425 if lib, ok := dep.(Dependency); ok {
426 paths.stubsHeaderPath = lib.HeaderJars()
427 paths.stubsImplPath = lib.ImplementationJars()
428 return nil
429 } else {
430 return fmt.Errorf("expected module that implements Dependency, e.g. java_library")
431 }
432}
433
Paul Duffin0ff08bd2020-04-29 13:30:54 +0100434func (paths *scopePaths) treatDepAsApiStubsProvider(dep android.Module, action func(provider ApiStubsProvider)) error {
435 if apiStubsProvider, ok := dep.(ApiStubsProvider); ok {
436 action(apiStubsProvider)
Paul Duffinc8782502020-04-29 20:45:27 +0100437 return nil
438 } else {
439 return fmt.Errorf("expected module that implements ApiStubsProvider, e.g. droidstubs")
440 }
441}
442
Paul Duffin0ff08bd2020-04-29 13:30:54 +0100443func (paths *scopePaths) extractApiInfoFromApiStubsProvider(provider ApiStubsProvider) {
444 paths.currentApiFilePath = provider.ApiFilePath()
445 paths.removedApiFilePath = provider.RemovedApiFilePath()
446}
447
448func (paths *scopePaths) extractApiInfoFromDep(dep android.Module) error {
449 return paths.treatDepAsApiStubsProvider(dep, func(provider ApiStubsProvider) {
450 paths.extractApiInfoFromApiStubsProvider(provider)
451 })
452}
453
454func (paths *scopePaths) extractStubsSourceInfoFromApiStubsProviders(provider ApiStubsProvider) {
455 paths.stubsSrcJar = provider.StubsSrcJar()
456}
457
458func (paths *scopePaths) extractStubsSourceInfoFromDep(dep android.Module) error {
459 return paths.treatDepAsApiStubsProvider(dep, func(provider ApiStubsProvider) {
460 paths.extractStubsSourceInfoFromApiStubsProviders(provider)
461 })
462}
463
464func (paths *scopePaths) extractStubsSourceAndApiInfoFromApiStubsProvider(dep android.Module) error {
465 return paths.treatDepAsApiStubsProvider(dep, func(provider ApiStubsProvider) {
466 paths.extractApiInfoFromApiStubsProvider(provider)
467 paths.extractStubsSourceInfoFromApiStubsProviders(provider)
468 })
469}
470
471type commonToSdkLibraryAndImportProperties struct {
Paul Duffin1b1e8062020-05-08 13:44:43 +0100472 // The naming scheme to use for the components that this module creates.
473 //
474 // If not specified then it defaults to "default", which is currently the only
475 // allowable value.
476 //
477 // This is a temporary mechanism to simplify conversion from separate modules for each
478 // component that follow a different naming pattern to the default one.
479 //
480 // TODO(b/155480189) - Remove once naming inconsistencies have been resolved.
Paul Duffin0ff08bd2020-04-29 13:30:54 +0100481 Naming_scheme *string
482}
483
Paul Duffin56d44902020-01-31 13:36:25 +0000484// Common code between sdk library and sdk library import
485type commonToSdkLibraryAndImport struct {
Paul Duffinc3091c82020-05-08 14:16:20 +0100486 moduleBase *android.ModuleBase
487
Paul Duffin56d44902020-01-31 13:36:25 +0000488 scopePaths map[*apiScope]*scopePaths
Paul Duffin1b1e8062020-05-08 13:44:43 +0100489
490 namingScheme sdkLibraryComponentNamingScheme
491
492 commonProperties commonToSdkLibraryAndImportProperties
Paul Duffin56d44902020-01-31 13:36:25 +0000493}
494
Paul Duffinc3091c82020-05-08 14:16:20 +0100495func (c *commonToSdkLibraryAndImport) initCommon(moduleBase *android.ModuleBase) {
496 c.moduleBase = moduleBase
Paul Duffin1b1e8062020-05-08 13:44:43 +0100497
498 moduleBase.AddProperties(&c.commonProperties)
499}
500
501func (c *commonToSdkLibraryAndImport) initCommonAfterDefaultsApplied(ctx android.DefaultableHookContext) bool {
502 schemeProperty := proptools.StringDefault(c.commonProperties.Naming_scheme, "default")
503 switch schemeProperty {
504 case "default":
505 c.namingScheme = &defaultNamingScheme{}
506 default:
507 ctx.PropertyErrorf("naming_scheme", "expected 'default' but was %q", schemeProperty)
508 return false
509 }
510
511 return true
Paul Duffinc3091c82020-05-08 14:16:20 +0100512}
513
514// Name of the java_library module that compiles the stubs source.
515func (c *commonToSdkLibraryAndImport) stubsLibraryModuleName(apiScope *apiScope) string {
Paul Duffin1b1e8062020-05-08 13:44:43 +0100516 return c.namingScheme.stubsLibraryModuleName(apiScope, c.moduleBase.BaseModuleName())
Paul Duffinc3091c82020-05-08 14:16:20 +0100517}
518
519// Name of the droidstubs module that generates the stubs source and may also
520// generate/check the API.
521func (c *commonToSdkLibraryAndImport) stubsSourceModuleName(apiScope *apiScope) string {
Paul Duffin1b1e8062020-05-08 13:44:43 +0100522 return c.namingScheme.stubsSourceModuleName(apiScope, c.moduleBase.BaseModuleName())
Paul Duffinc3091c82020-05-08 14:16:20 +0100523}
524
525// Name of the droidstubs module that generates/checks the API. Only used if it
526// requires different arts to the stubs source generating module.
527func (c *commonToSdkLibraryAndImport) apiModuleName(apiScope *apiScope) string {
Paul Duffin1b1e8062020-05-08 13:44:43 +0100528 return c.namingScheme.apiModuleName(apiScope, c.moduleBase.BaseModuleName())
Paul Duffinc3091c82020-05-08 14:16:20 +0100529}
530
Paul Duffin56d44902020-01-31 13:36:25 +0000531func (c *commonToSdkLibraryAndImport) getScopePaths(scope *apiScope) *scopePaths {
532 if c.scopePaths == nil {
533 c.scopePaths = make(map[*apiScope]*scopePaths)
534 }
535 paths := c.scopePaths[scope]
536 if paths == nil {
537 paths = &scopePaths{}
538 c.scopePaths[scope] = paths
539 }
540
541 return paths
542}
543
Inseob Kimc0907f12019-02-08 21:00:45 +0900544type SdkLibrary struct {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900545 Library
Jiyong Parkc678ad32018-04-10 13:07:10 +0900546
Sundong Ahn054b19a2018-10-19 13:46:09 +0900547 sdkLibraryProperties sdkLibraryProperties
Jiyong Parkc678ad32018-04-10 13:07:10 +0900548
Paul Duffin3375e352020-04-28 10:44:03 +0100549 // Map from api scope to the scope specific property structure.
550 scopeToProperties map[*apiScope]*ApiScopeProperties
551
Paul Duffin56d44902020-01-31 13:36:25 +0000552 commonToSdkLibraryAndImport
Jiyong Parkc678ad32018-04-10 13:07:10 +0900553}
554
Inseob Kimc0907f12019-02-08 21:00:45 +0900555var _ Dependency = (*SdkLibrary)(nil)
556var _ SdkLibraryDependency = (*SdkLibrary)(nil)
Colin Cross897d2ed2019-02-11 14:03:51 -0800557
Paul Duffin3375e352020-04-28 10:44:03 +0100558func (module *SdkLibrary) generateTestAndSystemScopesByDefault() bool {
559 return module.sdkLibraryProperties.Generate_system_and_test_apis
560}
561
562func (module *SdkLibrary) getGeneratedApiScopes(ctx android.EarlyModuleContext) apiScopes {
563 // Check to see if any scopes have been explicitly enabled. If any have then all
564 // must be.
565 anyScopesExplicitlyEnabled := false
566 for _, scope := range allApiScopes {
567 scopeProperties := module.scopeToProperties[scope]
568 if scopeProperties.Enabled != nil {
569 anyScopesExplicitlyEnabled = true
570 break
571 }
Paul Duffind1b3a922020-01-22 11:57:20 +0000572 }
Paul Duffin3375e352020-04-28 10:44:03 +0100573
574 var generatedScopes apiScopes
575 enabledScopes := make(map[*apiScope]struct{})
576 for _, scope := range allApiScopes {
577 scopeProperties := module.scopeToProperties[scope]
578 // If any scopes are explicitly enabled then ignore the legacy enabled status.
579 // This is to ensure that any new usages of this module type do not rely on legacy
580 // behaviour.
581 defaultEnabledStatus := false
582 if anyScopesExplicitlyEnabled {
583 defaultEnabledStatus = scope.defaultEnabledStatus
584 } else {
585 defaultEnabledStatus = scope.legacyEnabledStatus(module)
586 }
587 enabled := proptools.BoolDefault(scopeProperties.Enabled, defaultEnabledStatus)
588 if enabled {
589 enabledScopes[scope] = struct{}{}
590 generatedScopes = append(generatedScopes, scope)
591 }
592 }
593
594 // Now check to make sure that any scope that is extended by an enabled scope is also
595 // enabled.
596 for _, scope := range allApiScopes {
597 if _, ok := enabledScopes[scope]; ok {
598 extends := scope.extends
599 if extends != nil {
600 if _, ok := enabledScopes[extends]; !ok {
601 ctx.ModuleErrorf("enabled api scope %q depends on disabled scope %q", scope, extends)
602 }
603 }
604 }
605 }
606
607 return generatedScopes
Paul Duffind1b3a922020-01-22 11:57:20 +0000608}
609
Paul Duffine74ac732020-02-06 13:51:46 +0000610var xmlPermissionsFileTag = dependencyTag{name: "xml-permissions-file"}
611
Jiyong Parke3833882020-02-17 17:28:10 +0900612func IsXmlPermissionsFileDepTag(depTag blueprint.DependencyTag) bool {
613 if dt, ok := depTag.(dependencyTag); ok {
614 return dt == xmlPermissionsFileTag
615 }
616 return false
617}
618
Inseob Kimc0907f12019-02-08 21:00:45 +0900619func (module *SdkLibrary) DepsMutator(ctx android.BottomUpMutatorContext) {
Paul Duffin3375e352020-04-28 10:44:03 +0100620 for _, apiScope := range module.getGeneratedApiScopes(ctx) {
Paul Duffind1b3a922020-01-22 11:57:20 +0000621 // Add dependencies to the stubs library
Paul Duffinc3091c82020-05-08 14:16:20 +0100622 ctx.AddVariationDependencies(nil, apiScope.stubsTag, module.stubsLibraryModuleName(apiScope))
Paul Duffind1b3a922020-01-22 11:57:20 +0000623
Paul Duffin0ff08bd2020-04-29 13:30:54 +0100624 // If the stubs source and API cannot be generated together then add an additional dependency on
625 // the API module.
626 if apiScope.createStubsSourceAndApiTogether {
627 // Add a dependency on the stubs source in order to access both stubs source and api information.
Paul Duffinc3091c82020-05-08 14:16:20 +0100628 ctx.AddVariationDependencies(nil, apiScope.stubsSourceAndApiTag, module.stubsSourceModuleName(apiScope))
Paul Duffin0ff08bd2020-04-29 13:30:54 +0100629 } else {
630 // Add separate dependencies on the creators of the stubs source files and the API.
Paul Duffinc3091c82020-05-08 14:16:20 +0100631 ctx.AddVariationDependencies(nil, apiScope.stubsSourceTag, module.stubsSourceModuleName(apiScope))
632 ctx.AddVariationDependencies(nil, apiScope.apiFileTag, module.apiModuleName(apiScope))
Paul Duffin0ff08bd2020-04-29 13:30:54 +0100633 }
Sundong Ahn054b19a2018-10-19 13:46:09 +0900634 }
635
Paul Duffine74ac732020-02-06 13:51:46 +0000636 if !proptools.Bool(module.sdkLibraryProperties.Api_only) {
637 // Add dependency to the rule for generating the xml permissions file
Jiyong Parke3833882020-02-17 17:28:10 +0900638 ctx.AddDependency(module, xmlPermissionsFileTag, module.xmlFileName())
Paul Duffine74ac732020-02-06 13:51:46 +0000639 }
640
Sundong Ahn054b19a2018-10-19 13:46:09 +0900641 module.Library.deps(ctx)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900642}
643
Inseob Kimc0907f12019-02-08 21:00:45 +0900644func (module *SdkLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Paul Duffin43db9be2019-12-30 17:35:49 +0000645 // Don't build an implementation library if this is api only.
646 if !proptools.Bool(module.sdkLibraryProperties.Api_only) {
647 module.Library.GenerateAndroidBuildActions(ctx)
648 }
Sundong Ahn054b19a2018-10-19 13:46:09 +0900649
Sundong Ahn57368eb2018-07-06 11:20:23 +0900650 // Record the paths to the header jars of the library (stubs and impl).
Paul Duffind1b3a922020-01-22 11:57:20 +0000651 // When this java_sdk_library is depended upon from others via "libs" property,
Jiyong Parkc678ad32018-04-10 13:07:10 +0900652 // the recorded paths will be returned depending on the link type of the caller.
653 ctx.VisitDirectDeps(func(to android.Module) {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900654 tag := ctx.OtherModuleDependencyTag(to)
655
Paul Duffinc8782502020-04-29 20:45:27 +0100656 // Extract information from any of the scope specific dependencies.
657 if scopeTag, ok := tag.(scopeDependencyTag); ok {
658 apiScope := scopeTag.apiScope
659 scopePaths := module.getScopePaths(apiScope)
660
661 // Extract information from the dependency. The exact information extracted
662 // is determined by the nature of the dependency which is determined by the tag.
663 scopeTag.extractDepInfo(ctx, to, scopePaths)
Sundong Ahn20e998b2018-07-24 11:19:26 +0900664 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900665 })
666}
667
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900668func (module *SdkLibrary) AndroidMkEntries() []android.AndroidMkEntries {
Paul Duffin43db9be2019-12-30 17:35:49 +0000669 if proptools.Bool(module.sdkLibraryProperties.Api_only) {
670 return nil
671 }
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900672 entriesList := module.Library.AndroidMkEntries()
673 entries := &entriesList[0]
Jaewoong Jungb0c127c2019-08-29 14:56:03 -0700674 entries.Required = append(entries.Required, module.xmlFileName())
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900675 return entriesList
Jiyong Park82484c02018-04-23 21:41:26 +0900676}
677
Jiyong Parkc678ad32018-04-10 13:07:10 +0900678// Module name of the runtime implementation library
Inseob Kimc0907f12019-02-08 21:00:45 +0900679func (module *SdkLibrary) implName() string {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900680 return module.BaseModuleName()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900681}
682
Jiyong Parkc678ad32018-04-10 13:07:10 +0900683// Module name of the XML file for the lib
Inseob Kimc0907f12019-02-08 21:00:45 +0900684func (module *SdkLibrary) xmlFileName() string {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900685 return module.BaseModuleName() + sdkXmlFileSuffix
686}
687
Anton Hansson5fd5d242020-03-27 19:43:19 +0000688// The dist path of the stub artifacts
689func (module *SdkLibrary) apiDistPath(apiScope *apiScope) string {
690 if module.ModuleBase.Owner() != "" {
691 return path.Join("apistubs", module.ModuleBase.Owner(), apiScope.name)
692 } else if Bool(module.sdkLibraryProperties.Core_lib) {
693 return path.Join("apistubs", "core", apiScope.name)
694 } else {
695 return path.Join("apistubs", "android", apiScope.name)
696 }
697}
698
Paul Duffin12ceb462019-12-24 20:31:31 +0000699// Get the sdk version for use when compiling the stubs library.
Paul Duffin780c5f42020-05-12 15:52:55 +0100700func (module *SdkLibrary) sdkVersionForStubsLibrary(mctx android.EarlyModuleContext, apiScope *apiScope) string {
Paul Duffin12ceb462019-12-24 20:31:31 +0000701 sdkDep := decodeSdkDep(mctx, sdkContext(&module.Library))
702 if sdkDep.hasStandardLibs() {
703 // If building against a standard sdk then use the sdk version appropriate for the scope.
Paul Duffind1b3a922020-01-22 11:57:20 +0000704 return apiScope.sdkVersion
Paul Duffin12ceb462019-12-24 20:31:31 +0000705 } else {
706 // Otherwise, use no system module.
707 return "none"
708 }
709}
710
Paul Duffind1b3a922020-01-22 11:57:20 +0000711func (module *SdkLibrary) latestApiFilegroupName(apiScope *apiScope) string {
712 return ":" + module.BaseModuleName() + ".api." + apiScope.name + ".latest"
Jiyong Park58c518b2018-05-12 22:29:12 +0900713}
Jiyong Parkc678ad32018-04-10 13:07:10 +0900714
Paul Duffind1b3a922020-01-22 11:57:20 +0000715func (module *SdkLibrary) latestRemovedApiFilegroupName(apiScope *apiScope) string {
716 return ":" + module.BaseModuleName() + "-removed.api." + apiScope.name + ".latest"
Jiyong Parkc678ad32018-04-10 13:07:10 +0900717}
718
719// Creates a static java library that has API stubs
Paul Duffinf0229202020-04-29 16:47:28 +0100720func (module *SdkLibrary) createStubsLibrary(mctx android.DefaultableHookContext, apiScope *apiScope) {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900721 props := struct {
Sundong Ahn0d7dff42019-12-04 12:53:44 +0900722 Name *string
Paul Duffin4911a892020-04-29 23:35:13 +0100723 Visibility []string
Sundong Ahn0d7dff42019-12-04 12:53:44 +0900724 Srcs []string
Paul Duffin367ab912019-12-23 19:40:36 +0000725 Installable *bool
Sundong Ahn0d7dff42019-12-04 12:53:44 +0900726 Sdk_version *string
Paul Duffin12ceb462019-12-24 20:31:31 +0000727 System_modules *string
Paul Duffinab8da5d2020-02-07 16:12:04 +0000728 Patch_module *string
Sundong Ahn0d7dff42019-12-04 12:53:44 +0900729 Libs []string
730 Soc_specific *bool
731 Device_specific *bool
732 Product_specific *bool
733 System_ext_specific *bool
734 Compile_dex *bool
Sundong Ahn0d7dff42019-12-04 12:53:44 +0900735 Java_version *string
736 Product_variables struct {
Jiyong Park82484c02018-04-23 21:41:26 +0900737 Pdk struct {
738 Enabled *bool
739 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900740 }
Sundong Ahn054b19a2018-10-19 13:46:09 +0900741 Openjdk9 struct {
742 Srcs []string
743 Javacflags []string
744 }
Anton Hansson5fd5d242020-03-27 19:43:19 +0000745 Dist struct {
746 Targets []string
747 Dest *string
748 Dir *string
749 Tag *string
750 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900751 }{}
752
Paul Duffinc3091c82020-05-08 14:16:20 +0100753 props.Name = proptools.StringPtr(module.stubsLibraryModuleName(apiScope))
Paul Duffin4911a892020-04-29 23:35:13 +0100754
755 // If stubs_library_visibility is not set then the created module will use the
756 // visibility of this module.
757 visibility := module.sdkLibraryProperties.Stubs_library_visibility
758 props.Visibility = visibility
759
Jiyong Parkc678ad32018-04-10 13:07:10 +0900760 // sources are generated from the droiddoc
Paul Duffinc3091c82020-05-08 14:16:20 +0100761 props.Srcs = []string{":" + module.stubsSourceModuleName(apiScope)}
Paul Duffin12ceb462019-12-24 20:31:31 +0000762 sdkVersion := module.sdkVersionForStubsLibrary(mctx, apiScope)
Paul Duffin52d398a2019-06-11 12:31:14 +0100763 props.Sdk_version = proptools.StringPtr(sdkVersion)
Paul Duffin12ceb462019-12-24 20:31:31 +0000764 props.System_modules = module.Library.Module.deviceProperties.System_modules
Paul Duffinab8da5d2020-02-07 16:12:04 +0000765 props.Patch_module = module.Library.Module.properties.Patch_module
Paul Duffin367ab912019-12-23 19:40:36 +0000766 props.Installable = proptools.BoolPtr(false)
Sundong Ahn054b19a2018-10-19 13:46:09 +0900767 props.Libs = module.sdkLibraryProperties.Stub_only_libs
Jiyong Park82484c02018-04-23 21:41:26 +0900768 props.Product_variables.Pdk.Enabled = proptools.BoolPtr(false)
Sundong Ahn054b19a2018-10-19 13:46:09 +0900769 props.Openjdk9.Srcs = module.Library.Module.properties.Openjdk9.Srcs
770 props.Openjdk9.Javacflags = module.Library.Module.properties.Openjdk9.Javacflags
771 props.Java_version = module.Library.Module.properties.Java_version
772 if module.Library.Module.deviceProperties.Compile_dex != nil {
773 props.Compile_dex = module.Library.Module.deviceProperties.Compile_dex
Sundong Ahndd567f92018-07-31 17:19:11 +0900774 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900775
776 if module.SocSpecific() {
777 props.Soc_specific = proptools.BoolPtr(true)
778 } else if module.DeviceSpecific() {
779 props.Device_specific = proptools.BoolPtr(true)
780 } else if module.ProductSpecific() {
781 props.Product_specific = proptools.BoolPtr(true)
Sundong Ahn0d7dff42019-12-04 12:53:44 +0900782 } else if module.SystemExtSpecific() {
783 props.System_ext_specific = proptools.BoolPtr(true)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900784 }
Anton Hansson5fd5d242020-03-27 19:43:19 +0000785 // Dist the class jar artifact for sdk builds.
786 if !Bool(module.sdkLibraryProperties.No_dist) {
787 props.Dist.Targets = []string{"sdk", "win_sdk"}
788 props.Dist.Dest = proptools.StringPtr(fmt.Sprintf("%v.jar", module.BaseModuleName()))
789 props.Dist.Dir = proptools.StringPtr(module.apiDistPath(apiScope))
790 props.Dist.Tag = proptools.StringPtr(".jar")
791 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900792
Colin Cross84dfc3d2019-09-25 11:33:01 -0700793 mctx.CreateModule(LibraryFactory, &props)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900794}
795
Paul Duffin6d0886e2020-04-07 18:49:53 +0100796// Creates a droidstubs module that creates stubs source files from the given full source
Paul Duffinc8782502020-04-29 20:45:27 +0100797// files and also updates and checks the API specification files.
Paul Duffin0ff08bd2020-04-29 13:30:54 +0100798func (module *SdkLibrary) createStubsSourcesAndApi(mctx android.DefaultableHookContext, apiScope *apiScope, name string, createStubSources, createApi bool, scopeSpecificDroidstubsArgs []string) {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900799 props := struct {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900800 Name *string
Paul Duffin4911a892020-04-29 23:35:13 +0100801 Visibility []string
Sundong Ahn054b19a2018-10-19 13:46:09 +0900802 Srcs []string
803 Installable *bool
Paul Duffin52d398a2019-06-11 12:31:14 +0100804 Sdk_version *string
Paul Duffin12ceb462019-12-24 20:31:31 +0000805 System_modules *string
Sundong Ahn054b19a2018-10-19 13:46:09 +0900806 Libs []string
Paul Duffin11512472019-02-11 15:55:17 +0000807 Arg_files []string
Sundong Ahn054b19a2018-10-19 13:46:09 +0900808 Args *string
Sundong Ahn054b19a2018-10-19 13:46:09 +0900809 Java_version *string
810 Merge_annotations_dirs []string
811 Merge_inclusion_annotations_dirs []string
Paul Duffin0ff08bd2020-04-29 13:30:54 +0100812 Generate_stubs *bool
Sundong Ahn054b19a2018-10-19 13:46:09 +0900813 Check_api struct {
Inseob Kim38449af2019-02-28 14:24:05 +0900814 Current ApiToCheck
815 Last_released ApiToCheck
816 Ignore_missing_latest_api *bool
Paul Duffin160fe412020-05-10 19:32:20 +0100817
818 Api_lint struct {
819 Enabled *bool
820 New_since *string
821 Baseline_file *string
822 }
Jiyong Park58c518b2018-05-12 22:29:12 +0900823 }
Sundong Ahn1b92c822018-05-29 11:35:17 +0900824 Aidl struct {
825 Include_dirs []string
826 Local_include_dirs []string
827 }
Anton Hansson5fd5d242020-03-27 19:43:19 +0000828 Dist struct {
829 Targets []string
830 Dest *string
831 Dir *string
832 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900833 }{}
834
Paul Duffin7b78b4d2020-04-28 14:08:32 +0100835 // The stubs source processing uses the same compile time classpath when extracting the
836 // API from the implementation library as it does when compiling it. i.e. the same
837 // * sdk version
838 // * system_modules
839 // * libs (static_libs/libs)
Paul Duffin250e6192019-06-07 10:44:37 +0100840
Paul Duffin0ff08bd2020-04-29 13:30:54 +0100841 props.Name = proptools.StringPtr(name)
Paul Duffin4911a892020-04-29 23:35:13 +0100842
843 // If stubs_source_visibility is not set then the created module will use the
844 // visibility of this module.
845 visibility := module.sdkLibraryProperties.Stubs_source_visibility
846 props.Visibility = visibility
847
Sundong Ahn054b19a2018-10-19 13:46:09 +0900848 props.Srcs = append(props.Srcs, module.Library.Module.properties.Srcs...)
Paul Duffin7b78b4d2020-04-28 14:08:32 +0100849 props.Sdk_version = module.Library.Module.deviceProperties.Sdk_version
Paul Duffin12ceb462019-12-24 20:31:31 +0000850 props.System_modules = module.Library.Module.deviceProperties.System_modules
Jiyong Parkc678ad32018-04-10 13:07:10 +0900851 props.Installable = proptools.BoolPtr(false)
Sundong Ahne6f0b052018-06-05 16:46:14 +0900852 // A droiddoc module has only one Libs property and doesn't distinguish between
853 // shared libs and static libs. So we need to add both of these libs to Libs property.
Sundong Ahn054b19a2018-10-19 13:46:09 +0900854 props.Libs = module.Library.Module.properties.Libs
855 props.Libs = append(props.Libs, module.Library.Module.properties.Static_libs...)
856 props.Aidl.Include_dirs = module.Library.Module.deviceProperties.Aidl.Include_dirs
857 props.Aidl.Local_include_dirs = module.Library.Module.deviceProperties.Aidl.Local_include_dirs
Sundong Ahn054b19a2018-10-19 13:46:09 +0900858 props.Java_version = module.Library.Module.properties.Java_version
Jiyong Parkc678ad32018-04-10 13:07:10 +0900859
Sundong Ahn054b19a2018-10-19 13:46:09 +0900860 props.Merge_annotations_dirs = module.sdkLibraryProperties.Merge_annotations_dirs
861 props.Merge_inclusion_annotations_dirs = module.sdkLibraryProperties.Merge_inclusion_annotations_dirs
862
Paul Duffin6d0886e2020-04-07 18:49:53 +0100863 droidstubsArgs := []string{}
Paul Duffin235ffff2019-12-24 10:41:30 +0000864 if len(module.sdkLibraryProperties.Api_packages) != 0 {
Paul Duffin6d0886e2020-04-07 18:49:53 +0100865 droidstubsArgs = append(droidstubsArgs, "--stub-packages "+strings.Join(module.sdkLibraryProperties.Api_packages, ":"))
Paul Duffin235ffff2019-12-24 10:41:30 +0000866 }
867 if len(module.sdkLibraryProperties.Hidden_api_packages) != 0 {
Paul Duffin6d0886e2020-04-07 18:49:53 +0100868 droidstubsArgs = append(droidstubsArgs,
Paul Duffin235ffff2019-12-24 10:41:30 +0000869 android.JoinWithPrefix(module.sdkLibraryProperties.Hidden_api_packages, " --hide-package "))
870 }
Paul Duffin6d0886e2020-04-07 18:49:53 +0100871 droidstubsArgs = append(droidstubsArgs, module.sdkLibraryProperties.Droiddoc_options...)
Paul Duffin235ffff2019-12-24 10:41:30 +0000872 disabledWarnings := []string{
873 "MissingPermission",
874 "BroadcastBehavior",
875 "HiddenSuperclass",
876 "DeprecationMismatch",
877 "UnavailableSymbol",
878 "SdkConstant",
879 "HiddenTypeParameter",
880 "Todo",
881 "Typo",
882 }
Paul Duffin6d0886e2020-04-07 18:49:53 +0100883 droidstubsArgs = append(droidstubsArgs, android.JoinWithPrefix(disabledWarnings, "--hide "))
Sundong Ahnfb2721f2018-09-17 13:23:09 +0900884
Paul Duffin0ff08bd2020-04-29 13:30:54 +0100885 if !createStubSources {
886 // Stubs are not required.
887 props.Generate_stubs = proptools.BoolPtr(false)
888 }
889
Paul Duffin1fb487d2020-04-07 18:50:10 +0100890 // Add in scope specific arguments.
Paul Duffin0ff08bd2020-04-29 13:30:54 +0100891 droidstubsArgs = append(droidstubsArgs, scopeSpecificDroidstubsArgs...)
Paul Duffin11512472019-02-11 15:55:17 +0000892 props.Arg_files = module.sdkLibraryProperties.Droiddoc_option_files
Paul Duffin6d0886e2020-04-07 18:49:53 +0100893 props.Args = proptools.StringPtr(strings.Join(droidstubsArgs, " "))
Jiyong Parkc678ad32018-04-10 13:07:10 +0900894
Paul Duffin0ff08bd2020-04-29 13:30:54 +0100895 if createApi {
896 // List of APIs identified from the provided source files are created. They are later
897 // compared against to the not-yet-released (a.k.a current) list of APIs and to the
898 // last-released (a.k.a numbered) list of API.
899 currentApiFileName := apiScope.apiFilePrefix + "current.txt"
900 removedApiFileName := apiScope.apiFilePrefix + "removed.txt"
901 apiDir := module.getApiDir()
902 currentApiFileName = path.Join(apiDir, currentApiFileName)
903 removedApiFileName = path.Join(apiDir, removedApiFileName)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900904
Paul Duffin0ff08bd2020-04-29 13:30:54 +0100905 // check against the not-yet-release API
906 props.Check_api.Current.Api_file = proptools.StringPtr(currentApiFileName)
907 props.Check_api.Current.Removed_api_file = proptools.StringPtr(removedApiFileName)
Jiyong Park58c518b2018-05-12 22:29:12 +0900908
Paul Duffin0ff08bd2020-04-29 13:30:54 +0100909 if !apiScope.unstable {
910 // check against the latest released API
911 latestApiFilegroupName := proptools.StringPtr(module.latestApiFilegroupName(apiScope))
912 props.Check_api.Last_released.Api_file = latestApiFilegroupName
913 props.Check_api.Last_released.Removed_api_file = proptools.StringPtr(
914 module.latestRemovedApiFilegroupName(apiScope))
915 props.Check_api.Ignore_missing_latest_api = proptools.BoolPtr(true)
Paul Duffin160fe412020-05-10 19:32:20 +0100916
Paul Duffin0ff08bd2020-04-29 13:30:54 +0100917 if proptools.Bool(module.sdkLibraryProperties.Api_lint.Enabled) {
918 // Enable api lint.
919 props.Check_api.Api_lint.Enabled = proptools.BoolPtr(true)
920 props.Check_api.Api_lint.New_since = latestApiFilegroupName
Paul Duffin160fe412020-05-10 19:32:20 +0100921
Paul Duffin0ff08bd2020-04-29 13:30:54 +0100922 // If it exists then pass a lint-baseline.txt through to droidstubs.
923 baselinePath := path.Join(apiDir, apiScope.apiFilePrefix+"lint-baseline.txt")
924 baselinePathRelativeToRoot := path.Join(mctx.ModuleDir(), baselinePath)
925 paths, err := mctx.GlobWithDeps(baselinePathRelativeToRoot, nil)
926 if err != nil {
927 mctx.ModuleErrorf("error checking for presence of %s: %s", baselinePathRelativeToRoot, err)
928 }
929 if len(paths) == 1 {
930 props.Check_api.Api_lint.Baseline_file = proptools.StringPtr(baselinePath)
931 } else if len(paths) != 0 {
932 mctx.ModuleErrorf("error checking for presence of %s: expected one path, found: %v", baselinePathRelativeToRoot, paths)
933 }
Paul Duffin160fe412020-05-10 19:32:20 +0100934 }
935 }
Jiyong Park58c518b2018-05-12 22:29:12 +0900936
Paul Duffin0ff08bd2020-04-29 13:30:54 +0100937 // Dist the api txt artifact for sdk builds.
938 if !Bool(module.sdkLibraryProperties.No_dist) {
939 props.Dist.Targets = []string{"sdk", "win_sdk"}
940 props.Dist.Dest = proptools.StringPtr(fmt.Sprintf("%v.txt", module.BaseModuleName()))
941 props.Dist.Dir = proptools.StringPtr(path.Join(module.apiDistPath(apiScope), "api"))
942 }
Anton Hansson5fd5d242020-03-27 19:43:19 +0000943 }
944
Colin Cross84dfc3d2019-09-25 11:33:01 -0700945 mctx.CreateModule(DroidstubsFactory, &props)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900946}
947
Jooyung Han5e9013b2020-03-10 06:23:13 +0900948func (module *SdkLibrary) DepIsInSameApex(mctx android.BaseModuleContext, dep android.Module) bool {
949 depTag := mctx.OtherModuleDependencyTag(dep)
950 if depTag == xmlPermissionsFileTag {
951 return true
952 }
953 return module.Library.DepIsInSameApex(mctx, dep)
954}
955
Jiyong Parkc678ad32018-04-10 13:07:10 +0900956// Creates the xml file that publicizes the runtime library
Paul Duffinf0229202020-04-29 16:47:28 +0100957func (module *SdkLibrary) createXmlFile(mctx android.DefaultableHookContext) {
Jiyong Parke3833882020-02-17 17:28:10 +0900958 props := struct {
Sundong Ahn0d7dff42019-12-04 12:53:44 +0900959 Name *string
Jiyong Parke3833882020-02-17 17:28:10 +0900960 Lib_name *string
Sundong Ahn0d7dff42019-12-04 12:53:44 +0900961 Soc_specific *bool
962 Device_specific *bool
963 Product_specific *bool
964 System_ext_specific *bool
Jooyung Han5e9013b2020-03-10 06:23:13 +0900965 Apex_available []string
Jiyong Parke3833882020-02-17 17:28:10 +0900966 }{
Jooyung Han5e9013b2020-03-10 06:23:13 +0900967 Name: proptools.StringPtr(module.xmlFileName()),
968 Lib_name: proptools.StringPtr(module.BaseModuleName()),
969 Apex_available: module.ApexProperties.Apex_available,
Jiyong Parkc678ad32018-04-10 13:07:10 +0900970 }
Jiyong Parke3833882020-02-17 17:28:10 +0900971
972 if module.SocSpecific() {
973 props.Soc_specific = proptools.BoolPtr(true)
974 } else if module.DeviceSpecific() {
975 props.Device_specific = proptools.BoolPtr(true)
976 } else if module.ProductSpecific() {
977 props.Product_specific = proptools.BoolPtr(true)
978 } else if module.SystemExtSpecific() {
979 props.System_ext_specific = proptools.BoolPtr(true)
980 }
981
982 mctx.CreateModule(sdkLibraryXmlFactory, &props)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900983}
984
Paul Duffin50061512020-01-21 16:31:05 +0000985func PrebuiltJars(ctx android.BaseModuleContext, baseName string, s sdkSpec) android.Paths {
Jiyong Park6a927c42020-01-21 02:03:43 +0900986 var ver sdkVersion
987 var kind sdkKind
988 if s.usePrebuilt(ctx) {
989 ver = s.version
990 kind = s.kind
Jiyong Parkc678ad32018-04-10 13:07:10 +0900991 } else {
Jiyong Park6a927c42020-01-21 02:03:43 +0900992 // We don't have prebuilt SDK for the specific sdkVersion.
993 // Instead of breaking the build, fallback to use "system_current"
994 ver = sdkVersionCurrent
995 kind = sdkSystem
Sundong Ahn054b19a2018-10-19 13:46:09 +0900996 }
Jiyong Park6a927c42020-01-21 02:03:43 +0900997
998 dir := filepath.Join("prebuilts", "sdk", ver.String(), kind.String())
Paul Duffin50061512020-01-21 16:31:05 +0000999 jar := filepath.Join(dir, baseName+".jar")
Sundong Ahn054b19a2018-10-19 13:46:09 +09001000 jarPath := android.ExistentPathForSource(ctx, jar)
Sundong Ahnae418ac2019-02-28 15:01:28 +09001001 if !jarPath.Valid() {
Colin Cross07c88562020-01-07 09:34:44 -08001002 if ctx.Config().AllowMissingDependencies() {
1003 return android.Paths{android.PathForSource(ctx, jar)}
1004 } else {
Jiyong Park6a927c42020-01-21 02:03:43 +09001005 ctx.PropertyErrorf("sdk_library", "invalid sdk version %q, %q does not exist", s.raw, jar)
Colin Cross07c88562020-01-07 09:34:44 -08001006 }
Sundong Ahnae418ac2019-02-28 15:01:28 +09001007 return nil
1008 }
Sundong Ahn054b19a2018-10-19 13:46:09 +09001009 return android.Paths{jarPath.Path()}
1010}
1011
Paul Duffind1b3a922020-01-22 11:57:20 +00001012func (module *SdkLibrary) sdkJars(
1013 ctx android.BaseModuleContext,
1014 sdkVersion sdkSpec,
1015 headerJars bool) android.Paths {
1016
Paul Duffin50061512020-01-21 16:31:05 +00001017 // If a specific numeric version has been requested then use prebuilt versions of the sdk.
1018 if sdkVersion.version.isNumbered() {
1019 return PrebuiltJars(ctx, module.BaseModuleName(), sdkVersion)
Sundong Ahn054b19a2018-10-19 13:46:09 +09001020 } else {
Paul Duffind1b3a922020-01-22 11:57:20 +00001021 if !sdkVersion.specified() {
1022 if headerJars {
1023 return module.Library.HeaderJars()
1024 } else {
1025 return module.Library.ImplementationJars()
1026 }
1027 }
Paul Duffin726d23c2020-01-22 16:30:37 +00001028 var apiScope *apiScope
Jiyong Park6a927c42020-01-21 02:03:43 +09001029 switch sdkVersion.kind {
1030 case sdkSystem:
Paul Duffin726d23c2020-01-22 16:30:37 +00001031 apiScope = apiScopeSystem
1032 case sdkTest:
1033 apiScope = apiScopeTest
Jiyong Park6a927c42020-01-21 02:03:43 +09001034 case sdkPrivate:
Sundong Ahn054b19a2018-10-19 13:46:09 +09001035 return module.Library.HeaderJars()
Jiyong Park6a927c42020-01-21 02:03:43 +09001036 default:
Paul Duffin726d23c2020-01-22 16:30:37 +00001037 apiScope = apiScopePublic
Paul Duffind1b3a922020-01-22 11:57:20 +00001038 }
1039
Paul Duffin726d23c2020-01-22 16:30:37 +00001040 paths := module.getScopePaths(apiScope)
Paul Duffind1b3a922020-01-22 11:57:20 +00001041 if headerJars {
1042 return paths.stubsHeaderPath
1043 } else {
1044 return paths.stubsImplPath
Sundong Ahn054b19a2018-10-19 13:46:09 +09001045 }
Jiyong Parkc678ad32018-04-10 13:07:10 +09001046 }
1047}
1048
Sundong Ahn241cd372018-07-13 16:16:44 +09001049// to satisfy SdkLibraryDependency interface
Paul Duffind1b3a922020-01-22 11:57:20 +00001050func (module *SdkLibrary) SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths {
1051 return module.sdkJars(ctx, sdkVersion, true /*headerJars*/)
1052}
1053
1054// to satisfy SdkLibraryDependency interface
Jiyong Park6a927c42020-01-21 02:03:43 +09001055func (module *SdkLibrary) SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths {
Paul Duffind1b3a922020-01-22 11:57:20 +00001056 return module.sdkJars(ctx, sdkVersion, false /*headerJars*/)
Sundong Ahn241cd372018-07-13 16:16:44 +09001057}
1058
Sundong Ahn80a87b32019-05-13 15:02:50 +09001059func (module *SdkLibrary) SetNoDist() {
1060 module.sdkLibraryProperties.No_dist = proptools.BoolPtr(true)
1061}
1062
Colin Cross571cccf2019-02-04 11:22:08 -08001063var javaSdkLibrariesKey = android.NewOnceKey("javaSdkLibraries")
1064
Jiyong Park82484c02018-04-23 21:41:26 +09001065func javaSdkLibraries(config android.Config) *[]string {
Colin Cross571cccf2019-02-04 11:22:08 -08001066 return config.Once(javaSdkLibrariesKey, func() interface{} {
Jiyong Park82484c02018-04-23 21:41:26 +09001067 return &[]string{}
1068 }).(*[]string)
1069}
1070
Paul Duffin749f98f2019-12-30 17:23:46 +00001071func (module *SdkLibrary) getApiDir() string {
1072 return proptools.StringDefault(module.sdkLibraryProperties.Api_dir, "api")
1073}
1074
Jiyong Parkc678ad32018-04-10 13:07:10 +09001075// For a java_sdk_library module, create internal modules for stubs, docs,
1076// runtime libs and xml file. If requested, the stubs and docs are created twice
1077// once for public API level and once for system API level
Paul Duffinf0229202020-04-29 16:47:28 +01001078func (module *SdkLibrary) CreateInternalModules(mctx android.DefaultableHookContext) {
1079 // If the module has been disabled then don't create any child modules.
1080 if !module.Enabled() {
1081 return
1082 }
1083
Inseob Kim6e93ac92019-03-21 17:43:49 +09001084 if len(module.Library.Module.properties.Srcs) == 0 {
Inseob Kimc0907f12019-02-08 21:00:45 +09001085 mctx.PropertyErrorf("srcs", "java_sdk_library must specify srcs")
Jooyung Han58f26ab2019-12-18 15:34:32 +09001086 return
Inseob Kimc0907f12019-02-08 21:00:45 +09001087 }
1088
Paul Duffin37e0b772019-12-30 17:20:10 +00001089 // If this builds against standard libraries (i.e. is not part of the core libraries)
1090 // then assume it provides both system and test apis. Otherwise, assume it does not and
1091 // also assume it does not contribute to the dist build.
1092 sdkDep := decodeSdkDep(mctx, sdkContext(&module.Library))
1093 hasSystemAndTestApis := sdkDep.hasStandardLibs()
Paul Duffin3375e352020-04-28 10:44:03 +01001094 module.sdkLibraryProperties.Generate_system_and_test_apis = hasSystemAndTestApis
Paul Duffin37e0b772019-12-30 17:20:10 +00001095 module.sdkLibraryProperties.No_dist = proptools.BoolPtr(!hasSystemAndTestApis)
1096
Inseob Kim8098faa2019-03-18 10:19:51 +09001097 missing_current_api := false
1098
Paul Duffin3375e352020-04-28 10:44:03 +01001099 generatedScopes := module.getGeneratedApiScopes(mctx)
Paul Duffind1b3a922020-01-22 11:57:20 +00001100
Paul Duffin749f98f2019-12-30 17:23:46 +00001101 apiDir := module.getApiDir()
Paul Duffin3375e352020-04-28 10:44:03 +01001102 for _, scope := range generatedScopes {
Inseob Kim8098faa2019-03-18 10:19:51 +09001103 for _, api := range []string{"current.txt", "removed.txt"} {
Paul Duffind1b3a922020-01-22 11:57:20 +00001104 path := path.Join(mctx.ModuleDir(), apiDir, scope.apiFilePrefix+api)
Inseob Kim8098faa2019-03-18 10:19:51 +09001105 p := android.ExistentPathForSource(mctx, path)
1106 if !p.Valid() {
1107 mctx.ModuleErrorf("Current api file %#v doesn't exist", path)
1108 missing_current_api = true
1109 }
1110 }
1111 }
1112
1113 if missing_current_api {
1114 script := "build/soong/scripts/gen-java-current-api-files.sh"
1115 p := android.ExistentPathForSource(mctx, script)
1116
1117 if !p.Valid() {
1118 panic(fmt.Sprintf("script file %s doesn't exist", script))
1119 }
1120
1121 mctx.ModuleErrorf("One or more current api files are missing. "+
1122 "You can update them by:\n"+
Paul Duffin37e0b772019-12-30 17:20:10 +00001123 "%s %q %s && m update-api",
Paul Duffind1b3a922020-01-22 11:57:20 +00001124 script, filepath.Join(mctx.ModuleDir(), apiDir),
Paul Duffin3375e352020-04-28 10:44:03 +01001125 strings.Join(generatedScopes.Strings(func(s *apiScope) string { return s.apiFilePrefix }), " "))
Inseob Kim8098faa2019-03-18 10:19:51 +09001126 return
1127 }
1128
Paul Duffin3375e352020-04-28 10:44:03 +01001129 for _, scope := range generatedScopes {
Paul Duffin0ff08bd2020-04-29 13:30:54 +01001130 stubsSourceArgs := scope.droidstubsArgsForGeneratingStubsSource
Paul Duffinc3091c82020-05-08 14:16:20 +01001131 stubsSourceModuleName := module.stubsSourceModuleName(scope)
Paul Duffin0ff08bd2020-04-29 13:30:54 +01001132
1133 // If the args needed to generate the stubs and API are the same then they
1134 // can be generated in a single invocation of metalava, otherwise they will
1135 // need separate invocations.
1136 if scope.createStubsSourceAndApiTogether {
1137 // Use the stubs source name for legacy reasons.
1138 module.createStubsSourcesAndApi(mctx, scope, stubsSourceModuleName, true, true, stubsSourceArgs)
1139 } else {
1140 module.createStubsSourcesAndApi(mctx, scope, stubsSourceModuleName, true, false, stubsSourceArgs)
1141
1142 apiArgs := scope.droidstubsArgsForGeneratingApi
Paul Duffinc3091c82020-05-08 14:16:20 +01001143 apiName := module.apiModuleName(scope)
Paul Duffin0ff08bd2020-04-29 13:30:54 +01001144 module.createStubsSourcesAndApi(mctx, scope, apiName, false, true, apiArgs)
1145 }
1146
Paul Duffind1b3a922020-01-22 11:57:20 +00001147 module.createStubsLibrary(mctx, scope)
Inseob Kimc0907f12019-02-08 21:00:45 +09001148 }
1149
Paul Duffin43db9be2019-12-30 17:35:49 +00001150 if !proptools.Bool(module.sdkLibraryProperties.Api_only) {
1151 // for runtime
1152 module.createXmlFile(mctx)
1153
1154 // record java_sdk_library modules so that they are exported to make
1155 javaSdkLibraries := javaSdkLibraries(mctx.Config())
1156 javaSdkLibrariesLock.Lock()
1157 defer javaSdkLibrariesLock.Unlock()
1158 *javaSdkLibraries = append(*javaSdkLibraries, module.BaseModuleName())
1159 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001160}
1161
1162func (module *SdkLibrary) InitSdkLibraryProperties() {
Sundong Ahn054b19a2018-10-19 13:46:09 +09001163 module.AddProperties(
1164 &module.sdkLibraryProperties,
1165 &module.Library.Module.properties,
1166 &module.Library.Module.dexpreoptProperties,
1167 &module.Library.Module.deviceProperties,
1168 &module.Library.Module.protoProperties,
1169 )
1170
1171 module.Library.Module.properties.Installable = proptools.BoolPtr(true)
1172 module.Library.Module.deviceProperties.IsSDKLibrary = true
Inseob Kimc0907f12019-02-08 21:00:45 +09001173}
Sundong Ahn054b19a2018-10-19 13:46:09 +09001174
Paul Duffin1b1e8062020-05-08 13:44:43 +01001175// Defines how to name the individual component modules the sdk library creates.
1176type sdkLibraryComponentNamingScheme interface {
1177 stubsLibraryModuleName(scope *apiScope, baseName string) string
1178
1179 stubsSourceModuleName(scope *apiScope, baseName string) string
1180
1181 apiModuleName(scope *apiScope, baseName string) string
1182}
1183
1184type defaultNamingScheme struct {
1185}
1186
1187func (s *defaultNamingScheme) stubsLibraryModuleName(scope *apiScope, baseName string) string {
1188 return scope.stubsLibraryModuleName(baseName)
1189}
1190
1191func (s *defaultNamingScheme) stubsSourceModuleName(scope *apiScope, baseName string) string {
1192 return scope.stubsSourceModuleName(baseName)
1193}
1194
1195func (s *defaultNamingScheme) apiModuleName(scope *apiScope, baseName string) string {
1196 return scope.apiModuleName(baseName)
1197}
1198
1199var _ sdkLibraryComponentNamingScheme = (*defaultNamingScheme)(nil)
1200
Jaewoong Jung4f158ee2019-07-11 10:05:35 -07001201// java_sdk_library is a special Java library that provides optional platform APIs to apps.
1202// In practice, it can be viewed as a combination of several modules: 1) stubs library that clients
1203// are linked against to, 2) droiddoc module that internally generates API stubs source files,
1204// 3) the real runtime shared library that implements the APIs, and 4) XML file for adding
1205// the runtime lib to the classpath at runtime if requested via <uses-library>.
Inseob Kimc0907f12019-02-08 21:00:45 +09001206func SdkLibraryFactory() android.Module {
1207 module := &SdkLibrary{}
Paul Duffinc3091c82020-05-08 14:16:20 +01001208
1209 // Initialize information common between source and prebuilt.
1210 module.initCommon(&module.ModuleBase)
1211
Inseob Kimc0907f12019-02-08 21:00:45 +09001212 module.InitSdkLibraryProperties()
Jooyung Han58f26ab2019-12-18 15:34:32 +09001213 android.InitApexModule(module)
Sundong Ahn054b19a2018-10-19 13:46:09 +09001214 InitJavaModule(module, android.HostAndDeviceSupported)
Paul Duffin3375e352020-04-28 10:44:03 +01001215
1216 // Initialize the map from scope to scope specific properties.
1217 scopeToProperties := make(map[*apiScope]*ApiScopeProperties)
1218 for _, scope := range allApiScopes {
1219 scopeToProperties[scope] = scope.scopeSpecificProperties(module)
1220 }
1221 module.scopeToProperties = scopeToProperties
1222
Paul Duffin4911a892020-04-29 23:35:13 +01001223 // Add the properties containing visibility rules so that they are checked.
1224 android.AddVisibilityProperty(module, "stubs_library_visibility", &module.sdkLibraryProperties.Stubs_library_visibility)
1225 android.AddVisibilityProperty(module, "stubs_source_visibility", &module.sdkLibraryProperties.Stubs_source_visibility)
1226
Paul Duffin1b1e8062020-05-08 13:44:43 +01001227 module.SetDefaultableHook(func(ctx android.DefaultableHookContext) {
1228 if module.initCommonAfterDefaultsApplied(ctx) {
1229 module.CreateInternalModules(ctx)
1230 }
1231 })
Jiyong Parkc678ad32018-04-10 13:07:10 +09001232 return module
1233}
Colin Cross79c7c262019-04-17 11:11:46 -07001234
1235//
1236// SDK library prebuilts
1237//
1238
Paul Duffin56d44902020-01-31 13:36:25 +00001239// Properties associated with each api scope.
1240type sdkLibraryScopeProperties struct {
Colin Cross79c7c262019-04-17 11:11:46 -07001241 Jars []string `android:"path"`
1242
1243 Sdk_version *string
1244
Colin Cross79c7c262019-04-17 11:11:46 -07001245 // List of shared java libs that this module has dependencies to
1246 Libs []string
Paul Duffin3d1248c2020-04-09 00:10:17 +01001247
Paul Duffinc8782502020-04-29 20:45:27 +01001248 // The stubs source.
Paul Duffin3d1248c2020-04-09 00:10:17 +01001249 Stub_srcs []string `android:"path"`
Paul Duffin1fd005d2020-04-09 01:08:11 +01001250
1251 // The current.txt
1252 Current_api string `android:"path"`
1253
1254 // The removed.txt
1255 Removed_api string `android:"path"`
Colin Cross79c7c262019-04-17 11:11:46 -07001256}
1257
Paul Duffin56d44902020-01-31 13:36:25 +00001258type sdkLibraryImportProperties struct {
Paul Duffinfcfd7912020-01-31 17:54:30 +00001259 // List of shared java libs, common to all scopes, that this module has
1260 // dependencies to
1261 Libs []string
Paul Duffin56d44902020-01-31 13:36:25 +00001262}
1263
Colin Cross79c7c262019-04-17 11:11:46 -07001264type sdkLibraryImport struct {
1265 android.ModuleBase
1266 android.DefaultableModuleBase
1267 prebuilt android.Prebuilt
Paul Duffindd46f712020-02-10 13:37:10 +00001268 android.ApexModuleBase
1269 android.SdkBase
Colin Cross79c7c262019-04-17 11:11:46 -07001270
1271 properties sdkLibraryImportProperties
1272
Paul Duffin46a26a82020-04-07 19:27:04 +01001273 // Map from api scope to the scope specific property structure.
1274 scopeProperties map[*apiScope]*sdkLibraryScopeProperties
1275
Paul Duffin56d44902020-01-31 13:36:25 +00001276 commonToSdkLibraryAndImport
Colin Cross79c7c262019-04-17 11:11:46 -07001277}
1278
1279var _ SdkLibraryDependency = (*sdkLibraryImport)(nil)
1280
Paul Duffin46a26a82020-04-07 19:27:04 +01001281// The type of a structure that contains a field of type sdkLibraryScopeProperties
1282// for each apiscope in allApiScopes, e.g. something like:
1283// struct {
1284// Public sdkLibraryScopeProperties
1285// System sdkLibraryScopeProperties
1286// ...
1287// }
1288var allScopeStructType = createAllScopePropertiesStructType()
1289
1290// Dynamically create a structure type for each apiscope in allApiScopes.
1291func createAllScopePropertiesStructType() reflect.Type {
1292 var fields []reflect.StructField
1293 for _, apiScope := range allApiScopes {
1294 field := reflect.StructField{
1295 Name: apiScope.fieldName,
1296 Type: reflect.TypeOf(sdkLibraryScopeProperties{}),
1297 }
1298 fields = append(fields, field)
1299 }
1300
1301 return reflect.StructOf(fields)
1302}
1303
1304// Create an instance of the scope specific structure type and return a map
1305// from apiscope to a pointer to each scope specific field.
1306func createPropertiesInstance() (interface{}, map[*apiScope]*sdkLibraryScopeProperties) {
1307 allScopePropertiesPtr := reflect.New(allScopeStructType)
1308 allScopePropertiesStruct := allScopePropertiesPtr.Elem()
1309 scopeProperties := make(map[*apiScope]*sdkLibraryScopeProperties)
1310
1311 for _, apiScope := range allApiScopes {
1312 field := allScopePropertiesStruct.FieldByName(apiScope.fieldName)
1313 scopeProperties[apiScope] = field.Addr().Interface().(*sdkLibraryScopeProperties)
1314 }
1315
1316 return allScopePropertiesPtr.Interface(), scopeProperties
1317}
1318
Jaewoong Jung4f158ee2019-07-11 10:05:35 -07001319// java_sdk_library_import imports a prebuilt java_sdk_library.
Colin Cross79c7c262019-04-17 11:11:46 -07001320func sdkLibraryImportFactory() android.Module {
1321 module := &sdkLibraryImport{}
1322
Paul Duffin46a26a82020-04-07 19:27:04 +01001323 allScopeProperties, scopeToProperties := createPropertiesInstance()
1324 module.scopeProperties = scopeToProperties
1325 module.AddProperties(&module.properties, allScopeProperties)
Colin Cross79c7c262019-04-17 11:11:46 -07001326
Paul Duffinc3091c82020-05-08 14:16:20 +01001327 // Initialize information common between source and prebuilt.
1328 module.initCommon(&module.ModuleBase)
1329
Paul Duffin0bdcb272020-02-06 15:24:57 +00001330 android.InitPrebuiltModule(module, &[]string{""})
Paul Duffindd46f712020-02-10 13:37:10 +00001331 android.InitApexModule(module)
1332 android.InitSdkAwareModule(module)
Colin Cross79c7c262019-04-17 11:11:46 -07001333 InitJavaModule(module, android.HostAndDeviceSupported)
1334
Paul Duffin1b1e8062020-05-08 13:44:43 +01001335 module.SetDefaultableHook(func(mctx android.DefaultableHookContext) {
1336 if module.initCommonAfterDefaultsApplied(mctx) {
1337 module.createInternalModules(mctx)
1338 }
1339 })
Colin Cross79c7c262019-04-17 11:11:46 -07001340 return module
1341}
1342
1343func (module *sdkLibraryImport) Prebuilt() *android.Prebuilt {
1344 return &module.prebuilt
1345}
1346
1347func (module *sdkLibraryImport) Name() string {
1348 return module.prebuilt.Name(module.ModuleBase.Name())
1349}
1350
Paul Duffin6e7ecbf2020-05-08 15:01:19 +01001351func (module *sdkLibraryImport) createInternalModules(mctx android.DefaultableHookContext) {
Colin Cross79c7c262019-04-17 11:11:46 -07001352
Paul Duffin50061512020-01-21 16:31:05 +00001353 // If the build is configured to use prebuilts then force this to be preferred.
1354 if mctx.Config().UnbundledBuildUsePrebuiltSdks() {
1355 module.prebuilt.ForcePrefer()
1356 }
1357
Paul Duffin46a26a82020-04-07 19:27:04 +01001358 for apiScope, scopeProperties := range module.scopeProperties {
Paul Duffin56d44902020-01-31 13:36:25 +00001359 if len(scopeProperties.Jars) == 0 {
1360 continue
1361 }
1362
Paul Duffinbbb546b2020-04-09 00:07:11 +01001363 module.createJavaImportForStubs(mctx, apiScope, scopeProperties)
Paul Duffin3d1248c2020-04-09 00:10:17 +01001364
1365 module.createPrebuiltStubsSources(mctx, apiScope, scopeProperties)
Paul Duffin56d44902020-01-31 13:36:25 +00001366 }
Colin Cross79c7c262019-04-17 11:11:46 -07001367
1368 javaSdkLibraries := javaSdkLibraries(mctx.Config())
1369 javaSdkLibrariesLock.Lock()
1370 defer javaSdkLibrariesLock.Unlock()
1371 *javaSdkLibraries = append(*javaSdkLibraries, module.BaseModuleName())
1372}
1373
Paul Duffin6e7ecbf2020-05-08 15:01:19 +01001374func (module *sdkLibraryImport) createJavaImportForStubs(mctx android.DefaultableHookContext, apiScope *apiScope, scopeProperties *sdkLibraryScopeProperties) {
Paul Duffinbbb546b2020-04-09 00:07:11 +01001375 // Creates a java import for the jar with ".stubs" suffix
1376 props := struct {
1377 Name *string
1378 Soc_specific *bool
1379 Device_specific *bool
1380 Product_specific *bool
1381 System_ext_specific *bool
1382 Sdk_version *string
1383 Libs []string
1384 Jars []string
1385 Prefer *bool
1386 }{}
Paul Duffinc3091c82020-05-08 14:16:20 +01001387 props.Name = proptools.StringPtr(module.stubsLibraryModuleName(apiScope))
Paul Duffinbbb546b2020-04-09 00:07:11 +01001388 props.Sdk_version = scopeProperties.Sdk_version
1389 // Prepend any of the libs from the legacy public properties to the libs for each of the
1390 // scopes to avoid having to duplicate them in each scope.
1391 props.Libs = append(module.properties.Libs, scopeProperties.Libs...)
1392 props.Jars = scopeProperties.Jars
1393 if module.SocSpecific() {
1394 props.Soc_specific = proptools.BoolPtr(true)
1395 } else if module.DeviceSpecific() {
1396 props.Device_specific = proptools.BoolPtr(true)
1397 } else if module.ProductSpecific() {
1398 props.Product_specific = proptools.BoolPtr(true)
1399 } else if module.SystemExtSpecific() {
1400 props.System_ext_specific = proptools.BoolPtr(true)
1401 }
1402 // If the build should use prebuilt sdks then set prefer to true on the stubs library.
1403 // That will cause the prebuilt version of the stubs to override the source version.
1404 if mctx.Config().UnbundledBuildUsePrebuiltSdks() {
1405 props.Prefer = proptools.BoolPtr(true)
1406 }
1407 mctx.CreateModule(ImportFactory, &props)
1408}
1409
Paul Duffin6e7ecbf2020-05-08 15:01:19 +01001410func (module *sdkLibraryImport) createPrebuiltStubsSources(mctx android.DefaultableHookContext, apiScope *apiScope, scopeProperties *sdkLibraryScopeProperties) {
Paul Duffin3d1248c2020-04-09 00:10:17 +01001411 props := struct {
1412 Name *string
1413 Srcs []string
1414 }{}
Paul Duffinc3091c82020-05-08 14:16:20 +01001415 props.Name = proptools.StringPtr(module.stubsSourceModuleName(apiScope))
Paul Duffin3d1248c2020-04-09 00:10:17 +01001416 props.Srcs = scopeProperties.Stub_srcs
1417 mctx.CreateModule(PrebuiltStubsSourcesFactory, &props)
1418}
1419
Colin Cross79c7c262019-04-17 11:11:46 -07001420func (module *sdkLibraryImport) DepsMutator(ctx android.BottomUpMutatorContext) {
Paul Duffin46a26a82020-04-07 19:27:04 +01001421 for apiScope, scopeProperties := range module.scopeProperties {
Paul Duffin56d44902020-01-31 13:36:25 +00001422 if len(scopeProperties.Jars) == 0 {
1423 continue
1424 }
1425
1426 // Add dependencies to the prebuilt stubs library
Paul Duffinc3091c82020-05-08 14:16:20 +01001427 ctx.AddVariationDependencies(nil, apiScope.stubsTag, module.stubsLibraryModuleName(apiScope))
Paul Duffin56d44902020-01-31 13:36:25 +00001428 }
Colin Cross79c7c262019-04-17 11:11:46 -07001429}
1430
1431func (module *sdkLibraryImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1432 // Record the paths to the prebuilt stubs library.
1433 ctx.VisitDirectDeps(func(to android.Module) {
1434 tag := ctx.OtherModuleDependencyTag(to)
1435
Paul Duffin56d44902020-01-31 13:36:25 +00001436 if lib, ok := to.(Dependency); ok {
1437 if scopeTag, ok := tag.(scopeDependencyTag); ok {
1438 apiScope := scopeTag.apiScope
1439 scopePaths := module.getScopePaths(apiScope)
1440 scopePaths.stubsHeaderPath = lib.HeaderJars()
1441 }
Colin Cross79c7c262019-04-17 11:11:46 -07001442 }
1443 })
1444}
1445
Paul Duffin56d44902020-01-31 13:36:25 +00001446func (module *sdkLibraryImport) sdkJars(
1447 ctx android.BaseModuleContext,
1448 sdkVersion sdkSpec) android.Paths {
1449
Paul Duffin50061512020-01-21 16:31:05 +00001450 // If a specific numeric version has been requested then use prebuilt versions of the sdk.
1451 if sdkVersion.version.isNumbered() {
1452 return PrebuiltJars(ctx, module.BaseModuleName(), sdkVersion)
1453 }
1454
Paul Duffin56d44902020-01-31 13:36:25 +00001455 var apiScope *apiScope
1456 switch sdkVersion.kind {
1457 case sdkSystem:
1458 apiScope = apiScopeSystem
1459 case sdkTest:
1460 apiScope = apiScopeTest
1461 default:
1462 apiScope = apiScopePublic
1463 }
1464
1465 paths := module.getScopePaths(apiScope)
1466 return paths.stubsHeaderPath
1467}
1468
Colin Cross79c7c262019-04-17 11:11:46 -07001469// to satisfy SdkLibraryDependency interface
Jiyong Park6a927c42020-01-21 02:03:43 +09001470func (module *sdkLibraryImport) SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths {
Colin Cross79c7c262019-04-17 11:11:46 -07001471 // This module is just a wrapper for the prebuilt stubs.
Paul Duffin56d44902020-01-31 13:36:25 +00001472 return module.sdkJars(ctx, sdkVersion)
Colin Cross79c7c262019-04-17 11:11:46 -07001473}
1474
1475// to satisfy SdkLibraryDependency interface
Jiyong Park6a927c42020-01-21 02:03:43 +09001476func (module *sdkLibraryImport) SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths {
Colin Cross79c7c262019-04-17 11:11:46 -07001477 // This module is just a wrapper for the stubs.
Paul Duffin56d44902020-01-31 13:36:25 +00001478 return module.sdkJars(ctx, sdkVersion)
Colin Cross79c7c262019-04-17 11:11:46 -07001479}
Jiyong Parke3833882020-02-17 17:28:10 +09001480
1481//
1482// java_sdk_library_xml
1483//
1484type sdkLibraryXml struct {
1485 android.ModuleBase
1486 android.DefaultableModuleBase
1487 android.ApexModuleBase
1488
1489 properties sdkLibraryXmlProperties
1490
1491 outputFilePath android.OutputPath
1492 installDirPath android.InstallPath
1493}
1494
1495type sdkLibraryXmlProperties struct {
1496 // canonical name of the lib
1497 Lib_name *string
1498}
1499
1500// java_sdk_library_xml builds the permission xml file for a java_sdk_library.
1501// Not to be used directly by users. java_sdk_library internally uses this.
1502func sdkLibraryXmlFactory() android.Module {
1503 module := &sdkLibraryXml{}
1504
1505 module.AddProperties(&module.properties)
1506
1507 android.InitApexModule(module)
1508 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibCommon)
1509
1510 return module
1511}
1512
1513// from android.PrebuiltEtcModule
1514func (module *sdkLibraryXml) SubDir() string {
1515 return "permissions"
1516}
1517
1518// from android.PrebuiltEtcModule
1519func (module *sdkLibraryXml) OutputFile() android.OutputPath {
1520 return module.outputFilePath
1521}
1522
1523// from android.ApexModule
1524func (module *sdkLibraryXml) AvailableFor(what string) bool {
1525 return true
1526}
1527
1528func (module *sdkLibraryXml) DepsMutator(ctx android.BottomUpMutatorContext) {
1529 // do nothing
1530}
1531
1532// File path to the runtime implementation library
1533func (module *sdkLibraryXml) implPath() string {
1534 implName := proptools.String(module.properties.Lib_name)
1535 if apexName := module.ApexName(); apexName != "" {
1536 // TODO(b/146468504): ApexName() is only a soong module name, not apex name.
1537 // In most cases, this works fine. But when apex_name is set or override_apex is used
1538 // this can be wrong.
1539 return fmt.Sprintf("/apex/%s/javalib/%s.jar", apexName, implName)
1540 }
1541 partition := "system"
1542 if module.SocSpecific() {
1543 partition = "vendor"
1544 } else if module.DeviceSpecific() {
1545 partition = "odm"
1546 } else if module.ProductSpecific() {
1547 partition = "product"
1548 } else if module.SystemExtSpecific() {
1549 partition = "system_ext"
1550 }
1551 return "/" + partition + "/framework/" + implName + ".jar"
1552}
1553
1554func (module *sdkLibraryXml) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1555 libName := proptools.String(module.properties.Lib_name)
1556 xmlContent := fmt.Sprintf(permissionsTemplate, libName, module.implPath())
1557
1558 module.outputFilePath = android.PathForModuleOut(ctx, libName+".xml").OutputPath
1559 rule := android.NewRuleBuilder()
1560 rule.Command().
1561 Text("/bin/bash -c \"echo -e '" + xmlContent + "'\" > ").
1562 Output(module.outputFilePath)
1563
1564 rule.Build(pctx, ctx, "java_sdk_xml", "Permission XML")
1565
1566 module.installDirPath = android.PathForModuleInstall(ctx, "etc", module.SubDir())
1567}
1568
1569func (module *sdkLibraryXml) AndroidMkEntries() []android.AndroidMkEntries {
1570 if !module.IsForPlatform() {
1571 return []android.AndroidMkEntries{android.AndroidMkEntries{
1572 Disabled: true,
1573 }}
1574 }
1575
1576 return []android.AndroidMkEntries{android.AndroidMkEntries{
1577 Class: "ETC",
1578 OutputFile: android.OptionalPathForPath(module.outputFilePath),
1579 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
1580 func(entries *android.AndroidMkEntries) {
1581 entries.SetString("LOCAL_MODULE_TAGS", "optional")
1582 entries.SetString("LOCAL_MODULE_PATH", module.installDirPath.ToMakePath().String())
1583 entries.SetString("LOCAL_INSTALLED_MODULE_STEM", module.outputFilePath.Base())
1584 },
1585 },
1586 }}
1587}
Paul Duffindd46f712020-02-10 13:37:10 +00001588
1589type sdkLibrarySdkMemberType struct {
1590 android.SdkMemberTypeBase
1591}
1592
1593func (s *sdkLibrarySdkMemberType) AddDependencies(mctx android.BottomUpMutatorContext, dependencyTag blueprint.DependencyTag, names []string) {
1594 mctx.AddVariationDependencies(nil, dependencyTag, names...)
1595}
1596
1597func (s *sdkLibrarySdkMemberType) IsInstance(module android.Module) bool {
1598 _, ok := module.(*SdkLibrary)
1599 return ok
1600}
1601
1602func (s *sdkLibrarySdkMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule {
1603 return ctx.SnapshotBuilder().AddPrebuiltModule(member, "java_sdk_library_import")
1604}
1605
1606func (s *sdkLibrarySdkMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties {
1607 return &sdkLibrarySdkMemberProperties{}
1608}
1609
1610type sdkLibrarySdkMemberProperties struct {
1611 android.SdkMemberPropertiesBase
1612
1613 // Scope to per scope properties.
1614 Scopes map[*apiScope]scopeProperties
1615
1616 // Additional libraries that the exported stubs libraries depend upon.
1617 Libs []string
Paul Duffin3d1248c2020-04-09 00:10:17 +01001618
1619 // The Java stubs source files.
1620 Stub_srcs []string
Paul Duffindd46f712020-02-10 13:37:10 +00001621}
1622
1623type scopeProperties struct {
Paul Duffin1fd005d2020-04-09 01:08:11 +01001624 Jars android.Paths
1625 StubsSrcJar android.Path
1626 CurrentApiFile android.Path
1627 RemovedApiFile android.Path
1628 SdkVersion string
Paul Duffindd46f712020-02-10 13:37:10 +00001629}
1630
1631func (s *sdkLibrarySdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) {
1632 sdk := variant.(*SdkLibrary)
1633
1634 s.Scopes = make(map[*apiScope]scopeProperties)
1635 for _, apiScope := range allApiScopes {
1636 paths := sdk.getScopePaths(apiScope)
1637 jars := paths.stubsImplPath
1638 if len(jars) > 0 {
1639 properties := scopeProperties{}
1640 properties.Jars = jars
Paul Duffin780c5f42020-05-12 15:52:55 +01001641 properties.SdkVersion = sdk.sdkVersionForStubsLibrary(ctx.SdkModuleContext(), apiScope)
Paul Duffin3d1248c2020-04-09 00:10:17 +01001642 properties.StubsSrcJar = paths.stubsSrcJar
Paul Duffin1fd005d2020-04-09 01:08:11 +01001643 properties.CurrentApiFile = paths.currentApiFilePath
1644 properties.RemovedApiFile = paths.removedApiFilePath
Paul Duffindd46f712020-02-10 13:37:10 +00001645 s.Scopes[apiScope] = properties
1646 }
1647 }
1648
1649 s.Libs = sdk.properties.Libs
1650}
1651
1652func (s *sdkLibrarySdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) {
1653 for _, apiScope := range allApiScopes {
1654 if properties, ok := s.Scopes[apiScope]; ok {
1655 scopeSet := propertySet.AddPropertySet(apiScope.name)
1656
Paul Duffin3d1248c2020-04-09 00:10:17 +01001657 scopeDir := filepath.Join("sdk_library", s.OsPrefix(), apiScope.name)
1658
Paul Duffindd46f712020-02-10 13:37:10 +00001659 var jars []string
1660 for _, p := range properties.Jars {
Paul Duffin3d1248c2020-04-09 00:10:17 +01001661 dest := filepath.Join(scopeDir, ctx.Name()+"-stubs.jar")
Paul Duffindd46f712020-02-10 13:37:10 +00001662 ctx.SnapshotBuilder().CopyToSnapshot(p, dest)
1663 jars = append(jars, dest)
1664 }
1665 scopeSet.AddProperty("jars", jars)
1666
Paul Duffin3d1248c2020-04-09 00:10:17 +01001667 // Merge the stubs source jar into the snapshot zip so that when it is unpacked
1668 // the source files are also unpacked.
1669 snapshotRelativeDir := filepath.Join(scopeDir, ctx.Name()+"_stub_sources")
1670 ctx.SnapshotBuilder().UnzipToSnapshot(properties.StubsSrcJar, snapshotRelativeDir)
1671 scopeSet.AddProperty("stub_srcs", []string{snapshotRelativeDir})
1672
Paul Duffin1fd005d2020-04-09 01:08:11 +01001673 if properties.CurrentApiFile != nil {
1674 currentApiSnapshotPath := filepath.Join(scopeDir, ctx.Name()+".txt")
1675 ctx.SnapshotBuilder().CopyToSnapshot(properties.CurrentApiFile, currentApiSnapshotPath)
1676 scopeSet.AddProperty("current_api", currentApiSnapshotPath)
1677 }
1678
1679 if properties.RemovedApiFile != nil {
1680 removedApiSnapshotPath := filepath.Join(scopeDir, ctx.Name()+"-removed.txt")
1681 ctx.SnapshotBuilder().CopyToSnapshot(properties.CurrentApiFile, removedApiSnapshotPath)
1682 scopeSet.AddProperty("removed_api", removedApiSnapshotPath)
1683 }
1684
Paul Duffindd46f712020-02-10 13:37:10 +00001685 if properties.SdkVersion != "" {
1686 scopeSet.AddProperty("sdk_version", properties.SdkVersion)
1687 }
1688 }
1689 }
1690
1691 if len(s.Libs) > 0 {
1692 propertySet.AddPropertyWithTag("libs", s.Libs, ctx.SnapshotBuilder().SdkMemberReferencePropertyTag(false))
1693 }
1694}