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