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() { |
| 77 | android.RegisterModuleType("java_sdk_library", sdkLibraryFactory) |
| 78 | |
| 79 | android.PreArchMutators(func(ctx android.RegisterMutatorsContext) { |
| 80 | ctx.TopDown("java_sdk_library", sdkLibraryMutator).Parallel() |
| 81 | }) |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 82 | |
| 83 | android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) { |
| 84 | javaSdkLibraries := javaSdkLibraries(ctx.Config()) |
| 85 | sort.Strings(*javaSdkLibraries) |
| 86 | ctx.Strict("JAVA_SDK_LIBRARIES", strings.Join(*javaSdkLibraries, " ")) |
| 87 | }) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | type sdkLibraryProperties struct { |
Jiyong Park | baaf9dd | 2018-05-02 01:35:27 +0900 | [diff] [blame] | 91 | // list of optional source files that are part of API but not part of runtime library. |
| 92 | Api_srcs []string `android:"arch_variant"` |
| 93 | |
Sundong Ahn | f043cf6 | 2018-06-25 16:04:37 +0900 | [diff] [blame] | 94 | // List of Java libraries that will be in the classpath when building stubs |
| 95 | Stub_only_libs []string `android:"arch_variant"` |
| 96 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 97 | // list of package names that will be documented and publicized as API |
| 98 | Api_packages []string |
| 99 | |
Jiyong Park | 5a2c9d7 | 2018-05-01 22:25:41 +0900 | [diff] [blame] | 100 | // list of package names that must be hidden from the API |
| 101 | Hidden_api_packages []string |
| 102 | |
Sundong Ahn | dd567f9 | 2018-07-31 17:19:11 +0900 | [diff] [blame] | 103 | // Additional droiddoc options |
| 104 | Droiddoc_options []string |
| 105 | |
Sundong Ahn | b952ba0 | 2019-01-08 16:32:12 +0900 | [diff] [blame] | 106 | // the java library (in classpath) for documentation that provides java srcs and srcjars. |
| 107 | Srcs_lib *string |
| 108 | |
| 109 | // the base dirs under srcs_lib will be scanned for java srcs. |
| 110 | Srcs_lib_whitelist_dirs []string |
| 111 | |
Sundong Ahn | dd567f9 | 2018-07-31 17:19:11 +0900 | [diff] [blame] | 112 | // the sub dirs under srcs_lib_whitelist_dirs will be scanned for java srcs. |
| 113 | // Defaults to "android.annotation". |
| 114 | Srcs_lib_whitelist_pkgs []string |
| 115 | |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame^] | 116 | // a list of top-level directories containing files to merge qualifier annotations |
| 117 | // (i.e. those intended to be included in the stubs written) from. |
| 118 | Merge_annotations_dirs []string |
| 119 | |
| 120 | // a list of top-level directories containing Java stub files to merge show/hide annotations from. |
| 121 | Merge_inclusion_annotations_dirs []string |
| 122 | |
| 123 | // If set to true, the path of dist files is apistubs/core. Defaults to false. |
| 124 | Core_lib *bool |
| 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 | |
| 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 | |
| 148 | func (module *sdkLibrary) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 149 | // Add dependencies to the stubs library |
Colin Cross | 42d48b7 | 2018-08-29 14:10:52 -0700 | [diff] [blame] | 150 | ctx.AddVariationDependencies(nil, publicApiStubsTag, module.stubsName(apiScopePublic)) |
Colin Cross | 42d48b7 | 2018-08-29 14:10:52 -0700 | [diff] [blame] | 151 | ctx.AddVariationDependencies(nil, publicApiFileTag, module.docsName(apiScopePublic)) |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame^] | 152 | |
| 153 | if !Bool(module.properties.No_standard_libs) { |
| 154 | ctx.AddVariationDependencies(nil, systemApiStubsTag, module.stubsName(apiScopeSystem)) |
| 155 | ctx.AddVariationDependencies(nil, systemApiFileTag, module.docsName(apiScopeSystem)) |
| 156 | ctx.AddVariationDependencies(nil, testApiFileTag, module.docsName(apiScopeTest)) |
| 157 | ctx.AddVariationDependencies(nil, testApiStubsTag, module.stubsName(apiScopeTest)) |
| 158 | } |
| 159 | |
| 160 | module.Library.deps(ctx) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | func (module *sdkLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame^] | 164 | module.Library.GenerateAndroidBuildActions(ctx) |
| 165 | |
Sundong Ahn | 57368eb | 2018-07-06 11:20:23 +0900 | [diff] [blame] | 166 | // Record the paths to the header jars of the library (stubs and impl). |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 167 | // When this java_sdk_library is dependened from others via "libs" property, |
| 168 | // the recorded paths will be returned depending on the link type of the caller. |
| 169 | ctx.VisitDirectDeps(func(to android.Module) { |
| 170 | otherName := ctx.OtherModuleName(to) |
| 171 | tag := ctx.OtherModuleDependencyTag(to) |
| 172 | |
Sundong Ahn | 57368eb | 2018-07-06 11:20:23 +0900 | [diff] [blame] | 173 | if lib, ok := to.(Dependency); ok { |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 174 | switch tag { |
| 175 | case publicApiStubsTag: |
Sundong Ahn | 57368eb | 2018-07-06 11:20:23 +0900 | [diff] [blame] | 176 | module.publicApiStubsPath = lib.HeaderJars() |
Sundong Ahn | 241cd37 | 2018-07-13 16:16:44 +0900 | [diff] [blame] | 177 | module.publicApiStubsImplPath = lib.ImplementationJars() |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 178 | case systemApiStubsTag: |
Sundong Ahn | 57368eb | 2018-07-06 11:20:23 +0900 | [diff] [blame] | 179 | module.systemApiStubsPath = lib.HeaderJars() |
Sundong Ahn | 241cd37 | 2018-07-13 16:16:44 +0900 | [diff] [blame] | 180 | module.systemApiStubsImplPath = lib.ImplementationJars() |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 181 | case testApiStubsTag: |
Sundong Ahn | 57368eb | 2018-07-06 11:20:23 +0900 | [diff] [blame] | 182 | module.testApiStubsPath = lib.HeaderJars() |
Sundong Ahn | 241cd37 | 2018-07-13 16:16:44 +0900 | [diff] [blame] | 183 | module.testApiStubsImplPath = lib.ImplementationJars() |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 184 | } |
| 185 | } |
Sundong Ahn | 20e998b | 2018-07-24 11:19:26 +0900 | [diff] [blame] | 186 | if doc, ok := to.(ApiFilePath); ok { |
| 187 | switch tag { |
| 188 | case publicApiFileTag: |
| 189 | module.publicApiFilePath = doc.ApiFilePath() |
| 190 | case systemApiFileTag: |
| 191 | module.systemApiFilePath = doc.ApiFilePath() |
| 192 | case testApiFileTag: |
| 193 | module.testApiFilePath = doc.ApiFilePath() |
| 194 | default: |
| 195 | ctx.ModuleErrorf("depends on module %q of unknown tag %q", otherName, tag) |
| 196 | } |
| 197 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 198 | }) |
| 199 | } |
| 200 | |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 201 | func (module *sdkLibrary) AndroidMk() android.AndroidMkData { |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame^] | 202 | data := module.Library.AndroidMk() |
| 203 | data.Required = append(data.Required, module.xmlFileName()) |
| 204 | |
| 205 | data.Custom = func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) { |
| 206 | android.WriteAndroidMkData(w, data) |
| 207 | |
| 208 | module.Library.AndroidMkHostDex(w, name, data) |
| 209 | // Create a phony module that installs the impl library, for the case when this lib is |
| 210 | // in PRODUCT_PACKAGES. |
| 211 | owner := module.ModuleBase.Owner() |
| 212 | if owner == "" { |
| 213 | if Bool(module.sdkLibraryProperties.Core_lib) { |
| 214 | owner = "core" |
| 215 | } else { |
Sundong Ahn | 4fd04bb | 2018-08-31 18:01:37 +0900 | [diff] [blame] | 216 | owner = "android" |
| 217 | } |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame^] | 218 | } |
| 219 | // Create dist rules to install the stubs libs to the dist dir |
| 220 | if len(module.publicApiStubsPath) == 1 { |
| 221 | fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+ |
| 222 | module.publicApiStubsImplPath.Strings()[0]+ |
| 223 | ":"+path.Join("apistubs", owner, "public", |
| 224 | module.BaseModuleName()+".jar")+")") |
| 225 | } |
| 226 | if len(module.systemApiStubsPath) == 1 { |
| 227 | fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+ |
| 228 | module.systemApiStubsImplPath.Strings()[0]+ |
| 229 | ":"+path.Join("apistubs", owner, "system", |
| 230 | module.BaseModuleName()+".jar")+")") |
| 231 | } |
| 232 | if len(module.testApiStubsPath) == 1 { |
| 233 | fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+ |
| 234 | module.testApiStubsImplPath.Strings()[0]+ |
| 235 | ":"+path.Join("apistubs", owner, "test", |
| 236 | module.BaseModuleName()+".jar")+")") |
| 237 | } |
| 238 | if module.publicApiFilePath != nil { |
| 239 | fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+ |
| 240 | module.publicApiFilePath.String()+ |
| 241 | ":"+path.Join("apistubs", owner, "public", "api", |
| 242 | module.BaseModuleName()+".txt")+")") |
| 243 | } |
| 244 | if module.systemApiFilePath != nil { |
| 245 | fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+ |
| 246 | module.systemApiFilePath.String()+ |
| 247 | ":"+path.Join("apistubs", owner, "system", "api", |
| 248 | module.BaseModuleName()+".txt")+")") |
| 249 | } |
| 250 | if module.testApiFilePath != nil { |
| 251 | fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+ |
| 252 | module.testApiFilePath.String()+ |
| 253 | ":"+path.Join("apistubs", owner, "test", "api", |
| 254 | module.BaseModuleName()+".txt")+")") |
| 255 | } |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 256 | } |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame^] | 257 | return data |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 258 | } |
| 259 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 260 | // Module name of the stubs library |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 261 | func (module *sdkLibrary) stubsName(apiScope apiScope) string { |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 262 | stubsName := module.BaseModuleName() + sdkStubsLibrarySuffix |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 263 | switch apiScope { |
| 264 | case apiScopeSystem: |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 265 | stubsName = stubsName + sdkSystemApiSuffix |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 266 | case apiScopeTest: |
| 267 | stubsName = stubsName + sdkTestApiSuffix |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 268 | } |
| 269 | return stubsName |
| 270 | } |
| 271 | |
| 272 | // Module name of the docs |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 273 | func (module *sdkLibrary) docsName(apiScope apiScope) string { |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 274 | docsName := module.BaseModuleName() + sdkDocsSuffix |
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 | docsName = docsName + sdkSystemApiSuffix |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 278 | case apiScopeTest: |
| 279 | docsName = docsName + sdkTestApiSuffix |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 280 | } |
| 281 | return docsName |
| 282 | } |
| 283 | |
| 284 | // Module name of the runtime implementation library |
| 285 | func (module *sdkLibrary) implName() string { |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame^] | 286 | return module.BaseModuleName() |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | // File path to the runtime implementation library |
| 290 | func (module *sdkLibrary) implPath() string { |
| 291 | partition := "system" |
| 292 | if module.SocSpecific() { |
| 293 | partition = "vendor" |
| 294 | } else if module.DeviceSpecific() { |
| 295 | partition = "odm" |
| 296 | } else if module.ProductSpecific() { |
| 297 | partition = "product" |
| 298 | } |
| 299 | return "/" + partition + "/framework/" + module.implName() + ".jar" |
| 300 | } |
| 301 | |
| 302 | // Module name of the XML file for the lib |
| 303 | func (module *sdkLibrary) xmlFileName() string { |
| 304 | return module.BaseModuleName() + sdkXmlFileSuffix |
| 305 | } |
| 306 | |
| 307 | // SDK version that the stubs library is built against. Note that this is always |
| 308 | // *current. Older stubs library built with a numberd SDK version is created from |
| 309 | // the prebuilt jar. |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 310 | func (module *sdkLibrary) sdkVersion(apiScope apiScope) string { |
| 311 | switch apiScope { |
| 312 | case apiScopePublic: |
| 313 | return "current" |
| 314 | case apiScopeSystem: |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 315 | return "system_current" |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 316 | case apiScopeTest: |
| 317 | return "test_current" |
| 318 | default: |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 319 | return "current" |
| 320 | } |
| 321 | } |
| 322 | |
| 323 | // $(INTERNAL_PLATFORM_<apiTagName>_API_FILE) points to the generated |
| 324 | // api file for the current source |
| 325 | // TODO: remove this when apicheck is done in soong |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 326 | func (module *sdkLibrary) apiTagName(apiScope apiScope) string { |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 327 | apiTagName := strings.Replace(strings.ToUpper(module.BaseModuleName()), ".", "_", -1) |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 328 | switch apiScope { |
| 329 | case apiScopeSystem: |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 330 | apiTagName = apiTagName + "_SYSTEM" |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 331 | case apiScopeTest: |
| 332 | apiTagName = apiTagName + "_TEST" |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 333 | } |
| 334 | return apiTagName |
| 335 | } |
| 336 | |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 337 | func (module *sdkLibrary) latestApiFilegroupName(apiScope apiScope) string { |
| 338 | name := ":" + module.BaseModuleName() + ".api." |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 339 | switch apiScope { |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 340 | case apiScopePublic: |
| 341 | name = name + "public" |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 342 | case apiScopeSystem: |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 343 | name = name + "system" |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 344 | case apiScopeTest: |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 345 | name = name + "test" |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 346 | } |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 347 | name = name + ".latest" |
| 348 | return name |
| 349 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 350 | |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 351 | func (module *sdkLibrary) latestRemovedApiFilegroupName(apiScope apiScope) string { |
| 352 | name := ":" + module.BaseModuleName() + "-removed.api." |
| 353 | switch apiScope { |
| 354 | case apiScopePublic: |
| 355 | name = name + "public" |
| 356 | case apiScopeSystem: |
| 357 | name = name + "system" |
| 358 | case apiScopeTest: |
| 359 | name = name + "test" |
| 360 | } |
| 361 | name = name + ".latest" |
| 362 | return name |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | // Creates a static java library that has API stubs |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 366 | func (module *sdkLibrary) createStubsLibrary(mctx android.TopDownMutatorContext, apiScope apiScope) { |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 367 | props := struct { |
| 368 | Name *string |
| 369 | Srcs []string |
| 370 | Sdk_version *string |
Sundong Ahn | f043cf6 | 2018-06-25 16:04:37 +0900 | [diff] [blame] | 371 | Libs []string |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 372 | Soc_specific *bool |
| 373 | Device_specific *bool |
| 374 | Product_specific *bool |
Sundong Ahn | dd567f9 | 2018-07-31 17:19:11 +0900 | [diff] [blame] | 375 | Compile_dex *bool |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame^] | 376 | No_standard_libs *bool |
| 377 | System_modules *string |
| 378 | Java_version *string |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 379 | Product_variables struct { |
| 380 | Unbundled_build struct { |
| 381 | Enabled *bool |
| 382 | } |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 383 | Pdk struct { |
| 384 | Enabled *bool |
| 385 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 386 | } |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame^] | 387 | Openjdk9 struct { |
| 388 | Srcs []string |
| 389 | Javacflags []string |
| 390 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 391 | }{} |
| 392 | |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 393 | props.Name = proptools.StringPtr(module.stubsName(apiScope)) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 394 | // sources are generated from the droiddoc |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 395 | props.Srcs = []string{":" + module.docsName(apiScope)} |
| 396 | props.Sdk_version = proptools.StringPtr(module.sdkVersion(apiScope)) |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame^] | 397 | props.Libs = module.sdkLibraryProperties.Stub_only_libs |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 398 | // Unbundled apps will use the prebult one from /prebuilts/sdk |
| 399 | props.Product_variables.Unbundled_build.Enabled = proptools.BoolPtr(false) |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 400 | props.Product_variables.Pdk.Enabled = proptools.BoolPtr(false) |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame^] | 401 | props.No_standard_libs = module.Library.Module.properties.No_standard_libs |
| 402 | props.System_modules = module.Library.Module.deviceProperties.System_modules |
| 403 | props.Openjdk9.Srcs = module.Library.Module.properties.Openjdk9.Srcs |
| 404 | props.Openjdk9.Javacflags = module.Library.Module.properties.Openjdk9.Javacflags |
| 405 | props.Java_version = module.Library.Module.properties.Java_version |
| 406 | if module.Library.Module.deviceProperties.Compile_dex != nil { |
| 407 | props.Compile_dex = module.Library.Module.deviceProperties.Compile_dex |
Sundong Ahn | dd567f9 | 2018-07-31 17:19:11 +0900 | [diff] [blame] | 408 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 409 | |
| 410 | if module.SocSpecific() { |
| 411 | props.Soc_specific = proptools.BoolPtr(true) |
| 412 | } else if module.DeviceSpecific() { |
| 413 | props.Device_specific = proptools.BoolPtr(true) |
| 414 | } else if module.ProductSpecific() { |
| 415 | props.Product_specific = proptools.BoolPtr(true) |
| 416 | } |
| 417 | |
Colin Cross | 9ae1b92 | 2018-06-26 17:59:05 -0700 | [diff] [blame] | 418 | mctx.CreateModule(android.ModuleFactoryAdaptor(LibraryFactory), &props) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 419 | } |
| 420 | |
| 421 | // Creates a droiddoc module that creates stubs source files from the given full source |
| 422 | // files |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 423 | func (module *sdkLibrary) createDocs(mctx android.TopDownMutatorContext, apiScope apiScope) { |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 424 | props := struct { |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame^] | 425 | Name *string |
| 426 | Srcs []string |
| 427 | Installable *bool |
| 428 | Srcs_lib *string |
| 429 | Srcs_lib_whitelist_dirs []string |
| 430 | Srcs_lib_whitelist_pkgs []string |
| 431 | Libs []string |
| 432 | Args *string |
| 433 | Api_tag_name *string |
| 434 | Api_filename *string |
| 435 | Removed_api_filename *string |
| 436 | No_standard_libs *bool |
| 437 | Java_version *string |
| 438 | Merge_annotations_dirs []string |
| 439 | Merge_inclusion_annotations_dirs []string |
| 440 | Check_api struct { |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 441 | Current ApiToCheck |
| 442 | Last_released ApiToCheck |
| 443 | } |
Sundong Ahn | 1b92c82 | 2018-05-29 11:35:17 +0900 | [diff] [blame] | 444 | Aidl struct { |
| 445 | Include_dirs []string |
| 446 | Local_include_dirs []string |
| 447 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 448 | }{} |
| 449 | |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 450 | props.Name = proptools.StringPtr(module.docsName(apiScope)) |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame^] | 451 | props.Srcs = append(props.Srcs, module.Library.Module.properties.Srcs...) |
| 452 | props.Srcs = append(props.Srcs, module.sdkLibraryProperties.Api_srcs...) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 453 | props.Installable = proptools.BoolPtr(false) |
Sundong Ahn | e6f0b05 | 2018-06-05 16:46:14 +0900 | [diff] [blame] | 454 | // A droiddoc module has only one Libs property and doesn't distinguish between |
| 455 | // 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^] | 456 | props.Libs = module.Library.Module.properties.Libs |
| 457 | props.Libs = append(props.Libs, module.Library.Module.properties.Static_libs...) |
| 458 | props.Aidl.Include_dirs = module.Library.Module.deviceProperties.Aidl.Include_dirs |
| 459 | props.Aidl.Local_include_dirs = module.Library.Module.deviceProperties.Aidl.Local_include_dirs |
| 460 | props.No_standard_libs = module.Library.Module.properties.No_standard_libs |
| 461 | props.Java_version = module.Library.Module.properties.Java_version |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 462 | |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame^] | 463 | props.Merge_annotations_dirs = module.sdkLibraryProperties.Merge_annotations_dirs |
| 464 | props.Merge_inclusion_annotations_dirs = module.sdkLibraryProperties.Merge_inclusion_annotations_dirs |
| 465 | |
| 466 | droiddocArgs := " --stub-packages " + strings.Join(module.sdkLibraryProperties.Api_packages, ":") + |
| 467 | " " + android.JoinWithPrefix(module.sdkLibraryProperties.Hidden_api_packages, " --hide-package ") + |
| 468 | " " + android.JoinWithPrefix(module.sdkLibraryProperties.Droiddoc_options, " ") + |
Sundong Ahn | 04ef8a3 | 2019-01-14 11:36:50 +0900 | [diff] [blame] | 469 | " --hide MissingPermission --hide BroadcastBehavior " + |
| 470 | "--hide HiddenSuperclass --hide DeprecationMismatch --hide UnavailableSymbol " + |
| 471 | "--hide SdkConstant --hide HiddenTypeParameter --hide Todo --hide Typo" |
Sundong Ahn | fb2721f | 2018-09-17 13:23:09 +0900 | [diff] [blame] | 472 | |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 473 | switch apiScope { |
| 474 | case apiScopeSystem: |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 475 | droiddocArgs = droiddocArgs + " -showAnnotation android.annotation.SystemApi" |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 476 | case apiScopeTest: |
| 477 | droiddocArgs = droiddocArgs + " -showAnnotation android.annotation.TestApi" |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 478 | } |
| 479 | props.Args = proptools.StringPtr(droiddocArgs) |
| 480 | |
| 481 | // List of APIs identified from the provided source files are created. They are later |
| 482 | // compared against to the not-yet-released (a.k.a current) list of APIs and to the |
| 483 | // last-released (a.k.a numbered) list of API. |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 484 | currentApiFileName := "current.txt" |
| 485 | removedApiFileName := "removed.txt" |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 486 | switch apiScope { |
| 487 | case apiScopeSystem: |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 488 | currentApiFileName = "system-" + currentApiFileName |
| 489 | removedApiFileName = "system-" + removedApiFileName |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 490 | case apiScopeTest: |
| 491 | currentApiFileName = "test-" + currentApiFileName |
| 492 | removedApiFileName = "test-" + removedApiFileName |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 493 | } |
| 494 | currentApiFileName = path.Join("api", currentApiFileName) |
| 495 | removedApiFileName = path.Join("api", removedApiFileName) |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 496 | // TODO(jiyong): remove these three props |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 497 | props.Api_tag_name = proptools.StringPtr(module.apiTagName(apiScope)) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 498 | props.Api_filename = proptools.StringPtr(currentApiFileName) |
| 499 | props.Removed_api_filename = proptools.StringPtr(removedApiFileName) |
| 500 | |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 501 | // check against the not-yet-release API |
| 502 | props.Check_api.Current.Api_file = proptools.StringPtr(currentApiFileName) |
| 503 | props.Check_api.Current.Removed_api_file = proptools.StringPtr(removedApiFileName) |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 504 | |
| 505 | // check against the latest released API |
| 506 | props.Check_api.Last_released.Api_file = proptools.StringPtr( |
| 507 | module.latestApiFilegroupName(apiScope)) |
| 508 | props.Check_api.Last_released.Removed_api_file = proptools.StringPtr( |
| 509 | module.latestRemovedApiFilegroupName(apiScope)) |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame^] | 510 | props.Srcs_lib = module.sdkLibraryProperties.Srcs_lib |
| 511 | props.Srcs_lib_whitelist_dirs = module.sdkLibraryProperties.Srcs_lib_whitelist_dirs |
| 512 | props.Srcs_lib_whitelist_pkgs = module.sdkLibraryProperties.Srcs_lib_whitelist_pkgs |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 513 | |
Sundong Ahn | 04ef8a3 | 2019-01-14 11:36:50 +0900 | [diff] [blame] | 514 | mctx.CreateModule(android.ModuleFactoryAdaptor(DroidstubsFactory), &props) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 515 | } |
| 516 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 517 | // Creates the xml file that publicizes the runtime library |
| 518 | func (module *sdkLibrary) createXmlFile(mctx android.TopDownMutatorContext) { |
| 519 | template := ` |
| 520 | <?xml version="1.0" encoding="utf-8"?> |
| 521 | <!-- Copyright (C) 2018 The Android Open Source Project |
| 522 | |
| 523 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 524 | you may not use this file except in compliance with the License. |
| 525 | You may obtain a copy of the License at |
| 526 | |
| 527 | http://www.apache.org/licenses/LICENSE-2.0 |
| 528 | |
| 529 | Unless required by applicable law or agreed to in writing, software |
| 530 | distributed under the License is distributed on an "AS IS" BASIS, |
| 531 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 532 | See the License for the specific language governing permissions and |
| 533 | limitations under the License. |
| 534 | --> |
| 535 | |
| 536 | <permissions> |
| 537 | <library name="%s" file="%s"/> |
| 538 | </permissions> |
| 539 | ` |
| 540 | // genrule to generate the xml file content from the template above |
| 541 | // TODO: preserve newlines in the generate xml file. Newlines are being squashed |
| 542 | // in the ninja file. Do we need to have an external tool for this? |
| 543 | xmlContent := fmt.Sprintf(template, module.BaseModuleName(), module.implPath()) |
| 544 | genruleProps := struct { |
| 545 | Name *string |
| 546 | Cmd *string |
| 547 | Out []string |
| 548 | }{} |
| 549 | genruleProps.Name = proptools.StringPtr(module.xmlFileName() + "-gen") |
| 550 | genruleProps.Cmd = proptools.StringPtr("echo '" + xmlContent + "' > $(out)") |
| 551 | genruleProps.Out = []string{module.xmlFileName()} |
| 552 | mctx.CreateModule(android.ModuleFactoryAdaptor(genrule.GenRuleFactory), &genruleProps) |
| 553 | |
| 554 | // creates a prebuilt_etc module to actually place the xml file under |
| 555 | // <partition>/etc/permissions |
| 556 | etcProps := struct { |
| 557 | Name *string |
Jiyong Park | 5a8d1be | 2018-04-25 22:57:34 +0900 | [diff] [blame] | 558 | Src *string |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 559 | Sub_dir *string |
| 560 | Soc_specific *bool |
| 561 | Device_specific *bool |
| 562 | Product_specific *bool |
| 563 | }{} |
| 564 | etcProps.Name = proptools.StringPtr(module.xmlFileName()) |
Jiyong Park | 5a8d1be | 2018-04-25 22:57:34 +0900 | [diff] [blame] | 565 | etcProps.Src = proptools.StringPtr(":" + module.xmlFileName() + "-gen") |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 566 | etcProps.Sub_dir = proptools.StringPtr("permissions") |
| 567 | if module.SocSpecific() { |
| 568 | etcProps.Soc_specific = proptools.BoolPtr(true) |
| 569 | } else if module.DeviceSpecific() { |
| 570 | etcProps.Device_specific = proptools.BoolPtr(true) |
| 571 | } else if module.ProductSpecific() { |
| 572 | etcProps.Product_specific = proptools.BoolPtr(true) |
| 573 | } |
| 574 | mctx.CreateModule(android.ModuleFactoryAdaptor(android.PrebuiltEtcFactory), &etcProps) |
| 575 | } |
| 576 | |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame^] | 577 | func (module *sdkLibrary) PrebuiltJars(ctx android.BaseContext, sdkVersion string) android.Paths { |
| 578 | var api, v string |
| 579 | if sdkVersion == "" { |
| 580 | api = "system" |
| 581 | v = "current" |
| 582 | } else if strings.Contains(sdkVersion, "_") { |
| 583 | t := strings.Split(sdkVersion, "_") |
| 584 | api = t[0] |
| 585 | v = t[1] |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 586 | } else { |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame^] | 587 | api = "public" |
| 588 | v = sdkVersion |
| 589 | } |
| 590 | dir := filepath.Join("prebuilts", "sdk", v, api) |
| 591 | jar := filepath.Join(dir, module.BaseModuleName()+".jar") |
| 592 | jarPath := android.ExistentPathForSource(ctx, jar) |
| 593 | return android.Paths{jarPath.Path()} |
| 594 | } |
| 595 | |
| 596 | // to satisfy SdkLibraryDependency interface |
| 597 | func (module *sdkLibrary) HeaderJars(ctx android.BaseContext, sdkVersion string) android.Paths { |
| 598 | // This module is just a wrapper for the stubs. |
| 599 | if ctx.Config().UnbundledBuild() { |
| 600 | return module.PrebuiltJars(ctx, sdkVersion) |
| 601 | } else { |
| 602 | if strings.HasPrefix(sdkVersion, "system_") { |
| 603 | return module.systemApiStubsPath |
| 604 | } else if sdkVersion == "" { |
| 605 | return module.Library.HeaderJars() |
| 606 | } else { |
| 607 | return module.publicApiStubsPath |
| 608 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 609 | } |
| 610 | } |
| 611 | |
Sundong Ahn | 241cd37 | 2018-07-13 16:16:44 +0900 | [diff] [blame] | 612 | // to satisfy SdkLibraryDependency interface |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame^] | 613 | func (module *sdkLibrary) ImplementationJars(ctx android.BaseContext, sdkVersion string) android.Paths { |
Sundong Ahn | 241cd37 | 2018-07-13 16:16:44 +0900 | [diff] [blame] | 614 | // This module is just a wrapper for the stubs. |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame^] | 615 | if ctx.Config().UnbundledBuild() { |
| 616 | return module.PrebuiltJars(ctx, sdkVersion) |
Sundong Ahn | 241cd37 | 2018-07-13 16:16:44 +0900 | [diff] [blame] | 617 | } else { |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame^] | 618 | if strings.HasPrefix(sdkVersion, "system_") { |
| 619 | return module.systemApiStubsImplPath |
| 620 | } else if sdkVersion == "" { |
| 621 | return module.Library.ImplementationJars() |
| 622 | } else { |
| 623 | return module.publicApiStubsImplPath |
| 624 | } |
Sundong Ahn | 241cd37 | 2018-07-13 16:16:44 +0900 | [diff] [blame] | 625 | } |
| 626 | } |
| 627 | |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 628 | func javaSdkLibraries(config android.Config) *[]string { |
| 629 | return config.Once("javaSdkLibraries", func() interface{} { |
| 630 | return &[]string{} |
| 631 | }).(*[]string) |
| 632 | } |
| 633 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 634 | // For a java_sdk_library module, create internal modules for stubs, docs, |
| 635 | // runtime libs and xml file. If requested, the stubs and docs are created twice |
| 636 | // once for public API level and once for system API level |
| 637 | func sdkLibraryMutator(mctx android.TopDownMutatorContext) { |
| 638 | if module, ok := mctx.Module().(*sdkLibrary); ok { |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame^] | 639 | if module.Library.Module.properties.Srcs == nil { |
Anton Hansson | 8959e14 | 2018-04-25 11:56:13 +0100 | [diff] [blame] | 640 | mctx.PropertyErrorf("srcs", "java_sdk_library must specify srcs") |
| 641 | } |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame^] | 642 | |
| 643 | if module.sdkLibraryProperties.Api_packages == nil { |
Anton Hansson | 8959e14 | 2018-04-25 11:56:13 +0100 | [diff] [blame] | 644 | mctx.PropertyErrorf("api_packages", "java_sdk_library must specify api_packages") |
| 645 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 646 | // for public API stubs |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 647 | module.createStubsLibrary(mctx, apiScopePublic) |
| 648 | module.createDocs(mctx, apiScopePublic) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 649 | |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame^] | 650 | if !Bool(module.properties.No_standard_libs) { |
| 651 | // for system API stubs |
| 652 | module.createStubsLibrary(mctx, apiScopeSystem) |
| 653 | module.createDocs(mctx, apiScopeSystem) |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 654 | |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame^] | 655 | // for test API stubs |
| 656 | module.createStubsLibrary(mctx, apiScopeTest) |
| 657 | module.createDocs(mctx, apiScopeTest) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 658 | |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame^] | 659 | // for runtime |
| 660 | module.createXmlFile(mctx) |
| 661 | } |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 662 | |
| 663 | // record java_sdk_library modules so that they are exported to make |
| 664 | javaSdkLibraries := javaSdkLibraries(mctx.Config()) |
| 665 | javaSdkLibrariesLock.Lock() |
| 666 | defer javaSdkLibrariesLock.Unlock() |
| 667 | *javaSdkLibraries = append(*javaSdkLibraries, module.BaseModuleName()) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 668 | } |
| 669 | } |
| 670 | |
| 671 | func sdkLibraryFactory() android.Module { |
| 672 | module := &sdkLibrary{} |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame^] | 673 | module.AddProperties( |
| 674 | &module.sdkLibraryProperties, |
| 675 | &module.Library.Module.properties, |
| 676 | &module.Library.Module.dexpreoptProperties, |
| 677 | &module.Library.Module.deviceProperties, |
| 678 | &module.Library.Module.protoProperties, |
| 679 | ) |
| 680 | |
| 681 | module.Library.Module.properties.Installable = proptools.BoolPtr(true) |
| 682 | module.Library.Module.deviceProperties.IsSDKLibrary = true |
| 683 | |
| 684 | InitJavaModule(module, android.HostAndDeviceSupported) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 685 | return module |
| 686 | } |