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