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