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