blob: 4d480ee1b6f69cb9100011bfa00f2dcc72a7d5bb [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"
Jiyong Parkc678ad32018-04-10 13:07:10 +090037 sdkXmlFileSuffix = ".xml"
Jiyong Parke3833882020-02-17 17:28:10 +090038 permissionsTemplate = `<?xml version=\"1.0\" encoding=\"utf-8\"?>\n` +
Jooyung Han624058e2019-12-24 18:38:06 +090039 `<!-- Copyright (C) 2018 The Android Open Source Project\n` +
40 `\n` +
Jiyong Parke3833882020-02-17 17:28:10 +090041 ` Licensed under the Apache License, Version 2.0 (the \"License\");\n` +
Jooyung Han624058e2019-12-24 18:38:06 +090042 ` you may not use this file except in compliance with the License.\n` +
43 ` You may obtain a copy of the License at\n` +
44 `\n` +
45 ` http://www.apache.org/licenses/LICENSE-2.0\n` +
46 `\n` +
47 ` Unless required by applicable law or agreed to in writing, software\n` +
Jiyong Parke3833882020-02-17 17:28:10 +090048 ` distributed under the License is distributed on an \"AS IS\" BASIS,\n` +
Jooyung Han624058e2019-12-24 18:38:06 +090049 ` WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n` +
50 ` See the License for the specific language governing permissions and\n` +
51 ` limitations under the License.\n` +
52 `-->\n` +
53 `<permissions>\n` +
Jiyong Parke3833882020-02-17 17:28:10 +090054 ` <library name=\"%s\" file=\"%s\"/>\n` +
Jooyung Han624058e2019-12-24 18:38:06 +090055 `</permissions>\n`
Jiyong Parkc678ad32018-04-10 13:07:10 +090056)
57
Paul Duffind1b3a922020-01-22 11:57:20 +000058// A tag to associated a dependency with a specific api scope.
59type scopeDependencyTag struct {
60 blueprint.BaseDependencyTag
61 name string
62 apiScope *apiScope
63}
64
65// Provides information about an api scope, e.g. public, system, test.
66type apiScope struct {
67 // The name of the api scope, e.g. public, system, test
68 name string
69
Paul Duffin97b53b82020-05-05 14:40:52 +010070 // The api scope that this scope extends.
71 extends *apiScope
72
Paul Duffin46a26a82020-04-07 19:27:04 +010073 // The name of the field in the dynamically created structure.
74 fieldName string
75
Paul Duffind1b3a922020-01-22 11:57:20 +000076 // The tag to use to depend on the stubs library module.
77 stubsTag scopeDependencyTag
78
79 // The tag to use to depend on the stubs
80 apiFileTag scopeDependencyTag
81
82 // The scope specific prefix to add to the api file base of "current.txt" or "removed.txt".
83 apiFilePrefix string
84
85 // The scope specific prefix to add to the sdk library module name to construct a scope specific
86 // module name.
87 moduleSuffix string
88
Paul Duffind1b3a922020-01-22 11:57:20 +000089 // SDK version that the stubs library is built against. Note that this is always
90 // *current. Older stubs library built with a numbered SDK version is created from
91 // the prebuilt jar.
92 sdkVersion string
Paul Duffin1fb487d2020-04-07 18:50:10 +010093
94 // Extra arguments to pass to droidstubs for this scope.
95 droidstubsArgs []string
Anton Hansson6478ac12020-05-02 11:19:36 +010096
97 // Whether the api scope can be treated as unstable, and should skip compat checks.
98 unstable bool
Paul Duffind1b3a922020-01-22 11:57:20 +000099}
100
101// Initialize a scope, creating and adding appropriate dependency tags
102func initApiScope(scope *apiScope) *apiScope {
Paul Duffin46a26a82020-04-07 19:27:04 +0100103 scope.fieldName = proptools.FieldNameForProperty(scope.name)
Paul Duffind1b3a922020-01-22 11:57:20 +0000104 scope.stubsTag = scopeDependencyTag{
105 name: scope.name + "-stubs",
106 apiScope: scope,
107 }
108 scope.apiFileTag = scopeDependencyTag{
109 name: scope.name + "-api",
110 apiScope: scope,
111 }
112 return scope
113}
114
115func (scope *apiScope) stubsModuleName(baseName string) string {
116 return baseName + sdkStubsLibrarySuffix + scope.moduleSuffix
117}
118
119func (scope *apiScope) docsModuleName(baseName string) string {
Paul Duffin91b883d2020-02-11 13:05:28 +0000120 return baseName + sdkStubsSourceSuffix + scope.moduleSuffix
Paul Duffind1b3a922020-01-22 11:57:20 +0000121}
122
123type apiScopes []*apiScope
124
125func (scopes apiScopes) Strings(accessor func(*apiScope) string) []string {
126 var list []string
127 for _, scope := range scopes {
128 list = append(list, accessor(scope))
129 }
130 return list
131}
132
Jiyong Parkc678ad32018-04-10 13:07:10 +0900133var (
Paul Duffind1b3a922020-01-22 11:57:20 +0000134 apiScopePublic = initApiScope(&apiScope{
135 name: "public",
136 sdkVersion: "current",
137 })
138 apiScopeSystem = initApiScope(&apiScope{
Anton Hansson6affb1f2020-04-28 16:47:41 +0100139 name: "system",
Paul Duffin97b53b82020-05-05 14:40:52 +0100140 extends: apiScopePublic,
Anton Hansson6affb1f2020-04-28 16:47:41 +0100141 apiFilePrefix: "system-",
142 moduleSuffix: sdkSystemApiSuffix,
143 sdkVersion: "system_current",
144 droidstubsArgs: []string{"-showAnnotation android.annotation.SystemApi"},
Paul Duffind1b3a922020-01-22 11:57:20 +0000145 })
146 apiScopeTest = initApiScope(&apiScope{
Anton Hansson6affb1f2020-04-28 16:47:41 +0100147 name: "test",
Paul Duffin97b53b82020-05-05 14:40:52 +0100148 extends: apiScopePublic,
Anton Hansson6affb1f2020-04-28 16:47:41 +0100149 apiFilePrefix: "test-",
150 moduleSuffix: sdkTestApiSuffix,
151 sdkVersion: "test_current",
152 droidstubsArgs: []string{"-showAnnotation android.annotation.TestApi"},
Anton Hansson6478ac12020-05-02 11:19:36 +0100153 unstable: true,
Paul Duffind1b3a922020-01-22 11:57:20 +0000154 })
155 allApiScopes = apiScopes{
156 apiScopePublic,
157 apiScopeSystem,
158 apiScopeTest,
159 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900160)
161
Jiyong Park82484c02018-04-23 21:41:26 +0900162var (
163 javaSdkLibrariesLock sync.Mutex
164)
165
Jiyong Parkc678ad32018-04-10 13:07:10 +0900166// TODO: these are big features that are currently missing
Jiyong Park1be96912018-05-28 18:02:19 +0900167// 1) disallowing linking to the runtime shared lib
168// 2) HTML generation
Jiyong Parkc678ad32018-04-10 13:07:10 +0900169
170func init() {
Paul Duffin43dc1cc2019-12-19 11:18:54 +0000171 RegisterSdkLibraryBuildComponents(android.InitRegistrationContext)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900172
Jiyong Park82484c02018-04-23 21:41:26 +0900173 android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) {
174 javaSdkLibraries := javaSdkLibraries(ctx.Config())
175 sort.Strings(*javaSdkLibraries)
176 ctx.Strict("JAVA_SDK_LIBRARIES", strings.Join(*javaSdkLibraries, " "))
177 })
Paul Duffindd46f712020-02-10 13:37:10 +0000178
179 // Register sdk member types.
180 android.RegisterSdkMemberType(&sdkLibrarySdkMemberType{
181 android.SdkMemberTypeBase{
182 PropertyName: "java_sdk_libs",
183 SupportsSdk: true,
184 },
185 })
Jiyong Parkc678ad32018-04-10 13:07:10 +0900186}
187
Paul Duffin43dc1cc2019-12-19 11:18:54 +0000188func RegisterSdkLibraryBuildComponents(ctx android.RegistrationContext) {
189 ctx.RegisterModuleType("java_sdk_library", SdkLibraryFactory)
190 ctx.RegisterModuleType("java_sdk_library_import", sdkLibraryImportFactory)
191}
192
Jiyong Parkc678ad32018-04-10 13:07:10 +0900193type sdkLibraryProperties struct {
Sundong Ahnf043cf62018-06-25 16:04:37 +0900194 // List of Java libraries that will be in the classpath when building stubs
195 Stub_only_libs []string `android:"arch_variant"`
196
Paul Duffin7a586d32019-12-30 17:09:34 +0000197 // list of package names that will be documented and publicized as API.
198 // This allows the API to be restricted to a subset of the source files provided.
199 // If this is unspecified then all the source files will be treated as being part
200 // of the API.
Jiyong Parkc678ad32018-04-10 13:07:10 +0900201 Api_packages []string
202
Jiyong Park5a2c9d72018-05-01 22:25:41 +0900203 // list of package names that must be hidden from the API
204 Hidden_api_packages []string
205
Paul Duffin749f98f2019-12-30 17:23:46 +0000206 // the relative path to the directory containing the api specification files.
207 // Defaults to "api".
208 Api_dir *string
209
Paul Duffin43db9be2019-12-30 17:35:49 +0000210 // If set to true there is no runtime library.
211 Api_only *bool
212
Paul Duffin11512472019-02-11 15:55:17 +0000213 // local files that are used within user customized droiddoc options.
214 Droiddoc_option_files []string
215
216 // additional droiddoc options
217 // Available variables for substitution:
218 //
219 // $(location <label>): the path to the droiddoc_option_files with name <label>
Sundong Ahndd567f92018-07-31 17:19:11 +0900220 Droiddoc_options []string
221
Sundong Ahn054b19a2018-10-19 13:46:09 +0900222 // a list of top-level directories containing files to merge qualifier annotations
223 // (i.e. those intended to be included in the stubs written) from.
224 Merge_annotations_dirs []string
225
226 // a list of top-level directories containing Java stub files to merge show/hide annotations from.
227 Merge_inclusion_annotations_dirs []string
228
229 // If set to true, the path of dist files is apistubs/core. Defaults to false.
230 Core_lib *bool
231
Sundong Ahn80a87b32019-05-13 15:02:50 +0900232 // don't create dist rules.
233 No_dist *bool `blueprint:"mutated"`
234
Paul Duffin37e0b772019-12-30 17:20:10 +0000235 // indicates whether system and test apis should be managed.
236 Has_system_and_test_apis bool `blueprint:"mutated"`
237
Jiyong Parkc678ad32018-04-10 13:07:10 +0900238 // TODO: determines whether to create HTML doc or not
239 //Html_doc *bool
240}
241
Paul Duffind1b3a922020-01-22 11:57:20 +0000242type scopePaths struct {
Paul Duffin1fd005d2020-04-09 01:08:11 +0100243 stubsHeaderPath android.Paths
244 stubsImplPath android.Paths
245 currentApiFilePath android.Path
246 removedApiFilePath android.Path
247 stubsSrcJar android.Path
Paul Duffind1b3a922020-01-22 11:57:20 +0000248}
249
Paul Duffin56d44902020-01-31 13:36:25 +0000250// Common code between sdk library and sdk library import
251type commonToSdkLibraryAndImport struct {
252 scopePaths map[*apiScope]*scopePaths
253}
254
255func (c *commonToSdkLibraryAndImport) getScopePaths(scope *apiScope) *scopePaths {
256 if c.scopePaths == nil {
257 c.scopePaths = make(map[*apiScope]*scopePaths)
258 }
259 paths := c.scopePaths[scope]
260 if paths == nil {
261 paths = &scopePaths{}
262 c.scopePaths[scope] = paths
263 }
264
265 return paths
266}
267
Inseob Kimc0907f12019-02-08 21:00:45 +0900268type SdkLibrary struct {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900269 Library
Jiyong Parkc678ad32018-04-10 13:07:10 +0900270
Sundong Ahn054b19a2018-10-19 13:46:09 +0900271 sdkLibraryProperties sdkLibraryProperties
Jiyong Parkc678ad32018-04-10 13:07:10 +0900272
Paul Duffin56d44902020-01-31 13:36:25 +0000273 commonToSdkLibraryAndImport
Jiyong Parkc678ad32018-04-10 13:07:10 +0900274}
275
Inseob Kimc0907f12019-02-08 21:00:45 +0900276var _ Dependency = (*SdkLibrary)(nil)
277var _ SdkLibraryDependency = (*SdkLibrary)(nil)
Colin Cross897d2ed2019-02-11 14:03:51 -0800278
Paul Duffind1b3a922020-01-22 11:57:20 +0000279func (module *SdkLibrary) getActiveApiScopes() apiScopes {
280 if module.sdkLibraryProperties.Has_system_and_test_apis {
281 return allApiScopes
282 } else {
283 return apiScopes{apiScopePublic}
284 }
285}
286
Paul Duffine74ac732020-02-06 13:51:46 +0000287var xmlPermissionsFileTag = dependencyTag{name: "xml-permissions-file"}
288
Jiyong Parke3833882020-02-17 17:28:10 +0900289func IsXmlPermissionsFileDepTag(depTag blueprint.DependencyTag) bool {
290 if dt, ok := depTag.(dependencyTag); ok {
291 return dt == xmlPermissionsFileTag
292 }
293 return false
294}
295
Inseob Kimc0907f12019-02-08 21:00:45 +0900296func (module *SdkLibrary) DepsMutator(ctx android.BottomUpMutatorContext) {
Paul Duffind1b3a922020-01-22 11:57:20 +0000297 for _, apiScope := range module.getActiveApiScopes() {
298 // Add dependencies to the stubs library
Paul Duffin50061512020-01-21 16:31:05 +0000299 ctx.AddVariationDependencies(nil, apiScope.stubsTag, module.stubsName(apiScope))
Paul Duffind1b3a922020-01-22 11:57:20 +0000300
Paul Duffin50061512020-01-21 16:31:05 +0000301 // And the api file
Paul Duffind1b3a922020-01-22 11:57:20 +0000302 ctx.AddVariationDependencies(nil, apiScope.apiFileTag, module.docsName(apiScope))
Sundong Ahn054b19a2018-10-19 13:46:09 +0900303 }
304
Paul Duffine74ac732020-02-06 13:51:46 +0000305 if !proptools.Bool(module.sdkLibraryProperties.Api_only) {
306 // Add dependency to the rule for generating the xml permissions file
Jiyong Parke3833882020-02-17 17:28:10 +0900307 ctx.AddDependency(module, xmlPermissionsFileTag, module.xmlFileName())
Paul Duffine74ac732020-02-06 13:51:46 +0000308 }
309
Sundong Ahn054b19a2018-10-19 13:46:09 +0900310 module.Library.deps(ctx)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900311}
312
Inseob Kimc0907f12019-02-08 21:00:45 +0900313func (module *SdkLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Paul Duffin43db9be2019-12-30 17:35:49 +0000314 // Don't build an implementation library if this is api only.
315 if !proptools.Bool(module.sdkLibraryProperties.Api_only) {
316 module.Library.GenerateAndroidBuildActions(ctx)
317 }
Sundong Ahn054b19a2018-10-19 13:46:09 +0900318
Sundong Ahn57368eb2018-07-06 11:20:23 +0900319 // Record the paths to the header jars of the library (stubs and impl).
Paul Duffind1b3a922020-01-22 11:57:20 +0000320 // When this java_sdk_library is depended upon from others via "libs" property,
Jiyong Parkc678ad32018-04-10 13:07:10 +0900321 // the recorded paths will be returned depending on the link type of the caller.
322 ctx.VisitDirectDeps(func(to android.Module) {
323 otherName := ctx.OtherModuleName(to)
324 tag := ctx.OtherModuleDependencyTag(to)
325
Sundong Ahn57368eb2018-07-06 11:20:23 +0900326 if lib, ok := to.(Dependency); ok {
Paul Duffind1b3a922020-01-22 11:57:20 +0000327 if scopeTag, ok := tag.(scopeDependencyTag); ok {
328 apiScope := scopeTag.apiScope
329 scopePaths := module.getScopePaths(apiScope)
330 scopePaths.stubsHeaderPath = lib.HeaderJars()
331 scopePaths.stubsImplPath = lib.ImplementationJars()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900332 }
333 }
Paul Duffin3d1248c2020-04-09 00:10:17 +0100334 if doc, ok := to.(ApiStubsProvider); ok {
Paul Duffind1b3a922020-01-22 11:57:20 +0000335 if scopeTag, ok := tag.(scopeDependencyTag); ok {
336 apiScope := scopeTag.apiScope
337 scopePaths := module.getScopePaths(apiScope)
Paul Duffin1fd005d2020-04-09 01:08:11 +0100338 scopePaths.currentApiFilePath = doc.ApiFilePath()
339 scopePaths.removedApiFilePath = doc.RemovedApiFilePath()
Paul Duffin3d1248c2020-04-09 00:10:17 +0100340 scopePaths.stubsSrcJar = doc.StubsSrcJar()
Paul Duffind1b3a922020-01-22 11:57:20 +0000341 } else {
Sundong Ahn20e998b2018-07-24 11:19:26 +0900342 ctx.ModuleErrorf("depends on module %q of unknown tag %q", otherName, tag)
343 }
344 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900345 })
346}
347
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900348func (module *SdkLibrary) AndroidMkEntries() []android.AndroidMkEntries {
Paul Duffin43db9be2019-12-30 17:35:49 +0000349 if proptools.Bool(module.sdkLibraryProperties.Api_only) {
350 return nil
351 }
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900352 entriesList := module.Library.AndroidMkEntries()
353 entries := &entriesList[0]
Jaewoong Jungb0c127c2019-08-29 14:56:03 -0700354 entries.Required = append(entries.Required, module.xmlFileName())
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900355 return entriesList
Jiyong Park82484c02018-04-23 21:41:26 +0900356}
357
Jiyong Parkc678ad32018-04-10 13:07:10 +0900358// Module name of the stubs library
Paul Duffind1b3a922020-01-22 11:57:20 +0000359func (module *SdkLibrary) stubsName(apiScope *apiScope) string {
360 return apiScope.stubsModuleName(module.BaseModuleName())
Jiyong Parkc678ad32018-04-10 13:07:10 +0900361}
362
363// Module name of the docs
Paul Duffind1b3a922020-01-22 11:57:20 +0000364func (module *SdkLibrary) docsName(apiScope *apiScope) string {
365 return apiScope.docsModuleName(module.BaseModuleName())
Jiyong Parkc678ad32018-04-10 13:07:10 +0900366}
367
368// Module name of the runtime implementation library
Inseob Kimc0907f12019-02-08 21:00:45 +0900369func (module *SdkLibrary) implName() string {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900370 return module.BaseModuleName()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900371}
372
Jiyong Parkc678ad32018-04-10 13:07:10 +0900373// Module name of the XML file for the lib
Inseob Kimc0907f12019-02-08 21:00:45 +0900374func (module *SdkLibrary) xmlFileName() string {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900375 return module.BaseModuleName() + sdkXmlFileSuffix
376}
377
Anton Hansson5fd5d242020-03-27 19:43:19 +0000378// The dist path of the stub artifacts
379func (module *SdkLibrary) apiDistPath(apiScope *apiScope) string {
380 if module.ModuleBase.Owner() != "" {
381 return path.Join("apistubs", module.ModuleBase.Owner(), apiScope.name)
382 } else if Bool(module.sdkLibraryProperties.Core_lib) {
383 return path.Join("apistubs", "core", apiScope.name)
384 } else {
385 return path.Join("apistubs", "android", apiScope.name)
386 }
387}
388
Paul Duffin12ceb462019-12-24 20:31:31 +0000389// Get the sdk version for use when compiling the stubs library.
Paul Duffind1b3a922020-01-22 11:57:20 +0000390func (module *SdkLibrary) sdkVersionForStubsLibrary(mctx android.LoadHookContext, apiScope *apiScope) string {
Paul Duffin12ceb462019-12-24 20:31:31 +0000391 sdkDep := decodeSdkDep(mctx, sdkContext(&module.Library))
392 if sdkDep.hasStandardLibs() {
393 // If building against a standard sdk then use the sdk version appropriate for the scope.
Paul Duffind1b3a922020-01-22 11:57:20 +0000394 return apiScope.sdkVersion
Paul Duffin12ceb462019-12-24 20:31:31 +0000395 } else {
396 // Otherwise, use no system module.
397 return "none"
398 }
399}
400
Paul Duffind1b3a922020-01-22 11:57:20 +0000401func (module *SdkLibrary) latestApiFilegroupName(apiScope *apiScope) string {
402 return ":" + module.BaseModuleName() + ".api." + apiScope.name + ".latest"
Jiyong Park58c518b2018-05-12 22:29:12 +0900403}
Jiyong Parkc678ad32018-04-10 13:07:10 +0900404
Paul Duffind1b3a922020-01-22 11:57:20 +0000405func (module *SdkLibrary) latestRemovedApiFilegroupName(apiScope *apiScope) string {
406 return ":" + module.BaseModuleName() + "-removed.api." + apiScope.name + ".latest"
Jiyong Parkc678ad32018-04-10 13:07:10 +0900407}
408
409// Creates a static java library that has API stubs
Paul Duffind1b3a922020-01-22 11:57:20 +0000410func (module *SdkLibrary) createStubsLibrary(mctx android.LoadHookContext, apiScope *apiScope) {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900411 props := struct {
Sundong Ahn0d7dff42019-12-04 12:53:44 +0900412 Name *string
413 Srcs []string
Paul Duffin367ab912019-12-23 19:40:36 +0000414 Installable *bool
Sundong Ahn0d7dff42019-12-04 12:53:44 +0900415 Sdk_version *string
Paul Duffin12ceb462019-12-24 20:31:31 +0000416 System_modules *string
Paul Duffinab8da5d2020-02-07 16:12:04 +0000417 Patch_module *string
Sundong Ahn0d7dff42019-12-04 12:53:44 +0900418 Libs []string
419 Soc_specific *bool
420 Device_specific *bool
421 Product_specific *bool
422 System_ext_specific *bool
423 Compile_dex *bool
Sundong Ahn0d7dff42019-12-04 12:53:44 +0900424 Java_version *string
425 Product_variables struct {
Jiyong Park82484c02018-04-23 21:41:26 +0900426 Pdk struct {
427 Enabled *bool
428 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900429 }
Sundong Ahn054b19a2018-10-19 13:46:09 +0900430 Openjdk9 struct {
431 Srcs []string
432 Javacflags []string
433 }
Anton Hansson5fd5d242020-03-27 19:43:19 +0000434 Dist struct {
435 Targets []string
436 Dest *string
437 Dir *string
438 Tag *string
439 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900440 }{}
441
Jiyong Parkdf130542018-04-27 16:29:21 +0900442 props.Name = proptools.StringPtr(module.stubsName(apiScope))
Jiyong Parkc678ad32018-04-10 13:07:10 +0900443 // sources are generated from the droiddoc
Jiyong Parkdf130542018-04-27 16:29:21 +0900444 props.Srcs = []string{":" + module.docsName(apiScope)}
Paul Duffin12ceb462019-12-24 20:31:31 +0000445 sdkVersion := module.sdkVersionForStubsLibrary(mctx, apiScope)
Paul Duffin52d398a2019-06-11 12:31:14 +0100446 props.Sdk_version = proptools.StringPtr(sdkVersion)
Paul Duffin12ceb462019-12-24 20:31:31 +0000447 props.System_modules = module.Library.Module.deviceProperties.System_modules
Paul Duffinab8da5d2020-02-07 16:12:04 +0000448 props.Patch_module = module.Library.Module.properties.Patch_module
Paul Duffin367ab912019-12-23 19:40:36 +0000449 props.Installable = proptools.BoolPtr(false)
Sundong Ahn054b19a2018-10-19 13:46:09 +0900450 props.Libs = module.sdkLibraryProperties.Stub_only_libs
Jiyong Park82484c02018-04-23 21:41:26 +0900451 props.Product_variables.Pdk.Enabled = proptools.BoolPtr(false)
Sundong Ahn054b19a2018-10-19 13:46:09 +0900452 props.Openjdk9.Srcs = module.Library.Module.properties.Openjdk9.Srcs
453 props.Openjdk9.Javacflags = module.Library.Module.properties.Openjdk9.Javacflags
454 props.Java_version = module.Library.Module.properties.Java_version
455 if module.Library.Module.deviceProperties.Compile_dex != nil {
456 props.Compile_dex = module.Library.Module.deviceProperties.Compile_dex
Sundong Ahndd567f92018-07-31 17:19:11 +0900457 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900458
459 if module.SocSpecific() {
460 props.Soc_specific = proptools.BoolPtr(true)
461 } else if module.DeviceSpecific() {
462 props.Device_specific = proptools.BoolPtr(true)
463 } else if module.ProductSpecific() {
464 props.Product_specific = proptools.BoolPtr(true)
Sundong Ahn0d7dff42019-12-04 12:53:44 +0900465 } else if module.SystemExtSpecific() {
466 props.System_ext_specific = proptools.BoolPtr(true)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900467 }
Anton Hansson5fd5d242020-03-27 19:43:19 +0000468 // Dist the class jar artifact for sdk builds.
469 if !Bool(module.sdkLibraryProperties.No_dist) {
470 props.Dist.Targets = []string{"sdk", "win_sdk"}
471 props.Dist.Dest = proptools.StringPtr(fmt.Sprintf("%v.jar", module.BaseModuleName()))
472 props.Dist.Dir = proptools.StringPtr(module.apiDistPath(apiScope))
473 props.Dist.Tag = proptools.StringPtr(".jar")
474 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900475
Colin Cross84dfc3d2019-09-25 11:33:01 -0700476 mctx.CreateModule(LibraryFactory, &props)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900477}
478
Paul Duffin6d0886e2020-04-07 18:49:53 +0100479// Creates a droidstubs module that creates stubs source files from the given full source
Jiyong Parkc678ad32018-04-10 13:07:10 +0900480// files
Paul Duffind1b3a922020-01-22 11:57:20 +0000481func (module *SdkLibrary) createStubsSources(mctx android.LoadHookContext, apiScope *apiScope) {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900482 props := struct {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900483 Name *string
484 Srcs []string
485 Installable *bool
Paul Duffin52d398a2019-06-11 12:31:14 +0100486 Sdk_version *string
Paul Duffin12ceb462019-12-24 20:31:31 +0000487 System_modules *string
Sundong Ahn054b19a2018-10-19 13:46:09 +0900488 Libs []string
Paul Duffin11512472019-02-11 15:55:17 +0000489 Arg_files []string
Sundong Ahn054b19a2018-10-19 13:46:09 +0900490 Args *string
Sundong Ahn054b19a2018-10-19 13:46:09 +0900491 Java_version *string
492 Merge_annotations_dirs []string
493 Merge_inclusion_annotations_dirs []string
494 Check_api struct {
Inseob Kim38449af2019-02-28 14:24:05 +0900495 Current ApiToCheck
496 Last_released ApiToCheck
497 Ignore_missing_latest_api *bool
Jiyong Park58c518b2018-05-12 22:29:12 +0900498 }
Sundong Ahn1b92c822018-05-29 11:35:17 +0900499 Aidl struct {
500 Include_dirs []string
501 Local_include_dirs []string
502 }
Anton Hansson5fd5d242020-03-27 19:43:19 +0000503 Dist struct {
504 Targets []string
505 Dest *string
506 Dir *string
507 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900508 }{}
509
Paul Duffin7b78b4d2020-04-28 14:08:32 +0100510 // The stubs source processing uses the same compile time classpath when extracting the
511 // API from the implementation library as it does when compiling it. i.e. the same
512 // * sdk version
513 // * system_modules
514 // * libs (static_libs/libs)
Paul Duffin250e6192019-06-07 10:44:37 +0100515
Jiyong Parkdf130542018-04-27 16:29:21 +0900516 props.Name = proptools.StringPtr(module.docsName(apiScope))
Sundong Ahn054b19a2018-10-19 13:46:09 +0900517 props.Srcs = append(props.Srcs, module.Library.Module.properties.Srcs...)
Paul Duffin7b78b4d2020-04-28 14:08:32 +0100518 props.Sdk_version = module.Library.Module.deviceProperties.Sdk_version
Paul Duffin12ceb462019-12-24 20:31:31 +0000519 props.System_modules = module.Library.Module.deviceProperties.System_modules
Jiyong Parkc678ad32018-04-10 13:07:10 +0900520 props.Installable = proptools.BoolPtr(false)
Sundong Ahne6f0b052018-06-05 16:46:14 +0900521 // A droiddoc module has only one Libs property and doesn't distinguish between
522 // shared libs and static libs. So we need to add both of these libs to Libs property.
Sundong Ahn054b19a2018-10-19 13:46:09 +0900523 props.Libs = module.Library.Module.properties.Libs
524 props.Libs = append(props.Libs, module.Library.Module.properties.Static_libs...)
525 props.Aidl.Include_dirs = module.Library.Module.deviceProperties.Aidl.Include_dirs
526 props.Aidl.Local_include_dirs = module.Library.Module.deviceProperties.Aidl.Local_include_dirs
Sundong Ahn054b19a2018-10-19 13:46:09 +0900527 props.Java_version = module.Library.Module.properties.Java_version
Jiyong Parkc678ad32018-04-10 13:07:10 +0900528
Sundong Ahn054b19a2018-10-19 13:46:09 +0900529 props.Merge_annotations_dirs = module.sdkLibraryProperties.Merge_annotations_dirs
530 props.Merge_inclusion_annotations_dirs = module.sdkLibraryProperties.Merge_inclusion_annotations_dirs
531
Paul Duffin6d0886e2020-04-07 18:49:53 +0100532 droidstubsArgs := []string{}
Paul Duffin235ffff2019-12-24 10:41:30 +0000533 if len(module.sdkLibraryProperties.Api_packages) != 0 {
Paul Duffin6d0886e2020-04-07 18:49:53 +0100534 droidstubsArgs = append(droidstubsArgs, "--stub-packages "+strings.Join(module.sdkLibraryProperties.Api_packages, ":"))
Paul Duffin235ffff2019-12-24 10:41:30 +0000535 }
536 if len(module.sdkLibraryProperties.Hidden_api_packages) != 0 {
Paul Duffin6d0886e2020-04-07 18:49:53 +0100537 droidstubsArgs = append(droidstubsArgs,
Paul Duffin235ffff2019-12-24 10:41:30 +0000538 android.JoinWithPrefix(module.sdkLibraryProperties.Hidden_api_packages, " --hide-package "))
539 }
Paul Duffin6d0886e2020-04-07 18:49:53 +0100540 droidstubsArgs = append(droidstubsArgs, module.sdkLibraryProperties.Droiddoc_options...)
Paul Duffin235ffff2019-12-24 10:41:30 +0000541 disabledWarnings := []string{
542 "MissingPermission",
543 "BroadcastBehavior",
544 "HiddenSuperclass",
545 "DeprecationMismatch",
546 "UnavailableSymbol",
547 "SdkConstant",
548 "HiddenTypeParameter",
549 "Todo",
550 "Typo",
551 }
Paul Duffin6d0886e2020-04-07 18:49:53 +0100552 droidstubsArgs = append(droidstubsArgs, android.JoinWithPrefix(disabledWarnings, "--hide "))
Sundong Ahnfb2721f2018-09-17 13:23:09 +0900553
Paul Duffin1fb487d2020-04-07 18:50:10 +0100554 // Add in scope specific arguments.
555 droidstubsArgs = append(droidstubsArgs, apiScope.droidstubsArgs...)
Paul Duffin11512472019-02-11 15:55:17 +0000556 props.Arg_files = module.sdkLibraryProperties.Droiddoc_option_files
Paul Duffin6d0886e2020-04-07 18:49:53 +0100557 props.Args = proptools.StringPtr(strings.Join(droidstubsArgs, " "))
Jiyong Parkc678ad32018-04-10 13:07:10 +0900558
559 // List of APIs identified from the provided source files are created. They are later
560 // compared against to the not-yet-released (a.k.a current) list of APIs and to the
561 // last-released (a.k.a numbered) list of API.
Paul Duffind1b3a922020-01-22 11:57:20 +0000562 currentApiFileName := apiScope.apiFilePrefix + "current.txt"
563 removedApiFileName := apiScope.apiFilePrefix + "removed.txt"
Paul Duffin749f98f2019-12-30 17:23:46 +0000564 apiDir := module.getApiDir()
565 currentApiFileName = path.Join(apiDir, currentApiFileName)
566 removedApiFileName = path.Join(apiDir, removedApiFileName)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900567
Jiyong Park58c518b2018-05-12 22:29:12 +0900568 // check against the not-yet-release API
569 props.Check_api.Current.Api_file = proptools.StringPtr(currentApiFileName)
570 props.Check_api.Current.Removed_api_file = proptools.StringPtr(removedApiFileName)
Jiyong Park58c518b2018-05-12 22:29:12 +0900571
Anton Hansson6478ac12020-05-02 11:19:36 +0100572 if !apiScope.unstable {
573 // check against the latest released API
574 props.Check_api.Last_released.Api_file = proptools.StringPtr(
575 module.latestApiFilegroupName(apiScope))
576 props.Check_api.Last_released.Removed_api_file = proptools.StringPtr(
577 module.latestRemovedApiFilegroupName(apiScope))
578 props.Check_api.Ignore_missing_latest_api = proptools.BoolPtr(true)
579 }
Jiyong Park58c518b2018-05-12 22:29:12 +0900580
Anton Hansson5fd5d242020-03-27 19:43:19 +0000581 // Dist the api txt artifact for sdk builds.
582 if !Bool(module.sdkLibraryProperties.No_dist) {
583 props.Dist.Targets = []string{"sdk", "win_sdk"}
584 props.Dist.Dest = proptools.StringPtr(fmt.Sprintf("%v.txt", module.BaseModuleName()))
585 props.Dist.Dir = proptools.StringPtr(path.Join(module.apiDistPath(apiScope), "api"))
586 }
587
Colin Cross84dfc3d2019-09-25 11:33:01 -0700588 mctx.CreateModule(DroidstubsFactory, &props)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900589}
590
Jooyung Han5e9013b2020-03-10 06:23:13 +0900591func (module *SdkLibrary) DepIsInSameApex(mctx android.BaseModuleContext, dep android.Module) bool {
592 depTag := mctx.OtherModuleDependencyTag(dep)
593 if depTag == xmlPermissionsFileTag {
594 return true
595 }
596 return module.Library.DepIsInSameApex(mctx, dep)
597}
598
Jiyong Parkc678ad32018-04-10 13:07:10 +0900599// Creates the xml file that publicizes the runtime library
Colin Crossf8b860a2019-04-16 14:43:28 -0700600func (module *SdkLibrary) createXmlFile(mctx android.LoadHookContext) {
Jiyong Parke3833882020-02-17 17:28:10 +0900601 props := struct {
Sundong Ahn0d7dff42019-12-04 12:53:44 +0900602 Name *string
Jiyong Parke3833882020-02-17 17:28:10 +0900603 Lib_name *string
Sundong Ahn0d7dff42019-12-04 12:53:44 +0900604 Soc_specific *bool
605 Device_specific *bool
606 Product_specific *bool
607 System_ext_specific *bool
Jooyung Han5e9013b2020-03-10 06:23:13 +0900608 Apex_available []string
Jiyong Parke3833882020-02-17 17:28:10 +0900609 }{
Jooyung Han5e9013b2020-03-10 06:23:13 +0900610 Name: proptools.StringPtr(module.xmlFileName()),
611 Lib_name: proptools.StringPtr(module.BaseModuleName()),
612 Apex_available: module.ApexProperties.Apex_available,
Jiyong Parkc678ad32018-04-10 13:07:10 +0900613 }
Jiyong Parke3833882020-02-17 17:28:10 +0900614
615 if module.SocSpecific() {
616 props.Soc_specific = proptools.BoolPtr(true)
617 } else if module.DeviceSpecific() {
618 props.Device_specific = proptools.BoolPtr(true)
619 } else if module.ProductSpecific() {
620 props.Product_specific = proptools.BoolPtr(true)
621 } else if module.SystemExtSpecific() {
622 props.System_ext_specific = proptools.BoolPtr(true)
623 }
624
625 mctx.CreateModule(sdkLibraryXmlFactory, &props)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900626}
627
Paul Duffin50061512020-01-21 16:31:05 +0000628func PrebuiltJars(ctx android.BaseModuleContext, baseName string, s sdkSpec) android.Paths {
Jiyong Park6a927c42020-01-21 02:03:43 +0900629 var ver sdkVersion
630 var kind sdkKind
631 if s.usePrebuilt(ctx) {
632 ver = s.version
633 kind = s.kind
Jiyong Parkc678ad32018-04-10 13:07:10 +0900634 } else {
Jiyong Park6a927c42020-01-21 02:03:43 +0900635 // We don't have prebuilt SDK for the specific sdkVersion.
636 // Instead of breaking the build, fallback to use "system_current"
637 ver = sdkVersionCurrent
638 kind = sdkSystem
Sundong Ahn054b19a2018-10-19 13:46:09 +0900639 }
Jiyong Park6a927c42020-01-21 02:03:43 +0900640
641 dir := filepath.Join("prebuilts", "sdk", ver.String(), kind.String())
Paul Duffin50061512020-01-21 16:31:05 +0000642 jar := filepath.Join(dir, baseName+".jar")
Sundong Ahn054b19a2018-10-19 13:46:09 +0900643 jarPath := android.ExistentPathForSource(ctx, jar)
Sundong Ahnae418ac2019-02-28 15:01:28 +0900644 if !jarPath.Valid() {
Colin Cross07c88562020-01-07 09:34:44 -0800645 if ctx.Config().AllowMissingDependencies() {
646 return android.Paths{android.PathForSource(ctx, jar)}
647 } else {
Jiyong Park6a927c42020-01-21 02:03:43 +0900648 ctx.PropertyErrorf("sdk_library", "invalid sdk version %q, %q does not exist", s.raw, jar)
Colin Cross07c88562020-01-07 09:34:44 -0800649 }
Sundong Ahnae418ac2019-02-28 15:01:28 +0900650 return nil
651 }
Sundong Ahn054b19a2018-10-19 13:46:09 +0900652 return android.Paths{jarPath.Path()}
653}
654
Paul Duffind1b3a922020-01-22 11:57:20 +0000655func (module *SdkLibrary) sdkJars(
656 ctx android.BaseModuleContext,
657 sdkVersion sdkSpec,
658 headerJars bool) android.Paths {
659
Paul Duffin50061512020-01-21 16:31:05 +0000660 // If a specific numeric version has been requested then use prebuilt versions of the sdk.
661 if sdkVersion.version.isNumbered() {
662 return PrebuiltJars(ctx, module.BaseModuleName(), sdkVersion)
Sundong Ahn054b19a2018-10-19 13:46:09 +0900663 } else {
Paul Duffind1b3a922020-01-22 11:57:20 +0000664 if !sdkVersion.specified() {
665 if headerJars {
666 return module.Library.HeaderJars()
667 } else {
668 return module.Library.ImplementationJars()
669 }
670 }
Paul Duffin726d23c2020-01-22 16:30:37 +0000671 var apiScope *apiScope
Jiyong Park6a927c42020-01-21 02:03:43 +0900672 switch sdkVersion.kind {
673 case sdkSystem:
Paul Duffin726d23c2020-01-22 16:30:37 +0000674 apiScope = apiScopeSystem
675 case sdkTest:
676 apiScope = apiScopeTest
Jiyong Park6a927c42020-01-21 02:03:43 +0900677 case sdkPrivate:
Sundong Ahn054b19a2018-10-19 13:46:09 +0900678 return module.Library.HeaderJars()
Jiyong Park6a927c42020-01-21 02:03:43 +0900679 default:
Paul Duffin726d23c2020-01-22 16:30:37 +0000680 apiScope = apiScopePublic
Paul Duffind1b3a922020-01-22 11:57:20 +0000681 }
682
Paul Duffin726d23c2020-01-22 16:30:37 +0000683 paths := module.getScopePaths(apiScope)
Paul Duffind1b3a922020-01-22 11:57:20 +0000684 if headerJars {
685 return paths.stubsHeaderPath
686 } else {
687 return paths.stubsImplPath
Sundong Ahn054b19a2018-10-19 13:46:09 +0900688 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900689 }
690}
691
Sundong Ahn241cd372018-07-13 16:16:44 +0900692// to satisfy SdkLibraryDependency interface
Paul Duffind1b3a922020-01-22 11:57:20 +0000693func (module *SdkLibrary) SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths {
694 return module.sdkJars(ctx, sdkVersion, true /*headerJars*/)
695}
696
697// to satisfy SdkLibraryDependency interface
Jiyong Park6a927c42020-01-21 02:03:43 +0900698func (module *SdkLibrary) SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths {
Paul Duffind1b3a922020-01-22 11:57:20 +0000699 return module.sdkJars(ctx, sdkVersion, false /*headerJars*/)
Sundong Ahn241cd372018-07-13 16:16:44 +0900700}
701
Sundong Ahn80a87b32019-05-13 15:02:50 +0900702func (module *SdkLibrary) SetNoDist() {
703 module.sdkLibraryProperties.No_dist = proptools.BoolPtr(true)
704}
705
Colin Cross571cccf2019-02-04 11:22:08 -0800706var javaSdkLibrariesKey = android.NewOnceKey("javaSdkLibraries")
707
Jiyong Park82484c02018-04-23 21:41:26 +0900708func javaSdkLibraries(config android.Config) *[]string {
Colin Cross571cccf2019-02-04 11:22:08 -0800709 return config.Once(javaSdkLibrariesKey, func() interface{} {
Jiyong Park82484c02018-04-23 21:41:26 +0900710 return &[]string{}
711 }).(*[]string)
712}
713
Paul Duffin749f98f2019-12-30 17:23:46 +0000714func (module *SdkLibrary) getApiDir() string {
715 return proptools.StringDefault(module.sdkLibraryProperties.Api_dir, "api")
716}
717
Jiyong Parkc678ad32018-04-10 13:07:10 +0900718// For a java_sdk_library module, create internal modules for stubs, docs,
719// runtime libs and xml file. If requested, the stubs and docs are created twice
720// once for public API level and once for system API level
Colin Crossf8b860a2019-04-16 14:43:28 -0700721func (module *SdkLibrary) CreateInternalModules(mctx android.LoadHookContext) {
Inseob Kim6e93ac92019-03-21 17:43:49 +0900722 if len(module.Library.Module.properties.Srcs) == 0 {
Inseob Kimc0907f12019-02-08 21:00:45 +0900723 mctx.PropertyErrorf("srcs", "java_sdk_library must specify srcs")
Jooyung Han58f26ab2019-12-18 15:34:32 +0900724 return
Inseob Kimc0907f12019-02-08 21:00:45 +0900725 }
726
Paul Duffin37e0b772019-12-30 17:20:10 +0000727 // If this builds against standard libraries (i.e. is not part of the core libraries)
728 // then assume it provides both system and test apis. Otherwise, assume it does not and
729 // also assume it does not contribute to the dist build.
730 sdkDep := decodeSdkDep(mctx, sdkContext(&module.Library))
731 hasSystemAndTestApis := sdkDep.hasStandardLibs()
732 module.sdkLibraryProperties.Has_system_and_test_apis = hasSystemAndTestApis
733 module.sdkLibraryProperties.No_dist = proptools.BoolPtr(!hasSystemAndTestApis)
734
Inseob Kim8098faa2019-03-18 10:19:51 +0900735 missing_current_api := false
736
Paul Duffind1b3a922020-01-22 11:57:20 +0000737 activeScopes := module.getActiveApiScopes()
738
Paul Duffin749f98f2019-12-30 17:23:46 +0000739 apiDir := module.getApiDir()
Paul Duffind1b3a922020-01-22 11:57:20 +0000740 for _, scope := range activeScopes {
Inseob Kim8098faa2019-03-18 10:19:51 +0900741 for _, api := range []string{"current.txt", "removed.txt"} {
Paul Duffind1b3a922020-01-22 11:57:20 +0000742 path := path.Join(mctx.ModuleDir(), apiDir, scope.apiFilePrefix+api)
Inseob Kim8098faa2019-03-18 10:19:51 +0900743 p := android.ExistentPathForSource(mctx, path)
744 if !p.Valid() {
745 mctx.ModuleErrorf("Current api file %#v doesn't exist", path)
746 missing_current_api = true
747 }
748 }
749 }
750
751 if missing_current_api {
752 script := "build/soong/scripts/gen-java-current-api-files.sh"
753 p := android.ExistentPathForSource(mctx, script)
754
755 if !p.Valid() {
756 panic(fmt.Sprintf("script file %s doesn't exist", script))
757 }
758
759 mctx.ModuleErrorf("One or more current api files are missing. "+
760 "You can update them by:\n"+
Paul Duffin37e0b772019-12-30 17:20:10 +0000761 "%s %q %s && m update-api",
Paul Duffind1b3a922020-01-22 11:57:20 +0000762 script, filepath.Join(mctx.ModuleDir(), apiDir),
763 strings.Join(activeScopes.Strings(func(s *apiScope) string { return s.apiFilePrefix }), " "))
Inseob Kim8098faa2019-03-18 10:19:51 +0900764 return
765 }
766
Paul Duffind1b3a922020-01-22 11:57:20 +0000767 for _, scope := range activeScopes {
768 module.createStubsLibrary(mctx, scope)
769 module.createStubsSources(mctx, scope)
Inseob Kimc0907f12019-02-08 21:00:45 +0900770 }
771
Paul Duffin43db9be2019-12-30 17:35:49 +0000772 if !proptools.Bool(module.sdkLibraryProperties.Api_only) {
773 // for runtime
774 module.createXmlFile(mctx)
775
776 // record java_sdk_library modules so that they are exported to make
777 javaSdkLibraries := javaSdkLibraries(mctx.Config())
778 javaSdkLibrariesLock.Lock()
779 defer javaSdkLibrariesLock.Unlock()
780 *javaSdkLibraries = append(*javaSdkLibraries, module.BaseModuleName())
781 }
Inseob Kimc0907f12019-02-08 21:00:45 +0900782}
783
784func (module *SdkLibrary) InitSdkLibraryProperties() {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900785 module.AddProperties(
786 &module.sdkLibraryProperties,
787 &module.Library.Module.properties,
788 &module.Library.Module.dexpreoptProperties,
789 &module.Library.Module.deviceProperties,
790 &module.Library.Module.protoProperties,
791 )
792
793 module.Library.Module.properties.Installable = proptools.BoolPtr(true)
794 module.Library.Module.deviceProperties.IsSDKLibrary = true
Inseob Kimc0907f12019-02-08 21:00:45 +0900795}
Sundong Ahn054b19a2018-10-19 13:46:09 +0900796
Jaewoong Jung4f158ee2019-07-11 10:05:35 -0700797// java_sdk_library is a special Java library that provides optional platform APIs to apps.
798// In practice, it can be viewed as a combination of several modules: 1) stubs library that clients
799// are linked against to, 2) droiddoc module that internally generates API stubs source files,
800// 3) the real runtime shared library that implements the APIs, and 4) XML file for adding
801// the runtime lib to the classpath at runtime if requested via <uses-library>.
Inseob Kimc0907f12019-02-08 21:00:45 +0900802func SdkLibraryFactory() android.Module {
803 module := &SdkLibrary{}
804 module.InitSdkLibraryProperties()
Jooyung Han58f26ab2019-12-18 15:34:32 +0900805 android.InitApexModule(module)
Sundong Ahn054b19a2018-10-19 13:46:09 +0900806 InitJavaModule(module, android.HostAndDeviceSupported)
Colin Crossf8b860a2019-04-16 14:43:28 -0700807 android.AddLoadHook(module, func(ctx android.LoadHookContext) { module.CreateInternalModules(ctx) })
Jiyong Parkc678ad32018-04-10 13:07:10 +0900808 return module
809}
Colin Cross79c7c262019-04-17 11:11:46 -0700810
811//
812// SDK library prebuilts
813//
814
Paul Duffin56d44902020-01-31 13:36:25 +0000815// Properties associated with each api scope.
816type sdkLibraryScopeProperties struct {
Colin Cross79c7c262019-04-17 11:11:46 -0700817 Jars []string `android:"path"`
818
819 Sdk_version *string
820
Colin Cross79c7c262019-04-17 11:11:46 -0700821 // List of shared java libs that this module has dependencies to
822 Libs []string
Paul Duffin3d1248c2020-04-09 00:10:17 +0100823
824 // The stub sources.
825 Stub_srcs []string `android:"path"`
Paul Duffin1fd005d2020-04-09 01:08:11 +0100826
827 // The current.txt
828 Current_api string `android:"path"`
829
830 // The removed.txt
831 Removed_api string `android:"path"`
Colin Cross79c7c262019-04-17 11:11:46 -0700832}
833
Paul Duffin56d44902020-01-31 13:36:25 +0000834type sdkLibraryImportProperties struct {
Paul Duffinfcfd7912020-01-31 17:54:30 +0000835 // List of shared java libs, common to all scopes, that this module has
836 // dependencies to
837 Libs []string
Paul Duffin56d44902020-01-31 13:36:25 +0000838}
839
Colin Cross79c7c262019-04-17 11:11:46 -0700840type sdkLibraryImport struct {
841 android.ModuleBase
842 android.DefaultableModuleBase
843 prebuilt android.Prebuilt
Paul Duffindd46f712020-02-10 13:37:10 +0000844 android.ApexModuleBase
845 android.SdkBase
Colin Cross79c7c262019-04-17 11:11:46 -0700846
847 properties sdkLibraryImportProperties
848
Paul Duffin46a26a82020-04-07 19:27:04 +0100849 // Map from api scope to the scope specific property structure.
850 scopeProperties map[*apiScope]*sdkLibraryScopeProperties
851
Paul Duffin56d44902020-01-31 13:36:25 +0000852 commonToSdkLibraryAndImport
Colin Cross79c7c262019-04-17 11:11:46 -0700853}
854
855var _ SdkLibraryDependency = (*sdkLibraryImport)(nil)
856
Paul Duffin46a26a82020-04-07 19:27:04 +0100857// The type of a structure that contains a field of type sdkLibraryScopeProperties
858// for each apiscope in allApiScopes, e.g. something like:
859// struct {
860// Public sdkLibraryScopeProperties
861// System sdkLibraryScopeProperties
862// ...
863// }
864var allScopeStructType = createAllScopePropertiesStructType()
865
866// Dynamically create a structure type for each apiscope in allApiScopes.
867func createAllScopePropertiesStructType() reflect.Type {
868 var fields []reflect.StructField
869 for _, apiScope := range allApiScopes {
870 field := reflect.StructField{
871 Name: apiScope.fieldName,
872 Type: reflect.TypeOf(sdkLibraryScopeProperties{}),
873 }
874 fields = append(fields, field)
875 }
876
877 return reflect.StructOf(fields)
878}
879
880// Create an instance of the scope specific structure type and return a map
881// from apiscope to a pointer to each scope specific field.
882func createPropertiesInstance() (interface{}, map[*apiScope]*sdkLibraryScopeProperties) {
883 allScopePropertiesPtr := reflect.New(allScopeStructType)
884 allScopePropertiesStruct := allScopePropertiesPtr.Elem()
885 scopeProperties := make(map[*apiScope]*sdkLibraryScopeProperties)
886
887 for _, apiScope := range allApiScopes {
888 field := allScopePropertiesStruct.FieldByName(apiScope.fieldName)
889 scopeProperties[apiScope] = field.Addr().Interface().(*sdkLibraryScopeProperties)
890 }
891
892 return allScopePropertiesPtr.Interface(), scopeProperties
893}
894
Jaewoong Jung4f158ee2019-07-11 10:05:35 -0700895// java_sdk_library_import imports a prebuilt java_sdk_library.
Colin Cross79c7c262019-04-17 11:11:46 -0700896func sdkLibraryImportFactory() android.Module {
897 module := &sdkLibraryImport{}
898
Paul Duffin46a26a82020-04-07 19:27:04 +0100899 allScopeProperties, scopeToProperties := createPropertiesInstance()
900 module.scopeProperties = scopeToProperties
901 module.AddProperties(&module.properties, allScopeProperties)
Colin Cross79c7c262019-04-17 11:11:46 -0700902
Paul Duffin0bdcb272020-02-06 15:24:57 +0000903 android.InitPrebuiltModule(module, &[]string{""})
Paul Duffindd46f712020-02-10 13:37:10 +0000904 android.InitApexModule(module)
905 android.InitSdkAwareModule(module)
Colin Cross79c7c262019-04-17 11:11:46 -0700906 InitJavaModule(module, android.HostAndDeviceSupported)
907
908 android.AddLoadHook(module, func(mctx android.LoadHookContext) { module.createInternalModules(mctx) })
909 return module
910}
911
912func (module *sdkLibraryImport) Prebuilt() *android.Prebuilt {
913 return &module.prebuilt
914}
915
916func (module *sdkLibraryImport) Name() string {
917 return module.prebuilt.Name(module.ModuleBase.Name())
918}
919
920func (module *sdkLibraryImport) createInternalModules(mctx android.LoadHookContext) {
Colin Cross79c7c262019-04-17 11:11:46 -0700921
Paul Duffin50061512020-01-21 16:31:05 +0000922 // If the build is configured to use prebuilts then force this to be preferred.
923 if mctx.Config().UnbundledBuildUsePrebuiltSdks() {
924 module.prebuilt.ForcePrefer()
925 }
926
Paul Duffin46a26a82020-04-07 19:27:04 +0100927 for apiScope, scopeProperties := range module.scopeProperties {
Paul Duffin56d44902020-01-31 13:36:25 +0000928 if len(scopeProperties.Jars) == 0 {
929 continue
930 }
931
Paul Duffinbbb546b2020-04-09 00:07:11 +0100932 module.createJavaImportForStubs(mctx, apiScope, scopeProperties)
Paul Duffin3d1248c2020-04-09 00:10:17 +0100933
934 module.createPrebuiltStubsSources(mctx, apiScope, scopeProperties)
Paul Duffin56d44902020-01-31 13:36:25 +0000935 }
Colin Cross79c7c262019-04-17 11:11:46 -0700936
937 javaSdkLibraries := javaSdkLibraries(mctx.Config())
938 javaSdkLibrariesLock.Lock()
939 defer javaSdkLibrariesLock.Unlock()
940 *javaSdkLibraries = append(*javaSdkLibraries, module.BaseModuleName())
941}
942
Paul Duffinbbb546b2020-04-09 00:07:11 +0100943func (module *sdkLibraryImport) createJavaImportForStubs(mctx android.LoadHookContext, apiScope *apiScope, scopeProperties *sdkLibraryScopeProperties) {
944 // Creates a java import for the jar with ".stubs" suffix
945 props := struct {
946 Name *string
947 Soc_specific *bool
948 Device_specific *bool
949 Product_specific *bool
950 System_ext_specific *bool
951 Sdk_version *string
952 Libs []string
953 Jars []string
954 Prefer *bool
955 }{}
956 props.Name = proptools.StringPtr(apiScope.stubsModuleName(module.BaseModuleName()))
957 props.Sdk_version = scopeProperties.Sdk_version
958 // Prepend any of the libs from the legacy public properties to the libs for each of the
959 // scopes to avoid having to duplicate them in each scope.
960 props.Libs = append(module.properties.Libs, scopeProperties.Libs...)
961 props.Jars = scopeProperties.Jars
962 if module.SocSpecific() {
963 props.Soc_specific = proptools.BoolPtr(true)
964 } else if module.DeviceSpecific() {
965 props.Device_specific = proptools.BoolPtr(true)
966 } else if module.ProductSpecific() {
967 props.Product_specific = proptools.BoolPtr(true)
968 } else if module.SystemExtSpecific() {
969 props.System_ext_specific = proptools.BoolPtr(true)
970 }
971 // If the build should use prebuilt sdks then set prefer to true on the stubs library.
972 // That will cause the prebuilt version of the stubs to override the source version.
973 if mctx.Config().UnbundledBuildUsePrebuiltSdks() {
974 props.Prefer = proptools.BoolPtr(true)
975 }
976 mctx.CreateModule(ImportFactory, &props)
977}
978
Paul Duffin3d1248c2020-04-09 00:10:17 +0100979func (module *sdkLibraryImport) createPrebuiltStubsSources(mctx android.LoadHookContext, apiScope *apiScope, scopeProperties *sdkLibraryScopeProperties) {
980 props := struct {
981 Name *string
982 Srcs []string
983 }{}
984 props.Name = proptools.StringPtr(apiScope.docsModuleName(module.BaseModuleName()))
985 props.Srcs = scopeProperties.Stub_srcs
986 mctx.CreateModule(PrebuiltStubsSourcesFactory, &props)
987}
988
Colin Cross79c7c262019-04-17 11:11:46 -0700989func (module *sdkLibraryImport) DepsMutator(ctx android.BottomUpMutatorContext) {
Paul Duffin46a26a82020-04-07 19:27:04 +0100990 for apiScope, scopeProperties := range module.scopeProperties {
Paul Duffin56d44902020-01-31 13:36:25 +0000991 if len(scopeProperties.Jars) == 0 {
992 continue
993 }
994
995 // Add dependencies to the prebuilt stubs library
996 ctx.AddVariationDependencies(nil, apiScope.stubsTag, apiScope.stubsModuleName(module.BaseModuleName()))
997 }
Colin Cross79c7c262019-04-17 11:11:46 -0700998}
999
1000func (module *sdkLibraryImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1001 // Record the paths to the prebuilt stubs library.
1002 ctx.VisitDirectDeps(func(to android.Module) {
1003 tag := ctx.OtherModuleDependencyTag(to)
1004
Paul Duffin56d44902020-01-31 13:36:25 +00001005 if lib, ok := to.(Dependency); ok {
1006 if scopeTag, ok := tag.(scopeDependencyTag); ok {
1007 apiScope := scopeTag.apiScope
1008 scopePaths := module.getScopePaths(apiScope)
1009 scopePaths.stubsHeaderPath = lib.HeaderJars()
1010 }
Colin Cross79c7c262019-04-17 11:11:46 -07001011 }
1012 })
1013}
1014
Paul Duffin56d44902020-01-31 13:36:25 +00001015func (module *sdkLibraryImport) sdkJars(
1016 ctx android.BaseModuleContext,
1017 sdkVersion sdkSpec) android.Paths {
1018
Paul Duffin50061512020-01-21 16:31:05 +00001019 // If a specific numeric version has been requested then use prebuilt versions of the sdk.
1020 if sdkVersion.version.isNumbered() {
1021 return PrebuiltJars(ctx, module.BaseModuleName(), sdkVersion)
1022 }
1023
Paul Duffin56d44902020-01-31 13:36:25 +00001024 var apiScope *apiScope
1025 switch sdkVersion.kind {
1026 case sdkSystem:
1027 apiScope = apiScopeSystem
1028 case sdkTest:
1029 apiScope = apiScopeTest
1030 default:
1031 apiScope = apiScopePublic
1032 }
1033
1034 paths := module.getScopePaths(apiScope)
1035 return paths.stubsHeaderPath
1036}
1037
Colin Cross79c7c262019-04-17 11:11:46 -07001038// to satisfy SdkLibraryDependency interface
Jiyong Park6a927c42020-01-21 02:03:43 +09001039func (module *sdkLibraryImport) SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths {
Colin Cross79c7c262019-04-17 11:11:46 -07001040 // This module is just a wrapper for the prebuilt stubs.
Paul Duffin56d44902020-01-31 13:36:25 +00001041 return module.sdkJars(ctx, sdkVersion)
Colin Cross79c7c262019-04-17 11:11:46 -07001042}
1043
1044// to satisfy SdkLibraryDependency interface
Jiyong Park6a927c42020-01-21 02:03:43 +09001045func (module *sdkLibraryImport) SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths {
Colin Cross79c7c262019-04-17 11:11:46 -07001046 // This module is just a wrapper for the stubs.
Paul Duffin56d44902020-01-31 13:36:25 +00001047 return module.sdkJars(ctx, sdkVersion)
Colin Cross79c7c262019-04-17 11:11:46 -07001048}
Jiyong Parke3833882020-02-17 17:28:10 +09001049
1050//
1051// java_sdk_library_xml
1052//
1053type sdkLibraryXml struct {
1054 android.ModuleBase
1055 android.DefaultableModuleBase
1056 android.ApexModuleBase
1057
1058 properties sdkLibraryXmlProperties
1059
1060 outputFilePath android.OutputPath
1061 installDirPath android.InstallPath
1062}
1063
1064type sdkLibraryXmlProperties struct {
1065 // canonical name of the lib
1066 Lib_name *string
1067}
1068
1069// java_sdk_library_xml builds the permission xml file for a java_sdk_library.
1070// Not to be used directly by users. java_sdk_library internally uses this.
1071func sdkLibraryXmlFactory() android.Module {
1072 module := &sdkLibraryXml{}
1073
1074 module.AddProperties(&module.properties)
1075
1076 android.InitApexModule(module)
1077 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibCommon)
1078
1079 return module
1080}
1081
1082// from android.PrebuiltEtcModule
1083func (module *sdkLibraryXml) SubDir() string {
1084 return "permissions"
1085}
1086
1087// from android.PrebuiltEtcModule
1088func (module *sdkLibraryXml) OutputFile() android.OutputPath {
1089 return module.outputFilePath
1090}
1091
1092// from android.ApexModule
1093func (module *sdkLibraryXml) AvailableFor(what string) bool {
1094 return true
1095}
1096
1097func (module *sdkLibraryXml) DepsMutator(ctx android.BottomUpMutatorContext) {
1098 // do nothing
1099}
1100
1101// File path to the runtime implementation library
1102func (module *sdkLibraryXml) implPath() string {
1103 implName := proptools.String(module.properties.Lib_name)
1104 if apexName := module.ApexName(); apexName != "" {
1105 // TODO(b/146468504): ApexName() is only a soong module name, not apex name.
1106 // In most cases, this works fine. But when apex_name is set or override_apex is used
1107 // this can be wrong.
1108 return fmt.Sprintf("/apex/%s/javalib/%s.jar", apexName, implName)
1109 }
1110 partition := "system"
1111 if module.SocSpecific() {
1112 partition = "vendor"
1113 } else if module.DeviceSpecific() {
1114 partition = "odm"
1115 } else if module.ProductSpecific() {
1116 partition = "product"
1117 } else if module.SystemExtSpecific() {
1118 partition = "system_ext"
1119 }
1120 return "/" + partition + "/framework/" + implName + ".jar"
1121}
1122
1123func (module *sdkLibraryXml) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1124 libName := proptools.String(module.properties.Lib_name)
1125 xmlContent := fmt.Sprintf(permissionsTemplate, libName, module.implPath())
1126
1127 module.outputFilePath = android.PathForModuleOut(ctx, libName+".xml").OutputPath
1128 rule := android.NewRuleBuilder()
1129 rule.Command().
1130 Text("/bin/bash -c \"echo -e '" + xmlContent + "'\" > ").
1131 Output(module.outputFilePath)
1132
1133 rule.Build(pctx, ctx, "java_sdk_xml", "Permission XML")
1134
1135 module.installDirPath = android.PathForModuleInstall(ctx, "etc", module.SubDir())
1136}
1137
1138func (module *sdkLibraryXml) AndroidMkEntries() []android.AndroidMkEntries {
1139 if !module.IsForPlatform() {
1140 return []android.AndroidMkEntries{android.AndroidMkEntries{
1141 Disabled: true,
1142 }}
1143 }
1144
1145 return []android.AndroidMkEntries{android.AndroidMkEntries{
1146 Class: "ETC",
1147 OutputFile: android.OptionalPathForPath(module.outputFilePath),
1148 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
1149 func(entries *android.AndroidMkEntries) {
1150 entries.SetString("LOCAL_MODULE_TAGS", "optional")
1151 entries.SetString("LOCAL_MODULE_PATH", module.installDirPath.ToMakePath().String())
1152 entries.SetString("LOCAL_INSTALLED_MODULE_STEM", module.outputFilePath.Base())
1153 },
1154 },
1155 }}
1156}
Paul Duffindd46f712020-02-10 13:37:10 +00001157
1158type sdkLibrarySdkMemberType struct {
1159 android.SdkMemberTypeBase
1160}
1161
1162func (s *sdkLibrarySdkMemberType) AddDependencies(mctx android.BottomUpMutatorContext, dependencyTag blueprint.DependencyTag, names []string) {
1163 mctx.AddVariationDependencies(nil, dependencyTag, names...)
1164}
1165
1166func (s *sdkLibrarySdkMemberType) IsInstance(module android.Module) bool {
1167 _, ok := module.(*SdkLibrary)
1168 return ok
1169}
1170
1171func (s *sdkLibrarySdkMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule {
1172 return ctx.SnapshotBuilder().AddPrebuiltModule(member, "java_sdk_library_import")
1173}
1174
1175func (s *sdkLibrarySdkMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties {
1176 return &sdkLibrarySdkMemberProperties{}
1177}
1178
1179type sdkLibrarySdkMemberProperties struct {
1180 android.SdkMemberPropertiesBase
1181
1182 // Scope to per scope properties.
1183 Scopes map[*apiScope]scopeProperties
1184
1185 // Additional libraries that the exported stubs libraries depend upon.
1186 Libs []string
Paul Duffin3d1248c2020-04-09 00:10:17 +01001187
1188 // The Java stubs source files.
1189 Stub_srcs []string
Paul Duffindd46f712020-02-10 13:37:10 +00001190}
1191
1192type scopeProperties struct {
Paul Duffin1fd005d2020-04-09 01:08:11 +01001193 Jars android.Paths
1194 StubsSrcJar android.Path
1195 CurrentApiFile android.Path
1196 RemovedApiFile android.Path
1197 SdkVersion string
Paul Duffindd46f712020-02-10 13:37:10 +00001198}
1199
1200func (s *sdkLibrarySdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) {
1201 sdk := variant.(*SdkLibrary)
1202
1203 s.Scopes = make(map[*apiScope]scopeProperties)
1204 for _, apiScope := range allApiScopes {
1205 paths := sdk.getScopePaths(apiScope)
1206 jars := paths.stubsImplPath
1207 if len(jars) > 0 {
1208 properties := scopeProperties{}
1209 properties.Jars = jars
1210 properties.SdkVersion = apiScope.sdkVersion
Paul Duffin3d1248c2020-04-09 00:10:17 +01001211 properties.StubsSrcJar = paths.stubsSrcJar
Paul Duffin1fd005d2020-04-09 01:08:11 +01001212 properties.CurrentApiFile = paths.currentApiFilePath
1213 properties.RemovedApiFile = paths.removedApiFilePath
Paul Duffindd46f712020-02-10 13:37:10 +00001214 s.Scopes[apiScope] = properties
1215 }
1216 }
1217
1218 s.Libs = sdk.properties.Libs
1219}
1220
1221func (s *sdkLibrarySdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) {
1222 for _, apiScope := range allApiScopes {
1223 if properties, ok := s.Scopes[apiScope]; ok {
1224 scopeSet := propertySet.AddPropertySet(apiScope.name)
1225
Paul Duffin3d1248c2020-04-09 00:10:17 +01001226 scopeDir := filepath.Join("sdk_library", s.OsPrefix(), apiScope.name)
1227
Paul Duffindd46f712020-02-10 13:37:10 +00001228 var jars []string
1229 for _, p := range properties.Jars {
Paul Duffin3d1248c2020-04-09 00:10:17 +01001230 dest := filepath.Join(scopeDir, ctx.Name()+"-stubs.jar")
Paul Duffindd46f712020-02-10 13:37:10 +00001231 ctx.SnapshotBuilder().CopyToSnapshot(p, dest)
1232 jars = append(jars, dest)
1233 }
1234 scopeSet.AddProperty("jars", jars)
1235
Paul Duffin3d1248c2020-04-09 00:10:17 +01001236 // Merge the stubs source jar into the snapshot zip so that when it is unpacked
1237 // the source files are also unpacked.
1238 snapshotRelativeDir := filepath.Join(scopeDir, ctx.Name()+"_stub_sources")
1239 ctx.SnapshotBuilder().UnzipToSnapshot(properties.StubsSrcJar, snapshotRelativeDir)
1240 scopeSet.AddProperty("stub_srcs", []string{snapshotRelativeDir})
1241
Paul Duffin1fd005d2020-04-09 01:08:11 +01001242 if properties.CurrentApiFile != nil {
1243 currentApiSnapshotPath := filepath.Join(scopeDir, ctx.Name()+".txt")
1244 ctx.SnapshotBuilder().CopyToSnapshot(properties.CurrentApiFile, currentApiSnapshotPath)
1245 scopeSet.AddProperty("current_api", currentApiSnapshotPath)
1246 }
1247
1248 if properties.RemovedApiFile != nil {
1249 removedApiSnapshotPath := filepath.Join(scopeDir, ctx.Name()+"-removed.txt")
1250 ctx.SnapshotBuilder().CopyToSnapshot(properties.CurrentApiFile, removedApiSnapshotPath)
1251 scopeSet.AddProperty("removed_api", removedApiSnapshotPath)
1252 }
1253
Paul Duffindd46f712020-02-10 13:37:10 +00001254 if properties.SdkVersion != "" {
1255 scopeSet.AddProperty("sdk_version", properties.SdkVersion)
1256 }
1257 }
1258 }
1259
1260 if len(s.Libs) > 0 {
1261 propertySet.AddPropertyWithTag("libs", s.Libs, ctx.SnapshotBuilder().SdkMemberReferencePropertyTag(false))
1262 }
1263}