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