Jihoon Kang | add2bb2 | 2024-11-05 22:29:34 +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 fsgen |
| 16 | |
| 17 | import ( |
| 18 | "android/soong/android" |
| 19 | "android/soong/etc" |
| 20 | "fmt" |
| 21 | "path/filepath" |
| 22 | "strings" |
| 23 | |
| 24 | "github.com/google/blueprint/proptools" |
| 25 | ) |
| 26 | |
| 27 | type srcBaseFileInstallBaseFileTuple struct { |
| 28 | srcBaseFile string |
| 29 | installBaseFile string |
| 30 | } |
| 31 | |
| 32 | // prebuilt src files grouped by the install partitions. |
| 33 | // Each groups are a mapping of the relative install path to the name of the files |
| 34 | type prebuiltSrcGroupByInstallPartition struct { |
| 35 | system map[string][]srcBaseFileInstallBaseFileTuple |
| 36 | system_ext map[string][]srcBaseFileInstallBaseFileTuple |
| 37 | product map[string][]srcBaseFileInstallBaseFileTuple |
| 38 | vendor map[string][]srcBaseFileInstallBaseFileTuple |
Jihoon Kang | d40d90f | 2024-12-02 19:10:37 +0000 | [diff] [blame] | 39 | recovery map[string][]srcBaseFileInstallBaseFileTuple |
Jihoon Kang | add2bb2 | 2024-11-05 22:29:34 +0000 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | func newPrebuiltSrcGroupByInstallPartition() *prebuiltSrcGroupByInstallPartition { |
| 43 | return &prebuiltSrcGroupByInstallPartition{ |
| 44 | system: map[string][]srcBaseFileInstallBaseFileTuple{}, |
| 45 | system_ext: map[string][]srcBaseFileInstallBaseFileTuple{}, |
| 46 | product: map[string][]srcBaseFileInstallBaseFileTuple{}, |
| 47 | vendor: map[string][]srcBaseFileInstallBaseFileTuple{}, |
Jihoon Kang | d40d90f | 2024-12-02 19:10:37 +0000 | [diff] [blame] | 48 | recovery: map[string][]srcBaseFileInstallBaseFileTuple{}, |
Jihoon Kang | add2bb2 | 2024-11-05 22:29:34 +0000 | [diff] [blame] | 49 | } |
| 50 | } |
| 51 | |
| 52 | func isSubdirectory(parent, child string) bool { |
| 53 | rel, err := filepath.Rel(parent, child) |
| 54 | if err != nil { |
| 55 | return false |
| 56 | } |
| 57 | return !strings.HasPrefix(rel, "..") |
| 58 | } |
| 59 | |
| 60 | func appendIfCorrectInstallPartition(partitionToInstallPathList []partitionToInstallPath, destPath, srcPath string, srcGroup *prebuiltSrcGroupByInstallPartition) { |
| 61 | for _, part := range partitionToInstallPathList { |
| 62 | partition := part.name |
| 63 | installPath := part.installPath |
| 64 | |
| 65 | if isSubdirectory(installPath, destPath) { |
| 66 | relativeInstallPath, _ := filepath.Rel(installPath, destPath) |
| 67 | relativeInstallDir := filepath.Dir(relativeInstallPath) |
| 68 | var srcMap map[string][]srcBaseFileInstallBaseFileTuple |
| 69 | switch partition { |
| 70 | case "system": |
| 71 | srcMap = srcGroup.system |
| 72 | case "system_ext": |
| 73 | srcMap = srcGroup.system_ext |
| 74 | case "product": |
| 75 | srcMap = srcGroup.product |
| 76 | case "vendor": |
| 77 | srcMap = srcGroup.vendor |
Jihoon Kang | d40d90f | 2024-12-02 19:10:37 +0000 | [diff] [blame] | 78 | case "recovery": |
| 79 | srcMap = srcGroup.recovery |
Jihoon Kang | add2bb2 | 2024-11-05 22:29:34 +0000 | [diff] [blame] | 80 | } |
| 81 | if srcMap != nil { |
| 82 | srcMap[relativeInstallDir] = append(srcMap[relativeInstallDir], srcBaseFileInstallBaseFileTuple{ |
| 83 | srcBaseFile: filepath.Base(srcPath), |
| 84 | installBaseFile: filepath.Base(destPath), |
| 85 | }) |
| 86 | } |
| 87 | return |
| 88 | } |
| 89 | } |
| 90 | } |
| 91 | |
Jihoon Kang | 3a8759c | 2024-11-08 19:35:09 +0000 | [diff] [blame] | 92 | // Create a map of source files to the list of destination files from PRODUCT_COPY_FILES entries. |
| 93 | // Note that the value of the map is a list of string, given that a single source file can be |
| 94 | // copied to multiple files. |
| 95 | // This function also checks the existence of the source files, and validates that there is no |
| 96 | // multiple source files copying to the same dest file. |
| 97 | func uniqueExistingProductCopyFileMap(ctx android.LoadHookContext) map[string][]string { |
Jihoon Kang | add2bb2 | 2024-11-05 22:29:34 +0000 | [diff] [blame] | 98 | seen := make(map[string]bool) |
Jihoon Kang | 3a8759c | 2024-11-08 19:35:09 +0000 | [diff] [blame] | 99 | filtered := make(map[string][]string) |
Jihoon Kang | add2bb2 | 2024-11-05 22:29:34 +0000 | [diff] [blame] | 100 | |
Jihoon Kang | 3a8759c | 2024-11-08 19:35:09 +0000 | [diff] [blame] | 101 | for _, copyFilePair := range ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse.ProductCopyFiles { |
| 102 | srcDestList := strings.Split(copyFilePair, ":") |
| 103 | if len(srcDestList) < 2 { |
| 104 | ctx.ModuleErrorf("PRODUCT_COPY_FILES must follow the format \"src:dest\", got: %s", copyFilePair) |
| 105 | } |
| 106 | src, dest := srcDestList[0], srcDestList[1] |
Jihoon Kang | f27c3a5 | 2024-11-12 21:27:09 +0000 | [diff] [blame] | 107 | |
| 108 | // Some downstream branches use absolute path as entries in PRODUCT_COPY_FILES. |
| 109 | // Convert them to relative path from top and check if they do not escape the tree root. |
| 110 | relSrc := android.ToRelativeSourcePath(ctx, src) |
| 111 | |
Jihoon Kang | add2bb2 | 2024-11-05 22:29:34 +0000 | [diff] [blame] | 112 | if _, ok := seen[dest]; !ok { |
Jihoon Kang | f27c3a5 | 2024-11-12 21:27:09 +0000 | [diff] [blame] | 113 | if optionalPath := android.ExistentPathForSource(ctx, relSrc); optionalPath.Valid() { |
Jihoon Kang | add2bb2 | 2024-11-05 22:29:34 +0000 | [diff] [blame] | 114 | seen[dest] = true |
Jihoon Kang | f27c3a5 | 2024-11-12 21:27:09 +0000 | [diff] [blame] | 115 | filtered[relSrc] = append(filtered[relSrc], dest) |
Jihoon Kang | add2bb2 | 2024-11-05 22:29:34 +0000 | [diff] [blame] | 116 | } |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | return filtered |
| 121 | } |
| 122 | |
| 123 | type partitionToInstallPath struct { |
| 124 | name string |
| 125 | installPath string |
| 126 | } |
| 127 | |
| 128 | func processProductCopyFiles(ctx android.LoadHookContext) map[string]*prebuiltSrcGroupByInstallPartition { |
| 129 | // Filter out duplicate dest entries and non existing src entries |
| 130 | productCopyFileMap := uniqueExistingProductCopyFileMap(ctx) |
| 131 | |
| 132 | // System is intentionally added at the last to consider the scenarios where |
| 133 | // non-system partitions are installed as part of the system partition |
| 134 | partitionToInstallPathList := []partitionToInstallPath{ |
Jihoon Kang | d40d90f | 2024-12-02 19:10:37 +0000 | [diff] [blame] | 135 | {name: "recovery", installPath: "recovery/root"}, |
Jihoon Kang | add2bb2 | 2024-11-05 22:29:34 +0000 | [diff] [blame] | 136 | {name: "vendor", installPath: ctx.DeviceConfig().VendorPath()}, |
| 137 | {name: "product", installPath: ctx.DeviceConfig().ProductPath()}, |
| 138 | {name: "system_ext", installPath: ctx.DeviceConfig().SystemExtPath()}, |
| 139 | {name: "system", installPath: "system"}, |
| 140 | } |
| 141 | |
| 142 | groupedSources := map[string]*prebuiltSrcGroupByInstallPartition{} |
| 143 | for _, src := range android.SortedKeys(productCopyFileMap) { |
Jihoon Kang | 3a8759c | 2024-11-08 19:35:09 +0000 | [diff] [blame] | 144 | destFiles := productCopyFileMap[src] |
Jihoon Kang | add2bb2 | 2024-11-05 22:29:34 +0000 | [diff] [blame] | 145 | srcFileDir := filepath.Dir(src) |
| 146 | if _, ok := groupedSources[srcFileDir]; !ok { |
| 147 | groupedSources[srcFileDir] = newPrebuiltSrcGroupByInstallPartition() |
| 148 | } |
Jihoon Kang | 3a8759c | 2024-11-08 19:35:09 +0000 | [diff] [blame] | 149 | for _, dest := range destFiles { |
| 150 | appendIfCorrectInstallPartition(partitionToInstallPathList, dest, filepath.Base(src), groupedSources[srcFileDir]) |
| 151 | } |
Jihoon Kang | add2bb2 | 2024-11-05 22:29:34 +0000 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | return groupedSources |
| 155 | } |
| 156 | |
| 157 | type prebuiltModuleProperties struct { |
| 158 | Name *string |
| 159 | |
| 160 | Soc_specific *bool |
| 161 | Product_specific *bool |
| 162 | System_ext_specific *bool |
Jihoon Kang | d40d90f | 2024-12-02 19:10:37 +0000 | [diff] [blame] | 163 | Recovery *bool |
| 164 | Ramdisk *bool |
Jihoon Kang | add2bb2 | 2024-11-05 22:29:34 +0000 | [diff] [blame] | 165 | |
| 166 | Srcs []string |
Jihoon Kang | add2bb2 | 2024-11-05 22:29:34 +0000 | [diff] [blame] | 167 | |
| 168 | No_full_install *bool |
| 169 | |
| 170 | NamespaceExportedToMake bool |
| 171 | |
| 172 | Visibility []string |
| 173 | } |
| 174 | |
| 175 | // Split relative_install_path to a separate struct, because it is not supported for every |
| 176 | // modules listed in [etcInstallPathToFactoryMap] |
| 177 | type prebuiltSubdirProperties struct { |
| 178 | // If the base file name of the src and dst all match, dsts property does not need to be |
| 179 | // set, and only relative_install_path can be set. |
| 180 | Relative_install_path *string |
| 181 | } |
| 182 | |
Jihoon Kang | d40d90f | 2024-12-02 19:10:37 +0000 | [diff] [blame] | 183 | // Split install_in_root to a separate struct as it is part of rootProperties instead of |
| 184 | // properties |
| 185 | type prebuiltInstallInRootProperties struct { |
| 186 | Install_in_root *bool |
| 187 | } |
| 188 | |
Jihoon Kang | add2bb2 | 2024-11-05 22:29:34 +0000 | [diff] [blame] | 189 | var ( |
| 190 | etcInstallPathToFactoryList = map[string]android.ModuleFactory{ |
Jihoon Kang | 320ca7c | 2024-12-03 18:14:50 +0000 | [diff] [blame] | 191 | "": etc.PrebuiltRootFactory, |
| 192 | "avb": etc.PrebuiltAvbFactory, |
| 193 | "bin": etc.PrebuiltBinaryFactory, |
| 194 | "bt_firmware": etc.PrebuiltBtFirmwareFactory, |
| 195 | "cacerts": etc.PrebuiltEtcCaCertsFactory, |
| 196 | "dsp": etc.PrebuiltDSPFactory, |
| 197 | "etc": etc.PrebuiltEtcFactory, |
| 198 | "etc/dsp": etc.PrebuiltDSPFactory, |
| 199 | "etc/firmware": etc.PrebuiltFirmwareFactory, |
| 200 | "firmware": etc.PrebuiltFirmwareFactory, |
| 201 | "first_stage_ramdisk": etc.PrebuiltFirstStageRamdiskFactory, |
| 202 | "fonts": etc.PrebuiltFontFactory, |
| 203 | "framework": etc.PrebuiltFrameworkFactory, |
| 204 | "lib": etc.PrebuiltRenderScriptBitcodeFactory, |
| 205 | "lib64": etc.PrebuiltRenderScriptBitcodeFactory, |
| 206 | "lib/rfsa": etc.PrebuiltRFSAFactory, |
| 207 | "media": etc.PrebuiltMediaFactory, |
| 208 | "odm": etc.PrebuiltOdmFactory, |
| 209 | "optee": etc.PrebuiltOpteeFactory, |
| 210 | "overlay": etc.PrebuiltOverlayFactory, |
| 211 | "priv-app": etc.PrebuiltPrivAppFactory, |
| 212 | "sbin": etc.PrebuiltSbinFactory, |
| 213 | "system": etc.PrebuiltSystemFactory, |
| 214 | "res": etc.PrebuiltResFactory, |
| 215 | "rfs": etc.PrebuiltRfsFactory, |
| 216 | "tts": etc.PrebuiltVoicepackFactory, |
| 217 | "tvconfig": etc.PrebuiltTvConfigFactory, |
| 218 | "tvservice": etc.PrebuiltTvServiceFactory, |
| 219 | "usr/share": etc.PrebuiltUserShareFactory, |
| 220 | "usr/hyphen-data": etc.PrebuiltUserHyphenDataFactory, |
| 221 | "usr/keylayout": etc.PrebuiltUserKeyLayoutFactory, |
| 222 | "usr/keychars": etc.PrebuiltUserKeyCharsFactory, |
| 223 | "usr/srec": etc.PrebuiltUserSrecFactory, |
| 224 | "usr/idc": etc.PrebuiltUserIdcFactory, |
| 225 | "vendor": etc.PrebuiltVendorFactory, |
| 226 | "vendor_dlkm": etc.PrebuiltVendorDlkmFactory, |
| 227 | "wallpaper": etc.PrebuiltWallpaperFactory, |
| 228 | "wlc_upt": etc.PrebuiltWlcUptFactory, |
Jihoon Kang | add2bb2 | 2024-11-05 22:29:34 +0000 | [diff] [blame] | 229 | } |
| 230 | ) |
| 231 | |
Jihoon Kang | 3a8759c | 2024-11-08 19:35:09 +0000 | [diff] [blame] | 232 | func generatedPrebuiltEtcModuleName(partition, srcDir, destDir string, count int) string { |
Jihoon Kang | add2bb2 | 2024-11-05 22:29:34 +0000 | [diff] [blame] | 233 | // generated module name follows the pattern: |
Jihoon Kang | 3a8759c | 2024-11-08 19:35:09 +0000 | [diff] [blame] | 234 | // <install partition>-<src file path>-<relative install path from partition root>-<number> |
Jihoon Kang | add2bb2 | 2024-11-05 22:29:34 +0000 | [diff] [blame] | 235 | // Note that all path separators are replaced with "_" in the name |
| 236 | moduleName := partition |
| 237 | if !android.InList(srcDir, []string{"", "."}) { |
| 238 | moduleName += fmt.Sprintf("-%s", strings.ReplaceAll(srcDir, string(filepath.Separator), "_")) |
| 239 | } |
| 240 | if !android.InList(destDir, []string{"", "."}) { |
| 241 | moduleName += fmt.Sprintf("-%s", strings.ReplaceAll(destDir, string(filepath.Separator), "_")) |
| 242 | } |
Jihoon Kang | 3a8759c | 2024-11-08 19:35:09 +0000 | [diff] [blame] | 243 | moduleName += fmt.Sprintf("-%d", count) |
Jihoon Kang | add2bb2 | 2024-11-05 22:29:34 +0000 | [diff] [blame] | 244 | |
Jihoon Kang | 3a8759c | 2024-11-08 19:35:09 +0000 | [diff] [blame] | 245 | return moduleName |
| 246 | } |
| 247 | |
| 248 | func groupDestFilesBySrc(destFiles []srcBaseFileInstallBaseFileTuple) (ret map[string][]srcBaseFileInstallBaseFileTuple, maxLen int) { |
| 249 | ret = map[string][]srcBaseFileInstallBaseFileTuple{} |
| 250 | maxLen = 0 |
Jihoon Kang | add2bb2 | 2024-11-05 22:29:34 +0000 | [diff] [blame] | 251 | for _, tuple := range destFiles { |
Jihoon Kang | 3a8759c | 2024-11-08 19:35:09 +0000 | [diff] [blame] | 252 | if _, ok := ret[tuple.srcBaseFile]; !ok { |
| 253 | ret[tuple.srcBaseFile] = []srcBaseFileInstallBaseFileTuple{} |
Jihoon Kang | add2bb2 | 2024-11-05 22:29:34 +0000 | [diff] [blame] | 254 | } |
Jihoon Kang | 3a8759c | 2024-11-08 19:35:09 +0000 | [diff] [blame] | 255 | ret[tuple.srcBaseFile] = append(ret[tuple.srcBaseFile], tuple) |
| 256 | maxLen = max(maxLen, len(ret[tuple.srcBaseFile])) |
Jihoon Kang | add2bb2 | 2024-11-05 22:29:34 +0000 | [diff] [blame] | 257 | } |
Jihoon Kang | 3a8759c | 2024-11-08 19:35:09 +0000 | [diff] [blame] | 258 | return ret, maxLen |
| 259 | } |
Jihoon Kang | add2bb2 | 2024-11-05 22:29:34 +0000 | [diff] [blame] | 260 | |
Jihoon Kang | d40d90f | 2024-12-02 19:10:37 +0000 | [diff] [blame] | 261 | func prebuiltEtcModuleProps(ctx android.LoadHookContext, moduleName, partition, destDir string) prebuiltModuleProperties { |
Jihoon Kang | 3a8759c | 2024-11-08 19:35:09 +0000 | [diff] [blame] | 262 | moduleProps := prebuiltModuleProperties{} |
| 263 | moduleProps.Name = proptools.StringPtr(moduleName) |
Jihoon Kang | add2bb2 | 2024-11-05 22:29:34 +0000 | [diff] [blame] | 264 | |
| 265 | // Set partition specific properties |
| 266 | switch partition { |
| 267 | case "system_ext": |
| 268 | moduleProps.System_ext_specific = proptools.BoolPtr(true) |
| 269 | case "product": |
| 270 | moduleProps.Product_specific = proptools.BoolPtr(true) |
| 271 | case "vendor": |
| 272 | moduleProps.Soc_specific = proptools.BoolPtr(true) |
Jihoon Kang | d40d90f | 2024-12-02 19:10:37 +0000 | [diff] [blame] | 273 | case "recovery": |
| 274 | // To match the logic in modulePartition() in android/paths.go |
| 275 | if ctx.DeviceConfig().BoardUsesRecoveryAsBoot() && strings.HasPrefix(destDir, "first_stage_ramdisk") { |
| 276 | moduleProps.Ramdisk = proptools.BoolPtr(true) |
| 277 | } else { |
| 278 | moduleProps.Recovery = proptools.BoolPtr(true) |
| 279 | } |
Jihoon Kang | add2bb2 | 2024-11-05 22:29:34 +0000 | [diff] [blame] | 280 | } |
| 281 | |
Jihoon Kang | add2bb2 | 2024-11-05 22:29:34 +0000 | [diff] [blame] | 282 | moduleProps.No_full_install = proptools.BoolPtr(true) |
| 283 | moduleProps.NamespaceExportedToMake = true |
| 284 | moduleProps.Visibility = []string{"//visibility:public"} |
| 285 | |
Jihoon Kang | 3a8759c | 2024-11-08 19:35:09 +0000 | [diff] [blame] | 286 | return moduleProps |
| 287 | } |
Jihoon Kang | add2bb2 | 2024-11-05 22:29:34 +0000 | [diff] [blame] | 288 | |
Jihoon Kang | 3a8759c | 2024-11-08 19:35:09 +0000 | [diff] [blame] | 289 | func createPrebuiltEtcModulesInDirectory(ctx android.LoadHookContext, partition, srcDir, destDir string, destFiles []srcBaseFileInstallBaseFileTuple) (moduleNames []string) { |
| 290 | groupedDestFiles, maxLen := groupDestFilesBySrc(destFiles) |
| 291 | |
| 292 | // Find out the most appropriate module type to generate |
| 293 | var etcInstallPathKey string |
| 294 | for _, etcInstallPath := range android.SortedKeys(etcInstallPathToFactoryList) { |
| 295 | // Do not break when found but iterate until the end to find a module with more |
| 296 | // specific install path |
| 297 | if strings.HasPrefix(destDir, etcInstallPath) { |
| 298 | etcInstallPathKey = etcInstallPath |
| 299 | } |
| 300 | } |
Jihoon Kang | 3e14966 | 2025-03-12 22:14:39 +0000 | [diff] [blame] | 301 | moduleFactory := etcInstallPathToFactoryList[etcInstallPathKey] |
Jihoon Kang | 3a8759c | 2024-11-08 19:35:09 +0000 | [diff] [blame] | 302 | relDestDirFromInstallDirBase, _ := filepath.Rel(etcInstallPathKey, destDir) |
| 303 | |
| 304 | for fileIndex := range maxLen { |
| 305 | srcTuple := []srcBaseFileInstallBaseFileTuple{} |
Jihoon Kang | 47dadd9 | 2024-11-13 01:00:57 +0000 | [diff] [blame] | 306 | for _, srcFile := range android.SortedKeys(groupedDestFiles) { |
| 307 | groupedDestFile := groupedDestFiles[srcFile] |
Jihoon Kang | 3a8759c | 2024-11-08 19:35:09 +0000 | [diff] [blame] | 308 | if len(groupedDestFile) > fileIndex { |
| 309 | srcTuple = append(srcTuple, groupedDestFile[fileIndex]) |
| 310 | } |
| 311 | } |
| 312 | |
| 313 | moduleName := generatedPrebuiltEtcModuleName(partition, srcDir, destDir, fileIndex) |
Jihoon Kang | d40d90f | 2024-12-02 19:10:37 +0000 | [diff] [blame] | 314 | moduleProps := prebuiltEtcModuleProps(ctx, moduleName, partition, destDir) |
Jihoon Kang | 3a8759c | 2024-11-08 19:35:09 +0000 | [diff] [blame] | 315 | modulePropsPtr := &moduleProps |
| 316 | propsList := []interface{}{modulePropsPtr} |
| 317 | |
| 318 | allCopyFileNamesUnchanged := true |
| 319 | var srcBaseFiles, installBaseFiles []string |
| 320 | for _, tuple := range srcTuple { |
| 321 | if tuple.srcBaseFile != tuple.installBaseFile { |
| 322 | allCopyFileNamesUnchanged = false |
| 323 | } |
| 324 | srcBaseFiles = append(srcBaseFiles, tuple.srcBaseFile) |
| 325 | installBaseFiles = append(installBaseFiles, tuple.installBaseFile) |
| 326 | } |
| 327 | |
Jihoon Kang | d40d90f | 2024-12-02 19:10:37 +0000 | [diff] [blame] | 328 | // Recovery partition-installed modules are installed to `recovery/root/system` by |
| 329 | // default (See modulePartition() in android/paths.go). If the destination file |
| 330 | // directory is not `recovery/root/system/...`, it should set install_in_root to true |
| 331 | // to prevent being installed in `recovery/root/system`. |
| 332 | if partition == "recovery" && !strings.HasPrefix(destDir, "system") { |
| 333 | propsList = append(propsList, &prebuiltInstallInRootProperties{ |
| 334 | Install_in_root: proptools.BoolPtr(true), |
| 335 | }) |
| 336 | } |
| 337 | |
Jihoon Kang | 3a8759c | 2024-11-08 19:35:09 +0000 | [diff] [blame] | 338 | // Set appropriate srcs, dsts, and releative_install_path based on |
| 339 | // the source and install file names |
Jihoon Kang | 1c87a30 | 2025-03-17 23:19:27 +0000 | [diff] [blame^] | 340 | modulePropsPtr.Srcs = srcBaseFiles |
Jihoon Kang | 3a8759c | 2024-11-08 19:35:09 +0000 | [diff] [blame] | 341 | |
Jihoon Kang | 1c87a30 | 2025-03-17 23:19:27 +0000 | [diff] [blame^] | 342 | // prebuilt_root should only be used in very limited cases in prebuilt_etc moddule gen, where: |
| 343 | // - all source file names are identical to the installed file names, and |
| 344 | // - all source files are installed in root, not the subdirectories of root |
| 345 | // prebuilt_root currently does not have a good way to specify the names of the multiple |
| 346 | // installed files, and prebuilt_root does not allow installing files at a subdirectory |
| 347 | // of the root. |
| 348 | // Use prebuilt_any instead of prebuilt_root if either of the conditions are not met as |
| 349 | // a fallback behavior. |
| 350 | if etcInstallPathKey == "" { |
| 351 | if !(allCopyFileNamesUnchanged && android.InList(relDestDirFromInstallDirBase, []string{"", "."})) { |
| 352 | moduleFactory = etc.PrebuiltAnyFactory |
| 353 | } |
| 354 | } |
| 355 | |
| 356 | if allCopyFileNamesUnchanged { |
Jihoon Kang | 3a8759c | 2024-11-08 19:35:09 +0000 | [diff] [blame] | 357 | // Specify relative_install_path if it is not installed in the root directory of the |
| 358 | // partition |
| 359 | if !android.InList(relDestDirFromInstallDirBase, []string{"", "."}) { |
| 360 | propsList = append(propsList, &prebuiltSubdirProperties{ |
| 361 | Relative_install_path: proptools.StringPtr(relDestDirFromInstallDirBase), |
| 362 | }) |
| 363 | } |
| 364 | } else { |
Jihoon Kang | 3e14966 | 2025-03-12 22:14:39 +0000 | [diff] [blame] | 365 | // If dsts property has to be set and the selected module type is prebuilt_root, |
| 366 | // use prebuilt_any instead. |
Jihoon Kang | 723f122 | 2025-03-12 22:24:52 +0000 | [diff] [blame] | 367 | dsts := proptools.NewConfigurable[[]string](nil, nil) |
Jihoon Kang | 3a8759c | 2024-11-08 19:35:09 +0000 | [diff] [blame] | 368 | for _, installBaseFile := range installBaseFiles { |
Jihoon Kang | 723f122 | 2025-03-12 22:24:52 +0000 | [diff] [blame] | 369 | dsts.AppendSimpleValue([]string{filepath.Join(relDestDirFromInstallDirBase, installBaseFile)}) |
Jihoon Kang | 3a8759c | 2024-11-08 19:35:09 +0000 | [diff] [blame] | 370 | } |
Jihoon Kang | 723f122 | 2025-03-12 22:24:52 +0000 | [diff] [blame] | 371 | propsList = append(propsList, &etc.PrebuiltDstsProperties{ |
| 372 | Dsts: dsts, |
| 373 | }) |
Jihoon Kang | 3a8759c | 2024-11-08 19:35:09 +0000 | [diff] [blame] | 374 | } |
| 375 | |
Jihoon Kang | 3e14966 | 2025-03-12 22:14:39 +0000 | [diff] [blame] | 376 | ctx.CreateModuleInDirectory(moduleFactory, srcDir, propsList...) |
Jihoon Kang | 3a8759c | 2024-11-08 19:35:09 +0000 | [diff] [blame] | 377 | moduleNames = append(moduleNames, moduleName) |
| 378 | } |
| 379 | |
| 380 | return moduleNames |
Jihoon Kang | add2bb2 | 2024-11-05 22:29:34 +0000 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | func createPrebuiltEtcModulesForPartition(ctx android.LoadHookContext, partition, srcDir string, destDirFilesMap map[string][]srcBaseFileInstallBaseFileTuple) (ret []string) { |
| 384 | for _, destDir := range android.SortedKeys(destDirFilesMap) { |
Jihoon Kang | 3a8759c | 2024-11-08 19:35:09 +0000 | [diff] [blame] | 385 | ret = append(ret, createPrebuiltEtcModulesInDirectory(ctx, partition, srcDir, destDir, destDirFilesMap[destDir])...) |
Jihoon Kang | add2bb2 | 2024-11-05 22:29:34 +0000 | [diff] [blame] | 386 | } |
| 387 | return ret |
| 388 | } |
| 389 | |
| 390 | // Creates prebuilt_* modules based on the install paths and returns the list of generated |
| 391 | // module names |
| 392 | func createPrebuiltEtcModules(ctx android.LoadHookContext) (ret []string) { |
| 393 | groupedSources := processProductCopyFiles(ctx) |
| 394 | for _, srcDir := range android.SortedKeys(groupedSources) { |
| 395 | groupedSource := groupedSources[srcDir] |
| 396 | ret = append(ret, createPrebuiltEtcModulesForPartition(ctx, "system", srcDir, groupedSource.system)...) |
| 397 | ret = append(ret, createPrebuiltEtcModulesForPartition(ctx, "system_ext", srcDir, groupedSource.system_ext)...) |
| 398 | ret = append(ret, createPrebuiltEtcModulesForPartition(ctx, "product", srcDir, groupedSource.product)...) |
| 399 | ret = append(ret, createPrebuiltEtcModulesForPartition(ctx, "vendor", srcDir, groupedSource.vendor)...) |
Jihoon Kang | d40d90f | 2024-12-02 19:10:37 +0000 | [diff] [blame] | 400 | ret = append(ret, createPrebuiltEtcModulesForPartition(ctx, "recovery", srcDir, groupedSource.recovery)...) |
Jihoon Kang | add2bb2 | 2024-11-05 22:29:34 +0000 | [diff] [blame] | 401 | } |
| 402 | |
| 403 | return ret |
| 404 | } |
Jihoon Kang | 04f12c9 | 2024-11-12 23:03:08 +0000 | [diff] [blame] | 405 | |
| 406 | func createAvbpubkeyModule(ctx android.LoadHookContext) bool { |
| 407 | avbKeyPath := ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse.BoardAvbKeyPath |
| 408 | if avbKeyPath == "" { |
| 409 | return false |
| 410 | } |
| 411 | ctx.CreateModuleInDirectory( |
| 412 | etc.AvbpubkeyModuleFactory, |
| 413 | ".", |
| 414 | &struct { |
| 415 | Name *string |
| 416 | Product_specific *bool |
| 417 | Private_key *string |
| 418 | No_full_install *bool |
| 419 | Visibility []string |
| 420 | }{ |
| 421 | Name: proptools.StringPtr("system_other_avbpubkey"), |
| 422 | Product_specific: proptools.BoolPtr(true), |
| 423 | Private_key: proptools.StringPtr(avbKeyPath), |
| 424 | No_full_install: proptools.BoolPtr(true), |
| 425 | Visibility: []string{"//visibility:public"}, |
| 426 | }, |
| 427 | ) |
| 428 | return true |
| 429 | } |