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