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