Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 1 | // Copyright 2015 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 | // This file contains the module types for compiling Android apps. |
| 18 | |
| 19 | import ( |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 20 | "strings" |
| 21 | |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 22 | "github.com/google/blueprint" |
Colin Cross | 76b5f0c | 2017-08-29 16:02:06 -0700 | [diff] [blame] | 23 | "github.com/google/blueprint/proptools" |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 24 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 25 | "android/soong/android" |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 26 | "android/soong/cc" |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 27 | "android/soong/tradefed" |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 28 | ) |
| 29 | |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 30 | func init() { |
Colin Cross | 5ab4e6d | 2017-11-22 16:20:45 -0800 | [diff] [blame] | 31 | android.RegisterModuleType("android_app", AndroidAppFactory) |
Colin Cross | ae5caf5 | 2018-05-22 11:11:52 -0700 | [diff] [blame] | 32 | android.RegisterModuleType("android_test", AndroidTestFactory) |
Colin Cross | 252fc6f | 2018-10-04 15:22:03 -0700 | [diff] [blame] | 33 | android.RegisterModuleType("android_test_helper_app", AndroidTestHelperAppFactory) |
Colin Cross | bd01e2a | 2018-10-04 15:21:03 -0700 | [diff] [blame] | 34 | android.RegisterModuleType("android_app_certificate", AndroidAppCertificateFactory) |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 35 | } |
| 36 | |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 37 | // AndroidManifest.xml merging |
| 38 | // package splits |
| 39 | |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 40 | type appProperties struct { |
Colin Cross | bd01e2a | 2018-10-04 15:21:03 -0700 | [diff] [blame] | 41 | // The name of a certificate in the default certificate directory, blank to use the default product certificate, |
| 42 | // or an android_app_certificate module name in the form ":module". |
Nan Zhang | ea568a4 | 2017-11-08 21:20:04 -0800 | [diff] [blame] | 43 | Certificate *string |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 44 | |
Colin Cross | bd01e2a | 2018-10-04 15:21:03 -0700 | [diff] [blame] | 45 | // Names of extra android_app_certificate modules to sign the apk with in the form ":module". |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 46 | Additional_certificates []string |
| 47 | |
| 48 | // If set, create package-export.apk, which other packages can |
| 49 | // use to get PRODUCT-agnostic resource data like IDs and type definitions. |
Nan Zhang | ea568a4 | 2017-11-08 21:20:04 -0800 | [diff] [blame] | 50 | Export_package_resources *bool |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 51 | |
Colin Cross | 1605606 | 2017-12-13 22:46:28 -0800 | [diff] [blame] | 52 | // Specifies that this app should be installed to the priv-app directory, |
| 53 | // where the system will grant it additional privileges not available to |
| 54 | // normal apps. |
| 55 | Privileged *bool |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 56 | |
| 57 | // list of resource labels to generate individual resource packages |
| 58 | Package_splits []string |
Jason Monk | d4122be | 2018-08-10 09:33:36 -0400 | [diff] [blame] | 59 | |
| 60 | // Names of modules to be overridden. Listed modules can only be other binaries |
| 61 | // (in Make or Soong). |
| 62 | // This does not completely prevent installation of the overridden binaries, but if both |
| 63 | // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed |
| 64 | // from PRODUCT_PACKAGES. |
| 65 | Overrides []string |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 66 | |
| 67 | // list of native libraries that will be provided in or alongside the resulting jar |
| 68 | Jni_libs []string `android:"arch_variant"` |
| 69 | |
Colin Cross | 5a0dcd5 | 2018-10-05 14:20:06 -0700 | [diff] [blame] | 70 | AllowDexPreopt bool `blueprint:"mutated"` |
| 71 | EmbedJNI bool `blueprint:"mutated"` |
| 72 | StripDex bool `blueprint:"mutated"` |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 73 | } |
| 74 | |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 75 | type AndroidApp struct { |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 76 | Library |
| 77 | aapt |
| 78 | |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 79 | certificate Certificate |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 80 | |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 81 | appProperties appProperties |
Colin Cross | ae5caf5 | 2018-05-22 11:11:52 -0700 | [diff] [blame] | 82 | |
| 83 | extraLinkFlags []string |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 84 | |
| 85 | installJniLibs []jniLib |
Colin Cross | f623721 | 2018-10-29 23:14:58 -0700 | [diff] [blame] | 86 | |
| 87 | bundleFile android.Path |
Colin Cross | e1731a5 | 2017-12-14 11:22:55 -0800 | [diff] [blame] | 88 | } |
| 89 | |
Colin Cross | 89c3158 | 2018-04-30 15:55:11 -0700 | [diff] [blame] | 90 | func (a *AndroidApp) ExportedProguardFlagFiles() android.Paths { |
| 91 | return nil |
| 92 | } |
| 93 | |
Colin Cross | 66f7882 | 2018-05-02 12:58:28 -0700 | [diff] [blame] | 94 | func (a *AndroidApp) ExportedStaticPackages() android.Paths { |
| 95 | return nil |
| 96 | } |
| 97 | |
Colin Cross | 3165695 | 2018-05-24 16:11:20 -0700 | [diff] [blame] | 98 | func (a *AndroidApp) ExportedManifest() android.Path { |
| 99 | return a.manifestPath |
| 100 | } |
| 101 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 102 | var _ AndroidLibraryDependency = (*AndroidApp)(nil) |
| 103 | |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 104 | type Certificate struct { |
| 105 | Pem, Key android.Path |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 106 | } |
| 107 | |
Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 108 | func (a *AndroidApp) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 109 | a.Module.deps(ctx) |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 110 | |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 111 | if !Bool(a.properties.No_framework_libs) && !Bool(a.properties.No_standard_libs) { |
Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 112 | a.aapt.deps(ctx, sdkContext(a)) |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 113 | } |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 114 | |
| 115 | for _, jniTarget := range ctx.MultiTargets() { |
| 116 | variation := []blueprint.Variation{ |
| 117 | {Mutator: "arch", Variation: jniTarget.String()}, |
| 118 | {Mutator: "link", Variation: "shared"}, |
| 119 | } |
| 120 | tag := &jniDependencyTag{ |
| 121 | target: jniTarget, |
| 122 | } |
| 123 | ctx.AddFarVariationDependencies(variation, tag, a.appProperties.Jni_libs...) |
| 124 | } |
Colin Cross | bd01e2a | 2018-10-04 15:21:03 -0700 | [diff] [blame] | 125 | |
| 126 | cert := android.SrcIsModule(String(a.appProperties.Certificate)) |
| 127 | if cert != "" { |
| 128 | ctx.AddDependency(ctx.Module(), certificateTag, cert) |
| 129 | } |
| 130 | |
| 131 | for _, cert := range a.appProperties.Additional_certificates { |
| 132 | cert = android.SrcIsModule(cert) |
| 133 | if cert != "" { |
| 134 | ctx.AddDependency(ctx.Module(), certificateTag, cert) |
| 135 | } else { |
| 136 | ctx.PropertyErrorf("additional_certificates", |
| 137 | `must be names of android_app_certificate modules in the form ":module"`) |
| 138 | } |
| 139 | } |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 140 | } |
| 141 | |
Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 142 | func (a *AndroidApp) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Colin Cross | ae5caf5 | 2018-05-22 11:11:52 -0700 | [diff] [blame] | 143 | a.generateAndroidBuildActions(ctx) |
| 144 | } |
| 145 | |
Colin Cross | 5a0dcd5 | 2018-10-05 14:20:06 -0700 | [diff] [blame] | 146 | // Returns whether this module should have the dex file stored uncompressed in the APK, or stripped completely. If |
| 147 | // stripped, the code will still be present on the device in the dexpreopted files. |
| 148 | // This is only necessary for APKs, and not jars, because APKs are signed and the dex file should not be uncompressed |
| 149 | // or removed after the signature has been generated. For jars, which are not signed, the dex file is uncompressed |
| 150 | // or removed at installation time in Make. |
| 151 | func (a *AndroidApp) uncompressOrStripDex(ctx android.ModuleContext) (uncompress, strip bool) { |
| 152 | if ctx.Config().UnbundledBuild() { |
| 153 | return false, false |
| 154 | } |
| 155 | |
| 156 | strip = ctx.Config().DefaultStripDex() |
| 157 | // TODO(ccross): don't strip dex installed on partitions that may be updated separately (like vendor) |
| 158 | // TODO(ccross): don't strip dex on modules with LOCAL_APK_LIBRARIES equivalent |
Colin Cross | 5a0dcd5 | 2018-10-05 14:20:06 -0700 | [diff] [blame] | 159 | |
| 160 | // Uncompress dex in APKs of privileged apps, and modules used by privileged apps. |
| 161 | if ctx.Config().UncompressPrivAppDex() && |
| 162 | (Bool(a.appProperties.Privileged) || |
| 163 | inList(ctx.ModuleName(), ctx.Config().ModulesLoadedByPrivilegedModules())) { |
| 164 | |
| 165 | uncompress = true |
| 166 | // If the dex files is store uncompressed, don't strip it, we will reuse the uncompressed dex from the APK |
| 167 | // instead of copying it into the odex file. |
| 168 | strip = false |
| 169 | } |
| 170 | |
| 171 | // If dexpreopt is disabled, don't strip the dex file |
| 172 | if !a.appProperties.AllowDexPreopt || |
| 173 | !BoolDefault(a.deviceProperties.Dex_preopt.Enabled, true) || |
| 174 | ctx.Config().DisableDexPreopt(ctx.ModuleName()) { |
| 175 | strip = false |
| 176 | } |
| 177 | |
Colin Cross | 762fbfb | 2018-10-29 12:58:06 -0700 | [diff] [blame] | 178 | // TODO(ccross): strip dexpropted modules that are not propted to system_other |
| 179 | strip = false |
| 180 | |
Colin Cross | 5a0dcd5 | 2018-10-05 14:20:06 -0700 | [diff] [blame] | 181 | return uncompress, strip |
| 182 | } |
| 183 | |
Colin Cross | ae5caf5 | 2018-05-22 11:11:52 -0700 | [diff] [blame] | 184 | func (a *AndroidApp) generateAndroidBuildActions(ctx android.ModuleContext) { |
| 185 | linkFlags := append([]string(nil), a.extraLinkFlags...) |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 186 | |
Colin Cross | e78dcd3 | 2018-04-19 15:25:19 -0700 | [diff] [blame] | 187 | hasProduct := false |
| 188 | for _, f := range a.aaptProperties.Aaptflags { |
| 189 | if strings.HasPrefix(f, "--product") { |
| 190 | hasProduct = true |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | // Product characteristics |
| 195 | if !hasProduct && len(ctx.Config().ProductAAPTCharacteristics()) > 0 { |
| 196 | linkFlags = append(linkFlags, "--product", ctx.Config().ProductAAPTCharacteristics()) |
| 197 | } |
| 198 | |
Dan Willemsen | 72be590 | 2018-10-24 20:24:57 -0700 | [diff] [blame] | 199 | if !Bool(a.aaptProperties.Aapt_include_all_resources) { |
| 200 | // Product AAPT config |
| 201 | for _, aaptConfig := range ctx.Config().ProductAAPTConfig() { |
| 202 | linkFlags = append(linkFlags, "-c", aaptConfig) |
| 203 | } |
Colin Cross | e78dcd3 | 2018-04-19 15:25:19 -0700 | [diff] [blame] | 204 | |
Dan Willemsen | 72be590 | 2018-10-24 20:24:57 -0700 | [diff] [blame] | 205 | // Product AAPT preferred config |
| 206 | if len(ctx.Config().ProductAAPTPreferredConfig()) > 0 { |
| 207 | linkFlags = append(linkFlags, "--preferred-density", ctx.Config().ProductAAPTPreferredConfig()) |
| 208 | } |
Colin Cross | e78dcd3 | 2018-04-19 15:25:19 -0700 | [diff] [blame] | 209 | } |
| 210 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 211 | // TODO: LOCAL_PACKAGE_OVERRIDES |
| 212 | // $(addprefix --rename-manifest-package , $(PRIVATE_MANIFEST_PACKAGE_NAME)) \ |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 213 | |
Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 214 | a.aapt.buildActions(ctx, sdkContext(a), linkFlags...) |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 215 | |
Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 216 | // apps manifests are handled by aapt, don't let Module see them |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 217 | a.properties.Manifest = nil |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 218 | |
Colin Cross | 89c3158 | 2018-04-30 15:55:11 -0700 | [diff] [blame] | 219 | var staticLibProguardFlagFiles android.Paths |
| 220 | ctx.VisitDirectDeps(func(m android.Module) { |
| 221 | if lib, ok := m.(AndroidLibraryDependency); ok && ctx.OtherModuleDependencyTag(m) == staticLibTag { |
| 222 | staticLibProguardFlagFiles = append(staticLibProguardFlagFiles, lib.ExportedProguardFlagFiles()...) |
| 223 | } |
| 224 | }) |
| 225 | |
| 226 | staticLibProguardFlagFiles = android.FirstUniquePaths(staticLibProguardFlagFiles) |
| 227 | |
| 228 | a.Module.extraProguardFlagFiles = append(a.Module.extraProguardFlagFiles, staticLibProguardFlagFiles...) |
| 229 | a.Module.extraProguardFlagFiles = append(a.Module.extraProguardFlagFiles, a.proguardOptionsFile) |
Colin Cross | 66dbc0b | 2017-12-28 12:23:20 -0800 | [diff] [blame] | 230 | |
Colin Cross | 5a0dcd5 | 2018-10-05 14:20:06 -0700 | [diff] [blame] | 231 | a.deviceProperties.UncompressDex, a.appProperties.StripDex = a.uncompressOrStripDex(ctx) |
| 232 | |
Colin Cross | 5ab4e6d | 2017-11-22 16:20:45 -0800 | [diff] [blame] | 233 | if ctx.ModuleName() != "framework-res" { |
| 234 | a.Module.compile(ctx, a.aaptSrcJar) |
| 235 | } |
Colin Cross | 5a0dcd5 | 2018-10-05 14:20:06 -0700 | [diff] [blame] | 236 | dexJarFile := a.dexJarFile |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 237 | |
Colin Cross | 5a0dcd5 | 2018-10-05 14:20:06 -0700 | [diff] [blame] | 238 | if a.appProperties.StripDex { |
| 239 | dexJarFile = nil |
| 240 | } |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 241 | |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 242 | var certificates []Certificate |
Colin Cross | bd01e2a | 2018-10-04 15:21:03 -0700 | [diff] [blame] | 243 | |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 244 | var jniJarFile android.WritablePath |
Colin Cross | bd01e2a | 2018-10-04 15:21:03 -0700 | [diff] [blame] | 245 | jniLibs, certificateDeps := a.collectAppDeps(ctx) |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 246 | if len(jniLibs) > 0 { |
| 247 | embedJni := ctx.Config().UnbundledBuild() || a.appProperties.EmbedJNI |
| 248 | if embedJni { |
| 249 | jniJarFile = android.PathForModuleOut(ctx, "jnilibs.zip") |
| 250 | TransformJniLibsToJar(ctx, jniJarFile, jniLibs) |
| 251 | } else { |
| 252 | a.installJniLibs = jniLibs |
| 253 | } |
| 254 | } |
| 255 | |
Colin Cross | bd01e2a | 2018-10-04 15:21:03 -0700 | [diff] [blame] | 256 | if ctx.Failed() { |
| 257 | return |
| 258 | } |
| 259 | |
| 260 | cert := String(a.appProperties.Certificate) |
| 261 | certModule := android.SrcIsModule(cert) |
| 262 | if certModule != "" { |
| 263 | a.certificate = certificateDeps[0] |
| 264 | certificateDeps = certificateDeps[1:] |
| 265 | } else if cert != "" { |
| 266 | defaultDir := ctx.Config().DefaultAppCertificateDir(ctx) |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 267 | a.certificate = Certificate{ |
Colin Cross | bd01e2a | 2018-10-04 15:21:03 -0700 | [diff] [blame] | 268 | defaultDir.Join(ctx, cert+".x509.pem"), |
| 269 | defaultDir.Join(ctx, cert+".pk8"), |
| 270 | } |
| 271 | } else { |
| 272 | pem, key := ctx.Config().DefaultAppCertificate(ctx) |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 273 | a.certificate = Certificate{pem, key} |
Colin Cross | bd01e2a | 2018-10-04 15:21:03 -0700 | [diff] [blame] | 274 | } |
| 275 | |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 276 | certificates = append([]Certificate{a.certificate}, certificateDeps...) |
Colin Cross | bd01e2a | 2018-10-04 15:21:03 -0700 | [diff] [blame] | 277 | |
Colin Cross | 5a0dcd5 | 2018-10-05 14:20:06 -0700 | [diff] [blame] | 278 | packageFile := android.PathForModuleOut(ctx, "package.apk") |
| 279 | CreateAppPackage(ctx, packageFile, a.exportPackage, jniJarFile, dexJarFile, certificates) |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 280 | a.outputFile = packageFile |
| 281 | |
Colin Cross | f623721 | 2018-10-29 23:14:58 -0700 | [diff] [blame] | 282 | bundleFile := android.PathForModuleOut(ctx, "base.zip") |
| 283 | BuildBundleModule(ctx, bundleFile, a.exportPackage, jniJarFile, dexJarFile) |
| 284 | a.bundleFile = bundleFile |
| 285 | |
Colin Cross | 5ab4e6d | 2017-11-22 16:20:45 -0800 | [diff] [blame] | 286 | if ctx.ModuleName() == "framework-res" { |
| 287 | // framework-res.apk is installed as system/framework/framework-res.apk |
| 288 | ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"), ctx.ModuleName()+".apk", a.outputFile) |
Colin Cross | 1605606 | 2017-12-13 22:46:28 -0800 | [diff] [blame] | 289 | } else if Bool(a.appProperties.Privileged) { |
| 290 | ctx.InstallFile(android.PathForModuleInstall(ctx, "priv-app"), ctx.ModuleName()+".apk", a.outputFile) |
Colin Cross | 5ab4e6d | 2017-11-22 16:20:45 -0800 | [diff] [blame] | 291 | } else { |
| 292 | ctx.InstallFile(android.PathForModuleInstall(ctx, "app"), ctx.ModuleName()+".apk", a.outputFile) |
| 293 | } |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 294 | } |
| 295 | |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 296 | func (a *AndroidApp) collectAppDeps(ctx android.ModuleContext) ([]jniLib, []Certificate) { |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 297 | var jniLibs []jniLib |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 298 | var certificates []Certificate |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 299 | |
| 300 | ctx.VisitDirectDeps(func(module android.Module) { |
| 301 | otherName := ctx.OtherModuleName(module) |
| 302 | tag := ctx.OtherModuleDependencyTag(module) |
| 303 | |
| 304 | if jniTag, ok := tag.(*jniDependencyTag); ok { |
| 305 | if dep, ok := module.(*cc.Module); ok { |
| 306 | lib := dep.OutputFile() |
| 307 | if lib.Valid() { |
| 308 | jniLibs = append(jniLibs, jniLib{ |
| 309 | name: ctx.OtherModuleName(module), |
| 310 | path: lib.Path(), |
| 311 | target: jniTag.target, |
| 312 | }) |
| 313 | } else { |
| 314 | ctx.ModuleErrorf("dependency %q missing output file", otherName) |
| 315 | } |
| 316 | } else { |
| 317 | ctx.ModuleErrorf("jni_libs dependency %q must be a cc library", otherName) |
| 318 | |
| 319 | } |
Colin Cross | bd01e2a | 2018-10-04 15:21:03 -0700 | [diff] [blame] | 320 | } else if tag == certificateTag { |
| 321 | if dep, ok := module.(*AndroidAppCertificate); ok { |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 322 | certificates = append(certificates, dep.Certificate) |
Colin Cross | bd01e2a | 2018-10-04 15:21:03 -0700 | [diff] [blame] | 323 | } else { |
| 324 | ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", otherName) |
| 325 | } |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 326 | } |
| 327 | }) |
| 328 | |
Colin Cross | bd01e2a | 2018-10-04 15:21:03 -0700 | [diff] [blame] | 329 | return jniLibs, certificates |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 330 | } |
| 331 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 332 | func AndroidAppFactory() android.Module { |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 333 | module := &AndroidApp{} |
| 334 | |
Colin Cross | 66dbc0b | 2017-12-28 12:23:20 -0800 | [diff] [blame] | 335 | module.Module.deviceProperties.Optimize.Enabled = proptools.BoolPtr(true) |
| 336 | module.Module.deviceProperties.Optimize.Shrink = proptools.BoolPtr(true) |
| 337 | |
Colin Cross | ae5caf5 | 2018-05-22 11:11:52 -0700 | [diff] [blame] | 338 | module.Module.properties.Instrument = true |
Colin Cross | 9ae1b92 | 2018-06-26 17:59:05 -0700 | [diff] [blame] | 339 | module.Module.properties.Installable = proptools.BoolPtr(true) |
Colin Cross | 5a0dcd5 | 2018-10-05 14:20:06 -0700 | [diff] [blame] | 340 | module.appProperties.AllowDexPreopt = true |
Colin Cross | ae5caf5 | 2018-05-22 11:11:52 -0700 | [diff] [blame] | 341 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 342 | module.AddProperties( |
Colin Cross | 540eff8 | 2017-06-22 17:01:52 -0700 | [diff] [blame] | 343 | &module.Module.properties, |
| 344 | &module.Module.deviceProperties, |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 345 | &module.Module.protoProperties, |
| 346 | &module.aaptProperties, |
Colin Cross | 540eff8 | 2017-06-22 17:01:52 -0700 | [diff] [blame] | 347 | &module.appProperties) |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 348 | |
Colin Cross | a9d8bee | 2018-10-02 13:59:46 -0700 | [diff] [blame] | 349 | module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool { |
| 350 | return class == android.Device && ctx.Config().DevicePrefer32BitApps() |
| 351 | }) |
| 352 | |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 353 | android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon) |
| 354 | android.InitDefaultableModule(module) |
| 355 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 356 | return module |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 357 | } |
Colin Cross | ae5caf5 | 2018-05-22 11:11:52 -0700 | [diff] [blame] | 358 | |
| 359 | type appTestProperties struct { |
| 360 | Instrumentation_for *string |
| 361 | } |
| 362 | |
| 363 | type AndroidTest struct { |
| 364 | AndroidApp |
| 365 | |
| 366 | appTestProperties appTestProperties |
| 367 | |
| 368 | testProperties testProperties |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 369 | |
| 370 | testConfig android.Path |
Colin Cross | d96ca35 | 2018-08-10 16:06:24 -0700 | [diff] [blame] | 371 | data android.Paths |
Colin Cross | ae5caf5 | 2018-05-22 11:11:52 -0700 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | func (a *AndroidTest) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Colin Cross | ae5caf5 | 2018-05-22 11:11:52 -0700 | [diff] [blame] | 375 | a.generateAndroidBuildActions(ctx) |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 376 | |
Jack He | 3333889 | 2018-09-19 02:21:28 -0700 | [diff] [blame] | 377 | a.testConfig = tradefed.AutoGenInstrumentationTestConfig(ctx, a.testProperties.Test_config, a.testProperties.Test_config_template, a.manifestPath) |
Colin Cross | d96ca35 | 2018-08-10 16:06:24 -0700 | [diff] [blame] | 378 | a.data = ctx.ExpandSources(a.testProperties.Data, nil) |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 379 | } |
| 380 | |
| 381 | func (a *AndroidTest) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 382 | android.ExtractSourceDeps(ctx, a.testProperties.Test_config) |
Jack He | 3333889 | 2018-09-19 02:21:28 -0700 | [diff] [blame] | 383 | android.ExtractSourceDeps(ctx, a.testProperties.Test_config_template) |
Colin Cross | d96ca35 | 2018-08-10 16:06:24 -0700 | [diff] [blame] | 384 | android.ExtractSourcesDeps(ctx, a.testProperties.Data) |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 385 | a.AndroidApp.DepsMutator(ctx) |
Colin Cross | 4b964c0 | 2018-10-15 16:18:06 -0700 | [diff] [blame] | 386 | if a.appTestProperties.Instrumentation_for != nil { |
| 387 | // The android_app dependency listed in instrumentation_for needs to be added to the classpath for javac, |
| 388 | // but not added to the aapt2 link includes like a normal android_app or android_library dependency, so |
| 389 | // use instrumentationForTag instead of libTag. |
| 390 | ctx.AddVariationDependencies(nil, instrumentationForTag, String(a.appTestProperties.Instrumentation_for)) |
| 391 | } |
Colin Cross | ae5caf5 | 2018-05-22 11:11:52 -0700 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | func AndroidTestFactory() android.Module { |
| 395 | module := &AndroidTest{} |
| 396 | |
| 397 | module.Module.deviceProperties.Optimize.Enabled = proptools.BoolPtr(true) |
Colin Cross | 5067db9 | 2018-09-17 16:46:35 -0700 | [diff] [blame] | 398 | |
| 399 | module.Module.properties.Instrument = true |
Colin Cross | 9ae1b92 | 2018-06-26 17:59:05 -0700 | [diff] [blame] | 400 | module.Module.properties.Installable = proptools.BoolPtr(true) |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 401 | module.appProperties.EmbedJNI = true |
Colin Cross | 5a0dcd5 | 2018-10-05 14:20:06 -0700 | [diff] [blame] | 402 | module.appProperties.AllowDexPreopt = false |
Colin Cross | ae5caf5 | 2018-05-22 11:11:52 -0700 | [diff] [blame] | 403 | |
| 404 | module.AddProperties( |
| 405 | &module.Module.properties, |
| 406 | &module.Module.deviceProperties, |
| 407 | &module.Module.protoProperties, |
| 408 | &module.aaptProperties, |
| 409 | &module.appProperties, |
Dan Willemsen | f5531d2 | 2018-07-16 17:21:19 -0700 | [diff] [blame] | 410 | &module.appTestProperties, |
| 411 | &module.testProperties) |
Colin Cross | ae5caf5 | 2018-05-22 11:11:52 -0700 | [diff] [blame] | 412 | |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 413 | android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon) |
| 414 | android.InitDefaultableModule(module) |
Colin Cross | ae5caf5 | 2018-05-22 11:11:52 -0700 | [diff] [blame] | 415 | return module |
| 416 | } |
Colin Cross | bd01e2a | 2018-10-04 15:21:03 -0700 | [diff] [blame] | 417 | |
Colin Cross | 252fc6f | 2018-10-04 15:22:03 -0700 | [diff] [blame] | 418 | type appTestHelperAppProperties struct { |
| 419 | // list of compatibility suites (for example "cts", "vts") that the module should be |
| 420 | // installed into. |
| 421 | Test_suites []string `android:"arch_variant"` |
| 422 | } |
| 423 | |
| 424 | type AndroidTestHelperApp struct { |
| 425 | AndroidApp |
| 426 | |
| 427 | appTestHelperAppProperties appTestHelperAppProperties |
| 428 | } |
| 429 | |
| 430 | func AndroidTestHelperAppFactory() android.Module { |
| 431 | module := &AndroidTestHelperApp{} |
| 432 | |
| 433 | module.Module.deviceProperties.Optimize.Enabled = proptools.BoolPtr(true) |
| 434 | |
| 435 | module.Module.properties.Installable = proptools.BoolPtr(true) |
| 436 | module.appProperties.EmbedJNI = true |
Colin Cross | 5a0dcd5 | 2018-10-05 14:20:06 -0700 | [diff] [blame] | 437 | module.appProperties.AllowDexPreopt = false |
Colin Cross | 252fc6f | 2018-10-04 15:22:03 -0700 | [diff] [blame] | 438 | |
| 439 | module.AddProperties( |
| 440 | &module.Module.properties, |
| 441 | &module.Module.deviceProperties, |
| 442 | &module.Module.protoProperties, |
| 443 | &module.aaptProperties, |
| 444 | &module.appProperties, |
| 445 | &module.appTestHelperAppProperties) |
| 446 | |
| 447 | android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon) |
| 448 | android.InitDefaultableModule(module) |
| 449 | return module |
| 450 | } |
| 451 | |
Colin Cross | bd01e2a | 2018-10-04 15:21:03 -0700 | [diff] [blame] | 452 | type AndroidAppCertificate struct { |
| 453 | android.ModuleBase |
| 454 | properties AndroidAppCertificateProperties |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 455 | Certificate Certificate |
Colin Cross | bd01e2a | 2018-10-04 15:21:03 -0700 | [diff] [blame] | 456 | } |
| 457 | |
| 458 | type AndroidAppCertificateProperties struct { |
| 459 | // Name of the certificate files. Extensions .x509.pem and .pk8 will be added to the name. |
| 460 | Certificate *string |
| 461 | } |
| 462 | |
| 463 | func AndroidAppCertificateFactory() android.Module { |
| 464 | module := &AndroidAppCertificate{} |
| 465 | module.AddProperties(&module.properties) |
| 466 | android.InitAndroidModule(module) |
| 467 | return module |
| 468 | } |
| 469 | |
| 470 | func (c *AndroidAppCertificate) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 471 | } |
| 472 | |
| 473 | func (c *AndroidAppCertificate) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 474 | cert := String(c.properties.Certificate) |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 475 | c.Certificate = Certificate{ |
Colin Cross | bd01e2a | 2018-10-04 15:21:03 -0700 | [diff] [blame] | 476 | android.PathForModuleSrc(ctx, cert+".x509.pem"), |
| 477 | android.PathForModuleSrc(ctx, cert+".pk8"), |
| 478 | } |
| 479 | } |