Jihoon Kang | f2c5398 | 2024-10-09 17:32:52 +0000 | [diff] [blame] | 1 | // Copyright (C) 2024 The Android Open Source Project |
| 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 filesystem |
| 16 | |
| 17 | import ( |
Jihoon Kang | abec3ec | 2025-02-19 00:55:10 +0000 | [diff] [blame] | 18 | "cmp" |
Jihoon Kang | 0a6315b | 2025-01-30 01:14:49 +0000 | [diff] [blame] | 19 | "fmt" |
Cole Faust | 1dcf9e4 | 2025-02-19 17:23:34 -0800 | [diff] [blame] | 20 | "path/filepath" |
Jihoon Kang | abec3ec | 2025-02-19 00:55:10 +0000 | [diff] [blame] | 21 | "slices" |
Spandan Das | 258c08f | 2025-01-08 23:30:45 +0000 | [diff] [blame] | 22 | "strings" |
Cole Faust | b55a41c | 2025-01-09 16:53:58 -0800 | [diff] [blame] | 23 | "sync/atomic" |
Spandan Das | 258c08f | 2025-01-08 23:30:45 +0000 | [diff] [blame] | 24 | |
Jihoon Kang | f2c5398 | 2024-10-09 17:32:52 +0000 | [diff] [blame] | 25 | "android/soong/android" |
Cole Faust | 1dcf9e4 | 2025-02-19 17:23:34 -0800 | [diff] [blame] | 26 | "android/soong/java" |
Jihoon Kang | f2c5398 | 2024-10-09 17:32:52 +0000 | [diff] [blame] | 27 | |
| 28 | "github.com/google/blueprint" |
| 29 | "github.com/google/blueprint/proptools" |
| 30 | ) |
| 31 | |
Cole Faust | 1dcf9e4 | 2025-02-19 17:23:34 -0800 | [diff] [blame] | 32 | var proguardDictToProto = pctx.AndroidStaticRule("proguard_dict_to_proto", blueprint.RuleParams{ |
| 33 | Command: `${symbols_map} -r8 $in -location $location -write_if_changed $out`, |
| 34 | Restat: true, |
| 35 | CommandDeps: []string{"${symbols_map}"}, |
| 36 | }, "location") |
| 37 | |
Jihoon Kang | f2c5398 | 2024-10-09 17:32:52 +0000 | [diff] [blame] | 38 | type PartitionNameProperties struct { |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 39 | // Name of the super partition filesystem module |
| 40 | Super_partition_name *string |
Jihoon Kang | e7e3ec8 | 2025-01-02 21:29:14 +0000 | [diff] [blame] | 41 | // Name of the boot partition filesystem module |
Jihoon Kang | f2c5398 | 2024-10-09 17:32:52 +0000 | [diff] [blame] | 42 | Boot_partition_name *string |
Jihoon Kang | e7e3ec8 | 2025-01-02 21:29:14 +0000 | [diff] [blame] | 43 | // Name of the vendor boot partition filesystem module |
| 44 | Vendor_boot_partition_name *string |
| 45 | // Name of the init boot partition filesystem module |
| 46 | Init_boot_partition_name *string |
| 47 | // Name of the system partition filesystem module |
Jihoon Kang | f2c5398 | 2024-10-09 17:32:52 +0000 | [diff] [blame] | 48 | System_partition_name *string |
Jihoon Kang | e7e3ec8 | 2025-01-02 21:29:14 +0000 | [diff] [blame] | 49 | // Name of the system_ext partition filesystem module |
Jihoon Kang | f2c5398 | 2024-10-09 17:32:52 +0000 | [diff] [blame] | 50 | System_ext_partition_name *string |
Jihoon Kang | e7e3ec8 | 2025-01-02 21:29:14 +0000 | [diff] [blame] | 51 | // Name of the product partition filesystem module |
Jihoon Kang | f2c5398 | 2024-10-09 17:32:52 +0000 | [diff] [blame] | 52 | Product_partition_name *string |
Jihoon Kang | e7e3ec8 | 2025-01-02 21:29:14 +0000 | [diff] [blame] | 53 | // Name of the vendor partition filesystem module |
Jihoon Kang | f2c5398 | 2024-10-09 17:32:52 +0000 | [diff] [blame] | 54 | Vendor_partition_name *string |
Jihoon Kang | e7e3ec8 | 2025-01-02 21:29:14 +0000 | [diff] [blame] | 55 | // Name of the odm partition filesystem module |
Spandan Das | c571716 | 2024-11-01 18:33:57 +0000 | [diff] [blame] | 56 | Odm_partition_name *string |
Jihoon Kang | e7e3ec8 | 2025-01-02 21:29:14 +0000 | [diff] [blame] | 57 | // Name of the recovery partition filesystem module |
| 58 | Recovery_partition_name *string |
Cole Faust | 3552eb6 | 2024-11-06 18:07:26 -0800 | [diff] [blame] | 59 | // The vbmeta partition and its "chained" partitions |
| 60 | Vbmeta_partitions []string |
Jihoon Kang | e7e3ec8 | 2025-01-02 21:29:14 +0000 | [diff] [blame] | 61 | // Name of the userdata partition filesystem module |
mrziwang | 23ba876 | 2024-11-07 16:21:53 -0800 | [diff] [blame] | 62 | Userdata_partition_name *string |
Spandan Das | a039400 | 2025-01-07 18:38:34 +0000 | [diff] [blame] | 63 | // Name of the system_dlkm partition filesystem module |
| 64 | System_dlkm_partition_name *string |
| 65 | // Name of the vendor_dlkm partition filesystem module |
| 66 | Vendor_dlkm_partition_name *string |
| 67 | // Name of the odm_dlkm partition filesystem module |
| 68 | Odm_dlkm_partition_name *string |
Jihoon Kang | f2c5398 | 2024-10-09 17:32:52 +0000 | [diff] [blame] | 69 | } |
| 70 | |
Jihoon Kang | 3be1716 | 2025-01-09 20:51:54 +0000 | [diff] [blame] | 71 | type DeviceProperties struct { |
| 72 | // Path to the prebuilt bootloader that would be copied to PRODUCT_OUT |
| 73 | Bootloader *string `android:"path"` |
Spandan Das | e51ff95 | 2025-01-09 18:11:59 +0000 | [diff] [blame] | 74 | // Path to android-info.txt file containing board specific info. |
| 75 | Android_info *string `android:"path"` |
Cole Faust | 11fda33 | 2025-01-14 16:47:19 -0800 | [diff] [blame] | 76 | // If this is the "main" android_device target for the build, i.e. the one that gets built |
| 77 | // when running a plain `m` command. Currently, this is the autogenerated android_device module |
| 78 | // in soong-only builds, but in the future when we check in android_device modules, the main |
| 79 | // one will be determined based on the lunch product. TODO: Figure out how to make this |
| 80 | // blueprint:"mutated" and still set it from filesystem_creator |
| 81 | Main_device *bool |
Spandan Das | 29d4488 | 2025-01-15 21:12:36 +0000 | [diff] [blame] | 82 | |
Spandan Das | 0094807 | 2025-02-12 19:36:03 +0000 | [diff] [blame] | 83 | Ab_ota_updater *bool |
| 84 | Ab_ota_partitions []string |
| 85 | Ab_ota_keys []string |
| 86 | Ab_ota_postinstall_config []string |
Spandan Das | 75955b1 | 2025-02-13 22:12:52 +0000 | [diff] [blame] | 87 | |
Spandan Das | 37240d9 | 2025-02-14 00:18:41 +0000 | [diff] [blame] | 88 | Ramdisk_node_list *string `android:"path"` |
| 89 | Releasetools_extension *string `android:"path"` |
Jihoon Kang | 3be1716 | 2025-01-09 20:51:54 +0000 | [diff] [blame] | 90 | } |
| 91 | |
Jihoon Kang | f2c5398 | 2024-10-09 17:32:52 +0000 | [diff] [blame] | 92 | type androidDevice struct { |
| 93 | android.ModuleBase |
| 94 | |
| 95 | partitionProps PartitionNameProperties |
Jihoon Kang | 3be1716 | 2025-01-09 20:51:54 +0000 | [diff] [blame] | 96 | |
| 97 | deviceProps DeviceProperties |
Cole Faust | a472a6f | 2025-02-10 16:10:04 -0800 | [diff] [blame] | 98 | |
| 99 | allImagesZip android.Path |
Cole Faust | 54124c8 | 2025-02-21 14:46:02 -0800 | [diff] [blame] | 100 | |
| 101 | proguardDictZip android.Path |
| 102 | proguardDictMapping android.Path |
| 103 | proguardUsageZip android.Path |
Jihoon Kang | f2c5398 | 2024-10-09 17:32:52 +0000 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | func AndroidDeviceFactory() android.Module { |
| 107 | module := &androidDevice{} |
Jihoon Kang | 3be1716 | 2025-01-09 20:51:54 +0000 | [diff] [blame] | 108 | module.AddProperties(&module.partitionProps, &module.deviceProps) |
Cole Faust | 341d5f1 | 2025-01-07 15:32:38 -0800 | [diff] [blame] | 109 | android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibFirst) |
Jihoon Kang | f2c5398 | 2024-10-09 17:32:52 +0000 | [diff] [blame] | 110 | return module |
| 111 | } |
| 112 | |
Cole Faust | 11fda33 | 2025-01-14 16:47:19 -0800 | [diff] [blame] | 113 | var numMainAndroidDevicesOnceKey android.OnceKey = android.NewOnceKey("num_auto_generated_anroid_devices") |
Cole Faust | b55a41c | 2025-01-09 16:53:58 -0800 | [diff] [blame] | 114 | |
Jihoon Kang | f2c5398 | 2024-10-09 17:32:52 +0000 | [diff] [blame] | 115 | type partitionDepTagType struct { |
| 116 | blueprint.BaseDependencyTag |
| 117 | } |
| 118 | |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 119 | type superPartitionDepTagType struct { |
| 120 | blueprint.BaseDependencyTag |
| 121 | } |
Spandan Das | 29d4488 | 2025-01-15 21:12:36 +0000 | [diff] [blame] | 122 | type targetFilesMetadataDepTagType struct { |
| 123 | blueprint.BaseDependencyTag |
| 124 | } |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 125 | |
| 126 | var superPartitionDepTag superPartitionDepTagType |
Jihoon Kang | f2c5398 | 2024-10-09 17:32:52 +0000 | [diff] [blame] | 127 | var filesystemDepTag partitionDepTagType |
Spandan Das | 29d4488 | 2025-01-15 21:12:36 +0000 | [diff] [blame] | 128 | var targetFilesMetadataDepTag targetFilesMetadataDepTagType |
Jihoon Kang | f2c5398 | 2024-10-09 17:32:52 +0000 | [diff] [blame] | 129 | |
| 130 | func (a *androidDevice) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 131 | addDependencyIfDefined := func(dep *string) { |
| 132 | if dep != nil { |
Cole Faust | 341d5f1 | 2025-01-07 15:32:38 -0800 | [diff] [blame] | 133 | ctx.AddDependency(ctx.Module(), filesystemDepTag, proptools.String(dep)) |
Jihoon Kang | f2c5398 | 2024-10-09 17:32:52 +0000 | [diff] [blame] | 134 | } |
| 135 | } |
| 136 | |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 137 | if a.partitionProps.Super_partition_name != nil { |
| 138 | ctx.AddDependency(ctx.Module(), superPartitionDepTag, *a.partitionProps.Super_partition_name) |
| 139 | } |
Jihoon Kang | f2c5398 | 2024-10-09 17:32:52 +0000 | [diff] [blame] | 140 | addDependencyIfDefined(a.partitionProps.Boot_partition_name) |
Jihoon Kang | 9e08700 | 2025-01-08 19:12:23 +0000 | [diff] [blame] | 141 | addDependencyIfDefined(a.partitionProps.Init_boot_partition_name) |
Spandan Das | ef200ac | 2025-01-08 01:42:45 +0000 | [diff] [blame] | 142 | addDependencyIfDefined(a.partitionProps.Vendor_boot_partition_name) |
Jihoon Kang | f2c5398 | 2024-10-09 17:32:52 +0000 | [diff] [blame] | 143 | addDependencyIfDefined(a.partitionProps.System_partition_name) |
| 144 | addDependencyIfDefined(a.partitionProps.System_ext_partition_name) |
| 145 | addDependencyIfDefined(a.partitionProps.Product_partition_name) |
| 146 | addDependencyIfDefined(a.partitionProps.Vendor_partition_name) |
Spandan Das | c571716 | 2024-11-01 18:33:57 +0000 | [diff] [blame] | 147 | addDependencyIfDefined(a.partitionProps.Odm_partition_name) |
mrziwang | 23ba876 | 2024-11-07 16:21:53 -0800 | [diff] [blame] | 148 | addDependencyIfDefined(a.partitionProps.Userdata_partition_name) |
Spandan Das | a039400 | 2025-01-07 18:38:34 +0000 | [diff] [blame] | 149 | addDependencyIfDefined(a.partitionProps.System_dlkm_partition_name) |
| 150 | addDependencyIfDefined(a.partitionProps.Vendor_dlkm_partition_name) |
| 151 | addDependencyIfDefined(a.partitionProps.Odm_dlkm_partition_name) |
Spandan Das | ef200ac | 2025-01-08 01:42:45 +0000 | [diff] [blame] | 152 | addDependencyIfDefined(a.partitionProps.Recovery_partition_name) |
Cole Faust | 3552eb6 | 2024-11-06 18:07:26 -0800 | [diff] [blame] | 153 | for _, vbmetaPartition := range a.partitionProps.Vbmeta_partitions { |
| 154 | ctx.AddDependency(ctx.Module(), filesystemDepTag, vbmetaPartition) |
| 155 | } |
Spandan Das | 29d4488 | 2025-01-15 21:12:36 +0000 | [diff] [blame] | 156 | a.addDepsForTargetFilesMetadata(ctx) |
| 157 | } |
| 158 | |
| 159 | func (a *androidDevice) addDepsForTargetFilesMetadata(ctx android.BottomUpMutatorContext) { |
| 160 | ctx.AddFarVariationDependencies(ctx.Config().BuildOSTarget.Variations(), targetFilesMetadataDepTag, "liblz4") // host variant |
Jihoon Kang | f2c5398 | 2024-10-09 17:32:52 +0000 | [diff] [blame] | 161 | } |
| 162 | |
Cole Faust | 11fda33 | 2025-01-14 16:47:19 -0800 | [diff] [blame] | 163 | func (a *androidDevice) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 164 | if proptools.Bool(a.deviceProps.Main_device) { |
| 165 | numMainAndroidDevices := ctx.Config().Once(numMainAndroidDevicesOnceKey, func() interface{} { |
| 166 | return &atomic.Int32{} |
| 167 | }).(*atomic.Int32) |
| 168 | total := numMainAndroidDevices.Add(1) |
| 169 | if total > 1 { |
| 170 | // There should only be 1 main android_device module. That one will be |
| 171 | // made the default thing to build in soong-only builds. |
| 172 | ctx.ModuleErrorf("There cannot be more than 1 main android_device module") |
| 173 | } |
Jihoon Kang | 3be1716 | 2025-01-09 20:51:54 +0000 | [diff] [blame] | 174 | } |
| 175 | |
Cole Faust | 1dcf9e4 | 2025-02-19 17:23:34 -0800 | [diff] [blame] | 176 | allInstalledModules := a.allInstalledModules(ctx) |
| 177 | |
Spandan Das | dad9870 | 2025-02-26 14:32:28 +0000 | [diff] [blame] | 178 | a.buildTargetFilesZip(ctx, allInstalledModules) |
Cole Faust | 1dcf9e4 | 2025-02-19 17:23:34 -0800 | [diff] [blame] | 179 | a.buildProguardZips(ctx, allInstalledModules) |
| 180 | |
mrziwang | 2fd33a7 | 2025-01-08 12:22:08 -0800 | [diff] [blame] | 181 | var deps []android.Path |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 182 | if proptools.String(a.partitionProps.Super_partition_name) != "" { |
Cole Faust | 19eb09d | 2025-01-14 13:27:00 -0800 | [diff] [blame] | 183 | superImage := ctx.GetDirectDepProxyWithTag(*a.partitionProps.Super_partition_name, superPartitionDepTag) |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 184 | if info, ok := android.OtherModuleProvider(ctx, superImage, SuperImageProvider); ok { |
| 185 | assertUnset := func(prop *string, propName string) { |
| 186 | if prop != nil && *prop != "" { |
| 187 | ctx.PropertyErrorf(propName, "Cannot be set because it's already part of the super image") |
| 188 | } |
| 189 | } |
| 190 | for _, subPartitionType := range android.SortedKeys(info.SubImageInfo) { |
| 191 | switch subPartitionType { |
| 192 | case "system": |
| 193 | assertUnset(a.partitionProps.System_partition_name, "system_partition_name") |
| 194 | case "system_ext": |
| 195 | assertUnset(a.partitionProps.System_ext_partition_name, "system_ext_partition_name") |
| 196 | case "system_dlkm": |
| 197 | assertUnset(a.partitionProps.System_dlkm_partition_name, "system_dlkm_partition_name") |
| 198 | case "system_other": |
| 199 | // TODO |
| 200 | case "product": |
| 201 | assertUnset(a.partitionProps.Product_partition_name, "product_partition_name") |
| 202 | case "vendor": |
| 203 | assertUnset(a.partitionProps.Vendor_partition_name, "vendor_partition_name") |
| 204 | case "vendor_dlkm": |
| 205 | assertUnset(a.partitionProps.Vendor_dlkm_partition_name, "vendor_dlkm_partition_name") |
| 206 | case "odm": |
| 207 | assertUnset(a.partitionProps.Odm_partition_name, "odm_partition_name") |
| 208 | case "odm_dlkm": |
| 209 | assertUnset(a.partitionProps.Odm_dlkm_partition_name, "odm_dlkm_partition_name") |
| 210 | default: |
| 211 | ctx.ModuleErrorf("Unsupported sub-partition of super partition: %q", subPartitionType) |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | deps = append(deps, info.SuperImage) |
| 216 | } else { |
| 217 | ctx.ModuleErrorf("Expected super image dep to provide SuperImageProvider") |
| 218 | } |
| 219 | } |
Cole Faust | 19eb09d | 2025-01-14 13:27:00 -0800 | [diff] [blame] | 220 | ctx.VisitDirectDepsProxyWithTag(filesystemDepTag, func(m android.ModuleProxy) { |
mrziwang | 2fd33a7 | 2025-01-08 12:22:08 -0800 | [diff] [blame] | 221 | imageOutput, ok := android.OtherModuleProvider(ctx, m, android.OutputFilesProvider) |
| 222 | if !ok { |
| 223 | ctx.ModuleErrorf("Partition module %s doesn't set OutputfilesProvider", m.Name()) |
| 224 | } |
| 225 | if len(imageOutput.DefaultOutputFiles) != 1 { |
| 226 | ctx.ModuleErrorf("Partition module %s should provide exact 1 output file", m.Name()) |
| 227 | } |
| 228 | deps = append(deps, imageOutput.DefaultOutputFiles[0]) |
| 229 | }) |
Jihoon Kang | 3be1716 | 2025-01-09 20:51:54 +0000 | [diff] [blame] | 230 | |
Cole Faust | a472a6f | 2025-02-10 16:10:04 -0800 | [diff] [blame] | 231 | allImagesZip := android.PathForModuleOut(ctx, "all_images.zip") |
| 232 | allImagesZipBuilder := android.NewRuleBuilder(pctx, ctx) |
Cole Faust | 8967d75 | 2025-02-19 17:27:29 -0800 | [diff] [blame] | 233 | cmd := allImagesZipBuilder.Command().BuiltTool("soong_zip") |
Cole Faust | a472a6f | 2025-02-10 16:10:04 -0800 | [diff] [blame] | 234 | for _, dep := range deps { |
| 235 | cmd.FlagWithArg("-e ", dep.Base()) |
| 236 | cmd.FlagWithInput("-f ", dep) |
| 237 | } |
| 238 | cmd.FlagWithOutput("-o ", allImagesZip) |
| 239 | allImagesZipBuilder.Build("soong_all_images_zip", "all_images.zip") |
| 240 | a.allImagesZip = allImagesZip |
| 241 | |
Cole Faust | b55a41c | 2025-01-09 16:53:58 -0800 | [diff] [blame] | 242 | allImagesStamp := android.PathForModuleOut(ctx, "all_images_stamp") |
Cole Faust | 11fda33 | 2025-01-14 16:47:19 -0800 | [diff] [blame] | 243 | var validations android.Paths |
| 244 | if !ctx.Config().KatiEnabled() && proptools.Bool(a.deviceProps.Main_device) { |
Cole Faust | b55a41c | 2025-01-09 16:53:58 -0800 | [diff] [blame] | 245 | // In soong-only builds, build this module by default. |
| 246 | // This is the analogue to this make code: |
| 247 | // https://cs.android.com/android/platform/superproject/main/+/main:build/make/core/main.mk;l=1396;drc=6595459cdd8164a6008335f6372c9f97b9094060 |
| 248 | ctx.Phony("droidcore-unbundled", allImagesStamp) |
Cole Faust | 11fda33 | 2025-01-14 16:47:19 -0800 | [diff] [blame] | 249 | |
Cole Faust | 19fbb07 | 2025-01-30 18:19:29 -0800 | [diff] [blame] | 250 | deps = append(deps, a.copyFilesToProductOutForSoongOnly(ctx)) |
Cole Faust | b55a41c | 2025-01-09 16:53:58 -0800 | [diff] [blame] | 251 | } |
Cole Faust | 11fda33 | 2025-01-14 16:47:19 -0800 | [diff] [blame] | 252 | |
| 253 | ctx.Build(pctx, android.BuildParams{ |
| 254 | Rule: android.Touch, |
| 255 | Output: allImagesStamp, |
| 256 | Implicits: deps, |
| 257 | Validations: validations, |
| 258 | }) |
| 259 | |
| 260 | // Checkbuilding it causes soong to make a phony, so you can say `m <module name>` |
| 261 | ctx.CheckbuildFile(allImagesStamp) |
Jihoon Kang | 0a6315b | 2025-01-30 01:14:49 +0000 | [diff] [blame] | 262 | |
| 263 | a.setVbmetaPhonyTargets(ctx) |
Jihoon Kang | f67b7de | 2025-02-12 01:01:09 +0000 | [diff] [blame] | 264 | |
| 265 | a.distFiles(ctx) |
| 266 | } |
| 267 | |
Jihoon Kang | abec3ec | 2025-02-19 00:55:10 +0000 | [diff] [blame] | 268 | // Returns a list of modules that are installed, which are collected from the dependency |
| 269 | // filesystem and super_image modules. |
| 270 | func (a *androidDevice) allInstalledModules(ctx android.ModuleContext) []android.Module { |
| 271 | fsInfoMap := a.getFsInfos(ctx) |
| 272 | allOwners := make(map[string][]string) |
| 273 | for _, partition := range android.SortedKeys(fsInfoMap) { |
| 274 | fsInfo := fsInfoMap[partition] |
| 275 | for _, owner := range fsInfo.Owners { |
| 276 | allOwners[owner.Name] = append(allOwners[owner.Name], owner.Variation) |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | ret := []android.Module{} |
| 281 | ctx.WalkDepsProxy(func(mod, _ android.ModuleProxy) bool { |
Spandan Das | 5c78fe9 | 2025-02-26 14:25:56 +0000 | [diff] [blame] | 282 | if variations, ok := allOwners[ctx.OtherModuleName(mod)]; ok && android.InList(ctx.OtherModuleSubDir(mod), variations) { |
Jihoon Kang | abec3ec | 2025-02-19 00:55:10 +0000 | [diff] [blame] | 283 | ret = append(ret, mod) |
| 284 | } |
| 285 | return true |
| 286 | }) |
| 287 | |
| 288 | // Remove duplicates |
| 289 | ret = android.FirstUniqueFunc(ret, func(a, b android.Module) bool { |
| 290 | return a.String() == b.String() |
| 291 | }) |
| 292 | |
| 293 | // Sort the modules by their names and variants |
| 294 | slices.SortFunc(ret, func(a, b android.Module) int { |
| 295 | return cmp.Compare(a.String(), b.String()) |
| 296 | }) |
| 297 | return ret |
| 298 | } |
| 299 | |
Cole Faust | 54124c8 | 2025-02-21 14:46:02 -0800 | [diff] [blame] | 300 | func insertBeforeExtension(file, insertion string) string { |
| 301 | ext := filepath.Ext(file) |
| 302 | return strings.TrimSuffix(file, ext) + insertion + ext |
| 303 | } |
| 304 | |
Jihoon Kang | f67b7de | 2025-02-12 01:01:09 +0000 | [diff] [blame] | 305 | func (a *androidDevice) distFiles(ctx android.ModuleContext) { |
Cole Faust | 54124c8 | 2025-02-21 14:46:02 -0800 | [diff] [blame] | 306 | if !ctx.Config().KatiEnabled() && proptools.Bool(a.deviceProps.Main_device) { |
| 307 | fsInfoMap := a.getFsInfos(ctx) |
| 308 | for _, partition := range android.SortedKeys(fsInfoMap) { |
| 309 | fsInfo := fsInfoMap[partition] |
| 310 | if fsInfo.InstalledFiles.Json != nil { |
| 311 | ctx.DistForGoal("droidcore-unbundled", fsInfo.InstalledFiles.Json) |
| 312 | } |
| 313 | if fsInfo.InstalledFiles.Txt != nil { |
| 314 | ctx.DistForGoal("droidcore-unbundled", fsInfo.InstalledFiles.Txt) |
Jihoon Kang | f67b7de | 2025-02-12 01:01:09 +0000 | [diff] [blame] | 315 | } |
| 316 | } |
Jihoon Kang | f67b7de | 2025-02-12 01:01:09 +0000 | [diff] [blame] | 317 | |
Cole Faust | 54124c8 | 2025-02-21 14:46:02 -0800 | [diff] [blame] | 318 | namePrefix := "" |
| 319 | if ctx.Config().HasDeviceProduct() { |
| 320 | namePrefix = ctx.Config().DeviceProduct() + "-" |
| 321 | } |
| 322 | ctx.DistForGoalWithFilename("droidcore-unbundled", a.proguardDictZip, namePrefix+insertBeforeExtension(a.proguardDictZip.Base(), "-FILE_NAME_TAG_PLACEHOLDER")) |
| 323 | ctx.DistForGoalWithFilename("droidcore-unbundled", a.proguardDictMapping, namePrefix+insertBeforeExtension(a.proguardDictMapping.Base(), "-FILE_NAME_TAG_PLACEHOLDER")) |
| 324 | ctx.DistForGoalWithFilename("droidcore-unbundled", a.proguardUsageZip, namePrefix+insertBeforeExtension(a.proguardUsageZip.Base(), "-FILE_NAME_TAG_PLACEHOLDER")) |
| 325 | } |
Cole Faust | 4408041 | 2024-12-20 14:17:07 -0800 | [diff] [blame] | 326 | } |
Jihoon Kang | f2c5398 | 2024-10-09 17:32:52 +0000 | [diff] [blame] | 327 | |
Yu Liu | 2a815b6 | 2025-02-21 20:46:25 +0000 | [diff] [blame] | 328 | func (a *androidDevice) MakeVars(_ android.MakeVarsModuleContext) []android.ModuleMakeVarsValue { |
Cole Faust | a472a6f | 2025-02-10 16:10:04 -0800 | [diff] [blame] | 329 | if proptools.Bool(a.deviceProps.Main_device) { |
Yu Liu | 2a815b6 | 2025-02-21 20:46:25 +0000 | [diff] [blame] | 330 | return []android.ModuleMakeVarsValue{{"SOONG_ONLY_ALL_IMAGES_ZIP", a.allImagesZip.String()}} |
Cole Faust | a472a6f | 2025-02-10 16:10:04 -0800 | [diff] [blame] | 331 | } |
Yu Liu | 2a815b6 | 2025-02-21 20:46:25 +0000 | [diff] [blame] | 332 | return nil |
Cole Faust | a472a6f | 2025-02-10 16:10:04 -0800 | [diff] [blame] | 333 | } |
| 334 | |
Cole Faust | 1dcf9e4 | 2025-02-19 17:23:34 -0800 | [diff] [blame] | 335 | func (a *androidDevice) buildProguardZips(ctx android.ModuleContext, allInstalledModules []android.Module) { |
| 336 | dictZip := android.PathForModuleOut(ctx, "proguard-dict.zip") |
| 337 | dictZipBuilder := android.NewRuleBuilder(pctx, ctx) |
| 338 | dictZipCmd := dictZipBuilder.Command().BuiltTool("soong_zip").Flag("-d").FlagWithOutput("-o ", dictZip) |
| 339 | |
| 340 | dictMapping := android.PathForModuleOut(ctx, "proguard-dict-mapping.textproto") |
| 341 | dictMappingBuilder := android.NewRuleBuilder(pctx, ctx) |
| 342 | dictMappingCmd := dictMappingBuilder.Command().BuiltTool("symbols_map").Flag("-merge").Output(dictMapping) |
| 343 | |
| 344 | protosDir := android.PathForModuleOut(ctx, "proguard_mapping_protos") |
| 345 | |
| 346 | usageZip := android.PathForModuleOut(ctx, "proguard-usage.zip") |
| 347 | usageZipBuilder := android.NewRuleBuilder(pctx, ctx) |
| 348 | usageZipCmd := usageZipBuilder.Command().BuiltTool("merge_zips").Output(usageZip) |
| 349 | |
| 350 | for _, mod := range allInstalledModules { |
| 351 | if proguardInfo, ok := android.OtherModuleProvider(ctx, mod, java.ProguardProvider); ok { |
| 352 | // Maintain these out/target/common paths for backwards compatibility. They may be able |
| 353 | // to be changed if tools look up file locations from the protobuf, but I'm not |
| 354 | // exactly sure how that works. |
| 355 | dictionaryFakePath := fmt.Sprintf("out/target/common/obj/%s/%s_intermediates/proguard_dictionary", proguardInfo.Class, proguardInfo.ModuleName) |
| 356 | dictZipCmd.FlagWithArg("-e ", dictionaryFakePath) |
| 357 | dictZipCmd.FlagWithInput("-f ", proguardInfo.ProguardDictionary) |
| 358 | dictZipCmd.Textf("-e out/target/common/obj/%s/%s_intermediates/classes.jar", proguardInfo.Class, proguardInfo.ModuleName) |
| 359 | dictZipCmd.FlagWithInput("-f ", proguardInfo.ClassesJar) |
| 360 | |
| 361 | protoFile := protosDir.Join(ctx, filepath.Dir(dictionaryFakePath), "proguard_dictionary.textproto") |
| 362 | ctx.Build(pctx, android.BuildParams{ |
| 363 | Rule: proguardDictToProto, |
| 364 | Input: proguardInfo.ProguardDictionary, |
| 365 | Output: protoFile, |
| 366 | Args: map[string]string{ |
| 367 | "location": dictionaryFakePath, |
| 368 | }, |
| 369 | }) |
| 370 | dictMappingCmd.Input(protoFile) |
| 371 | |
| 372 | usageZipCmd.Input(proguardInfo.ProguardUsageZip) |
| 373 | } |
| 374 | } |
| 375 | |
| 376 | dictZipBuilder.Build("proguard_dict_zip", "Building proguard dictionary zip") |
| 377 | dictMappingBuilder.Build("proguard_dict_mapping_proto", "Building proguard mapping proto") |
| 378 | usageZipBuilder.Build("proguard_usage_zip", "Building proguard usage zip") |
Cole Faust | 54124c8 | 2025-02-21 14:46:02 -0800 | [diff] [blame] | 379 | |
| 380 | a.proguardDictZip = dictZip |
| 381 | a.proguardDictMapping = dictMapping |
| 382 | a.proguardUsageZip = usageZip |
Cole Faust | 1dcf9e4 | 2025-02-19 17:23:34 -0800 | [diff] [blame] | 383 | } |
| 384 | |
Spandan Das | ef77574 | 2025-01-13 22:17:40 +0000 | [diff] [blame] | 385 | // Helper structs for target_files.zip creation |
Spandan Das | ef200ac | 2025-01-08 01:42:45 +0000 | [diff] [blame] | 386 | type targetFilesZipCopy struct { |
| 387 | srcModule *string |
| 388 | destSubdir string |
| 389 | } |
| 390 | |
Spandan Das | ef77574 | 2025-01-13 22:17:40 +0000 | [diff] [blame] | 391 | type targetFilesystemZipCopy struct { |
| 392 | fsInfo FilesystemInfo |
| 393 | destSubdir string |
| 394 | } |
| 395 | |
Spandan Das | dad9870 | 2025-02-26 14:32:28 +0000 | [diff] [blame] | 396 | func (a *androidDevice) buildTargetFilesZip(ctx android.ModuleContext, allInstalledModules []android.Module) { |
Cole Faust | 4408041 | 2024-12-20 14:17:07 -0800 | [diff] [blame] | 397 | targetFilesDir := android.PathForModuleOut(ctx, "target_files_dir") |
| 398 | targetFilesZip := android.PathForModuleOut(ctx, "target_files.zip") |
| 399 | |
| 400 | builder := android.NewRuleBuilder(pctx, ctx) |
| 401 | builder.Command().Textf("rm -rf %s", targetFilesDir.String()) |
| 402 | builder.Command().Textf("mkdir -p %s", targetFilesDir.String()) |
Spandan Das | ef200ac | 2025-01-08 01:42:45 +0000 | [diff] [blame] | 403 | toCopy := []targetFilesZipCopy{ |
| 404 | targetFilesZipCopy{a.partitionProps.System_partition_name, "SYSTEM"}, |
| 405 | targetFilesZipCopy{a.partitionProps.System_ext_partition_name, "SYSTEM_EXT"}, |
| 406 | targetFilesZipCopy{a.partitionProps.Product_partition_name, "PRODUCT"}, |
| 407 | targetFilesZipCopy{a.partitionProps.Vendor_partition_name, "VENDOR"}, |
| 408 | targetFilesZipCopy{a.partitionProps.Odm_partition_name, "ODM"}, |
| 409 | targetFilesZipCopy{a.partitionProps.System_dlkm_partition_name, "SYSTEM_DLKM"}, |
| 410 | targetFilesZipCopy{a.partitionProps.Vendor_dlkm_partition_name, "VENDOR_DLKM"}, |
| 411 | targetFilesZipCopy{a.partitionProps.Odm_dlkm_partition_name, "ODM_DLKM"}, |
| 412 | targetFilesZipCopy{a.partitionProps.Init_boot_partition_name, "BOOT/RAMDISK"}, |
| 413 | targetFilesZipCopy{a.partitionProps.Init_boot_partition_name, "INIT_BOOT/RAMDISK"}, |
| 414 | targetFilesZipCopy{a.partitionProps.Vendor_boot_partition_name, "VENDOR_BOOT/RAMDISK"}, |
Spandan Das | 25649f5 | 2025-01-07 18:09:22 +0000 | [diff] [blame] | 415 | } |
Spandan Das | ef200ac | 2025-01-08 01:42:45 +0000 | [diff] [blame] | 416 | |
Spandan Das | ef77574 | 2025-01-13 22:17:40 +0000 | [diff] [blame] | 417 | filesystemsToCopy := []targetFilesystemZipCopy{} |
Spandan Das | ef200ac | 2025-01-08 01:42:45 +0000 | [diff] [blame] | 418 | for _, zipCopy := range toCopy { |
| 419 | if zipCopy.srcModule == nil { |
Spandan Das | 25649f5 | 2025-01-07 18:09:22 +0000 | [diff] [blame] | 420 | continue |
| 421 | } |
Spandan Das | ef77574 | 2025-01-13 22:17:40 +0000 | [diff] [blame] | 422 | filesystemsToCopy = append( |
| 423 | filesystemsToCopy, |
| 424 | targetFilesystemZipCopy{a.getFilesystemInfo(ctx, *zipCopy.srcModule), zipCopy.destSubdir}, |
| 425 | ) |
| 426 | } |
| 427 | // Get additional filesystems from super_partition dependency |
| 428 | if a.partitionProps.Super_partition_name != nil { |
Cole Faust | 19eb09d | 2025-01-14 13:27:00 -0800 | [diff] [blame] | 429 | superPartition := ctx.GetDirectDepProxyWithTag(*a.partitionProps.Super_partition_name, superPartitionDepTag) |
Spandan Das | ef77574 | 2025-01-13 22:17:40 +0000 | [diff] [blame] | 430 | if info, ok := android.OtherModuleProvider(ctx, superPartition, SuperImageProvider); ok { |
Cole Faust | 310de66 | 2025-02-19 16:15:07 -0800 | [diff] [blame] | 431 | for _, partition := range android.SortedKeys(info.SubImageInfo) { |
Spandan Das | ef77574 | 2025-01-13 22:17:40 +0000 | [diff] [blame] | 432 | filesystemsToCopy = append( |
| 433 | filesystemsToCopy, |
| 434 | targetFilesystemZipCopy{info.SubImageInfo[partition], strings.ToUpper(partition)}, |
| 435 | ) |
| 436 | } |
| 437 | } else { |
| 438 | ctx.ModuleErrorf("Super partition %s does set SuperImageProvider\n", superPartition.Name()) |
| 439 | } |
| 440 | } |
| 441 | |
| 442 | for _, toCopy := range filesystemsToCopy { |
| 443 | rootDirString := toCopy.fsInfo.RootDir.String() |
| 444 | if toCopy.destSubdir == "SYSTEM" { |
Spandan Das | ef200ac | 2025-01-08 01:42:45 +0000 | [diff] [blame] | 445 | rootDirString = rootDirString + "/system" |
| 446 | } |
Spandan Das | ef77574 | 2025-01-13 22:17:40 +0000 | [diff] [blame] | 447 | builder.Command().Textf("mkdir -p %s/%s", targetFilesDir.String(), toCopy.destSubdir) |
Cole Faust | 4408041 | 2024-12-20 14:17:07 -0800 | [diff] [blame] | 448 | builder.Command(). |
| 449 | BuiltTool("acp"). |
Spandan Das | ef77574 | 2025-01-13 22:17:40 +0000 | [diff] [blame] | 450 | Textf("-rd %s/. %s/%s", rootDirString, targetFilesDir, toCopy.destSubdir). |
| 451 | Implicit(toCopy.fsInfo.Output) // so that the staging dir is built |
Cole Faust | b36763e | 2025-02-18 15:21:44 -0800 | [diff] [blame] | 452 | for _, extraRootDir := range toCopy.fsInfo.ExtraRootDirs { |
| 453 | builder.Command(). |
| 454 | BuiltTool("acp"). |
| 455 | Textf("-rd %s/. %s/%s", extraRootDir, targetFilesDir, toCopy.destSubdir). |
| 456 | Implicit(toCopy.fsInfo.Output) // so that the staging dir is built |
| 457 | } |
Spandan Das | ef200ac | 2025-01-08 01:42:45 +0000 | [diff] [blame] | 458 | |
Spandan Das | ef77574 | 2025-01-13 22:17:40 +0000 | [diff] [blame] | 459 | if toCopy.destSubdir == "SYSTEM" { |
Spandan Das | 3ec6d06 | 2025-01-09 19:37:47 +0000 | [diff] [blame] | 460 | // Create the ROOT partition in target_files.zip |
Spandan Das | ef77574 | 2025-01-13 22:17:40 +0000 | [diff] [blame] | 461 | builder.Command().Textf("rsync --links --exclude=system/* %s/ -r %s/ROOT", toCopy.fsInfo.RootDir, targetFilesDir.String()) |
Spandan Das | 3ec6d06 | 2025-01-09 19:37:47 +0000 | [diff] [blame] | 462 | } |
Cole Faust | 4408041 | 2024-12-20 14:17:07 -0800 | [diff] [blame] | 463 | } |
Spandan Das | 9b17df2 | 2025-01-08 23:30:45 +0000 | [diff] [blame] | 464 | // Copy cmdline, kernel etc. files of boot images |
Spandan Das | 258c08f | 2025-01-08 23:30:45 +0000 | [diff] [blame] | 465 | if a.partitionProps.Vendor_boot_partition_name != nil { |
Cole Faust | 19eb09d | 2025-01-14 13:27:00 -0800 | [diff] [blame] | 466 | bootImg := ctx.GetDirectDepProxyWithTag(proptools.String(a.partitionProps.Vendor_boot_partition_name), filesystemDepTag) |
Spandan Das | 258c08f | 2025-01-08 23:30:45 +0000 | [diff] [blame] | 467 | bootImgInfo, _ := android.OtherModuleProvider(ctx, bootImg, BootimgInfoProvider) |
Spandan Das | 9b17df2 | 2025-01-08 23:30:45 +0000 | [diff] [blame] | 468 | builder.Command().Textf("echo %s > %s/VENDOR_BOOT/cmdline", proptools.ShellEscape(strings.Join(bootImgInfo.Cmdline, " ")), targetFilesDir) |
| 469 | builder.Command().Textf("echo %s > %s/VENDOR_BOOT/vendor_cmdline", proptools.ShellEscape(strings.Join(bootImgInfo.Cmdline, " ")), targetFilesDir) |
| 470 | if bootImgInfo.Dtb != nil { |
Spandan Das | fed3d04 | 2025-01-13 21:38:47 +0000 | [diff] [blame] | 471 | builder.Command().Textf("cp ").Input(bootImgInfo.Dtb).Textf(" %s/VENDOR_BOOT/dtb", targetFilesDir) |
Spandan Das | 9b17df2 | 2025-01-08 23:30:45 +0000 | [diff] [blame] | 472 | } |
Spandan Das | 2351137 | 2025-01-08 23:30:45 +0000 | [diff] [blame] | 473 | if bootImgInfo.Bootconfig != nil { |
Spandan Das | fed3d04 | 2025-01-13 21:38:47 +0000 | [diff] [blame] | 474 | builder.Command().Textf("cp ").Input(bootImgInfo.Bootconfig).Textf(" %s/VENDOR_BOOT/vendor_bootconfig", targetFilesDir) |
Spandan Das | 2351137 | 2025-01-08 23:30:45 +0000 | [diff] [blame] | 475 | } |
Spandan Das | 258c08f | 2025-01-08 23:30:45 +0000 | [diff] [blame] | 476 | } |
| 477 | if a.partitionProps.Boot_partition_name != nil { |
Cole Faust | 19eb09d | 2025-01-14 13:27:00 -0800 | [diff] [blame] | 478 | bootImg := ctx.GetDirectDepProxyWithTag(proptools.String(a.partitionProps.Boot_partition_name), filesystemDepTag) |
Spandan Das | 258c08f | 2025-01-08 23:30:45 +0000 | [diff] [blame] | 479 | bootImgInfo, _ := android.OtherModuleProvider(ctx, bootImg, BootimgInfoProvider) |
Spandan Das | 9b17df2 | 2025-01-08 23:30:45 +0000 | [diff] [blame] | 480 | builder.Command().Textf("echo %s > %s/BOOT/cmdline", proptools.ShellEscape(strings.Join(bootImgInfo.Cmdline, " ")), targetFilesDir) |
| 481 | if bootImgInfo.Dtb != nil { |
Spandan Das | fed3d04 | 2025-01-13 21:38:47 +0000 | [diff] [blame] | 482 | builder.Command().Textf("cp ").Input(bootImgInfo.Dtb).Textf(" %s/BOOT/dtb", targetFilesDir) |
Spandan Das | 9b17df2 | 2025-01-08 23:30:45 +0000 | [diff] [blame] | 483 | } |
| 484 | if bootImgInfo.Kernel != nil { |
Spandan Das | fed3d04 | 2025-01-13 21:38:47 +0000 | [diff] [blame] | 485 | builder.Command().Textf("cp ").Input(bootImgInfo.Kernel).Textf(" %s/BOOT/kernel", targetFilesDir) |
Spandan Das | 9b17df2 | 2025-01-08 23:30:45 +0000 | [diff] [blame] | 486 | // Even though kernel is not used to build vendor_boot, copy the kernel to VENDOR_BOOT to match the behavior of make packaging. |
Spandan Das | fed3d04 | 2025-01-13 21:38:47 +0000 | [diff] [blame] | 487 | builder.Command().Textf("cp ").Input(bootImgInfo.Kernel).Textf(" %s/VENDOR_BOOT/kernel", targetFilesDir) |
Spandan Das | 9b17df2 | 2025-01-08 23:30:45 +0000 | [diff] [blame] | 488 | } |
Spandan Das | 2351137 | 2025-01-08 23:30:45 +0000 | [diff] [blame] | 489 | if bootImgInfo.Bootconfig != nil { |
Spandan Das | fed3d04 | 2025-01-13 21:38:47 +0000 | [diff] [blame] | 490 | builder.Command().Textf("cp ").Input(bootImgInfo.Bootconfig).Textf(" %s/BOOT/bootconfig", targetFilesDir) |
Spandan Das | 2351137 | 2025-01-08 23:30:45 +0000 | [diff] [blame] | 491 | } |
Spandan Das | 258c08f | 2025-01-08 23:30:45 +0000 | [diff] [blame] | 492 | } |
| 493 | |
Spandan Das | e51ff95 | 2025-01-09 18:11:59 +0000 | [diff] [blame] | 494 | if a.deviceProps.Android_info != nil { |
| 495 | builder.Command().Textf("mkdir -p %s/OTA", targetFilesDir) |
Cole Faust | 11fda33 | 2025-01-14 16:47:19 -0800 | [diff] [blame] | 496 | builder.Command().Textf("cp ").Input(android.PathForModuleSrc(ctx, *a.deviceProps.Android_info)).Textf(" %s/OTA/android-info.txt", targetFilesDir) |
Spandan Das | e51ff95 | 2025-01-09 18:11:59 +0000 | [diff] [blame] | 497 | } |
| 498 | |
Spandan Das | 0036fa3 | 2025-01-10 23:40:45 +0000 | [diff] [blame] | 499 | a.copyImagesToTargetZip(ctx, builder, targetFilesDir) |
Spandan Das | dad9870 | 2025-02-26 14:32:28 +0000 | [diff] [blame] | 500 | a.copyMetadataToTargetZip(ctx, builder, targetFilesDir, allInstalledModules) |
Spandan Das | 0036fa3 | 2025-01-10 23:40:45 +0000 | [diff] [blame] | 501 | |
Cole Faust | 4408041 | 2024-12-20 14:17:07 -0800 | [diff] [blame] | 502 | builder.Command(). |
| 503 | BuiltTool("soong_zip"). |
| 504 | Text("-d"). |
| 505 | FlagWithOutput("-o ", targetFilesZip). |
| 506 | FlagWithArg("-C ", targetFilesDir.String()). |
| 507 | FlagWithArg("-D ", targetFilesDir.String()). |
| 508 | Text("-sha256") |
| 509 | builder.Build("target_files_"+ctx.ModuleName(), "Build target_files.zip") |
| 510 | } |
| 511 | |
Spandan Das | 0036fa3 | 2025-01-10 23:40:45 +0000 | [diff] [blame] | 512 | func (a *androidDevice) copyImagesToTargetZip(ctx android.ModuleContext, builder *android.RuleBuilder, targetFilesDir android.WritablePath) { |
| 513 | // Create an IMAGES/ subdirectory |
| 514 | builder.Command().Textf("mkdir -p %s/IMAGES", targetFilesDir.String()) |
| 515 | if a.deviceProps.Bootloader != nil { |
| 516 | builder.Command().Textf("cp ").Input(android.PathForModuleSrc(ctx, proptools.String(a.deviceProps.Bootloader))).Textf(" %s/IMAGES/bootloader", targetFilesDir.String()) |
| 517 | } |
| 518 | // Copy the filesystem ,boot and vbmeta img files to IMAGES/ |
| 519 | ctx.VisitDirectDepsProxyWithTag(filesystemDepTag, func(child android.ModuleProxy) { |
Spandan Das | a9db76d | 2025-01-14 01:34:43 +0000 | [diff] [blame] | 520 | if strings.Contains(child.Name(), "recovery") { |
| 521 | return // skip recovery.img to match the make packaging behavior |
| 522 | } |
Spandan Das | ef77574 | 2025-01-13 22:17:40 +0000 | [diff] [blame] | 523 | if info, ok := android.OtherModuleProvider(ctx, child, BootimgInfoProvider); ok { |
| 524 | // Check Boot img first so that the boot.img is copied and not its dep ramdisk.img |
Spandan Das | 0036fa3 | 2025-01-10 23:40:45 +0000 | [diff] [blame] | 525 | builder.Command().Textf("cp ").Input(info.Output).Textf(" %s/IMAGES/", targetFilesDir.String()) |
Spandan Das | ef77574 | 2025-01-13 22:17:40 +0000 | [diff] [blame] | 526 | } else if info, ok := android.OtherModuleProvider(ctx, child, FilesystemProvider); ok { |
Spandan Das | 0036fa3 | 2025-01-10 23:40:45 +0000 | [diff] [blame] | 527 | builder.Command().Textf("cp ").Input(info.Output).Textf(" %s/IMAGES/", targetFilesDir.String()) |
| 528 | } else if info, ok := android.OtherModuleProvider(ctx, child, vbmetaPartitionProvider); ok { |
| 529 | builder.Command().Textf("cp ").Input(info.Output).Textf(" %s/IMAGES/", targetFilesDir.String()) |
| 530 | } else { |
| 531 | ctx.ModuleErrorf("Module %s does not provide an .img file output for target_files.zip", child.Name()) |
| 532 | } |
| 533 | }) |
Spandan Das | ef77574 | 2025-01-13 22:17:40 +0000 | [diff] [blame] | 534 | |
| 535 | if a.partitionProps.Super_partition_name != nil { |
Cole Faust | 19eb09d | 2025-01-14 13:27:00 -0800 | [diff] [blame] | 536 | superPartition := ctx.GetDirectDepProxyWithTag(*a.partitionProps.Super_partition_name, superPartitionDepTag) |
Spandan Das | ef77574 | 2025-01-13 22:17:40 +0000 | [diff] [blame] | 537 | if info, ok := android.OtherModuleProvider(ctx, superPartition, SuperImageProvider); ok { |
Cole Faust | 19eb09d | 2025-01-14 13:27:00 -0800 | [diff] [blame] | 538 | for _, partition := range android.SortedKeys(info.SubImageInfo) { |
Spandan Das | 7a42d1c | 2025-02-12 01:32:21 +0000 | [diff] [blame] | 539 | if info.SubImageInfo[partition].OutputHermetic != nil { |
| 540 | builder.Command().Textf("cp ").Input(info.SubImageInfo[partition].OutputHermetic).Textf(" %s/IMAGES/", targetFilesDir.String()) |
| 541 | } |
| 542 | if info.SubImageInfo[partition].MapFile != nil { |
| 543 | builder.Command().Textf("cp ").Input(info.SubImageInfo[partition].MapFile).Textf(" %s/IMAGES/", targetFilesDir.String()) |
| 544 | } |
Spandan Das | ef77574 | 2025-01-13 22:17:40 +0000 | [diff] [blame] | 545 | } |
| 546 | } else { |
| 547 | ctx.ModuleErrorf("Super partition %s does set SuperImageProvider\n", superPartition.Name()) |
| 548 | } |
| 549 | } |
Spandan Das | 0036fa3 | 2025-01-10 23:40:45 +0000 | [diff] [blame] | 550 | } |
| 551 | |
Spandan Das | dad9870 | 2025-02-26 14:32:28 +0000 | [diff] [blame] | 552 | func (a *androidDevice) copyMetadataToTargetZip(ctx android.ModuleContext, builder *android.RuleBuilder, targetFilesDir android.WritablePath, allInstalledModules []android.Module) { |
Spandan Das | 29d4488 | 2025-01-15 21:12:36 +0000 | [diff] [blame] | 553 | // Create a META/ subdirectory |
| 554 | builder.Command().Textf("mkdir -p %s/META", targetFilesDir.String()) |
| 555 | if proptools.Bool(a.deviceProps.Ab_ota_updater) { |
| 556 | ctx.VisitDirectDepsProxyWithTag(targetFilesMetadataDepTag, func(child android.ModuleProxy) { |
| 557 | info, _ := android.OtherModuleProvider(ctx, child, android.OutputFilesProvider) |
| 558 | builder.Command().Textf("cp").Inputs(info.DefaultOutputFiles).Textf(" %s/META/", targetFilesDir.String()) |
| 559 | }) |
Spandan Das | b5f40cf | 2025-02-12 19:36:03 +0000 | [diff] [blame] | 560 | builder.Command().Textf("cp").Input(android.PathForSource(ctx, "external/zucchini/version_info.h")).Textf(" %s/META/zucchini_config.txt", targetFilesDir.String()) |
| 561 | builder.Command().Textf("cp").Input(android.PathForSource(ctx, "system/update_engine/update_engine.conf")).Textf(" %s/META/update_engine_config.txt", targetFilesDir.String()) |
| 562 | if a.getFsInfos(ctx)["system"].ErofsCompressHints != nil { |
| 563 | builder.Command().Textf("cp").Input(a.getFsInfos(ctx)["system"].ErofsCompressHints).Textf(" %s/META/erofs_default_compress_hints.txt", targetFilesDir.String()) |
| 564 | } |
| 565 | // ab_partitions.txt |
| 566 | abPartitionsSorted := android.SortedUniqueStrings(a.deviceProps.Ab_ota_partitions) |
| 567 | abPartitionsSortedString := proptools.ShellEscape(strings.Join(abPartitionsSorted, "\\n")) |
| 568 | builder.Command().Textf("echo -e").Flag(abPartitionsSortedString).Textf(" > %s/META/ab_partitions.txt", targetFilesDir.String()) |
Spandan Das | 35b7874 | 2025-02-12 19:36:03 +0000 | [diff] [blame] | 569 | // otakeys.txt |
| 570 | abOtaKeysSorted := android.SortedUniqueStrings(a.deviceProps.Ab_ota_keys) |
| 571 | abOtaKeysSortedString := proptools.ShellEscape(strings.Join(abOtaKeysSorted, "\\n")) |
| 572 | builder.Command().Textf("echo -e").Flag(abOtaKeysSortedString).Textf(" > %s/META/otakeys.txt", targetFilesDir.String()) |
Spandan Das | 0094807 | 2025-02-12 19:36:03 +0000 | [diff] [blame] | 573 | // postinstall_config.txt |
| 574 | abOtaPostInstallConfigString := proptools.ShellEscape(strings.Join(a.deviceProps.Ab_ota_postinstall_config, "\\n")) |
| 575 | builder.Command().Textf("echo -e").Flag(abOtaPostInstallConfigString).Textf(" > %s/META/postinstall_config.txt", targetFilesDir.String()) |
Spandan Das | f12ff9b | 2025-02-12 22:27:43 +0000 | [diff] [blame] | 576 | // selinuxfc |
| 577 | if a.getFsInfos(ctx)["system"].SelinuxFc != nil { |
| 578 | builder.Command().Textf("cp").Input(a.getFsInfos(ctx)["system"].SelinuxFc).Textf(" %s/META/file_contexts.bin", targetFilesDir.String()) |
| 579 | } |
Spandan Das | d71af18 | 2025-02-12 18:03:29 +0000 | [diff] [blame] | 580 | } |
Spandan Das | dd262fb | 2025-02-13 00:15:59 +0000 | [diff] [blame] | 581 | // Copy $partition_filesystem_config.txt |
| 582 | fsInfos := a.getFsInfos(ctx) |
| 583 | for _, partition := range android.SortedKeys(fsInfos) { |
| 584 | if fsInfos[partition].FilesystemConfig == nil { |
| 585 | continue |
| 586 | } |
| 587 | if android.InList(partition, []string{"userdata"}) { |
| 588 | continue |
| 589 | } |
| 590 | builder.Command().Textf("cp").Input(fsInfos[partition].FilesystemConfig).Textf(" %s/META/%s", targetFilesDir.String(), a.filesystemConfigNameForTargetFiles(partition)) |
| 591 | } |
Spandan Das | 75955b1 | 2025-02-13 22:12:52 +0000 | [diff] [blame] | 592 | // Copy ramdisk_node_list |
Spandan Das | 37240d9 | 2025-02-14 00:18:41 +0000 | [diff] [blame] | 593 | if ramdiskNodeList := android.PathForModuleSrc(ctx, proptools.String(a.deviceProps.Ramdisk_node_list)); ramdiskNodeList != nil { |
| 594 | builder.Command().Textf("cp").Input(ramdiskNodeList).Textf(" %s/META/", targetFilesDir.String()) |
| 595 | } |
| 596 | // Copy releasetools.py |
| 597 | if releaseTools := android.PathForModuleSrc(ctx, proptools.String(a.deviceProps.Releasetools_extension)); releaseTools != nil { |
| 598 | builder.Command().Textf("cp").Input(releaseTools).Textf(" %s/META/", targetFilesDir.String()) |
| 599 | } |
Spandan Das | dad9870 | 2025-02-26 14:32:28 +0000 | [diff] [blame] | 600 | // apexkeys.txt |
| 601 | var installedApexKeys []android.Path |
| 602 | for _, installedModule := range allInstalledModules { |
| 603 | if info, ok := android.OtherModuleProvider(ctx, installedModule, ApexKeyPathInfoProvider); ok { |
| 604 | installedApexKeys = append(installedApexKeys, info.ApexKeyPath) |
| 605 | } |
| 606 | } |
| 607 | installedApexKeys = android.SortedUniquePaths(installedApexKeys) // Sort by keypath to match make |
| 608 | builder.Command().Text("cat").Inputs(installedApexKeys).Textf(" >> %s/META/apexkeys.txt", targetFilesDir.String()) |
| 609 | |
Spandan Das | dd262fb | 2025-02-13 00:15:59 +0000 | [diff] [blame] | 610 | } |
| 611 | |
Spandan Das | dad9870 | 2025-02-26 14:32:28 +0000 | [diff] [blame] | 612 | type ApexKeyPathInfo struct { |
| 613 | ApexKeyPath android.Path |
| 614 | } |
| 615 | |
| 616 | var ApexKeyPathInfoProvider = blueprint.NewProvider[ApexKeyPathInfo]() |
| 617 | |
Spandan Das | dd262fb | 2025-02-13 00:15:59 +0000 | [diff] [blame] | 618 | // Filenames for the partition specific fs_config files. |
| 619 | // Hardcode the ramdisk files to their boot image prefix |
| 620 | func (a *androidDevice) filesystemConfigNameForTargetFiles(partition string) string { |
| 621 | name := partition + "_filesystem_config.txt" |
| 622 | if partition == "system" { |
| 623 | name = "filesystem_config.txt" |
| 624 | } else if partition == "ramdisk" { |
| 625 | name = "init_boot_filesystem_config.txt" |
| 626 | } |
| 627 | return name |
Spandan Das | 29d4488 | 2025-01-15 21:12:36 +0000 | [diff] [blame] | 628 | } |
| 629 | |
Cole Faust | 4408041 | 2024-12-20 14:17:07 -0800 | [diff] [blame] | 630 | func (a *androidDevice) getFilesystemInfo(ctx android.ModuleContext, depName string) FilesystemInfo { |
Cole Faust | 19eb09d | 2025-01-14 13:27:00 -0800 | [diff] [blame] | 631 | fsMod := ctx.GetDirectDepProxyWithTag(depName, filesystemDepTag) |
Cole Faust | 4408041 | 2024-12-20 14:17:07 -0800 | [diff] [blame] | 632 | fsInfo, ok := android.OtherModuleProvider(ctx, fsMod, FilesystemProvider) |
| 633 | if !ok { |
| 634 | ctx.ModuleErrorf("Expected dependency %s to be a filesystem", depName) |
| 635 | } |
| 636 | return fsInfo |
Jihoon Kang | f2c5398 | 2024-10-09 17:32:52 +0000 | [diff] [blame] | 637 | } |
Jihoon Kang | 0a6315b | 2025-01-30 01:14:49 +0000 | [diff] [blame] | 638 | |
| 639 | func (a *androidDevice) setVbmetaPhonyTargets(ctx android.ModuleContext) { |
| 640 | if !proptools.Bool(a.deviceProps.Main_device) { |
| 641 | return |
| 642 | } |
| 643 | |
| 644 | if !ctx.Config().KatiEnabled() { |
| 645 | for _, vbmetaPartitionName := range a.partitionProps.Vbmeta_partitions { |
| 646 | img := ctx.GetDirectDepProxyWithTag(vbmetaPartitionName, filesystemDepTag) |
| 647 | if provider, ok := android.OtherModuleProvider(ctx, img, vbmetaPartitionProvider); ok { |
| 648 | // make generates `vbmetasystemimage` phony target instead of `vbmeta_systemimage` phony target. |
| 649 | partitionName := strings.ReplaceAll(provider.Name, "_", "") |
| 650 | ctx.Phony(fmt.Sprintf("%simage", partitionName), provider.Output) |
| 651 | } |
| 652 | } |
| 653 | } |
| 654 | } |