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