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 | |
Sundong Ahn | dd567f9 | 2018-07-31 17:19:11 +0900 | [diff] [blame] | 120 | // Additional droiddoc options |
| 121 | Droiddoc_options []string |
| 122 | |
| 123 | // If set to true, compile dex regardless of installable. Defaults to false. |
| 124 | // This applies to the stubs lib. |
| 125 | Compile_dex *bool |
| 126 | |
| 127 | // the sub dirs under srcs_lib_whitelist_dirs will be scanned for java srcs. |
| 128 | // Defaults to "android.annotation". |
| 129 | Srcs_lib_whitelist_pkgs []string |
| 130 | |
Sundong Ahn | fb2721f | 2018-09-17 13:23:09 +0900 | [diff] [blame] | 131 | // if set to true, create stubs through Metalava instead of Doclava. Javadoc/Doclava is |
| 132 | // currently still used for documentation generation, and will be replaced by Dokka soon. |
| 133 | // Defaults to true. |
| 134 | Metalava_enabled *bool |
| 135 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 136 | // TODO: determines whether to create HTML doc or not |
| 137 | //Html_doc *bool |
| 138 | } |
| 139 | |
| 140 | type sdkLibrary struct { |
| 141 | android.ModuleBase |
| 142 | android.DefaultableModuleBase |
| 143 | |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 144 | properties sdkLibraryProperties |
| 145 | deviceProperties CompilerDeviceProperties |
| 146 | dexpreoptProperties DexpreoptProperties |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 147 | |
| 148 | publicApiStubsPath android.Paths |
| 149 | systemApiStubsPath android.Paths |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 150 | testApiStubsPath android.Paths |
Sundong Ahn | 57368eb | 2018-07-06 11:20:23 +0900 | [diff] [blame] | 151 | implLibPath android.Paths |
Sundong Ahn | 241cd37 | 2018-07-13 16:16:44 +0900 | [diff] [blame] | 152 | |
| 153 | publicApiStubsImplPath android.Paths |
| 154 | systemApiStubsImplPath android.Paths |
| 155 | testApiStubsImplPath android.Paths |
| 156 | implLibImplPath android.Paths |
Sundong Ahn | 20e998b | 2018-07-24 11:19:26 +0900 | [diff] [blame] | 157 | |
| 158 | publicApiFilePath android.Path |
| 159 | systemApiFilePath android.Path |
| 160 | testApiFilePath android.Path |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | func (module *sdkLibrary) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 164 | // Add dependencies to the stubs library |
Colin Cross | 42d48b7 | 2018-08-29 14:10:52 -0700 | [diff] [blame] | 165 | ctx.AddVariationDependencies(nil, publicApiStubsTag, module.stubsName(apiScopePublic)) |
| 166 | ctx.AddVariationDependencies(nil, systemApiStubsTag, module.stubsName(apiScopeSystem)) |
| 167 | ctx.AddVariationDependencies(nil, testApiStubsTag, module.stubsName(apiScopeTest)) |
| 168 | ctx.AddVariationDependencies(nil, implLibTag, module.implName()) |
Sundong Ahn | 20e998b | 2018-07-24 11:19:26 +0900 | [diff] [blame] | 169 | |
Colin Cross | 42d48b7 | 2018-08-29 14:10:52 -0700 | [diff] [blame] | 170 | ctx.AddVariationDependencies(nil, publicApiFileTag, module.docsName(apiScopePublic)) |
| 171 | ctx.AddVariationDependencies(nil, systemApiFileTag, module.docsName(apiScopeSystem)) |
| 172 | ctx.AddVariationDependencies(nil, testApiFileTag, module.docsName(apiScopeTest)) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | func (module *sdkLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
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() |
Sundong Ahn | 57368eb | 2018-07-06 11:20:23 +0900 | [diff] [blame] | 194 | case implLibTag: |
| 195 | module.implLibPath = lib.HeaderJars() |
Sundong Ahn | 241cd37 | 2018-07-13 16:16:44 +0900 | [diff] [blame] | 196 | module.implLibImplPath = lib.ImplementationJars() |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 197 | default: |
| 198 | ctx.ModuleErrorf("depends on module %q of unknown tag %q", otherName, tag) |
| 199 | } |
| 200 | } |
Sundong Ahn | 20e998b | 2018-07-24 11:19:26 +0900 | [diff] [blame] | 201 | if doc, ok := to.(ApiFilePath); ok { |
| 202 | switch tag { |
| 203 | case publicApiFileTag: |
| 204 | module.publicApiFilePath = doc.ApiFilePath() |
| 205 | case systemApiFileTag: |
| 206 | module.systemApiFilePath = doc.ApiFilePath() |
| 207 | case testApiFileTag: |
| 208 | module.testApiFilePath = doc.ApiFilePath() |
| 209 | default: |
| 210 | ctx.ModuleErrorf("depends on module %q of unknown tag %q", otherName, tag) |
| 211 | } |
| 212 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 213 | }) |
| 214 | } |
| 215 | |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 216 | func (module *sdkLibrary) AndroidMk() android.AndroidMkData { |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 217 | return android.AndroidMkData{ |
| 218 | Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) { |
Jiyong Park | 9007838 | 2018-05-02 19:30:15 +0900 | [diff] [blame] | 219 | // Create a phony module that installs the impl library, for the case when this lib is |
| 220 | // in PRODUCT_PACKAGES. |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 221 | fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)") |
| 222 | fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir) |
| 223 | fmt.Fprintln(w, "LOCAL_MODULE :=", name) |
| 224 | fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES := "+module.implName()) |
| 225 | fmt.Fprintln(w, "include $(BUILD_PHONY_PACKAGE)") |
Sundong Ahn | 4fd04bb | 2018-08-31 18:01:37 +0900 | [diff] [blame] | 226 | owner := module.ModuleBase.Owner() |
| 227 | if owner == "" { |
| 228 | owner = "android" |
| 229 | } |
Jiyong Park | 9007838 | 2018-05-02 19:30:15 +0900 | [diff] [blame] | 230 | // Create dist rules to install the stubs libs to the dist dir |
Jiyong Park | b674a52 | 2018-05-06 07:53:02 +0900 | [diff] [blame] | 231 | if len(module.publicApiStubsPath) == 1 { |
| 232 | fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+ |
Colin Cross | ac50272 | 2018-11-21 20:33:56 -0800 | [diff] [blame] | 233 | module.publicApiStubsImplPath.Strings()[0]+ |
Sundong Ahn | 4fd04bb | 2018-08-31 18:01:37 +0900 | [diff] [blame] | 234 | ":"+path.Join("apistubs", owner, "public", |
| 235 | module.BaseModuleName()+".jar")+")") |
Jiyong Park | b674a52 | 2018-05-06 07:53:02 +0900 | [diff] [blame] | 236 | } |
| 237 | if len(module.systemApiStubsPath) == 1 { |
| 238 | fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+ |
Colin Cross | ac50272 | 2018-11-21 20:33:56 -0800 | [diff] [blame] | 239 | module.systemApiStubsImplPath.Strings()[0]+ |
Sundong Ahn | 4fd04bb | 2018-08-31 18:01:37 +0900 | [diff] [blame] | 240 | ":"+path.Join("apistubs", owner, "system", |
| 241 | module.BaseModuleName()+".jar")+")") |
Jiyong Park | b674a52 | 2018-05-06 07:53:02 +0900 | [diff] [blame] | 242 | } |
| 243 | if len(module.testApiStubsPath) == 1 { |
| 244 | fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+ |
Colin Cross | ac50272 | 2018-11-21 20:33:56 -0800 | [diff] [blame] | 245 | module.testApiStubsImplPath.Strings()[0]+ |
Sundong Ahn | 4fd04bb | 2018-08-31 18:01:37 +0900 | [diff] [blame] | 246 | ":"+path.Join("apistubs", owner, "test", |
| 247 | module.BaseModuleName()+".jar")+")") |
Jiyong Park | b674a52 | 2018-05-06 07:53:02 +0900 | [diff] [blame] | 248 | } |
Sundong Ahn | 20e998b | 2018-07-24 11:19:26 +0900 | [diff] [blame] | 249 | if module.publicApiFilePath != nil { |
| 250 | fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+ |
| 251 | module.publicApiFilePath.String()+ |
Sundong Ahn | 4fd04bb | 2018-08-31 18:01:37 +0900 | [diff] [blame] | 252 | ":"+path.Join("apistubs", owner, "public", "api", |
Sundong Ahn | 20e998b | 2018-07-24 11:19:26 +0900 | [diff] [blame] | 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()+ |
Sundong Ahn | 4fd04bb | 2018-08-31 18:01:37 +0900 | [diff] [blame] | 258 | ":"+path.Join("apistubs", owner, "system", "api", |
Sundong Ahn | 20e998b | 2018-07-24 11:19:26 +0900 | [diff] [blame] | 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()+ |
Sundong Ahn | 4fd04bb | 2018-08-31 18:01:37 +0900 | [diff] [blame] | 264 | ":"+path.Join("apistubs", owner, "test", "api", |
Sundong Ahn | 20e998b | 2018-07-24 11:19:26 +0900 | [diff] [blame] | 265 | module.BaseModuleName()+".txt")+")") |
| 266 | } |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 267 | }, |
| 268 | } |
| 269 | } |
| 270 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 271 | // Module name of the stubs library |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 272 | func (module *sdkLibrary) stubsName(apiScope apiScope) string { |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 273 | stubsName := module.BaseModuleName() + sdkStubsLibrarySuffix |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 274 | switch apiScope { |
| 275 | case apiScopeSystem: |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 276 | stubsName = stubsName + sdkSystemApiSuffix |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 277 | case apiScopeTest: |
| 278 | stubsName = stubsName + sdkTestApiSuffix |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 279 | } |
| 280 | return stubsName |
| 281 | } |
| 282 | |
| 283 | // Module name of the docs |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 284 | func (module *sdkLibrary) docsName(apiScope apiScope) string { |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 285 | docsName := module.BaseModuleName() + sdkDocsSuffix |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 286 | switch apiScope { |
| 287 | case apiScopeSystem: |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 288 | docsName = docsName + sdkSystemApiSuffix |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 289 | case apiScopeTest: |
| 290 | docsName = docsName + sdkTestApiSuffix |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 291 | } |
| 292 | return docsName |
| 293 | } |
| 294 | |
| 295 | // Module name of the runtime implementation library |
| 296 | func (module *sdkLibrary) implName() string { |
| 297 | return module.BaseModuleName() + sdkImplLibrarySuffix |
| 298 | } |
| 299 | |
| 300 | // File path to the runtime implementation library |
| 301 | func (module *sdkLibrary) implPath() string { |
| 302 | partition := "system" |
| 303 | if module.SocSpecific() { |
| 304 | partition = "vendor" |
| 305 | } else if module.DeviceSpecific() { |
| 306 | partition = "odm" |
| 307 | } else if module.ProductSpecific() { |
| 308 | partition = "product" |
| 309 | } |
| 310 | return "/" + partition + "/framework/" + module.implName() + ".jar" |
| 311 | } |
| 312 | |
| 313 | // Module name of the XML file for the lib |
| 314 | func (module *sdkLibrary) xmlFileName() string { |
| 315 | return module.BaseModuleName() + sdkXmlFileSuffix |
| 316 | } |
| 317 | |
| 318 | // SDK version that the stubs library is built against. Note that this is always |
| 319 | // *current. Older stubs library built with a numberd SDK version is created from |
| 320 | // the prebuilt jar. |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 321 | func (module *sdkLibrary) sdkVersion(apiScope apiScope) string { |
| 322 | switch apiScope { |
| 323 | case apiScopePublic: |
| 324 | return "current" |
| 325 | case apiScopeSystem: |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 326 | return "system_current" |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 327 | case apiScopeTest: |
| 328 | return "test_current" |
| 329 | default: |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 330 | return "current" |
| 331 | } |
| 332 | } |
| 333 | |
| 334 | // $(INTERNAL_PLATFORM_<apiTagName>_API_FILE) points to the generated |
| 335 | // api file for the current source |
| 336 | // TODO: remove this when apicheck is done in soong |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 337 | func (module *sdkLibrary) apiTagName(apiScope apiScope) string { |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 338 | apiTagName := strings.Replace(strings.ToUpper(module.BaseModuleName()), ".", "_", -1) |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 339 | switch apiScope { |
| 340 | case apiScopeSystem: |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 341 | apiTagName = apiTagName + "_SYSTEM" |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 342 | case apiScopeTest: |
| 343 | apiTagName = apiTagName + "_TEST" |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 344 | } |
| 345 | return apiTagName |
| 346 | } |
| 347 | |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 348 | func (module *sdkLibrary) latestApiFilegroupName(apiScope apiScope) string { |
| 349 | name := ":" + module.BaseModuleName() + ".api." |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 350 | switch apiScope { |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 351 | case apiScopePublic: |
| 352 | name = name + "public" |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 353 | case apiScopeSystem: |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 354 | name = name + "system" |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 355 | case apiScopeTest: |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 356 | name = name + "test" |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 357 | } |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 358 | name = name + ".latest" |
| 359 | return name |
| 360 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 361 | |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 362 | func (module *sdkLibrary) latestRemovedApiFilegroupName(apiScope apiScope) string { |
| 363 | name := ":" + module.BaseModuleName() + "-removed.api." |
| 364 | switch apiScope { |
| 365 | case apiScopePublic: |
| 366 | name = name + "public" |
| 367 | case apiScopeSystem: |
| 368 | name = name + "system" |
| 369 | case apiScopeTest: |
| 370 | name = name + "test" |
| 371 | } |
| 372 | name = name + ".latest" |
| 373 | return name |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | // Creates a static java library that has API stubs |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 377 | func (module *sdkLibrary) createStubsLibrary(mctx android.TopDownMutatorContext, apiScope apiScope) { |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 378 | props := struct { |
| 379 | Name *string |
| 380 | Srcs []string |
| 381 | Sdk_version *string |
Sundong Ahn | f043cf6 | 2018-06-25 16:04:37 +0900 | [diff] [blame] | 382 | Libs []string |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 383 | Soc_specific *bool |
| 384 | Device_specific *bool |
| 385 | Product_specific *bool |
Sundong Ahn | dd567f9 | 2018-07-31 17:19:11 +0900 | [diff] [blame] | 386 | Compile_dex *bool |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 387 | Product_variables struct { |
| 388 | Unbundled_build struct { |
| 389 | Enabled *bool |
| 390 | } |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 391 | Pdk struct { |
| 392 | Enabled *bool |
| 393 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 394 | } |
| 395 | }{} |
| 396 | |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 397 | props.Name = proptools.StringPtr(module.stubsName(apiScope)) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 398 | // sources are generated from the droiddoc |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 399 | props.Srcs = []string{":" + module.docsName(apiScope)} |
| 400 | props.Sdk_version = proptools.StringPtr(module.sdkVersion(apiScope)) |
Sundong Ahn | f043cf6 | 2018-06-25 16:04:37 +0900 | [diff] [blame] | 401 | props.Libs = module.properties.Stub_only_libs |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 402 | // Unbundled apps will use the prebult one from /prebuilts/sdk |
| 403 | props.Product_variables.Unbundled_build.Enabled = proptools.BoolPtr(false) |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 404 | props.Product_variables.Pdk.Enabled = proptools.BoolPtr(false) |
Sundong Ahn | dd567f9 | 2018-07-31 17:19:11 +0900 | [diff] [blame] | 405 | if module.properties.Compile_dex != nil { |
| 406 | props.Compile_dex = module.properties.Compile_dex |
| 407 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 408 | |
| 409 | if module.SocSpecific() { |
| 410 | props.Soc_specific = proptools.BoolPtr(true) |
| 411 | } else if module.DeviceSpecific() { |
| 412 | props.Device_specific = proptools.BoolPtr(true) |
| 413 | } else if module.ProductSpecific() { |
| 414 | props.Product_specific = proptools.BoolPtr(true) |
| 415 | } |
| 416 | |
Colin Cross | 9ae1b92 | 2018-06-26 17:59:05 -0700 | [diff] [blame] | 417 | mctx.CreateModule(android.ModuleFactoryAdaptor(LibraryFactory), &props) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 418 | } |
| 419 | |
| 420 | // Creates a droiddoc module that creates stubs source files from the given full source |
| 421 | // files |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 422 | func (module *sdkLibrary) createDocs(mctx android.TopDownMutatorContext, apiScope apiScope) { |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 423 | props := struct { |
| 424 | Name *string |
| 425 | Srcs []string |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 426 | Installable *bool |
| 427 | Srcs_lib *string |
| 428 | Srcs_lib_whitelist_dirs []string |
| 429 | Srcs_lib_whitelist_pkgs []string |
| 430 | Libs []string |
| 431 | Args *string |
| 432 | Api_tag_name *string |
| 433 | Api_filename *string |
| 434 | Removed_api_filename *string |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 435 | Check_api struct { |
| 436 | Current ApiToCheck |
| 437 | Last_released ApiToCheck |
| 438 | } |
Sundong Ahn | 1b92c82 | 2018-05-29 11:35:17 +0900 | [diff] [blame] | 439 | Aidl struct { |
| 440 | Include_dirs []string |
| 441 | Local_include_dirs []string |
| 442 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 443 | }{} |
Sundong Ahn | fb2721f | 2018-09-17 13:23:09 +0900 | [diff] [blame] | 444 | droiddocProps := struct { |
| 445 | Custom_template *string |
| 446 | }{} |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 447 | |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 448 | props.Name = proptools.StringPtr(module.docsName(apiScope)) |
Jiyong Park | baaf9dd | 2018-05-02 01:35:27 +0900 | [diff] [blame] | 449 | props.Srcs = append(props.Srcs, module.properties.Srcs...) |
| 450 | props.Srcs = append(props.Srcs, module.properties.Api_srcs...) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 451 | props.Installable = proptools.BoolPtr(false) |
Sundong Ahn | e6f0b05 | 2018-06-05 16:46:14 +0900 | [diff] [blame] | 452 | // A droiddoc module has only one Libs property and doesn't distinguish between |
| 453 | // 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] | 454 | props.Libs = module.properties.Libs |
Sundong Ahn | e6f0b05 | 2018-06-05 16:46:14 +0900 | [diff] [blame] | 455 | props.Libs = append(props.Libs, module.properties.Static_libs...) |
Sundong Ahn | 1b92c82 | 2018-05-29 11:35:17 +0900 | [diff] [blame] | 456 | props.Aidl.Include_dirs = module.deviceProperties.Aidl.Include_dirs |
| 457 | props.Aidl.Local_include_dirs = module.deviceProperties.Aidl.Local_include_dirs |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 458 | |
Sundong Ahn | fb2721f | 2018-09-17 13:23:09 +0900 | [diff] [blame] | 459 | if module.properties.Metalava_enabled == nil { |
| 460 | module.properties.Metalava_enabled = proptools.BoolPtr(true) |
| 461 | } |
| 462 | |
| 463 | droiddocArgs := "" |
| 464 | if Bool(module.properties.Metalava_enabled) == true { |
| 465 | droiddocArgs = " --stub-packages " + strings.Join(module.properties.Api_packages, ":") + |
| 466 | " " + android.JoinWithPrefix(module.properties.Hidden_api_packages, " --hide-package ") + |
| 467 | " " + android.JoinWithPrefix(module.properties.Droiddoc_options, " ") + |
| 468 | " --hide MissingPermission --hide BroadcastBehavior " + |
| 469 | "--hide HiddenSuperclass --hide DeprecationMismatch --hide UnavailableSymbol " + |
| 470 | "--hide SdkConstant --hide HiddenTypeParameter --hide Todo --hide Typo" |
| 471 | } else { |
| 472 | droiddocProps.Custom_template = proptools.StringPtr("droiddoc-templates-sdk") |
| 473 | droiddocArgs = " -stubpackages " + strings.Join(module.properties.Api_packages, ":") + |
| 474 | " " + android.JoinWithPrefix(module.properties.Hidden_api_packages, " -hidePackage ") + |
| 475 | " " + android.JoinWithPrefix(module.properties.Droiddoc_options, " ") + |
| 476 | " -hide 110 -hide 111 -hide 113 -hide 121 -hide 125 -hide 126 -hide 127 -hide 128 -nodocs" |
| 477 | } |
| 478 | |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 479 | switch apiScope { |
| 480 | case apiScopeSystem: |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 481 | droiddocArgs = droiddocArgs + " -showAnnotation android.annotation.SystemApi" |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 482 | case apiScopeTest: |
| 483 | droiddocArgs = droiddocArgs + " -showAnnotation android.annotation.TestApi" |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 484 | } |
| 485 | props.Args = proptools.StringPtr(droiddocArgs) |
| 486 | |
| 487 | // List of APIs identified from the provided source files are created. They are later |
| 488 | // compared against to the not-yet-released (a.k.a current) list of APIs and to the |
| 489 | // last-released (a.k.a numbered) list of API. |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 490 | currentApiFileName := "current.txt" |
| 491 | removedApiFileName := "removed.txt" |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 492 | switch apiScope { |
| 493 | case apiScopeSystem: |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 494 | currentApiFileName = "system-" + currentApiFileName |
| 495 | removedApiFileName = "system-" + removedApiFileName |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 496 | case apiScopeTest: |
| 497 | currentApiFileName = "test-" + currentApiFileName |
| 498 | removedApiFileName = "test-" + removedApiFileName |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 499 | } |
| 500 | currentApiFileName = path.Join("api", currentApiFileName) |
| 501 | removedApiFileName = path.Join("api", removedApiFileName) |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 502 | // TODO(jiyong): remove these three props |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 503 | props.Api_tag_name = proptools.StringPtr(module.apiTagName(apiScope)) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 504 | props.Api_filename = proptools.StringPtr(currentApiFileName) |
| 505 | props.Removed_api_filename = proptools.StringPtr(removedApiFileName) |
| 506 | |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 507 | // check against the not-yet-release API |
| 508 | props.Check_api.Current.Api_file = proptools.StringPtr(currentApiFileName) |
| 509 | props.Check_api.Current.Removed_api_file = proptools.StringPtr(removedApiFileName) |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 510 | |
| 511 | // check against the latest released API |
| 512 | props.Check_api.Last_released.Api_file = proptools.StringPtr( |
| 513 | module.latestApiFilegroupName(apiScope)) |
| 514 | props.Check_api.Last_released.Removed_api_file = proptools.StringPtr( |
| 515 | module.latestRemovedApiFilegroupName(apiScope)) |
Sundong Ahn | fb2721f | 2018-09-17 13:23:09 +0900 | [diff] [blame] | 516 | if Bool(module.properties.Metalava_enabled) == false { |
| 517 | // any change is reported as error |
| 518 | props.Check_api.Current.Args = proptools.StringPtr("-error 2 -error 3 -error 4 -error 5 " + |
| 519 | "-error 6 -error 7 -error 8 -error 9 -error 10 -error 11 -error 12 -error 13 " + |
| 520 | "-error 14 -error 15 -error 16 -error 17 -error 18 -error 19 -error 20 " + |
| 521 | "-error 21 -error 23 -error 24 -error 25 -error 26 -error 27") |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 522 | |
Sundong Ahn | fb2721f | 2018-09-17 13:23:09 +0900 | [diff] [blame] | 523 | // backward incompatible changes are reported as error |
| 524 | props.Check_api.Last_released.Args = proptools.StringPtr("-hide 2 -hide 3 -hide 4 -hide 5 " + |
| 525 | "-hide 6 -hide 24 -hide 25 -hide 26 -hide 27 " + |
| 526 | "-error 7 -error 8 -error 9 -error 10 -error 11 -error 12 -error 13 -error 14 " + |
| 527 | "-error 15 -error 16 -error 17 -error 18") |
| 528 | |
| 529 | // Include the part of the framework source. This is required for the case when |
| 530 | // API class is extending from the framework class. In that case, doclava needs |
| 531 | // to know whether the base class is hidden or not. Since that information is |
| 532 | // encoded as @hide string in the comment, we need source files for the classes, |
| 533 | // not the compiled ones. |
| 534 | props.Srcs_lib = proptools.StringPtr("framework") |
| 535 | props.Srcs_lib_whitelist_dirs = []string{"core/java"} |
| 536 | |
| 537 | // Add android.annotation package to give access to the framework-defined |
| 538 | // annotations such as SystemApi, NonNull, etc. |
| 539 | if module.properties.Srcs_lib_whitelist_pkgs != nil { |
| 540 | props.Srcs_lib_whitelist_pkgs = module.properties.Srcs_lib_whitelist_pkgs |
| 541 | } else { |
| 542 | props.Srcs_lib_whitelist_pkgs = []string{"android.annotation"} |
| 543 | } |
Sundong Ahn | dd567f9 | 2018-07-31 17:19:11 +0900 | [diff] [blame] | 544 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 545 | |
Sundong Ahn | fb2721f | 2018-09-17 13:23:09 +0900 | [diff] [blame] | 546 | if Bool(module.properties.Metalava_enabled) == true { |
| 547 | mctx.CreateModule(android.ModuleFactoryAdaptor(DroidstubsFactory), &props) |
| 548 | } else { |
| 549 | mctx.CreateModule(android.ModuleFactoryAdaptor(DroiddocFactory), &props, &droiddocProps) |
| 550 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 551 | } |
| 552 | |
| 553 | // Creates the runtime library. This is not directly linkable from other modules. |
| 554 | func (module *sdkLibrary) createImplLibrary(mctx android.TopDownMutatorContext) { |
| 555 | props := struct { |
| 556 | Name *string |
| 557 | Srcs []string |
| 558 | Libs []string |
| 559 | Static_libs []string |
| 560 | Soc_specific *bool |
| 561 | Device_specific *bool |
| 562 | Product_specific *bool |
Colin Cross | 9ae1b92 | 2018-06-26 17:59:05 -0700 | [diff] [blame] | 563 | Installable *bool |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 564 | Required []string |
Jiyong Park | b5b709f | 2018-06-15 10:38:59 +0900 | [diff] [blame] | 565 | Errorprone struct { |
| 566 | Javacflags []string |
| 567 | } |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 568 | IsSDKLibrary bool |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 569 | }{} |
| 570 | |
| 571 | props.Name = proptools.StringPtr(module.implName()) |
| 572 | props.Srcs = module.properties.Srcs |
| 573 | props.Libs = module.properties.Libs |
| 574 | props.Static_libs = module.properties.Static_libs |
Colin Cross | 9ae1b92 | 2018-06-26 17:59:05 -0700 | [diff] [blame] | 575 | props.Installable = proptools.BoolPtr(true) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 576 | // XML file is installed along with the impl lib |
| 577 | props.Required = []string{module.xmlFileName()} |
Jiyong Park | b5b709f | 2018-06-15 10:38:59 +0900 | [diff] [blame] | 578 | props.Errorprone.Javacflags = module.properties.Errorprone.Javacflags |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 579 | props.IsSDKLibrary = true |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 580 | |
| 581 | if module.SocSpecific() { |
| 582 | props.Soc_specific = proptools.BoolPtr(true) |
| 583 | } else if module.DeviceSpecific() { |
| 584 | props.Device_specific = proptools.BoolPtr(true) |
| 585 | } else if module.ProductSpecific() { |
| 586 | props.Product_specific = proptools.BoolPtr(true) |
| 587 | } |
| 588 | |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 589 | mctx.CreateModule(android.ModuleFactoryAdaptor(LibraryFactory), |
| 590 | &props, |
| 591 | &module.deviceProperties, |
| 592 | &module.dexpreoptProperties) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 593 | } |
| 594 | |
| 595 | // Creates the xml file that publicizes the runtime library |
| 596 | func (module *sdkLibrary) createXmlFile(mctx android.TopDownMutatorContext) { |
| 597 | template := ` |
| 598 | <?xml version="1.0" encoding="utf-8"?> |
| 599 | <!-- Copyright (C) 2018 The Android Open Source Project |
| 600 | |
| 601 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 602 | you may not use this file except in compliance with the License. |
| 603 | You may obtain a copy of the License at |
| 604 | |
| 605 | http://www.apache.org/licenses/LICENSE-2.0 |
| 606 | |
| 607 | Unless required by applicable law or agreed to in writing, software |
| 608 | distributed under the License is distributed on an "AS IS" BASIS, |
| 609 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 610 | See the License for the specific language governing permissions and |
| 611 | limitations under the License. |
| 612 | --> |
| 613 | |
| 614 | <permissions> |
| 615 | <library name="%s" file="%s"/> |
| 616 | </permissions> |
| 617 | ` |
| 618 | // genrule to generate the xml file content from the template above |
| 619 | // TODO: preserve newlines in the generate xml file. Newlines are being squashed |
| 620 | // in the ninja file. Do we need to have an external tool for this? |
| 621 | xmlContent := fmt.Sprintf(template, module.BaseModuleName(), module.implPath()) |
| 622 | genruleProps := struct { |
| 623 | Name *string |
| 624 | Cmd *string |
| 625 | Out []string |
| 626 | }{} |
| 627 | genruleProps.Name = proptools.StringPtr(module.xmlFileName() + "-gen") |
| 628 | genruleProps.Cmd = proptools.StringPtr("echo '" + xmlContent + "' > $(out)") |
| 629 | genruleProps.Out = []string{module.xmlFileName()} |
| 630 | mctx.CreateModule(android.ModuleFactoryAdaptor(genrule.GenRuleFactory), &genruleProps) |
| 631 | |
| 632 | // creates a prebuilt_etc module to actually place the xml file under |
| 633 | // <partition>/etc/permissions |
| 634 | etcProps := struct { |
| 635 | Name *string |
Jiyong Park | 5a8d1be | 2018-04-25 22:57:34 +0900 | [diff] [blame] | 636 | Src *string |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 637 | Sub_dir *string |
| 638 | Soc_specific *bool |
| 639 | Device_specific *bool |
| 640 | Product_specific *bool |
| 641 | }{} |
| 642 | etcProps.Name = proptools.StringPtr(module.xmlFileName()) |
Jiyong Park | 5a8d1be | 2018-04-25 22:57:34 +0900 | [diff] [blame] | 643 | etcProps.Src = proptools.StringPtr(":" + module.xmlFileName() + "-gen") |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 644 | etcProps.Sub_dir = proptools.StringPtr("permissions") |
| 645 | if module.SocSpecific() { |
| 646 | etcProps.Soc_specific = proptools.BoolPtr(true) |
| 647 | } else if module.DeviceSpecific() { |
| 648 | etcProps.Device_specific = proptools.BoolPtr(true) |
| 649 | } else if module.ProductSpecific() { |
| 650 | etcProps.Product_specific = proptools.BoolPtr(true) |
| 651 | } |
| 652 | mctx.CreateModule(android.ModuleFactoryAdaptor(android.PrebuiltEtcFactory), &etcProps) |
| 653 | } |
| 654 | |
| 655 | // to satisfy SdkLibraryDependency interface |
| 656 | func (module *sdkLibrary) HeaderJars(linkType linkType) android.Paths { |
| 657 | // This module is just a wrapper for the stubs. |
Sundong Ahn | 57368eb | 2018-07-06 11:20:23 +0900 | [diff] [blame] | 658 | if linkType == javaSystem { |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 659 | return module.systemApiStubsPath |
Sundong Ahn | 57368eb | 2018-07-06 11:20:23 +0900 | [diff] [blame] | 660 | } else if linkType == javaPlatform { |
| 661 | return module.implLibPath |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 662 | } else { |
| 663 | return module.publicApiStubsPath |
| 664 | } |
| 665 | } |
| 666 | |
Sundong Ahn | 241cd37 | 2018-07-13 16:16:44 +0900 | [diff] [blame] | 667 | // to satisfy SdkLibraryDependency interface |
| 668 | func (module *sdkLibrary) ImplementationJars(linkType linkType) android.Paths { |
| 669 | // This module is just a wrapper for the stubs. |
| 670 | if linkType == javaSystem { |
| 671 | return module.systemApiStubsImplPath |
| 672 | } else if linkType == javaPlatform { |
| 673 | return module.implLibImplPath |
| 674 | } else { |
| 675 | return module.publicApiStubsImplPath |
| 676 | } |
| 677 | } |
| 678 | |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 679 | func javaSdkLibraries(config android.Config) *[]string { |
| 680 | return config.Once("javaSdkLibraries", func() interface{} { |
| 681 | return &[]string{} |
| 682 | }).(*[]string) |
| 683 | } |
| 684 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 685 | // For a java_sdk_library module, create internal modules for stubs, docs, |
| 686 | // runtime libs and xml file. If requested, the stubs and docs are created twice |
| 687 | // once for public API level and once for system API level |
| 688 | func sdkLibraryMutator(mctx android.TopDownMutatorContext) { |
| 689 | if module, ok := mctx.Module().(*sdkLibrary); ok { |
Anton Hansson | 8959e14 | 2018-04-25 11:56:13 +0100 | [diff] [blame] | 690 | if module.properties.Srcs == nil { |
| 691 | mctx.PropertyErrorf("srcs", "java_sdk_library must specify srcs") |
| 692 | } |
| 693 | if module.properties.Api_packages == nil { |
| 694 | mctx.PropertyErrorf("api_packages", "java_sdk_library must specify api_packages") |
| 695 | } |
| 696 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 697 | // for public API stubs |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 698 | module.createStubsLibrary(mctx, apiScopePublic) |
| 699 | module.createDocs(mctx, apiScopePublic) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 700 | |
| 701 | // for system API stubs |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 702 | module.createStubsLibrary(mctx, apiScopeSystem) |
| 703 | module.createDocs(mctx, apiScopeSystem) |
| 704 | |
| 705 | // for test API stubs |
| 706 | module.createStubsLibrary(mctx, apiScopeTest) |
| 707 | module.createDocs(mctx, apiScopeTest) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 708 | |
| 709 | // for runtime |
| 710 | module.createXmlFile(mctx) |
| 711 | module.createImplLibrary(mctx) |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 712 | |
| 713 | // record java_sdk_library modules so that they are exported to make |
| 714 | javaSdkLibraries := javaSdkLibraries(mctx.Config()) |
| 715 | javaSdkLibrariesLock.Lock() |
| 716 | defer javaSdkLibrariesLock.Unlock() |
| 717 | *javaSdkLibraries = append(*javaSdkLibraries, module.BaseModuleName()) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 718 | } |
| 719 | } |
| 720 | |
| 721 | func sdkLibraryFactory() android.Module { |
| 722 | module := &sdkLibrary{} |
| 723 | module.AddProperties(&module.properties) |
Jiyong Park | 441a47d | 2018-05-01 23:33:08 +0900 | [diff] [blame] | 724 | module.AddProperties(&module.deviceProperties) |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 725 | module.AddProperties(&module.dexpreoptProperties) |
Colin Cross | 48de9a4 | 2018-10-02 13:53:33 -0700 | [diff] [blame] | 726 | InitJavaModule(module, android.DeviceSupported) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 727 | return module |
| 728 | } |