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