Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1 | // 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 | |
| 15 | package java |
| 16 | |
| 17 | import ( |
| 18 | "android/soong/android" |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 19 | "fmt" |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 20 | "io" |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 21 | "path" |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 22 | "path/filepath" |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 23 | "sort" |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 24 | "strings" |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 25 | "sync" |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 26 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 27 | "github.com/google/blueprint/proptools" |
| 28 | ) |
| 29 | |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 30 | const ( |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 31 | sdkStubsLibrarySuffix = ".stubs" |
| 32 | sdkSystemApiSuffix = ".system" |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 33 | sdkTestApiSuffix = ".test" |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 34 | sdkDocsSuffix = ".docs" |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 35 | sdkXmlFileSuffix = ".xml" |
Jooyung Han | 624058e | 2019-12-24 18:38:06 +0900 | [diff] [blame] | 36 | permissionsTemplate = `<?xml version="1.0" encoding="utf-8"?>\n` + |
| 37 | `<!-- Copyright (C) 2018 The Android Open Source Project\n` + |
| 38 | `\n` + |
| 39 | ` Licensed under the Apache License, Version 2.0 (the "License");\n` + |
| 40 | ` you may not use this file except in compliance with the License.\n` + |
| 41 | ` You may obtain a copy of the License at\n` + |
| 42 | `\n` + |
| 43 | ` http://www.apache.org/licenses/LICENSE-2.0\n` + |
| 44 | `\n` + |
| 45 | ` Unless required by applicable law or agreed to in writing, software\n` + |
| 46 | ` distributed under the License is distributed on an "AS IS" BASIS,\n` + |
| 47 | ` WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n` + |
| 48 | ` See the License for the specific language governing permissions and\n` + |
| 49 | ` limitations under the License.\n` + |
| 50 | `-->\n` + |
| 51 | `<permissions>\n` + |
| 52 | ` <library name="%s" file="%s"/>\n` + |
| 53 | `</permissions>\n` |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 54 | ) |
| 55 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 56 | var ( |
| 57 | publicApiStubsTag = dependencyTag{name: "public"} |
| 58 | systemApiStubsTag = dependencyTag{name: "system"} |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 59 | testApiStubsTag = dependencyTag{name: "test"} |
Sundong Ahn | 20e998b | 2018-07-24 11:19:26 +0900 | [diff] [blame] | 60 | publicApiFileTag = dependencyTag{name: "publicApi"} |
| 61 | systemApiFileTag = dependencyTag{name: "systemApi"} |
| 62 | testApiFileTag = dependencyTag{name: "testApi"} |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 63 | ) |
| 64 | |
| 65 | type apiScope int |
| 66 | |
| 67 | const ( |
| 68 | apiScopePublic apiScope = iota |
| 69 | apiScopeSystem |
| 70 | apiScopeTest |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 71 | ) |
| 72 | |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 73 | var ( |
| 74 | javaSdkLibrariesLock sync.Mutex |
| 75 | ) |
| 76 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 77 | // TODO: these are big features that are currently missing |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 78 | // 1) disallowing linking to the runtime shared lib |
| 79 | // 2) HTML generation |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 80 | |
| 81 | func init() { |
Paul Duffin | 43dc1cc | 2019-12-19 11:18:54 +0000 | [diff] [blame] | 82 | RegisterSdkLibraryBuildComponents(android.InitRegistrationContext) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 83 | |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 84 | android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) { |
| 85 | javaSdkLibraries := javaSdkLibraries(ctx.Config()) |
| 86 | sort.Strings(*javaSdkLibraries) |
| 87 | ctx.Strict("JAVA_SDK_LIBRARIES", strings.Join(*javaSdkLibraries, " ")) |
| 88 | }) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 89 | } |
| 90 | |
Paul Duffin | 43dc1cc | 2019-12-19 11:18:54 +0000 | [diff] [blame] | 91 | func RegisterSdkLibraryBuildComponents(ctx android.RegistrationContext) { |
| 92 | ctx.RegisterModuleType("java_sdk_library", SdkLibraryFactory) |
| 93 | ctx.RegisterModuleType("java_sdk_library_import", sdkLibraryImportFactory) |
| 94 | } |
| 95 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 96 | type sdkLibraryProperties struct { |
Sundong Ahn | f043cf6 | 2018-06-25 16:04:37 +0900 | [diff] [blame] | 97 | // List of Java libraries that will be in the classpath when building stubs |
| 98 | Stub_only_libs []string `android:"arch_variant"` |
| 99 | |
Paul Duffin | 7a586d3 | 2019-12-30 17:09:34 +0000 | [diff] [blame] | 100 | // list of package names that will be documented and publicized as API. |
| 101 | // This allows the API to be restricted to a subset of the source files provided. |
| 102 | // If this is unspecified then all the source files will be treated as being part |
| 103 | // of the API. |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 104 | Api_packages []string |
| 105 | |
Jiyong Park | 5a2c9d7 | 2018-05-01 22:25:41 +0900 | [diff] [blame] | 106 | // list of package names that must be hidden from the API |
| 107 | Hidden_api_packages []string |
| 108 | |
Paul Duffin | 749f98f | 2019-12-30 17:23:46 +0000 | [diff] [blame] | 109 | // the relative path to the directory containing the api specification files. |
| 110 | // Defaults to "api". |
| 111 | Api_dir *string |
| 112 | |
Paul Duffin | 43db9be | 2019-12-30 17:35:49 +0000 | [diff] [blame^] | 113 | // If set to true there is no runtime library. |
| 114 | Api_only *bool |
| 115 | |
Paul Duffin | 1151247 | 2019-02-11 15:55:17 +0000 | [diff] [blame] | 116 | // local files that are used within user customized droiddoc options. |
| 117 | Droiddoc_option_files []string |
| 118 | |
| 119 | // additional droiddoc options |
| 120 | // Available variables for substitution: |
| 121 | // |
| 122 | // $(location <label>): the path to the droiddoc_option_files with name <label> |
Sundong Ahn | dd567f9 | 2018-07-31 17:19:11 +0900 | [diff] [blame] | 123 | Droiddoc_options []string |
| 124 | |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 125 | // a list of top-level directories containing files to merge qualifier annotations |
| 126 | // (i.e. those intended to be included in the stubs written) from. |
| 127 | Merge_annotations_dirs []string |
| 128 | |
| 129 | // a list of top-level directories containing Java stub files to merge show/hide annotations from. |
| 130 | Merge_inclusion_annotations_dirs []string |
| 131 | |
| 132 | // If set to true, the path of dist files is apistubs/core. Defaults to false. |
| 133 | Core_lib *bool |
| 134 | |
Sundong Ahn | 80a87b3 | 2019-05-13 15:02:50 +0900 | [diff] [blame] | 135 | // don't create dist rules. |
| 136 | No_dist *bool `blueprint:"mutated"` |
| 137 | |
Paul Duffin | 37e0b77 | 2019-12-30 17:20:10 +0000 | [diff] [blame] | 138 | // indicates whether system and test apis should be managed. |
| 139 | Has_system_and_test_apis bool `blueprint:"mutated"` |
| 140 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 141 | // TODO: determines whether to create HTML doc or not |
| 142 | //Html_doc *bool |
| 143 | } |
| 144 | |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 145 | type SdkLibrary struct { |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 146 | Library |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 147 | |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 148 | sdkLibraryProperties sdkLibraryProperties |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 149 | |
| 150 | publicApiStubsPath android.Paths |
| 151 | systemApiStubsPath android.Paths |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 152 | testApiStubsPath android.Paths |
Sundong Ahn | 241cd37 | 2018-07-13 16:16:44 +0900 | [diff] [blame] | 153 | |
| 154 | publicApiStubsImplPath android.Paths |
| 155 | systemApiStubsImplPath android.Paths |
| 156 | testApiStubsImplPath android.Paths |
Sundong Ahn | 20e998b | 2018-07-24 11:19:26 +0900 | [diff] [blame] | 157 | |
| 158 | publicApiFilePath android.Path |
| 159 | systemApiFilePath android.Path |
| 160 | testApiFilePath android.Path |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 161 | |
Jooyung Han | 624058e | 2019-12-24 18:38:06 +0900 | [diff] [blame] | 162 | permissionsFile android.Path |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 163 | } |
| 164 | |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 165 | var _ Dependency = (*SdkLibrary)(nil) |
| 166 | var _ SdkLibraryDependency = (*SdkLibrary)(nil) |
Colin Cross | 897d2ed | 2019-02-11 14:03:51 -0800 | [diff] [blame] | 167 | |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 168 | func (module *SdkLibrary) DepsMutator(ctx android.BottomUpMutatorContext) { |
Jiyong Park | e3ef3c8 | 2019-07-15 15:31:16 +0900 | [diff] [blame] | 169 | useBuiltStubs := !ctx.Config().UnbundledBuildUsePrebuiltSdks() |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 170 | // Add dependencies to the stubs library |
Jiyong Park | e3ef3c8 | 2019-07-15 15:31:16 +0900 | [diff] [blame] | 171 | if useBuiltStubs { |
| 172 | ctx.AddVariationDependencies(nil, publicApiStubsTag, module.stubsName(apiScopePublic)) |
| 173 | } |
Colin Cross | 42d48b7 | 2018-08-29 14:10:52 -0700 | [diff] [blame] | 174 | ctx.AddVariationDependencies(nil, publicApiFileTag, module.docsName(apiScopePublic)) |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 175 | |
Paul Duffin | 37e0b77 | 2019-12-30 17:20:10 +0000 | [diff] [blame] | 176 | if module.sdkLibraryProperties.Has_system_and_test_apis { |
Jiyong Park | e3ef3c8 | 2019-07-15 15:31:16 +0900 | [diff] [blame] | 177 | if useBuiltStubs { |
| 178 | ctx.AddVariationDependencies(nil, systemApiStubsTag, module.stubsName(apiScopeSystem)) |
| 179 | ctx.AddVariationDependencies(nil, testApiStubsTag, module.stubsName(apiScopeTest)) |
| 180 | } |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 181 | ctx.AddVariationDependencies(nil, systemApiFileTag, module.docsName(apiScopeSystem)) |
| 182 | ctx.AddVariationDependencies(nil, testApiFileTag, module.docsName(apiScopeTest)) |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | module.Library.deps(ctx) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 186 | } |
| 187 | |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 188 | func (module *SdkLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Paul Duffin | 43db9be | 2019-12-30 17:35:49 +0000 | [diff] [blame^] | 189 | // Don't build an implementation library if this is api only. |
| 190 | if !proptools.Bool(module.sdkLibraryProperties.Api_only) { |
| 191 | module.Library.GenerateAndroidBuildActions(ctx) |
| 192 | } |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 193 | |
Jooyung Han | 624058e | 2019-12-24 18:38:06 +0900 | [diff] [blame] | 194 | module.buildPermissionsFile(ctx) |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 195 | |
Sundong Ahn | 57368eb | 2018-07-06 11:20:23 +0900 | [diff] [blame] | 196 | // Record the paths to the header jars of the library (stubs and impl). |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 197 | // When this java_sdk_library is dependened from others via "libs" property, |
| 198 | // the recorded paths will be returned depending on the link type of the caller. |
| 199 | ctx.VisitDirectDeps(func(to android.Module) { |
| 200 | otherName := ctx.OtherModuleName(to) |
| 201 | tag := ctx.OtherModuleDependencyTag(to) |
| 202 | |
Sundong Ahn | 57368eb | 2018-07-06 11:20:23 +0900 | [diff] [blame] | 203 | if lib, ok := to.(Dependency); ok { |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 204 | switch tag { |
| 205 | case publicApiStubsTag: |
Sundong Ahn | 57368eb | 2018-07-06 11:20:23 +0900 | [diff] [blame] | 206 | module.publicApiStubsPath = lib.HeaderJars() |
Sundong Ahn | 241cd37 | 2018-07-13 16:16:44 +0900 | [diff] [blame] | 207 | module.publicApiStubsImplPath = lib.ImplementationJars() |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 208 | case systemApiStubsTag: |
Sundong Ahn | 57368eb | 2018-07-06 11:20:23 +0900 | [diff] [blame] | 209 | module.systemApiStubsPath = lib.HeaderJars() |
Sundong Ahn | 241cd37 | 2018-07-13 16:16:44 +0900 | [diff] [blame] | 210 | module.systemApiStubsImplPath = lib.ImplementationJars() |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 211 | case testApiStubsTag: |
Sundong Ahn | 57368eb | 2018-07-06 11:20:23 +0900 | [diff] [blame] | 212 | module.testApiStubsPath = lib.HeaderJars() |
Sundong Ahn | 241cd37 | 2018-07-13 16:16:44 +0900 | [diff] [blame] | 213 | module.testApiStubsImplPath = lib.ImplementationJars() |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 214 | } |
| 215 | } |
Sundong Ahn | 20e998b | 2018-07-24 11:19:26 +0900 | [diff] [blame] | 216 | if doc, ok := to.(ApiFilePath); ok { |
| 217 | switch tag { |
| 218 | case publicApiFileTag: |
| 219 | module.publicApiFilePath = doc.ApiFilePath() |
| 220 | case systemApiFileTag: |
| 221 | module.systemApiFilePath = doc.ApiFilePath() |
| 222 | case testApiFileTag: |
| 223 | module.testApiFilePath = doc.ApiFilePath() |
| 224 | default: |
| 225 | ctx.ModuleErrorf("depends on module %q of unknown tag %q", otherName, tag) |
| 226 | } |
| 227 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 228 | }) |
| 229 | } |
| 230 | |
Jooyung Han | 624058e | 2019-12-24 18:38:06 +0900 | [diff] [blame] | 231 | func (module *SdkLibrary) buildPermissionsFile(ctx android.ModuleContext) { |
| 232 | xmlContent := fmt.Sprintf(permissionsTemplate, module.BaseModuleName(), module.implPath()) |
| 233 | permissionsFile := android.PathForModuleOut(ctx, module.xmlFileName()) |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 234 | |
Jooyung Han | 624058e | 2019-12-24 18:38:06 +0900 | [diff] [blame] | 235 | ctx.Build(pctx, android.BuildParams{ |
| 236 | Rule: android.WriteFile, |
| 237 | Output: permissionsFile, |
| 238 | Description: "Generating " + module.BaseModuleName() + " permissions", |
| 239 | Args: map[string]string{ |
| 240 | "content": xmlContent, |
| 241 | }, |
| 242 | }) |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 243 | |
Jooyung Han | 624058e | 2019-12-24 18:38:06 +0900 | [diff] [blame] | 244 | module.permissionsFile = permissionsFile |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 245 | } |
| 246 | |
Jooyung Han | 624058e | 2019-12-24 18:38:06 +0900 | [diff] [blame] | 247 | func (module *SdkLibrary) OutputFiles(tag string) (android.Paths, error) { |
| 248 | switch tag { |
| 249 | case ".xml": |
| 250 | return android.Paths{module.permissionsFile}, nil |
| 251 | } |
| 252 | return module.Library.OutputFiles(tag) |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 253 | } |
| 254 | |
Jiyong Park | 0b0e1b9 | 2019-12-03 13:24:29 +0900 | [diff] [blame] | 255 | func (module *SdkLibrary) AndroidMkEntries() []android.AndroidMkEntries { |
Paul Duffin | 43db9be | 2019-12-30 17:35:49 +0000 | [diff] [blame^] | 256 | if proptools.Bool(module.sdkLibraryProperties.Api_only) { |
| 257 | return nil |
| 258 | } |
Jiyong Park | 0b0e1b9 | 2019-12-03 13:24:29 +0900 | [diff] [blame] | 259 | entriesList := module.Library.AndroidMkEntries() |
| 260 | entries := &entriesList[0] |
Jaewoong Jung | b0c127c | 2019-08-29 14:56:03 -0700 | [diff] [blame] | 261 | entries.Required = append(entries.Required, module.xmlFileName()) |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 262 | |
Jaewoong Jung | b0c127c | 2019-08-29 14:56:03 -0700 | [diff] [blame] | 263 | entries.ExtraFooters = []android.AndroidMkExtraFootersFunc{ |
| 264 | func(w io.Writer, name, prefix, moduleDir string, entries *android.AndroidMkEntries) { |
Jaewoong Jung | b0c127c | 2019-08-29 14:56:03 -0700 | [diff] [blame] | 265 | if !Bool(module.sdkLibraryProperties.No_dist) { |
| 266 | // Create a phony module that installs the impl library, for the case when this lib is |
| 267 | // in PRODUCT_PACKAGES. |
| 268 | owner := module.ModuleBase.Owner() |
| 269 | if owner == "" { |
| 270 | if Bool(module.sdkLibraryProperties.Core_lib) { |
| 271 | owner = "core" |
| 272 | } else { |
| 273 | owner = "android" |
| 274 | } |
| 275 | } |
| 276 | // Create dist rules to install the stubs libs to the dist dir |
| 277 | if len(module.publicApiStubsPath) == 1 { |
| 278 | fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+ |
| 279 | module.publicApiStubsImplPath.Strings()[0]+ |
| 280 | ":"+path.Join("apistubs", owner, "public", |
| 281 | module.BaseModuleName()+".jar")+")") |
| 282 | } |
| 283 | if len(module.systemApiStubsPath) == 1 { |
| 284 | fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+ |
| 285 | module.systemApiStubsImplPath.Strings()[0]+ |
| 286 | ":"+path.Join("apistubs", owner, "system", |
| 287 | module.BaseModuleName()+".jar")+")") |
| 288 | } |
| 289 | if len(module.testApiStubsPath) == 1 { |
| 290 | fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+ |
| 291 | module.testApiStubsImplPath.Strings()[0]+ |
| 292 | ":"+path.Join("apistubs", owner, "test", |
| 293 | module.BaseModuleName()+".jar")+")") |
| 294 | } |
| 295 | if module.publicApiFilePath != nil { |
| 296 | fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+ |
| 297 | module.publicApiFilePath.String()+ |
| 298 | ":"+path.Join("apistubs", owner, "public", "api", |
| 299 | module.BaseModuleName()+".txt")+")") |
| 300 | } |
| 301 | if module.systemApiFilePath != nil { |
| 302 | fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+ |
| 303 | module.systemApiFilePath.String()+ |
| 304 | ":"+path.Join("apistubs", owner, "system", "api", |
| 305 | module.BaseModuleName()+".txt")+")") |
| 306 | } |
| 307 | if module.testApiFilePath != nil { |
| 308 | fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+ |
| 309 | module.testApiFilePath.String()+ |
| 310 | ":"+path.Join("apistubs", owner, "test", "api", |
| 311 | module.BaseModuleName()+".txt")+")") |
Sundong Ahn | 80a87b3 | 2019-05-13 15:02:50 +0900 | [diff] [blame] | 312 | } |
Sundong Ahn | 4fd04bb | 2018-08-31 18:01:37 +0900 | [diff] [blame] | 313 | } |
Jaewoong Jung | b0c127c | 2019-08-29 14:56:03 -0700 | [diff] [blame] | 314 | }, |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 315 | } |
Jiyong Park | 0b0e1b9 | 2019-12-03 13:24:29 +0900 | [diff] [blame] | 316 | return entriesList |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 317 | } |
| 318 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 319 | // Module name of the stubs library |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 320 | func (module *SdkLibrary) stubsName(apiScope apiScope) string { |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 321 | stubsName := module.BaseModuleName() + sdkStubsLibrarySuffix |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 322 | switch apiScope { |
| 323 | case apiScopeSystem: |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 324 | stubsName = stubsName + sdkSystemApiSuffix |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 325 | case apiScopeTest: |
| 326 | stubsName = stubsName + sdkTestApiSuffix |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 327 | } |
| 328 | return stubsName |
| 329 | } |
| 330 | |
| 331 | // Module name of the docs |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 332 | func (module *SdkLibrary) docsName(apiScope apiScope) string { |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 333 | docsName := module.BaseModuleName() + sdkDocsSuffix |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 334 | switch apiScope { |
| 335 | case apiScopeSystem: |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 336 | docsName = docsName + sdkSystemApiSuffix |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 337 | case apiScopeTest: |
| 338 | docsName = docsName + sdkTestApiSuffix |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 339 | } |
| 340 | return docsName |
| 341 | } |
| 342 | |
| 343 | // Module name of the runtime implementation library |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 344 | func (module *SdkLibrary) implName() string { |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 345 | return module.BaseModuleName() |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 346 | } |
| 347 | |
| 348 | // File path to the runtime implementation library |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 349 | func (module *SdkLibrary) implPath() string { |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 350 | if apexName := module.ApexName(); apexName != "" { |
| 351 | // TODO(b/146468504): ApexName() is only a soong module name, not apex name. |
| 352 | // In most cases, this works fine. But when apex_name is set or override_apex is used |
| 353 | // this can be wrong. |
| 354 | return fmt.Sprintf("/apex/%s/javalib/%s.jar", apexName, module.implName()) |
| 355 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 356 | partition := "system" |
| 357 | if module.SocSpecific() { |
| 358 | partition = "vendor" |
| 359 | } else if module.DeviceSpecific() { |
| 360 | partition = "odm" |
| 361 | } else if module.ProductSpecific() { |
| 362 | partition = "product" |
Sundong Ahn | 0d7dff4 | 2019-12-04 12:53:44 +0900 | [diff] [blame] | 363 | } else if module.SystemExtSpecific() { |
| 364 | partition = "system_ext" |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 365 | } |
| 366 | return "/" + partition + "/framework/" + module.implName() + ".jar" |
| 367 | } |
| 368 | |
| 369 | // Module name of the XML file for the lib |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 370 | func (module *SdkLibrary) xmlFileName() string { |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 371 | return module.BaseModuleName() + sdkXmlFileSuffix |
| 372 | } |
| 373 | |
| 374 | // SDK version that the stubs library is built against. Note that this is always |
| 375 | // *current. Older stubs library built with a numberd SDK version is created from |
| 376 | // the prebuilt jar. |
Paul Duffin | 12ceb46 | 2019-12-24 20:31:31 +0000 | [diff] [blame] | 377 | func (module *SdkLibrary) sdkVersionForScope(apiScope apiScope) string { |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 378 | switch apiScope { |
| 379 | case apiScopePublic: |
| 380 | return "current" |
| 381 | case apiScopeSystem: |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 382 | return "system_current" |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 383 | case apiScopeTest: |
| 384 | return "test_current" |
| 385 | default: |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 386 | return "current" |
| 387 | } |
| 388 | } |
| 389 | |
Paul Duffin | 12ceb46 | 2019-12-24 20:31:31 +0000 | [diff] [blame] | 390 | // Get the sdk version for use when compiling the stubs library. |
| 391 | func (module *SdkLibrary) sdkVersionForStubsLibrary(mctx android.BaseModuleContext, apiScope apiScope) string { |
| 392 | sdkDep := decodeSdkDep(mctx, sdkContext(&module.Library)) |
| 393 | if sdkDep.hasStandardLibs() { |
| 394 | // If building against a standard sdk then use the sdk version appropriate for the scope. |
| 395 | return module.sdkVersionForScope(apiScope) |
| 396 | } else { |
| 397 | // Otherwise, use no system module. |
| 398 | return "none" |
| 399 | } |
| 400 | } |
| 401 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 402 | // $(INTERNAL_PLATFORM_<apiTagName>_API_FILE) points to the generated |
| 403 | // api file for the current source |
| 404 | // TODO: remove this when apicheck is done in soong |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 405 | func (module *SdkLibrary) apiTagName(apiScope apiScope) string { |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 406 | apiTagName := strings.Replace(strings.ToUpper(module.BaseModuleName()), ".", "_", -1) |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 407 | switch apiScope { |
| 408 | case apiScopeSystem: |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 409 | apiTagName = apiTagName + "_SYSTEM" |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 410 | case apiScopeTest: |
| 411 | apiTagName = apiTagName + "_TEST" |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 412 | } |
| 413 | return apiTagName |
| 414 | } |
| 415 | |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 416 | func (module *SdkLibrary) latestApiFilegroupName(apiScope apiScope) string { |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 417 | name := ":" + module.BaseModuleName() + ".api." |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 418 | switch apiScope { |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 419 | case apiScopePublic: |
| 420 | name = name + "public" |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 421 | case apiScopeSystem: |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 422 | name = name + "system" |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 423 | case apiScopeTest: |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 424 | name = name + "test" |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 425 | } |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 426 | name = name + ".latest" |
| 427 | return name |
| 428 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 429 | |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 430 | func (module *SdkLibrary) latestRemovedApiFilegroupName(apiScope apiScope) string { |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 431 | name := ":" + module.BaseModuleName() + "-removed.api." |
| 432 | switch apiScope { |
| 433 | case apiScopePublic: |
| 434 | name = name + "public" |
| 435 | case apiScopeSystem: |
| 436 | name = name + "system" |
| 437 | case apiScopeTest: |
| 438 | name = name + "test" |
| 439 | } |
| 440 | name = name + ".latest" |
| 441 | return name |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 442 | } |
| 443 | |
| 444 | // Creates a static java library that has API stubs |
Colin Cross | f8b860a | 2019-04-16 14:43:28 -0700 | [diff] [blame] | 445 | func (module *SdkLibrary) createStubsLibrary(mctx android.LoadHookContext, apiScope apiScope) { |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 446 | props := struct { |
Sundong Ahn | 0d7dff4 | 2019-12-04 12:53:44 +0900 | [diff] [blame] | 447 | Name *string |
| 448 | Srcs []string |
| 449 | Sdk_version *string |
Paul Duffin | 12ceb46 | 2019-12-24 20:31:31 +0000 | [diff] [blame] | 450 | System_modules *string |
Sundong Ahn | 0d7dff4 | 2019-12-04 12:53:44 +0900 | [diff] [blame] | 451 | Libs []string |
| 452 | Soc_specific *bool |
| 453 | Device_specific *bool |
| 454 | Product_specific *bool |
| 455 | System_ext_specific *bool |
| 456 | Compile_dex *bool |
Sundong Ahn | 0d7dff4 | 2019-12-04 12:53:44 +0900 | [diff] [blame] | 457 | Java_version *string |
| 458 | Product_variables struct { |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 459 | Unbundled_build struct { |
| 460 | Enabled *bool |
| 461 | } |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 462 | Pdk struct { |
| 463 | Enabled *bool |
| 464 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 465 | } |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 466 | Openjdk9 struct { |
| 467 | Srcs []string |
| 468 | Javacflags []string |
| 469 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 470 | }{} |
| 471 | |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 472 | props.Name = proptools.StringPtr(module.stubsName(apiScope)) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 473 | // sources are generated from the droiddoc |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 474 | props.Srcs = []string{":" + module.docsName(apiScope)} |
Paul Duffin | 12ceb46 | 2019-12-24 20:31:31 +0000 | [diff] [blame] | 475 | sdkVersion := module.sdkVersionForStubsLibrary(mctx, apiScope) |
Paul Duffin | 52d398a | 2019-06-11 12:31:14 +0100 | [diff] [blame] | 476 | props.Sdk_version = proptools.StringPtr(sdkVersion) |
Paul Duffin | 12ceb46 | 2019-12-24 20:31:31 +0000 | [diff] [blame] | 477 | props.System_modules = module.Library.Module.deviceProperties.System_modules |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 478 | props.Libs = module.sdkLibraryProperties.Stub_only_libs |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 479 | // Unbundled apps will use the prebult one from /prebuilts/sdk |
Colin Cross | 1093287 | 2019-04-18 14:27:12 -0700 | [diff] [blame] | 480 | if mctx.Config().UnbundledBuildUsePrebuiltSdks() { |
Colin Cross | 2c77ceb | 2019-01-21 11:56:21 -0800 | [diff] [blame] | 481 | props.Product_variables.Unbundled_build.Enabled = proptools.BoolPtr(false) |
| 482 | } |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 483 | props.Product_variables.Pdk.Enabled = proptools.BoolPtr(false) |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 484 | props.Openjdk9.Srcs = module.Library.Module.properties.Openjdk9.Srcs |
| 485 | props.Openjdk9.Javacflags = module.Library.Module.properties.Openjdk9.Javacflags |
| 486 | props.Java_version = module.Library.Module.properties.Java_version |
| 487 | if module.Library.Module.deviceProperties.Compile_dex != nil { |
| 488 | props.Compile_dex = module.Library.Module.deviceProperties.Compile_dex |
Sundong Ahn | dd567f9 | 2018-07-31 17:19:11 +0900 | [diff] [blame] | 489 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 490 | |
| 491 | if module.SocSpecific() { |
| 492 | props.Soc_specific = proptools.BoolPtr(true) |
| 493 | } else if module.DeviceSpecific() { |
| 494 | props.Device_specific = proptools.BoolPtr(true) |
| 495 | } else if module.ProductSpecific() { |
| 496 | props.Product_specific = proptools.BoolPtr(true) |
Sundong Ahn | 0d7dff4 | 2019-12-04 12:53:44 +0900 | [diff] [blame] | 497 | } else if module.SystemExtSpecific() { |
| 498 | props.System_ext_specific = proptools.BoolPtr(true) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 499 | } |
| 500 | |
Colin Cross | 84dfc3d | 2019-09-25 11:33:01 -0700 | [diff] [blame] | 501 | mctx.CreateModule(LibraryFactory, &props) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 502 | } |
| 503 | |
| 504 | // Creates a droiddoc module that creates stubs source files from the given full source |
| 505 | // files |
Paul Duffin | c4cea76 | 2019-12-30 17:32:47 +0000 | [diff] [blame] | 506 | func (module *SdkLibrary) createStubsSources(mctx android.LoadHookContext, apiScope apiScope) { |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 507 | props := struct { |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 508 | Name *string |
| 509 | Srcs []string |
| 510 | Installable *bool |
Paul Duffin | 52d398a | 2019-06-11 12:31:14 +0100 | [diff] [blame] | 511 | Sdk_version *string |
Paul Duffin | 12ceb46 | 2019-12-24 20:31:31 +0000 | [diff] [blame] | 512 | System_modules *string |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 513 | Libs []string |
Paul Duffin | 1151247 | 2019-02-11 15:55:17 +0000 | [diff] [blame] | 514 | Arg_files []string |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 515 | Args *string |
| 516 | Api_tag_name *string |
| 517 | Api_filename *string |
| 518 | Removed_api_filename *string |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 519 | Java_version *string |
| 520 | Merge_annotations_dirs []string |
| 521 | Merge_inclusion_annotations_dirs []string |
| 522 | Check_api struct { |
Inseob Kim | 38449af | 2019-02-28 14:24:05 +0900 | [diff] [blame] | 523 | Current ApiToCheck |
| 524 | Last_released ApiToCheck |
| 525 | Ignore_missing_latest_api *bool |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 526 | } |
Sundong Ahn | 1b92c82 | 2018-05-29 11:35:17 +0900 | [diff] [blame] | 527 | Aidl struct { |
| 528 | Include_dirs []string |
| 529 | Local_include_dirs []string |
| 530 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 531 | }{} |
| 532 | |
Paul Duffin | 250e619 | 2019-06-07 10:44:37 +0100 | [diff] [blame] | 533 | sdkDep := decodeSdkDep(mctx, sdkContext(&module.Library)) |
Paul Duffin | 12ceb46 | 2019-12-24 20:31:31 +0000 | [diff] [blame] | 534 | // Use the platform API if standard libraries were requested, otherwise use |
| 535 | // no default libraries. |
Paul Duffin | 52d398a | 2019-06-11 12:31:14 +0100 | [diff] [blame] | 536 | sdkVersion := "" |
| 537 | if !sdkDep.hasStandardLibs() { |
| 538 | sdkVersion = "none" |
| 539 | } |
Paul Duffin | 250e619 | 2019-06-07 10:44:37 +0100 | [diff] [blame] | 540 | |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 541 | props.Name = proptools.StringPtr(module.docsName(apiScope)) |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 542 | props.Srcs = append(props.Srcs, module.Library.Module.properties.Srcs...) |
Paul Duffin | 52d398a | 2019-06-11 12:31:14 +0100 | [diff] [blame] | 543 | props.Sdk_version = proptools.StringPtr(sdkVersion) |
Paul Duffin | 12ceb46 | 2019-12-24 20:31:31 +0000 | [diff] [blame] | 544 | props.System_modules = module.Library.Module.deviceProperties.System_modules |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 545 | props.Installable = proptools.BoolPtr(false) |
Sundong Ahn | e6f0b05 | 2018-06-05 16:46:14 +0900 | [diff] [blame] | 546 | // A droiddoc module has only one Libs property and doesn't distinguish between |
| 547 | // shared libs and static libs. So we need to add both of these libs to Libs property. |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 548 | props.Libs = module.Library.Module.properties.Libs |
| 549 | props.Libs = append(props.Libs, module.Library.Module.properties.Static_libs...) |
| 550 | props.Aidl.Include_dirs = module.Library.Module.deviceProperties.Aidl.Include_dirs |
| 551 | props.Aidl.Local_include_dirs = module.Library.Module.deviceProperties.Aidl.Local_include_dirs |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 552 | props.Java_version = module.Library.Module.properties.Java_version |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 553 | |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 554 | props.Merge_annotations_dirs = module.sdkLibraryProperties.Merge_annotations_dirs |
| 555 | props.Merge_inclusion_annotations_dirs = module.sdkLibraryProperties.Merge_inclusion_annotations_dirs |
| 556 | |
Paul Duffin | 235ffff | 2019-12-24 10:41:30 +0000 | [diff] [blame] | 557 | droiddocArgs := []string{} |
| 558 | if len(module.sdkLibraryProperties.Api_packages) != 0 { |
| 559 | droiddocArgs = append(droiddocArgs, "--stub-packages "+strings.Join(module.sdkLibraryProperties.Api_packages, ":")) |
| 560 | } |
| 561 | if len(module.sdkLibraryProperties.Hidden_api_packages) != 0 { |
| 562 | droiddocArgs = append(droiddocArgs, |
| 563 | android.JoinWithPrefix(module.sdkLibraryProperties.Hidden_api_packages, " --hide-package ")) |
| 564 | } |
| 565 | droiddocArgs = append(droiddocArgs, module.sdkLibraryProperties.Droiddoc_options...) |
| 566 | disabledWarnings := []string{ |
| 567 | "MissingPermission", |
| 568 | "BroadcastBehavior", |
| 569 | "HiddenSuperclass", |
| 570 | "DeprecationMismatch", |
| 571 | "UnavailableSymbol", |
| 572 | "SdkConstant", |
| 573 | "HiddenTypeParameter", |
| 574 | "Todo", |
| 575 | "Typo", |
| 576 | } |
| 577 | droiddocArgs = append(droiddocArgs, android.JoinWithPrefix(disabledWarnings, "--hide ")) |
Sundong Ahn | fb2721f | 2018-09-17 13:23:09 +0900 | [diff] [blame] | 578 | |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 579 | switch apiScope { |
| 580 | case apiScopeSystem: |
Paul Duffin | 235ffff | 2019-12-24 10:41:30 +0000 | [diff] [blame] | 581 | droiddocArgs = append(droiddocArgs, "-showAnnotation android.annotation.SystemApi") |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 582 | case apiScopeTest: |
Paul Duffin | 235ffff | 2019-12-24 10:41:30 +0000 | [diff] [blame] | 583 | droiddocArgs = append(droiddocArgs, " -showAnnotation android.annotation.TestApi") |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 584 | } |
Paul Duffin | 1151247 | 2019-02-11 15:55:17 +0000 | [diff] [blame] | 585 | props.Arg_files = module.sdkLibraryProperties.Droiddoc_option_files |
Paul Duffin | 235ffff | 2019-12-24 10:41:30 +0000 | [diff] [blame] | 586 | props.Args = proptools.StringPtr(strings.Join(droiddocArgs, " ")) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 587 | |
| 588 | // List of APIs identified from the provided source files are created. They are later |
| 589 | // compared against to the not-yet-released (a.k.a current) list of APIs and to the |
| 590 | // last-released (a.k.a numbered) list of API. |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 591 | currentApiFileName := "current.txt" |
| 592 | removedApiFileName := "removed.txt" |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 593 | switch apiScope { |
| 594 | case apiScopeSystem: |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 595 | currentApiFileName = "system-" + currentApiFileName |
| 596 | removedApiFileName = "system-" + removedApiFileName |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 597 | case apiScopeTest: |
| 598 | currentApiFileName = "test-" + currentApiFileName |
| 599 | removedApiFileName = "test-" + removedApiFileName |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 600 | } |
Paul Duffin | 749f98f | 2019-12-30 17:23:46 +0000 | [diff] [blame] | 601 | apiDir := module.getApiDir() |
| 602 | currentApiFileName = path.Join(apiDir, currentApiFileName) |
| 603 | removedApiFileName = path.Join(apiDir, removedApiFileName) |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 604 | // TODO(jiyong): remove these three props |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 605 | props.Api_tag_name = proptools.StringPtr(module.apiTagName(apiScope)) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 606 | props.Api_filename = proptools.StringPtr(currentApiFileName) |
| 607 | props.Removed_api_filename = proptools.StringPtr(removedApiFileName) |
| 608 | |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 609 | // check against the not-yet-release API |
| 610 | props.Check_api.Current.Api_file = proptools.StringPtr(currentApiFileName) |
| 611 | props.Check_api.Current.Removed_api_file = proptools.StringPtr(removedApiFileName) |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 612 | |
| 613 | // check against the latest released API |
| 614 | props.Check_api.Last_released.Api_file = proptools.StringPtr( |
| 615 | module.latestApiFilegroupName(apiScope)) |
| 616 | props.Check_api.Last_released.Removed_api_file = proptools.StringPtr( |
| 617 | module.latestRemovedApiFilegroupName(apiScope)) |
Inseob Kim | 38449af | 2019-02-28 14:24:05 +0900 | [diff] [blame] | 618 | props.Check_api.Ignore_missing_latest_api = proptools.BoolPtr(true) |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 619 | |
Colin Cross | 84dfc3d | 2019-09-25 11:33:01 -0700 | [diff] [blame] | 620 | mctx.CreateModule(DroidstubsFactory, &props) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 621 | } |
| 622 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 623 | // Creates the xml file that publicizes the runtime library |
Colin Cross | f8b860a | 2019-04-16 14:43:28 -0700 | [diff] [blame] | 624 | func (module *SdkLibrary) createXmlFile(mctx android.LoadHookContext) { |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 625 | // creates a prebuilt_etc module to actually place the xml file under |
| 626 | // <partition>/etc/permissions |
| 627 | etcProps := struct { |
Sundong Ahn | 0d7dff4 | 2019-12-04 12:53:44 +0900 | [diff] [blame] | 628 | Name *string |
| 629 | Src *string |
| 630 | Sub_dir *string |
| 631 | Soc_specific *bool |
| 632 | Device_specific *bool |
| 633 | Product_specific *bool |
| 634 | System_ext_specific *bool |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 635 | }{} |
| 636 | etcProps.Name = proptools.StringPtr(module.xmlFileName()) |
Jooyung Han | 624058e | 2019-12-24 18:38:06 +0900 | [diff] [blame] | 637 | etcProps.Src = proptools.StringPtr(":" + module.BaseModuleName() + "{.xml}") |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 638 | etcProps.Sub_dir = proptools.StringPtr("permissions") |
| 639 | if module.SocSpecific() { |
| 640 | etcProps.Soc_specific = proptools.BoolPtr(true) |
| 641 | } else if module.DeviceSpecific() { |
| 642 | etcProps.Device_specific = proptools.BoolPtr(true) |
| 643 | } else if module.ProductSpecific() { |
| 644 | etcProps.Product_specific = proptools.BoolPtr(true) |
Sundong Ahn | 0d7dff4 | 2019-12-04 12:53:44 +0900 | [diff] [blame] | 645 | } else if module.SystemExtSpecific() { |
| 646 | etcProps.System_ext_specific = proptools.BoolPtr(true) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 647 | } |
Colin Cross | 84dfc3d | 2019-09-25 11:33:01 -0700 | [diff] [blame] | 648 | mctx.CreateModule(android.PrebuiltEtcFactory, &etcProps) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 649 | } |
| 650 | |
Colin Cross | 0ea8ba8 | 2019-06-06 14:33:29 -0700 | [diff] [blame] | 651 | func (module *SdkLibrary) PrebuiltJars(ctx android.BaseModuleContext, sdkVersion string) android.Paths { |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 652 | var api, v string |
Paul Duffin | 52d398a | 2019-06-11 12:31:14 +0100 | [diff] [blame] | 653 | if sdkVersion == "" || sdkVersion == "none" { |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 654 | api = "system" |
| 655 | v = "current" |
| 656 | } else if strings.Contains(sdkVersion, "_") { |
| 657 | t := strings.Split(sdkVersion, "_") |
| 658 | api = t[0] |
| 659 | v = t[1] |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 660 | } else { |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 661 | api = "public" |
| 662 | v = sdkVersion |
| 663 | } |
| 664 | dir := filepath.Join("prebuilts", "sdk", v, api) |
| 665 | jar := filepath.Join(dir, module.BaseModuleName()+".jar") |
| 666 | jarPath := android.ExistentPathForSource(ctx, jar) |
Sundong Ahn | ae418ac | 2019-02-28 15:01:28 +0900 | [diff] [blame] | 667 | if !jarPath.Valid() { |
| 668 | ctx.PropertyErrorf("sdk_library", "invalid sdk version %q, %q does not exist", v, jar) |
| 669 | return nil |
| 670 | } |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 671 | return android.Paths{jarPath.Path()} |
| 672 | } |
| 673 | |
| 674 | // to satisfy SdkLibraryDependency interface |
Colin Cross | 0ea8ba8 | 2019-06-06 14:33:29 -0700 | [diff] [blame] | 675 | func (module *SdkLibrary) SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion string) android.Paths { |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 676 | // This module is just a wrapper for the stubs. |
Colin Cross | 1093287 | 2019-04-18 14:27:12 -0700 | [diff] [blame] | 677 | if ctx.Config().UnbundledBuildUsePrebuiltSdks() { |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 678 | return module.PrebuiltJars(ctx, sdkVersion) |
| 679 | } else { |
| 680 | if strings.HasPrefix(sdkVersion, "system_") { |
| 681 | return module.systemApiStubsPath |
| 682 | } else if sdkVersion == "" { |
| 683 | return module.Library.HeaderJars() |
| 684 | } else { |
| 685 | return module.publicApiStubsPath |
| 686 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 687 | } |
| 688 | } |
| 689 | |
Sundong Ahn | 241cd37 | 2018-07-13 16:16:44 +0900 | [diff] [blame] | 690 | // to satisfy SdkLibraryDependency interface |
Colin Cross | 0ea8ba8 | 2019-06-06 14:33:29 -0700 | [diff] [blame] | 691 | func (module *SdkLibrary) SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion string) android.Paths { |
Sundong Ahn | 241cd37 | 2018-07-13 16:16:44 +0900 | [diff] [blame] | 692 | // This module is just a wrapper for the stubs. |
Colin Cross | 1093287 | 2019-04-18 14:27:12 -0700 | [diff] [blame] | 693 | if ctx.Config().UnbundledBuildUsePrebuiltSdks() { |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 694 | return module.PrebuiltJars(ctx, sdkVersion) |
Sundong Ahn | 241cd37 | 2018-07-13 16:16:44 +0900 | [diff] [blame] | 695 | } else { |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 696 | if strings.HasPrefix(sdkVersion, "system_") { |
| 697 | return module.systemApiStubsImplPath |
| 698 | } else if sdkVersion == "" { |
| 699 | return module.Library.ImplementationJars() |
| 700 | } else { |
| 701 | return module.publicApiStubsImplPath |
| 702 | } |
Sundong Ahn | 241cd37 | 2018-07-13 16:16:44 +0900 | [diff] [blame] | 703 | } |
| 704 | } |
| 705 | |
Sundong Ahn | 80a87b3 | 2019-05-13 15:02:50 +0900 | [diff] [blame] | 706 | func (module *SdkLibrary) SetNoDist() { |
| 707 | module.sdkLibraryProperties.No_dist = proptools.BoolPtr(true) |
| 708 | } |
| 709 | |
Colin Cross | 571cccf | 2019-02-04 11:22:08 -0800 | [diff] [blame] | 710 | var javaSdkLibrariesKey = android.NewOnceKey("javaSdkLibraries") |
| 711 | |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 712 | func javaSdkLibraries(config android.Config) *[]string { |
Colin Cross | 571cccf | 2019-02-04 11:22:08 -0800 | [diff] [blame] | 713 | return config.Once(javaSdkLibrariesKey, func() interface{} { |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 714 | return &[]string{} |
| 715 | }).(*[]string) |
| 716 | } |
| 717 | |
Paul Duffin | 749f98f | 2019-12-30 17:23:46 +0000 | [diff] [blame] | 718 | func (module *SdkLibrary) getApiDir() string { |
| 719 | return proptools.StringDefault(module.sdkLibraryProperties.Api_dir, "api") |
| 720 | } |
| 721 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 722 | // For a java_sdk_library module, create internal modules for stubs, docs, |
| 723 | // runtime libs and xml file. If requested, the stubs and docs are created twice |
| 724 | // once for public API level and once for system API level |
Colin Cross | f8b860a | 2019-04-16 14:43:28 -0700 | [diff] [blame] | 725 | func (module *SdkLibrary) CreateInternalModules(mctx android.LoadHookContext) { |
Inseob Kim | 6e93ac9 | 2019-03-21 17:43:49 +0900 | [diff] [blame] | 726 | if len(module.Library.Module.properties.Srcs) == 0 { |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 727 | mctx.PropertyErrorf("srcs", "java_sdk_library must specify srcs") |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 728 | return |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 729 | } |
| 730 | |
Paul Duffin | 37e0b77 | 2019-12-30 17:20:10 +0000 | [diff] [blame] | 731 | // If this builds against standard libraries (i.e. is not part of the core libraries) |
| 732 | // then assume it provides both system and test apis. Otherwise, assume it does not and |
| 733 | // also assume it does not contribute to the dist build. |
| 734 | sdkDep := decodeSdkDep(mctx, sdkContext(&module.Library)) |
| 735 | hasSystemAndTestApis := sdkDep.hasStandardLibs() |
| 736 | module.sdkLibraryProperties.Has_system_and_test_apis = hasSystemAndTestApis |
| 737 | module.sdkLibraryProperties.No_dist = proptools.BoolPtr(!hasSystemAndTestApis) |
| 738 | |
| 739 | scopes := []string{""} |
| 740 | if hasSystemAndTestApis { |
| 741 | scopes = append(scopes, "system-", "test-") |
| 742 | } |
| 743 | |
Inseob Kim | 8098faa | 2019-03-18 10:19:51 +0900 | [diff] [blame] | 744 | missing_current_api := false |
| 745 | |
Paul Duffin | 749f98f | 2019-12-30 17:23:46 +0000 | [diff] [blame] | 746 | apiDir := module.getApiDir() |
Paul Duffin | 37e0b77 | 2019-12-30 17:20:10 +0000 | [diff] [blame] | 747 | for _, scope := range scopes { |
Inseob Kim | 8098faa | 2019-03-18 10:19:51 +0900 | [diff] [blame] | 748 | for _, api := range []string{"current.txt", "removed.txt"} { |
Paul Duffin | 749f98f | 2019-12-30 17:23:46 +0000 | [diff] [blame] | 749 | path := path.Join(mctx.ModuleDir(), apiDir, scope+api) |
Inseob Kim | 8098faa | 2019-03-18 10:19:51 +0900 | [diff] [blame] | 750 | p := android.ExistentPathForSource(mctx, path) |
| 751 | if !p.Valid() { |
| 752 | mctx.ModuleErrorf("Current api file %#v doesn't exist", path) |
| 753 | missing_current_api = true |
| 754 | } |
| 755 | } |
| 756 | } |
| 757 | |
| 758 | if missing_current_api { |
| 759 | script := "build/soong/scripts/gen-java-current-api-files.sh" |
| 760 | p := android.ExistentPathForSource(mctx, script) |
| 761 | |
| 762 | if !p.Valid() { |
| 763 | panic(fmt.Sprintf("script file %s doesn't exist", script)) |
| 764 | } |
| 765 | |
| 766 | mctx.ModuleErrorf("One or more current api files are missing. "+ |
| 767 | "You can update them by:\n"+ |
Paul Duffin | 37e0b77 | 2019-12-30 17:20:10 +0000 | [diff] [blame] | 768 | "%s %q %s && m update-api", |
Paul Duffin | 749f98f | 2019-12-30 17:23:46 +0000 | [diff] [blame] | 769 | script, filepath.Join(mctx.ModuleDir(), apiDir), strings.Join(scopes, " ")) |
Inseob Kim | 8098faa | 2019-03-18 10:19:51 +0900 | [diff] [blame] | 770 | return |
| 771 | } |
| 772 | |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 773 | // for public API stubs |
| 774 | module.createStubsLibrary(mctx, apiScopePublic) |
Paul Duffin | c4cea76 | 2019-12-30 17:32:47 +0000 | [diff] [blame] | 775 | module.createStubsSources(mctx, apiScopePublic) |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 776 | |
Paul Duffin | 37e0b77 | 2019-12-30 17:20:10 +0000 | [diff] [blame] | 777 | if hasSystemAndTestApis { |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 778 | // for system API stubs |
| 779 | module.createStubsLibrary(mctx, apiScopeSystem) |
Paul Duffin | c4cea76 | 2019-12-30 17:32:47 +0000 | [diff] [blame] | 780 | module.createStubsSources(mctx, apiScopeSystem) |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 781 | |
| 782 | // for test API stubs |
| 783 | module.createStubsLibrary(mctx, apiScopeTest) |
Paul Duffin | c4cea76 | 2019-12-30 17:32:47 +0000 | [diff] [blame] | 784 | module.createStubsSources(mctx, apiScopeTest) |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 785 | } |
| 786 | |
Paul Duffin | 43db9be | 2019-12-30 17:35:49 +0000 | [diff] [blame^] | 787 | if !proptools.Bool(module.sdkLibraryProperties.Api_only) { |
| 788 | // for runtime |
| 789 | module.createXmlFile(mctx) |
| 790 | |
| 791 | // record java_sdk_library modules so that they are exported to make |
| 792 | javaSdkLibraries := javaSdkLibraries(mctx.Config()) |
| 793 | javaSdkLibrariesLock.Lock() |
| 794 | defer javaSdkLibrariesLock.Unlock() |
| 795 | *javaSdkLibraries = append(*javaSdkLibraries, module.BaseModuleName()) |
| 796 | } |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 797 | } |
| 798 | |
| 799 | func (module *SdkLibrary) InitSdkLibraryProperties() { |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 800 | module.AddProperties( |
| 801 | &module.sdkLibraryProperties, |
| 802 | &module.Library.Module.properties, |
| 803 | &module.Library.Module.dexpreoptProperties, |
| 804 | &module.Library.Module.deviceProperties, |
| 805 | &module.Library.Module.protoProperties, |
| 806 | ) |
| 807 | |
| 808 | module.Library.Module.properties.Installable = proptools.BoolPtr(true) |
| 809 | module.Library.Module.deviceProperties.IsSDKLibrary = true |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 810 | } |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 811 | |
Jaewoong Jung | 4f158ee | 2019-07-11 10:05:35 -0700 | [diff] [blame] | 812 | // java_sdk_library is a special Java library that provides optional platform APIs to apps. |
| 813 | // In practice, it can be viewed as a combination of several modules: 1) stubs library that clients |
| 814 | // are linked against to, 2) droiddoc module that internally generates API stubs source files, |
| 815 | // 3) the real runtime shared library that implements the APIs, and 4) XML file for adding |
| 816 | // the runtime lib to the classpath at runtime if requested via <uses-library>. |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 817 | func SdkLibraryFactory() android.Module { |
| 818 | module := &SdkLibrary{} |
| 819 | module.InitSdkLibraryProperties() |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 820 | android.InitApexModule(module) |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 821 | InitJavaModule(module, android.HostAndDeviceSupported) |
Colin Cross | f8b860a | 2019-04-16 14:43:28 -0700 | [diff] [blame] | 822 | android.AddLoadHook(module, func(ctx android.LoadHookContext) { module.CreateInternalModules(ctx) }) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 823 | return module |
| 824 | } |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 825 | |
| 826 | // |
| 827 | // SDK library prebuilts |
| 828 | // |
| 829 | |
| 830 | type sdkLibraryImportProperties struct { |
| 831 | Jars []string `android:"path"` |
| 832 | |
| 833 | Sdk_version *string |
| 834 | |
| 835 | Installable *bool |
| 836 | |
| 837 | // List of shared java libs that this module has dependencies to |
| 838 | Libs []string |
| 839 | |
| 840 | // List of files to remove from the jar file(s) |
| 841 | Exclude_files []string |
| 842 | |
| 843 | // List of directories to remove from the jar file(s) |
| 844 | Exclude_dirs []string |
| 845 | } |
| 846 | |
| 847 | type sdkLibraryImport struct { |
| 848 | android.ModuleBase |
| 849 | android.DefaultableModuleBase |
| 850 | prebuilt android.Prebuilt |
| 851 | |
| 852 | properties sdkLibraryImportProperties |
| 853 | |
| 854 | stubsPath android.Paths |
| 855 | } |
| 856 | |
| 857 | var _ SdkLibraryDependency = (*sdkLibraryImport)(nil) |
| 858 | |
Jaewoong Jung | 4f158ee | 2019-07-11 10:05:35 -0700 | [diff] [blame] | 859 | // java_sdk_library_import imports a prebuilt java_sdk_library. |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 860 | func sdkLibraryImportFactory() android.Module { |
| 861 | module := &sdkLibraryImport{} |
| 862 | |
| 863 | module.AddProperties(&module.properties) |
| 864 | |
| 865 | android.InitPrebuiltModule(module, &module.properties.Jars) |
| 866 | InitJavaModule(module, android.HostAndDeviceSupported) |
| 867 | |
| 868 | android.AddLoadHook(module, func(mctx android.LoadHookContext) { module.createInternalModules(mctx) }) |
| 869 | return module |
| 870 | } |
| 871 | |
| 872 | func (module *sdkLibraryImport) Prebuilt() *android.Prebuilt { |
| 873 | return &module.prebuilt |
| 874 | } |
| 875 | |
| 876 | func (module *sdkLibraryImport) Name() string { |
| 877 | return module.prebuilt.Name(module.ModuleBase.Name()) |
| 878 | } |
| 879 | |
| 880 | func (module *sdkLibraryImport) createInternalModules(mctx android.LoadHookContext) { |
| 881 | // Creates a java import for the jar with ".stubs" suffix |
| 882 | props := struct { |
Sundong Ahn | 0d7dff4 | 2019-12-04 12:53:44 +0900 | [diff] [blame] | 883 | Name *string |
| 884 | Soc_specific *bool |
| 885 | Device_specific *bool |
| 886 | Product_specific *bool |
| 887 | System_ext_specific *bool |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 888 | }{} |
| 889 | |
| 890 | props.Name = proptools.StringPtr(module.BaseModuleName() + sdkStubsLibrarySuffix) |
| 891 | |
| 892 | if module.SocSpecific() { |
| 893 | props.Soc_specific = proptools.BoolPtr(true) |
| 894 | } else if module.DeviceSpecific() { |
| 895 | props.Device_specific = proptools.BoolPtr(true) |
| 896 | } else if module.ProductSpecific() { |
| 897 | props.Product_specific = proptools.BoolPtr(true) |
Sundong Ahn | 0d7dff4 | 2019-12-04 12:53:44 +0900 | [diff] [blame] | 898 | } else if module.SystemExtSpecific() { |
| 899 | props.System_ext_specific = proptools.BoolPtr(true) |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 900 | } |
| 901 | |
Colin Cross | 84dfc3d | 2019-09-25 11:33:01 -0700 | [diff] [blame] | 902 | mctx.CreateModule(ImportFactory, &props, &module.properties) |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 903 | |
| 904 | javaSdkLibraries := javaSdkLibraries(mctx.Config()) |
| 905 | javaSdkLibrariesLock.Lock() |
| 906 | defer javaSdkLibrariesLock.Unlock() |
| 907 | *javaSdkLibraries = append(*javaSdkLibraries, module.BaseModuleName()) |
| 908 | } |
| 909 | |
| 910 | func (module *sdkLibraryImport) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 911 | // Add dependencies to the prebuilt stubs library |
| 912 | ctx.AddVariationDependencies(nil, publicApiStubsTag, module.BaseModuleName()+sdkStubsLibrarySuffix) |
| 913 | } |
| 914 | |
| 915 | func (module *sdkLibraryImport) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 916 | // Record the paths to the prebuilt stubs library. |
| 917 | ctx.VisitDirectDeps(func(to android.Module) { |
| 918 | tag := ctx.OtherModuleDependencyTag(to) |
| 919 | |
| 920 | switch tag { |
| 921 | case publicApiStubsTag: |
| 922 | module.stubsPath = to.(Dependency).HeaderJars() |
| 923 | } |
| 924 | }) |
| 925 | } |
| 926 | |
| 927 | // to satisfy SdkLibraryDependency interface |
Colin Cross | 0ea8ba8 | 2019-06-06 14:33:29 -0700 | [diff] [blame] | 928 | func (module *sdkLibraryImport) SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion string) android.Paths { |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 929 | // This module is just a wrapper for the prebuilt stubs. |
| 930 | return module.stubsPath |
| 931 | } |
| 932 | |
| 933 | // to satisfy SdkLibraryDependency interface |
Colin Cross | 0ea8ba8 | 2019-06-06 14:33:29 -0700 | [diff] [blame] | 934 | func (module *sdkLibraryImport) SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion string) android.Paths { |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 935 | // This module is just a wrapper for the stubs. |
| 936 | return module.stubsPath |
| 937 | } |