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 | // java_sdk_library is to make a Java library that implements optional platform APIs to apps. |
| 67 | // It is actually a wrapper of several modules: 1) stubs library that clients are linked against |
| 68 | // to, 2) droiddoc module that internally generates API stubs source files, 3) the real runtime |
| 69 | // shared library that implements the APIs, and 4) XML file for adding the runtime lib to the |
| 70 | // classpath at runtime if requested via <uses-library>. |
| 71 | // |
| 72 | // TODO: these are big features that are currently missing |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 73 | // 1) disallowing linking to the runtime shared lib |
| 74 | // 2) HTML generation |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 75 | |
| 76 | func init() { |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 77 | android.RegisterModuleType("java_sdk_library", SdkLibraryFactory) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 78 | |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 79 | android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) { |
| 80 | javaSdkLibraries := javaSdkLibraries(ctx.Config()) |
| 81 | sort.Strings(*javaSdkLibraries) |
| 82 | ctx.Strict("JAVA_SDK_LIBRARIES", strings.Join(*javaSdkLibraries, " ")) |
| 83 | }) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | type sdkLibraryProperties struct { |
Jiyong Park | baaf9dd | 2018-05-02 01:35:27 +0900 | [diff] [blame] | 87 | // list of optional source files that are part of API but not part of runtime library. |
| 88 | Api_srcs []string `android:"arch_variant"` |
| 89 | |
Sundong Ahn | f043cf6 | 2018-06-25 16:04:37 +0900 | [diff] [blame] | 90 | // List of Java libraries that will be in the classpath when building stubs |
| 91 | Stub_only_libs []string `android:"arch_variant"` |
| 92 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 93 | // list of package names that will be documented and publicized as API |
| 94 | Api_packages []string |
| 95 | |
Jiyong Park | 5a2c9d7 | 2018-05-01 22:25:41 +0900 | [diff] [blame] | 96 | // list of package names that must be hidden from the API |
| 97 | Hidden_api_packages []string |
| 98 | |
Paul Duffin | 1151247 | 2019-02-11 15:55:17 +0000 | [diff] [blame] | 99 | // local files that are used within user customized droiddoc options. |
| 100 | Droiddoc_option_files []string |
| 101 | |
| 102 | // additional droiddoc options |
| 103 | // Available variables for substitution: |
| 104 | // |
| 105 | // $(location <label>): the path to the droiddoc_option_files with name <label> |
Sundong Ahn | dd567f9 | 2018-07-31 17:19:11 +0900 | [diff] [blame] | 106 | Droiddoc_options []string |
| 107 | |
Sundong Ahn | b952ba0 | 2019-01-08 16:32:12 +0900 | [diff] [blame] | 108 | // the java library (in classpath) for documentation that provides java srcs and srcjars. |
| 109 | Srcs_lib *string |
| 110 | |
| 111 | // the base dirs under srcs_lib will be scanned for java srcs. |
| 112 | Srcs_lib_whitelist_dirs []string |
| 113 | |
Sundong Ahn | dd567f9 | 2018-07-31 17:19:11 +0900 | [diff] [blame] | 114 | // the sub dirs under srcs_lib_whitelist_dirs will be scanned for java srcs. |
| 115 | // Defaults to "android.annotation". |
| 116 | Srcs_lib_whitelist_pkgs []string |
| 117 | |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 118 | // a list of top-level directories containing files to merge qualifier annotations |
| 119 | // (i.e. those intended to be included in the stubs written) from. |
| 120 | Merge_annotations_dirs []string |
| 121 | |
| 122 | // a list of top-level directories containing Java stub files to merge show/hide annotations from. |
| 123 | Merge_inclusion_annotations_dirs []string |
| 124 | |
| 125 | // If set to true, the path of dist files is apistubs/core. Defaults to false. |
| 126 | Core_lib *bool |
| 127 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 128 | // TODO: determines whether to create HTML doc or not |
| 129 | //Html_doc *bool |
| 130 | } |
| 131 | |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 132 | type SdkLibrary struct { |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 133 | Library |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 134 | |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 135 | sdkLibraryProperties sdkLibraryProperties |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 136 | |
| 137 | publicApiStubsPath android.Paths |
| 138 | systemApiStubsPath android.Paths |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 139 | testApiStubsPath android.Paths |
Sundong Ahn | 241cd37 | 2018-07-13 16:16:44 +0900 | [diff] [blame] | 140 | |
| 141 | publicApiStubsImplPath android.Paths |
| 142 | systemApiStubsImplPath android.Paths |
| 143 | testApiStubsImplPath android.Paths |
Sundong Ahn | 20e998b | 2018-07-24 11:19:26 +0900 | [diff] [blame] | 144 | |
| 145 | publicApiFilePath android.Path |
| 146 | systemApiFilePath android.Path |
| 147 | testApiFilePath android.Path |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 148 | } |
| 149 | |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 150 | var _ Dependency = (*SdkLibrary)(nil) |
| 151 | var _ SdkLibraryDependency = (*SdkLibrary)(nil) |
Colin Cross | 897d2ed | 2019-02-11 14:03:51 -0800 | [diff] [blame] | 152 | |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 153 | func (module *SdkLibrary) DepsMutator(ctx android.BottomUpMutatorContext) { |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 154 | // Add dependencies to the stubs library |
Colin Cross | 42d48b7 | 2018-08-29 14:10:52 -0700 | [diff] [blame] | 155 | ctx.AddVariationDependencies(nil, publicApiStubsTag, module.stubsName(apiScopePublic)) |
Colin Cross | 42d48b7 | 2018-08-29 14:10:52 -0700 | [diff] [blame] | 156 | ctx.AddVariationDependencies(nil, publicApiFileTag, module.docsName(apiScopePublic)) |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 157 | |
| 158 | if !Bool(module.properties.No_standard_libs) { |
| 159 | ctx.AddVariationDependencies(nil, systemApiStubsTag, module.stubsName(apiScopeSystem)) |
| 160 | ctx.AddVariationDependencies(nil, systemApiFileTag, module.docsName(apiScopeSystem)) |
| 161 | ctx.AddVariationDependencies(nil, testApiFileTag, module.docsName(apiScopeTest)) |
| 162 | ctx.AddVariationDependencies(nil, testApiStubsTag, module.stubsName(apiScopeTest)) |
| 163 | } |
| 164 | |
| 165 | module.Library.deps(ctx) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 166 | } |
| 167 | |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 168 | func (module *SdkLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 169 | module.Library.GenerateAndroidBuildActions(ctx) |
| 170 | |
Sundong Ahn | 57368eb | 2018-07-06 11:20:23 +0900 | [diff] [blame] | 171 | // 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] | 172 | // When this java_sdk_library is dependened from others via "libs" property, |
| 173 | // the recorded paths will be returned depending on the link type of the caller. |
| 174 | ctx.VisitDirectDeps(func(to android.Module) { |
| 175 | otherName := ctx.OtherModuleName(to) |
| 176 | tag := ctx.OtherModuleDependencyTag(to) |
| 177 | |
Sundong Ahn | 57368eb | 2018-07-06 11:20:23 +0900 | [diff] [blame] | 178 | if lib, ok := to.(Dependency); ok { |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 179 | switch tag { |
| 180 | case publicApiStubsTag: |
Sundong Ahn | 57368eb | 2018-07-06 11:20:23 +0900 | [diff] [blame] | 181 | module.publicApiStubsPath = lib.HeaderJars() |
Sundong Ahn | 241cd37 | 2018-07-13 16:16:44 +0900 | [diff] [blame] | 182 | module.publicApiStubsImplPath = lib.ImplementationJars() |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 183 | case systemApiStubsTag: |
Sundong Ahn | 57368eb | 2018-07-06 11:20:23 +0900 | [diff] [blame] | 184 | module.systemApiStubsPath = lib.HeaderJars() |
Sundong Ahn | 241cd37 | 2018-07-13 16:16:44 +0900 | [diff] [blame] | 185 | module.systemApiStubsImplPath = lib.ImplementationJars() |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 186 | case testApiStubsTag: |
Sundong Ahn | 57368eb | 2018-07-06 11:20:23 +0900 | [diff] [blame] | 187 | module.testApiStubsPath = lib.HeaderJars() |
Sundong Ahn | 241cd37 | 2018-07-13 16:16:44 +0900 | [diff] [blame] | 188 | module.testApiStubsImplPath = lib.ImplementationJars() |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 189 | } |
| 190 | } |
Sundong Ahn | 20e998b | 2018-07-24 11:19:26 +0900 | [diff] [blame] | 191 | if doc, ok := to.(ApiFilePath); ok { |
| 192 | switch tag { |
| 193 | case publicApiFileTag: |
| 194 | module.publicApiFilePath = doc.ApiFilePath() |
| 195 | case systemApiFileTag: |
| 196 | module.systemApiFilePath = doc.ApiFilePath() |
| 197 | case testApiFileTag: |
| 198 | module.testApiFilePath = doc.ApiFilePath() |
| 199 | default: |
| 200 | ctx.ModuleErrorf("depends on module %q of unknown tag %q", otherName, tag) |
| 201 | } |
| 202 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 203 | }) |
| 204 | } |
| 205 | |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 206 | func (module *SdkLibrary) AndroidMk() android.AndroidMkData { |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 207 | data := module.Library.AndroidMk() |
| 208 | data.Required = append(data.Required, module.xmlFileName()) |
| 209 | |
| 210 | data.Custom = func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) { |
| 211 | android.WriteAndroidMkData(w, data) |
| 212 | |
| 213 | module.Library.AndroidMkHostDex(w, name, data) |
| 214 | // Create a phony module that installs the impl library, for the case when this lib is |
| 215 | // in PRODUCT_PACKAGES. |
| 216 | owner := module.ModuleBase.Owner() |
| 217 | if owner == "" { |
| 218 | if Bool(module.sdkLibraryProperties.Core_lib) { |
| 219 | owner = "core" |
| 220 | } else { |
Sundong Ahn | 4fd04bb | 2018-08-31 18:01:37 +0900 | [diff] [blame] | 221 | owner = "android" |
| 222 | } |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 223 | } |
| 224 | // Create dist rules to install the stubs libs to the dist dir |
| 225 | if len(module.publicApiStubsPath) == 1 { |
| 226 | fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+ |
| 227 | module.publicApiStubsImplPath.Strings()[0]+ |
| 228 | ":"+path.Join("apistubs", owner, "public", |
| 229 | module.BaseModuleName()+".jar")+")") |
| 230 | } |
| 231 | if len(module.systemApiStubsPath) == 1 { |
| 232 | fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+ |
| 233 | module.systemApiStubsImplPath.Strings()[0]+ |
| 234 | ":"+path.Join("apistubs", owner, "system", |
| 235 | module.BaseModuleName()+".jar")+")") |
| 236 | } |
| 237 | if len(module.testApiStubsPath) == 1 { |
| 238 | fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+ |
| 239 | module.testApiStubsImplPath.Strings()[0]+ |
| 240 | ":"+path.Join("apistubs", owner, "test", |
| 241 | module.BaseModuleName()+".jar")+")") |
| 242 | } |
| 243 | if module.publicApiFilePath != nil { |
| 244 | fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+ |
| 245 | module.publicApiFilePath.String()+ |
| 246 | ":"+path.Join("apistubs", owner, "public", "api", |
| 247 | module.BaseModuleName()+".txt")+")") |
| 248 | } |
| 249 | if module.systemApiFilePath != nil { |
| 250 | fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+ |
| 251 | module.systemApiFilePath.String()+ |
| 252 | ":"+path.Join("apistubs", owner, "system", "api", |
| 253 | module.BaseModuleName()+".txt")+")") |
| 254 | } |
| 255 | if module.testApiFilePath != nil { |
| 256 | fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+ |
| 257 | module.testApiFilePath.String()+ |
| 258 | ":"+path.Join("apistubs", owner, "test", "api", |
| 259 | module.BaseModuleName()+".txt")+")") |
| 260 | } |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 261 | } |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 262 | return data |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 263 | } |
| 264 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 265 | // Module name of the stubs library |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 266 | func (module *SdkLibrary) stubsName(apiScope apiScope) string { |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 267 | stubsName := module.BaseModuleName() + sdkStubsLibrarySuffix |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 268 | switch apiScope { |
| 269 | case apiScopeSystem: |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 270 | stubsName = stubsName + sdkSystemApiSuffix |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 271 | case apiScopeTest: |
| 272 | stubsName = stubsName + sdkTestApiSuffix |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 273 | } |
| 274 | return stubsName |
| 275 | } |
| 276 | |
| 277 | // Module name of the docs |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 278 | func (module *SdkLibrary) docsName(apiScope apiScope) string { |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 279 | docsName := module.BaseModuleName() + sdkDocsSuffix |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 280 | switch apiScope { |
| 281 | case apiScopeSystem: |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 282 | docsName = docsName + sdkSystemApiSuffix |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 283 | case apiScopeTest: |
| 284 | docsName = docsName + sdkTestApiSuffix |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 285 | } |
| 286 | return docsName |
| 287 | } |
| 288 | |
| 289 | // Module name of the runtime implementation library |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 290 | func (module *SdkLibrary) implName() string { |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 291 | return module.BaseModuleName() |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | // File path to the runtime implementation library |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 295 | func (module *SdkLibrary) implPath() string { |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 296 | partition := "system" |
| 297 | if module.SocSpecific() { |
| 298 | partition = "vendor" |
| 299 | } else if module.DeviceSpecific() { |
| 300 | partition = "odm" |
| 301 | } else if module.ProductSpecific() { |
| 302 | partition = "product" |
| 303 | } |
| 304 | return "/" + partition + "/framework/" + module.implName() + ".jar" |
| 305 | } |
| 306 | |
| 307 | // Module name of the XML file for the lib |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 308 | func (module *SdkLibrary) xmlFileName() string { |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 309 | return module.BaseModuleName() + sdkXmlFileSuffix |
| 310 | } |
| 311 | |
| 312 | // SDK version that the stubs library is built against. Note that this is always |
| 313 | // *current. Older stubs library built with a numberd SDK version is created from |
| 314 | // the prebuilt jar. |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 315 | func (module *SdkLibrary) sdkVersion(apiScope apiScope) string { |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 316 | switch apiScope { |
| 317 | case apiScopePublic: |
| 318 | return "current" |
| 319 | case apiScopeSystem: |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 320 | return "system_current" |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 321 | case apiScopeTest: |
| 322 | return "test_current" |
| 323 | default: |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 324 | return "current" |
| 325 | } |
| 326 | } |
| 327 | |
| 328 | // $(INTERNAL_PLATFORM_<apiTagName>_API_FILE) points to the generated |
| 329 | // api file for the current source |
| 330 | // TODO: remove this when apicheck is done in soong |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 331 | func (module *SdkLibrary) apiTagName(apiScope apiScope) string { |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 332 | apiTagName := strings.Replace(strings.ToUpper(module.BaseModuleName()), ".", "_", -1) |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 333 | switch apiScope { |
| 334 | case apiScopeSystem: |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 335 | apiTagName = apiTagName + "_SYSTEM" |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 336 | case apiScopeTest: |
| 337 | apiTagName = apiTagName + "_TEST" |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 338 | } |
| 339 | return apiTagName |
| 340 | } |
| 341 | |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 342 | func (module *SdkLibrary) latestApiFilegroupName(apiScope apiScope) string { |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 343 | name := ":" + module.BaseModuleName() + ".api." |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 344 | switch apiScope { |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 345 | case apiScopePublic: |
| 346 | name = name + "public" |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 347 | case apiScopeSystem: |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 348 | name = name + "system" |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 349 | case apiScopeTest: |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 350 | name = name + "test" |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 351 | } |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 352 | name = name + ".latest" |
| 353 | return name |
| 354 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 355 | |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 356 | func (module *SdkLibrary) latestRemovedApiFilegroupName(apiScope apiScope) string { |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 357 | name := ":" + module.BaseModuleName() + "-removed.api." |
| 358 | switch apiScope { |
| 359 | case apiScopePublic: |
| 360 | name = name + "public" |
| 361 | case apiScopeSystem: |
| 362 | name = name + "system" |
| 363 | case apiScopeTest: |
| 364 | name = name + "test" |
| 365 | } |
| 366 | name = name + ".latest" |
| 367 | return name |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | // Creates a static java library that has API stubs |
Colin Cross | f8b860a | 2019-04-16 14:43:28 -0700 | [diff] [blame] | 371 | func (module *SdkLibrary) createStubsLibrary(mctx android.LoadHookContext, apiScope apiScope) { |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 372 | props := struct { |
| 373 | Name *string |
| 374 | Srcs []string |
| 375 | Sdk_version *string |
Sundong Ahn | f043cf6 | 2018-06-25 16:04:37 +0900 | [diff] [blame] | 376 | Libs []string |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 377 | Soc_specific *bool |
| 378 | Device_specific *bool |
| 379 | Product_specific *bool |
Sundong Ahn | dd567f9 | 2018-07-31 17:19:11 +0900 | [diff] [blame] | 380 | Compile_dex *bool |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 381 | No_standard_libs *bool |
| 382 | System_modules *string |
| 383 | Java_version *string |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 384 | Product_variables struct { |
| 385 | Unbundled_build struct { |
| 386 | Enabled *bool |
| 387 | } |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 388 | Pdk struct { |
| 389 | Enabled *bool |
| 390 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 391 | } |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 392 | Openjdk9 struct { |
| 393 | Srcs []string |
| 394 | Javacflags []string |
| 395 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 396 | }{} |
| 397 | |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 398 | props.Name = proptools.StringPtr(module.stubsName(apiScope)) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 399 | // sources are generated from the droiddoc |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 400 | props.Srcs = []string{":" + module.docsName(apiScope)} |
| 401 | props.Sdk_version = proptools.StringPtr(module.sdkVersion(apiScope)) |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 402 | props.Libs = module.sdkLibraryProperties.Stub_only_libs |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 403 | // Unbundled apps will use the prebult one from /prebuilts/sdk |
Colin Cross | 2c77ceb | 2019-01-21 11:56:21 -0800 | [diff] [blame] | 404 | if mctx.Config().UnbundledBuildPrebuiltSdks() { |
| 405 | props.Product_variables.Unbundled_build.Enabled = proptools.BoolPtr(false) |
| 406 | } |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 407 | props.Product_variables.Pdk.Enabled = proptools.BoolPtr(false) |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 408 | props.No_standard_libs = module.Library.Module.properties.No_standard_libs |
| 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 |
| 435 | Srcs_lib *string |
| 436 | Srcs_lib_whitelist_dirs []string |
| 437 | Srcs_lib_whitelist_pkgs []string |
| 438 | Libs []string |
Paul Duffin | 1151247 | 2019-02-11 15:55:17 +0000 | [diff] [blame] | 439 | Arg_files []string |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 440 | Args *string |
| 441 | Api_tag_name *string |
| 442 | Api_filename *string |
| 443 | Removed_api_filename *string |
| 444 | No_standard_libs *bool |
| 445 | Java_version *string |
| 446 | Merge_annotations_dirs []string |
| 447 | Merge_inclusion_annotations_dirs []string |
| 448 | Check_api struct { |
Inseob Kim | 38449af | 2019-02-28 14:24:05 +0900 | [diff] [blame] | 449 | Current ApiToCheck |
| 450 | Last_released ApiToCheck |
| 451 | Ignore_missing_latest_api *bool |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 452 | } |
Sundong Ahn | 1b92c82 | 2018-05-29 11:35:17 +0900 | [diff] [blame] | 453 | Aidl struct { |
| 454 | Include_dirs []string |
| 455 | Local_include_dirs []string |
| 456 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 457 | }{} |
| 458 | |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 459 | props.Name = proptools.StringPtr(module.docsName(apiScope)) |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 460 | props.Srcs = append(props.Srcs, module.Library.Module.properties.Srcs...) |
| 461 | props.Srcs = append(props.Srcs, module.sdkLibraryProperties.Api_srcs...) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 462 | props.Installable = proptools.BoolPtr(false) |
Sundong Ahn | e6f0b05 | 2018-06-05 16:46:14 +0900 | [diff] [blame] | 463 | // A droiddoc module has only one Libs property and doesn't distinguish between |
| 464 | // 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] | 465 | props.Libs = module.Library.Module.properties.Libs |
| 466 | props.Libs = append(props.Libs, module.Library.Module.properties.Static_libs...) |
| 467 | props.Aidl.Include_dirs = module.Library.Module.deviceProperties.Aidl.Include_dirs |
| 468 | props.Aidl.Local_include_dirs = module.Library.Module.deviceProperties.Aidl.Local_include_dirs |
| 469 | props.No_standard_libs = module.Library.Module.properties.No_standard_libs |
| 470 | props.Java_version = module.Library.Module.properties.Java_version |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 471 | |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 472 | props.Merge_annotations_dirs = module.sdkLibraryProperties.Merge_annotations_dirs |
| 473 | props.Merge_inclusion_annotations_dirs = module.sdkLibraryProperties.Merge_inclusion_annotations_dirs |
| 474 | |
| 475 | droiddocArgs := " --stub-packages " + strings.Join(module.sdkLibraryProperties.Api_packages, ":") + |
| 476 | " " + android.JoinWithPrefix(module.sdkLibraryProperties.Hidden_api_packages, " --hide-package ") + |
| 477 | " " + android.JoinWithPrefix(module.sdkLibraryProperties.Droiddoc_options, " ") + |
Sundong Ahn | 04ef8a3 | 2019-01-14 11:36:50 +0900 | [diff] [blame] | 478 | " --hide MissingPermission --hide BroadcastBehavior " + |
| 479 | "--hide HiddenSuperclass --hide DeprecationMismatch --hide UnavailableSymbol " + |
| 480 | "--hide SdkConstant --hide HiddenTypeParameter --hide Todo --hide Typo" |
Sundong Ahn | fb2721f | 2018-09-17 13:23:09 +0900 | [diff] [blame] | 481 | |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 482 | switch apiScope { |
| 483 | case apiScopeSystem: |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 484 | droiddocArgs = droiddocArgs + " -showAnnotation android.annotation.SystemApi" |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 485 | case apiScopeTest: |
| 486 | droiddocArgs = droiddocArgs + " -showAnnotation android.annotation.TestApi" |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 487 | } |
Paul Duffin | 1151247 | 2019-02-11 15:55:17 +0000 | [diff] [blame] | 488 | props.Arg_files = module.sdkLibraryProperties.Droiddoc_option_files |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 489 | props.Args = proptools.StringPtr(droiddocArgs) |
| 490 | |
| 491 | // List of APIs identified from the provided source files are created. They are later |
| 492 | // compared against to the not-yet-released (a.k.a current) list of APIs and to the |
| 493 | // last-released (a.k.a numbered) list of API. |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 494 | currentApiFileName := "current.txt" |
| 495 | removedApiFileName := "removed.txt" |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 496 | switch apiScope { |
| 497 | case apiScopeSystem: |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 498 | currentApiFileName = "system-" + currentApiFileName |
| 499 | removedApiFileName = "system-" + removedApiFileName |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 500 | case apiScopeTest: |
| 501 | currentApiFileName = "test-" + currentApiFileName |
| 502 | removedApiFileName = "test-" + removedApiFileName |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 503 | } |
| 504 | currentApiFileName = path.Join("api", currentApiFileName) |
| 505 | removedApiFileName = path.Join("api", removedApiFileName) |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 506 | // TODO(jiyong): remove these three props |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 507 | props.Api_tag_name = proptools.StringPtr(module.apiTagName(apiScope)) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 508 | props.Api_filename = proptools.StringPtr(currentApiFileName) |
| 509 | props.Removed_api_filename = proptools.StringPtr(removedApiFileName) |
| 510 | |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 511 | // check against the not-yet-release API |
| 512 | props.Check_api.Current.Api_file = proptools.StringPtr(currentApiFileName) |
| 513 | props.Check_api.Current.Removed_api_file = proptools.StringPtr(removedApiFileName) |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 514 | |
| 515 | // check against the latest released API |
| 516 | props.Check_api.Last_released.Api_file = proptools.StringPtr( |
| 517 | module.latestApiFilegroupName(apiScope)) |
| 518 | props.Check_api.Last_released.Removed_api_file = proptools.StringPtr( |
| 519 | module.latestRemovedApiFilegroupName(apiScope)) |
Inseob Kim | 38449af | 2019-02-28 14:24:05 +0900 | [diff] [blame] | 520 | props.Check_api.Ignore_missing_latest_api = proptools.BoolPtr(true) |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 521 | props.Srcs_lib = module.sdkLibraryProperties.Srcs_lib |
| 522 | props.Srcs_lib_whitelist_dirs = module.sdkLibraryProperties.Srcs_lib_whitelist_dirs |
| 523 | props.Srcs_lib_whitelist_pkgs = module.sdkLibraryProperties.Srcs_lib_whitelist_pkgs |
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 |
| 537 | |
| 538 | http://www.apache.org/licenses/LICENSE-2.0 |
| 539 | |
| 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 | |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 588 | func (module *SdkLibrary) PrebuiltJars(ctx android.BaseContext, sdkVersion string) android.Paths { |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 589 | var api, v string |
| 590 | if sdkVersion == "" { |
| 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 |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 612 | func (module *SdkLibrary) SdkHeaderJars(ctx android.BaseContext, 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 | 2c77ceb | 2019-01-21 11:56:21 -0800 | [diff] [blame] | 614 | if ctx.Config().UnbundledBuildPrebuiltSdks() { |
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 |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 628 | func (module *SdkLibrary) SdkImplementationJars(ctx android.BaseContext, 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 | 2c77ceb | 2019-01-21 11:56:21 -0800 | [diff] [blame] | 630 | if ctx.Config().UnbundledBuildPrebuiltSdks() { |
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 | |
Colin Cross | 571cccf | 2019-02-04 11:22:08 -0800 | [diff] [blame] | 643 | var javaSdkLibrariesKey = android.NewOnceKey("javaSdkLibraries") |
| 644 | |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 645 | func javaSdkLibraries(config android.Config) *[]string { |
Colin Cross | 571cccf | 2019-02-04 11:22:08 -0800 | [diff] [blame] | 646 | return config.Once(javaSdkLibrariesKey, func() interface{} { |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 647 | return &[]string{} |
| 648 | }).(*[]string) |
| 649 | } |
| 650 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 651 | // For a java_sdk_library module, create internal modules for stubs, docs, |
| 652 | // runtime libs and xml file. If requested, the stubs and docs are created twice |
| 653 | // once for public API level and once for system API level |
Colin Cross | f8b860a | 2019-04-16 14:43:28 -0700 | [diff] [blame] | 654 | func (module *SdkLibrary) CreateInternalModules(mctx android.LoadHookContext) { |
Inseob Kim | 6e93ac9 | 2019-03-21 17:43:49 +0900 | [diff] [blame] | 655 | if len(module.Library.Module.properties.Srcs) == 0 { |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 656 | mctx.PropertyErrorf("srcs", "java_sdk_library must specify srcs") |
| 657 | } |
| 658 | |
Inseob Kim | 6e93ac9 | 2019-03-21 17:43:49 +0900 | [diff] [blame] | 659 | if len(module.sdkLibraryProperties.Api_packages) == 0 { |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 660 | mctx.PropertyErrorf("api_packages", "java_sdk_library must specify api_packages") |
| 661 | } |
Inseob Kim | 8098faa | 2019-03-18 10:19:51 +0900 | [diff] [blame] | 662 | |
| 663 | missing_current_api := false |
| 664 | |
| 665 | for _, scope := range []string{"", "system-", "test-"} { |
| 666 | for _, api := range []string{"current.txt", "removed.txt"} { |
| 667 | path := path.Join(mctx.ModuleDir(), "api", scope+api) |
| 668 | p := android.ExistentPathForSource(mctx, path) |
| 669 | if !p.Valid() { |
| 670 | mctx.ModuleErrorf("Current api file %#v doesn't exist", path) |
| 671 | missing_current_api = true |
| 672 | } |
| 673 | } |
| 674 | } |
| 675 | |
| 676 | if missing_current_api { |
| 677 | script := "build/soong/scripts/gen-java-current-api-files.sh" |
| 678 | p := android.ExistentPathForSource(mctx, script) |
| 679 | |
| 680 | if !p.Valid() { |
| 681 | panic(fmt.Sprintf("script file %s doesn't exist", script)) |
| 682 | } |
| 683 | |
| 684 | mctx.ModuleErrorf("One or more current api files are missing. "+ |
| 685 | "You can update them by:\n"+ |
| 686 | "%s %q && m update-api", script, mctx.ModuleDir()) |
| 687 | return |
| 688 | } |
| 689 | |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 690 | // for public API stubs |
| 691 | module.createStubsLibrary(mctx, apiScopePublic) |
| 692 | module.createDocs(mctx, apiScopePublic) |
| 693 | |
| 694 | if !Bool(module.properties.No_standard_libs) { |
| 695 | // for system API stubs |
| 696 | module.createStubsLibrary(mctx, apiScopeSystem) |
| 697 | module.createDocs(mctx, apiScopeSystem) |
| 698 | |
| 699 | // for test API stubs |
| 700 | module.createStubsLibrary(mctx, apiScopeTest) |
| 701 | module.createDocs(mctx, apiScopeTest) |
| 702 | |
| 703 | // for runtime |
| 704 | module.createXmlFile(mctx) |
| 705 | } |
| 706 | |
| 707 | // record java_sdk_library modules so that they are exported to make |
| 708 | javaSdkLibraries := javaSdkLibraries(mctx.Config()) |
| 709 | javaSdkLibrariesLock.Lock() |
| 710 | defer javaSdkLibrariesLock.Unlock() |
| 711 | *javaSdkLibraries = append(*javaSdkLibraries, module.BaseModuleName()) |
| 712 | } |
| 713 | |
| 714 | func (module *SdkLibrary) InitSdkLibraryProperties() { |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 715 | module.AddProperties( |
| 716 | &module.sdkLibraryProperties, |
| 717 | &module.Library.Module.properties, |
| 718 | &module.Library.Module.dexpreoptProperties, |
| 719 | &module.Library.Module.deviceProperties, |
| 720 | &module.Library.Module.protoProperties, |
| 721 | ) |
| 722 | |
| 723 | module.Library.Module.properties.Installable = proptools.BoolPtr(true) |
| 724 | module.Library.Module.deviceProperties.IsSDKLibrary = true |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 725 | } |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 726 | |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 727 | func SdkLibraryFactory() android.Module { |
| 728 | module := &SdkLibrary{} |
| 729 | module.InitSdkLibraryProperties() |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 730 | InitJavaModule(module, android.HostAndDeviceSupported) |
Colin Cross | f8b860a | 2019-04-16 14:43:28 -0700 | [diff] [blame] | 731 | android.AddLoadHook(module, func(ctx android.LoadHookContext) { module.CreateInternalModules(ctx) }) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 732 | return module |
| 733 | } |