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 | |
| 70 | EmbedJNI bool `blueprint:"mutated"` |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 71 | } |
| 72 | |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 73 | type AndroidApp struct { |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 74 | Library |
| 75 | aapt |
| 76 | |
| 77 | certificate certificate |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 78 | |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 79 | appProperties appProperties |
Colin Cross | ae5caf5 | 2018-05-22 11:11:52 -0700 | [diff] [blame] | 80 | |
| 81 | extraLinkFlags []string |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 82 | |
| 83 | installJniLibs []jniLib |
Colin Cross | e1731a5 | 2017-12-14 11:22:55 -0800 | [diff] [blame] | 84 | } |
| 85 | |
Colin Cross | 89c3158 | 2018-04-30 15:55:11 -0700 | [diff] [blame] | 86 | func (a *AndroidApp) ExportedProguardFlagFiles() android.Paths { |
| 87 | return nil |
| 88 | } |
| 89 | |
Colin Cross | 66f7882 | 2018-05-02 12:58:28 -0700 | [diff] [blame] | 90 | func (a *AndroidApp) ExportedStaticPackages() android.Paths { |
| 91 | return nil |
| 92 | } |
| 93 | |
Colin Cross | 3165695 | 2018-05-24 16:11:20 -0700 | [diff] [blame] | 94 | func (a *AndroidApp) ExportedManifest() android.Path { |
| 95 | return a.manifestPath |
| 96 | } |
| 97 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 98 | var _ AndroidLibraryDependency = (*AndroidApp)(nil) |
| 99 | |
Colin Cross | e1731a5 | 2017-12-14 11:22:55 -0800 | [diff] [blame] | 100 | type certificate struct { |
| 101 | pem, key android.Path |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 102 | } |
| 103 | |
Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 104 | func (a *AndroidApp) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 105 | a.Module.deps(ctx) |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 106 | |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 107 | 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] | 108 | a.aapt.deps(ctx, sdkContext(a)) |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 109 | } |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 110 | |
| 111 | for _, jniTarget := range ctx.MultiTargets() { |
| 112 | variation := []blueprint.Variation{ |
| 113 | {Mutator: "arch", Variation: jniTarget.String()}, |
| 114 | {Mutator: "link", Variation: "shared"}, |
| 115 | } |
| 116 | tag := &jniDependencyTag{ |
| 117 | target: jniTarget, |
| 118 | } |
| 119 | ctx.AddFarVariationDependencies(variation, tag, a.appProperties.Jni_libs...) |
| 120 | } |
Colin Cross | bd01e2a | 2018-10-04 15:21:03 -0700 | [diff] [blame] | 121 | |
| 122 | cert := android.SrcIsModule(String(a.appProperties.Certificate)) |
| 123 | if cert != "" { |
| 124 | ctx.AddDependency(ctx.Module(), certificateTag, cert) |
| 125 | } |
| 126 | |
| 127 | for _, cert := range a.appProperties.Additional_certificates { |
| 128 | cert = android.SrcIsModule(cert) |
| 129 | if cert != "" { |
| 130 | ctx.AddDependency(ctx.Module(), certificateTag, cert) |
| 131 | } else { |
| 132 | ctx.PropertyErrorf("additional_certificates", |
| 133 | `must be names of android_app_certificate modules in the form ":module"`) |
| 134 | } |
| 135 | } |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 136 | } |
| 137 | |
Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 138 | func (a *AndroidApp) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Colin Cross | ae5caf5 | 2018-05-22 11:11:52 -0700 | [diff] [blame] | 139 | a.generateAndroidBuildActions(ctx) |
| 140 | } |
| 141 | |
| 142 | func (a *AndroidApp) generateAndroidBuildActions(ctx android.ModuleContext) { |
| 143 | linkFlags := append([]string(nil), a.extraLinkFlags...) |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 144 | |
Colin Cross | e78dcd3 | 2018-04-19 15:25:19 -0700 | [diff] [blame] | 145 | hasProduct := false |
| 146 | for _, f := range a.aaptProperties.Aaptflags { |
| 147 | if strings.HasPrefix(f, "--product") { |
| 148 | hasProduct = true |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | // Product characteristics |
| 153 | if !hasProduct && len(ctx.Config().ProductAAPTCharacteristics()) > 0 { |
| 154 | linkFlags = append(linkFlags, "--product", ctx.Config().ProductAAPTCharacteristics()) |
| 155 | } |
| 156 | |
| 157 | // Product AAPT config |
| 158 | for _, aaptConfig := range ctx.Config().ProductAAPTConfig() { |
| 159 | linkFlags = append(linkFlags, "-c", aaptConfig) |
| 160 | } |
| 161 | |
| 162 | // Product AAPT preferred config |
| 163 | if len(ctx.Config().ProductAAPTPreferredConfig()) > 0 { |
| 164 | linkFlags = append(linkFlags, "--preferred-density", ctx.Config().ProductAAPTPreferredConfig()) |
| 165 | } |
| 166 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 167 | // TODO: LOCAL_PACKAGE_OVERRIDES |
| 168 | // $(addprefix --rename-manifest-package , $(PRIVATE_MANIFEST_PACKAGE_NAME)) \ |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 169 | |
Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 170 | a.aapt.buildActions(ctx, sdkContext(a), linkFlags...) |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 171 | |
Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 172 | // apps manifests are handled by aapt, don't let Module see them |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 173 | a.properties.Manifest = nil |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 174 | |
Colin Cross | 89c3158 | 2018-04-30 15:55:11 -0700 | [diff] [blame] | 175 | var staticLibProguardFlagFiles android.Paths |
| 176 | ctx.VisitDirectDeps(func(m android.Module) { |
| 177 | if lib, ok := m.(AndroidLibraryDependency); ok && ctx.OtherModuleDependencyTag(m) == staticLibTag { |
| 178 | staticLibProguardFlagFiles = append(staticLibProguardFlagFiles, lib.ExportedProguardFlagFiles()...) |
| 179 | } |
| 180 | }) |
| 181 | |
| 182 | staticLibProguardFlagFiles = android.FirstUniquePaths(staticLibProguardFlagFiles) |
| 183 | |
| 184 | a.Module.extraProguardFlagFiles = append(a.Module.extraProguardFlagFiles, staticLibProguardFlagFiles...) |
| 185 | a.Module.extraProguardFlagFiles = append(a.Module.extraProguardFlagFiles, a.proguardOptionsFile) |
Colin Cross | 66dbc0b | 2017-12-28 12:23:20 -0800 | [diff] [blame] | 186 | |
Colin Cross | 5ab4e6d | 2017-11-22 16:20:45 -0800 | [diff] [blame] | 187 | if ctx.ModuleName() != "framework-res" { |
| 188 | a.Module.compile(ctx, a.aaptSrcJar) |
| 189 | } |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 190 | |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 191 | packageFile := android.PathForModuleOut(ctx, "package.apk") |
| 192 | |
Colin Cross | bd01e2a | 2018-10-04 15:21:03 -0700 | [diff] [blame] | 193 | var certificates []certificate |
| 194 | |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 195 | var jniJarFile android.WritablePath |
Colin Cross | bd01e2a | 2018-10-04 15:21:03 -0700 | [diff] [blame] | 196 | jniLibs, certificateDeps := a.collectAppDeps(ctx) |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 197 | if len(jniLibs) > 0 { |
| 198 | embedJni := ctx.Config().UnbundledBuild() || a.appProperties.EmbedJNI |
| 199 | if embedJni { |
| 200 | jniJarFile = android.PathForModuleOut(ctx, "jnilibs.zip") |
| 201 | TransformJniLibsToJar(ctx, jniJarFile, jniLibs) |
| 202 | } else { |
| 203 | a.installJniLibs = jniLibs |
| 204 | } |
| 205 | } |
| 206 | |
Colin Cross | bd01e2a | 2018-10-04 15:21:03 -0700 | [diff] [blame] | 207 | if ctx.Failed() { |
| 208 | return |
| 209 | } |
| 210 | |
| 211 | cert := String(a.appProperties.Certificate) |
| 212 | certModule := android.SrcIsModule(cert) |
| 213 | if certModule != "" { |
| 214 | a.certificate = certificateDeps[0] |
| 215 | certificateDeps = certificateDeps[1:] |
| 216 | } else if cert != "" { |
| 217 | defaultDir := ctx.Config().DefaultAppCertificateDir(ctx) |
| 218 | a.certificate = certificate{ |
| 219 | defaultDir.Join(ctx, cert+".x509.pem"), |
| 220 | defaultDir.Join(ctx, cert+".pk8"), |
| 221 | } |
| 222 | } else { |
| 223 | pem, key := ctx.Config().DefaultAppCertificate(ctx) |
| 224 | a.certificate = certificate{pem, key} |
| 225 | } |
| 226 | |
| 227 | certificates = append([]certificate{a.certificate}, certificateDeps...) |
| 228 | |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 229 | CreateAppPackage(ctx, packageFile, a.exportPackage, jniJarFile, a.outputFile, certificates) |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 230 | |
| 231 | a.outputFile = packageFile |
| 232 | |
Colin Cross | 5ab4e6d | 2017-11-22 16:20:45 -0800 | [diff] [blame] | 233 | if ctx.ModuleName() == "framework-res" { |
| 234 | // framework-res.apk is installed as system/framework/framework-res.apk |
| 235 | ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"), ctx.ModuleName()+".apk", a.outputFile) |
Colin Cross | 1605606 | 2017-12-13 22:46:28 -0800 | [diff] [blame] | 236 | } else if Bool(a.appProperties.Privileged) { |
| 237 | ctx.InstallFile(android.PathForModuleInstall(ctx, "priv-app"), ctx.ModuleName()+".apk", a.outputFile) |
Colin Cross | 5ab4e6d | 2017-11-22 16:20:45 -0800 | [diff] [blame] | 238 | } else { |
| 239 | ctx.InstallFile(android.PathForModuleInstall(ctx, "app"), ctx.ModuleName()+".apk", a.outputFile) |
| 240 | } |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 241 | } |
| 242 | |
Colin Cross | bd01e2a | 2018-10-04 15:21:03 -0700 | [diff] [blame] | 243 | func (a *AndroidApp) collectAppDeps(ctx android.ModuleContext) ([]jniLib, []certificate) { |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 244 | var jniLibs []jniLib |
Colin Cross | bd01e2a | 2018-10-04 15:21:03 -0700 | [diff] [blame] | 245 | var certificates []certificate |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 246 | |
| 247 | ctx.VisitDirectDeps(func(module android.Module) { |
| 248 | otherName := ctx.OtherModuleName(module) |
| 249 | tag := ctx.OtherModuleDependencyTag(module) |
| 250 | |
| 251 | if jniTag, ok := tag.(*jniDependencyTag); ok { |
| 252 | if dep, ok := module.(*cc.Module); ok { |
| 253 | lib := dep.OutputFile() |
| 254 | if lib.Valid() { |
| 255 | jniLibs = append(jniLibs, jniLib{ |
| 256 | name: ctx.OtherModuleName(module), |
| 257 | path: lib.Path(), |
| 258 | target: jniTag.target, |
| 259 | }) |
| 260 | } else { |
| 261 | ctx.ModuleErrorf("dependency %q missing output file", otherName) |
| 262 | } |
| 263 | } else { |
| 264 | ctx.ModuleErrorf("jni_libs dependency %q must be a cc library", otherName) |
| 265 | |
| 266 | } |
Colin Cross | bd01e2a | 2018-10-04 15:21:03 -0700 | [diff] [blame] | 267 | } else if tag == certificateTag { |
| 268 | if dep, ok := module.(*AndroidAppCertificate); ok { |
| 269 | certificates = append(certificates, dep.certificate) |
| 270 | } else { |
| 271 | ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", otherName) |
| 272 | } |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 273 | } |
| 274 | }) |
| 275 | |
Colin Cross | bd01e2a | 2018-10-04 15:21:03 -0700 | [diff] [blame] | 276 | return jniLibs, certificates |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 277 | } |
| 278 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 279 | func AndroidAppFactory() android.Module { |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 280 | module := &AndroidApp{} |
| 281 | |
Colin Cross | 66dbc0b | 2017-12-28 12:23:20 -0800 | [diff] [blame] | 282 | module.Module.deviceProperties.Optimize.Enabled = proptools.BoolPtr(true) |
| 283 | module.Module.deviceProperties.Optimize.Shrink = proptools.BoolPtr(true) |
| 284 | |
Colin Cross | ae5caf5 | 2018-05-22 11:11:52 -0700 | [diff] [blame] | 285 | module.Module.properties.Instrument = true |
Colin Cross | 9ae1b92 | 2018-06-26 17:59:05 -0700 | [diff] [blame] | 286 | module.Module.properties.Installable = proptools.BoolPtr(true) |
Colin Cross | ae5caf5 | 2018-05-22 11:11:52 -0700 | [diff] [blame] | 287 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 288 | module.AddProperties( |
Colin Cross | 540eff8 | 2017-06-22 17:01:52 -0700 | [diff] [blame] | 289 | &module.Module.properties, |
| 290 | &module.Module.deviceProperties, |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 291 | &module.Module.protoProperties, |
| 292 | &module.aaptProperties, |
Colin Cross | 540eff8 | 2017-06-22 17:01:52 -0700 | [diff] [blame] | 293 | &module.appProperties) |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 294 | |
Colin Cross | a9d8bee | 2018-10-02 13:59:46 -0700 | [diff] [blame] | 295 | module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool { |
| 296 | return class == android.Device && ctx.Config().DevicePrefer32BitApps() |
| 297 | }) |
| 298 | |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 299 | android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon) |
| 300 | android.InitDefaultableModule(module) |
| 301 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 302 | return module |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 303 | } |
Colin Cross | ae5caf5 | 2018-05-22 11:11:52 -0700 | [diff] [blame] | 304 | |
| 305 | type appTestProperties struct { |
| 306 | Instrumentation_for *string |
| 307 | } |
| 308 | |
| 309 | type AndroidTest struct { |
| 310 | AndroidApp |
| 311 | |
| 312 | appTestProperties appTestProperties |
| 313 | |
| 314 | testProperties testProperties |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 315 | |
| 316 | testConfig android.Path |
Colin Cross | d96ca35 | 2018-08-10 16:06:24 -0700 | [diff] [blame] | 317 | data android.Paths |
Colin Cross | ae5caf5 | 2018-05-22 11:11:52 -0700 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | func (a *AndroidTest) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 321 | if String(a.appTestProperties.Instrumentation_for) != "" { |
| 322 | a.AndroidApp.extraLinkFlags = append(a.AndroidApp.extraLinkFlags, |
| 323 | "--rename-instrumentation-target-package", |
| 324 | String(a.appTestProperties.Instrumentation_for)) |
| 325 | } |
| 326 | |
| 327 | a.generateAndroidBuildActions(ctx) |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 328 | |
Jack He | 3333889 | 2018-09-19 02:21:28 -0700 | [diff] [blame] | 329 | 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] | 330 | a.data = ctx.ExpandSources(a.testProperties.Data, nil) |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | func (a *AndroidTest) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 334 | android.ExtractSourceDeps(ctx, a.testProperties.Test_config) |
Jack He | 3333889 | 2018-09-19 02:21:28 -0700 | [diff] [blame] | 335 | android.ExtractSourceDeps(ctx, a.testProperties.Test_config_template) |
Colin Cross | d96ca35 | 2018-08-10 16:06:24 -0700 | [diff] [blame] | 336 | android.ExtractSourcesDeps(ctx, a.testProperties.Data) |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 337 | a.AndroidApp.DepsMutator(ctx) |
Colin Cross | ae5caf5 | 2018-05-22 11:11:52 -0700 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | func AndroidTestFactory() android.Module { |
| 341 | module := &AndroidTest{} |
| 342 | |
| 343 | module.Module.deviceProperties.Optimize.Enabled = proptools.BoolPtr(true) |
Colin Cross | 5067db9 | 2018-09-17 16:46:35 -0700 | [diff] [blame] | 344 | |
| 345 | module.Module.properties.Instrument = true |
Colin Cross | 9ae1b92 | 2018-06-26 17:59:05 -0700 | [diff] [blame] | 346 | module.Module.properties.Installable = proptools.BoolPtr(true) |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 347 | module.appProperties.EmbedJNI = true |
Colin Cross | ae5caf5 | 2018-05-22 11:11:52 -0700 | [diff] [blame] | 348 | |
| 349 | module.AddProperties( |
| 350 | &module.Module.properties, |
| 351 | &module.Module.deviceProperties, |
| 352 | &module.Module.protoProperties, |
| 353 | &module.aaptProperties, |
| 354 | &module.appProperties, |
Dan Willemsen | f5531d2 | 2018-07-16 17:21:19 -0700 | [diff] [blame] | 355 | &module.appTestProperties, |
| 356 | &module.testProperties) |
Colin Cross | ae5caf5 | 2018-05-22 11:11:52 -0700 | [diff] [blame] | 357 | |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 358 | android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon) |
| 359 | android.InitDefaultableModule(module) |
Colin Cross | ae5caf5 | 2018-05-22 11:11:52 -0700 | [diff] [blame] | 360 | return module |
| 361 | } |
Colin Cross | bd01e2a | 2018-10-04 15:21:03 -0700 | [diff] [blame] | 362 | |
Colin Cross | 252fc6f | 2018-10-04 15:22:03 -0700 | [diff] [blame^] | 363 | type appTestHelperAppProperties struct { |
| 364 | // list of compatibility suites (for example "cts", "vts") that the module should be |
| 365 | // installed into. |
| 366 | Test_suites []string `android:"arch_variant"` |
| 367 | } |
| 368 | |
| 369 | type AndroidTestHelperApp struct { |
| 370 | AndroidApp |
| 371 | |
| 372 | appTestHelperAppProperties appTestHelperAppProperties |
| 373 | } |
| 374 | |
| 375 | func AndroidTestHelperAppFactory() android.Module { |
| 376 | module := &AndroidTestHelperApp{} |
| 377 | |
| 378 | module.Module.deviceProperties.Optimize.Enabled = proptools.BoolPtr(true) |
| 379 | |
| 380 | module.Module.properties.Installable = proptools.BoolPtr(true) |
| 381 | module.appProperties.EmbedJNI = true |
| 382 | |
| 383 | module.AddProperties( |
| 384 | &module.Module.properties, |
| 385 | &module.Module.deviceProperties, |
| 386 | &module.Module.protoProperties, |
| 387 | &module.aaptProperties, |
| 388 | &module.appProperties, |
| 389 | &module.appTestHelperAppProperties) |
| 390 | |
| 391 | android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon) |
| 392 | android.InitDefaultableModule(module) |
| 393 | return module |
| 394 | } |
| 395 | |
Colin Cross | bd01e2a | 2018-10-04 15:21:03 -0700 | [diff] [blame] | 396 | type AndroidAppCertificate struct { |
| 397 | android.ModuleBase |
| 398 | properties AndroidAppCertificateProperties |
| 399 | certificate certificate |
| 400 | } |
| 401 | |
| 402 | type AndroidAppCertificateProperties struct { |
| 403 | // Name of the certificate files. Extensions .x509.pem and .pk8 will be added to the name. |
| 404 | Certificate *string |
| 405 | } |
| 406 | |
| 407 | func AndroidAppCertificateFactory() android.Module { |
| 408 | module := &AndroidAppCertificate{} |
| 409 | module.AddProperties(&module.properties) |
| 410 | android.InitAndroidModule(module) |
| 411 | return module |
| 412 | } |
| 413 | |
| 414 | func (c *AndroidAppCertificate) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 415 | } |
| 416 | |
| 417 | func (c *AndroidAppCertificate) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 418 | cert := String(c.properties.Certificate) |
| 419 | c.certificate = certificate{ |
| 420 | android.PathForModuleSrc(ctx, cert+".x509.pem"), |
| 421 | android.PathForModuleSrc(ctx, cert+".pk8"), |
| 422 | } |
| 423 | } |