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 | "path/filepath" |
| 21 | "strings" |
| 22 | |
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 | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 26 | ) |
| 27 | |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame^] | 28 | func init() { |
| 29 | android.RegisterPreSingletonType("overlay", OverlaySingletonFactory) |
| 30 | } |
| 31 | |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 32 | // AAR prebuilts |
| 33 | // AndroidManifest.xml merging |
| 34 | // package splits |
| 35 | |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 36 | type androidAppProperties struct { |
| 37 | // path to a certificate, or the name of a certificate in the default |
| 38 | // certificate directory, or blank to use the default product certificate |
Nan Zhang | ea568a4 | 2017-11-08 21:20:04 -0800 | [diff] [blame] | 39 | Certificate *string |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 40 | |
| 41 | // paths to extra certificates to sign the apk with |
| 42 | Additional_certificates []string |
| 43 | |
| 44 | // If set, create package-export.apk, which other packages can |
| 45 | // use to get PRODUCT-agnostic resource data like IDs and type definitions. |
Nan Zhang | ea568a4 | 2017-11-08 21:20:04 -0800 | [diff] [blame] | 46 | Export_package_resources *bool |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 47 | |
| 48 | // flags passed to aapt when creating the apk |
| 49 | Aaptflags []string |
| 50 | |
| 51 | // list of resource labels to generate individual resource packages |
| 52 | Package_splits []string |
| 53 | |
| 54 | // list of directories relative to the Blueprints file containing assets. |
| 55 | // Defaults to "assets" |
| 56 | Asset_dirs []string |
| 57 | |
| 58 | // list of directories relative to the Blueprints file containing |
Colin Cross | 86a63ff | 2017-09-27 17:33:10 -0700 | [diff] [blame] | 59 | // Android resources |
| 60 | Resource_dirs []string |
Colin Cross | cb93359 | 2017-11-22 13:49:43 -0800 | [diff] [blame] | 61 | |
| 62 | Instrumentation_for *string |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 63 | } |
| 64 | |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 65 | type AndroidApp struct { |
Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 66 | Module |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 67 | |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 68 | appProperties androidAppProperties |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 69 | |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame^] | 70 | aaptSrcJar android.Path |
| 71 | exportPackage android.Path |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 72 | } |
| 73 | |
Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 74 | func (a *AndroidApp) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 75 | a.Module.deps(ctx) |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 76 | |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame^] | 77 | if !Bool(a.properties.No_framework_libs) && !Bool(a.properties.No_standard_libs) { |
Nan Zhang | ea568a4 | 2017-11-08 21:20:04 -0800 | [diff] [blame] | 78 | switch String(a.deviceProperties.Sdk_version) { // TODO: Res_sdk_version? |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 79 | case "current", "system_current", "": |
Colin Cross | be1da47 | 2017-07-07 15:59:46 -0700 | [diff] [blame] | 80 | ctx.AddDependency(ctx.Module(), frameworkResTag, "framework-res") |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 81 | default: |
| 82 | // We'll already have a dependency on an sdk prebuilt android.jar |
| 83 | } |
| 84 | } |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 85 | } |
| 86 | |
Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 87 | func (a *AndroidApp) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame^] | 88 | linkFlags, linkDeps, resDirs, overlayDirs := a.aapt2Flags(ctx) |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 89 | |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame^] | 90 | packageRes := android.PathForModuleOut(ctx, "package-res.apk") |
| 91 | srcJar := android.PathForModuleGen(ctx, "R.jar") |
| 92 | proguardOptionsFile := android.PathForModuleGen(ctx, "proguard.options") |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 93 | |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame^] | 94 | var compiledRes, compiledOverlay android.Paths |
| 95 | for _, dir := range resDirs { |
| 96 | compiledRes = append(compiledRes, aapt2Compile(ctx, dir.dir, dir.files).Paths()...) |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 97 | } |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame^] | 98 | for _, dir := range overlayDirs { |
| 99 | compiledOverlay = append(compiledOverlay, aapt2Compile(ctx, dir.dir, dir.files).Paths()...) |
| 100 | } |
| 101 | |
| 102 | aapt2Link(ctx, packageRes, srcJar, proguardOptionsFile, |
| 103 | linkFlags, linkDeps, compiledRes, compiledOverlay) |
| 104 | |
| 105 | a.exportPackage = packageRes |
| 106 | a.aaptSrcJar = srcJar |
| 107 | |
| 108 | ctx.CheckbuildFile(proguardOptionsFile) |
| 109 | ctx.CheckbuildFile(a.exportPackage) |
| 110 | ctx.CheckbuildFile(a.aaptSrcJar) |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 111 | |
Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 112 | // apps manifests are handled by aapt, don't let Module see them |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 113 | a.properties.Manifest = nil |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 114 | |
| 115 | //if !ctx.ContainsProperty("proguard.enabled") { |
| 116 | // a.properties.Proguard.Enabled = true |
| 117 | //} |
| 118 | |
Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 119 | a.Module.compile(ctx) |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 120 | |
Nan Zhang | ea568a4 | 2017-11-08 21:20:04 -0800 | [diff] [blame] | 121 | certificate := String(a.appProperties.Certificate) |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 122 | if certificate == "" { |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 123 | certificate = ctx.AConfig().DefaultAppCertificate(ctx).String() |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 124 | } else if dir, _ := filepath.Split(certificate); dir == "" { |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 125 | certificate = filepath.Join(ctx.AConfig().DefaultAppCertificateDir(ctx).String(), certificate) |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 126 | } else { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 127 | certificate = filepath.Join(android.PathForSource(ctx).String(), certificate) |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | certificates := []string{certificate} |
| 131 | for _, c := range a.appProperties.Additional_certificates { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 132 | certificates = append(certificates, filepath.Join(android.PathForSource(ctx).String(), c)) |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 133 | } |
| 134 | |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame^] | 135 | packageFile := android.PathForModuleOut(ctx, "package.apk") |
| 136 | |
| 137 | CreateAppPackage(ctx, packageFile, a.exportPackage, a.outputFile, certificates) |
| 138 | |
| 139 | a.outputFile = packageFile |
| 140 | |
Colin Cross | 5c51792 | 2017-08-31 12:29:17 -0700 | [diff] [blame] | 141 | ctx.InstallFile(android.PathForModuleInstall(ctx, "app"), ctx.ModuleName()+".apk", a.outputFile) |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | var aaptIgnoreFilenames = []string{ |
| 145 | ".svn", |
| 146 | ".git", |
| 147 | ".ds_store", |
| 148 | "*.scc", |
| 149 | ".*", |
| 150 | "CVS", |
| 151 | "thumbs.db", |
| 152 | "picasa.ini", |
| 153 | "*~", |
| 154 | } |
| 155 | |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame^] | 156 | type globbedResourceDir struct { |
| 157 | dir android.Path |
| 158 | files android.Paths |
| 159 | } |
| 160 | |
| 161 | func (a *AndroidApp) aapt2Flags(ctx android.ModuleContext) (flags []string, deps android.Paths, |
| 162 | resDirs, overlayDirs []globbedResourceDir) { |
| 163 | |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 164 | hasVersionCode := false |
| 165 | hasVersionName := false |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame^] | 166 | hasProduct := false |
| 167 | for _, f := range a.appProperties.Aaptflags { |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 168 | if strings.HasPrefix(f, "--version-code") { |
| 169 | hasVersionCode = true |
| 170 | } else if strings.HasPrefix(f, "--version-name") { |
| 171 | hasVersionName = true |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame^] | 172 | } else if strings.HasPrefix(f, "--product") { |
| 173 | hasProduct = true |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 174 | } |
| 175 | } |
| 176 | |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame^] | 177 | var linkFlags []string |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 178 | |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame^] | 179 | // Flags specified in Android.bp |
| 180 | linkFlags = append(linkFlags, a.appProperties.Aaptflags...) |
| 181 | |
| 182 | linkFlags = append(linkFlags, "--no-static-lib-packages") |
| 183 | |
| 184 | // Find implicit or explicit asset and resource dirs |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 185 | assetDirs := android.PathsWithOptionalDefaultForModuleSrc(ctx, a.appProperties.Asset_dirs, "assets") |
Colin Cross | 86a63ff | 2017-09-27 17:33:10 -0700 | [diff] [blame] | 186 | resourceDirs := android.PathsWithOptionalDefaultForModuleSrc(ctx, a.appProperties.Resource_dirs, "res") |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 187 | |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame^] | 188 | var linkDeps android.Paths |
| 189 | |
| 190 | // Glob directories into lists of paths |
| 191 | for _, dir := range resourceDirs { |
| 192 | resDirs = append(resDirs, globbedResourceDir{ |
| 193 | dir: dir, |
| 194 | files: resourceGlob(ctx, dir), |
| 195 | }) |
| 196 | overlayDirs = append(overlayDirs, overlayResourceGlob(ctx, dir)...) |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 197 | } |
| 198 | |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame^] | 199 | var assetFiles android.Paths |
| 200 | for _, dir := range assetDirs { |
| 201 | assetFiles = append(assetFiles, resourceGlob(ctx, dir)...) |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 202 | } |
| 203 | |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame^] | 204 | // App manifest file |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 205 | var manifestFile string |
| 206 | if a.properties.Manifest == nil { |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 207 | manifestFile = "AndroidManifest.xml" |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 208 | } else { |
| 209 | manifestFile = *a.properties.Manifest |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 210 | } |
| 211 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 212 | manifestPath := android.PathForModuleSrc(ctx, manifestFile) |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame^] | 213 | linkFlags = append(linkFlags, "--manifest "+manifestPath.String()) |
| 214 | linkDeps = append(linkDeps, manifestPath) |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 215 | |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame^] | 216 | linkFlags = append(linkFlags, android.JoinWithPrefix(assetDirs.Strings(), "-A ")) |
| 217 | linkDeps = append(linkDeps, assetFiles...) |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 218 | |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame^] | 219 | // Include dirs |
Colin Cross | d11fcda | 2017-10-23 17:59:01 -0700 | [diff] [blame] | 220 | ctx.VisitDirectDeps(func(module android.Module) { |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 221 | var depFiles android.Paths |
Colin Cross | fc3674a | 2017-09-18 17:41:52 -0700 | [diff] [blame] | 222 | if javaDep, ok := module.(Dependency); ok { |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame^] | 223 | // TODO: shared android libraries |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 224 | if ctx.OtherModuleName(module) == "framework-res" { |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 225 | depFiles = android.Paths{javaDep.(*AndroidApp).exportPackage} |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 226 | } |
| 227 | } |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 228 | |
| 229 | for _, dep := range depFiles { |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame^] | 230 | linkFlags = append(linkFlags, "-I "+dep.String()) |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 231 | } |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame^] | 232 | linkDeps = append(linkDeps, depFiles...) |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 233 | }) |
| 234 | |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame^] | 235 | // SDK version flags |
Nan Zhang | ea568a4 | 2017-11-08 21:20:04 -0800 | [diff] [blame] | 236 | sdkVersion := String(a.deviceProperties.Sdk_version) |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame^] | 237 | switch sdkVersion { |
| 238 | case "", "current", "system_current", "test_current": |
| 239 | sdkVersion = ctx.AConfig().AppsDefaultVersionName() |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 240 | } |
| 241 | |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame^] | 242 | linkFlags = append(linkFlags, "--min-sdk-version "+sdkVersion) |
| 243 | linkFlags = append(linkFlags, "--target-sdk-version "+sdkVersion) |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 244 | |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame^] | 245 | // Product characteristics |
| 246 | if !hasProduct && len(ctx.AConfig().ProductAAPTCharacteristics()) > 0 { |
| 247 | linkFlags = append(linkFlags, "--product", ctx.AConfig().ProductAAPTCharacteristics()) |
| 248 | } |
| 249 | |
| 250 | // Product AAPT config |
| 251 | for _, aaptConfig := range ctx.AConfig().ProductAAPTConfig() { |
| 252 | linkFlags = append(linkFlags, "-c", aaptConfig) |
| 253 | } |
| 254 | |
| 255 | // Product AAPT preferred config |
| 256 | if len(ctx.AConfig().ProductAAPTPreferredConfig()) > 0 { |
| 257 | linkFlags = append(linkFlags, "--preferred-density", ctx.AConfig().ProductAAPTPreferredConfig()) |
| 258 | } |
| 259 | |
| 260 | // Version code |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 261 | if !hasVersionCode { |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame^] | 262 | linkFlags = append(linkFlags, "--version-code", ctx.AConfig().PlatformSdkVersion()) |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | if !hasVersionName { |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame^] | 266 | versionName := proptools.NinjaEscape([]string{ctx.AConfig().AppsDefaultVersionName()})[0] |
| 267 | linkFlags = append(linkFlags, "--version-name ", versionName) |
| 268 | } |
| 269 | |
| 270 | if String(a.appProperties.Instrumentation_for) != "" { |
| 271 | linkFlags = append(linkFlags, |
| 272 | "--rename-instrumentation-target-package", |
| 273 | String(a.appProperties.Instrumentation_for)) |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | // TODO: LOCAL_PACKAGE_OVERRIDES |
| 277 | // $(addprefix --rename-manifest-package , $(PRIVATE_MANIFEST_PACKAGE_NAME)) \ |
| 278 | |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame^] | 279 | return linkFlags, linkDeps, resDirs, overlayDirs |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 280 | } |
| 281 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 282 | func AndroidAppFactory() android.Module { |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 283 | module := &AndroidApp{} |
| 284 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 285 | module.AddProperties( |
Colin Cross | 540eff8 | 2017-06-22 17:01:52 -0700 | [diff] [blame] | 286 | &module.Module.properties, |
| 287 | &module.Module.deviceProperties, |
| 288 | &module.appProperties) |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 289 | |
| 290 | android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibCommon) |
| 291 | return module |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 292 | } |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame^] | 293 | |
| 294 | func resourceGlob(ctx android.ModuleContext, dir android.Path) android.Paths { |
| 295 | var ret android.Paths |
| 296 | files := ctx.Glob(filepath.Join(dir.String(), "**/*"), aaptIgnoreFilenames) |
| 297 | for _, f := range files { |
| 298 | if isDir, err := ctx.Fs().IsDir(f.String()); err != nil { |
| 299 | ctx.ModuleErrorf("error in IsDir(%s): %s", f.String(), err.Error()) |
| 300 | return nil |
| 301 | } else if !isDir { |
| 302 | ret = append(ret, f) |
| 303 | } |
| 304 | } |
| 305 | return ret |
| 306 | } |
| 307 | |
| 308 | type overlayGlobResult struct { |
| 309 | dir string |
| 310 | paths android.DirectorySortedPaths |
| 311 | } |
| 312 | |
| 313 | const overlayDataKey = "overlayDataKey" |
| 314 | |
| 315 | func overlayResourceGlob(ctx android.ModuleContext, dir android.Path) []globbedResourceDir { |
| 316 | overlayData := ctx.AConfig().Get(overlayDataKey).([]overlayGlobResult) |
| 317 | |
| 318 | var ret []globbedResourceDir |
| 319 | |
| 320 | for _, data := range overlayData { |
| 321 | files := data.paths.PathsInDirectory(filepath.Join(data.dir, dir.String())) |
| 322 | if len(files) > 0 { |
| 323 | ret = append(ret, globbedResourceDir{ |
| 324 | dir: android.PathForSource(ctx, data.dir, dir.String()), |
| 325 | files: files, |
| 326 | }) |
| 327 | } |
| 328 | } |
| 329 | |
| 330 | return ret |
| 331 | } |
| 332 | |
| 333 | func OverlaySingletonFactory() android.Singleton { |
| 334 | return overlaySingleton{} |
| 335 | } |
| 336 | |
| 337 | type overlaySingleton struct{} |
| 338 | |
| 339 | func (overlaySingleton) GenerateBuildActions(ctx android.SingletonContext) { |
| 340 | var overlayData []overlayGlobResult |
| 341 | for _, overlay := range ctx.Config().(android.Config).ResourceOverlays() { |
| 342 | var result overlayGlobResult |
| 343 | result.dir = overlay |
| 344 | files, err := ctx.GlobWithDeps(filepath.Join(overlay, "**/*"), aaptIgnoreFilenames) |
| 345 | if err != nil { |
| 346 | ctx.Errorf("failed to glob resource dir %q: %s", overlay, err.Error()) |
| 347 | continue |
| 348 | } |
| 349 | var paths android.Paths |
| 350 | for _, f := range files { |
| 351 | if isDir, err := ctx.Fs().IsDir(f); err != nil { |
| 352 | ctx.Errorf("error in IsDir(%s): %s", f, err.Error()) |
| 353 | return |
| 354 | } else if !isDir { |
| 355 | paths = append(paths, android.PathForSource(ctx, f)) |
| 356 | } |
| 357 | } |
| 358 | result.paths = android.PathsToDirectorySortedPaths(paths) |
| 359 | overlayData = append(overlayData, result) |
| 360 | } |
| 361 | |
| 362 | ctx.Config().(android.Config).Once(overlayDataKey, func() interface{} { |
| 363 | return overlayData |
| 364 | }) |
| 365 | } |