Colin Cross | f0056cb | 2017-12-22 15:56:08 -0800 | [diff] [blame] | 1 | // Copyright 2017 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 | import ( |
| 18 | "strings" |
| 19 | |
| 20 | "github.com/google/blueprint" |
David Srbecky | e033cba | 2020-05-20 22:20:28 +0100 | [diff] [blame] | 21 | "github.com/google/blueprint/proptools" |
Colin Cross | f0056cb | 2017-12-22 15:56:08 -0800 | [diff] [blame] | 22 | |
| 23 | "android/soong/android" |
Ramy Medhat | 1dcc27e | 2020-04-21 21:36:23 -0400 | [diff] [blame] | 24 | "android/soong/remoteexec" |
Colin Cross | f0056cb | 2017-12-22 15:56:08 -0800 | [diff] [blame] | 25 | ) |
| 26 | |
Liz Kammer | a7a64f3 | 2020-07-09 15:16:41 -0700 | [diff] [blame] | 27 | type DexProperties struct { |
| 28 | // If set to true, compile dex regardless of installable. Defaults to false. |
| 29 | Compile_dex *bool |
| 30 | |
| 31 | // list of module-specific flags that will be used for dex compiles |
| 32 | Dxflags []string `android:"arch_variant"` |
| 33 | |
| 34 | Optimize struct { |
| 35 | // If false, disable all optimization. Defaults to true for android_app and android_test |
| 36 | // modules, false for java_library and java_test modules. |
| 37 | Enabled *bool |
| 38 | // True if the module containing this has it set by default. |
| 39 | EnabledByDefault bool `blueprint:"mutated"` |
| 40 | |
Christoffer Quist Adamsen | f2d7b16 | 2020-08-24 15:56:16 +0200 | [diff] [blame] | 41 | // If true, runs R8 in Proguard compatibility mode (default). |
| 42 | // Otherwise, runs R8 in full mode. |
| 43 | Proguard_compatibility *bool |
| 44 | |
Liz Kammer | a7a64f3 | 2020-07-09 15:16:41 -0700 | [diff] [blame] | 45 | // If true, optimize for size by removing unused code. Defaults to true for apps, |
| 46 | // false for libraries and tests. |
| 47 | Shrink *bool |
| 48 | |
| 49 | // If true, optimize bytecode. Defaults to false. |
| 50 | Optimize *bool |
| 51 | |
| 52 | // If true, obfuscate bytecode. Defaults to false. |
| 53 | Obfuscate *bool |
| 54 | |
| 55 | // If true, do not use the flag files generated by aapt that automatically keep |
| 56 | // classes referenced by the app manifest. Defaults to false. |
| 57 | No_aapt_flags *bool |
| 58 | |
| 59 | // Flags to pass to proguard. |
| 60 | Proguard_flags []string |
| 61 | |
| 62 | // Specifies the locations of files containing proguard flags. |
| 63 | Proguard_flags_files []string `android:"path"` |
| 64 | } |
| 65 | |
| 66 | // Keep the data uncompressed. We always need uncompressed dex for execution, |
| 67 | // so this might actually save space by avoiding storing the same data twice. |
| 68 | // This defaults to reasonable value based on module and should not be set. |
| 69 | // It exists only to support ART tests. |
| 70 | Uncompress_dex *bool |
| 71 | } |
| 72 | |
| 73 | type dexer struct { |
| 74 | dexProperties DexProperties |
| 75 | |
| 76 | // list of extra proguard flag files |
| 77 | extraProguardFlagFiles android.Paths |
| 78 | proguardDictionary android.OptionalPath |
Colin Cross | cb6143a | 2020-08-14 17:39:29 -0700 | [diff] [blame] | 79 | proguardUsageZip android.OptionalPath |
Liz Kammer | a7a64f3 | 2020-07-09 15:16:41 -0700 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | func (d *dexer) effectiveOptimizeEnabled() bool { |
| 83 | return BoolDefault(d.dexProperties.Optimize.Enabled, d.dexProperties.Optimize.EnabledByDefault) |
| 84 | } |
| 85 | |
Kousik Kumar | 366afc5 | 2020-05-20 11:27:16 -0700 | [diff] [blame] | 86 | var d8, d8RE = remoteexec.MultiCommandStaticRules(pctx, "d8", |
Colin Cross | f0056cb | 2017-12-22 15:56:08 -0800 | [diff] [blame] | 87 | blueprint.RuleParams{ |
| 88 | Command: `rm -rf "$outDir" && mkdir -p "$outDir" && ` + |
Kousik Kumar | 366afc5 | 2020-05-20 11:27:16 -0700 | [diff] [blame] | 89 | `$d8Template${config.D8Cmd} ${config.DexFlags} --output $outDir $d8Flags $in && ` + |
| 90 | `$zipTemplate${config.SoongZipCmd} $zipFlags -o $outDir/classes.dex.jar -C $outDir -f "$outDir/classes*.dex" && ` + |
Colin Cross | 4c03f68 | 2018-07-15 08:16:31 -0700 | [diff] [blame] | 91 | `${config.MergeZipsCmd} -D -stripFile "**/*.class" $out $outDir/classes.dex.jar $in`, |
Colin Cross | f0056cb | 2017-12-22 15:56:08 -0800 | [diff] [blame] | 92 | CommandDeps: []string{ |
| 93 | "${config.D8Cmd}", |
| 94 | "${config.SoongZipCmd}", |
| 95 | "${config.MergeZipsCmd}", |
| 96 | }, |
Kousik Kumar | 366afc5 | 2020-05-20 11:27:16 -0700 | [diff] [blame] | 97 | }, map[string]*remoteexec.REParams{ |
| 98 | "$d8Template": &remoteexec.REParams{ |
| 99 | Labels: map[string]string{"type": "compile", "compiler": "d8"}, |
| 100 | Inputs: []string{"${config.D8Jar}"}, |
| 101 | ExecStrategy: "${config.RED8ExecStrategy}", |
| 102 | ToolchainInputs: []string{"${config.JavaCmd}"}, |
| 103 | Platform: map[string]string{remoteexec.PoolKey: "${config.REJavaPool}"}, |
| 104 | }, |
| 105 | "$zipTemplate": &remoteexec.REParams{ |
| 106 | Labels: map[string]string{"type": "tool", "name": "soong_zip"}, |
| 107 | Inputs: []string{"${config.SoongZipCmd}", "$outDir"}, |
| 108 | OutputFiles: []string{"$outDir/classes.dex.jar"}, |
| 109 | ExecStrategy: "${config.RED8ExecStrategy}", |
| 110 | Platform: map[string]string{remoteexec.PoolKey: "${config.REJavaPool}"}, |
| 111 | }, |
Ramy Medhat | 1dcc27e | 2020-04-21 21:36:23 -0400 | [diff] [blame] | 112 | }, []string{"outDir", "d8Flags", "zipFlags"}, nil) |
Colin Cross | f0056cb | 2017-12-22 15:56:08 -0800 | [diff] [blame] | 113 | |
Kousik Kumar | 366afc5 | 2020-05-20 11:27:16 -0700 | [diff] [blame] | 114 | var r8, r8RE = remoteexec.MultiCommandStaticRules(pctx, "r8", |
Colin Cross | 66dbc0b | 2017-12-28 12:23:20 -0800 | [diff] [blame] | 115 | blueprint.RuleParams{ |
| 116 | Command: `rm -rf "$outDir" && mkdir -p "$outDir" && ` + |
Colin Cross | cb6143a | 2020-08-14 17:39:29 -0700 | [diff] [blame] | 117 | `rm -f "$outDict" && rm -rf "${outUsageDir}" && ` + |
| 118 | `mkdir -p $$(dirname ${outUsage}) && ` + |
Kousik Kumar | 366afc5 | 2020-05-20 11:27:16 -0700 | [diff] [blame] | 119 | `$r8Template${config.R8Cmd} ${config.DexFlags} -injars $in --output $outDir ` + |
Søren Gjesse | 24f1702 | 2018-09-14 15:20:42 +0200 | [diff] [blame] | 120 | `--no-data-resources ` + |
Colin Cross | cb6143a | 2020-08-14 17:39:29 -0700 | [diff] [blame] | 121 | `-printmapping ${outDict} ` + |
| 122 | `-printusage ${outUsage} ` + |
Colin Cross | ffb657e | 2018-09-21 12:29:22 -0700 | [diff] [blame] | 123 | `$r8Flags && ` + |
Colin Cross | cb6143a | 2020-08-14 17:39:29 -0700 | [diff] [blame] | 124 | `touch "${outDict}" "${outUsage}" && ` + |
| 125 | `${config.SoongZipCmd} -o ${outUsageZip} -C ${outUsageDir} -f ${outUsage} && ` + |
| 126 | `rm -rf ${outUsageDir} && ` + |
Kousik Kumar | 366afc5 | 2020-05-20 11:27:16 -0700 | [diff] [blame] | 127 | `$zipTemplate${config.SoongZipCmd} $zipFlags -o $outDir/classes.dex.jar -C $outDir -f "$outDir/classes*.dex" && ` + |
Colin Cross | 4c03f68 | 2018-07-15 08:16:31 -0700 | [diff] [blame] | 128 | `${config.MergeZipsCmd} -D -stripFile "**/*.class" $out $outDir/classes.dex.jar $in`, |
Colin Cross | 66dbc0b | 2017-12-28 12:23:20 -0800 | [diff] [blame] | 129 | CommandDeps: []string{ |
| 130 | "${config.R8Cmd}", |
| 131 | "${config.SoongZipCmd}", |
| 132 | "${config.MergeZipsCmd}", |
| 133 | }, |
Kousik Kumar | 366afc5 | 2020-05-20 11:27:16 -0700 | [diff] [blame] | 134 | }, map[string]*remoteexec.REParams{ |
| 135 | "$r8Template": &remoteexec.REParams{ |
| 136 | Labels: map[string]string{"type": "compile", "compiler": "r8"}, |
| 137 | Inputs: []string{"$implicits", "${config.R8Jar}"}, |
Colin Cross | e00c0e7 | 2020-09-17 11:54:30 -0700 | [diff] [blame] | 138 | OutputFiles: []string{"${outUsage}"}, |
Kousik Kumar | 366afc5 | 2020-05-20 11:27:16 -0700 | [diff] [blame] | 139 | ExecStrategy: "${config.RER8ExecStrategy}", |
| 140 | ToolchainInputs: []string{"${config.JavaCmd}"}, |
| 141 | Platform: map[string]string{remoteexec.PoolKey: "${config.REJavaPool}"}, |
| 142 | }, |
| 143 | "$zipTemplate": &remoteexec.REParams{ |
| 144 | Labels: map[string]string{"type": "tool", "name": "soong_zip"}, |
| 145 | Inputs: []string{"${config.SoongZipCmd}", "$outDir"}, |
| 146 | OutputFiles: []string{"$outDir/classes.dex.jar"}, |
| 147 | ExecStrategy: "${config.RER8ExecStrategy}", |
| 148 | Platform: map[string]string{remoteexec.PoolKey: "${config.REJavaPool}"}, |
| 149 | }, |
Colin Cross | cb6143a | 2020-08-14 17:39:29 -0700 | [diff] [blame] | 150 | "$zipUsageTemplate": &remoteexec.REParams{ |
| 151 | Labels: map[string]string{"type": "tool", "name": "soong_zip"}, |
| 152 | Inputs: []string{"${config.SoongZipCmd}", "${outUsage}"}, |
| 153 | OutputFiles: []string{"${outUsageZip}"}, |
| 154 | ExecStrategy: "${config.RER8ExecStrategy}", |
| 155 | Platform: map[string]string{remoteexec.PoolKey: "${config.REJavaPool}"}, |
| 156 | }, |
| 157 | }, []string{"outDir", "outDict", "outUsage", "outUsageZip", "outUsageDir", |
| 158 | "r8Flags", "zipFlags"}, []string{"implicits"}) |
Colin Cross | 66dbc0b | 2017-12-28 12:23:20 -0800 | [diff] [blame] | 159 | |
Liz Kammer | a7a64f3 | 2020-07-09 15:16:41 -0700 | [diff] [blame] | 160 | func (d *dexer) dexCommonFlags(ctx android.ModuleContext, minSdkVersion sdkSpec) []string { |
| 161 | flags := d.dexProperties.Dxflags |
Colin Cross | bafb897 | 2018-06-06 21:46:32 +0000 | [diff] [blame] | 162 | // Translate all the DX flags to D8 ones until all the build files have been migrated |
| 163 | // to D8 flags. See: b/69377755 |
| 164 | flags = android.RemoveListFromList(flags, |
| 165 | []string{"--core-library", "--dex", "--multi-dex"}) |
Colin Cross | f0056cb | 2017-12-22 15:56:08 -0800 | [diff] [blame] | 166 | |
| 167 | if ctx.Config().Getenv("NO_OPTIMIZE_DX") != "" { |
Colin Cross | bafb897 | 2018-06-06 21:46:32 +0000 | [diff] [blame] | 168 | flags = append(flags, "--debug") |
Colin Cross | f0056cb | 2017-12-22 15:56:08 -0800 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | if ctx.Config().Getenv("GENERATE_DEX_DEBUG") != "" { |
| 172 | flags = append(flags, |
| 173 | "--debug", |
| 174 | "--verbose") |
Colin Cross | f0056cb | 2017-12-22 15:56:08 -0800 | [diff] [blame] | 175 | } |
| 176 | |
Liz Kammer | a7a64f3 | 2020-07-09 15:16:41 -0700 | [diff] [blame] | 177 | effectiveVersion, err := minSdkVersion.effectiveVersion(ctx) |
Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 178 | if err != nil { |
| 179 | ctx.PropertyErrorf("min_sdk_version", "%s", err) |
| 180 | } |
| 181 | |
Liz Kammer | a7a64f3 | 2020-07-09 15:16:41 -0700 | [diff] [blame] | 182 | flags = append(flags, "--min-api "+effectiveVersion.asNumberString()) |
Colin Cross | f0056cb | 2017-12-22 15:56:08 -0800 | [diff] [blame] | 183 | return flags |
| 184 | } |
| 185 | |
Liz Kammer | a7a64f3 | 2020-07-09 15:16:41 -0700 | [diff] [blame] | 186 | func d8Flags(flags javaBuilderFlags) (d8Flags []string, d8Deps android.Paths) { |
Colin Cross | c2557d1 | 2019-10-31 15:22:57 -0700 | [diff] [blame] | 187 | d8Flags = append(d8Flags, flags.bootClasspath.FormRepeatedClassPath("--lib ")...) |
| 188 | d8Flags = append(d8Flags, flags.classpath.FormRepeatedClassPath("--lib ")...) |
Colin Cross | ffb657e | 2018-09-21 12:29:22 -0700 | [diff] [blame] | 189 | |
Colin Cross | 6dab9bd | 2018-09-28 08:06:24 -0700 | [diff] [blame] | 190 | d8Deps = append(d8Deps, flags.bootClasspath...) |
| 191 | d8Deps = append(d8Deps, flags.classpath...) |
| 192 | |
| 193 | return d8Flags, d8Deps |
Colin Cross | ffb657e | 2018-09-21 12:29:22 -0700 | [diff] [blame] | 194 | } |
| 195 | |
Liz Kammer | a7a64f3 | 2020-07-09 15:16:41 -0700 | [diff] [blame] | 196 | func (d *dexer) r8Flags(ctx android.ModuleContext, flags javaBuilderFlags) (r8Flags []string, r8Deps android.Paths) { |
| 197 | opt := d.dexProperties.Optimize |
Colin Cross | 66dbc0b | 2017-12-28 12:23:20 -0800 | [diff] [blame] | 198 | |
| 199 | // When an app contains references to APIs that are not in the SDK specified by |
| 200 | // its LOCAL_SDK_VERSION for example added by support library or by runtime |
Colin Cross | bafb897 | 2018-06-06 21:46:32 +0000 | [diff] [blame] | 201 | // classes added by desugaring, we artifically raise the "SDK version" "linked" by |
Colin Cross | 66dbc0b | 2017-12-28 12:23:20 -0800 | [diff] [blame] | 202 | // ProGuard, to |
| 203 | // - suppress ProGuard warnings of referencing symbols unknown to the lower SDK version. |
| 204 | // - prevent ProGuard stripping subclass in the support library that extends class added in the higher SDK version. |
| 205 | // See b/20667396 |
| 206 | var proguardRaiseDeps classpath |
| 207 | ctx.VisitDirectDepsWithTag(proguardRaiseTag, func(dep android.Module) { |
| 208 | proguardRaiseDeps = append(proguardRaiseDeps, dep.(Dependency).HeaderJars()...) |
| 209 | }) |
| 210 | |
| 211 | r8Flags = append(r8Flags, proguardRaiseDeps.FormJavaClassPath("-libraryjars")) |
| 212 | r8Flags = append(r8Flags, flags.bootClasspath.FormJavaClassPath("-libraryjars")) |
| 213 | r8Flags = append(r8Flags, flags.classpath.FormJavaClassPath("-libraryjars")) |
Colin Cross | 66dbc0b | 2017-12-28 12:23:20 -0800 | [diff] [blame] | 214 | |
Colin Cross | 6dab9bd | 2018-09-28 08:06:24 -0700 | [diff] [blame] | 215 | r8Deps = append(r8Deps, proguardRaiseDeps...) |
| 216 | r8Deps = append(r8Deps, flags.bootClasspath...) |
| 217 | r8Deps = append(r8Deps, flags.classpath...) |
| 218 | |
Colin Cross | 66dbc0b | 2017-12-28 12:23:20 -0800 | [diff] [blame] | 219 | flagFiles := android.Paths{ |
| 220 | android.PathForSource(ctx, "build/make/core/proguard.flags"), |
| 221 | } |
| 222 | |
Liz Kammer | a7a64f3 | 2020-07-09 15:16:41 -0700 | [diff] [blame] | 223 | flagFiles = append(flagFiles, d.extraProguardFlagFiles...) |
Colin Cross | 66dbc0b | 2017-12-28 12:23:20 -0800 | [diff] [blame] | 224 | // TODO(ccross): static android library proguard files |
| 225 | |
Liz Kammer | a7a64f3 | 2020-07-09 15:16:41 -0700 | [diff] [blame] | 226 | flagFiles = append(flagFiles, android.PathsForModuleSrc(ctx, opt.Proguard_flags_files)...) |
Colin Cross | bd1cef5 | 2018-08-13 10:28:18 -0700 | [diff] [blame] | 227 | |
Colin Cross | 66dbc0b | 2017-12-28 12:23:20 -0800 | [diff] [blame] | 228 | r8Flags = append(r8Flags, android.JoinWithPrefix(flagFiles.Strings(), "-include ")) |
| 229 | r8Deps = append(r8Deps, flagFiles...) |
| 230 | |
| 231 | // TODO(b/70942988): This is included from build/make/core/proguard.flags |
| 232 | r8Deps = append(r8Deps, android.PathForSource(ctx, |
| 233 | "build/make/core/proguard_basic_keeps.flags")) |
| 234 | |
Liz Kammer | a7a64f3 | 2020-07-09 15:16:41 -0700 | [diff] [blame] | 235 | r8Flags = append(r8Flags, opt.Proguard_flags...) |
Colin Cross | 66dbc0b | 2017-12-28 12:23:20 -0800 | [diff] [blame] | 236 | |
Christoffer Quist Adamsen | f2d7b16 | 2020-08-24 15:56:16 +0200 | [diff] [blame] | 237 | if BoolDefault(opt.Proguard_compatibility, true) { |
| 238 | r8Flags = append(r8Flags, "--force-proguard-compatibility") |
| 239 | } |
| 240 | |
Colin Cross | 66dbc0b | 2017-12-28 12:23:20 -0800 | [diff] [blame] | 241 | // TODO(ccross): Don't shrink app instrumentation tests by default. |
| 242 | if !Bool(opt.Shrink) { |
| 243 | r8Flags = append(r8Flags, "-dontshrink") |
| 244 | } |
| 245 | |
| 246 | if !Bool(opt.Optimize) { |
| 247 | r8Flags = append(r8Flags, "-dontoptimize") |
| 248 | } |
| 249 | |
| 250 | // TODO(ccross): error if obufscation + app instrumentation test. |
| 251 | if !Bool(opt.Obfuscate) { |
| 252 | r8Flags = append(r8Flags, "-dontobfuscate") |
| 253 | } |
Colin Cross | 4b964c0 | 2018-10-15 16:18:06 -0700 | [diff] [blame] | 254 | // TODO(ccross): if this is an instrumentation test of an obfuscated app, use the |
| 255 | // dictionary of the app and move the app from libraryjars to injars. |
Colin Cross | 66dbc0b | 2017-12-28 12:23:20 -0800 | [diff] [blame] | 256 | |
Jaewoong Jung | 1d6eb68 | 2018-11-29 15:08:44 -0800 | [diff] [blame] | 257 | // Don't strip out debug information for eng builds. |
| 258 | if ctx.Config().Eng() { |
| 259 | r8Flags = append(r8Flags, "--debug") |
| 260 | } |
| 261 | |
Colin Cross | 66dbc0b | 2017-12-28 12:23:20 -0800 | [diff] [blame] | 262 | return r8Flags, r8Deps |
| 263 | } |
| 264 | |
Liz Kammer | a7a64f3 | 2020-07-09 15:16:41 -0700 | [diff] [blame] | 265 | func (d *dexer) compileDex(ctx android.ModuleContext, flags javaBuilderFlags, minSdkVersion sdkSpec, |
Paul Duffin | 612e610 | 2021-02-02 13:38:13 +0000 | [diff] [blame^] | 266 | classesJar android.Path, jarName string) android.OutputPath { |
Colin Cross | f0056cb | 2017-12-22 15:56:08 -0800 | [diff] [blame] | 267 | |
Colin Cross | f0056cb | 2017-12-22 15:56:08 -0800 | [diff] [blame] | 268 | // Compile classes.jar into classes.dex and then javalib.jar |
Paul Duffin | 612e610 | 2021-02-02 13:38:13 +0000 | [diff] [blame^] | 269 | javalibJar := android.PathForModuleOut(ctx, "dex", jarName).OutputPath |
Colin Cross | f0056cb | 2017-12-22 15:56:08 -0800 | [diff] [blame] | 270 | outDir := android.PathForModuleOut(ctx, "dex") |
| 271 | |
Sasha Smundak | d3cf4ee | 2019-02-15 10:14:23 -0800 | [diff] [blame] | 272 | zipFlags := "--ignore_missing_files" |
Liz Kammer | a7a64f3 | 2020-07-09 15:16:41 -0700 | [diff] [blame] | 273 | if proptools.Bool(d.dexProperties.Uncompress_dex) { |
Sasha Smundak | d3cf4ee | 2019-02-15 10:14:23 -0800 | [diff] [blame] | 274 | zipFlags += " -L 0" |
Colin Cross | 5a0dcd5 | 2018-10-05 14:20:06 -0700 | [diff] [blame] | 275 | } |
| 276 | |
Liz Kammer | a7a64f3 | 2020-07-09 15:16:41 -0700 | [diff] [blame] | 277 | commonFlags := d.dexCommonFlags(ctx, minSdkVersion) |
| 278 | |
| 279 | useR8 := d.effectiveOptimizeEnabled() |
Colin Cross | 66dbc0b | 2017-12-28 12:23:20 -0800 | [diff] [blame] | 280 | if useR8 { |
Colin Cross | c0c664c | 2018-05-16 16:47:21 -0700 | [diff] [blame] | 281 | proguardDictionary := android.PathForModuleOut(ctx, "proguard_dictionary") |
Liz Kammer | a7a64f3 | 2020-07-09 15:16:41 -0700 | [diff] [blame] | 282 | d.proguardDictionary = android.OptionalPathForPath(proguardDictionary) |
Colin Cross | cb6143a | 2020-08-14 17:39:29 -0700 | [diff] [blame] | 283 | proguardUsageDir := android.PathForModuleOut(ctx, "proguard_usage") |
| 284 | proguardUsage := proguardUsageDir.Join(ctx, ctx.Namespace().Path, |
| 285 | android.ModuleNameWithPossibleOverride(ctx), "unused.txt") |
| 286 | proguardUsageZip := android.PathForModuleOut(ctx, "proguard_usage.zip") |
| 287 | d.proguardUsageZip = android.OptionalPathForPath(proguardUsageZip) |
Liz Kammer | a7a64f3 | 2020-07-09 15:16:41 -0700 | [diff] [blame] | 288 | r8Flags, r8Deps := d.r8Flags(ctx, flags) |
Ramy Medhat | 1dcc27e | 2020-04-21 21:36:23 -0400 | [diff] [blame] | 289 | rule := r8 |
| 290 | args := map[string]string{ |
Colin Cross | cb6143a | 2020-08-14 17:39:29 -0700 | [diff] [blame] | 291 | "r8Flags": strings.Join(append(commonFlags, r8Flags...), " "), |
| 292 | "zipFlags": zipFlags, |
| 293 | "outDict": proguardDictionary.String(), |
| 294 | "outUsageDir": proguardUsageDir.String(), |
| 295 | "outUsage": proguardUsage.String(), |
| 296 | "outUsageZip": proguardUsageZip.String(), |
| 297 | "outDir": outDir.String(), |
Ramy Medhat | 1dcc27e | 2020-04-21 21:36:23 -0400 | [diff] [blame] | 298 | } |
Ramy Medhat | 16f23a4 | 2020-09-03 01:29:49 -0400 | [diff] [blame] | 299 | if ctx.Config().UseRBE() && ctx.Config().IsEnvTrue("RBE_R8") { |
Ramy Medhat | 1dcc27e | 2020-04-21 21:36:23 -0400 | [diff] [blame] | 300 | rule = r8RE |
| 301 | args["implicits"] = strings.Join(r8Deps.Strings(), ",") |
| 302 | } |
Colin Cross | 66dbc0b | 2017-12-28 12:23:20 -0800 | [diff] [blame] | 303 | ctx.Build(pctx, android.BuildParams{ |
Colin Cross | cb6143a | 2020-08-14 17:39:29 -0700 | [diff] [blame] | 304 | Rule: rule, |
| 305 | Description: "r8", |
| 306 | Output: javalibJar, |
| 307 | ImplicitOutputs: android.WritablePaths{proguardDictionary, proguardUsageZip}, |
| 308 | Input: classesJar, |
| 309 | Implicits: r8Deps, |
| 310 | Args: args, |
Colin Cross | 66dbc0b | 2017-12-28 12:23:20 -0800 | [diff] [blame] | 311 | }) |
| 312 | } else { |
Liz Kammer | a7a64f3 | 2020-07-09 15:16:41 -0700 | [diff] [blame] | 313 | d8Flags, d8Deps := d8Flags(flags) |
Ramy Medhat | 1dcc27e | 2020-04-21 21:36:23 -0400 | [diff] [blame] | 314 | rule := d8 |
Ramy Medhat | 16f23a4 | 2020-09-03 01:29:49 -0400 | [diff] [blame] | 315 | if ctx.Config().UseRBE() && ctx.Config().IsEnvTrue("RBE_D8") { |
Ramy Medhat | 1dcc27e | 2020-04-21 21:36:23 -0400 | [diff] [blame] | 316 | rule = d8RE |
| 317 | } |
Colin Cross | 66dbc0b | 2017-12-28 12:23:20 -0800 | [diff] [blame] | 318 | ctx.Build(pctx, android.BuildParams{ |
Ramy Medhat | 1dcc27e | 2020-04-21 21:36:23 -0400 | [diff] [blame] | 319 | Rule: rule, |
Colin Cross | bafb897 | 2018-06-06 21:46:32 +0000 | [diff] [blame] | 320 | Description: "d8", |
Colin Cross | 66dbc0b | 2017-12-28 12:23:20 -0800 | [diff] [blame] | 321 | Output: javalibJar, |
| 322 | Input: classesJar, |
Colin Cross | 6dab9bd | 2018-09-28 08:06:24 -0700 | [diff] [blame] | 323 | Implicits: d8Deps, |
Colin Cross | 66dbc0b | 2017-12-28 12:23:20 -0800 | [diff] [blame] | 324 | Args: map[string]string{ |
Liz Kammer | a7a64f3 | 2020-07-09 15:16:41 -0700 | [diff] [blame] | 325 | "d8Flags": strings.Join(append(commonFlags, d8Flags...), " "), |
Colin Cross | 5a0dcd5 | 2018-10-05 14:20:06 -0700 | [diff] [blame] | 326 | "zipFlags": zipFlags, |
| 327 | "outDir": outDir.String(), |
Colin Cross | 66dbc0b | 2017-12-28 12:23:20 -0800 | [diff] [blame] | 328 | }, |
| 329 | }) |
Colin Cross | f0056cb | 2017-12-22 15:56:08 -0800 | [diff] [blame] | 330 | } |
Liz Kammer | a7a64f3 | 2020-07-09 15:16:41 -0700 | [diff] [blame] | 331 | if proptools.Bool(d.dexProperties.Uncompress_dex) { |
Paul Duffin | 612e610 | 2021-02-02 13:38:13 +0000 | [diff] [blame^] | 332 | alignedJavalibJar := android.PathForModuleOut(ctx, "aligned", jarName).OutputPath |
Nicolas Geoffray | 65fd8ba | 2019-01-21 23:20:23 +0000 | [diff] [blame] | 333 | TransformZipAlign(ctx, alignedJavalibJar, javalibJar) |
| 334 | javalibJar = alignedJavalibJar |
| 335 | } |
Colin Cross | f0056cb | 2017-12-22 15:56:08 -0800 | [diff] [blame] | 336 | |
Colin Cross | f0056cb | 2017-12-22 15:56:08 -0800 | [diff] [blame] | 337 | return javalibJar |
| 338 | } |