| Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -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 | "path/filepath" | 
| Colin Cross | b69301e | 2017-12-01 10:48:26 -0800 | [diff] [blame] | 19 | "sort" | 
| Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 20 | "strconv" | 
|  | 21 | "strings" | 
|  | 22 |  | 
|  | 23 | "github.com/google/blueprint" | 
|  | 24 |  | 
|  | 25 | "android/soong/android" | 
|  | 26 | ) | 
|  | 27 |  | 
| Inseob Kim | 34dc4cd | 2023-11-07 13:37:14 +0900 | [diff] [blame] | 28 | func isPathValueResource(res android.Path) bool { | 
|  | 29 | subDir := filepath.Dir(res.String()) | 
|  | 30 | subDir, lastDir := filepath.Split(subDir) | 
|  | 31 | return strings.HasPrefix(lastDir, "values") | 
|  | 32 | } | 
|  | 33 |  | 
| Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 34 | // Convert input resource file path to output file path. | 
|  | 35 | // values-[config]/<file>.xml -> values-[config]_<file>.arsc.flat; | 
| Jaewoong Jung | 60d6d57 | 2020-11-20 17:58:27 -0800 | [diff] [blame] | 36 | // For other resource file, just replace the last "/" with "_" and add .flat extension. | 
| Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 37 | func pathToAapt2Path(ctx android.ModuleContext, res android.Path) android.WritablePath { | 
|  | 38 |  | 
|  | 39 | name := res.Base() | 
| Inseob Kim | 34dc4cd | 2023-11-07 13:37:14 +0900 | [diff] [blame] | 40 | if isPathValueResource(res) { | 
| Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 41 | name = strings.TrimSuffix(name, ".xml") + ".arsc" | 
|  | 42 | } | 
| Inseob Kim | 34dc4cd | 2023-11-07 13:37:14 +0900 | [diff] [blame] | 43 | subDir := filepath.Dir(res.String()) | 
|  | 44 | subDir, lastDir := filepath.Split(subDir) | 
| Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 45 | name = lastDir + "_" + name + ".flat" | 
|  | 46 | return android.PathForModuleOut(ctx, "aapt2", subDir, name) | 
|  | 47 | } | 
|  | 48 |  | 
| Jaewoong Jung | 60d6d57 | 2020-11-20 17:58:27 -0800 | [diff] [blame] | 49 | // pathsToAapt2Paths Calls pathToAapt2Path on each entry of the given Paths, i.e. []Path. | 
| Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 50 | func pathsToAapt2Paths(ctx android.ModuleContext, resPaths android.Paths) android.WritablePaths { | 
|  | 51 | outPaths := make(android.WritablePaths, len(resPaths)) | 
|  | 52 |  | 
|  | 53 | for i, res := range resPaths { | 
|  | 54 | outPaths[i] = pathToAapt2Path(ctx, res) | 
|  | 55 | } | 
|  | 56 |  | 
|  | 57 | return outPaths | 
|  | 58 | } | 
|  | 59 |  | 
| Jaewoong Jung | 60d6d57 | 2020-11-20 17:58:27 -0800 | [diff] [blame] | 60 | // Shard resource files for efficiency. See aapt2Compile for details. | 
|  | 61 | const AAPT2_SHARD_SIZE = 100 | 
|  | 62 |  | 
| Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 63 | var aapt2CompileRule = pctx.AndroidStaticRule("aapt2Compile", | 
|  | 64 | blueprint.RuleParams{ | 
| Colin Cross | 4215cfd | 2019-06-20 16:53:30 -0700 | [diff] [blame] | 65 | Command:     `${config.Aapt2Cmd} compile -o $outDir $cFlags $in`, | 
| Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 66 | CommandDeps: []string{"${config.Aapt2Cmd}"}, | 
|  | 67 | }, | 
|  | 68 | "outDir", "cFlags") | 
|  | 69 |  | 
| Jaewoong Jung | 60d6d57 | 2020-11-20 17:58:27 -0800 | [diff] [blame] | 70 | // aapt2Compile compiles resources and puts the results in the requested directory. | 
| Colin Cross | a0ba2f5 | 2019-06-22 12:59:27 -0700 | [diff] [blame] | 71 | func aapt2Compile(ctx android.ModuleContext, dir android.Path, paths android.Paths, | 
| Inseob Kim | 34dc4cd | 2023-11-07 13:37:14 +0900 | [diff] [blame] | 72 | flags []string, productToFilter string) android.WritablePaths { | 
|  | 73 | if productToFilter != "" && productToFilter != "default" { | 
|  | 74 | // --filter-product leaves only product-specific resources. Product-specific resources only exist | 
|  | 75 | // in value resources (values/*.xml), so filter value resource files only. Ignore other types of | 
|  | 76 | // resources as they don't need to be in product characteristics RRO (and they will cause aapt2 | 
|  | 77 | // compile errors) | 
|  | 78 | filteredPaths := android.Paths{} | 
|  | 79 | for _, path := range paths { | 
|  | 80 | if isPathValueResource(path) { | 
|  | 81 | filteredPaths = append(filteredPaths, path) | 
|  | 82 | } | 
|  | 83 | } | 
|  | 84 | paths = filteredPaths | 
|  | 85 | flags = append([]string{"--filter-product " + productToFilter}, flags...) | 
|  | 86 | } | 
| Colin Cross | a0ba2f5 | 2019-06-22 12:59:27 -0700 | [diff] [blame] | 87 |  | 
| Jaewoong Jung | 60d6d57 | 2020-11-20 17:58:27 -0800 | [diff] [blame] | 88 | // Shard the input paths so that they can be processed in parallel. If we shard them into too | 
|  | 89 | // small chunks, the additional cost of spinning up aapt2 outweighs the performance gain. The | 
|  | 90 | // current shard size, 100, seems to be a good balance between the added cost and the gain. | 
|  | 91 | // The aapt2 compile actions are trivially short, but each action in ninja takes on the order of | 
|  | 92 | // ~10 ms to run. frameworks/base/core/res/res has >10k resource files, so compiling each one | 
|  | 93 | // with an individual action could take 100 CPU seconds. Sharding them reduces the overhead of | 
|  | 94 | // starting actions by a factor of 100, at the expense of recompiling more files when one | 
|  | 95 | // changes.  Since the individual compiles are trivial it's a good tradeoff. | 
| Colin Cross | 0a2f719 | 2019-09-23 14:33:09 -0700 | [diff] [blame] | 96 | shards := android.ShardPaths(paths, AAPT2_SHARD_SIZE) | 
| Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 97 |  | 
|  | 98 | ret := make(android.WritablePaths, 0, len(paths)) | 
|  | 99 |  | 
|  | 100 | for i, shard := range shards { | 
| Jaewoong Jung | 60d6d57 | 2020-11-20 17:58:27 -0800 | [diff] [blame] | 101 | // This should be kept in sync with pathToAapt2Path. The aapt2 compile command takes an | 
|  | 102 | // output directory path, but not output file paths. So, outPaths is just where we expect | 
|  | 103 | // the output files will be located. | 
| Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 104 | outPaths := pathsToAapt2Paths(ctx, shard) | 
|  | 105 | ret = append(ret, outPaths...) | 
|  | 106 |  | 
|  | 107 | shardDesc := "" | 
|  | 108 | if i != 0 { | 
|  | 109 | shardDesc = " " + strconv.Itoa(i+1) | 
|  | 110 | } | 
|  | 111 |  | 
|  | 112 | ctx.Build(pctx, android.BuildParams{ | 
|  | 113 | Rule:        aapt2CompileRule, | 
|  | 114 | Description: "aapt2 compile " + dir.String() + shardDesc, | 
|  | 115 | Inputs:      shard, | 
|  | 116 | Outputs:     outPaths, | 
|  | 117 | Args: map[string]string{ | 
| Jaewoong Jung | 60d6d57 | 2020-11-20 17:58:27 -0800 | [diff] [blame] | 118 | // The aapt2 compile command takes an output directory path, but not output file paths. | 
|  | 119 | // outPaths specified above is only used for dependency management purposes. In order for | 
|  | 120 | // the outPaths values to match the actual outputs from aapt2, the dir parameter value | 
|  | 121 | // must be a common prefix path of the paths values, and the top-level path segment used | 
|  | 122 | // below, "aapt2", must always be kept in sync with the one in pathToAapt2Path. | 
|  | 123 | // TODO(b/174505750): Make this easier and robust to use. | 
| Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 124 | "outDir": android.PathForModuleOut(ctx, "aapt2", dir.String()).String(), | 
| Colin Cross | a0ba2f5 | 2019-06-22 12:59:27 -0700 | [diff] [blame] | 125 | "cFlags": strings.Join(flags, " "), | 
| Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 126 | }, | 
|  | 127 | }) | 
|  | 128 | } | 
|  | 129 |  | 
| Colin Cross | b69301e | 2017-12-01 10:48:26 -0800 | [diff] [blame] | 130 | sort.Slice(ret, func(i, j int) bool { | 
|  | 131 | return ret[i].String() < ret[j].String() | 
|  | 132 | }) | 
| Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 133 | return ret | 
|  | 134 | } | 
|  | 135 |  | 
| Colin Cross | a592e3e | 2019-02-19 16:59:53 -0800 | [diff] [blame] | 136 | var aapt2CompileZipRule = pctx.AndroidStaticRule("aapt2CompileZip", | 
|  | 137 | blueprint.RuleParams{ | 
| Dan Willemsen | 304cfec | 2019-05-28 14:49:06 -0700 | [diff] [blame] | 138 | Command: `${config.ZipSyncCmd} -d $resZipDir $zipSyncFlags $in && ` + | 
| Colin Cross | 4215cfd | 2019-06-20 16:53:30 -0700 | [diff] [blame] | 139 | `${config.Aapt2Cmd} compile -o $out $cFlags --dir $resZipDir`, | 
| Colin Cross | a592e3e | 2019-02-19 16:59:53 -0800 | [diff] [blame] | 140 | CommandDeps: []string{ | 
|  | 141 | "${config.Aapt2Cmd}", | 
|  | 142 | "${config.ZipSyncCmd}", | 
|  | 143 | }, | 
| Dan Willemsen | 304cfec | 2019-05-28 14:49:06 -0700 | [diff] [blame] | 144 | }, "cFlags", "resZipDir", "zipSyncFlags") | 
| Colin Cross | a592e3e | 2019-02-19 16:59:53 -0800 | [diff] [blame] | 145 |  | 
| Jaewoong Jung | 60d6d57 | 2020-11-20 17:58:27 -0800 | [diff] [blame] | 146 | // Unzips the given compressed file and compiles the resource source files in it. The zipPrefix | 
|  | 147 | // parameter points to the subdirectory in the zip file where the resource files are located. | 
| Colin Cross | a0ba2f5 | 2019-06-22 12:59:27 -0700 | [diff] [blame] | 148 | func aapt2CompileZip(ctx android.ModuleContext, flata android.WritablePath, zip android.Path, zipPrefix string, | 
|  | 149 | flags []string) { | 
|  | 150 |  | 
| Dan Willemsen | 304cfec | 2019-05-28 14:49:06 -0700 | [diff] [blame] | 151 | if zipPrefix != "" { | 
|  | 152 | zipPrefix = "--zip-prefix " + zipPrefix | 
|  | 153 | } | 
| Colin Cross | a592e3e | 2019-02-19 16:59:53 -0800 | [diff] [blame] | 154 | ctx.Build(pctx, android.BuildParams{ | 
|  | 155 | Rule:        aapt2CompileZipRule, | 
|  | 156 | Description: "aapt2 compile zip", | 
|  | 157 | Input:       zip, | 
|  | 158 | Output:      flata, | 
|  | 159 | Args: map[string]string{ | 
| Colin Cross | a0ba2f5 | 2019-06-22 12:59:27 -0700 | [diff] [blame] | 160 | "cFlags":       strings.Join(flags, " "), | 
| Dan Willemsen | 304cfec | 2019-05-28 14:49:06 -0700 | [diff] [blame] | 161 | "resZipDir":    android.PathForModuleOut(ctx, "aapt2", "reszip", flata.Base()).String(), | 
|  | 162 | "zipSyncFlags": zipPrefix, | 
| Colin Cross | a592e3e | 2019-02-19 16:59:53 -0800 | [diff] [blame] | 163 | }, | 
|  | 164 | }) | 
|  | 165 | } | 
|  | 166 |  | 
| Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 167 | var aapt2LinkRule = pctx.AndroidStaticRule("aapt2Link", | 
|  | 168 | blueprint.RuleParams{ | 
| Colin Cross | f3b7bad | 2023-08-02 15:49:00 -0700 | [diff] [blame] | 169 | Command: `$preamble` + | 
|  | 170 | `${config.Aapt2Cmd} link -o $out $flags --proguard $proguardOptions ` + | 
|  | 171 | `--output-text-symbols ${rTxt} $inFlags` + | 
|  | 172 | `$postamble`, | 
| Colin Cross | 66f7882 | 2018-05-02 12:58:28 -0700 | [diff] [blame] | 173 |  | 
| Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 174 | CommandDeps: []string{ | 
| Colin Cross | 44f0668 | 2017-11-29 00:17:36 -0800 | [diff] [blame] | 175 | "${config.Aapt2Cmd}", | 
| Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 176 | "${config.SoongZipCmd}", | 
|  | 177 | }, | 
|  | 178 | Restat: true, | 
|  | 179 | }, | 
| Colin Cross | f3b7bad | 2023-08-02 15:49:00 -0700 | [diff] [blame] | 180 | "flags", "inFlags", "proguardOptions", "rTxt", "extraPackages", "preamble", "postamble") | 
|  | 181 |  | 
|  | 182 | var aapt2ExtractExtraPackagesRule = pctx.AndroidStaticRule("aapt2ExtractExtraPackages", | 
|  | 183 | blueprint.RuleParams{ | 
|  | 184 | Command:     `${config.ExtractJarPackagesCmd} -i $in -o $out --prefix '--extra-packages '`, | 
|  | 185 | CommandDeps: []string{"${config.ExtractJarPackagesCmd}"}, | 
|  | 186 | Restat:      true, | 
|  | 187 | }) | 
| Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 188 |  | 
|  | 189 | var fileListToFileRule = pctx.AndroidStaticRule("fileListToFile", | 
|  | 190 | blueprint.RuleParams{ | 
|  | 191 | Command:        `cp $out.rsp $out`, | 
|  | 192 | Rspfile:        "$out.rsp", | 
|  | 193 | RspfileContent: "$in", | 
|  | 194 | }) | 
|  | 195 |  | 
| Jaewoong Jung | 6431ca7 | 2020-01-15 14:15:10 -0800 | [diff] [blame] | 196 | var mergeAssetsRule = pctx.AndroidStaticRule("mergeAssets", | 
|  | 197 | blueprint.RuleParams{ | 
|  | 198 | Command:     `${config.MergeZipsCmd} ${out} ${in}`, | 
|  | 199 | CommandDeps: []string{"${config.MergeZipsCmd}"}, | 
|  | 200 | }) | 
|  | 201 |  | 
| Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 202 | func aapt2Link(ctx android.ModuleContext, | 
| Colin Cross | f3b7bad | 2023-08-02 15:49:00 -0700 | [diff] [blame] | 203 | packageRes, genJar, proguardOptions, rTxt android.WritablePath, | 
| Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 204 | flags []string, deps android.Paths, | 
| Jihoon Kang | 84b2589 | 2023-12-01 22:01:06 +0000 | [diff] [blame] | 205 | compiledRes, compiledOverlay, assetPackages android.Paths, splitPackages android.WritablePaths, | 
|  | 206 | featureFlagsPaths android.Paths) { | 
| Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 207 |  | 
| Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 208 | var inFlags []string | 
|  | 209 |  | 
|  | 210 | if len(compiledRes) > 0 { | 
| Jaewoong Jung | 60d6d57 | 2020-11-20 17:58:27 -0800 | [diff] [blame] | 211 | // Create a file that contains the list of all compiled resource file paths. | 
| Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 212 | resFileList := android.PathForModuleOut(ctx, "aapt2", "res.list") | 
|  | 213 | // Write out file lists to files | 
|  | 214 | ctx.Build(pctx, android.BuildParams{ | 
|  | 215 | Rule:        fileListToFileRule, | 
|  | 216 | Description: "resource file list", | 
|  | 217 | Inputs:      compiledRes, | 
|  | 218 | Output:      resFileList, | 
|  | 219 | }) | 
|  | 220 |  | 
|  | 221 | deps = append(deps, compiledRes...) | 
|  | 222 | deps = append(deps, resFileList) | 
| Jaewoong Jung | 60d6d57 | 2020-11-20 17:58:27 -0800 | [diff] [blame] | 223 | // aapt2 filepath arguments that start with "@" mean file-list files. | 
| Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 224 | inFlags = append(inFlags, "@"+resFileList.String()) | 
|  | 225 | } | 
|  | 226 |  | 
|  | 227 | if len(compiledOverlay) > 0 { | 
| Jaewoong Jung | 60d6d57 | 2020-11-20 17:58:27 -0800 | [diff] [blame] | 228 | // Compiled overlay files are processed the same way as compiled resources. | 
| Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 229 | overlayFileList := android.PathForModuleOut(ctx, "aapt2", "overlay.list") | 
|  | 230 | ctx.Build(pctx, android.BuildParams{ | 
|  | 231 | Rule:        fileListToFileRule, | 
|  | 232 | Description: "overlay resource file list", | 
|  | 233 | Inputs:      compiledOverlay, | 
|  | 234 | Output:      overlayFileList, | 
|  | 235 | }) | 
|  | 236 |  | 
|  | 237 | deps = append(deps, compiledOverlay...) | 
|  | 238 | deps = append(deps, overlayFileList) | 
| Jaewoong Jung | 60d6d57 | 2020-11-20 17:58:27 -0800 | [diff] [blame] | 239 | // Compiled overlay files are passed over to aapt2 using -R option. | 
| Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 240 | inFlags = append(inFlags, "-R", "@"+overlayFileList.String()) | 
|  | 241 | } | 
|  | 242 |  | 
| Jaewoong Jung | 60d6d57 | 2020-11-20 17:58:27 -0800 | [diff] [blame] | 243 | // Set auxiliary outputs as implicit outputs to establish correct dependency chains. | 
| Colin Cross | f3b7bad | 2023-08-02 15:49:00 -0700 | [diff] [blame] | 244 | implicitOutputs := append(splitPackages, proguardOptions, rTxt) | 
| Jaewoong Jung | 6431ca7 | 2020-01-15 14:15:10 -0800 | [diff] [blame] | 245 | linkOutput := packageRes | 
|  | 246 |  | 
|  | 247 | // AAPT2 ignores assets in overlays. Merge them after linking. | 
|  | 248 | if len(assetPackages) > 0 { | 
|  | 249 | linkOutput = android.PathForModuleOut(ctx, "aapt2", "package-res.apk") | 
|  | 250 | inputZips := append(android.Paths{linkOutput}, assetPackages...) | 
|  | 251 | ctx.Build(pctx, android.BuildParams{ | 
|  | 252 | Rule:        mergeAssetsRule, | 
|  | 253 | Inputs:      inputZips, | 
|  | 254 | Output:      packageRes, | 
|  | 255 | Description: "merge assets from dependencies", | 
|  | 256 | }) | 
|  | 257 | } | 
| Colin Cross | e560c4a | 2019-03-19 16:03:11 -0700 | [diff] [blame] | 258 |  | 
| Jihoon Kang | 84b2589 | 2023-12-01 22:01:06 +0000 | [diff] [blame] | 259 | for _, featureFlagsPath := range featureFlagsPaths { | 
|  | 260 | deps = append(deps, featureFlagsPath) | 
|  | 261 | inFlags = append(inFlags, "--feature-flags", "@"+featureFlagsPath.String()) | 
|  | 262 | } | 
|  | 263 |  | 
| Colin Cross | f3b7bad | 2023-08-02 15:49:00 -0700 | [diff] [blame] | 264 | // Note the absence of splitPackages. The caller is supposed to compose and provide --split flag | 
|  | 265 | // values via the flags parameter when it wants to split outputs. | 
|  | 266 | // TODO(b/174509108): Perhaps we can process it in this func while keeping the code reasonably | 
|  | 267 | // tidy. | 
|  | 268 | args := map[string]string{ | 
|  | 269 | "flags":           strings.Join(flags, " "), | 
|  | 270 | "inFlags":         strings.Join(inFlags, " "), | 
|  | 271 | "proguardOptions": proguardOptions.String(), | 
|  | 272 | "rTxt":            rTxt.String(), | 
|  | 273 | } | 
|  | 274 |  | 
|  | 275 | if genJar != nil { | 
|  | 276 | // Generating java source files from aapt2 was requested, use aapt2LinkAndGenRule and pass it | 
|  | 277 | // genJar and genDir args. | 
|  | 278 | genDir := android.PathForModuleGen(ctx, "aapt2", "R") | 
|  | 279 | ctx.Variable(pctx, "aapt2GenDir", genDir.String()) | 
|  | 280 | ctx.Variable(pctx, "aapt2GenJar", genJar.String()) | 
|  | 281 | implicitOutputs = append(implicitOutputs, genJar) | 
|  | 282 | args["preamble"] = `rm -rf $aapt2GenDir && ` | 
|  | 283 | args["postamble"] = `&& ${config.SoongZipCmd} -write_if_changed -jar -o $aapt2GenJar -C $aapt2GenDir -D $aapt2GenDir && ` + | 
|  | 284 | `rm -rf $aapt2GenDir` | 
|  | 285 | args["flags"] += " --java $aapt2GenDir" | 
|  | 286 | } | 
|  | 287 |  | 
| Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 288 | ctx.Build(pctx, android.BuildParams{ | 
|  | 289 | Rule:            aapt2LinkRule, | 
|  | 290 | Description:     "aapt2 link", | 
|  | 291 | Implicits:       deps, | 
| Jaewoong Jung | 6431ca7 | 2020-01-15 14:15:10 -0800 | [diff] [blame] | 292 | Output:          linkOutput, | 
| Colin Cross | e560c4a | 2019-03-19 16:03:11 -0700 | [diff] [blame] | 293 | ImplicitOutputs: implicitOutputs, | 
| Colin Cross | f3b7bad | 2023-08-02 15:49:00 -0700 | [diff] [blame] | 294 | Args:            args, | 
|  | 295 | }) | 
|  | 296 | } | 
|  | 297 |  | 
|  | 298 | // aapt2ExtractExtraPackages takes a srcjar generated by aapt2 or a classes jar generated by ResourceProcessorBusyBox | 
|  | 299 | // and converts it to a text file containing a list of --extra_package arguments for passing to Make modules so they | 
|  | 300 | // correctly generate R.java entries for packages provided by transitive dependencies. | 
|  | 301 | func aapt2ExtractExtraPackages(ctx android.ModuleContext, out android.WritablePath, in android.Path) { | 
|  | 302 | ctx.Build(pctx, android.BuildParams{ | 
|  | 303 | Rule:        aapt2ExtractExtraPackagesRule, | 
|  | 304 | Description: "aapt2 extract extra packages", | 
|  | 305 | Input:       in, | 
|  | 306 | Output:      out, | 
| Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 307 | }) | 
|  | 308 | } | 
| Colin Cross | f623721 | 2018-10-29 23:14:58 -0700 | [diff] [blame] | 309 |  | 
|  | 310 | var aapt2ConvertRule = pctx.AndroidStaticRule("aapt2Convert", | 
|  | 311 | blueprint.RuleParams{ | 
| Rico Wind | 2186228 | 2023-08-01 14:38:36 +0200 | [diff] [blame] | 312 | Command: `${config.Aapt2Cmd} convert --enable-compact-entries ` + | 
|  | 313 | `--output-format $format $in -o $out`, | 
| Colin Cross | f623721 | 2018-10-29 23:14:58 -0700 | [diff] [blame] | 314 | CommandDeps: []string{"${config.Aapt2Cmd}"}, | 
| Rico Wind | 351bac9 | 2022-09-22 10:41:42 +0200 | [diff] [blame] | 315 | }, "format", | 
|  | 316 | ) | 
| Colin Cross | f623721 | 2018-10-29 23:14:58 -0700 | [diff] [blame] | 317 |  | 
| Jaewoong Jung | 60d6d57 | 2020-11-20 17:58:27 -0800 | [diff] [blame] | 318 | // Converts xml files and resource tables (resources.arsc) in the given jar/apk file to a proto | 
|  | 319 | // format. The proto definition is available at frameworks/base/tools/aapt2/Resources.proto. | 
| Rico Wind | 351bac9 | 2022-09-22 10:41:42 +0200 | [diff] [blame] | 320 | func aapt2Convert(ctx android.ModuleContext, out android.WritablePath, in android.Path, format string) { | 
| Colin Cross | f623721 | 2018-10-29 23:14:58 -0700 | [diff] [blame] | 321 | ctx.Build(pctx, android.BuildParams{ | 
|  | 322 | Rule:        aapt2ConvertRule, | 
|  | 323 | Input:       in, | 
|  | 324 | Output:      out, | 
| Rico Wind | 351bac9 | 2022-09-22 10:41:42 +0200 | [diff] [blame] | 325 | Description: "convert to " + format, | 
|  | 326 | Args: map[string]string{ | 
|  | 327 | "format": format, | 
|  | 328 | }, | 
| Colin Cross | f623721 | 2018-10-29 23:14:58 -0700 | [diff] [blame] | 329 | }) | 
|  | 330 | } |