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