Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 1 | // Copyright 2018 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 ( |
Colin Cross | a592e3e | 2019-02-19 16:59:53 -0800 | [diff] [blame] | 18 | "fmt" |
Jaewoong Jung | 5b425e2 | 2019-06-17 17:40:56 -0700 | [diff] [blame] | 19 | "path/filepath" |
Colin Cross | c20dc85 | 2020-11-10 12:27:45 -0800 | [diff] [blame] | 20 | "strconv" |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 21 | "strings" |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 22 | |
Jaewoong Jung | 9befb0c | 2020-01-18 10:33:43 -0800 | [diff] [blame] | 23 | "android/soong/android" |
Romain Jobredeaux | c9b2bba | 2022-02-15 09:35:07 -0500 | [diff] [blame] | 24 | "android/soong/bazel" |
Ulya Trafimovich | 31e444e | 2020-08-14 17:32:16 +0100 | [diff] [blame] | 25 | "android/soong/dexpreopt" |
Romain Jobredeaux | 7a71e07 | 2023-08-16 17:39:12 -0400 | [diff] [blame^] | 26 | "android/soong/ui/metrics/bp2build_metrics_proto" |
Jaewoong Jung | 9befb0c | 2020-01-18 10:33:43 -0800 | [diff] [blame] | 27 | |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 28 | "github.com/google/blueprint" |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 29 | "github.com/google/blueprint/proptools" |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 30 | ) |
| 31 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 32 | type AndroidLibraryDependency interface { |
Jared Duke | 5979b30 | 2022-12-19 21:08:39 +0000 | [diff] [blame] | 33 | LibraryDependency |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 34 | ExportPackage() android.Path |
Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 35 | ResourcesNodeDepSet() *android.DepSet[*resourcesNode] |
| 36 | RRODirsDepSet() *android.DepSet[rroDir] |
| 37 | ManifestsDepSet() *android.DepSet[android.Path] |
Jaewoong Jung | c779cd4 | 2020-10-06 18:56:10 -0700 | [diff] [blame] | 38 | SetRROEnforcedForDependent(enforce bool) |
| 39 | IsRROEnforced(ctx android.BaseModuleContext) bool |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | func init() { |
Paul Duffin | f9b1da0 | 2019-12-18 19:51:55 +0000 | [diff] [blame] | 43 | RegisterAARBuildComponents(android.InitRegistrationContext) |
| 44 | } |
| 45 | |
| 46 | func RegisterAARBuildComponents(ctx android.RegistrationContext) { |
| 47 | ctx.RegisterModuleType("android_library_import", AARImportFactory) |
| 48 | ctx.RegisterModuleType("android_library", AndroidLibraryFactory) |
Paul Duffin | 04ba70d | 2021-03-22 13:56:43 +0000 | [diff] [blame] | 49 | ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) { |
| 50 | ctx.TopDown("propagate_rro_enforcement", propagateRROEnforcementMutator).Parallel() |
| 51 | }) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | // |
| 55 | // AAR (android library) |
| 56 | // |
| 57 | |
| 58 | type androidLibraryProperties struct { |
| 59 | BuildAAR bool `blueprint:"mutated"` |
| 60 | } |
| 61 | |
| 62 | type aaptProperties struct { |
| 63 | // flags passed to aapt when creating the apk |
| 64 | Aaptflags []string |
| 65 | |
Dan Willemsen | 72be590 | 2018-10-24 20:24:57 -0700 | [diff] [blame] | 66 | // include all resource configurations, not just the product-configured |
| 67 | // ones. |
| 68 | Aapt_include_all_resources *bool |
| 69 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 70 | // list of directories relative to the Blueprints file containing assets. |
Colin Cross | 0ddae7f | 2019-02-07 15:30:01 -0800 | [diff] [blame] | 71 | // Defaults to ["assets"] if a directory called assets exists. Set to [] |
| 72 | // to disable the default. |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 73 | Asset_dirs []string |
| 74 | |
| 75 | // list of directories relative to the Blueprints file containing |
Colin Cross | 0ddae7f | 2019-02-07 15:30:01 -0800 | [diff] [blame] | 76 | // Android resources. Defaults to ["res"] if a directory called res exists. |
| 77 | // Set to [] to disable the default. |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 78 | Resource_dirs []string |
| 79 | |
Colin Cross | a592e3e | 2019-02-19 16:59:53 -0800 | [diff] [blame] | 80 | // list of zip files containing Android resources. |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 81 | Resource_zips []string `android:"path"` |
Colin Cross | a592e3e | 2019-02-19 16:59:53 -0800 | [diff] [blame] | 82 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 83 | // path to AndroidManifest.xml. If unset, defaults to "AndroidManifest.xml". |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 84 | Manifest *string `android:"path"` |
changho.shin | b5432b7 | 2019-08-08 18:37:17 +0900 | [diff] [blame] | 85 | |
| 86 | // paths to additional manifest files to merge with main manifest. |
| 87 | Additional_manifests []string `android:"path"` |
Sasha Smundak | 541056c | 2019-10-28 15:50:06 -0700 | [diff] [blame] | 88 | |
| 89 | // do not include AndroidManifest from dependent libraries |
| 90 | Dont_merge_manifests *bool |
Jaewoong Jung | c779cd4 | 2020-10-06 18:56:10 -0700 | [diff] [blame] | 91 | |
Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 92 | // If use_resource_processor is set, use Bazel's resource processor instead of aapt2 to generate R.class files. |
| 93 | // The resource processor produces more optimal R.class files that only list resources in the package of the |
| 94 | // library that provided them, as opposed to aapt2 which produces R.java files for every package containing |
| 95 | // every resource. Using the resource processor can provide significant build time speedups, but requires |
| 96 | // fixing the module to use the correct package to reference each resource, and to avoid having any other |
| 97 | // libraries in the tree that use the same package name. Defaults to false, but will default to true in the |
| 98 | // future. |
| 99 | Use_resource_processor *bool |
| 100 | |
Jaewoong Jung | c779cd4 | 2020-10-06 18:56:10 -0700 | [diff] [blame] | 101 | // true if RRO is enforced for any of the dependent modules |
| 102 | RROEnforcedForDependent bool `blueprint:"mutated"` |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | type aapt struct { |
Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 106 | aaptSrcJar android.Path |
| 107 | transitiveAaptRJars android.Paths |
| 108 | transitiveAaptResourcePackages android.Paths |
| 109 | exportPackage android.Path |
| 110 | manifestPath android.Path |
| 111 | proguardOptionsFile android.Path |
| 112 | rTxt android.Path |
| 113 | rJar android.Path |
| 114 | extraAaptPackagesFile android.Path |
| 115 | mergedManifestFile android.Path |
| 116 | noticeFile android.OptionalPath |
| 117 | assetPackage android.OptionalPath |
| 118 | isLibrary bool |
| 119 | defaultManifestVersion string |
| 120 | useEmbeddedNativeLibs bool |
| 121 | useEmbeddedDex bool |
| 122 | usesNonSdkApis bool |
| 123 | hasNoCode bool |
| 124 | LoggingParent string |
| 125 | resourceFiles android.Paths |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 126 | |
Colin Cross | e560c4a | 2019-03-19 16:03:11 -0700 | [diff] [blame] | 127 | splitNames []string |
| 128 | splits []split |
| 129 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 130 | aaptProperties aaptProperties |
Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 131 | |
| 132 | resourcesNodesDepSet *android.DepSet[*resourcesNode] |
| 133 | rroDirsDepSet *android.DepSet[rroDir] |
| 134 | manifestsDepSet *android.DepSet[android.Path] |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 135 | } |
| 136 | |
Colin Cross | e560c4a | 2019-03-19 16:03:11 -0700 | [diff] [blame] | 137 | type split struct { |
| 138 | name string |
| 139 | suffix string |
| 140 | path android.Path |
| 141 | } |
| 142 | |
Jaewoong Jung | c779cd4 | 2020-10-06 18:56:10 -0700 | [diff] [blame] | 143 | // Propagate RRO enforcement flag to static lib dependencies transitively. |
| 144 | func propagateRROEnforcementMutator(ctx android.TopDownMutatorContext) { |
| 145 | m := ctx.Module() |
| 146 | if d, ok := m.(AndroidLibraryDependency); ok && d.IsRROEnforced(ctx) { |
| 147 | ctx.VisitDirectDepsWithTag(staticLibTag, func(d android.Module) { |
| 148 | if a, ok := d.(AndroidLibraryDependency); ok { |
| 149 | a.SetRROEnforcedForDependent(true) |
| 150 | } |
| 151 | }) |
| 152 | } |
| 153 | } |
| 154 | |
Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 155 | func (a *aapt) useResourceProcessorBusyBox() bool { |
| 156 | return BoolDefault(a.aaptProperties.Use_resource_processor, false) |
| 157 | } |
| 158 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 159 | func (a *aapt) ExportPackage() android.Path { |
| 160 | return a.exportPackage |
| 161 | } |
Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 162 | func (a *aapt) ResourcesNodeDepSet() *android.DepSet[*resourcesNode] { |
| 163 | return a.resourcesNodesDepSet |
Colin Cross | c1c3755 | 2019-01-31 11:42:41 -0800 | [diff] [blame] | 164 | } |
| 165 | |
Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 166 | func (a *aapt) RRODirsDepSet() *android.DepSet[rroDir] { |
| 167 | return a.rroDirsDepSet |
Colin Cross | c1c3755 | 2019-01-31 11:42:41 -0800 | [diff] [blame] | 168 | } |
| 169 | |
Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 170 | func (a *aapt) ManifestsDepSet() *android.DepSet[android.Path] { |
| 171 | return a.manifestsDepSet |
Jaewoong Jung | 6431ca7 | 2020-01-15 14:15:10 -0800 | [diff] [blame] | 172 | } |
| 173 | |
Jaewoong Jung | c779cd4 | 2020-10-06 18:56:10 -0700 | [diff] [blame] | 174 | func (a *aapt) SetRROEnforcedForDependent(enforce bool) { |
| 175 | a.aaptProperties.RROEnforcedForDependent = enforce |
| 176 | } |
| 177 | |
| 178 | func (a *aapt) IsRROEnforced(ctx android.BaseModuleContext) bool { |
| 179 | // True if RRO is enforced for this module or... |
| 180 | return ctx.Config().EnforceRROForModule(ctx.ModuleName()) || |
Jeongik Cha | cee5ba9 | 2021-02-19 12:11:51 +0900 | [diff] [blame] | 181 | // if RRO is enforced for any of its dependents. |
| 182 | a.aaptProperties.RROEnforcedForDependent |
Jaewoong Jung | c779cd4 | 2020-10-06 18:56:10 -0700 | [diff] [blame] | 183 | } |
| 184 | |
Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 185 | func (a *aapt) aapt2Flags(ctx android.ModuleContext, sdkContext android.SdkContext, |
Colin Cross | a0ba2f5 | 2019-06-22 12:59:27 -0700 | [diff] [blame] | 186 | manifestPath android.Path) (compileFlags, linkFlags []string, linkDeps android.Paths, |
| 187 | resDirs, overlayDirs []globbedResourceDir, rroDirs []rroDir, resZips android.Paths) { |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 188 | |
Jaewoong Jung | 3aff578 | 2020-02-11 07:54:35 -0800 | [diff] [blame] | 189 | hasVersionCode := android.PrefixInList(a.aaptProperties.Aaptflags, "--version-code") |
| 190 | hasVersionName := android.PrefixInList(a.aaptProperties.Aaptflags, "--version-name") |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 191 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 192 | // Flags specified in Android.bp |
| 193 | linkFlags = append(linkFlags, a.aaptProperties.Aaptflags...) |
| 194 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 195 | // Find implicit or explicit asset and resource dirs |
| 196 | assetDirs := android.PathsWithOptionalDefaultForModuleSrc(ctx, a.aaptProperties.Asset_dirs, "assets") |
| 197 | resourceDirs := android.PathsWithOptionalDefaultForModuleSrc(ctx, a.aaptProperties.Resource_dirs, "res") |
Colin Cross | 8a49795 | 2019-03-05 22:25:09 -0800 | [diff] [blame] | 198 | resourceZips := android.PathsForModuleSrc(ctx, a.aaptProperties.Resource_zips) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 199 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 200 | // Glob directories into lists of paths |
| 201 | for _, dir := range resourceDirs { |
| 202 | resDirs = append(resDirs, globbedResourceDir{ |
| 203 | dir: dir, |
| 204 | files: androidResourceGlob(ctx, dir), |
| 205 | }) |
Jaewoong Jung | c779cd4 | 2020-10-06 18:56:10 -0700 | [diff] [blame] | 206 | resOverlayDirs, resRRODirs := overlayResourceGlob(ctx, a, dir) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 207 | overlayDirs = append(overlayDirs, resOverlayDirs...) |
| 208 | rroDirs = append(rroDirs, resRRODirs...) |
| 209 | } |
| 210 | |
Colin Cross | c20dc85 | 2020-11-10 12:27:45 -0800 | [diff] [blame] | 211 | var assetDeps android.Paths |
| 212 | for i, dir := range assetDirs { |
| 213 | // Add a dependency on every file in the asset directory. This ensures the aapt2 |
| 214 | // rule will be rerun if one of the files in the asset directory is modified. |
| 215 | assetDeps = append(assetDeps, androidResourceGlob(ctx, dir)...) |
| 216 | |
| 217 | // Add a dependency on a file that contains a list of all the files in the asset directory. |
| 218 | // This ensures the aapt2 rule will be run if a file is removed from the asset directory, |
| 219 | // or a file is added whose timestamp is older than the output of aapt2. |
| 220 | assetFileListFile := android.PathForModuleOut(ctx, "asset_dir_globs", strconv.Itoa(i)+".glob") |
| 221 | androidResourceGlobList(ctx, dir, assetFileListFile) |
| 222 | assetDeps = append(assetDeps, assetFileListFile) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 223 | } |
| 224 | |
Jaewoong Jung | 5b425e2 | 2019-06-17 17:40:56 -0700 | [diff] [blame] | 225 | assetDirStrings := assetDirs.Strings() |
| 226 | if a.noticeFile.Valid() { |
| 227 | assetDirStrings = append(assetDirStrings, filepath.Dir(a.noticeFile.Path().String())) |
Colin Cross | c20dc85 | 2020-11-10 12:27:45 -0800 | [diff] [blame] | 228 | assetDeps = append(assetDeps, a.noticeFile.Path()) |
Jaewoong Jung | 5b425e2 | 2019-06-17 17:40:56 -0700 | [diff] [blame] | 229 | } |
| 230 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 231 | linkFlags = append(linkFlags, "--manifest "+manifestPath.String()) |
| 232 | linkDeps = append(linkDeps, manifestPath) |
| 233 | |
Jaewoong Jung | 5b425e2 | 2019-06-17 17:40:56 -0700 | [diff] [blame] | 234 | linkFlags = append(linkFlags, android.JoinWithPrefix(assetDirStrings, "-A ")) |
Colin Cross | c20dc85 | 2020-11-10 12:27:45 -0800 | [diff] [blame] | 235 | linkDeps = append(linkDeps, assetDeps...) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 236 | |
Spandan Das | 50885c0 | 2023-02-23 21:31:33 +0000 | [diff] [blame] | 237 | // Returns the effective version for {min|target}_sdk_version |
Spandan Das | 8c9ae7e | 2023-03-03 21:20:36 +0000 | [diff] [blame] | 238 | effectiveVersionString := func(sdkVersion android.SdkSpec, minSdkVersion android.ApiLevel) string { |
Spandan Das | 50885c0 | 2023-02-23 21:31:33 +0000 | [diff] [blame] | 239 | // If {min|target}_sdk_version is current, use sdk_version to determine the effective level |
| 240 | // This is necessary for vendor modules. |
| 241 | // The effective version does not _only_ depend on {min|target}_sdk_version(level), |
| 242 | // but also on the sdk_version (kind+level) |
Spandan Das | 8c9ae7e | 2023-03-03 21:20:36 +0000 | [diff] [blame] | 243 | if minSdkVersion.IsCurrent() { |
Spandan Das | 50885c0 | 2023-02-23 21:31:33 +0000 | [diff] [blame] | 244 | ret, err := sdkVersion.EffectiveVersionString(ctx) |
| 245 | if err != nil { |
| 246 | ctx.ModuleErrorf("invalid sdk_version: %s", err) |
| 247 | } |
| 248 | return ret |
| 249 | } |
| 250 | ret, err := minSdkVersion.EffectiveVersionString(ctx) |
| 251 | if err != nil { |
| 252 | ctx.ModuleErrorf("invalid min_sdk_version: %s", err) |
| 253 | } |
| 254 | return ret |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 255 | } |
Spandan Das | 50885c0 | 2023-02-23 21:31:33 +0000 | [diff] [blame] | 256 | // SDK version flags |
| 257 | sdkVersion := sdkContext.SdkVersion(ctx) |
| 258 | minSdkVersion := effectiveVersionString(sdkVersion, sdkContext.MinSdkVersion(ctx)) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 259 | |
Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 260 | linkFlags = append(linkFlags, "--min-sdk-version "+minSdkVersion) |
Spandan Das | 6450b55 | 2023-02-23 19:27:07 +0000 | [diff] [blame] | 261 | // Use minSdkVersion for target-sdk-version, even if `target_sdk_version` is set |
| 262 | // This behavior has been copied from Make. |
Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 263 | linkFlags = append(linkFlags, "--target-sdk-version "+minSdkVersion) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 264 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 265 | // Version code |
| 266 | if !hasVersionCode { |
Dan Albert | 4f378d7 | 2020-07-23 17:32:15 -0700 | [diff] [blame] | 267 | linkFlags = append(linkFlags, "--version-code", ctx.Config().PlatformSdkVersion().String()) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | if !hasVersionName { |
Colin Cross | 402d5e0 | 2018-04-25 14:54:06 -0700 | [diff] [blame] | 271 | var versionName string |
| 272 | if ctx.ModuleName() == "framework-res" { |
| 273 | // Some builds set AppsDefaultVersionName() to include the build number ("O-123456"). aapt2 copies the |
| 274 | // version name of framework-res into app manifests as compileSdkVersionCodename, which confuses things |
Colin Cross | bfd347d | 2018-05-09 11:11:35 -0700 | [diff] [blame] | 275 | // if it contains the build number. Use the PlatformVersionName instead. |
| 276 | versionName = ctx.Config().PlatformVersionName() |
Colin Cross | 402d5e0 | 2018-04-25 14:54:06 -0700 | [diff] [blame] | 277 | } else { |
| 278 | versionName = ctx.Config().AppsDefaultVersionName() |
| 279 | } |
Colin Cross | 0b9f31f | 2019-02-28 11:00:01 -0800 | [diff] [blame] | 280 | versionName = proptools.NinjaEscape(versionName) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 281 | linkFlags = append(linkFlags, "--version-name ", versionName) |
| 282 | } |
| 283 | |
Colin Cross | a0ba2f5 | 2019-06-22 12:59:27 -0700 | [diff] [blame] | 284 | linkFlags, compileFlags = android.FilterList(linkFlags, []string{"--legacy"}) |
| 285 | |
| 286 | // Always set --pseudo-localize, it will be stripped out later for release |
| 287 | // builds that don't want it. |
| 288 | compileFlags = append(compileFlags, "--pseudo-localize") |
| 289 | |
| 290 | return compileFlags, linkFlags, linkDeps, resDirs, overlayDirs, rroDirs, resourceZips |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 291 | } |
| 292 | |
Paul Duffin | 250e619 | 2019-06-07 10:44:37 +0100 | [diff] [blame] | 293 | func (a *aapt) deps(ctx android.BottomUpMutatorContext, sdkDep sdkDep) { |
Colin Cross | 42308aa | 2018-11-14 21:44:17 -0800 | [diff] [blame] | 294 | if sdkDep.frameworkResModule != "" { |
| 295 | ctx.AddVariationDependencies(nil, frameworkResTag, sdkDep.frameworkResModule) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 296 | } |
| 297 | } |
| 298 | |
Jaewoong Jung | 6431ca7 | 2020-01-15 14:15:10 -0800 | [diff] [blame] | 299 | var extractAssetsRule = pctx.AndroidStaticRule("extractAssets", |
| 300 | blueprint.RuleParams{ |
| 301 | Command: `${config.Zip2ZipCmd} -i ${in} -o ${out} "assets/**/*"`, |
| 302 | CommandDeps: []string{"${config.Zip2ZipCmd}"}, |
| 303 | }) |
| 304 | |
Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 305 | func (a *aapt) buildActions(ctx android.ModuleContext, sdkContext android.SdkContext, |
Paul Duffin | 0653057 | 2022-02-03 17:54:15 +0000 | [diff] [blame] | 306 | classLoaderContexts dexpreopt.ClassLoaderContextMap, excludedLibs []string, |
Harshit Mahajan | 5b8b730 | 2022-06-10 11:24:05 +0000 | [diff] [blame] | 307 | enforceDefaultTargetSdkVersion bool, extraLinkFlags ...string) { |
Colin Cross | 5446e88 | 2019-05-22 10:46:27 -0700 | [diff] [blame] | 308 | |
Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 309 | staticResourcesNodesDepSet, staticRRODirsDepSet, staticManifestsDepSet, sharedDeps, libFlags := |
Ulya Trafimovich | b23d28c | 2020-10-08 12:53:58 +0100 | [diff] [blame] | 310 | aaptLibs(ctx, sdkContext, classLoaderContexts) |
Ulya Trafimovich | 31e444e | 2020-08-14 17:32:16 +0100 | [diff] [blame] | 311 | |
Paul Duffin | 0653057 | 2022-02-03 17:54:15 +0000 | [diff] [blame] | 312 | // Exclude any libraries from the supplied list. |
| 313 | classLoaderContexts = classLoaderContexts.ExcludeLibs(excludedLibs) |
| 314 | |
Colin Cross | 3165695 | 2018-05-24 16:11:20 -0700 | [diff] [blame] | 315 | // App manifest file |
| 316 | manifestFile := proptools.StringDefault(a.aaptProperties.Manifest, "AndroidManifest.xml") |
| 317 | manifestSrcPath := android.PathForModuleSrc(ctx, manifestFile) |
| 318 | |
Gurpreet Singh | 7deabfa | 2022-02-10 13:28:35 +0000 | [diff] [blame] | 319 | manifestPath := ManifestFixer(ctx, manifestSrcPath, ManifestFixerParams{ |
Harshit Mahajan | 5b8b730 | 2022-06-10 11:24:05 +0000 | [diff] [blame] | 320 | SdkContext: sdkContext, |
| 321 | ClassLoaderContexts: classLoaderContexts, |
| 322 | IsLibrary: a.isLibrary, |
| 323 | DefaultManifestVersion: a.defaultManifestVersion, |
| 324 | UseEmbeddedNativeLibs: a.useEmbeddedNativeLibs, |
| 325 | UsesNonSdkApis: a.usesNonSdkApis, |
| 326 | UseEmbeddedDex: a.useEmbeddedDex, |
| 327 | HasNoCode: a.hasNoCode, |
| 328 | LoggingParent: a.LoggingParent, |
| 329 | EnforceDefaultTargetSdkVersion: enforceDefaultTargetSdkVersion, |
Gurpreet Singh | 75d65f3 | 2022-01-24 17:44:05 +0000 | [diff] [blame] | 330 | }) |
Colin Cross | 90c25c6 | 2019-04-19 16:22:57 -0700 | [diff] [blame] | 331 | |
Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 332 | staticDeps := transitiveAarDeps(staticResourcesNodesDepSet.ToList()) |
| 333 | |
Luca Stefani | fd89882 | 2019-09-10 22:13:31 +0200 | [diff] [blame] | 334 | // Add additional manifest files to transitive manifests. |
| 335 | additionalManifests := android.PathsForModuleSrc(ctx, a.aaptProperties.Additional_manifests) |
Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 336 | transitiveManifestPaths := append(android.Paths{manifestPath}, additionalManifests...) |
| 337 | // TODO(b/288358614): Soong has historically not merged manifests from dependencies of android_library_import |
| 338 | // modules. Merging manifests from dependencies could remove the need for pom2bp to generate the "-nodeps" copies |
| 339 | // of androidx libraries, but doing so triggers errors due to errors introduced by existing dependencies of |
| 340 | // android_library_import modules. If this is fixed, staticManifestsDepSet can be dropped completely in favor of |
| 341 | // staticResourcesNodesDepSet.manifests() |
| 342 | transitiveManifestPaths = append(transitiveManifestPaths, staticManifestsDepSet.ToList()...) |
Colin Cross | 90c25c6 | 2019-04-19 16:22:57 -0700 | [diff] [blame] | 343 | |
Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 344 | if len(transitiveManifestPaths) > 1 && !Bool(a.aaptProperties.Dont_merge_manifests) { |
| 345 | a.mergedManifestFile = manifestMerger(ctx, transitiveManifestPaths[0], transitiveManifestPaths[1:], a.isLibrary) |
Colin Cross | 90c25c6 | 2019-04-19 16:22:57 -0700 | [diff] [blame] | 346 | if !a.isLibrary { |
| 347 | // Only use the merged manifest for applications. For libraries, the transitive closure of manifests |
| 348 | // will be propagated to the final application and merged there. The merged manifest for libraries is |
| 349 | // only passed to Make, which can't handle transitive dependencies. |
| 350 | manifestPath = a.mergedManifestFile |
| 351 | } |
| 352 | } else { |
| 353 | a.mergedManifestFile = manifestPath |
| 354 | } |
Colin Cross | 3165695 | 2018-05-24 16:11:20 -0700 | [diff] [blame] | 355 | |
Colin Cross | a0ba2f5 | 2019-06-22 12:59:27 -0700 | [diff] [blame] | 356 | compileFlags, linkFlags, linkDeps, resDirs, overlayDirs, rroDirs, resZips := a.aapt2Flags(ctx, sdkContext, manifestPath) |
Colin Cross | 3165695 | 2018-05-24 16:11:20 -0700 | [diff] [blame] | 357 | |
| 358 | linkFlags = append(linkFlags, libFlags...) |
Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 359 | linkDeps = append(linkDeps, sharedDeps...) |
| 360 | linkDeps = append(linkDeps, staticDeps.resPackages()...) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 361 | linkFlags = append(linkFlags, extraLinkFlags...) |
Colin Cross | 1b6a3cf | 2018-07-24 14:51:30 -0700 | [diff] [blame] | 362 | if a.isLibrary { |
| 363 | linkFlags = append(linkFlags, "--static-lib") |
| 364 | } |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 365 | |
Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 366 | if a.isLibrary && a.useResourceProcessorBusyBox() { |
| 367 | // When building an android_library using ResourceProcessorBusyBox the resources are merged into |
| 368 | // package-res.apk with --merge-only, but --no-static-lib-packages is not used so that R.txt only |
| 369 | // contains resources from this library. |
| 370 | linkFlags = append(linkFlags, "--merge-only") |
| 371 | } else { |
| 372 | // When building and app or when building an android_library without ResourceProcessorBusyBox |
| 373 | // --no-static-lib-packages is used to put all the resources into the app. If ResourceProcessorBusyBox |
| 374 | // is used then the app's R.txt will be post-processed along with the R.txt files from dependencies to |
| 375 | // sort resources into the right packages in R.class. |
| 376 | linkFlags = append(linkFlags, "--no-static-lib-packages") |
| 377 | } |
| 378 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 379 | packageRes := android.PathForModuleOut(ctx, "package-res.apk") |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 380 | proguardOptionsFile := android.PathForModuleGen(ctx, "proguard.options") |
| 381 | rTxt := android.PathForModuleOut(ctx, "R.txt") |
Colin Cross | 66f7882 | 2018-05-02 12:58:28 -0700 | [diff] [blame] | 382 | // This file isn't used by Soong, but is generated for exporting |
| 383 | extraPackages := android.PathForModuleOut(ctx, "extra_packages") |
Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 384 | var transitiveRJars android.Paths |
Colin Cross | f3b7bad | 2023-08-02 15:49:00 -0700 | [diff] [blame] | 385 | var srcJar android.WritablePath |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 386 | |
Colin Cross | 4aaa84a | 2018-08-21 15:14:37 -0700 | [diff] [blame] | 387 | var compiledResDirs []android.Paths |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 388 | for _, dir := range resDirs { |
Colin Cross | 014489c | 2020-06-02 20:09:13 -0700 | [diff] [blame] | 389 | a.resourceFiles = append(a.resourceFiles, dir.files...) |
Colin Cross | a0ba2f5 | 2019-06-22 12:59:27 -0700 | [diff] [blame] | 390 | compiledResDirs = append(compiledResDirs, aapt2Compile(ctx, dir.dir, dir.files, compileFlags).Paths()) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 391 | } |
Colin Cross | 4aaa84a | 2018-08-21 15:14:37 -0700 | [diff] [blame] | 392 | |
Colin Cross | a592e3e | 2019-02-19 16:59:53 -0800 | [diff] [blame] | 393 | for i, zip := range resZips { |
| 394 | flata := android.PathForModuleOut(ctx, fmt.Sprintf("reszip.%d.flata", i)) |
Colin Cross | a0ba2f5 | 2019-06-22 12:59:27 -0700 | [diff] [blame] | 395 | aapt2CompileZip(ctx, flata, zip, "", compileFlags) |
Colin Cross | a592e3e | 2019-02-19 16:59:53 -0800 | [diff] [blame] | 396 | compiledResDirs = append(compiledResDirs, android.Paths{flata}) |
| 397 | } |
| 398 | |
Colin Cross | 4aaa84a | 2018-08-21 15:14:37 -0700 | [diff] [blame] | 399 | var compiledRes, compiledOverlay android.Paths |
| 400 | |
Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 401 | // AAPT2 overlays are in lowest to highest priority order, reverse the topological order |
| 402 | // of transitiveStaticLibs. |
| 403 | transitiveStaticLibs := android.ReversePaths(staticDeps.resPackages()) |
| 404 | |
Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 405 | if a.isLibrary && a.useResourceProcessorBusyBox() { |
| 406 | // When building an android_library with ResourceProcessorBusyBox enabled treat static library dependencies |
| 407 | // as imports. The resources from dependencies will not be merged into this module's package-res.apk, and |
| 408 | // instead modules depending on this module will reference package-res.apk from all transitive static |
| 409 | // dependencies. |
| 410 | for _, staticDep := range staticDeps { |
| 411 | linkDeps = append(linkDeps, staticDep.resPackage) |
| 412 | linkFlags = append(linkFlags, "-I "+staticDep.resPackage.String()) |
| 413 | if staticDep.usedResourceProcessor { |
| 414 | transitiveRJars = append(transitiveRJars, staticDep.rJar) |
| 415 | } |
| 416 | } |
| 417 | } else { |
| 418 | // When building an app or building a library without ResourceProcessorBusyBox enabled all static |
| 419 | // dependencies are compiled into this module's package-res.apk as overlays. |
| 420 | compiledOverlay = append(compiledOverlay, transitiveStaticLibs...) |
| 421 | } |
Colin Cross | 4aaa84a | 2018-08-21 15:14:37 -0700 | [diff] [blame] | 422 | |
Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 423 | if len(transitiveStaticLibs) > 0 { |
Colin Cross | 4aaa84a | 2018-08-21 15:14:37 -0700 | [diff] [blame] | 424 | // If we are using static android libraries, every source file becomes an overlay. |
| 425 | // This is to emulate old AAPT behavior which simulated library support. |
| 426 | for _, compiledResDir := range compiledResDirs { |
| 427 | compiledOverlay = append(compiledOverlay, compiledResDir...) |
| 428 | } |
Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 429 | } else if a.isLibrary { |
| 430 | // Otherwise, for a static library we treat all the resources equally with no overlay. |
| 431 | for _, compiledResDir := range compiledResDirs { |
| 432 | compiledRes = append(compiledRes, compiledResDir...) |
| 433 | } |
Colin Cross | 4aaa84a | 2018-08-21 15:14:37 -0700 | [diff] [blame] | 434 | } else if len(compiledResDirs) > 0 { |
| 435 | // Without static libraries, the first directory is our directory, which can then be |
| 436 | // overlaid by the rest. |
| 437 | compiledRes = append(compiledRes, compiledResDirs[0]...) |
| 438 | for _, compiledResDir := range compiledResDirs[1:] { |
| 439 | compiledOverlay = append(compiledOverlay, compiledResDir...) |
| 440 | } |
| 441 | } |
| 442 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 443 | for _, dir := range overlayDirs { |
Colin Cross | a0ba2f5 | 2019-06-22 12:59:27 -0700 | [diff] [blame] | 444 | compiledOverlay = append(compiledOverlay, aapt2Compile(ctx, dir.dir, dir.files, compileFlags).Paths()...) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 445 | } |
| 446 | |
Colin Cross | e560c4a | 2019-03-19 16:03:11 -0700 | [diff] [blame] | 447 | var splitPackages android.WritablePaths |
| 448 | var splits []split |
| 449 | |
| 450 | for _, s := range a.splitNames { |
| 451 | suffix := strings.Replace(s, ",", "_", -1) |
| 452 | path := android.PathForModuleOut(ctx, "package_"+suffix+".apk") |
| 453 | linkFlags = append(linkFlags, "--split", path.String()+":"+s) |
| 454 | splitPackages = append(splitPackages, path) |
| 455 | splits = append(splits, split{ |
| 456 | name: s, |
| 457 | suffix: suffix, |
| 458 | path: path, |
| 459 | }) |
| 460 | } |
| 461 | |
Colin Cross | f3b7bad | 2023-08-02 15:49:00 -0700 | [diff] [blame] | 462 | if !a.useResourceProcessorBusyBox() { |
| 463 | // the subdir "android" is required to be filtered by package names |
| 464 | srcJar = android.PathForModuleGen(ctx, "android", "R.srcjar") |
| 465 | } |
| 466 | |
Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 467 | // No need to specify assets from dependencies to aapt2Link for libraries, all transitive assets will be |
| 468 | // provided to the final app aapt2Link step. |
| 469 | var transitiveAssets android.Paths |
| 470 | if !a.isLibrary { |
| 471 | transitiveAssets = android.ReverseSliceInPlace(staticDeps.assets()) |
| 472 | } |
Colin Cross | f3b7bad | 2023-08-02 15:49:00 -0700 | [diff] [blame] | 473 | aapt2Link(ctx, packageRes, srcJar, proguardOptionsFile, rTxt, |
Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 474 | linkFlags, linkDeps, compiledRes, compiledOverlay, transitiveAssets, splitPackages) |
Jaewoong Jung | 6431ca7 | 2020-01-15 14:15:10 -0800 | [diff] [blame] | 475 | // Extract assets from the resource package output so that they can be used later in aapt2link |
| 476 | // for modules that depend on this one. |
Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 477 | if android.PrefixInList(linkFlags, "-A ") { |
Jaewoong Jung | 6431ca7 | 2020-01-15 14:15:10 -0800 | [diff] [blame] | 478 | assets := android.PathForModuleOut(ctx, "assets.zip") |
| 479 | ctx.Build(pctx, android.BuildParams{ |
| 480 | Rule: extractAssetsRule, |
| 481 | Input: packageRes, |
| 482 | Output: assets, |
| 483 | Description: "extract assets from built resource file", |
| 484 | }) |
| 485 | a.assetPackage = android.OptionalPathForPath(assets) |
| 486 | } |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 487 | |
Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 488 | if a.useResourceProcessorBusyBox() { |
| 489 | rJar := android.PathForModuleOut(ctx, "busybox/R.jar") |
| 490 | resourceProcessorBusyBoxGenerateBinaryR(ctx, rTxt, a.mergedManifestFile, rJar, staticDeps, a.isLibrary) |
Colin Cross | f3b7bad | 2023-08-02 15:49:00 -0700 | [diff] [blame] | 491 | aapt2ExtractExtraPackages(ctx, extraPackages, rJar) |
Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 492 | transitiveRJars = append(transitiveRJars, rJar) |
| 493 | a.rJar = rJar |
Colin Cross | f3b7bad | 2023-08-02 15:49:00 -0700 | [diff] [blame] | 494 | } else { |
| 495 | aapt2ExtractExtraPackages(ctx, extraPackages, srcJar) |
Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 496 | } |
| 497 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 498 | a.aaptSrcJar = srcJar |
Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 499 | a.transitiveAaptRJars = transitiveRJars |
| 500 | a.transitiveAaptResourcePackages = staticDeps.resPackages() |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 501 | a.exportPackage = packageRes |
| 502 | a.manifestPath = manifestPath |
| 503 | a.proguardOptionsFile = proguardOptionsFile |
Colin Cross | 66f7882 | 2018-05-02 12:58:28 -0700 | [diff] [blame] | 504 | a.extraAaptPackagesFile = extraPackages |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 505 | a.rTxt = rTxt |
Colin Cross | e560c4a | 2019-03-19 16:03:11 -0700 | [diff] [blame] | 506 | a.splits = splits |
Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 507 | a.resourcesNodesDepSet = android.NewDepSetBuilder[*resourcesNode](android.TOPOLOGICAL). |
| 508 | Direct(&resourcesNode{ |
| 509 | resPackage: a.exportPackage, |
| 510 | manifest: a.manifestPath, |
| 511 | additionalManifests: additionalManifests, |
Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 512 | rTxt: a.rTxt, |
| 513 | rJar: a.rJar, |
Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 514 | assets: a.assetPackage, |
Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 515 | |
| 516 | usedResourceProcessor: a.useResourceProcessorBusyBox(), |
Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 517 | }). |
| 518 | Transitive(staticResourcesNodesDepSet).Build() |
| 519 | a.rroDirsDepSet = android.NewDepSetBuilder[rroDir](android.TOPOLOGICAL). |
| 520 | Direct(rroDirs...). |
| 521 | Transitive(staticRRODirsDepSet).Build() |
| 522 | a.manifestsDepSet = android.NewDepSetBuilder[android.Path](android.TOPOLOGICAL). |
| 523 | Direct(a.manifestPath). |
| 524 | DirectSlice(additionalManifests). |
| 525 | Transitive(staticManifestsDepSet).Build() |
| 526 | } |
| 527 | |
Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 528 | var resourceProcessorBusyBox = pctx.AndroidStaticRule("resourceProcessorBusyBox", |
| 529 | blueprint.RuleParams{ |
| 530 | Command: "${config.JavaCmd} -cp ${config.ResourceProcessorBusyBox} " + |
| 531 | "com.google.devtools.build.android.ResourceProcessorBusyBox --tool=GENERATE_BINARY_R -- @${out}.args && " + |
| 532 | "if cmp -s ${out}.tmp ${out} ; then rm ${out}.tmp ; else mv ${out}.tmp ${out}; fi", |
| 533 | CommandDeps: []string{"${config.ResourceProcessorBusyBox}"}, |
| 534 | Rspfile: "${out}.args", |
| 535 | RspfileContent: "--primaryRTxt ${rTxt} --primaryManifest ${manifest} --classJarOutput ${out}.tmp ${args}", |
| 536 | Restat: true, |
| 537 | }, "rTxt", "manifest", "args") |
| 538 | |
| 539 | // resourceProcessorBusyBoxGenerateBinaryR converts the R.txt file produced by aapt2 into R.class files |
| 540 | // using Bazel's ResourceProcessorBusyBox tool, which is faster than compiling the R.java files and |
| 541 | // supports producing classes for static dependencies that only include resources from that dependency. |
| 542 | func resourceProcessorBusyBoxGenerateBinaryR(ctx android.ModuleContext, rTxt, manifest android.Path, |
| 543 | rJar android.WritablePath, transitiveDeps transitiveAarDeps, isLibrary bool) { |
| 544 | |
| 545 | var args []string |
| 546 | var deps android.Paths |
| 547 | |
| 548 | if !isLibrary { |
| 549 | // When compiling an app, pass all R.txt and AndroidManifest.xml from transitive static library dependencies |
| 550 | // to ResourceProcessorBusyBox so that it can regenerate R.class files with the final resource IDs for each |
| 551 | // package. |
| 552 | args, deps = transitiveDeps.resourceProcessorDeps() |
| 553 | } else { |
| 554 | // When compiling a library don't pass any dependencies as it only needs to generate an R.class file for this |
| 555 | // library. Pass --finalFields=false so that the R.class file contains non-final fields so they don't get |
| 556 | // inlined into the library before the final IDs are assigned during app compilation. |
| 557 | args = append(args, "--finalFields=false") |
| 558 | } |
| 559 | |
| 560 | deps = append(deps, rTxt, manifest) |
| 561 | |
| 562 | ctx.Build(pctx, android.BuildParams{ |
| 563 | Rule: resourceProcessorBusyBox, |
| 564 | Output: rJar, |
| 565 | Implicits: deps, |
| 566 | Description: "ResourceProcessorBusyBox", |
| 567 | Args: map[string]string{ |
| 568 | "rTxt": rTxt.String(), |
| 569 | "manifest": manifest.String(), |
| 570 | "args": strings.Join(args, " "), |
| 571 | }, |
| 572 | }) |
| 573 | } |
| 574 | |
Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 575 | type resourcesNode struct { |
| 576 | resPackage android.Path |
| 577 | manifest android.Path |
| 578 | additionalManifests android.Paths |
Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 579 | rTxt android.Path |
| 580 | rJar android.Path |
Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 581 | assets android.OptionalPath |
Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 582 | |
| 583 | usedResourceProcessor bool |
Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 584 | } |
| 585 | |
| 586 | type transitiveAarDeps []*resourcesNode |
| 587 | |
| 588 | func (t transitiveAarDeps) resPackages() android.Paths { |
Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 589 | paths := make(android.Paths, 0, len(t)) |
Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 590 | for _, dep := range t { |
| 591 | paths = append(paths, dep.resPackage) |
| 592 | } |
Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 593 | return paths |
Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 594 | } |
| 595 | |
| 596 | func (t transitiveAarDeps) manifests() android.Paths { |
Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 597 | paths := make(android.Paths, 0, len(t)) |
Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 598 | for _, dep := range t { |
| 599 | paths = append(paths, dep.manifest) |
| 600 | paths = append(paths, dep.additionalManifests...) |
| 601 | } |
Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 602 | return paths |
| 603 | } |
| 604 | |
| 605 | func (t transitiveAarDeps) resourceProcessorDeps() (args []string, deps android.Paths) { |
| 606 | for _, dep := range t { |
| 607 | args = append(args, "--library="+dep.rTxt.String()+","+dep.manifest.String()) |
| 608 | deps = append(deps, dep.rTxt, dep.manifest) |
| 609 | } |
| 610 | return args, deps |
Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 611 | } |
| 612 | |
| 613 | func (t transitiveAarDeps) assets() android.Paths { |
Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 614 | paths := make(android.Paths, 0, len(t)) |
Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 615 | for _, dep := range t { |
| 616 | if dep.assets.Valid() { |
| 617 | paths = append(paths, dep.assets.Path()) |
| 618 | } |
| 619 | } |
| 620 | return paths |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 621 | } |
| 622 | |
| 623 | // aaptLibs collects libraries from dependencies and sdk_version and converts them into paths |
Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 624 | func aaptLibs(ctx android.ModuleContext, sdkContext android.SdkContext, classLoaderContexts dexpreopt.ClassLoaderContextMap) ( |
Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 625 | staticResourcesNodes *android.DepSet[*resourcesNode], staticRRODirs *android.DepSet[rroDir], |
| 626 | staticManifests *android.DepSet[android.Path], sharedLibs android.Paths, flags []string) { |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 627 | |
Ulya Trafimovich | b23d28c | 2020-10-08 12:53:58 +0100 | [diff] [blame] | 628 | if classLoaderContexts == nil { |
Ulya Trafimovich | 1855424 | 2020-11-03 15:55:11 +0000 | [diff] [blame] | 629 | // Not all callers need to compute class loader context, those who don't just pass nil. |
| 630 | // Create a temporary class loader context here (it will be computed, but not used). |
Ulya Trafimovich | b23d28c | 2020-10-08 12:53:58 +0100 | [diff] [blame] | 631 | classLoaderContexts = make(dexpreopt.ClassLoaderContextMap) |
Ulya Trafimovich | 1855424 | 2020-11-03 15:55:11 +0000 | [diff] [blame] | 632 | } |
| 633 | |
Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 634 | sdkDep := decodeSdkDep(ctx, sdkContext) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 635 | if sdkDep.useFiles { |
Colin Cross | 86a60ae | 2018-05-29 14:44:55 -0700 | [diff] [blame] | 636 | sharedLibs = append(sharedLibs, sdkDep.jars...) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 637 | } |
| 638 | |
Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 639 | var resourcesNodeDepSets []*android.DepSet[*resourcesNode] |
| 640 | rroDirsDepSetBuilder := android.NewDepSetBuilder[rroDir](android.TOPOLOGICAL) |
| 641 | manifestsDepSetBuilder := android.NewDepSetBuilder[android.Path](android.TOPOLOGICAL) |
| 642 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 643 | ctx.VisitDirectDeps(func(module android.Module) { |
Ulya Trafimovich | 65b0319 | 2020-12-03 16:50:22 +0000 | [diff] [blame] | 644 | depTag := ctx.OtherModuleDependencyTag(module) |
Ulya Trafimovich | 1855424 | 2020-11-03 15:55:11 +0000 | [diff] [blame] | 645 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 646 | var exportPackage android.Path |
Colin Cross | 66f7882 | 2018-05-02 12:58:28 -0700 | [diff] [blame] | 647 | aarDep, _ := module.(AndroidLibraryDependency) |
| 648 | if aarDep != nil { |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 649 | exportPackage = aarDep.ExportPackage() |
| 650 | } |
| 651 | |
Ulya Trafimovich | 65b0319 | 2020-12-03 16:50:22 +0000 | [diff] [blame] | 652 | switch depTag { |
Colin Cross | 4b964c0 | 2018-10-15 16:18:06 -0700 | [diff] [blame] | 653 | case instrumentationForTag: |
| 654 | // Nothing, instrumentationForTag is treated as libTag for javac but not for aapt2. |
Liz Kammer | ef28a4c | 2022-09-23 16:50:56 -0400 | [diff] [blame] | 655 | case sdkLibTag, libTag: |
Colin Cross | 5446e88 | 2019-05-22 10:46:27 -0700 | [diff] [blame] | 656 | if exportPackage != nil { |
| 657 | sharedLibs = append(sharedLibs, exportPackage) |
| 658 | } |
Colin Cross | 5446e88 | 2019-05-22 10:46:27 -0700 | [diff] [blame] | 659 | case frameworkResTag: |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 660 | if exportPackage != nil { |
| 661 | sharedLibs = append(sharedLibs, exportPackage) |
| 662 | } |
| 663 | case staticLibTag: |
| 664 | if exportPackage != nil { |
Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 665 | resourcesNodeDepSets = append(resourcesNodeDepSets, aarDep.ResourcesNodeDepSet()) |
| 666 | rroDirsDepSetBuilder.Transitive(aarDep.RRODirsDepSet()) |
| 667 | manifestsDepSetBuilder.Transitive(aarDep.ManifestsDepSet()) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 668 | } |
| 669 | } |
Ulya Trafimovich | 1855424 | 2020-11-03 15:55:11 +0000 | [diff] [blame] | 670 | |
Ulya Trafimovich | 88bb6f6 | 2020-12-16 16:16:11 +0000 | [diff] [blame] | 671 | addCLCFromDep(ctx, module, classLoaderContexts) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 672 | }) |
| 673 | |
Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 674 | // AAPT2 overlays are in lowest to highest priority order, the topological order will be reversed later. |
| 675 | // Reverse the dependency order now going into the depset so that it comes out in order after the second |
| 676 | // reverse later. |
| 677 | // NOTE: this is legacy and probably incorrect behavior, for most other cases (e.g. conflicting classes in |
| 678 | // dependencies) the highest priority dependency is listed first, but for resources the highest priority |
| 679 | // dependency has to be listed last. |
| 680 | staticResourcesNodes = android.NewDepSet(android.TOPOLOGICAL, nil, |
| 681 | android.ReverseSliceInPlace(resourcesNodeDepSets)) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 682 | |
Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 683 | staticRRODirs = rroDirsDepSetBuilder.Build() |
| 684 | staticManifests = manifestsDepSetBuilder.Build() |
| 685 | |
| 686 | if len(staticResourcesNodes.ToList()) > 0 { |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 687 | flags = append(flags, "--auto-add-overlay") |
| 688 | } |
| 689 | |
| 690 | for _, sharedLib := range sharedLibs { |
| 691 | flags = append(flags, "-I "+sharedLib.String()) |
| 692 | } |
| 693 | |
Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 694 | return staticResourcesNodes, staticRRODirs, staticManifests, sharedLibs, flags |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 695 | } |
| 696 | |
| 697 | type AndroidLibrary struct { |
| 698 | Library |
| 699 | aapt |
Romain Jobredeaux | c9b2bba | 2022-02-15 09:35:07 -0500 | [diff] [blame] | 700 | android.BazelModuleBase |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 701 | |
| 702 | androidLibraryProperties androidLibraryProperties |
| 703 | |
| 704 | aarFile android.WritablePath |
Colin Cross | 89c3158 | 2018-04-30 15:55:11 -0700 | [diff] [blame] | 705 | } |
| 706 | |
Saeid Farivar Asanjan | 1fca301 | 2021-09-14 18:40:19 +0000 | [diff] [blame] | 707 | var _ android.OutputFileProducer = (*AndroidLibrary)(nil) |
| 708 | |
| 709 | // For OutputFileProducer interface |
| 710 | func (a *AndroidLibrary) OutputFiles(tag string) (android.Paths, error) { |
| 711 | switch tag { |
| 712 | case ".aar": |
| 713 | return []android.Path{a.aarFile}, nil |
| 714 | default: |
| 715 | return a.Library.OutputFiles(tag) |
| 716 | } |
| 717 | } |
| 718 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 719 | var _ AndroidLibraryDependency = (*AndroidLibrary)(nil) |
| 720 | |
| 721 | func (a *AndroidLibrary) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 722 | a.Module.deps(ctx) |
Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 723 | sdkDep := decodeSdkDep(ctx, android.SdkContext(a)) |
Paul Duffin | 250e619 | 2019-06-07 10:44:37 +0100 | [diff] [blame] | 724 | if sdkDep.hasFrameworkLibs() { |
| 725 | a.aapt.deps(ctx, sdkDep) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 726 | } |
Colin Cross | 4a80a15 | 2022-12-21 21:51:52 -0800 | [diff] [blame] | 727 | a.usesLibrary.deps(ctx, false) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 728 | } |
| 729 | |
| 730 | func (a *AndroidLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Colin Cross | e4246ab | 2019-02-05 21:55:21 -0800 | [diff] [blame] | 731 | a.aapt.isLibrary = true |
Ulya Trafimovich | 42c7f0d | 2021-08-17 16:20:29 +0100 | [diff] [blame] | 732 | a.classLoaderContexts = a.usesLibrary.classLoaderContextForUsesLibDeps(ctx) |
Harshit Mahajan | 5b8b730 | 2022-06-10 11:24:05 +0000 | [diff] [blame] | 733 | a.aapt.buildActions(ctx, android.SdkContext(a), a.classLoaderContexts, nil, false) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 734 | |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 735 | a.hideApexVariantFromMake = !ctx.Provider(android.ApexInfoProvider).(android.ApexInfo).IsForPlatform() |
| 736 | |
Jihoon Kang | 1bfb6f2 | 2023-07-01 00:13:47 +0000 | [diff] [blame] | 737 | a.stem = proptools.StringDefault(a.overridableDeviceProperties.Stem, ctx.ModuleName()) |
| 738 | |
Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 739 | ctx.CheckbuildFile(a.aapt.proguardOptionsFile) |
| 740 | ctx.CheckbuildFile(a.aapt.exportPackage) |
Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 741 | if a.useResourceProcessorBusyBox() { |
| 742 | ctx.CheckbuildFile(a.aapt.rJar) |
Colin Cross | f3b7bad | 2023-08-02 15:49:00 -0700 | [diff] [blame] | 743 | } else { |
| 744 | ctx.CheckbuildFile(a.aapt.aaptSrcJar) |
Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 745 | } |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 746 | |
| 747 | // apps manifests are handled by aapt, don't let Module see them |
| 748 | a.properties.Manifest = nil |
| 749 | |
Colin Cross | 014489c | 2020-06-02 20:09:13 -0700 | [diff] [blame] | 750 | a.linter.mergedManifest = a.aapt.mergedManifestFile |
| 751 | a.linter.manifest = a.aapt.manifestPath |
| 752 | a.linter.resources = a.aapt.resourceFiles |
| 753 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 754 | a.Module.extraProguardFlagFiles = append(a.Module.extraProguardFlagFiles, |
| 755 | a.proguardOptionsFile) |
| 756 | |
Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 757 | var extraSrcJars android.Paths |
| 758 | var extraCombinedJars android.Paths |
| 759 | var extraClasspathJars android.Paths |
| 760 | if a.useResourceProcessorBusyBox() { |
| 761 | // When building a library with ResourceProcessorBusyBox enabled ResourceProcessorBusyBox for this |
| 762 | // library and each of the transitive static android_library dependencies has already created an |
| 763 | // R.class file for the appropriate package. Add all of those R.class files to the classpath. |
| 764 | extraClasspathJars = a.transitiveAaptRJars |
| 765 | } else { |
| 766 | // When building a library without ResourceProcessorBusyBox the aapt2 rule creates R.srcjar containing |
| 767 | // R.java files for the library's package and the packages from all transitive static android_library |
| 768 | // dependencies. Compile the srcjar alongside the rest of the sources. |
| 769 | extraSrcJars = android.Paths{a.aapt.aaptSrcJar} |
| 770 | } |
| 771 | |
| 772 | a.Module.compile(ctx, extraSrcJars, extraClasspathJars, extraCombinedJars) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 773 | |
Colin Cross | f57c578 | 2019-01-25 13:20:38 -0800 | [diff] [blame] | 774 | a.aarFile = android.PathForModuleOut(ctx, ctx.ModuleName()+".aar") |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 775 | var res android.Paths |
| 776 | if a.androidLibraryProperties.BuildAAR { |
| 777 | BuildAAR(ctx, a.aarFile, a.outputFile, a.manifestPath, a.rTxt, res) |
| 778 | ctx.CheckbuildFile(a.aarFile) |
| 779 | } |
Colin Cross | 89c3158 | 2018-04-30 15:55:11 -0700 | [diff] [blame] | 780 | |
Cole Faust | 9a63131 | 2020-10-22 21:05:24 +0000 | [diff] [blame] | 781 | a.exportedProguardFlagFiles = append(a.exportedProguardFlagFiles, |
| 782 | android.PathsForModuleSrc(ctx, a.dexProperties.Optimize.Proguard_flags_files)...) |
Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 783 | |
Colin Cross | 89c3158 | 2018-04-30 15:55:11 -0700 | [diff] [blame] | 784 | ctx.VisitDirectDeps(func(m android.Module) { |
Jared Duke | 5979b30 | 2022-12-19 21:08:39 +0000 | [diff] [blame] | 785 | if ctx.OtherModuleDependencyTag(m) == staticLibTag { |
| 786 | if lib, ok := m.(LibraryDependency); ok { |
| 787 | a.exportedProguardFlagFiles = append(a.exportedProguardFlagFiles, lib.ExportedProguardFlagFiles()...) |
| 788 | } |
Colin Cross | 89c3158 | 2018-04-30 15:55:11 -0700 | [diff] [blame] | 789 | } |
| 790 | }) |
Colin Cross | 89c3158 | 2018-04-30 15:55:11 -0700 | [diff] [blame] | 791 | a.exportedProguardFlagFiles = android.FirstUniquePaths(a.exportedProguardFlagFiles) |
Sam Delmerico | 8260249 | 2022-06-10 17:05:42 +0000 | [diff] [blame] | 792 | |
| 793 | prebuiltJniPackages := android.Paths{} |
| 794 | ctx.VisitDirectDeps(func(module android.Module) { |
| 795 | if info, ok := ctx.OtherModuleProvider(module, JniPackageProvider).(JniPackageInfo); ok { |
| 796 | prebuiltJniPackages = append(prebuiltJniPackages, info.JniPackages...) |
| 797 | } |
| 798 | }) |
| 799 | if len(prebuiltJniPackages) > 0 { |
| 800 | ctx.SetProvider(JniPackageProvider, JniPackageInfo{ |
| 801 | JniPackages: prebuiltJniPackages, |
| 802 | }) |
| 803 | } |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 804 | } |
| 805 | |
Colin Cross | 1b16b0e | 2019-02-12 14:41:32 -0800 | [diff] [blame] | 806 | // android_library builds and links sources into a `.jar` file for the device along with Android resources. |
| 807 | // |
| 808 | // An android_library has a single variant that produces a `.jar` file containing `.class` files that were |
Sam Delmerico | 8260249 | 2022-06-10 17:05:42 +0000 | [diff] [blame] | 809 | // compiled against the device bootclasspath, along with a `package-res.apk` file containing Android resources compiled |
Colin Cross | 1b16b0e | 2019-02-12 14:41:32 -0800 | [diff] [blame] | 810 | // with aapt2. This module is not suitable for installing on a device, but can be used as a `static_libs` dependency of |
| 811 | // an android_app module. |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 812 | func AndroidLibraryFactory() android.Module { |
| 813 | module := &AndroidLibrary{} |
| 814 | |
Colin Cross | ce6734e | 2020-06-15 16:09:53 -0700 | [diff] [blame] | 815 | module.Module.addHostAndDeviceProperties() |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 816 | module.AddProperties( |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 817 | &module.aaptProperties, |
| 818 | &module.androidLibraryProperties) |
| 819 | |
| 820 | module.androidLibraryProperties.BuildAAR = true |
Colin Cross | 014489c | 2020-06-02 20:09:13 -0700 | [diff] [blame] | 821 | module.Module.linter.library = true |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 822 | |
Jooyung Han | acc7bbe | 2020-05-20 09:06:00 +0900 | [diff] [blame] | 823 | android.InitApexModule(module) |
Colin Cross | 48de9a4 | 2018-10-02 13:53:33 -0700 | [diff] [blame] | 824 | InitJavaModule(module, android.DeviceSupported) |
Romain Jobredeaux | c9b2bba | 2022-02-15 09:35:07 -0500 | [diff] [blame] | 825 | android.InitBazelModule(module) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 826 | return module |
| 827 | } |
| 828 | |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 829 | // |
| 830 | // AAR (android library) prebuilts |
| 831 | // |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 832 | |
Vinh Tran | ce0781f | 2022-04-13 01:30:44 +0000 | [diff] [blame] | 833 | // Properties for android_library_import |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 834 | type AARImportProperties struct { |
Vinh Tran | ce0781f | 2022-04-13 01:30:44 +0000 | [diff] [blame] | 835 | // ARR (android library prebuilt) filepath. Exactly one ARR is required. |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 836 | Aars []string `android:"path"` |
Vinh Tran | ce0781f | 2022-04-13 01:30:44 +0000 | [diff] [blame] | 837 | // If not blank, set to the version of the sdk to compile against. |
| 838 | // Defaults to private. |
| 839 | // Values are of one of the following forms: |
| 840 | // 1) numerical API level, "current", "none", or "core_platform" |
| 841 | // 2) An SDK kind with an API level: "<sdk kind>_<API level>" |
| 842 | // See build/soong/android/sdk_version.go for the complete and up to date list of SDK kinds. |
| 843 | // If the SDK kind is empty, it will be set to public |
| 844 | Sdk_version *string |
| 845 | // If not blank, set the minimum version of the sdk that the compiled artifacts will run against. |
| 846 | // Defaults to sdk_version if not set. See sdk_version for possible values. |
Colin Cross | 479884c | 2018-07-10 13:39:30 -0700 | [diff] [blame] | 847 | Min_sdk_version *string |
Vinh Tran | ce0781f | 2022-04-13 01:30:44 +0000 | [diff] [blame] | 848 | // List of java static libraries that the included ARR (android library prebuilts) has dependencies to. |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 849 | Static_libs []string |
Vinh Tran | ce0781f | 2022-04-13 01:30:44 +0000 | [diff] [blame] | 850 | // List of java libraries that the included ARR (android library prebuilts) has dependencies to. |
| 851 | Libs []string |
| 852 | // If set to true, run Jetifier against .aar file. Defaults to false. |
Colin Cross | 1001a79 | 2019-03-21 22:21:39 -0700 | [diff] [blame] | 853 | Jetifier *bool |
Sam Delmerico | 8260249 | 2022-06-10 17:05:42 +0000 | [diff] [blame] | 854 | // If true, extract JNI libs from AAR archive. These libs will be accessible to android_app modules and |
| 855 | // will be passed transitively through android_libraries to an android_app. |
| 856 | //TODO(b/241138093) evaluate whether we can have this flag default to true for Bazel conversion |
| 857 | Extract_jni *bool |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 858 | } |
| 859 | |
| 860 | type AARImport struct { |
| 861 | android.ModuleBase |
Colin Cross | 48de9a4 | 2018-10-02 13:53:33 -0700 | [diff] [blame] | 862 | android.DefaultableModuleBase |
Jooyung Han | acc7bbe | 2020-05-20 09:06:00 +0900 | [diff] [blame] | 863 | android.ApexModuleBase |
Romain Jobredeaux | c9b2bba | 2022-02-15 09:35:07 -0500 | [diff] [blame] | 864 | android.BazelModuleBase |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 865 | prebuilt android.Prebuilt |
| 866 | |
Jooyung Han | acc7bbe | 2020-05-20 09:06:00 +0900 | [diff] [blame] | 867 | // Functionality common to Module and Import. |
| 868 | embeddableInModuleAndImport |
| 869 | |
Sam Delmerico | 9f9c0a2 | 2022-11-29 11:19:37 -0500 | [diff] [blame] | 870 | providesTransitiveHeaderJars |
| 871 | |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 872 | properties AARImportProperties |
| 873 | |
Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 874 | classpathFile android.WritablePath |
| 875 | proguardFlags android.WritablePath |
| 876 | exportPackage android.WritablePath |
| 877 | transitiveAaptResourcePackages android.Paths |
| 878 | extraAaptPackagesFile android.WritablePath |
| 879 | manifest android.WritablePath |
| 880 | assetsPackage android.WritablePath |
| 881 | rTxt android.WritablePath |
| 882 | rJar android.WritablePath |
Colin Cross | 66f7882 | 2018-05-02 12:58:28 -0700 | [diff] [blame] | 883 | |
Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 884 | resourcesNodesDepSet *android.DepSet[*resourcesNode] |
| 885 | manifestsDepSet *android.DepSet[android.Path] |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 886 | |
| 887 | hideApexVariantFromMake bool |
Saeid Farivar Asanjan | f043696 | 2020-10-05 19:09:09 +0000 | [diff] [blame] | 888 | |
Sam Delmerico | 8260249 | 2022-06-10 17:05:42 +0000 | [diff] [blame] | 889 | aarPath android.Path |
| 890 | jniPackages android.Paths |
Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 891 | |
| 892 | sdkVersion android.SdkSpec |
Spandan Das | 8c9ae7e | 2023-03-03 21:20:36 +0000 | [diff] [blame] | 893 | minSdkVersion android.ApiLevel |
Saeid Farivar Asanjan | f043696 | 2020-10-05 19:09:09 +0000 | [diff] [blame] | 894 | } |
| 895 | |
| 896 | var _ android.OutputFileProducer = (*AARImport)(nil) |
| 897 | |
| 898 | // For OutputFileProducer interface |
| 899 | func (a *AARImport) OutputFiles(tag string) (android.Paths, error) { |
| 900 | switch tag { |
| 901 | case ".aar": |
| 902 | return []android.Path{a.aarPath}, nil |
| 903 | case "": |
| 904 | return []android.Path{a.classpathFile}, nil |
| 905 | default: |
| 906 | return nil, fmt.Errorf("unsupported module reference tag %q", tag) |
| 907 | } |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 908 | } |
| 909 | |
Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 910 | func (a *AARImport) SdkVersion(ctx android.EarlyModuleContext) android.SdkSpec { |
| 911 | return android.SdkSpecFrom(ctx, String(a.properties.Sdk_version)) |
Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 912 | } |
| 913 | |
Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 914 | func (a *AARImport) SystemModules() string { |
Paul Duffin | e25c644 | 2019-10-11 13:50:28 +0100 | [diff] [blame] | 915 | return "" |
| 916 | } |
| 917 | |
Spandan Das | 8c9ae7e | 2023-03-03 21:20:36 +0000 | [diff] [blame] | 918 | func (a *AARImport) MinSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel { |
Colin Cross | 479884c | 2018-07-10 13:39:30 -0700 | [diff] [blame] | 919 | if a.properties.Min_sdk_version != nil { |
Spandan Das | 8c9ae7e | 2023-03-03 21:20:36 +0000 | [diff] [blame] | 920 | return android.ApiLevelFrom(ctx, *a.properties.Min_sdk_version) |
Colin Cross | 479884c | 2018-07-10 13:39:30 -0700 | [diff] [blame] | 921 | } |
Spandan Das | 8c9ae7e | 2023-03-03 21:20:36 +0000 | [diff] [blame] | 922 | return a.SdkVersion(ctx).ApiLevel |
Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 923 | } |
| 924 | |
Spandan Das | a26eda7 | 2023-03-02 00:56:06 +0000 | [diff] [blame] | 925 | func (a *AARImport) ReplaceMaxSdkVersionPlaceholder(ctx android.EarlyModuleContext) android.ApiLevel { |
| 926 | return android.SdkSpecFrom(ctx, "").ApiLevel |
William Loh | 5a082f9 | 2022-05-17 20:21:50 +0000 | [diff] [blame] | 927 | } |
| 928 | |
Spandan Das | ca70fc4 | 2023-03-01 23:38:49 +0000 | [diff] [blame] | 929 | func (a *AARImport) TargetSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel { |
| 930 | return a.SdkVersion(ctx).ApiLevel |
Dan Willemsen | 419290a | 2018-10-31 15:28:47 -0700 | [diff] [blame] | 931 | } |
| 932 | |
Colin Cross | 1e74385 | 2019-10-28 11:37:20 -0700 | [diff] [blame] | 933 | func (a *AARImport) javaVersion() string { |
| 934 | return "" |
| 935 | } |
| 936 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 937 | var _ AndroidLibraryDependency = (*AARImport)(nil) |
| 938 | |
| 939 | func (a *AARImport) ExportPackage() android.Path { |
| 940 | return a.exportPackage |
| 941 | } |
Colin Cross | 89c3158 | 2018-04-30 15:55:11 -0700 | [diff] [blame] | 942 | func (a *AARImport) ExportedProguardFlagFiles() android.Paths { |
| 943 | return android.Paths{a.proguardFlags} |
| 944 | } |
| 945 | |
Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 946 | func (a *AARImport) ResourcesNodeDepSet() *android.DepSet[*resourcesNode] { |
| 947 | return a.resourcesNodesDepSet |
Colin Cross | c1c3755 | 2019-01-31 11:42:41 -0800 | [diff] [blame] | 948 | } |
| 949 | |
Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 950 | func (a *AARImport) RRODirsDepSet() *android.DepSet[rroDir] { |
| 951 | return android.NewDepSet[rroDir](android.TOPOLOGICAL, nil, nil) |
Colin Cross | 66f7882 | 2018-05-02 12:58:28 -0700 | [diff] [blame] | 952 | } |
| 953 | |
Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 954 | func (a *AARImport) ManifestsDepSet() *android.DepSet[android.Path] { |
| 955 | return a.manifestsDepSet |
Jaewoong Jung | 6431ca7 | 2020-01-15 14:15:10 -0800 | [diff] [blame] | 956 | } |
| 957 | |
Jaewoong Jung | c779cd4 | 2020-10-06 18:56:10 -0700 | [diff] [blame] | 958 | // RRO enforcement is not available on aar_import since its RRO dirs are not |
| 959 | // exported. |
| 960 | func (a *AARImport) SetRROEnforcedForDependent(enforce bool) { |
| 961 | } |
| 962 | |
| 963 | // RRO enforcement is not available on aar_import since its RRO dirs are not |
| 964 | // exported. |
| 965 | func (a *AARImport) IsRROEnforced(ctx android.BaseModuleContext) bool { |
| 966 | return false |
| 967 | } |
| 968 | |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 969 | func (a *AARImport) Prebuilt() *android.Prebuilt { |
| 970 | return &a.prebuilt |
| 971 | } |
| 972 | |
| 973 | func (a *AARImport) Name() string { |
| 974 | return a.prebuilt.Name(a.ModuleBase.Name()) |
| 975 | } |
| 976 | |
Jiyong Park | 618922e | 2020-01-08 13:35:43 +0900 | [diff] [blame] | 977 | func (a *AARImport) JacocoReportClassesFile() android.Path { |
| 978 | return nil |
| 979 | } |
| 980 | |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 981 | func (a *AARImport) DepsMutator(ctx android.BottomUpMutatorContext) { |
Jeongik Cha | 816a23a | 2020-07-08 01:09:23 +0900 | [diff] [blame] | 982 | if !ctx.Config().AlwaysUsePrebuiltSdks() { |
Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 983 | sdkDep := decodeSdkDep(ctx, android.SdkContext(a)) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 984 | if sdkDep.useModule && sdkDep.frameworkResModule != "" { |
Colin Cross | 42d48b7 | 2018-08-29 14:10:52 -0700 | [diff] [blame] | 985 | ctx.AddVariationDependencies(nil, frameworkResTag, sdkDep.frameworkResModule) |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 986 | } |
| 987 | } |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 988 | |
Colin Cross | 42d48b7 | 2018-08-29 14:10:52 -0700 | [diff] [blame] | 989 | ctx.AddVariationDependencies(nil, libTag, a.properties.Libs...) |
| 990 | ctx.AddVariationDependencies(nil, staticLibTag, a.properties.Static_libs...) |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 991 | } |
| 992 | |
Sam Delmerico | 8260249 | 2022-06-10 17:05:42 +0000 | [diff] [blame] | 993 | type JniPackageInfo struct { |
| 994 | // List of zip files containing JNI libraries |
| 995 | // Zip files should have directory structure jni/<arch>/*.so |
| 996 | JniPackages android.Paths |
| 997 | } |
| 998 | |
| 999 | var JniPackageProvider = blueprint.NewProvider(JniPackageInfo{}) |
| 1000 | |
| 1001 | // Unzip an AAR and extract the JNI libs for $archString. |
| 1002 | var extractJNI = pctx.AndroidStaticRule("extractJNI", |
| 1003 | blueprint.RuleParams{ |
| 1004 | Command: `rm -rf $out $outDir && touch $out && ` + |
| 1005 | `unzip -qoDD -d $outDir $in "jni/${archString}/*" && ` + |
| 1006 | `jni_files=$$(find $outDir/jni -type f) && ` + |
| 1007 | // print error message if there are no JNI libs for this arch |
| 1008 | `[ -n "$$jni_files" ] || (echo "ERROR: no JNI libs found for arch ${archString}" && exit 1) && ` + |
| 1009 | `${config.SoongZipCmd} -o $out -P 'lib/${archString}' ` + |
| 1010 | `-C $outDir/jni/${archString} $$(echo $$jni_files | xargs -n1 printf " -f %s")`, |
| 1011 | CommandDeps: []string{"${config.SoongZipCmd}"}, |
| 1012 | }, |
| 1013 | "outDir", "archString") |
| 1014 | |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 1015 | // Unzip an AAR into its constituent files and directories. Any files in Outputs that don't exist in the AAR will be |
Dan Willemsen | 304cfec | 2019-05-28 14:49:06 -0700 | [diff] [blame] | 1016 | // touched to create an empty file. The res directory is not extracted, as it will be extracted in its own rule. |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 1017 | var unzipAAR = pctx.AndroidStaticRule("unzipAAR", |
| 1018 | blueprint.RuleParams{ |
Dan Willemsen | 304cfec | 2019-05-28 14:49:06 -0700 | [diff] [blame] | 1019 | Command: `rm -rf $outDir && mkdir -p $outDir && ` + |
Colin Cross | 205e911 | 2020-08-06 13:20:17 -0700 | [diff] [blame] | 1020 | `unzip -qoDD -d $outDir $in && rm -rf $outDir/res && touch $out && ` + |
Michael Rosenfeld | 5ad1557 | 2021-12-03 13:25:10 -0800 | [diff] [blame] | 1021 | `${config.Zip2ZipCmd} -i $in -o $assetsPackage 'assets/**/*' && ` + |
Colin Cross | 205e911 | 2020-08-06 13:20:17 -0700 | [diff] [blame] | 1022 | `${config.MergeZipsCmd} $combinedClassesJar $$(ls $outDir/classes.jar 2> /dev/null) $$(ls $outDir/libs/*.jar 2> /dev/null)`, |
Michael Rosenfeld | 5ad1557 | 2021-12-03 13:25:10 -0800 | [diff] [blame] | 1023 | CommandDeps: []string{"${config.MergeZipsCmd}", "${config.Zip2ZipCmd}"}, |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 1024 | }, |
Michael Rosenfeld | 5ad1557 | 2021-12-03 13:25:10 -0800 | [diff] [blame] | 1025 | "outDir", "combinedClassesJar", "assetsPackage") |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 1026 | |
| 1027 | func (a *AARImport) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 1028 | if len(a.properties.Aars) != 1 { |
| 1029 | ctx.PropertyErrorf("aars", "exactly one aar is required") |
| 1030 | return |
| 1031 | } |
| 1032 | |
Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 1033 | a.sdkVersion = a.SdkVersion(ctx) |
| 1034 | a.minSdkVersion = a.MinSdkVersion(ctx) |
| 1035 | |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 1036 | a.hideApexVariantFromMake = !ctx.Provider(android.ApexInfoProvider).(android.ApexInfo).IsForPlatform() |
| 1037 | |
Nan Zhang | 4c819fb | 2018-08-27 18:31:46 -0700 | [diff] [blame] | 1038 | aarName := ctx.ModuleName() + ".aar" |
Saeid Farivar Asanjan | f043696 | 2020-10-05 19:09:09 +0000 | [diff] [blame] | 1039 | a.aarPath = android.PathForModuleSrc(ctx, a.properties.Aars[0]) |
| 1040 | |
Colin Cross | 1001a79 | 2019-03-21 22:21:39 -0700 | [diff] [blame] | 1041 | if Bool(a.properties.Jetifier) { |
Saeid Farivar Asanjan | f043696 | 2020-10-05 19:09:09 +0000 | [diff] [blame] | 1042 | inputFile := a.aarPath |
| 1043 | a.aarPath = android.PathForModuleOut(ctx, "jetifier", aarName) |
| 1044 | TransformJetifier(ctx, a.aarPath.(android.WritablePath), inputFile) |
Nan Zhang | 4c819fb | 2018-08-27 18:31:46 -0700 | [diff] [blame] | 1045 | } |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 1046 | |
| 1047 | extractedAARDir := android.PathForModuleOut(ctx, "aar") |
Colin Cross | 205e911 | 2020-08-06 13:20:17 -0700 | [diff] [blame] | 1048 | a.classpathFile = extractedAARDir.Join(ctx, "classes-combined.jar") |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 1049 | a.proguardFlags = extractedAARDir.Join(ctx, "proguard.txt") |
Colin Cross | 10f7c4a | 2018-05-23 10:59:28 -0700 | [diff] [blame] | 1050 | a.manifest = extractedAARDir.Join(ctx, "AndroidManifest.xml") |
Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 1051 | aarRTxt := extractedAARDir.Join(ctx, "R.txt") |
Michael Rosenfeld | 5ad1557 | 2021-12-03 13:25:10 -0800 | [diff] [blame] | 1052 | a.assetsPackage = android.PathForModuleOut(ctx, "assets.zip") |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 1053 | |
| 1054 | ctx.Build(pctx, android.BuildParams{ |
| 1055 | Rule: unzipAAR, |
Saeid Farivar Asanjan | f043696 | 2020-10-05 19:09:09 +0000 | [diff] [blame] | 1056 | Input: a.aarPath, |
Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 1057 | Outputs: android.WritablePaths{a.classpathFile, a.proguardFlags, a.manifest, a.assetsPackage, aarRTxt}, |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 1058 | Description: "unzip AAR", |
| 1059 | Args: map[string]string{ |
Colin Cross | 205e911 | 2020-08-06 13:20:17 -0700 | [diff] [blame] | 1060 | "outDir": extractedAARDir.String(), |
| 1061 | "combinedClassesJar": a.classpathFile.String(), |
Michael Rosenfeld | 5ad1557 | 2021-12-03 13:25:10 -0800 | [diff] [blame] | 1062 | "assetsPackage": a.assetsPackage.String(), |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 1063 | }, |
| 1064 | }) |
| 1065 | |
Colin Cross | a0ba2f5 | 2019-06-22 12:59:27 -0700 | [diff] [blame] | 1066 | // Always set --pseudo-localize, it will be stripped out later for release |
| 1067 | // builds that don't want it. |
| 1068 | compileFlags := []string{"--pseudo-localize"} |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 1069 | compiledResDir := android.PathForModuleOut(ctx, "flat-res") |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 1070 | flata := compiledResDir.Join(ctx, "gen_res.flata") |
Saeid Farivar Asanjan | f043696 | 2020-10-05 19:09:09 +0000 | [diff] [blame] | 1071 | aapt2CompileZip(ctx, flata, a.aarPath, "res", compileFlags) |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 1072 | |
| 1073 | a.exportPackage = android.PathForModuleOut(ctx, "package-res.apk") |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 1074 | proguardOptionsFile := android.PathForModuleGen(ctx, "proguard.options") |
Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 1075 | a.rTxt = android.PathForModuleOut(ctx, "R.txt") |
Colin Cross | 66f7882 | 2018-05-02 12:58:28 -0700 | [diff] [blame] | 1076 | a.extraAaptPackagesFile = android.PathForModuleOut(ctx, "extra_packages") |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 1077 | |
| 1078 | var linkDeps android.Paths |
| 1079 | |
| 1080 | linkFlags := []string{ |
| 1081 | "--static-lib", |
Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 1082 | "--merge-only", |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 1083 | "--auto-add-overlay", |
| 1084 | } |
| 1085 | |
Colin Cross | 10f7c4a | 2018-05-23 10:59:28 -0700 | [diff] [blame] | 1086 | linkFlags = append(linkFlags, "--manifest "+a.manifest.String()) |
| 1087 | linkDeps = append(linkDeps, a.manifest) |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 1088 | |
Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 1089 | staticResourcesNodesDepSet, staticRRODirsDepSet, staticManifestsDepSet, sharedLibs, libFlags := |
Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 1090 | aaptLibs(ctx, android.SdkContext(a), nil) |
Colin Cross | 3165695 | 2018-05-24 16:11:20 -0700 | [diff] [blame] | 1091 | |
Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 1092 | _ = staticRRODirsDepSet |
| 1093 | staticDeps := transitiveAarDeps(staticResourcesNodesDepSet.ToList()) |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 1094 | |
Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 1095 | linkDeps = append(linkDeps, sharedLibs...) |
Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 1096 | linkDeps = append(linkDeps, staticDeps.resPackages()...) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 1097 | linkFlags = append(linkFlags, libFlags...) |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 1098 | |
Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 1099 | overlayRes := android.Paths{flata} |
| 1100 | |
| 1101 | // Treat static library dependencies of static libraries as imports. |
| 1102 | transitiveStaticLibs := staticDeps.resPackages() |
| 1103 | linkDeps = append(linkDeps, transitiveStaticLibs...) |
| 1104 | for _, staticLib := range transitiveStaticLibs { |
| 1105 | linkFlags = append(linkFlags, "-I "+staticLib.String()) |
| 1106 | } |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 1107 | |
Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 1108 | transitiveAssets := android.ReverseSliceInPlace(staticDeps.assets()) |
Colin Cross | f3b7bad | 2023-08-02 15:49:00 -0700 | [diff] [blame] | 1109 | aapt2Link(ctx, a.exportPackage, nil, proguardOptionsFile, a.rTxt, |
Jaewoong Jung | 6431ca7 | 2020-01-15 14:15:10 -0800 | [diff] [blame] | 1110 | linkFlags, linkDeps, nil, overlayRes, transitiveAssets, nil) |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 1111 | |
Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 1112 | a.rJar = android.PathForModuleOut(ctx, "busybox/R.jar") |
| 1113 | resourceProcessorBusyBoxGenerateBinaryR(ctx, a.rTxt, a.manifest, a.rJar, nil, true) |
| 1114 | |
Colin Cross | f3b7bad | 2023-08-02 15:49:00 -0700 | [diff] [blame] | 1115 | aapt2ExtractExtraPackages(ctx, a.extraAaptPackagesFile, a.rJar) |
| 1116 | |
Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 1117 | resourcesNodesDepSetBuilder := android.NewDepSetBuilder[*resourcesNode](android.TOPOLOGICAL) |
| 1118 | resourcesNodesDepSetBuilder.Direct(&resourcesNode{ |
| 1119 | resPackage: a.exportPackage, |
| 1120 | manifest: a.manifest, |
Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 1121 | rTxt: a.rTxt, |
| 1122 | rJar: a.rJar, |
Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 1123 | assets: android.OptionalPathForPath(a.assetsPackage), |
Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 1124 | |
| 1125 | usedResourceProcessor: true, |
Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 1126 | }) |
| 1127 | resourcesNodesDepSetBuilder.Transitive(staticResourcesNodesDepSet) |
| 1128 | a.resourcesNodesDepSet = resourcesNodesDepSetBuilder.Build() |
| 1129 | |
| 1130 | manifestDepSetBuilder := android.NewDepSetBuilder[android.Path](android.TOPOLOGICAL).Direct(a.manifest) |
| 1131 | // TODO(b/288358614): Soong has historically not merged manifests from dependencies of android_library_import |
| 1132 | // modules. Merging manifests from dependencies could remove the need for pom2bp to generate the "-nodeps" copies |
| 1133 | // of androidx libraries, but doing so triggers errors due to errors introduced by existing dependencies of |
| 1134 | // android_library_import modules. If this is fixed, AndroidLibraryDependency.ManifestsDepSet can be dropped |
| 1135 | // completely in favor of AndroidLibraryDependency.ResourceNodesDepSet.manifest |
| 1136 | //manifestDepSetBuilder.Transitive(transitiveStaticDeps.manifests) |
| 1137 | _ = staticManifestsDepSet |
| 1138 | a.manifestsDepSet = manifestDepSetBuilder.Build() |
Michael Rosenfeld | 5ad1557 | 2021-12-03 13:25:10 -0800 | [diff] [blame] | 1139 | |
Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 1140 | a.transitiveAaptResourcePackages = staticDeps.resPackages() |
| 1141 | |
Sam Delmerico | 9f9c0a2 | 2022-11-29 11:19:37 -0500 | [diff] [blame] | 1142 | a.collectTransitiveHeaderJars(ctx) |
Colin Cross | dcf71b2 | 2021-02-01 13:59:03 -0800 | [diff] [blame] | 1143 | ctx.SetProvider(JavaInfoProvider, JavaInfo{ |
| 1144 | HeaderJars: android.PathsIfNonNil(a.classpathFile), |
Sam Delmerico | 9f9c0a2 | 2022-11-29 11:19:37 -0500 | [diff] [blame] | 1145 | TransitiveLibsHeaderJars: a.transitiveLibsHeaderJars, |
| 1146 | TransitiveStaticLibsHeaderJars: a.transitiveStaticLibsHeaderJars, |
Colin Cross | dcf71b2 | 2021-02-01 13:59:03 -0800 | [diff] [blame] | 1147 | ImplementationAndResourcesJars: android.PathsIfNonNil(a.classpathFile), |
| 1148 | ImplementationJars: android.PathsIfNonNil(a.classpathFile), |
Joe Onorato | 6fe59eb | 2023-07-16 13:20:33 -0700 | [diff] [blame] | 1149 | // TransitiveAconfigFiles: // TODO(b/289117800): LOCAL_ACONFIG_FILES for prebuilts |
Colin Cross | dcf71b2 | 2021-02-01 13:59:03 -0800 | [diff] [blame] | 1150 | }) |
Sam Delmerico | 8260249 | 2022-06-10 17:05:42 +0000 | [diff] [blame] | 1151 | |
| 1152 | if proptools.Bool(a.properties.Extract_jni) { |
| 1153 | for _, t := range ctx.MultiTargets() { |
| 1154 | arch := t.Arch.Abi[0] |
| 1155 | path := android.PathForModuleOut(ctx, arch+"_jni.zip") |
| 1156 | a.jniPackages = append(a.jniPackages, path) |
| 1157 | |
| 1158 | outDir := android.PathForModuleOut(ctx, "aarForJni") |
| 1159 | aarPath := android.PathForModuleSrc(ctx, a.properties.Aars[0]) |
| 1160 | ctx.Build(pctx, android.BuildParams{ |
| 1161 | Rule: extractJNI, |
| 1162 | Input: aarPath, |
| 1163 | Outputs: android.WritablePaths{path}, |
| 1164 | Description: "extract JNI from AAR", |
| 1165 | Args: map[string]string{ |
| 1166 | "outDir": outDir.String(), |
| 1167 | "archString": arch, |
| 1168 | }, |
| 1169 | }) |
| 1170 | } |
| 1171 | |
| 1172 | ctx.SetProvider(JniPackageProvider, JniPackageInfo{ |
| 1173 | JniPackages: a.jniPackages, |
| 1174 | }) |
| 1175 | } |
Colin Cross | dcf71b2 | 2021-02-01 13:59:03 -0800 | [diff] [blame] | 1176 | } |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 1177 | |
| 1178 | func (a *AARImport) HeaderJars() android.Paths { |
| 1179 | return android.Paths{a.classpathFile} |
| 1180 | } |
| 1181 | |
Colin Cross | 331a121 | 2018-08-15 20:40:52 -0700 | [diff] [blame] | 1182 | func (a *AARImport) ImplementationAndResourcesJars() android.Paths { |
| 1183 | return android.Paths{a.classpathFile} |
| 1184 | } |
| 1185 | |
Ulyana Trafimovich | 5539e7b | 2020-06-04 14:08:17 +0000 | [diff] [blame] | 1186 | func (a *AARImport) DexJarBuildPath() android.Path { |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 1187 | return nil |
| 1188 | } |
| 1189 | |
Ulya Trafimovich | 9f3052c | 2020-06-09 14:31:19 +0100 | [diff] [blame] | 1190 | func (a *AARImport) DexJarInstallPath() android.Path { |
| 1191 | return nil |
| 1192 | } |
| 1193 | |
Ulya Trafimovich | b23d28c | 2020-10-08 12:53:58 +0100 | [diff] [blame] | 1194 | func (a *AARImport) ClassLoaderContexts() dexpreopt.ClassLoaderContextMap { |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 1195 | return nil |
| 1196 | } |
| 1197 | |
Jiyong Park | 45bf82e | 2020-12-15 22:29:02 +0900 | [diff] [blame] | 1198 | var _ android.ApexModule = (*AARImport)(nil) |
| 1199 | |
| 1200 | // Implements android.ApexModule |
Jooyung Han | acc7bbe | 2020-05-20 09:06:00 +0900 | [diff] [blame] | 1201 | func (a *AARImport) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool { |
| 1202 | return a.depIsInSameApex(ctx, dep) |
| 1203 | } |
| 1204 | |
Jiyong Park | 45bf82e | 2020-12-15 22:29:02 +0900 | [diff] [blame] | 1205 | // Implements android.ApexModule |
Dan Albert | c806053 | 2020-07-22 22:32:17 -0700 | [diff] [blame] | 1206 | func (g *AARImport) ShouldSupportSdkVersion(ctx android.BaseModuleContext, |
| 1207 | sdkVersion android.ApiLevel) error { |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1208 | return nil |
| 1209 | } |
| 1210 | |
Sam Delmerico | af8bb70 | 2022-07-25 15:39:32 -0400 | [diff] [blame] | 1211 | var _ android.PrebuiltInterface = (*AARImport)(nil) |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 1212 | |
Colin Cross | 1b16b0e | 2019-02-12 14:41:32 -0800 | [diff] [blame] | 1213 | // android_library_import imports an `.aar` file into the build graph as if it was built with android_library. |
| 1214 | // |
| 1215 | // This module is not suitable for installing on a device, but can be used as a `static_libs` dependency of |
| 1216 | // an android_app module. |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 1217 | func AARImportFactory() android.Module { |
| 1218 | module := &AARImport{} |
| 1219 | |
| 1220 | module.AddProperties(&module.properties) |
| 1221 | |
| 1222 | android.InitPrebuiltModule(module, &module.properties.Aars) |
Jooyung Han | acc7bbe | 2020-05-20 09:06:00 +0900 | [diff] [blame] | 1223 | android.InitApexModule(module) |
Sam Delmerico | 8260249 | 2022-06-10 17:05:42 +0000 | [diff] [blame] | 1224 | InitJavaModuleMultiTargets(module, android.DeviceSupported) |
Romain Jobredeaux | c9b2bba | 2022-02-15 09:35:07 -0500 | [diff] [blame] | 1225 | android.InitBazelModule(module) |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 1226 | return module |
| 1227 | } |
Romain Jobredeaux | c9b2bba | 2022-02-15 09:35:07 -0500 | [diff] [blame] | 1228 | |
| 1229 | type bazelAapt struct { |
| 1230 | Manifest bazel.Label |
| 1231 | Resource_files bazel.LabelListAttribute |
Romain Jobredeaux | 7a71e07 | 2023-08-16 17:39:12 -0400 | [diff] [blame^] | 1232 | Assets_dir bazel.StringAttribute |
| 1233 | Assets bazel.LabelListAttribute |
Romain Jobredeaux | c9b2bba | 2022-02-15 09:35:07 -0500 | [diff] [blame] | 1234 | } |
| 1235 | |
| 1236 | type bazelAndroidLibrary struct { |
| 1237 | *javaLibraryAttributes |
| 1238 | *bazelAapt |
| 1239 | } |
| 1240 | |
| 1241 | type bazelAndroidLibraryImport struct { |
Romain Jobredeaux | 2eef2e1 | 2023-02-24 12:07:08 -0500 | [diff] [blame] | 1242 | Aar bazel.Label |
| 1243 | Deps bazel.LabelListAttribute |
| 1244 | Exports bazel.LabelListAttribute |
| 1245 | Sdk_version bazel.StringAttribute |
Romain Jobredeaux | c9b2bba | 2022-02-15 09:35:07 -0500 | [diff] [blame] | 1246 | } |
| 1247 | |
Romain Jobredeaux | 7a71e07 | 2023-08-16 17:39:12 -0400 | [diff] [blame^] | 1248 | func (a *aapt) convertAaptAttrsWithBp2Build(ctx android.TopDownMutatorContext) (*bazelAapt, bool) { |
Romain Jobredeaux | c9b2bba | 2022-02-15 09:35:07 -0500 | [diff] [blame] | 1249 | manifest := proptools.StringDefault(a.aaptProperties.Manifest, "AndroidManifest.xml") |
| 1250 | |
| 1251 | resourceFiles := bazel.LabelList{ |
| 1252 | Includes: []bazel.Label{}, |
| 1253 | } |
| 1254 | for _, dir := range android.PathsWithOptionalDefaultForModuleSrc(ctx, a.aaptProperties.Resource_dirs, "res") { |
| 1255 | files := android.RootToModuleRelativePaths(ctx, androidResourceGlob(ctx, dir)) |
| 1256 | resourceFiles.Includes = append(resourceFiles.Includes, files...) |
| 1257 | } |
Romain Jobredeaux | 7a71e07 | 2023-08-16 17:39:12 -0400 | [diff] [blame^] | 1258 | |
| 1259 | assetsDir := bazel.StringAttribute{} |
| 1260 | var assets bazel.LabelList |
| 1261 | for i, dir := range android.PathsWithOptionalDefaultForModuleSrc(ctx, a.aaptProperties.Asset_dirs, "assets") { |
| 1262 | if i > 0 { |
| 1263 | ctx.MarkBp2buildUnconvertible(bp2build_metrics_proto.UnconvertedReasonType_PROPERTY_UNSUPPORTED, "multiple asset_dirs") |
| 1264 | return &bazelAapt{}, false |
| 1265 | } |
| 1266 | // Assets_dirs are relative to the module dir when specified, but if the default in used in |
| 1267 | // PathsWithOptionalDefaultForModuleSrc, then dir is relative to the top. |
| 1268 | assetsRelDir, error := filepath.Rel(ctx.ModuleDir(), dir.Rel()) |
| 1269 | if error != nil { |
| 1270 | assetsRelDir = dir.Rel() |
| 1271 | } |
| 1272 | assetsDir.Value = proptools.StringPtr(assetsRelDir) |
| 1273 | assets = bazel.MakeLabelList(android.RootToModuleRelativePaths(ctx, androidResourceGlob(ctx, dir))) |
| 1274 | |
| 1275 | } |
Romain Jobredeaux | c9b2bba | 2022-02-15 09:35:07 -0500 | [diff] [blame] | 1276 | return &bazelAapt{ |
| 1277 | android.BazelLabelForModuleSrcSingle(ctx, manifest), |
| 1278 | bazel.MakeLabelListAttribute(resourceFiles), |
Romain Jobredeaux | 7a71e07 | 2023-08-16 17:39:12 -0400 | [diff] [blame^] | 1279 | assetsDir, |
| 1280 | bazel.MakeLabelListAttribute(assets), |
| 1281 | }, true |
Romain Jobredeaux | c9b2bba | 2022-02-15 09:35:07 -0500 | [diff] [blame] | 1282 | } |
| 1283 | |
| 1284 | func (a *AARImport) ConvertWithBp2build(ctx android.TopDownMutatorContext) { |
| 1285 | aars := android.BazelLabelForModuleSrcExcludes(ctx, a.properties.Aars, []string{}) |
| 1286 | exportableStaticLibs := []string{} |
| 1287 | // TODO(b/240716882): investigate and handle static_libs deps that are not imports. They are not supported for export by Bazel. |
| 1288 | for _, depName := range a.properties.Static_libs { |
| 1289 | if dep, ok := ctx.ModuleFromName(depName); ok { |
| 1290 | switch dep.(type) { |
| 1291 | case *AARImport, *Import: |
| 1292 | exportableStaticLibs = append(exportableStaticLibs, depName) |
| 1293 | } |
| 1294 | } |
| 1295 | } |
| 1296 | name := android.RemoveOptionalPrebuiltPrefix(a.Name()) |
| 1297 | deps := android.BazelLabelForModuleDeps(ctx, android.LastUniqueStrings(android.CopyOf(append(a.properties.Static_libs, a.properties.Libs...)))) |
| 1298 | exports := android.BazelLabelForModuleDeps(ctx, android.LastUniqueStrings(exportableStaticLibs)) |
| 1299 | |
| 1300 | ctx.CreateBazelTargetModule( |
| 1301 | bazel.BazelTargetModuleProperties{ |
| 1302 | Rule_class: "aar_import", |
Alix | a381cd1 | 2023-05-10 14:49:38 +0000 | [diff] [blame] | 1303 | Bzl_load_location: "//build/bazel/rules/android:aar_import.bzl", |
Romain Jobredeaux | c9b2bba | 2022-02-15 09:35:07 -0500 | [diff] [blame] | 1304 | }, |
| 1305 | android.CommonAttributes{Name: name}, |
| 1306 | &bazelAndroidLibraryImport{ |
Romain Jobredeaux | 2eef2e1 | 2023-02-24 12:07:08 -0500 | [diff] [blame] | 1307 | Aar: aars.Includes[0], |
| 1308 | Deps: bazel.MakeLabelListAttribute(deps), |
| 1309 | Exports: bazel.MakeLabelListAttribute(exports), |
| 1310 | Sdk_version: bazel.StringAttribute{Value: a.properties.Sdk_version}, |
Romain Jobredeaux | c9b2bba | 2022-02-15 09:35:07 -0500 | [diff] [blame] | 1311 | }, |
| 1312 | ) |
| 1313 | |
Alix | 14101de | 2023-01-06 03:42:07 +0000 | [diff] [blame] | 1314 | neverlink := true |
| 1315 | ctx.CreateBazelTargetModule( |
Alix | 3254002 | 2023-03-16 21:06:13 +0000 | [diff] [blame] | 1316 | AndroidLibraryBazelTargetModuleProperties(), |
Alix | 14101de | 2023-01-06 03:42:07 +0000 | [diff] [blame] | 1317 | android.CommonAttributes{Name: name + "-neverlink"}, |
| 1318 | &bazelAndroidLibrary{ |
| 1319 | javaLibraryAttributes: &javaLibraryAttributes{ |
| 1320 | Neverlink: bazel.BoolAttribute{Value: &neverlink}, |
| 1321 | Exports: bazel.MakeSingleLabelListAttribute(bazel.Label{Label: ":" + name}), |
Romain Jobredeaux | 2eef2e1 | 2023-02-24 12:07:08 -0500 | [diff] [blame] | 1322 | javaCommonAttributes: &javaCommonAttributes{ |
| 1323 | Sdk_version: bazel.StringAttribute{Value: a.properties.Sdk_version}, |
| 1324 | }, |
Alix | 14101de | 2023-01-06 03:42:07 +0000 | [diff] [blame] | 1325 | }, |
| 1326 | }, |
| 1327 | ) |
| 1328 | |
Romain Jobredeaux | c9b2bba | 2022-02-15 09:35:07 -0500 | [diff] [blame] | 1329 | } |
Alix | 3254002 | 2023-03-16 21:06:13 +0000 | [diff] [blame] | 1330 | func AndroidLibraryBazelTargetModuleProperties() bazel.BazelTargetModuleProperties { |
| 1331 | return bazel.BazelTargetModuleProperties{ |
| 1332 | Rule_class: "android_library", |
Alix | a381cd1 | 2023-05-10 14:49:38 +0000 | [diff] [blame] | 1333 | Bzl_load_location: "//build/bazel/rules/android:android_library.bzl", |
Alix | 3254002 | 2023-03-16 21:06:13 +0000 | [diff] [blame] | 1334 | } |
| 1335 | } |
Romain Jobredeaux | c9b2bba | 2022-02-15 09:35:07 -0500 | [diff] [blame] | 1336 | |
| 1337 | func (a *AndroidLibrary) ConvertWithBp2build(ctx android.TopDownMutatorContext) { |
Liz Kammer | 7f37586 | 2023-08-04 16:37:42 -0400 | [diff] [blame] | 1338 | commonAttrs, bp2buildInfo, supported := a.convertLibraryAttrsBp2Build(ctx) |
| 1339 | if !supported { |
| 1340 | return |
| 1341 | } |
| 1342 | |
Alix | 8062f4d | 2022-11-14 21:38:07 +0000 | [diff] [blame] | 1343 | depLabels := bp2buildInfo.DepLabels |
Romain Jobredeaux | c9b2bba | 2022-02-15 09:35:07 -0500 | [diff] [blame] | 1344 | |
| 1345 | deps := depLabels.Deps |
| 1346 | if !commonAttrs.Srcs.IsEmpty() { |
| 1347 | deps.Append(depLabels.StaticDeps) // we should only append these if there are sources to use them |
| 1348 | } else if !depLabels.Deps.IsEmpty() { |
| 1349 | ctx.ModuleErrorf("Module has direct dependencies but no sources. Bazel will not allow this.") |
| 1350 | } |
Alix | 82fb94e | 2022-10-26 20:40:18 +0000 | [diff] [blame] | 1351 | name := a.Name() |
Alix | 3254002 | 2023-03-16 21:06:13 +0000 | [diff] [blame] | 1352 | props := AndroidLibraryBazelTargetModuleProperties() |
Alix | 82fb94e | 2022-10-26 20:40:18 +0000 | [diff] [blame] | 1353 | |
Romain Jobredeaux | 7a71e07 | 2023-08-16 17:39:12 -0400 | [diff] [blame^] | 1354 | aaptAttrs, supported := a.convertAaptAttrsWithBp2Build(ctx) |
| 1355 | if !supported { |
| 1356 | return |
| 1357 | } |
Romain Jobredeaux | c9b2bba | 2022-02-15 09:35:07 -0500 | [diff] [blame] | 1358 | ctx.CreateBazelTargetModule( |
Alix | 82fb94e | 2022-10-26 20:40:18 +0000 | [diff] [blame] | 1359 | props, |
| 1360 | android.CommonAttributes{Name: name}, |
Romain Jobredeaux | c9b2bba | 2022-02-15 09:35:07 -0500 | [diff] [blame] | 1361 | &bazelAndroidLibrary{ |
| 1362 | &javaLibraryAttributes{ |
| 1363 | javaCommonAttributes: commonAttrs, |
| 1364 | Deps: deps, |
| 1365 | Exports: depLabels.StaticDeps, |
| 1366 | }, |
Romain Jobredeaux | 7a71e07 | 2023-08-16 17:39:12 -0400 | [diff] [blame^] | 1367 | aaptAttrs, |
Romain Jobredeaux | c9b2bba | 2022-02-15 09:35:07 -0500 | [diff] [blame] | 1368 | }, |
| 1369 | ) |
Alix | 82fb94e | 2022-10-26 20:40:18 +0000 | [diff] [blame] | 1370 | |
| 1371 | neverlink := true |
| 1372 | ctx.CreateBazelTargetModule( |
| 1373 | props, |
| 1374 | android.CommonAttributes{Name: name + "-neverlink"}, |
| 1375 | &bazelAndroidLibrary{ |
| 1376 | javaLibraryAttributes: &javaLibraryAttributes{ |
| 1377 | Neverlink: bazel.BoolAttribute{Value: &neverlink}, |
| 1378 | Exports: bazel.MakeSingleLabelListAttribute(bazel.Label{Label: ":" + name}), |
Romain Jobredeaux | 2eef2e1 | 2023-02-24 12:07:08 -0500 | [diff] [blame] | 1379 | javaCommonAttributes: &javaCommonAttributes{ |
| 1380 | Sdk_version: bazel.StringAttribute{Value: a.deviceProperties.Sdk_version}, |
| 1381 | Java_version: bazel.StringAttribute{Value: a.properties.Java_version}, |
| 1382 | }, |
Alix | 82fb94e | 2022-10-26 20:40:18 +0000 | [diff] [blame] | 1383 | }, |
| 1384 | }, |
| 1385 | ) |
Romain Jobredeaux | c9b2bba | 2022-02-15 09:35:07 -0500 | [diff] [blame] | 1386 | } |