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