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" |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 23 | "sort" |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 24 | "strings" |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 25 | "sync" |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 26 | |
| 27 | "github.com/google/blueprint" |
| 28 | "github.com/google/blueprint/proptools" |
| 29 | ) |
| 30 | |
| 31 | var ( |
| 32 | sdkStubsLibrarySuffix = ".stubs" |
| 33 | sdkSystemApiSuffix = ".system" |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 34 | sdkTestApiSuffix = ".test" |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 35 | sdkDocsSuffix = ".docs" |
| 36 | sdkImplLibrarySuffix = ".impl" |
| 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 | 57368eb | 2018-07-06 11:20:23 +0900 | [diff] [blame] | 49 | implLibTag = dependencyTag{name: "platform"} |
Sundong Ahn | 20e998b | 2018-07-24 11:19:26 +0900 | [diff] [blame^] | 50 | publicApiFileTag = dependencyTag{name: "publicApi"} |
| 51 | systemApiFileTag = dependencyTag{name: "systemApi"} |
| 52 | testApiFileTag = dependencyTag{name: "testApi"} |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 53 | ) |
| 54 | |
| 55 | type apiScope int |
| 56 | |
| 57 | const ( |
| 58 | apiScopePublic apiScope = iota |
| 59 | apiScopeSystem |
| 60 | apiScopeTest |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 61 | ) |
| 62 | |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 63 | var ( |
| 64 | javaSdkLibrariesLock sync.Mutex |
| 65 | ) |
| 66 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 67 | // java_sdk_library is to make a Java library that implements optional platform APIs to apps. |
| 68 | // It is actually a wrapper of several modules: 1) stubs library that clients are linked against |
| 69 | // to, 2) droiddoc module that internally generates API stubs source files, 3) the real runtime |
| 70 | // shared library that implements the APIs, and 4) XML file for adding the runtime lib to the |
| 71 | // classpath at runtime if requested via <uses-library>. |
| 72 | // |
| 73 | // TODO: these are big features that are currently missing |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 74 | // 1) disallowing linking to the runtime shared lib |
| 75 | // 2) HTML generation |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 76 | |
| 77 | func init() { |
| 78 | android.RegisterModuleType("java_sdk_library", sdkLibraryFactory) |
| 79 | |
| 80 | android.PreArchMutators(func(ctx android.RegisterMutatorsContext) { |
| 81 | ctx.TopDown("java_sdk_library", sdkLibraryMutator).Parallel() |
| 82 | }) |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 83 | |
| 84 | android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) { |
| 85 | javaSdkLibraries := javaSdkLibraries(ctx.Config()) |
| 86 | sort.Strings(*javaSdkLibraries) |
| 87 | ctx.Strict("JAVA_SDK_LIBRARIES", strings.Join(*javaSdkLibraries, " ")) |
| 88 | }) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | type sdkLibraryProperties struct { |
| 92 | // list of source files used to compile the Java module. May be .java, .logtags, .proto, |
| 93 | // or .aidl files. |
| 94 | Srcs []string `android:"arch_variant"` |
| 95 | |
Jiyong Park | baaf9dd | 2018-05-02 01:35:27 +0900 | [diff] [blame] | 96 | // list of optional source files that are part of API but not part of runtime library. |
| 97 | Api_srcs []string `android:"arch_variant"` |
| 98 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 99 | // list of of java libraries that will be in the classpath |
| 100 | Libs []string `android:"arch_variant"` |
| 101 | |
| 102 | // list of java libraries that will be compiled into the resulting runtime jar. |
| 103 | // These libraries are not compiled into the stubs jar. |
| 104 | Static_libs []string `android:"arch_variant"` |
| 105 | |
Sundong Ahn | f043cf6 | 2018-06-25 16:04:37 +0900 | [diff] [blame] | 106 | // List of Java libraries that will be in the classpath when building stubs |
| 107 | Stub_only_libs []string `android:"arch_variant"` |
| 108 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 109 | // list of package names that will be documented and publicized as API |
| 110 | Api_packages []string |
| 111 | |
Jiyong Park | 5a2c9d7 | 2018-05-01 22:25:41 +0900 | [diff] [blame] | 112 | // list of package names that must be hidden from the API |
| 113 | Hidden_api_packages []string |
| 114 | |
Jiyong Park | b5b709f | 2018-06-15 10:38:59 +0900 | [diff] [blame] | 115 | Errorprone struct { |
| 116 | // List of javac flags that should only be used when running errorprone. |
| 117 | Javacflags []string |
| 118 | } |
| 119 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 120 | // TODO: determines whether to create HTML doc or not |
| 121 | //Html_doc *bool |
| 122 | } |
| 123 | |
| 124 | type sdkLibrary struct { |
| 125 | android.ModuleBase |
| 126 | android.DefaultableModuleBase |
| 127 | |
Jiyong Park | 441a47d | 2018-05-01 23:33:08 +0900 | [diff] [blame] | 128 | properties sdkLibraryProperties |
| 129 | deviceProperties CompilerDeviceProperties |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 130 | |
| 131 | publicApiStubsPath android.Paths |
| 132 | systemApiStubsPath android.Paths |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 133 | testApiStubsPath android.Paths |
Sundong Ahn | 57368eb | 2018-07-06 11:20:23 +0900 | [diff] [blame] | 134 | implLibPath android.Paths |
Sundong Ahn | 241cd37 | 2018-07-13 16:16:44 +0900 | [diff] [blame] | 135 | |
| 136 | publicApiStubsImplPath android.Paths |
| 137 | systemApiStubsImplPath android.Paths |
| 138 | testApiStubsImplPath android.Paths |
| 139 | implLibImplPath android.Paths |
Sundong Ahn | 20e998b | 2018-07-24 11:19:26 +0900 | [diff] [blame^] | 140 | |
| 141 | publicApiFilePath android.Path |
| 142 | systemApiFilePath android.Path |
| 143 | testApiFilePath android.Path |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | func (module *sdkLibrary) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 147 | // Add dependencies to the stubs library |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 148 | ctx.AddDependency(ctx.Module(), publicApiStubsTag, module.stubsName(apiScopePublic)) |
| 149 | ctx.AddDependency(ctx.Module(), systemApiStubsTag, module.stubsName(apiScopeSystem)) |
| 150 | ctx.AddDependency(ctx.Module(), testApiStubsTag, module.stubsName(apiScopeTest)) |
Sundong Ahn | 57368eb | 2018-07-06 11:20:23 +0900 | [diff] [blame] | 151 | ctx.AddDependency(ctx.Module(), implLibTag, module.implName()) |
Sundong Ahn | 20e998b | 2018-07-24 11:19:26 +0900 | [diff] [blame^] | 152 | |
| 153 | ctx.AddDependency(ctx.Module(), publicApiFileTag, module.docsName(apiScopePublic)) |
| 154 | ctx.AddDependency(ctx.Module(), systemApiFileTag, module.docsName(apiScopeSystem)) |
| 155 | ctx.AddDependency(ctx.Module(), testApiFileTag, module.docsName(apiScopeTest)) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | func (module *sdkLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Sundong Ahn | 57368eb | 2018-07-06 11:20:23 +0900 | [diff] [blame] | 159 | // 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] | 160 | // When this java_sdk_library is dependened from others via "libs" property, |
| 161 | // the recorded paths will be returned depending on the link type of the caller. |
| 162 | ctx.VisitDirectDeps(func(to android.Module) { |
| 163 | otherName := ctx.OtherModuleName(to) |
| 164 | tag := ctx.OtherModuleDependencyTag(to) |
| 165 | |
Sundong Ahn | 57368eb | 2018-07-06 11:20:23 +0900 | [diff] [blame] | 166 | if lib, ok := to.(Dependency); ok { |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 167 | switch tag { |
| 168 | case publicApiStubsTag: |
Sundong Ahn | 57368eb | 2018-07-06 11:20:23 +0900 | [diff] [blame] | 169 | module.publicApiStubsPath = lib.HeaderJars() |
Sundong Ahn | 241cd37 | 2018-07-13 16:16:44 +0900 | [diff] [blame] | 170 | module.publicApiStubsImplPath = lib.ImplementationJars() |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 171 | case systemApiStubsTag: |
Sundong Ahn | 57368eb | 2018-07-06 11:20:23 +0900 | [diff] [blame] | 172 | module.systemApiStubsPath = lib.HeaderJars() |
Sundong Ahn | 241cd37 | 2018-07-13 16:16:44 +0900 | [diff] [blame] | 173 | module.systemApiStubsImplPath = lib.ImplementationJars() |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 174 | case testApiStubsTag: |
Sundong Ahn | 57368eb | 2018-07-06 11:20:23 +0900 | [diff] [blame] | 175 | module.testApiStubsPath = lib.HeaderJars() |
Sundong Ahn | 241cd37 | 2018-07-13 16:16:44 +0900 | [diff] [blame] | 176 | module.testApiStubsImplPath = lib.ImplementationJars() |
Sundong Ahn | 57368eb | 2018-07-06 11:20:23 +0900 | [diff] [blame] | 177 | case implLibTag: |
| 178 | module.implLibPath = lib.HeaderJars() |
Sundong Ahn | 241cd37 | 2018-07-13 16:16:44 +0900 | [diff] [blame] | 179 | module.implLibImplPath = lib.ImplementationJars() |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 180 | default: |
| 181 | ctx.ModuleErrorf("depends on module %q of unknown tag %q", otherName, tag) |
| 182 | } |
| 183 | } |
Sundong Ahn | 20e998b | 2018-07-24 11:19:26 +0900 | [diff] [blame^] | 184 | if doc, ok := to.(ApiFilePath); ok { |
| 185 | switch tag { |
| 186 | case publicApiFileTag: |
| 187 | module.publicApiFilePath = doc.ApiFilePath() |
| 188 | case systemApiFileTag: |
| 189 | module.systemApiFilePath = doc.ApiFilePath() |
| 190 | case testApiFileTag: |
| 191 | module.testApiFilePath = doc.ApiFilePath() |
| 192 | default: |
| 193 | ctx.ModuleErrorf("depends on module %q of unknown tag %q", otherName, tag) |
| 194 | } |
| 195 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 196 | }) |
| 197 | } |
| 198 | |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 199 | func (module *sdkLibrary) AndroidMk() android.AndroidMkData { |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 200 | return android.AndroidMkData{ |
| 201 | Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) { |
Jiyong Park | 9007838 | 2018-05-02 19:30:15 +0900 | [diff] [blame] | 202 | // Create a phony module that installs the impl library, for the case when this lib is |
| 203 | // in PRODUCT_PACKAGES. |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 204 | fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)") |
| 205 | fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir) |
| 206 | fmt.Fprintln(w, "LOCAL_MODULE :=", name) |
| 207 | fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES := "+module.implName()) |
| 208 | fmt.Fprintln(w, "include $(BUILD_PHONY_PACKAGE)") |
Jiyong Park | 9007838 | 2018-05-02 19:30:15 +0900 | [diff] [blame] | 209 | // Create dist rules to install the stubs libs to the dist dir |
Jiyong Park | b674a52 | 2018-05-06 07:53:02 +0900 | [diff] [blame] | 210 | if len(module.publicApiStubsPath) == 1 { |
| 211 | fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+ |
| 212 | module.publicApiStubsPath.Strings()[0]+ |
| 213 | ":"+path.Join("apistubs", "public", module.BaseModuleName()+".jar")+")") |
| 214 | } |
| 215 | if len(module.systemApiStubsPath) == 1 { |
| 216 | fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+ |
| 217 | module.systemApiStubsPath.Strings()[0]+ |
| 218 | ":"+path.Join("apistubs", "system", module.BaseModuleName()+".jar")+")") |
| 219 | } |
| 220 | if len(module.testApiStubsPath) == 1 { |
| 221 | fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+ |
| 222 | module.testApiStubsPath.Strings()[0]+ |
| 223 | ":"+path.Join("apistubs", "test", module.BaseModuleName()+".jar")+")") |
| 224 | } |
Sundong Ahn | 20e998b | 2018-07-24 11:19:26 +0900 | [diff] [blame^] | 225 | if module.publicApiFilePath != nil { |
| 226 | fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+ |
| 227 | module.publicApiFilePath.String()+ |
| 228 | ":"+path.Join("apistubs", "public", "api", |
| 229 | module.BaseModuleName()+".txt")+")") |
| 230 | } |
| 231 | if module.systemApiFilePath != nil { |
| 232 | fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+ |
| 233 | module.systemApiFilePath.String()+ |
| 234 | ":"+path.Join("apistubs", "system", "api", |
| 235 | module.BaseModuleName()+".txt")+")") |
| 236 | } |
| 237 | if module.testApiFilePath != nil { |
| 238 | fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+ |
| 239 | module.testApiFilePath.String()+ |
| 240 | ":"+path.Join("apistubs", "test", "api", |
| 241 | module.BaseModuleName()+".txt")+")") |
| 242 | } |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 243 | }, |
| 244 | } |
| 245 | } |
| 246 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 247 | // Module name of the stubs library |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 248 | func (module *sdkLibrary) stubsName(apiScope apiScope) string { |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 249 | stubsName := module.BaseModuleName() + sdkStubsLibrarySuffix |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 250 | switch apiScope { |
| 251 | case apiScopeSystem: |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 252 | stubsName = stubsName + sdkSystemApiSuffix |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 253 | case apiScopeTest: |
| 254 | stubsName = stubsName + sdkTestApiSuffix |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 255 | } |
| 256 | return stubsName |
| 257 | } |
| 258 | |
| 259 | // Module name of the docs |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 260 | func (module *sdkLibrary) docsName(apiScope apiScope) string { |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 261 | docsName := module.BaseModuleName() + sdkDocsSuffix |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 262 | switch apiScope { |
| 263 | case apiScopeSystem: |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 264 | docsName = docsName + sdkSystemApiSuffix |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 265 | case apiScopeTest: |
| 266 | docsName = docsName + sdkTestApiSuffix |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 267 | } |
| 268 | return docsName |
| 269 | } |
| 270 | |
| 271 | // Module name of the runtime implementation library |
| 272 | func (module *sdkLibrary) implName() string { |
| 273 | return module.BaseModuleName() + sdkImplLibrarySuffix |
| 274 | } |
| 275 | |
| 276 | // File path to the runtime implementation library |
| 277 | func (module *sdkLibrary) implPath() string { |
| 278 | partition := "system" |
| 279 | if module.SocSpecific() { |
| 280 | partition = "vendor" |
| 281 | } else if module.DeviceSpecific() { |
| 282 | partition = "odm" |
| 283 | } else if module.ProductSpecific() { |
| 284 | partition = "product" |
| 285 | } |
| 286 | return "/" + partition + "/framework/" + module.implName() + ".jar" |
| 287 | } |
| 288 | |
| 289 | // Module name of the XML file for the lib |
| 290 | func (module *sdkLibrary) xmlFileName() string { |
| 291 | return module.BaseModuleName() + sdkXmlFileSuffix |
| 292 | } |
| 293 | |
| 294 | // SDK version that the stubs library is built against. Note that this is always |
| 295 | // *current. Older stubs library built with a numberd SDK version is created from |
| 296 | // the prebuilt jar. |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 297 | func (module *sdkLibrary) sdkVersion(apiScope apiScope) string { |
| 298 | switch apiScope { |
| 299 | case apiScopePublic: |
| 300 | return "current" |
| 301 | case apiScopeSystem: |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 302 | return "system_current" |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 303 | case apiScopeTest: |
| 304 | return "test_current" |
| 305 | default: |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 306 | return "current" |
| 307 | } |
| 308 | } |
| 309 | |
| 310 | // $(INTERNAL_PLATFORM_<apiTagName>_API_FILE) points to the generated |
| 311 | // api file for the current source |
| 312 | // TODO: remove this when apicheck is done in soong |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 313 | func (module *sdkLibrary) apiTagName(apiScope apiScope) string { |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 314 | apiTagName := strings.Replace(strings.ToUpper(module.BaseModuleName()), ".", "_", -1) |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 315 | switch apiScope { |
| 316 | case apiScopeSystem: |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 317 | apiTagName = apiTagName + "_SYSTEM" |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 318 | case apiScopeTest: |
| 319 | apiTagName = apiTagName + "_TEST" |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 320 | } |
| 321 | return apiTagName |
| 322 | } |
| 323 | |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 324 | func (module *sdkLibrary) latestApiFilegroupName(apiScope apiScope) string { |
| 325 | name := ":" + module.BaseModuleName() + ".api." |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 326 | switch apiScope { |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 327 | case apiScopePublic: |
| 328 | name = name + "public" |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 329 | case apiScopeSystem: |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 330 | name = name + "system" |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 331 | case apiScopeTest: |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 332 | name = name + "test" |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 333 | } |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 334 | name = name + ".latest" |
| 335 | return name |
| 336 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 337 | |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 338 | func (module *sdkLibrary) latestRemovedApiFilegroupName(apiScope apiScope) string { |
| 339 | name := ":" + module.BaseModuleName() + "-removed.api." |
| 340 | switch apiScope { |
| 341 | case apiScopePublic: |
| 342 | name = name + "public" |
| 343 | case apiScopeSystem: |
| 344 | name = name + "system" |
| 345 | case apiScopeTest: |
| 346 | name = name + "test" |
| 347 | } |
| 348 | name = name + ".latest" |
| 349 | return name |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | // Creates a static java library that has API stubs |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 353 | func (module *sdkLibrary) createStubsLibrary(mctx android.TopDownMutatorContext, apiScope apiScope) { |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 354 | props := struct { |
| 355 | Name *string |
| 356 | Srcs []string |
| 357 | Sdk_version *string |
Sundong Ahn | f043cf6 | 2018-06-25 16:04:37 +0900 | [diff] [blame] | 358 | Libs []string |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 359 | Soc_specific *bool |
| 360 | Device_specific *bool |
| 361 | Product_specific *bool |
| 362 | Product_variables struct { |
| 363 | Unbundled_build struct { |
| 364 | Enabled *bool |
| 365 | } |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 366 | Pdk struct { |
| 367 | Enabled *bool |
| 368 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 369 | } |
| 370 | }{} |
| 371 | |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 372 | props.Name = proptools.StringPtr(module.stubsName(apiScope)) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 373 | // sources are generated from the droiddoc |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 374 | props.Srcs = []string{":" + module.docsName(apiScope)} |
| 375 | props.Sdk_version = proptools.StringPtr(module.sdkVersion(apiScope)) |
Sundong Ahn | f043cf6 | 2018-06-25 16:04:37 +0900 | [diff] [blame] | 376 | props.Libs = module.properties.Stub_only_libs |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 377 | // Unbundled apps will use the prebult one from /prebuilts/sdk |
| 378 | props.Product_variables.Unbundled_build.Enabled = proptools.BoolPtr(false) |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 379 | props.Product_variables.Pdk.Enabled = proptools.BoolPtr(false) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 380 | |
| 381 | if module.SocSpecific() { |
| 382 | props.Soc_specific = proptools.BoolPtr(true) |
| 383 | } else if module.DeviceSpecific() { |
| 384 | props.Device_specific = proptools.BoolPtr(true) |
| 385 | } else if module.ProductSpecific() { |
| 386 | props.Product_specific = proptools.BoolPtr(true) |
| 387 | } |
| 388 | |
Colin Cross | 9ae1b92 | 2018-06-26 17:59:05 -0700 | [diff] [blame] | 389 | mctx.CreateModule(android.ModuleFactoryAdaptor(LibraryFactory), &props) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | // Creates a droiddoc module that creates stubs source files from the given full source |
| 393 | // files |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 394 | func (module *sdkLibrary) createDocs(mctx android.TopDownMutatorContext, apiScope apiScope) { |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 395 | props := struct { |
| 396 | Name *string |
| 397 | Srcs []string |
| 398 | Custom_template *string |
| 399 | Installable *bool |
| 400 | Srcs_lib *string |
| 401 | Srcs_lib_whitelist_dirs []string |
| 402 | Srcs_lib_whitelist_pkgs []string |
| 403 | Libs []string |
| 404 | Args *string |
| 405 | Api_tag_name *string |
| 406 | Api_filename *string |
| 407 | Removed_api_filename *string |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 408 | Check_api struct { |
| 409 | Current ApiToCheck |
| 410 | Last_released ApiToCheck |
| 411 | } |
Sundong Ahn | 1b92c82 | 2018-05-29 11:35:17 +0900 | [diff] [blame] | 412 | Aidl struct { |
| 413 | Include_dirs []string |
| 414 | Local_include_dirs []string |
| 415 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 416 | }{} |
| 417 | |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 418 | props.Name = proptools.StringPtr(module.docsName(apiScope)) |
Jiyong Park | baaf9dd | 2018-05-02 01:35:27 +0900 | [diff] [blame] | 419 | props.Srcs = append(props.Srcs, module.properties.Srcs...) |
| 420 | props.Srcs = append(props.Srcs, module.properties.Api_srcs...) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 421 | props.Custom_template = proptools.StringPtr("droiddoc-templates-sdk") |
| 422 | props.Installable = proptools.BoolPtr(false) |
Sundong Ahn | e6f0b05 | 2018-06-05 16:46:14 +0900 | [diff] [blame] | 423 | // A droiddoc module has only one Libs property and doesn't distinguish between |
| 424 | // shared libs and static libs. So we need to add both of these libs to Libs property. |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 425 | props.Libs = module.properties.Libs |
Sundong Ahn | e6f0b05 | 2018-06-05 16:46:14 +0900 | [diff] [blame] | 426 | props.Libs = append(props.Libs, module.properties.Static_libs...) |
Sundong Ahn | 1b92c82 | 2018-05-29 11:35:17 +0900 | [diff] [blame] | 427 | props.Aidl.Include_dirs = module.deviceProperties.Aidl.Include_dirs |
| 428 | props.Aidl.Local_include_dirs = module.deviceProperties.Aidl.Local_include_dirs |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 429 | |
| 430 | droiddocArgs := " -hide 110 -hide 111 -hide 113 -hide 121 -hide 125 -hide 126 -hide 127 -hide 128" + |
| 431 | " -stubpackages " + strings.Join(module.properties.Api_packages, ":") + |
Jiyong Park | 5a2c9d7 | 2018-05-01 22:25:41 +0900 | [diff] [blame] | 432 | " " + android.JoinWithPrefix(module.properties.Hidden_api_packages, "-hidePackage ") + |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 433 | " -nodocs" |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 434 | switch apiScope { |
| 435 | case apiScopeSystem: |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 436 | droiddocArgs = droiddocArgs + " -showAnnotation android.annotation.SystemApi" |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 437 | case apiScopeTest: |
| 438 | droiddocArgs = droiddocArgs + " -showAnnotation android.annotation.TestApi" |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 439 | } |
| 440 | props.Args = proptools.StringPtr(droiddocArgs) |
| 441 | |
| 442 | // List of APIs identified from the provided source files are created. They are later |
| 443 | // compared against to the not-yet-released (a.k.a current) list of APIs and to the |
| 444 | // last-released (a.k.a numbered) list of API. |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 445 | currentApiFileName := "current.txt" |
| 446 | removedApiFileName := "removed.txt" |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 447 | switch apiScope { |
| 448 | case apiScopeSystem: |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 449 | currentApiFileName = "system-" + currentApiFileName |
| 450 | removedApiFileName = "system-" + removedApiFileName |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 451 | case apiScopeTest: |
| 452 | currentApiFileName = "test-" + currentApiFileName |
| 453 | removedApiFileName = "test-" + removedApiFileName |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 454 | } |
| 455 | currentApiFileName = path.Join("api", currentApiFileName) |
| 456 | removedApiFileName = path.Join("api", removedApiFileName) |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 457 | // TODO(jiyong): remove these three props |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 458 | props.Api_tag_name = proptools.StringPtr(module.apiTagName(apiScope)) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 459 | props.Api_filename = proptools.StringPtr(currentApiFileName) |
| 460 | props.Removed_api_filename = proptools.StringPtr(removedApiFileName) |
| 461 | |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 462 | // check against the not-yet-release API |
| 463 | props.Check_api.Current.Api_file = proptools.StringPtr(currentApiFileName) |
| 464 | props.Check_api.Current.Removed_api_file = proptools.StringPtr(removedApiFileName) |
| 465 | // any change is reported as error |
| 466 | props.Check_api.Current.Args = proptools.StringPtr("-error 2 -error 3 -error 4 -error 5 " + |
| 467 | "-error 6 -error 7 -error 8 -error 9 -error 10 -error 11 -error 12 -error 13 " + |
| 468 | "-error 14 -error 15 -error 16 -error 17 -error 18 -error 19 -error 20 " + |
| 469 | "-error 21 -error 23 -error 24 -error 25 -error 26 -error 27") |
| 470 | |
| 471 | // check against the latest released API |
| 472 | props.Check_api.Last_released.Api_file = proptools.StringPtr( |
| 473 | module.latestApiFilegroupName(apiScope)) |
| 474 | props.Check_api.Last_released.Removed_api_file = proptools.StringPtr( |
| 475 | module.latestRemovedApiFilegroupName(apiScope)) |
| 476 | // backward incompatible changes are reported as error |
| 477 | props.Check_api.Last_released.Args = proptools.StringPtr("-hide 2 -hide 3 -hide 4 -hide 5 " + |
| 478 | "-hide 6 -hide 24 -hide 25 -hide 26 -hide 27 " + |
| 479 | "-error 7 -error 8 -error 9 -error 10 -error 11 -error 12 -error 13 -error 14 " + |
| 480 | "-error 15 -error 16 -error 17 -error 18") |
| 481 | |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 482 | // Include the part of the framework source. This is required for the case when |
| 483 | // API class is extending from the framework class. In that case, doclava needs |
| 484 | // to know whether the base class is hidden or not. Since that information is |
| 485 | // encoded as @hide string in the comment, we need source files for the classes, |
Jiyong Park | baaf9dd | 2018-05-02 01:35:27 +0900 | [diff] [blame] | 486 | // not the compiled ones. |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 487 | props.Srcs_lib = proptools.StringPtr("framework") |
| 488 | props.Srcs_lib_whitelist_dirs = []string{"core/java"} |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 489 | // Add android.annotation package to give access to the framework-defined |
| 490 | // annotations such as SystemApi, NonNull, etc. |
Jiyong Park | baaf9dd | 2018-05-02 01:35:27 +0900 | [diff] [blame] | 491 | props.Srcs_lib_whitelist_pkgs = []string{"android.annotation"} |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 492 | // These libs are required by doclava to parse the framework sources add via |
| 493 | // Src_lib and Src_lib_whitelist_* properties just above. |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 494 | // If we don't add them to the classpath, errors messages are generated by doclava, |
| 495 | // though they don't break the build. |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 496 | props.Libs = append(props.Libs, "conscrypt", "bouncycastle", "okhttp", "framework") |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 497 | |
| 498 | mctx.CreateModule(android.ModuleFactoryAdaptor(DroiddocFactory), &props) |
| 499 | } |
| 500 | |
| 501 | // Creates the runtime library. This is not directly linkable from other modules. |
| 502 | func (module *sdkLibrary) createImplLibrary(mctx android.TopDownMutatorContext) { |
| 503 | props := struct { |
| 504 | Name *string |
| 505 | Srcs []string |
| 506 | Libs []string |
| 507 | Static_libs []string |
| 508 | Soc_specific *bool |
| 509 | Device_specific *bool |
| 510 | Product_specific *bool |
Colin Cross | 9ae1b92 | 2018-06-26 17:59:05 -0700 | [diff] [blame] | 511 | Installable *bool |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 512 | Required []string |
Jiyong Park | b5b709f | 2018-06-15 10:38:59 +0900 | [diff] [blame] | 513 | Errorprone struct { |
| 514 | Javacflags []string |
| 515 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 516 | }{} |
| 517 | |
| 518 | props.Name = proptools.StringPtr(module.implName()) |
| 519 | props.Srcs = module.properties.Srcs |
| 520 | props.Libs = module.properties.Libs |
| 521 | props.Static_libs = module.properties.Static_libs |
Colin Cross | 9ae1b92 | 2018-06-26 17:59:05 -0700 | [diff] [blame] | 522 | props.Installable = proptools.BoolPtr(true) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 523 | // XML file is installed along with the impl lib |
| 524 | props.Required = []string{module.xmlFileName()} |
Jiyong Park | b5b709f | 2018-06-15 10:38:59 +0900 | [diff] [blame] | 525 | props.Errorprone.Javacflags = module.properties.Errorprone.Javacflags |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 526 | |
| 527 | if module.SocSpecific() { |
| 528 | props.Soc_specific = proptools.BoolPtr(true) |
| 529 | } else if module.DeviceSpecific() { |
| 530 | props.Device_specific = proptools.BoolPtr(true) |
| 531 | } else if module.ProductSpecific() { |
| 532 | props.Product_specific = proptools.BoolPtr(true) |
| 533 | } |
| 534 | |
Colin Cross | 9ae1b92 | 2018-06-26 17:59:05 -0700 | [diff] [blame] | 535 | mctx.CreateModule(android.ModuleFactoryAdaptor(LibraryFactory), &props, &module.deviceProperties) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 536 | } |
| 537 | |
| 538 | // Creates the xml file that publicizes the runtime library |
| 539 | func (module *sdkLibrary) createXmlFile(mctx android.TopDownMutatorContext) { |
| 540 | template := ` |
| 541 | <?xml version="1.0" encoding="utf-8"?> |
| 542 | <!-- Copyright (C) 2018 The Android Open Source Project |
| 543 | |
| 544 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 545 | you may not use this file except in compliance with the License. |
| 546 | You may obtain a copy of the License at |
| 547 | |
| 548 | http://www.apache.org/licenses/LICENSE-2.0 |
| 549 | |
| 550 | Unless required by applicable law or agreed to in writing, software |
| 551 | distributed under the License is distributed on an "AS IS" BASIS, |
| 552 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 553 | See the License for the specific language governing permissions and |
| 554 | limitations under the License. |
| 555 | --> |
| 556 | |
| 557 | <permissions> |
| 558 | <library name="%s" file="%s"/> |
| 559 | </permissions> |
| 560 | ` |
| 561 | // genrule to generate the xml file content from the template above |
| 562 | // TODO: preserve newlines in the generate xml file. Newlines are being squashed |
| 563 | // in the ninja file. Do we need to have an external tool for this? |
| 564 | xmlContent := fmt.Sprintf(template, module.BaseModuleName(), module.implPath()) |
| 565 | genruleProps := struct { |
| 566 | Name *string |
| 567 | Cmd *string |
| 568 | Out []string |
| 569 | }{} |
| 570 | genruleProps.Name = proptools.StringPtr(module.xmlFileName() + "-gen") |
| 571 | genruleProps.Cmd = proptools.StringPtr("echo '" + xmlContent + "' > $(out)") |
| 572 | genruleProps.Out = []string{module.xmlFileName()} |
| 573 | mctx.CreateModule(android.ModuleFactoryAdaptor(genrule.GenRuleFactory), &genruleProps) |
| 574 | |
| 575 | // creates a prebuilt_etc module to actually place the xml file under |
| 576 | // <partition>/etc/permissions |
| 577 | etcProps := struct { |
| 578 | Name *string |
Jiyong Park | 5a8d1be | 2018-04-25 22:57:34 +0900 | [diff] [blame] | 579 | Src *string |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 580 | Sub_dir *string |
| 581 | Soc_specific *bool |
| 582 | Device_specific *bool |
| 583 | Product_specific *bool |
| 584 | }{} |
| 585 | etcProps.Name = proptools.StringPtr(module.xmlFileName()) |
Jiyong Park | 5a8d1be | 2018-04-25 22:57:34 +0900 | [diff] [blame] | 586 | etcProps.Src = proptools.StringPtr(":" + module.xmlFileName() + "-gen") |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 587 | etcProps.Sub_dir = proptools.StringPtr("permissions") |
| 588 | if module.SocSpecific() { |
| 589 | etcProps.Soc_specific = proptools.BoolPtr(true) |
| 590 | } else if module.DeviceSpecific() { |
| 591 | etcProps.Device_specific = proptools.BoolPtr(true) |
| 592 | } else if module.ProductSpecific() { |
| 593 | etcProps.Product_specific = proptools.BoolPtr(true) |
| 594 | } |
| 595 | mctx.CreateModule(android.ModuleFactoryAdaptor(android.PrebuiltEtcFactory), &etcProps) |
| 596 | } |
| 597 | |
| 598 | // to satisfy SdkLibraryDependency interface |
| 599 | func (module *sdkLibrary) HeaderJars(linkType linkType) android.Paths { |
| 600 | // This module is just a wrapper for the stubs. |
Sundong Ahn | 57368eb | 2018-07-06 11:20:23 +0900 | [diff] [blame] | 601 | if linkType == javaSystem { |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 602 | return module.systemApiStubsPath |
Sundong Ahn | 57368eb | 2018-07-06 11:20:23 +0900 | [diff] [blame] | 603 | } else if linkType == javaPlatform { |
| 604 | return module.implLibPath |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 605 | } else { |
| 606 | return module.publicApiStubsPath |
| 607 | } |
| 608 | } |
| 609 | |
Sundong Ahn | 241cd37 | 2018-07-13 16:16:44 +0900 | [diff] [blame] | 610 | // to satisfy SdkLibraryDependency interface |
| 611 | func (module *sdkLibrary) ImplementationJars(linkType linkType) android.Paths { |
| 612 | // This module is just a wrapper for the stubs. |
| 613 | if linkType == javaSystem { |
| 614 | return module.systemApiStubsImplPath |
| 615 | } else if linkType == javaPlatform { |
| 616 | return module.implLibImplPath |
| 617 | } else { |
| 618 | return module.publicApiStubsImplPath |
| 619 | } |
| 620 | } |
| 621 | |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 622 | func javaSdkLibraries(config android.Config) *[]string { |
| 623 | return config.Once("javaSdkLibraries", func() interface{} { |
| 624 | return &[]string{} |
| 625 | }).(*[]string) |
| 626 | } |
| 627 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 628 | // For a java_sdk_library module, create internal modules for stubs, docs, |
| 629 | // runtime libs and xml file. If requested, the stubs and docs are created twice |
| 630 | // once for public API level and once for system API level |
| 631 | func sdkLibraryMutator(mctx android.TopDownMutatorContext) { |
| 632 | if module, ok := mctx.Module().(*sdkLibrary); ok { |
Anton Hansson | 8959e14 | 2018-04-25 11:56:13 +0100 | [diff] [blame] | 633 | if module.properties.Srcs == nil { |
| 634 | mctx.PropertyErrorf("srcs", "java_sdk_library must specify srcs") |
| 635 | } |
| 636 | if module.properties.Api_packages == nil { |
| 637 | mctx.PropertyErrorf("api_packages", "java_sdk_library must specify api_packages") |
| 638 | } |
| 639 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 640 | // for public API stubs |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 641 | module.createStubsLibrary(mctx, apiScopePublic) |
| 642 | module.createDocs(mctx, apiScopePublic) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 643 | |
| 644 | // for system API stubs |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 645 | module.createStubsLibrary(mctx, apiScopeSystem) |
| 646 | module.createDocs(mctx, apiScopeSystem) |
| 647 | |
| 648 | // for test API stubs |
| 649 | module.createStubsLibrary(mctx, apiScopeTest) |
| 650 | module.createDocs(mctx, apiScopeTest) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 651 | |
| 652 | // for runtime |
| 653 | module.createXmlFile(mctx) |
| 654 | module.createImplLibrary(mctx) |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 655 | |
| 656 | // record java_sdk_library modules so that they are exported to make |
| 657 | javaSdkLibraries := javaSdkLibraries(mctx.Config()) |
| 658 | javaSdkLibrariesLock.Lock() |
| 659 | defer javaSdkLibrariesLock.Unlock() |
| 660 | *javaSdkLibraries = append(*javaSdkLibraries, module.BaseModuleName()) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 661 | } |
| 662 | } |
| 663 | |
| 664 | func sdkLibraryFactory() android.Module { |
| 665 | module := &sdkLibrary{} |
| 666 | module.AddProperties(&module.properties) |
Jiyong Park | 441a47d | 2018-05-01 23:33:08 +0900 | [diff] [blame] | 667 | module.AddProperties(&module.deviceProperties) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 668 | android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibCommon) |
| 669 | android.InitDefaultableModule(module) |
| 670 | return module |
| 671 | } |