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