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" |
Jaewoong Jung | 9befb0c | 2020-01-18 10:33:43 -0800 | [diff] [blame] | 26 | |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 27 | "github.com/google/blueprint" |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 28 | "github.com/google/blueprint/proptools" |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 29 | ) |
| 30 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 31 | type AndroidLibraryDependency interface { |
Jared Duke | 5979b30 | 2022-12-19 21:08:39 +0000 | [diff] [blame] | 32 | LibraryDependency |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 33 | ExportPackage() android.Path |
Anton Hansson | 53c8844 | 2019-03-18 15:53:16 +0000 | [diff] [blame] | 34 | ExportedRRODirs() []rroDir |
Colin Cross | 66f7882 | 2018-05-02 12:58:28 -0700 | [diff] [blame] | 35 | ExportedStaticPackages() android.Paths |
Colin Cross | 90c25c6 | 2019-04-19 16:22:57 -0700 | [diff] [blame] | 36 | ExportedManifests() android.Paths |
Jaewoong Jung | 6431ca7 | 2020-01-15 14:15:10 -0800 | [diff] [blame] | 37 | ExportedAssets() android.OptionalPath |
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 | |
| 92 | // true if RRO is enforced for any of the dependent modules |
| 93 | RROEnforcedForDependent bool `blueprint:"mutated"` |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | type aapt struct { |
Colin Cross | 90c25c6 | 2019-04-19 16:22:57 -0700 | [diff] [blame] | 97 | aaptSrcJar android.Path |
| 98 | exportPackage android.Path |
| 99 | manifestPath android.Path |
| 100 | transitiveManifestPaths android.Paths |
| 101 | proguardOptionsFile android.Path |
| 102 | rroDirs []rroDir |
| 103 | rTxt android.Path |
| 104 | extraAaptPackagesFile android.Path |
| 105 | mergedManifestFile android.Path |
Jaewoong Jung | 5b425e2 | 2019-06-17 17:40:56 -0700 | [diff] [blame] | 106 | noticeFile android.OptionalPath |
Jaewoong Jung | 6431ca7 | 2020-01-15 14:15:10 -0800 | [diff] [blame] | 107 | assetPackage android.OptionalPath |
Colin Cross | 90c25c6 | 2019-04-19 16:22:57 -0700 | [diff] [blame] | 108 | isLibrary bool |
Alexei Nicoara | 69cf0f3 | 2022-07-27 14:59:18 +0100 | [diff] [blame] | 109 | defaultManifestVersion string |
Sasha Smundak | 6ad7725 | 2019-05-01 13:16:22 -0700 | [diff] [blame] | 110 | useEmbeddedNativeLibs bool |
Colin Cross | 90c25c6 | 2019-04-19 16:22:57 -0700 | [diff] [blame] | 111 | useEmbeddedDex bool |
| 112 | usesNonSdkApis bool |
Jaewoong Jung | c27ab66 | 2019-05-30 15:51:14 -0700 | [diff] [blame] | 113 | hasNoCode bool |
Baligh Uddin | 5b16dfb | 2020-02-11 17:27:19 -0800 | [diff] [blame] | 114 | LoggingParent string |
Colin Cross | 014489c | 2020-06-02 20:09:13 -0700 | [diff] [blame] | 115 | resourceFiles android.Paths |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 116 | |
Colin Cross | e560c4a | 2019-03-19 16:03:11 -0700 | [diff] [blame] | 117 | splitNames []string |
| 118 | splits []split |
| 119 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 120 | aaptProperties aaptProperties |
| 121 | } |
| 122 | |
Colin Cross | e560c4a | 2019-03-19 16:03:11 -0700 | [diff] [blame] | 123 | type split struct { |
| 124 | name string |
| 125 | suffix string |
| 126 | path android.Path |
| 127 | } |
| 128 | |
Jaewoong Jung | c779cd4 | 2020-10-06 18:56:10 -0700 | [diff] [blame] | 129 | // Propagate RRO enforcement flag to static lib dependencies transitively. |
| 130 | func propagateRROEnforcementMutator(ctx android.TopDownMutatorContext) { |
| 131 | m := ctx.Module() |
| 132 | if d, ok := m.(AndroidLibraryDependency); ok && d.IsRROEnforced(ctx) { |
| 133 | ctx.VisitDirectDepsWithTag(staticLibTag, func(d android.Module) { |
| 134 | if a, ok := d.(AndroidLibraryDependency); ok { |
| 135 | a.SetRROEnforcedForDependent(true) |
| 136 | } |
| 137 | }) |
| 138 | } |
| 139 | } |
| 140 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 141 | func (a *aapt) ExportPackage() android.Path { |
| 142 | return a.exportPackage |
| 143 | } |
| 144 | |
Anton Hansson | 53c8844 | 2019-03-18 15:53:16 +0000 | [diff] [blame] | 145 | func (a *aapt) ExportedRRODirs() []rroDir { |
Colin Cross | c1c3755 | 2019-01-31 11:42:41 -0800 | [diff] [blame] | 146 | return a.rroDirs |
| 147 | } |
| 148 | |
Colin Cross | 90c25c6 | 2019-04-19 16:22:57 -0700 | [diff] [blame] | 149 | func (a *aapt) ExportedManifests() android.Paths { |
| 150 | return a.transitiveManifestPaths |
Colin Cross | c1c3755 | 2019-01-31 11:42:41 -0800 | [diff] [blame] | 151 | } |
| 152 | |
Jaewoong Jung | 6431ca7 | 2020-01-15 14:15:10 -0800 | [diff] [blame] | 153 | func (a *aapt) ExportedAssets() android.OptionalPath { |
| 154 | return a.assetPackage |
| 155 | } |
| 156 | |
Jaewoong Jung | c779cd4 | 2020-10-06 18:56:10 -0700 | [diff] [blame] | 157 | func (a *aapt) SetRROEnforcedForDependent(enforce bool) { |
| 158 | a.aaptProperties.RROEnforcedForDependent = enforce |
| 159 | } |
| 160 | |
| 161 | func (a *aapt) IsRROEnforced(ctx android.BaseModuleContext) bool { |
| 162 | // True if RRO is enforced for this module or... |
| 163 | return ctx.Config().EnforceRROForModule(ctx.ModuleName()) || |
Jeongik Cha | cee5ba9 | 2021-02-19 12:11:51 +0900 | [diff] [blame] | 164 | // if RRO is enforced for any of its dependents. |
| 165 | a.aaptProperties.RROEnforcedForDependent |
Jaewoong Jung | c779cd4 | 2020-10-06 18:56:10 -0700 | [diff] [blame] | 166 | } |
| 167 | |
Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 168 | func (a *aapt) aapt2Flags(ctx android.ModuleContext, sdkContext android.SdkContext, |
Colin Cross | a0ba2f5 | 2019-06-22 12:59:27 -0700 | [diff] [blame] | 169 | manifestPath android.Path) (compileFlags, linkFlags []string, linkDeps android.Paths, |
| 170 | resDirs, overlayDirs []globbedResourceDir, rroDirs []rroDir, resZips android.Paths) { |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 171 | |
Jaewoong Jung | 3aff578 | 2020-02-11 07:54:35 -0800 | [diff] [blame] | 172 | hasVersionCode := android.PrefixInList(a.aaptProperties.Aaptflags, "--version-code") |
| 173 | hasVersionName := android.PrefixInList(a.aaptProperties.Aaptflags, "--version-name") |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 174 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 175 | // Flags specified in Android.bp |
| 176 | linkFlags = append(linkFlags, a.aaptProperties.Aaptflags...) |
| 177 | |
| 178 | linkFlags = append(linkFlags, "--no-static-lib-packages") |
| 179 | |
| 180 | // Find implicit or explicit asset and resource dirs |
| 181 | assetDirs := android.PathsWithOptionalDefaultForModuleSrc(ctx, a.aaptProperties.Asset_dirs, "assets") |
| 182 | resourceDirs := android.PathsWithOptionalDefaultForModuleSrc(ctx, a.aaptProperties.Resource_dirs, "res") |
Colin Cross | 8a49795 | 2019-03-05 22:25:09 -0800 | [diff] [blame] | 183 | resourceZips := android.PathsForModuleSrc(ctx, a.aaptProperties.Resource_zips) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 184 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 185 | // Glob directories into lists of paths |
| 186 | for _, dir := range resourceDirs { |
| 187 | resDirs = append(resDirs, globbedResourceDir{ |
| 188 | dir: dir, |
| 189 | files: androidResourceGlob(ctx, dir), |
| 190 | }) |
Jaewoong Jung | c779cd4 | 2020-10-06 18:56:10 -0700 | [diff] [blame] | 191 | resOverlayDirs, resRRODirs := overlayResourceGlob(ctx, a, dir) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 192 | overlayDirs = append(overlayDirs, resOverlayDirs...) |
| 193 | rroDirs = append(rroDirs, resRRODirs...) |
| 194 | } |
| 195 | |
Colin Cross | c20dc85 | 2020-11-10 12:27:45 -0800 | [diff] [blame] | 196 | var assetDeps android.Paths |
| 197 | for i, dir := range assetDirs { |
| 198 | // Add a dependency on every file in the asset directory. This ensures the aapt2 |
| 199 | // rule will be rerun if one of the files in the asset directory is modified. |
| 200 | assetDeps = append(assetDeps, androidResourceGlob(ctx, dir)...) |
| 201 | |
| 202 | // Add a dependency on a file that contains a list of all the files in the asset directory. |
| 203 | // This ensures the aapt2 rule will be run if a file is removed from the asset directory, |
| 204 | // or a file is added whose timestamp is older than the output of aapt2. |
| 205 | assetFileListFile := android.PathForModuleOut(ctx, "asset_dir_globs", strconv.Itoa(i)+".glob") |
| 206 | androidResourceGlobList(ctx, dir, assetFileListFile) |
| 207 | assetDeps = append(assetDeps, assetFileListFile) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 208 | } |
| 209 | |
Jaewoong Jung | 5b425e2 | 2019-06-17 17:40:56 -0700 | [diff] [blame] | 210 | assetDirStrings := assetDirs.Strings() |
| 211 | if a.noticeFile.Valid() { |
| 212 | assetDirStrings = append(assetDirStrings, filepath.Dir(a.noticeFile.Path().String())) |
Colin Cross | c20dc85 | 2020-11-10 12:27:45 -0800 | [diff] [blame] | 213 | assetDeps = append(assetDeps, a.noticeFile.Path()) |
Jaewoong Jung | 5b425e2 | 2019-06-17 17:40:56 -0700 | [diff] [blame] | 214 | } |
| 215 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 216 | linkFlags = append(linkFlags, "--manifest "+manifestPath.String()) |
| 217 | linkDeps = append(linkDeps, manifestPath) |
| 218 | |
Jaewoong Jung | 5b425e2 | 2019-06-17 17:40:56 -0700 | [diff] [blame] | 219 | linkFlags = append(linkFlags, android.JoinWithPrefix(assetDirStrings, "-A ")) |
Colin Cross | c20dc85 | 2020-11-10 12:27:45 -0800 | [diff] [blame] | 220 | linkDeps = append(linkDeps, assetDeps...) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 221 | |
Spandan Das | 50885c0 | 2023-02-23 21:31:33 +0000 | [diff] [blame^] | 222 | // Returns the effective version for {min|target}_sdk_version |
| 223 | effectiveVersionString := func(sdkVersion android.SdkSpec, minSdkVersion android.SdkSpec) string { |
| 224 | // If {min|target}_sdk_version is current, use sdk_version to determine the effective level |
| 225 | // This is necessary for vendor modules. |
| 226 | // The effective version does not _only_ depend on {min|target}_sdk_version(level), |
| 227 | // but also on the sdk_version (kind+level) |
| 228 | if minSdkVersion.ApiLevel.IsCurrent() { |
| 229 | ret, err := sdkVersion.EffectiveVersionString(ctx) |
| 230 | if err != nil { |
| 231 | ctx.ModuleErrorf("invalid sdk_version: %s", err) |
| 232 | } |
| 233 | return ret |
| 234 | } |
| 235 | ret, err := minSdkVersion.EffectiveVersionString(ctx) |
| 236 | if err != nil { |
| 237 | ctx.ModuleErrorf("invalid min_sdk_version: %s", err) |
| 238 | } |
| 239 | return ret |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 240 | } |
Spandan Das | 50885c0 | 2023-02-23 21:31:33 +0000 | [diff] [blame^] | 241 | // SDK version flags |
| 242 | sdkVersion := sdkContext.SdkVersion(ctx) |
| 243 | minSdkVersion := effectiveVersionString(sdkVersion, sdkContext.MinSdkVersion(ctx)) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 244 | |
Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 245 | linkFlags = append(linkFlags, "--min-sdk-version "+minSdkVersion) |
| 246 | linkFlags = append(linkFlags, "--target-sdk-version "+minSdkVersion) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 247 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 248 | // Version code |
| 249 | if !hasVersionCode { |
Dan Albert | 4f378d7 | 2020-07-23 17:32:15 -0700 | [diff] [blame] | 250 | linkFlags = append(linkFlags, "--version-code", ctx.Config().PlatformSdkVersion().String()) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | if !hasVersionName { |
Colin Cross | 402d5e0 | 2018-04-25 14:54:06 -0700 | [diff] [blame] | 254 | var versionName string |
| 255 | if ctx.ModuleName() == "framework-res" { |
| 256 | // Some builds set AppsDefaultVersionName() to include the build number ("O-123456"). aapt2 copies the |
| 257 | // 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] | 258 | // if it contains the build number. Use the PlatformVersionName instead. |
| 259 | versionName = ctx.Config().PlatformVersionName() |
Colin Cross | 402d5e0 | 2018-04-25 14:54:06 -0700 | [diff] [blame] | 260 | } else { |
| 261 | versionName = ctx.Config().AppsDefaultVersionName() |
| 262 | } |
Colin Cross | 0b9f31f | 2019-02-28 11:00:01 -0800 | [diff] [blame] | 263 | versionName = proptools.NinjaEscape(versionName) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 264 | linkFlags = append(linkFlags, "--version-name ", versionName) |
| 265 | } |
| 266 | |
Colin Cross | a0ba2f5 | 2019-06-22 12:59:27 -0700 | [diff] [blame] | 267 | linkFlags, compileFlags = android.FilterList(linkFlags, []string{"--legacy"}) |
| 268 | |
| 269 | // Always set --pseudo-localize, it will be stripped out later for release |
| 270 | // builds that don't want it. |
| 271 | compileFlags = append(compileFlags, "--pseudo-localize") |
| 272 | |
| 273 | return compileFlags, linkFlags, linkDeps, resDirs, overlayDirs, rroDirs, resourceZips |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 274 | } |
| 275 | |
Paul Duffin | 250e619 | 2019-06-07 10:44:37 +0100 | [diff] [blame] | 276 | func (a *aapt) deps(ctx android.BottomUpMutatorContext, sdkDep sdkDep) { |
Colin Cross | 42308aa | 2018-11-14 21:44:17 -0800 | [diff] [blame] | 277 | if sdkDep.frameworkResModule != "" { |
| 278 | ctx.AddVariationDependencies(nil, frameworkResTag, sdkDep.frameworkResModule) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 279 | } |
| 280 | } |
| 281 | |
Jaewoong Jung | 6431ca7 | 2020-01-15 14:15:10 -0800 | [diff] [blame] | 282 | var extractAssetsRule = pctx.AndroidStaticRule("extractAssets", |
| 283 | blueprint.RuleParams{ |
| 284 | Command: `${config.Zip2ZipCmd} -i ${in} -o ${out} "assets/**/*"`, |
| 285 | CommandDeps: []string{"${config.Zip2ZipCmd}"}, |
| 286 | }) |
| 287 | |
Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 288 | func (a *aapt) buildActions(ctx android.ModuleContext, sdkContext android.SdkContext, |
Paul Duffin | 0653057 | 2022-02-03 17:54:15 +0000 | [diff] [blame] | 289 | classLoaderContexts dexpreopt.ClassLoaderContextMap, excludedLibs []string, |
Harshit Mahajan | 5b8b730 | 2022-06-10 11:24:05 +0000 | [diff] [blame] | 290 | enforceDefaultTargetSdkVersion bool, extraLinkFlags ...string) { |
Colin Cross | 5446e88 | 2019-05-22 10:46:27 -0700 | [diff] [blame] | 291 | |
Ulya Trafimovich | 1855424 | 2020-11-03 15:55:11 +0000 | [diff] [blame] | 292 | transitiveStaticLibs, transitiveStaticLibManifests, staticRRODirs, assetPackages, libDeps, libFlags := |
Ulya Trafimovich | b23d28c | 2020-10-08 12:53:58 +0100 | [diff] [blame] | 293 | aaptLibs(ctx, sdkContext, classLoaderContexts) |
Ulya Trafimovich | 31e444e | 2020-08-14 17:32:16 +0100 | [diff] [blame] | 294 | |
Paul Duffin | 0653057 | 2022-02-03 17:54:15 +0000 | [diff] [blame] | 295 | // Exclude any libraries from the supplied list. |
| 296 | classLoaderContexts = classLoaderContexts.ExcludeLibs(excludedLibs) |
| 297 | |
Colin Cross | 3165695 | 2018-05-24 16:11:20 -0700 | [diff] [blame] | 298 | // App manifest file |
| 299 | manifestFile := proptools.StringDefault(a.aaptProperties.Manifest, "AndroidManifest.xml") |
| 300 | manifestSrcPath := android.PathForModuleSrc(ctx, manifestFile) |
| 301 | |
Gurpreet Singh | 7deabfa | 2022-02-10 13:28:35 +0000 | [diff] [blame] | 302 | manifestPath := ManifestFixer(ctx, manifestSrcPath, ManifestFixerParams{ |
Harshit Mahajan | 5b8b730 | 2022-06-10 11:24:05 +0000 | [diff] [blame] | 303 | SdkContext: sdkContext, |
| 304 | ClassLoaderContexts: classLoaderContexts, |
| 305 | IsLibrary: a.isLibrary, |
| 306 | DefaultManifestVersion: a.defaultManifestVersion, |
| 307 | UseEmbeddedNativeLibs: a.useEmbeddedNativeLibs, |
| 308 | UsesNonSdkApis: a.usesNonSdkApis, |
| 309 | UseEmbeddedDex: a.useEmbeddedDex, |
| 310 | HasNoCode: a.hasNoCode, |
| 311 | LoggingParent: a.LoggingParent, |
| 312 | EnforceDefaultTargetSdkVersion: enforceDefaultTargetSdkVersion, |
Gurpreet Singh | 75d65f3 | 2022-01-24 17:44:05 +0000 | [diff] [blame] | 313 | }) |
Colin Cross | 90c25c6 | 2019-04-19 16:22:57 -0700 | [diff] [blame] | 314 | |
Luca Stefani | fd89882 | 2019-09-10 22:13:31 +0200 | [diff] [blame] | 315 | // Add additional manifest files to transitive manifests. |
| 316 | additionalManifests := android.PathsForModuleSrc(ctx, a.aaptProperties.Additional_manifests) |
| 317 | a.transitiveManifestPaths = append(android.Paths{manifestPath}, additionalManifests...) |
| 318 | a.transitiveManifestPaths = append(a.transitiveManifestPaths, transitiveStaticLibManifests...) |
Colin Cross | 90c25c6 | 2019-04-19 16:22:57 -0700 | [diff] [blame] | 319 | |
Sasha Smundak | 541056c | 2019-10-28 15:50:06 -0700 | [diff] [blame] | 320 | if len(a.transitiveManifestPaths) > 1 && !Bool(a.aaptProperties.Dont_merge_manifests) { |
Luca Stefani | fd89882 | 2019-09-10 22:13:31 +0200 | [diff] [blame] | 321 | a.mergedManifestFile = manifestMerger(ctx, a.transitiveManifestPaths[0], a.transitiveManifestPaths[1:], a.isLibrary) |
Colin Cross | 90c25c6 | 2019-04-19 16:22:57 -0700 | [diff] [blame] | 322 | if !a.isLibrary { |
| 323 | // Only use the merged manifest for applications. For libraries, the transitive closure of manifests |
| 324 | // will be propagated to the final application and merged there. The merged manifest for libraries is |
| 325 | // only passed to Make, which can't handle transitive dependencies. |
| 326 | manifestPath = a.mergedManifestFile |
| 327 | } |
| 328 | } else { |
| 329 | a.mergedManifestFile = manifestPath |
| 330 | } |
Colin Cross | 3165695 | 2018-05-24 16:11:20 -0700 | [diff] [blame] | 331 | |
Colin Cross | a0ba2f5 | 2019-06-22 12:59:27 -0700 | [diff] [blame] | 332 | compileFlags, linkFlags, linkDeps, resDirs, overlayDirs, rroDirs, resZips := a.aapt2Flags(ctx, sdkContext, manifestPath) |
Colin Cross | 3165695 | 2018-05-24 16:11:20 -0700 | [diff] [blame] | 333 | |
Colin Cross | c1c3755 | 2019-01-31 11:42:41 -0800 | [diff] [blame] | 334 | rroDirs = append(rroDirs, staticRRODirs...) |
Colin Cross | 3165695 | 2018-05-24 16:11:20 -0700 | [diff] [blame] | 335 | linkFlags = append(linkFlags, libFlags...) |
| 336 | linkDeps = append(linkDeps, libDeps...) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 337 | linkFlags = append(linkFlags, extraLinkFlags...) |
Colin Cross | 1b6a3cf | 2018-07-24 14:51:30 -0700 | [diff] [blame] | 338 | if a.isLibrary { |
| 339 | linkFlags = append(linkFlags, "--static-lib") |
| 340 | } |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 341 | |
| 342 | packageRes := android.PathForModuleOut(ctx, "package-res.apk") |
Jiyong Park | b7c639e | 2019-08-19 14:56:02 +0900 | [diff] [blame] | 343 | // the subdir "android" is required to be filtered by package names |
| 344 | srcJar := android.PathForModuleGen(ctx, "android", "R.srcjar") |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 345 | proguardOptionsFile := android.PathForModuleGen(ctx, "proguard.options") |
| 346 | rTxt := android.PathForModuleOut(ctx, "R.txt") |
Colin Cross | 66f7882 | 2018-05-02 12:58:28 -0700 | [diff] [blame] | 347 | // This file isn't used by Soong, but is generated for exporting |
| 348 | extraPackages := android.PathForModuleOut(ctx, "extra_packages") |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 349 | |
Colin Cross | 4aaa84a | 2018-08-21 15:14:37 -0700 | [diff] [blame] | 350 | var compiledResDirs []android.Paths |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 351 | for _, dir := range resDirs { |
Colin Cross | 014489c | 2020-06-02 20:09:13 -0700 | [diff] [blame] | 352 | a.resourceFiles = append(a.resourceFiles, dir.files...) |
Colin Cross | a0ba2f5 | 2019-06-22 12:59:27 -0700 | [diff] [blame] | 353 | compiledResDirs = append(compiledResDirs, aapt2Compile(ctx, dir.dir, dir.files, compileFlags).Paths()) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 354 | } |
Colin Cross | 4aaa84a | 2018-08-21 15:14:37 -0700 | [diff] [blame] | 355 | |
Colin Cross | a592e3e | 2019-02-19 16:59:53 -0800 | [diff] [blame] | 356 | for i, zip := range resZips { |
| 357 | flata := android.PathForModuleOut(ctx, fmt.Sprintf("reszip.%d.flata", i)) |
Colin Cross | a0ba2f5 | 2019-06-22 12:59:27 -0700 | [diff] [blame] | 358 | aapt2CompileZip(ctx, flata, zip, "", compileFlags) |
Colin Cross | a592e3e | 2019-02-19 16:59:53 -0800 | [diff] [blame] | 359 | compiledResDirs = append(compiledResDirs, android.Paths{flata}) |
| 360 | } |
| 361 | |
Colin Cross | 4aaa84a | 2018-08-21 15:14:37 -0700 | [diff] [blame] | 362 | var compiledRes, compiledOverlay android.Paths |
| 363 | |
| 364 | compiledOverlay = append(compiledOverlay, transitiveStaticLibs...) |
| 365 | |
Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 366 | if len(transitiveStaticLibs) > 0 { |
Colin Cross | 4aaa84a | 2018-08-21 15:14:37 -0700 | [diff] [blame] | 367 | // If we are using static android libraries, every source file becomes an overlay. |
| 368 | // This is to emulate old AAPT behavior which simulated library support. |
| 369 | for _, compiledResDir := range compiledResDirs { |
| 370 | compiledOverlay = append(compiledOverlay, compiledResDir...) |
| 371 | } |
Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 372 | } else if a.isLibrary { |
| 373 | // Otherwise, for a static library we treat all the resources equally with no overlay. |
| 374 | for _, compiledResDir := range compiledResDirs { |
| 375 | compiledRes = append(compiledRes, compiledResDir...) |
| 376 | } |
Colin Cross | 4aaa84a | 2018-08-21 15:14:37 -0700 | [diff] [blame] | 377 | } else if len(compiledResDirs) > 0 { |
| 378 | // Without static libraries, the first directory is our directory, which can then be |
| 379 | // overlaid by the rest. |
| 380 | compiledRes = append(compiledRes, compiledResDirs[0]...) |
| 381 | for _, compiledResDir := range compiledResDirs[1:] { |
| 382 | compiledOverlay = append(compiledOverlay, compiledResDir...) |
| 383 | } |
| 384 | } |
| 385 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 386 | for _, dir := range overlayDirs { |
Colin Cross | a0ba2f5 | 2019-06-22 12:59:27 -0700 | [diff] [blame] | 387 | compiledOverlay = append(compiledOverlay, aapt2Compile(ctx, dir.dir, dir.files, compileFlags).Paths()...) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 388 | } |
| 389 | |
Colin Cross | e560c4a | 2019-03-19 16:03:11 -0700 | [diff] [blame] | 390 | var splitPackages android.WritablePaths |
| 391 | var splits []split |
| 392 | |
| 393 | for _, s := range a.splitNames { |
| 394 | suffix := strings.Replace(s, ",", "_", -1) |
| 395 | path := android.PathForModuleOut(ctx, "package_"+suffix+".apk") |
| 396 | linkFlags = append(linkFlags, "--split", path.String()+":"+s) |
| 397 | splitPackages = append(splitPackages, path) |
| 398 | splits = append(splits, split{ |
| 399 | name: s, |
| 400 | suffix: suffix, |
| 401 | path: path, |
| 402 | }) |
| 403 | } |
| 404 | |
Colin Cross | 66f7882 | 2018-05-02 12:58:28 -0700 | [diff] [blame] | 405 | aapt2Link(ctx, packageRes, srcJar, proguardOptionsFile, rTxt, extraPackages, |
Jaewoong Jung | 6431ca7 | 2020-01-15 14:15:10 -0800 | [diff] [blame] | 406 | linkFlags, linkDeps, compiledRes, compiledOverlay, assetPackages, splitPackages) |
| 407 | |
| 408 | // Extract assets from the resource package output so that they can be used later in aapt2link |
| 409 | // for modules that depend on this one. |
Jaewoong Jung | 3aff578 | 2020-02-11 07:54:35 -0800 | [diff] [blame] | 410 | if android.PrefixInList(linkFlags, "-A ") || len(assetPackages) > 0 { |
Jaewoong Jung | 6431ca7 | 2020-01-15 14:15:10 -0800 | [diff] [blame] | 411 | assets := android.PathForModuleOut(ctx, "assets.zip") |
| 412 | ctx.Build(pctx, android.BuildParams{ |
| 413 | Rule: extractAssetsRule, |
| 414 | Input: packageRes, |
| 415 | Output: assets, |
| 416 | Description: "extract assets from built resource file", |
| 417 | }) |
| 418 | a.assetPackage = android.OptionalPathForPath(assets) |
| 419 | } |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 420 | |
| 421 | a.aaptSrcJar = srcJar |
| 422 | a.exportPackage = packageRes |
| 423 | a.manifestPath = manifestPath |
| 424 | a.proguardOptionsFile = proguardOptionsFile |
| 425 | a.rroDirs = rroDirs |
Colin Cross | 66f7882 | 2018-05-02 12:58:28 -0700 | [diff] [blame] | 426 | a.extraAaptPackagesFile = extraPackages |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 427 | a.rTxt = rTxt |
Colin Cross | e560c4a | 2019-03-19 16:03:11 -0700 | [diff] [blame] | 428 | a.splits = splits |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 429 | } |
| 430 | |
| 431 | // 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] | 432 | func aaptLibs(ctx android.ModuleContext, sdkContext android.SdkContext, classLoaderContexts dexpreopt.ClassLoaderContextMap) ( |
Ulya Trafimovich | 1855424 | 2020-11-03 15:55:11 +0000 | [diff] [blame] | 433 | transitiveStaticLibs, transitiveStaticLibManifests android.Paths, staticRRODirs []rroDir, assets, deps android.Paths, flags []string) { |
Colin Cross | 66f7882 | 2018-05-02 12:58:28 -0700 | [diff] [blame] | 434 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 435 | var sharedLibs android.Paths |
| 436 | |
Ulya Trafimovich | b23d28c | 2020-10-08 12:53:58 +0100 | [diff] [blame] | 437 | if classLoaderContexts == nil { |
Ulya Trafimovich | 1855424 | 2020-11-03 15:55:11 +0000 | [diff] [blame] | 438 | // Not all callers need to compute class loader context, those who don't just pass nil. |
| 439 | // 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] | 440 | classLoaderContexts = make(dexpreopt.ClassLoaderContextMap) |
Ulya Trafimovich | 1855424 | 2020-11-03 15:55:11 +0000 | [diff] [blame] | 441 | } |
| 442 | |
Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 443 | sdkDep := decodeSdkDep(ctx, sdkContext) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 444 | if sdkDep.useFiles { |
Colin Cross | 86a60ae | 2018-05-29 14:44:55 -0700 | [diff] [blame] | 445 | sharedLibs = append(sharedLibs, sdkDep.jars...) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 446 | } |
| 447 | |
| 448 | ctx.VisitDirectDeps(func(module android.Module) { |
Ulya Trafimovich | 65b0319 | 2020-12-03 16:50:22 +0000 | [diff] [blame] | 449 | depTag := ctx.OtherModuleDependencyTag(module) |
Ulya Trafimovich | 1855424 | 2020-11-03 15:55:11 +0000 | [diff] [blame] | 450 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 451 | var exportPackage android.Path |
Colin Cross | 66f7882 | 2018-05-02 12:58:28 -0700 | [diff] [blame] | 452 | aarDep, _ := module.(AndroidLibraryDependency) |
| 453 | if aarDep != nil { |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 454 | exportPackage = aarDep.ExportPackage() |
| 455 | } |
| 456 | |
Ulya Trafimovich | 65b0319 | 2020-12-03 16:50:22 +0000 | [diff] [blame] | 457 | switch depTag { |
Colin Cross | 4b964c0 | 2018-10-15 16:18:06 -0700 | [diff] [blame] | 458 | case instrumentationForTag: |
| 459 | // Nothing, instrumentationForTag is treated as libTag for javac but not for aapt2. |
Liz Kammer | ef28a4c | 2022-09-23 16:50:56 -0400 | [diff] [blame] | 460 | case sdkLibTag, libTag: |
Colin Cross | 5446e88 | 2019-05-22 10:46:27 -0700 | [diff] [blame] | 461 | if exportPackage != nil { |
| 462 | sharedLibs = append(sharedLibs, exportPackage) |
| 463 | } |
Colin Cross | 5446e88 | 2019-05-22 10:46:27 -0700 | [diff] [blame] | 464 | case frameworkResTag: |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 465 | if exportPackage != nil { |
| 466 | sharedLibs = append(sharedLibs, exportPackage) |
| 467 | } |
| 468 | case staticLibTag: |
| 469 | if exportPackage != nil { |
Colin Cross | 66f7882 | 2018-05-02 12:58:28 -0700 | [diff] [blame] | 470 | transitiveStaticLibs = append(transitiveStaticLibs, aarDep.ExportedStaticPackages()...) |
Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 471 | transitiveStaticLibs = append(transitiveStaticLibs, exportPackage) |
Colin Cross | 90c25c6 | 2019-04-19 16:22:57 -0700 | [diff] [blame] | 472 | transitiveStaticLibManifests = append(transitiveStaticLibManifests, aarDep.ExportedManifests()...) |
Jaewoong Jung | 6431ca7 | 2020-01-15 14:15:10 -0800 | [diff] [blame] | 473 | if aarDep.ExportedAssets().Valid() { |
| 474 | assets = append(assets, aarDep.ExportedAssets().Path()) |
| 475 | } |
Anton Hansson | 53c8844 | 2019-03-18 15:53:16 +0000 | [diff] [blame] | 476 | |
Jeongik Cha | cee5ba9 | 2021-02-19 12:11:51 +0900 | [diff] [blame] | 477 | outer: |
| 478 | for _, d := range aarDep.ExportedRRODirs() { |
| 479 | for _, e := range staticRRODirs { |
| 480 | if d.path == e.path { |
| 481 | continue outer |
Anton Hansson | 53c8844 | 2019-03-18 15:53:16 +0000 | [diff] [blame] | 482 | } |
| 483 | } |
Jeongik Cha | cee5ba9 | 2021-02-19 12:11:51 +0900 | [diff] [blame] | 484 | staticRRODirs = append(staticRRODirs, d) |
Anton Hansson | 53c8844 | 2019-03-18 15:53:16 +0000 | [diff] [blame] | 485 | } |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 486 | } |
| 487 | } |
Ulya Trafimovich | 1855424 | 2020-11-03 15:55:11 +0000 | [diff] [blame] | 488 | |
Ulya Trafimovich | 88bb6f6 | 2020-12-16 16:16:11 +0000 | [diff] [blame] | 489 | addCLCFromDep(ctx, module, classLoaderContexts) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 490 | }) |
| 491 | |
| 492 | deps = append(deps, sharedLibs...) |
Colin Cross | 66f7882 | 2018-05-02 12:58:28 -0700 | [diff] [blame] | 493 | deps = append(deps, transitiveStaticLibs...) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 494 | |
Colin Cross | 66f7882 | 2018-05-02 12:58:28 -0700 | [diff] [blame] | 495 | if len(transitiveStaticLibs) > 0 { |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 496 | flags = append(flags, "--auto-add-overlay") |
| 497 | } |
| 498 | |
| 499 | for _, sharedLib := range sharedLibs { |
| 500 | flags = append(flags, "-I "+sharedLib.String()) |
| 501 | } |
| 502 | |
Colin Cross | 66f7882 | 2018-05-02 12:58:28 -0700 | [diff] [blame] | 503 | transitiveStaticLibs = android.FirstUniquePaths(transitiveStaticLibs) |
Colin Cross | 90c25c6 | 2019-04-19 16:22:57 -0700 | [diff] [blame] | 504 | transitiveStaticLibManifests = android.FirstUniquePaths(transitiveStaticLibManifests) |
Colin Cross | 66f7882 | 2018-05-02 12:58:28 -0700 | [diff] [blame] | 505 | |
Ulya Trafimovich | 1855424 | 2020-11-03 15:55:11 +0000 | [diff] [blame] | 506 | return transitiveStaticLibs, transitiveStaticLibManifests, staticRRODirs, assets, deps, flags |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 507 | } |
| 508 | |
| 509 | type AndroidLibrary struct { |
| 510 | Library |
| 511 | aapt |
Romain Jobredeaux | c9b2bba | 2022-02-15 09:35:07 -0500 | [diff] [blame] | 512 | android.BazelModuleBase |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 513 | |
| 514 | androidLibraryProperties androidLibraryProperties |
| 515 | |
| 516 | aarFile android.WritablePath |
Colin Cross | 89c3158 | 2018-04-30 15:55:11 -0700 | [diff] [blame] | 517 | |
Jared Duke | 5979b30 | 2022-12-19 21:08:39 +0000 | [diff] [blame] | 518 | exportedStaticPackages android.Paths |
Colin Cross | 89c3158 | 2018-04-30 15:55:11 -0700 | [diff] [blame] | 519 | } |
| 520 | |
Saeid Farivar Asanjan | 1fca301 | 2021-09-14 18:40:19 +0000 | [diff] [blame] | 521 | var _ android.OutputFileProducer = (*AndroidLibrary)(nil) |
| 522 | |
| 523 | // For OutputFileProducer interface |
| 524 | func (a *AndroidLibrary) OutputFiles(tag string) (android.Paths, error) { |
| 525 | switch tag { |
| 526 | case ".aar": |
| 527 | return []android.Path{a.aarFile}, nil |
| 528 | default: |
| 529 | return a.Library.OutputFiles(tag) |
| 530 | } |
| 531 | } |
| 532 | |
Colin Cross | 66f7882 | 2018-05-02 12:58:28 -0700 | [diff] [blame] | 533 | func (a *AndroidLibrary) ExportedStaticPackages() android.Paths { |
| 534 | return a.exportedStaticPackages |
| 535 | } |
| 536 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 537 | var _ AndroidLibraryDependency = (*AndroidLibrary)(nil) |
| 538 | |
| 539 | func (a *AndroidLibrary) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 540 | a.Module.deps(ctx) |
Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 541 | sdkDep := decodeSdkDep(ctx, android.SdkContext(a)) |
Paul Duffin | 250e619 | 2019-06-07 10:44:37 +0100 | [diff] [blame] | 542 | if sdkDep.hasFrameworkLibs() { |
| 543 | a.aapt.deps(ctx, sdkDep) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 544 | } |
Colin Cross | 4a80a15 | 2022-12-21 21:51:52 -0800 | [diff] [blame] | 545 | a.usesLibrary.deps(ctx, false) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 546 | } |
| 547 | |
| 548 | func (a *AndroidLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Colin Cross | e4246ab | 2019-02-05 21:55:21 -0800 | [diff] [blame] | 549 | a.aapt.isLibrary = true |
Ulya Trafimovich | 42c7f0d | 2021-08-17 16:20:29 +0100 | [diff] [blame] | 550 | a.classLoaderContexts = a.usesLibrary.classLoaderContextForUsesLibDeps(ctx) |
Harshit Mahajan | 5b8b730 | 2022-06-10 11:24:05 +0000 | [diff] [blame] | 551 | a.aapt.buildActions(ctx, android.SdkContext(a), a.classLoaderContexts, nil, false) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 552 | |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 553 | a.hideApexVariantFromMake = !ctx.Provider(android.ApexInfoProvider).(android.ApexInfo).IsForPlatform() |
| 554 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 555 | ctx.CheckbuildFile(a.proguardOptionsFile) |
| 556 | ctx.CheckbuildFile(a.exportPackage) |
| 557 | ctx.CheckbuildFile(a.aaptSrcJar) |
| 558 | |
| 559 | // apps manifests are handled by aapt, don't let Module see them |
| 560 | a.properties.Manifest = nil |
| 561 | |
Colin Cross | 014489c | 2020-06-02 20:09:13 -0700 | [diff] [blame] | 562 | a.linter.mergedManifest = a.aapt.mergedManifestFile |
| 563 | a.linter.manifest = a.aapt.manifestPath |
| 564 | a.linter.resources = a.aapt.resourceFiles |
| 565 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 566 | a.Module.extraProguardFlagFiles = append(a.Module.extraProguardFlagFiles, |
| 567 | a.proguardOptionsFile) |
| 568 | |
| 569 | a.Module.compile(ctx, a.aaptSrcJar) |
| 570 | |
Colin Cross | f57c578 | 2019-01-25 13:20:38 -0800 | [diff] [blame] | 571 | a.aarFile = android.PathForModuleOut(ctx, ctx.ModuleName()+".aar") |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 572 | var res android.Paths |
| 573 | if a.androidLibraryProperties.BuildAAR { |
| 574 | BuildAAR(ctx, a.aarFile, a.outputFile, a.manifestPath, a.rTxt, res) |
| 575 | ctx.CheckbuildFile(a.aarFile) |
| 576 | } |
Colin Cross | 89c3158 | 2018-04-30 15:55:11 -0700 | [diff] [blame] | 577 | |
Cole Faust | 9a63131 | 2020-10-22 21:05:24 +0000 | [diff] [blame] | 578 | a.exportedProguardFlagFiles = append(a.exportedProguardFlagFiles, |
| 579 | android.PathsForModuleSrc(ctx, a.dexProperties.Optimize.Proguard_flags_files)...) |
Colin Cross | 89c3158 | 2018-04-30 15:55:11 -0700 | [diff] [blame] | 580 | ctx.VisitDirectDeps(func(m android.Module) { |
Jared Duke | 5979b30 | 2022-12-19 21:08:39 +0000 | [diff] [blame] | 581 | if ctx.OtherModuleDependencyTag(m) == staticLibTag { |
| 582 | if lib, ok := m.(LibraryDependency); ok { |
| 583 | a.exportedProguardFlagFiles = append(a.exportedProguardFlagFiles, lib.ExportedProguardFlagFiles()...) |
| 584 | } |
| 585 | if alib, ok := m.(AndroidLibraryDependency); ok { |
| 586 | a.exportedStaticPackages = append(a.exportedStaticPackages, alib.ExportPackage()) |
| 587 | a.exportedStaticPackages = append(a.exportedStaticPackages, alib.ExportedStaticPackages()...) |
| 588 | } |
Colin Cross | 89c3158 | 2018-04-30 15:55:11 -0700 | [diff] [blame] | 589 | } |
| 590 | }) |
Colin Cross | 89c3158 | 2018-04-30 15:55:11 -0700 | [diff] [blame] | 591 | a.exportedProguardFlagFiles = android.FirstUniquePaths(a.exportedProguardFlagFiles) |
Colin Cross | 66f7882 | 2018-05-02 12:58:28 -0700 | [diff] [blame] | 592 | a.exportedStaticPackages = android.FirstUniquePaths(a.exportedStaticPackages) |
Sam Delmerico | 8260249 | 2022-06-10 17:05:42 +0000 | [diff] [blame] | 593 | |
| 594 | prebuiltJniPackages := android.Paths{} |
| 595 | ctx.VisitDirectDeps(func(module android.Module) { |
| 596 | if info, ok := ctx.OtherModuleProvider(module, JniPackageProvider).(JniPackageInfo); ok { |
| 597 | prebuiltJniPackages = append(prebuiltJniPackages, info.JniPackages...) |
| 598 | } |
| 599 | }) |
| 600 | if len(prebuiltJniPackages) > 0 { |
| 601 | ctx.SetProvider(JniPackageProvider, JniPackageInfo{ |
| 602 | JniPackages: prebuiltJniPackages, |
| 603 | }) |
| 604 | } |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 605 | } |
| 606 | |
Colin Cross | 1b16b0e | 2019-02-12 14:41:32 -0800 | [diff] [blame] | 607 | // android_library builds and links sources into a `.jar` file for the device along with Android resources. |
| 608 | // |
| 609 | // 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] | 610 | // 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] | 611 | // with aapt2. This module is not suitable for installing on a device, but can be used as a `static_libs` dependency of |
| 612 | // an android_app module. |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 613 | func AndroidLibraryFactory() android.Module { |
| 614 | module := &AndroidLibrary{} |
| 615 | |
Colin Cross | ce6734e | 2020-06-15 16:09:53 -0700 | [diff] [blame] | 616 | module.Module.addHostAndDeviceProperties() |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 617 | module.AddProperties( |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 618 | &module.aaptProperties, |
| 619 | &module.androidLibraryProperties) |
| 620 | |
| 621 | module.androidLibraryProperties.BuildAAR = true |
Colin Cross | 014489c | 2020-06-02 20:09:13 -0700 | [diff] [blame] | 622 | module.Module.linter.library = true |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 623 | |
Jooyung Han | acc7bbe | 2020-05-20 09:06:00 +0900 | [diff] [blame] | 624 | android.InitApexModule(module) |
Colin Cross | 48de9a4 | 2018-10-02 13:53:33 -0700 | [diff] [blame] | 625 | InitJavaModule(module, android.DeviceSupported) |
Romain Jobredeaux | c9b2bba | 2022-02-15 09:35:07 -0500 | [diff] [blame] | 626 | android.InitBazelModule(module) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 627 | return module |
| 628 | } |
| 629 | |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 630 | // |
| 631 | // AAR (android library) prebuilts |
| 632 | // |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 633 | |
Vinh Tran | ce0781f | 2022-04-13 01:30:44 +0000 | [diff] [blame] | 634 | // Properties for android_library_import |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 635 | type AARImportProperties struct { |
Vinh Tran | ce0781f | 2022-04-13 01:30:44 +0000 | [diff] [blame] | 636 | // ARR (android library prebuilt) filepath. Exactly one ARR is required. |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 637 | Aars []string `android:"path"` |
Vinh Tran | ce0781f | 2022-04-13 01:30:44 +0000 | [diff] [blame] | 638 | // If not blank, set to the version of the sdk to compile against. |
| 639 | // Defaults to private. |
| 640 | // Values are of one of the following forms: |
| 641 | // 1) numerical API level, "current", "none", or "core_platform" |
| 642 | // 2) An SDK kind with an API level: "<sdk kind>_<API level>" |
| 643 | // See build/soong/android/sdk_version.go for the complete and up to date list of SDK kinds. |
| 644 | // If the SDK kind is empty, it will be set to public |
| 645 | Sdk_version *string |
| 646 | // If not blank, set the minimum version of the sdk that the compiled artifacts will run against. |
| 647 | // 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] | 648 | Min_sdk_version *string |
Vinh Tran | ce0781f | 2022-04-13 01:30:44 +0000 | [diff] [blame] | 649 | // 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] | 650 | Static_libs []string |
Vinh Tran | ce0781f | 2022-04-13 01:30:44 +0000 | [diff] [blame] | 651 | // List of java libraries that the included ARR (android library prebuilts) has dependencies to. |
| 652 | Libs []string |
| 653 | // If set to true, run Jetifier against .aar file. Defaults to false. |
Colin Cross | 1001a79 | 2019-03-21 22:21:39 -0700 | [diff] [blame] | 654 | Jetifier *bool |
Sam Delmerico | 8260249 | 2022-06-10 17:05:42 +0000 | [diff] [blame] | 655 | // If true, extract JNI libs from AAR archive. These libs will be accessible to android_app modules and |
| 656 | // will be passed transitively through android_libraries to an android_app. |
| 657 | //TODO(b/241138093) evaluate whether we can have this flag default to true for Bazel conversion |
| 658 | Extract_jni *bool |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 659 | } |
| 660 | |
| 661 | type AARImport struct { |
| 662 | android.ModuleBase |
Colin Cross | 48de9a4 | 2018-10-02 13:53:33 -0700 | [diff] [blame] | 663 | android.DefaultableModuleBase |
Jooyung Han | acc7bbe | 2020-05-20 09:06:00 +0900 | [diff] [blame] | 664 | android.ApexModuleBase |
Romain Jobredeaux | c9b2bba | 2022-02-15 09:35:07 -0500 | [diff] [blame] | 665 | android.BazelModuleBase |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 666 | prebuilt android.Prebuilt |
| 667 | |
Jooyung Han | acc7bbe | 2020-05-20 09:06:00 +0900 | [diff] [blame] | 668 | // Functionality common to Module and Import. |
| 669 | embeddableInModuleAndImport |
| 670 | |
Sam Delmerico | 9f9c0a2 | 2022-11-29 11:19:37 -0500 | [diff] [blame] | 671 | providesTransitiveHeaderJars |
| 672 | |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 673 | properties AARImportProperties |
| 674 | |
Colin Cross | 66f7882 | 2018-05-02 12:58:28 -0700 | [diff] [blame] | 675 | classpathFile android.WritablePath |
| 676 | proguardFlags android.WritablePath |
| 677 | exportPackage android.WritablePath |
| 678 | extraAaptPackagesFile android.WritablePath |
Colin Cross | 10f7c4a | 2018-05-23 10:59:28 -0700 | [diff] [blame] | 679 | manifest android.WritablePath |
Michael Rosenfeld | 5ad1557 | 2021-12-03 13:25:10 -0800 | [diff] [blame] | 680 | assetsPackage android.WritablePath |
Colin Cross | 66f7882 | 2018-05-02 12:58:28 -0700 | [diff] [blame] | 681 | |
| 682 | exportedStaticPackages android.Paths |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 683 | |
| 684 | hideApexVariantFromMake bool |
Saeid Farivar Asanjan | f043696 | 2020-10-05 19:09:09 +0000 | [diff] [blame] | 685 | |
Sam Delmerico | 8260249 | 2022-06-10 17:05:42 +0000 | [diff] [blame] | 686 | aarPath android.Path |
| 687 | jniPackages android.Paths |
Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 688 | |
| 689 | sdkVersion android.SdkSpec |
| 690 | minSdkVersion android.SdkSpec |
Saeid Farivar Asanjan | f043696 | 2020-10-05 19:09:09 +0000 | [diff] [blame] | 691 | } |
| 692 | |
| 693 | var _ android.OutputFileProducer = (*AARImport)(nil) |
| 694 | |
| 695 | // For OutputFileProducer interface |
| 696 | func (a *AARImport) OutputFiles(tag string) (android.Paths, error) { |
| 697 | switch tag { |
| 698 | case ".aar": |
| 699 | return []android.Path{a.aarPath}, nil |
| 700 | case "": |
| 701 | return []android.Path{a.classpathFile}, nil |
| 702 | default: |
| 703 | return nil, fmt.Errorf("unsupported module reference tag %q", tag) |
| 704 | } |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 705 | } |
| 706 | |
Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 707 | func (a *AARImport) SdkVersion(ctx android.EarlyModuleContext) android.SdkSpec { |
| 708 | return android.SdkSpecFrom(ctx, String(a.properties.Sdk_version)) |
Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 709 | } |
| 710 | |
Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 711 | func (a *AARImport) SystemModules() string { |
Paul Duffin | e25c644 | 2019-10-11 13:50:28 +0100 | [diff] [blame] | 712 | return "" |
| 713 | } |
| 714 | |
Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 715 | func (a *AARImport) MinSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec { |
Colin Cross | 479884c | 2018-07-10 13:39:30 -0700 | [diff] [blame] | 716 | if a.properties.Min_sdk_version != nil { |
Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 717 | return android.SdkSpecFrom(ctx, *a.properties.Min_sdk_version) |
Colin Cross | 479884c | 2018-07-10 13:39:30 -0700 | [diff] [blame] | 718 | } |
Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 719 | return a.SdkVersion(ctx) |
Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 720 | } |
| 721 | |
William Loh | 5a082f9 | 2022-05-17 20:21:50 +0000 | [diff] [blame] | 722 | func (a *AARImport) ReplaceMaxSdkVersionPlaceholder(ctx android.EarlyModuleContext) android.SdkSpec { |
| 723 | return android.SdkSpecFrom(ctx, "") |
| 724 | } |
| 725 | |
Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 726 | func (a *AARImport) TargetSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec { |
| 727 | return a.SdkVersion(ctx) |
Dan Willemsen | 419290a | 2018-10-31 15:28:47 -0700 | [diff] [blame] | 728 | } |
| 729 | |
Colin Cross | 1e74385 | 2019-10-28 11:37:20 -0700 | [diff] [blame] | 730 | func (a *AARImport) javaVersion() string { |
| 731 | return "" |
| 732 | } |
| 733 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 734 | var _ AndroidLibraryDependency = (*AARImport)(nil) |
| 735 | |
| 736 | func (a *AARImport) ExportPackage() android.Path { |
| 737 | return a.exportPackage |
| 738 | } |
| 739 | |
Colin Cross | 89c3158 | 2018-04-30 15:55:11 -0700 | [diff] [blame] | 740 | func (a *AARImport) ExportedProguardFlagFiles() android.Paths { |
| 741 | return android.Paths{a.proguardFlags} |
| 742 | } |
| 743 | |
Anton Hansson | 53c8844 | 2019-03-18 15:53:16 +0000 | [diff] [blame] | 744 | func (a *AARImport) ExportedRRODirs() []rroDir { |
Colin Cross | c1c3755 | 2019-01-31 11:42:41 -0800 | [diff] [blame] | 745 | return nil |
| 746 | } |
| 747 | |
Colin Cross | 66f7882 | 2018-05-02 12:58:28 -0700 | [diff] [blame] | 748 | func (a *AARImport) ExportedStaticPackages() android.Paths { |
| 749 | return a.exportedStaticPackages |
| 750 | } |
| 751 | |
Colin Cross | 90c25c6 | 2019-04-19 16:22:57 -0700 | [diff] [blame] | 752 | func (a *AARImport) ExportedManifests() android.Paths { |
| 753 | return android.Paths{a.manifest} |
Colin Cross | 3165695 | 2018-05-24 16:11:20 -0700 | [diff] [blame] | 754 | } |
| 755 | |
Jaewoong Jung | 6431ca7 | 2020-01-15 14:15:10 -0800 | [diff] [blame] | 756 | func (a *AARImport) ExportedAssets() android.OptionalPath { |
Michael Rosenfeld | 5ad1557 | 2021-12-03 13:25:10 -0800 | [diff] [blame] | 757 | return android.OptionalPathForPath(a.assetsPackage) |
Jaewoong Jung | 6431ca7 | 2020-01-15 14:15:10 -0800 | [diff] [blame] | 758 | } |
| 759 | |
Jaewoong Jung | c779cd4 | 2020-10-06 18:56:10 -0700 | [diff] [blame] | 760 | // RRO enforcement is not available on aar_import since its RRO dirs are not |
| 761 | // exported. |
| 762 | func (a *AARImport) SetRROEnforcedForDependent(enforce bool) { |
| 763 | } |
| 764 | |
| 765 | // RRO enforcement is not available on aar_import since its RRO dirs are not |
| 766 | // exported. |
| 767 | func (a *AARImport) IsRROEnforced(ctx android.BaseModuleContext) bool { |
| 768 | return false |
| 769 | } |
| 770 | |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 771 | func (a *AARImport) Prebuilt() *android.Prebuilt { |
| 772 | return &a.prebuilt |
| 773 | } |
| 774 | |
| 775 | func (a *AARImport) Name() string { |
| 776 | return a.prebuilt.Name(a.ModuleBase.Name()) |
| 777 | } |
| 778 | |
Jiyong Park | 618922e | 2020-01-08 13:35:43 +0900 | [diff] [blame] | 779 | func (a *AARImport) JacocoReportClassesFile() android.Path { |
| 780 | return nil |
| 781 | } |
| 782 | |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 783 | func (a *AARImport) DepsMutator(ctx android.BottomUpMutatorContext) { |
Jeongik Cha | 816a23a | 2020-07-08 01:09:23 +0900 | [diff] [blame] | 784 | if !ctx.Config().AlwaysUsePrebuiltSdks() { |
Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 785 | sdkDep := decodeSdkDep(ctx, android.SdkContext(a)) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 786 | if sdkDep.useModule && sdkDep.frameworkResModule != "" { |
Colin Cross | 42d48b7 | 2018-08-29 14:10:52 -0700 | [diff] [blame] | 787 | ctx.AddVariationDependencies(nil, frameworkResTag, sdkDep.frameworkResModule) |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 788 | } |
| 789 | } |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 790 | |
Colin Cross | 42d48b7 | 2018-08-29 14:10:52 -0700 | [diff] [blame] | 791 | ctx.AddVariationDependencies(nil, libTag, a.properties.Libs...) |
| 792 | ctx.AddVariationDependencies(nil, staticLibTag, a.properties.Static_libs...) |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 793 | } |
| 794 | |
Sam Delmerico | 8260249 | 2022-06-10 17:05:42 +0000 | [diff] [blame] | 795 | type JniPackageInfo struct { |
| 796 | // List of zip files containing JNI libraries |
| 797 | // Zip files should have directory structure jni/<arch>/*.so |
| 798 | JniPackages android.Paths |
| 799 | } |
| 800 | |
| 801 | var JniPackageProvider = blueprint.NewProvider(JniPackageInfo{}) |
| 802 | |
| 803 | // Unzip an AAR and extract the JNI libs for $archString. |
| 804 | var extractJNI = pctx.AndroidStaticRule("extractJNI", |
| 805 | blueprint.RuleParams{ |
| 806 | Command: `rm -rf $out $outDir && touch $out && ` + |
| 807 | `unzip -qoDD -d $outDir $in "jni/${archString}/*" && ` + |
| 808 | `jni_files=$$(find $outDir/jni -type f) && ` + |
| 809 | // print error message if there are no JNI libs for this arch |
| 810 | `[ -n "$$jni_files" ] || (echo "ERROR: no JNI libs found for arch ${archString}" && exit 1) && ` + |
| 811 | `${config.SoongZipCmd} -o $out -P 'lib/${archString}' ` + |
| 812 | `-C $outDir/jni/${archString} $$(echo $$jni_files | xargs -n1 printf " -f %s")`, |
| 813 | CommandDeps: []string{"${config.SoongZipCmd}"}, |
| 814 | }, |
| 815 | "outDir", "archString") |
| 816 | |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 817 | // 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] | 818 | // 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] | 819 | var unzipAAR = pctx.AndroidStaticRule("unzipAAR", |
| 820 | blueprint.RuleParams{ |
Dan Willemsen | 304cfec | 2019-05-28 14:49:06 -0700 | [diff] [blame] | 821 | Command: `rm -rf $outDir && mkdir -p $outDir && ` + |
Colin Cross | 205e911 | 2020-08-06 13:20:17 -0700 | [diff] [blame] | 822 | `unzip -qoDD -d $outDir $in && rm -rf $outDir/res && touch $out && ` + |
Michael Rosenfeld | 5ad1557 | 2021-12-03 13:25:10 -0800 | [diff] [blame] | 823 | `${config.Zip2ZipCmd} -i $in -o $assetsPackage 'assets/**/*' && ` + |
Colin Cross | 205e911 | 2020-08-06 13:20:17 -0700 | [diff] [blame] | 824 | `${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] | 825 | CommandDeps: []string{"${config.MergeZipsCmd}", "${config.Zip2ZipCmd}"}, |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 826 | }, |
Michael Rosenfeld | 5ad1557 | 2021-12-03 13:25:10 -0800 | [diff] [blame] | 827 | "outDir", "combinedClassesJar", "assetsPackage") |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 828 | |
| 829 | func (a *AARImport) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 830 | if len(a.properties.Aars) != 1 { |
| 831 | ctx.PropertyErrorf("aars", "exactly one aar is required") |
| 832 | return |
| 833 | } |
| 834 | |
Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 835 | a.sdkVersion = a.SdkVersion(ctx) |
| 836 | a.minSdkVersion = a.MinSdkVersion(ctx) |
| 837 | |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 838 | a.hideApexVariantFromMake = !ctx.Provider(android.ApexInfoProvider).(android.ApexInfo).IsForPlatform() |
| 839 | |
Nan Zhang | 4c819fb | 2018-08-27 18:31:46 -0700 | [diff] [blame] | 840 | aarName := ctx.ModuleName() + ".aar" |
Saeid Farivar Asanjan | f043696 | 2020-10-05 19:09:09 +0000 | [diff] [blame] | 841 | a.aarPath = android.PathForModuleSrc(ctx, a.properties.Aars[0]) |
| 842 | |
Colin Cross | 1001a79 | 2019-03-21 22:21:39 -0700 | [diff] [blame] | 843 | if Bool(a.properties.Jetifier) { |
Saeid Farivar Asanjan | f043696 | 2020-10-05 19:09:09 +0000 | [diff] [blame] | 844 | inputFile := a.aarPath |
| 845 | a.aarPath = android.PathForModuleOut(ctx, "jetifier", aarName) |
| 846 | TransformJetifier(ctx, a.aarPath.(android.WritablePath), inputFile) |
Nan Zhang | 4c819fb | 2018-08-27 18:31:46 -0700 | [diff] [blame] | 847 | } |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 848 | |
| 849 | extractedAARDir := android.PathForModuleOut(ctx, "aar") |
Colin Cross | 205e911 | 2020-08-06 13:20:17 -0700 | [diff] [blame] | 850 | a.classpathFile = extractedAARDir.Join(ctx, "classes-combined.jar") |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 851 | a.proguardFlags = extractedAARDir.Join(ctx, "proguard.txt") |
Colin Cross | 10f7c4a | 2018-05-23 10:59:28 -0700 | [diff] [blame] | 852 | a.manifest = extractedAARDir.Join(ctx, "AndroidManifest.xml") |
Michael Rosenfeld | 5ad1557 | 2021-12-03 13:25:10 -0800 | [diff] [blame] | 853 | a.assetsPackage = android.PathForModuleOut(ctx, "assets.zip") |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 854 | |
| 855 | ctx.Build(pctx, android.BuildParams{ |
| 856 | Rule: unzipAAR, |
Saeid Farivar Asanjan | f043696 | 2020-10-05 19:09:09 +0000 | [diff] [blame] | 857 | Input: a.aarPath, |
Michael Rosenfeld | 5ad1557 | 2021-12-03 13:25:10 -0800 | [diff] [blame] | 858 | Outputs: android.WritablePaths{a.classpathFile, a.proguardFlags, a.manifest, a.assetsPackage}, |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 859 | Description: "unzip AAR", |
| 860 | Args: map[string]string{ |
Colin Cross | 205e911 | 2020-08-06 13:20:17 -0700 | [diff] [blame] | 861 | "outDir": extractedAARDir.String(), |
| 862 | "combinedClassesJar": a.classpathFile.String(), |
Michael Rosenfeld | 5ad1557 | 2021-12-03 13:25:10 -0800 | [diff] [blame] | 863 | "assetsPackage": a.assetsPackage.String(), |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 864 | }, |
| 865 | }) |
| 866 | |
Colin Cross | a0ba2f5 | 2019-06-22 12:59:27 -0700 | [diff] [blame] | 867 | // Always set --pseudo-localize, it will be stripped out later for release |
| 868 | // builds that don't want it. |
| 869 | compileFlags := []string{"--pseudo-localize"} |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 870 | compiledResDir := android.PathForModuleOut(ctx, "flat-res") |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 871 | flata := compiledResDir.Join(ctx, "gen_res.flata") |
Saeid Farivar Asanjan | f043696 | 2020-10-05 19:09:09 +0000 | [diff] [blame] | 872 | aapt2CompileZip(ctx, flata, a.aarPath, "res", compileFlags) |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 873 | |
| 874 | a.exportPackage = android.PathForModuleOut(ctx, "package-res.apk") |
Jiyong Park | b7c639e | 2019-08-19 14:56:02 +0900 | [diff] [blame] | 875 | // the subdir "android" is required to be filtered by package names |
| 876 | srcJar := android.PathForModuleGen(ctx, "android", "R.srcjar") |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 877 | proguardOptionsFile := android.PathForModuleGen(ctx, "proguard.options") |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 878 | rTxt := android.PathForModuleOut(ctx, "R.txt") |
Colin Cross | 66f7882 | 2018-05-02 12:58:28 -0700 | [diff] [blame] | 879 | a.extraAaptPackagesFile = android.PathForModuleOut(ctx, "extra_packages") |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 880 | |
| 881 | var linkDeps android.Paths |
| 882 | |
| 883 | linkFlags := []string{ |
| 884 | "--static-lib", |
| 885 | "--no-static-lib-packages", |
| 886 | "--auto-add-overlay", |
| 887 | } |
| 888 | |
Colin Cross | 10f7c4a | 2018-05-23 10:59:28 -0700 | [diff] [blame] | 889 | linkFlags = append(linkFlags, "--manifest "+a.manifest.String()) |
| 890 | linkDeps = append(linkDeps, a.manifest) |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 891 | |
Ulya Trafimovich | 1855424 | 2020-11-03 15:55:11 +0000 | [diff] [blame] | 892 | transitiveStaticLibs, staticLibManifests, staticRRODirs, transitiveAssets, libDeps, libFlags := |
Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 893 | aaptLibs(ctx, android.SdkContext(a), nil) |
Colin Cross | 3165695 | 2018-05-24 16:11:20 -0700 | [diff] [blame] | 894 | |
| 895 | _ = staticLibManifests |
Colin Cross | c1c3755 | 2019-01-31 11:42:41 -0800 | [diff] [blame] | 896 | _ = staticRRODirs |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 897 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 898 | linkDeps = append(linkDeps, libDeps...) |
| 899 | linkFlags = append(linkFlags, libFlags...) |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 900 | |
Colin Cross | 66f7882 | 2018-05-02 12:58:28 -0700 | [diff] [blame] | 901 | overlayRes := append(android.Paths{flata}, transitiveStaticLibs...) |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 902 | |
Colin Cross | 66f7882 | 2018-05-02 12:58:28 -0700 | [diff] [blame] | 903 | aapt2Link(ctx, a.exportPackage, srcJar, proguardOptionsFile, rTxt, a.extraAaptPackagesFile, |
Jaewoong Jung | 6431ca7 | 2020-01-15 14:15:10 -0800 | [diff] [blame] | 904 | linkFlags, linkDeps, nil, overlayRes, transitiveAssets, nil) |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 905 | |
Michael Rosenfeld | 5ad1557 | 2021-12-03 13:25:10 -0800 | [diff] [blame] | 906 | // Merge this import's assets with its dependencies' assets (if there are any). |
| 907 | if len(transitiveAssets) > 0 { |
| 908 | mergedAssets := android.PathForModuleOut(ctx, "merged-assets.zip") |
| 909 | inputZips := append(android.Paths{a.assetsPackage}, transitiveAssets...) |
| 910 | ctx.Build(pctx, android.BuildParams{ |
| 911 | Rule: mergeAssetsRule, |
| 912 | Inputs: inputZips, |
| 913 | Output: mergedAssets, |
| 914 | Description: "merge assets from dependencies and self", |
| 915 | }) |
| 916 | a.assetsPackage = mergedAssets |
| 917 | } |
| 918 | |
Sam Delmerico | 9f9c0a2 | 2022-11-29 11:19:37 -0500 | [diff] [blame] | 919 | a.collectTransitiveHeaderJars(ctx) |
Colin Cross | dcf71b2 | 2021-02-01 13:59:03 -0800 | [diff] [blame] | 920 | ctx.SetProvider(JavaInfoProvider, JavaInfo{ |
| 921 | HeaderJars: android.PathsIfNonNil(a.classpathFile), |
Sam Delmerico | 9f9c0a2 | 2022-11-29 11:19:37 -0500 | [diff] [blame] | 922 | TransitiveLibsHeaderJars: a.transitiveLibsHeaderJars, |
| 923 | TransitiveStaticLibsHeaderJars: a.transitiveStaticLibsHeaderJars, |
Colin Cross | dcf71b2 | 2021-02-01 13:59:03 -0800 | [diff] [blame] | 924 | ImplementationAndResourcesJars: android.PathsIfNonNil(a.classpathFile), |
| 925 | ImplementationJars: android.PathsIfNonNil(a.classpathFile), |
| 926 | }) |
Sam Delmerico | 8260249 | 2022-06-10 17:05:42 +0000 | [diff] [blame] | 927 | |
| 928 | if proptools.Bool(a.properties.Extract_jni) { |
| 929 | for _, t := range ctx.MultiTargets() { |
| 930 | arch := t.Arch.Abi[0] |
| 931 | path := android.PathForModuleOut(ctx, arch+"_jni.zip") |
| 932 | a.jniPackages = append(a.jniPackages, path) |
| 933 | |
| 934 | outDir := android.PathForModuleOut(ctx, "aarForJni") |
| 935 | aarPath := android.PathForModuleSrc(ctx, a.properties.Aars[0]) |
| 936 | ctx.Build(pctx, android.BuildParams{ |
| 937 | Rule: extractJNI, |
| 938 | Input: aarPath, |
| 939 | Outputs: android.WritablePaths{path}, |
| 940 | Description: "extract JNI from AAR", |
| 941 | Args: map[string]string{ |
| 942 | "outDir": outDir.String(), |
| 943 | "archString": arch, |
| 944 | }, |
| 945 | }) |
| 946 | } |
| 947 | |
| 948 | ctx.SetProvider(JniPackageProvider, JniPackageInfo{ |
| 949 | JniPackages: a.jniPackages, |
| 950 | }) |
| 951 | } |
Colin Cross | dcf71b2 | 2021-02-01 13:59:03 -0800 | [diff] [blame] | 952 | } |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 953 | |
| 954 | func (a *AARImport) HeaderJars() android.Paths { |
| 955 | return android.Paths{a.classpathFile} |
| 956 | } |
| 957 | |
Colin Cross | 331a121 | 2018-08-15 20:40:52 -0700 | [diff] [blame] | 958 | func (a *AARImport) ImplementationAndResourcesJars() android.Paths { |
| 959 | return android.Paths{a.classpathFile} |
| 960 | } |
| 961 | |
Ulyana Trafimovich | 5539e7b | 2020-06-04 14:08:17 +0000 | [diff] [blame] | 962 | func (a *AARImport) DexJarBuildPath() android.Path { |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 963 | return nil |
| 964 | } |
| 965 | |
Ulya Trafimovich | 9f3052c | 2020-06-09 14:31:19 +0100 | [diff] [blame] | 966 | func (a *AARImport) DexJarInstallPath() android.Path { |
| 967 | return nil |
| 968 | } |
| 969 | |
Ulya Trafimovich | b23d28c | 2020-10-08 12:53:58 +0100 | [diff] [blame] | 970 | func (a *AARImport) ClassLoaderContexts() dexpreopt.ClassLoaderContextMap { |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 971 | return nil |
| 972 | } |
| 973 | |
Jiyong Park | 45bf82e | 2020-12-15 22:29:02 +0900 | [diff] [blame] | 974 | var _ android.ApexModule = (*AARImport)(nil) |
| 975 | |
| 976 | // Implements android.ApexModule |
Jooyung Han | acc7bbe | 2020-05-20 09:06:00 +0900 | [diff] [blame] | 977 | func (a *AARImport) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool { |
| 978 | return a.depIsInSameApex(ctx, dep) |
| 979 | } |
| 980 | |
Jiyong Park | 45bf82e | 2020-12-15 22:29:02 +0900 | [diff] [blame] | 981 | // Implements android.ApexModule |
Dan Albert | c806053 | 2020-07-22 22:32:17 -0700 | [diff] [blame] | 982 | func (g *AARImport) ShouldSupportSdkVersion(ctx android.BaseModuleContext, |
| 983 | sdkVersion android.ApiLevel) error { |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 984 | return nil |
| 985 | } |
| 986 | |
Sam Delmerico | af8bb70 | 2022-07-25 15:39:32 -0400 | [diff] [blame] | 987 | var _ android.PrebuiltInterface = (*AARImport)(nil) |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 988 | |
Colin Cross | 1b16b0e | 2019-02-12 14:41:32 -0800 | [diff] [blame] | 989 | // android_library_import imports an `.aar` file into the build graph as if it was built with android_library. |
| 990 | // |
| 991 | // This module is not suitable for installing on a device, but can be used as a `static_libs` dependency of |
| 992 | // an android_app module. |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 993 | func AARImportFactory() android.Module { |
| 994 | module := &AARImport{} |
| 995 | |
| 996 | module.AddProperties(&module.properties) |
| 997 | |
| 998 | android.InitPrebuiltModule(module, &module.properties.Aars) |
Jooyung Han | acc7bbe | 2020-05-20 09:06:00 +0900 | [diff] [blame] | 999 | android.InitApexModule(module) |
Sam Delmerico | 8260249 | 2022-06-10 17:05:42 +0000 | [diff] [blame] | 1000 | InitJavaModuleMultiTargets(module, android.DeviceSupported) |
Romain Jobredeaux | c9b2bba | 2022-02-15 09:35:07 -0500 | [diff] [blame] | 1001 | android.InitBazelModule(module) |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 1002 | return module |
| 1003 | } |
Romain Jobredeaux | c9b2bba | 2022-02-15 09:35:07 -0500 | [diff] [blame] | 1004 | |
| 1005 | type bazelAapt struct { |
| 1006 | Manifest bazel.Label |
| 1007 | Resource_files bazel.LabelListAttribute |
| 1008 | } |
| 1009 | |
| 1010 | type bazelAndroidLibrary struct { |
| 1011 | *javaLibraryAttributes |
| 1012 | *bazelAapt |
| 1013 | } |
| 1014 | |
| 1015 | type bazelAndroidLibraryImport struct { |
| 1016 | Aar bazel.Label |
| 1017 | Deps bazel.LabelListAttribute |
| 1018 | Exports bazel.LabelListAttribute |
| 1019 | } |
| 1020 | |
| 1021 | func (a *aapt) convertAaptAttrsWithBp2Build(ctx android.TopDownMutatorContext) *bazelAapt { |
| 1022 | manifest := proptools.StringDefault(a.aaptProperties.Manifest, "AndroidManifest.xml") |
| 1023 | |
| 1024 | resourceFiles := bazel.LabelList{ |
| 1025 | Includes: []bazel.Label{}, |
| 1026 | } |
| 1027 | for _, dir := range android.PathsWithOptionalDefaultForModuleSrc(ctx, a.aaptProperties.Resource_dirs, "res") { |
| 1028 | files := android.RootToModuleRelativePaths(ctx, androidResourceGlob(ctx, dir)) |
| 1029 | resourceFiles.Includes = append(resourceFiles.Includes, files...) |
| 1030 | } |
| 1031 | return &bazelAapt{ |
| 1032 | android.BazelLabelForModuleSrcSingle(ctx, manifest), |
| 1033 | bazel.MakeLabelListAttribute(resourceFiles), |
| 1034 | } |
| 1035 | } |
| 1036 | |
| 1037 | func (a *AARImport) ConvertWithBp2build(ctx android.TopDownMutatorContext) { |
| 1038 | aars := android.BazelLabelForModuleSrcExcludes(ctx, a.properties.Aars, []string{}) |
| 1039 | exportableStaticLibs := []string{} |
| 1040 | // TODO(b/240716882): investigate and handle static_libs deps that are not imports. They are not supported for export by Bazel. |
| 1041 | for _, depName := range a.properties.Static_libs { |
| 1042 | if dep, ok := ctx.ModuleFromName(depName); ok { |
| 1043 | switch dep.(type) { |
| 1044 | case *AARImport, *Import: |
| 1045 | exportableStaticLibs = append(exportableStaticLibs, depName) |
| 1046 | } |
| 1047 | } |
| 1048 | } |
| 1049 | name := android.RemoveOptionalPrebuiltPrefix(a.Name()) |
| 1050 | deps := android.BazelLabelForModuleDeps(ctx, android.LastUniqueStrings(android.CopyOf(append(a.properties.Static_libs, a.properties.Libs...)))) |
| 1051 | exports := android.BazelLabelForModuleDeps(ctx, android.LastUniqueStrings(exportableStaticLibs)) |
| 1052 | |
| 1053 | ctx.CreateBazelTargetModule( |
| 1054 | bazel.BazelTargetModuleProperties{ |
| 1055 | Rule_class: "aar_import", |
Romain Jobredeaux | 5ccb460 | 2022-12-19 11:17:16 -0500 | [diff] [blame] | 1056 | Bzl_load_location: "//build/bazel/rules/android:rules.bzl", |
Romain Jobredeaux | c9b2bba | 2022-02-15 09:35:07 -0500 | [diff] [blame] | 1057 | }, |
| 1058 | android.CommonAttributes{Name: name}, |
| 1059 | &bazelAndroidLibraryImport{ |
| 1060 | Aar: aars.Includes[0], |
| 1061 | Deps: bazel.MakeLabelListAttribute(deps), |
| 1062 | Exports: bazel.MakeLabelListAttribute(exports), |
| 1063 | }, |
| 1064 | ) |
| 1065 | |
Alix | 14101de | 2023-01-06 03:42:07 +0000 | [diff] [blame] | 1066 | neverlink := true |
| 1067 | ctx.CreateBazelTargetModule( |
| 1068 | bazel.BazelTargetModuleProperties{ |
| 1069 | Rule_class: "android_library", |
| 1070 | Bzl_load_location: "//build/bazel/rules/android:rules.bzl", |
| 1071 | }, |
| 1072 | android.CommonAttributes{Name: name + "-neverlink"}, |
| 1073 | &bazelAndroidLibrary{ |
| 1074 | javaLibraryAttributes: &javaLibraryAttributes{ |
| 1075 | Neverlink: bazel.BoolAttribute{Value: &neverlink}, |
| 1076 | Exports: bazel.MakeSingleLabelListAttribute(bazel.Label{Label: ":" + name}), |
| 1077 | }, |
| 1078 | }, |
| 1079 | ) |
| 1080 | |
Romain Jobredeaux | c9b2bba | 2022-02-15 09:35:07 -0500 | [diff] [blame] | 1081 | } |
| 1082 | |
| 1083 | func (a *AndroidLibrary) ConvertWithBp2build(ctx android.TopDownMutatorContext) { |
Alix | 8062f4d | 2022-11-14 21:38:07 +0000 | [diff] [blame] | 1084 | commonAttrs, bp2buildInfo := a.convertLibraryAttrsBp2Build(ctx) |
| 1085 | depLabels := bp2buildInfo.DepLabels |
Romain Jobredeaux | c9b2bba | 2022-02-15 09:35:07 -0500 | [diff] [blame] | 1086 | |
| 1087 | deps := depLabels.Deps |
| 1088 | if !commonAttrs.Srcs.IsEmpty() { |
| 1089 | deps.Append(depLabels.StaticDeps) // we should only append these if there are sources to use them |
| 1090 | } else if !depLabels.Deps.IsEmpty() { |
| 1091 | ctx.ModuleErrorf("Module has direct dependencies but no sources. Bazel will not allow this.") |
| 1092 | } |
| 1093 | |
Alix | 36795a7 | 2023-01-20 16:10:52 +0000 | [diff] [blame] | 1094 | if len(a.properties.Common_srcs) != 0 { |
| 1095 | commonAttrs.Common_srcs = bazel.MakeLabelListAttribute(android.BazelLabelForModuleSrc(ctx, a.properties.Common_srcs)) |
| 1096 | } |
| 1097 | |
Alix | 82fb94e | 2022-10-26 20:40:18 +0000 | [diff] [blame] | 1098 | name := a.Name() |
| 1099 | props := bazel.BazelTargetModuleProperties{ |
| 1100 | Rule_class: "android_library", |
Romain Jobredeaux | 5ccb460 | 2022-12-19 11:17:16 -0500 | [diff] [blame] | 1101 | Bzl_load_location: "//build/bazel/rules/android:rules.bzl", |
Alix | 82fb94e | 2022-10-26 20:40:18 +0000 | [diff] [blame] | 1102 | } |
| 1103 | |
Romain Jobredeaux | c9b2bba | 2022-02-15 09:35:07 -0500 | [diff] [blame] | 1104 | ctx.CreateBazelTargetModule( |
Alix | 82fb94e | 2022-10-26 20:40:18 +0000 | [diff] [blame] | 1105 | props, |
| 1106 | android.CommonAttributes{Name: name}, |
Romain Jobredeaux | c9b2bba | 2022-02-15 09:35:07 -0500 | [diff] [blame] | 1107 | &bazelAndroidLibrary{ |
| 1108 | &javaLibraryAttributes{ |
| 1109 | javaCommonAttributes: commonAttrs, |
| 1110 | Deps: deps, |
| 1111 | Exports: depLabels.StaticDeps, |
| 1112 | }, |
| 1113 | a.convertAaptAttrsWithBp2Build(ctx), |
| 1114 | }, |
| 1115 | ) |
Alix | 82fb94e | 2022-10-26 20:40:18 +0000 | [diff] [blame] | 1116 | |
| 1117 | neverlink := true |
| 1118 | ctx.CreateBazelTargetModule( |
| 1119 | props, |
| 1120 | android.CommonAttributes{Name: name + "-neverlink"}, |
| 1121 | &bazelAndroidLibrary{ |
| 1122 | javaLibraryAttributes: &javaLibraryAttributes{ |
| 1123 | Neverlink: bazel.BoolAttribute{Value: &neverlink}, |
| 1124 | Exports: bazel.MakeSingleLabelListAttribute(bazel.Label{Label: ":" + name}), |
| 1125 | }, |
| 1126 | }, |
| 1127 | ) |
Romain Jobredeaux | c9b2bba | 2022-02-15 09:35:07 -0500 | [diff] [blame] | 1128 | } |