blob: 07a97ede6387ded02c7a642bef24aa588b40f7ca [file] [log] [blame]
Colin Cross30e076a2015-04-13 13:58:27 -07001// 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
15package java
16
17// This file contains the module types for compiling Android apps.
18
19import (
Colin Cross43f08db2018-11-12 10:13:39 -080020 "path/filepath"
Colin Cross30e076a2015-04-13 13:58:27 -070021 "strings"
22
Colin Crossa4f08812018-10-02 22:03:40 -070023 "github.com/google/blueprint"
Colin Cross76b5f0c2017-08-29 16:02:06 -070024 "github.com/google/blueprint/proptools"
Colin Cross30e076a2015-04-13 13:58:27 -070025
Colin Cross635c3b02016-05-18 15:37:25 -070026 "android/soong/android"
Colin Crossa4f08812018-10-02 22:03:40 -070027 "android/soong/cc"
Colin Cross303e21f2018-08-07 16:49:25 -070028 "android/soong/tradefed"
Colin Cross30e076a2015-04-13 13:58:27 -070029)
30
Colin Cross3bc7ffa2017-11-22 16:19:37 -080031func init() {
Colin Cross5ab4e6d2017-11-22 16:20:45 -080032 android.RegisterModuleType("android_app", AndroidAppFactory)
Colin Crossae5caf52018-05-22 11:11:52 -070033 android.RegisterModuleType("android_test", AndroidTestFactory)
Colin Cross252fc6f2018-10-04 15:22:03 -070034 android.RegisterModuleType("android_test_helper_app", AndroidTestHelperAppFactory)
Colin Crossbd01e2a2018-10-04 15:21:03 -070035 android.RegisterModuleType("android_app_certificate", AndroidAppCertificateFactory)
Colin Cross3bc7ffa2017-11-22 16:19:37 -080036}
37
Colin Cross30e076a2015-04-13 13:58:27 -070038// AndroidManifest.xml merging
39// package splits
40
Colin Crossfabb6082018-02-20 17:22:23 -080041type appProperties struct {
Colin Crossbd01e2a2018-10-04 15:21:03 -070042 // 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 Zhangea568a42017-11-08 21:20:04 -080044 Certificate *string
Colin Cross7d5136f2015-05-11 13:39:40 -070045
Colin Crossbd01e2a2018-10-04 15:21:03 -070046 // Names of extra android_app_certificate modules to sign the apk with in the form ":module".
Colin Cross7d5136f2015-05-11 13:39:40 -070047 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 Zhangea568a42017-11-08 21:20:04 -080051 Export_package_resources *bool
Colin Cross7d5136f2015-05-11 13:39:40 -070052
Colin Cross16056062017-12-13 22:46:28 -080053 // 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 Crossa97c5d32018-03-28 14:58:31 -070057
58 // list of resource labels to generate individual resource packages
59 Package_splits []string
Jason Monkd4122be2018-08-10 09:33:36 -040060
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 Crossa4f08812018-10-02 22:03:40 -070067
68 // list of native libraries that will be provided in or alongside the resulting jar
69 Jni_libs []string `android:"arch_variant"`
70
Colin Cross43f08db2018-11-12 10:13:39 -080071 EmbedJNI bool `blueprint:"mutated"`
Colin Cross7d5136f2015-05-11 13:39:40 -070072}
73
Colin Cross30e076a2015-04-13 13:58:27 -070074type AndroidApp struct {
Colin Crossa97c5d32018-03-28 14:58:31 -070075 Library
76 aapt
77
Jiyong Parkc00cbd92018-10-30 21:20:05 +090078 certificate Certificate
Colin Cross30e076a2015-04-13 13:58:27 -070079
Colin Crossfabb6082018-02-20 17:22:23 -080080 appProperties appProperties
Colin Crossae5caf52018-05-22 11:11:52 -070081
Colin Crossa4f08812018-10-02 22:03:40 -070082 installJniLibs []jniLib
Colin Crossf6237212018-10-29 23:14:58 -070083
84 bundleFile android.Path
Colin Crosse1731a52017-12-14 11:22:55 -080085}
86
Colin Cross89c31582018-04-30 15:55:11 -070087func (a *AndroidApp) ExportedProguardFlagFiles() android.Paths {
88 return nil
89}
90
Colin Cross66f78822018-05-02 12:58:28 -070091func (a *AndroidApp) ExportedStaticPackages() android.Paths {
92 return nil
93}
94
Colin Cross31656952018-05-24 16:11:20 -070095func (a *AndroidApp) ExportedManifest() android.Path {
96 return a.manifestPath
97}
98
Colin Crossa97c5d32018-03-28 14:58:31 -070099var _ AndroidLibraryDependency = (*AndroidApp)(nil)
100
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900101type Certificate struct {
102 Pem, Key android.Path
Colin Cross30e076a2015-04-13 13:58:27 -0700103}
104
Colin Cross46c9b8b2017-06-22 16:51:17 -0700105func (a *AndroidApp) DepsMutator(ctx android.BottomUpMutatorContext) {
106 a.Module.deps(ctx)
Colin Crossa4f08812018-10-02 22:03:40 -0700107
Colin Cross3bc7ffa2017-11-22 16:19:37 -0800108 if !Bool(a.properties.No_framework_libs) && !Bool(a.properties.No_standard_libs) {
Colin Cross83bb3162018-06-25 15:48:06 -0700109 a.aapt.deps(ctx, sdkContext(a))
Colin Cross30e076a2015-04-13 13:58:27 -0700110 }
Colin Crossa4f08812018-10-02 22:03:40 -0700111
112 for _, jniTarget := range ctx.MultiTargets() {
113 variation := []blueprint.Variation{
114 {Mutator: "arch", Variation: jniTarget.String()},
115 {Mutator: "link", Variation: "shared"},
116 }
117 tag := &jniDependencyTag{
118 target: jniTarget,
119 }
120 ctx.AddFarVariationDependencies(variation, tag, a.appProperties.Jni_libs...)
121 }
Colin Crossbd01e2a2018-10-04 15:21:03 -0700122
Jaewoong Jung2ad817c2019-01-18 14:27:16 -0800123 cert := android.SrcIsModule(a.getCertString(ctx))
Colin Crossbd01e2a2018-10-04 15:21:03 -0700124 if cert != "" {
125 ctx.AddDependency(ctx.Module(), certificateTag, cert)
126 }
127
128 for _, cert := range a.appProperties.Additional_certificates {
129 cert = android.SrcIsModule(cert)
130 if cert != "" {
131 ctx.AddDependency(ctx.Module(), certificateTag, cert)
132 } else {
133 ctx.PropertyErrorf("additional_certificates",
134 `must be names of android_app_certificate modules in the form ":module"`)
135 }
136 }
Colin Cross30e076a2015-04-13 13:58:27 -0700137}
138
Colin Cross46c9b8b2017-06-22 16:51:17 -0700139func (a *AndroidApp) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Crossae5caf52018-05-22 11:11:52 -0700140 a.generateAndroidBuildActions(ctx)
141}
142
Colin Cross43f08db2018-11-12 10:13:39 -0800143// Returns whether this module should have the dex file stored uncompressed in the APK.
144func (a *AndroidApp) shouldUncompressDex(ctx android.ModuleContext) bool {
Colin Cross5a0dcd52018-10-05 14:20:06 -0700145 if ctx.Config().UnbundledBuild() {
Colin Cross43f08db2018-11-12 10:13:39 -0800146 return false
Colin Cross5a0dcd52018-10-05 14:20:06 -0700147 }
148
Colin Cross5a0dcd52018-10-05 14:20:06 -0700149 // Uncompress dex in APKs of privileged apps, and modules used by privileged apps.
Colin Cross43f08db2018-11-12 10:13:39 -0800150 return ctx.Config().UncompressPrivAppDex() &&
Colin Cross5a0dcd52018-10-05 14:20:06 -0700151 (Bool(a.appProperties.Privileged) ||
Colin Cross43f08db2018-11-12 10:13:39 -0800152 inList(ctx.ModuleName(), ctx.Config().ModulesLoadedByPrivilegedModules()))
Colin Cross5a0dcd52018-10-05 14:20:06 -0700153}
154
Colin Crossae5caf52018-05-22 11:11:52 -0700155func (a *AndroidApp) generateAndroidBuildActions(ctx android.ModuleContext) {
Jaewoong Jungde4c02f2019-01-22 11:19:56 -0800156 aaptLinkFlags := []string{}
Colin Cross3bc7ffa2017-11-22 16:19:37 -0800157
Jaewoong Jungde4c02f2019-01-22 11:19:56 -0800158 // Add TARGET_AAPT_CHARACTERISTICS values to AAPT link flags if they exist and --product flags were not provided.
Colin Crosse78dcd32018-04-19 15:25:19 -0700159 hasProduct := false
160 for _, f := range a.aaptProperties.Aaptflags {
161 if strings.HasPrefix(f, "--product") {
162 hasProduct = true
Jaewoong Jungde4c02f2019-01-22 11:19:56 -0800163 break
Colin Crosse78dcd32018-04-19 15:25:19 -0700164 }
165 }
Colin Crosse78dcd32018-04-19 15:25:19 -0700166 if !hasProduct && len(ctx.Config().ProductAAPTCharacteristics()) > 0 {
Jaewoong Jungde4c02f2019-01-22 11:19:56 -0800167 aaptLinkFlags = append(aaptLinkFlags, "--product", ctx.Config().ProductAAPTCharacteristics())
Colin Crosse78dcd32018-04-19 15:25:19 -0700168 }
169
Dan Willemsen72be5902018-10-24 20:24:57 -0700170 if !Bool(a.aaptProperties.Aapt_include_all_resources) {
171 // Product AAPT config
172 for _, aaptConfig := range ctx.Config().ProductAAPTConfig() {
Jaewoong Jungde4c02f2019-01-22 11:19:56 -0800173 aaptLinkFlags = append(aaptLinkFlags, "-c", aaptConfig)
Dan Willemsen72be5902018-10-24 20:24:57 -0700174 }
Colin Crosse78dcd32018-04-19 15:25:19 -0700175
Dan Willemsen72be5902018-10-24 20:24:57 -0700176 // Product AAPT preferred config
177 if len(ctx.Config().ProductAAPTPreferredConfig()) > 0 {
Jaewoong Jungde4c02f2019-01-22 11:19:56 -0800178 aaptLinkFlags = append(aaptLinkFlags, "--preferred-density", ctx.Config().ProductAAPTPreferredConfig())
Dan Willemsen72be5902018-10-24 20:24:57 -0700179 }
Colin Crosse78dcd32018-04-19 15:25:19 -0700180 }
181
Colin Crossa97c5d32018-03-28 14:58:31 -0700182 // TODO: LOCAL_PACKAGE_OVERRIDES
183 // $(addprefix --rename-manifest-package , $(PRIVATE_MANIFEST_PACKAGE_NAME)) \
Colin Cross3bc7ffa2017-11-22 16:19:37 -0800184
Jiyong Park7f67f482019-01-05 12:57:48 +0900185 manifestPackageName, overridden := ctx.DeviceConfig().OverrideManifestPackageNameFor(ctx.ModuleName())
186 if overridden {
Jaewoong Jungde4c02f2019-01-22 11:19:56 -0800187 aaptLinkFlags = append(aaptLinkFlags, "--rename-manifest-package "+manifestPackageName)
Jiyong Park7f67f482019-01-05 12:57:48 +0900188 }
189
Jaewoong Jungde4c02f2019-01-22 11:19:56 -0800190 a.aapt.buildActions(ctx, sdkContext(a), aaptLinkFlags...)
Colin Cross30e076a2015-04-13 13:58:27 -0700191
Colin Cross46c9b8b2017-06-22 16:51:17 -0700192 // apps manifests are handled by aapt, don't let Module see them
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700193 a.properties.Manifest = nil
Colin Cross30e076a2015-04-13 13:58:27 -0700194
Colin Cross89c31582018-04-30 15:55:11 -0700195 var staticLibProguardFlagFiles android.Paths
196 ctx.VisitDirectDeps(func(m android.Module) {
197 if lib, ok := m.(AndroidLibraryDependency); ok && ctx.OtherModuleDependencyTag(m) == staticLibTag {
198 staticLibProguardFlagFiles = append(staticLibProguardFlagFiles, lib.ExportedProguardFlagFiles()...)
199 }
200 })
201
202 staticLibProguardFlagFiles = android.FirstUniquePaths(staticLibProguardFlagFiles)
203
204 a.Module.extraProguardFlagFiles = append(a.Module.extraProguardFlagFiles, staticLibProguardFlagFiles...)
205 a.Module.extraProguardFlagFiles = append(a.Module.extraProguardFlagFiles, a.proguardOptionsFile)
Colin Cross66dbc0b2017-12-28 12:23:20 -0800206
Colin Cross43f08db2018-11-12 10:13:39 -0800207 a.deviceProperties.UncompressDex = a.shouldUncompressDex(ctx)
208
209 var installDir string
210 if ctx.ModuleName() == "framework-res" {
211 // framework-res.apk is installed as system/framework/framework-res.apk
212 installDir = "framework"
213 } else if Bool(a.appProperties.Privileged) {
214 installDir = filepath.Join("priv-app", ctx.ModuleName())
215 } else {
216 installDir = filepath.Join("app", ctx.ModuleName())
217 }
218 a.dexpreopter.installPath = android.PathForModuleInstall(ctx, installDir, ctx.ModuleName()+".apk")
Colin Cross5a0dcd52018-10-05 14:20:06 -0700219
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800220 if ctx.ModuleName() != "framework-res" {
221 a.Module.compile(ctx, a.aaptSrcJar)
222 }
Colin Cross30e076a2015-04-13 13:58:27 -0700223
Colin Cross43f08db2018-11-12 10:13:39 -0800224 dexJarFile := a.maybeStrippedDexJarFile
Colin Cross3bc7ffa2017-11-22 16:19:37 -0800225
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900226 var certificates []Certificate
Colin Crossbd01e2a2018-10-04 15:21:03 -0700227
Colin Crossa4f08812018-10-02 22:03:40 -0700228 var jniJarFile android.WritablePath
Colin Crossbd01e2a2018-10-04 15:21:03 -0700229 jniLibs, certificateDeps := a.collectAppDeps(ctx)
Colin Crossa4f08812018-10-02 22:03:40 -0700230 if len(jniLibs) > 0 {
231 embedJni := ctx.Config().UnbundledBuild() || a.appProperties.EmbedJNI
232 if embedJni {
233 jniJarFile = android.PathForModuleOut(ctx, "jnilibs.zip")
234 TransformJniLibsToJar(ctx, jniJarFile, jniLibs)
235 } else {
236 a.installJniLibs = jniLibs
237 }
238 }
239
Colin Crossbd01e2a2018-10-04 15:21:03 -0700240 if ctx.Failed() {
241 return
242 }
243
Jaewoong Jung2ad817c2019-01-18 14:27:16 -0800244 cert := a.getCertString(ctx)
Colin Crossbd01e2a2018-10-04 15:21:03 -0700245 certModule := android.SrcIsModule(cert)
246 if certModule != "" {
247 a.certificate = certificateDeps[0]
248 certificateDeps = certificateDeps[1:]
249 } else if cert != "" {
250 defaultDir := ctx.Config().DefaultAppCertificateDir(ctx)
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900251 a.certificate = Certificate{
Colin Crossbd01e2a2018-10-04 15:21:03 -0700252 defaultDir.Join(ctx, cert+".x509.pem"),
253 defaultDir.Join(ctx, cert+".pk8"),
254 }
255 } else {
256 pem, key := ctx.Config().DefaultAppCertificate(ctx)
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900257 a.certificate = Certificate{pem, key}
Colin Crossbd01e2a2018-10-04 15:21:03 -0700258 }
259
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900260 certificates = append([]Certificate{a.certificate}, certificateDeps...)
Colin Crossbd01e2a2018-10-04 15:21:03 -0700261
Colin Cross5a1af882019-01-17 14:31:52 -0800262 packageFile := android.PathForModuleOut(ctx, ctx.ModuleName()+".apk")
Colin Cross5a0dcd52018-10-05 14:20:06 -0700263 CreateAppPackage(ctx, packageFile, a.exportPackage, jniJarFile, dexJarFile, certificates)
Jeongik Chac9464142019-01-07 12:07:27 +0900264
265 if !a.Module.Platform() {
266 certPath := a.certificate.Pem.String()
267 systemCertPath := ctx.Config().DefaultAppCertificateDir(ctx).String()
268 if strings.HasPrefix(certPath, systemCertPath) {
269 enforceSystemCert := ctx.Config().EnforceSystemCertificate()
270 whitelist := ctx.Config().EnforceSystemCertificateWhitelist()
271
272 if enforceSystemCert && !inList(a.Module.Name(), whitelist) {
273 ctx.PropertyErrorf("certificate", "The module in product partition cannot be signed with certificate in system.")
274 }
275 }
276 }
277
Colin Cross3bc7ffa2017-11-22 16:19:37 -0800278 a.outputFile = packageFile
279
Colin Crossf6237212018-10-29 23:14:58 -0700280 bundleFile := android.PathForModuleOut(ctx, "base.zip")
281 BuildBundleModule(ctx, bundleFile, a.exportPackage, jniJarFile, dexJarFile)
282 a.bundleFile = bundleFile
283
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800284 if ctx.ModuleName() == "framework-res" {
285 // framework-res.apk is installed as system/framework/framework-res.apk
286 ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"), ctx.ModuleName()+".apk", a.outputFile)
Colin Cross16056062017-12-13 22:46:28 -0800287 } else if Bool(a.appProperties.Privileged) {
Colin Cross43f08db2018-11-12 10:13:39 -0800288 ctx.InstallFile(android.PathForModuleInstall(ctx, "priv-app", ctx.ModuleName()), ctx.ModuleName()+".apk", a.outputFile)
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800289 } else {
Colin Cross43f08db2018-11-12 10:13:39 -0800290 ctx.InstallFile(android.PathForModuleInstall(ctx, "app", ctx.ModuleName()), ctx.ModuleName()+".apk", a.outputFile)
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800291 }
Colin Cross30e076a2015-04-13 13:58:27 -0700292}
293
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900294func (a *AndroidApp) collectAppDeps(ctx android.ModuleContext) ([]jniLib, []Certificate) {
Colin Crossa4f08812018-10-02 22:03:40 -0700295 var jniLibs []jniLib
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900296 var certificates []Certificate
Colin Crossa4f08812018-10-02 22:03:40 -0700297
298 ctx.VisitDirectDeps(func(module android.Module) {
299 otherName := ctx.OtherModuleName(module)
300 tag := ctx.OtherModuleDependencyTag(module)
301
302 if jniTag, ok := tag.(*jniDependencyTag); ok {
303 if dep, ok := module.(*cc.Module); ok {
304 lib := dep.OutputFile()
305 if lib.Valid() {
306 jniLibs = append(jniLibs, jniLib{
307 name: ctx.OtherModuleName(module),
308 path: lib.Path(),
309 target: jniTag.target,
310 })
311 } else {
312 ctx.ModuleErrorf("dependency %q missing output file", otherName)
313 }
314 } else {
315 ctx.ModuleErrorf("jni_libs dependency %q must be a cc library", otherName)
316
317 }
Colin Crossbd01e2a2018-10-04 15:21:03 -0700318 } else if tag == certificateTag {
319 if dep, ok := module.(*AndroidAppCertificate); ok {
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900320 certificates = append(certificates, dep.Certificate)
Colin Crossbd01e2a2018-10-04 15:21:03 -0700321 } else {
322 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", otherName)
323 }
Colin Crossa4f08812018-10-02 22:03:40 -0700324 }
325 })
326
Colin Crossbd01e2a2018-10-04 15:21:03 -0700327 return jniLibs, certificates
Colin Crossa4f08812018-10-02 22:03:40 -0700328}
329
Jaewoong Jung2ad817c2019-01-18 14:27:16 -0800330func (a *AndroidApp) getCertString(ctx android.BaseContext) string {
331 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(ctx.ModuleName())
332 if overridden {
333 return ":" + certificate
334 }
335 return String(a.appProperties.Certificate)
336}
337
Colin Cross36242852017-06-23 15:06:31 -0700338func AndroidAppFactory() android.Module {
Colin Cross30e076a2015-04-13 13:58:27 -0700339 module := &AndroidApp{}
340
Colin Cross66dbc0b2017-12-28 12:23:20 -0800341 module.Module.deviceProperties.Optimize.Enabled = proptools.BoolPtr(true)
342 module.Module.deviceProperties.Optimize.Shrink = proptools.BoolPtr(true)
343
Colin Crossae5caf52018-05-22 11:11:52 -0700344 module.Module.properties.Instrument = true
Colin Cross9ae1b922018-06-26 17:59:05 -0700345 module.Module.properties.Installable = proptools.BoolPtr(true)
Colin Crossae5caf52018-05-22 11:11:52 -0700346
Colin Cross36242852017-06-23 15:06:31 -0700347 module.AddProperties(
Colin Cross540eff82017-06-22 17:01:52 -0700348 &module.Module.properties,
349 &module.Module.deviceProperties,
Colin Cross43f08db2018-11-12 10:13:39 -0800350 &module.Module.dexpreoptProperties,
Colin Crossa97c5d32018-03-28 14:58:31 -0700351 &module.Module.protoProperties,
352 &module.aaptProperties,
Colin Cross540eff82017-06-22 17:01:52 -0700353 &module.appProperties)
Colin Cross36242852017-06-23 15:06:31 -0700354
Colin Crossa9d8bee2018-10-02 13:59:46 -0700355 module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
356 return class == android.Device && ctx.Config().DevicePrefer32BitApps()
357 })
358
Colin Crossa4f08812018-10-02 22:03:40 -0700359 android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
360 android.InitDefaultableModule(module)
361
Colin Cross36242852017-06-23 15:06:31 -0700362 return module
Colin Cross30e076a2015-04-13 13:58:27 -0700363}
Colin Crossae5caf52018-05-22 11:11:52 -0700364
365type appTestProperties struct {
366 Instrumentation_for *string
367}
368
369type AndroidTest struct {
370 AndroidApp
371
372 appTestProperties appTestProperties
373
374 testProperties testProperties
Colin Cross303e21f2018-08-07 16:49:25 -0700375
376 testConfig android.Path
Colin Crossd96ca352018-08-10 16:06:24 -0700377 data android.Paths
Colin Crossae5caf52018-05-22 11:11:52 -0700378}
379
380func (a *AndroidTest) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Crossae5caf52018-05-22 11:11:52 -0700381 a.generateAndroidBuildActions(ctx)
Colin Cross303e21f2018-08-07 16:49:25 -0700382
Jack He33338892018-09-19 02:21:28 -0700383 a.testConfig = tradefed.AutoGenInstrumentationTestConfig(ctx, a.testProperties.Test_config, a.testProperties.Test_config_template, a.manifestPath)
Colin Crossd96ca352018-08-10 16:06:24 -0700384 a.data = ctx.ExpandSources(a.testProperties.Data, nil)
Colin Cross303e21f2018-08-07 16:49:25 -0700385}
386
387func (a *AndroidTest) DepsMutator(ctx android.BottomUpMutatorContext) {
388 android.ExtractSourceDeps(ctx, a.testProperties.Test_config)
Jack He33338892018-09-19 02:21:28 -0700389 android.ExtractSourceDeps(ctx, a.testProperties.Test_config_template)
Colin Crossd96ca352018-08-10 16:06:24 -0700390 android.ExtractSourcesDeps(ctx, a.testProperties.Data)
Colin Cross303e21f2018-08-07 16:49:25 -0700391 a.AndroidApp.DepsMutator(ctx)
Colin Cross4b964c02018-10-15 16:18:06 -0700392 if a.appTestProperties.Instrumentation_for != nil {
393 // The android_app dependency listed in instrumentation_for needs to be added to the classpath for javac,
394 // but not added to the aapt2 link includes like a normal android_app or android_library dependency, so
395 // use instrumentationForTag instead of libTag.
396 ctx.AddVariationDependencies(nil, instrumentationForTag, String(a.appTestProperties.Instrumentation_for))
397 }
Colin Crossae5caf52018-05-22 11:11:52 -0700398}
399
400func AndroidTestFactory() android.Module {
401 module := &AndroidTest{}
402
403 module.Module.deviceProperties.Optimize.Enabled = proptools.BoolPtr(true)
Colin Cross5067db92018-09-17 16:46:35 -0700404
405 module.Module.properties.Instrument = true
Colin Cross9ae1b922018-06-26 17:59:05 -0700406 module.Module.properties.Installable = proptools.BoolPtr(true)
Colin Crossa4f08812018-10-02 22:03:40 -0700407 module.appProperties.EmbedJNI = true
Colin Cross43f08db2018-11-12 10:13:39 -0800408 module.Module.dexpreopter.isTest = true
Colin Crossae5caf52018-05-22 11:11:52 -0700409
410 module.AddProperties(
411 &module.Module.properties,
412 &module.Module.deviceProperties,
Colin Cross43f08db2018-11-12 10:13:39 -0800413 &module.Module.dexpreoptProperties,
Colin Crossae5caf52018-05-22 11:11:52 -0700414 &module.Module.protoProperties,
415 &module.aaptProperties,
416 &module.appProperties,
Dan Willemsenf5531d22018-07-16 17:21:19 -0700417 &module.appTestProperties,
418 &module.testProperties)
Colin Crossae5caf52018-05-22 11:11:52 -0700419
Colin Crossa4f08812018-10-02 22:03:40 -0700420 android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
421 android.InitDefaultableModule(module)
Colin Crossae5caf52018-05-22 11:11:52 -0700422 return module
423}
Colin Crossbd01e2a2018-10-04 15:21:03 -0700424
Colin Cross252fc6f2018-10-04 15:22:03 -0700425type appTestHelperAppProperties struct {
426 // list of compatibility suites (for example "cts", "vts") that the module should be
427 // installed into.
428 Test_suites []string `android:"arch_variant"`
429}
430
431type AndroidTestHelperApp struct {
432 AndroidApp
433
434 appTestHelperAppProperties appTestHelperAppProperties
435}
436
437func AndroidTestHelperAppFactory() android.Module {
438 module := &AndroidTestHelperApp{}
439
440 module.Module.deviceProperties.Optimize.Enabled = proptools.BoolPtr(true)
441
442 module.Module.properties.Installable = proptools.BoolPtr(true)
443 module.appProperties.EmbedJNI = true
Colin Cross43f08db2018-11-12 10:13:39 -0800444 module.Module.dexpreopter.isTest = true
Colin Cross252fc6f2018-10-04 15:22:03 -0700445
446 module.AddProperties(
447 &module.Module.properties,
448 &module.Module.deviceProperties,
Colin Cross43f08db2018-11-12 10:13:39 -0800449 &module.Module.dexpreoptProperties,
Colin Cross252fc6f2018-10-04 15:22:03 -0700450 &module.Module.protoProperties,
451 &module.aaptProperties,
452 &module.appProperties,
453 &module.appTestHelperAppProperties)
454
455 android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
456 android.InitDefaultableModule(module)
457 return module
458}
459
Colin Crossbd01e2a2018-10-04 15:21:03 -0700460type AndroidAppCertificate struct {
461 android.ModuleBase
462 properties AndroidAppCertificateProperties
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900463 Certificate Certificate
Colin Crossbd01e2a2018-10-04 15:21:03 -0700464}
465
466type AndroidAppCertificateProperties struct {
467 // Name of the certificate files. Extensions .x509.pem and .pk8 will be added to the name.
468 Certificate *string
469}
470
471func AndroidAppCertificateFactory() android.Module {
472 module := &AndroidAppCertificate{}
473 module.AddProperties(&module.properties)
474 android.InitAndroidModule(module)
475 return module
476}
477
478func (c *AndroidAppCertificate) DepsMutator(ctx android.BottomUpMutatorContext) {
479}
480
481func (c *AndroidAppCertificate) GenerateAndroidBuildActions(ctx android.ModuleContext) {
482 cert := String(c.properties.Certificate)
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900483 c.Certificate = Certificate{
Colin Crossbd01e2a2018-10-04 15:21:03 -0700484 android.PathForModuleSrc(ctx, cert+".x509.pem"),
485 android.PathForModuleSrc(ctx, cert+".pk8"),
486 }
487}