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