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