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