Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +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 ( |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 18 | "crypto/sha256" |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 19 | "fmt" |
Spandan Das | 312cc41 | 2024-10-29 18:20:11 +0000 | [diff] [blame] | 20 | "path/filepath" |
mrziwang | 8f86c88 | 2024-10-03 12:34:33 -0700 | [diff] [blame] | 21 | "slices" |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 22 | "strconv" |
mrziwang | 8f86c88 | 2024-10-03 12:34:33 -0700 | [diff] [blame] | 23 | "strings" |
| 24 | "sync" |
| 25 | |
| 26 | "android/soong/android" |
Jihoon Kang | 675d468 | 2024-10-24 23:45:11 +0000 | [diff] [blame^] | 27 | "android/soong/etc" |
mrziwang | 8f86c88 | 2024-10-03 12:34:33 -0700 | [diff] [blame] | 28 | "android/soong/filesystem" |
Spandan Das | 5e33642 | 2024-11-01 22:31:20 +0000 | [diff] [blame] | 29 | "android/soong/kernel" |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 30 | |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 31 | "github.com/google/blueprint" |
mrziwang | 8f86c88 | 2024-10-03 12:34:33 -0700 | [diff] [blame] | 32 | "github.com/google/blueprint/parser" |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 33 | "github.com/google/blueprint/proptools" |
| 34 | ) |
| 35 | |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 36 | var pctx = android.NewPackageContext("android/soong/fsgen") |
| 37 | |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 38 | func init() { |
| 39 | registerBuildComponents(android.InitRegistrationContext) |
| 40 | } |
| 41 | |
| 42 | func registerBuildComponents(ctx android.RegistrationContext) { |
| 43 | ctx.RegisterModuleType("soong_filesystem_creator", filesystemCreatorFactory) |
mrziwang | 8f86c88 | 2024-10-03 12:34:33 -0700 | [diff] [blame] | 44 | ctx.PreDepsMutators(RegisterCollectFileSystemDepsMutators) |
| 45 | } |
| 46 | |
| 47 | func RegisterCollectFileSystemDepsMutators(ctx android.RegisterMutatorsContext) { |
| 48 | ctx.BottomUp("fs_collect_deps", collectDepsMutator).MutatesGlobalState() |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 49 | ctx.BottomUp("fs_set_deps", setDepsMutator) |
mrziwang | 8f86c88 | 2024-10-03 12:34:33 -0700 | [diff] [blame] | 50 | } |
| 51 | |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 52 | var fsGenStateOnceKey = android.NewOnceKey("FsGenState") |
Spandan Das | e1860e4 | 2024-10-24 22:29:50 +0000 | [diff] [blame] | 53 | var fsGenRemoveOverridesOnceKey = android.NewOnceKey("FsGenRemoveOverrides") |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 54 | |
| 55 | // Map of partition module name to its partition that may be generated by Soong. |
| 56 | // Note that it is not guaranteed that all modules returned by this function are successfully |
| 57 | // created. |
| 58 | func getAllSoongGeneratedPartitionNames(config android.Config, partitions []string) map[string]string { |
| 59 | ret := map[string]string{} |
| 60 | for _, partition := range partitions { |
| 61 | ret[generatedModuleNameForPartition(config, partition)] = partition |
| 62 | } |
| 63 | return ret |
| 64 | } |
| 65 | |
| 66 | type depCandidateProps struct { |
| 67 | Namespace string |
| 68 | Multilib string |
| 69 | Arch []android.ArchType |
| 70 | } |
| 71 | |
| 72 | // Map of module name to depCandidateProps |
Jihoon Kang | 83f135b | 2024-11-01 22:56:07 +0000 | [diff] [blame] | 73 | type multilibDeps map[string]*depCandidateProps |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 74 | |
| 75 | // Information necessary to generate the filesystem modules, including details about their |
| 76 | // dependencies |
| 77 | type FsGenState struct { |
| 78 | // List of modules in `PRODUCT_PACKAGES` and `PRODUCT_PACKAGES_DEBUG` |
| 79 | depCandidates []string |
| 80 | // Map of names of partition to the information of modules to be added as deps |
Jihoon Kang | 83f135b | 2024-11-01 22:56:07 +0000 | [diff] [blame] | 81 | fsDeps map[string]*multilibDeps |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 82 | // List of name of partitions to be generated by the filesystem_creator module |
| 83 | soongGeneratedPartitions []string |
| 84 | // Mutex to protect the fsDeps |
| 85 | fsDepsMutex sync.Mutex |
Spandan Das | e1860e4 | 2024-10-24 22:29:50 +0000 | [diff] [blame] | 86 | // Map of _all_ soong module names to their corresponding installation properties |
| 87 | moduleToInstallationProps map[string]installationProperties |
| 88 | } |
| 89 | |
| 90 | type installationProperties struct { |
| 91 | Required []string |
| 92 | Overrides []string |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 93 | } |
| 94 | |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 95 | func defaultDepCandidateProps(config android.Config) *depCandidateProps { |
| 96 | return &depCandidateProps{ |
| 97 | Namespace: ".", |
| 98 | Arch: []android.ArchType{config.BuildArch}, |
| 99 | } |
| 100 | } |
| 101 | |
Jihoon Kang | 675d468 | 2024-10-24 23:45:11 +0000 | [diff] [blame^] | 102 | type srcBaseFileInstallBaseFileTuple struct { |
| 103 | srcBaseFile string |
| 104 | installBaseFile string |
| 105 | } |
| 106 | |
| 107 | // prebuilt src files grouped by the install partitions. |
| 108 | // Each groups are a mapping of the relative install path to the name of the files |
| 109 | type prebuiltSrcGroupByInstallPartition struct { |
| 110 | system map[string][]srcBaseFileInstallBaseFileTuple |
| 111 | system_ext map[string][]srcBaseFileInstallBaseFileTuple |
| 112 | product map[string][]srcBaseFileInstallBaseFileTuple |
| 113 | vendor map[string][]srcBaseFileInstallBaseFileTuple |
| 114 | } |
| 115 | |
| 116 | func newPrebuiltSrcGroupByInstallPartition() *prebuiltSrcGroupByInstallPartition { |
| 117 | return &prebuiltSrcGroupByInstallPartition{ |
| 118 | system: map[string][]srcBaseFileInstallBaseFileTuple{}, |
| 119 | system_ext: map[string][]srcBaseFileInstallBaseFileTuple{}, |
| 120 | product: map[string][]srcBaseFileInstallBaseFileTuple{}, |
| 121 | vendor: map[string][]srcBaseFileInstallBaseFileTuple{}, |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | func isSubdirectory(parent, child string) bool { |
| 126 | rel, err := filepath.Rel(parent, child) |
| 127 | if err != nil { |
| 128 | return false |
| 129 | } |
| 130 | return !strings.HasPrefix(rel, "..") |
| 131 | } |
| 132 | |
| 133 | func appendIfCorrectInstallPartition(partitionToInstallPathList []partitionToInstallPath, destPath, srcPath string, srcGroup *prebuiltSrcGroupByInstallPartition) { |
| 134 | for _, part := range partitionToInstallPathList { |
| 135 | partition := part.name |
| 136 | installPath := part.installPath |
| 137 | |
| 138 | if isSubdirectory(installPath, destPath) { |
| 139 | relativeInstallPath, _ := filepath.Rel(installPath, destPath) |
| 140 | relativeInstallDir := filepath.Dir(relativeInstallPath) |
| 141 | var srcMap map[string][]srcBaseFileInstallBaseFileTuple |
| 142 | switch partition { |
| 143 | case "system": |
| 144 | srcMap = srcGroup.system |
| 145 | case "system_ext": |
| 146 | srcMap = srcGroup.system_ext |
| 147 | case "product": |
| 148 | srcMap = srcGroup.product |
| 149 | case "vendor": |
| 150 | srcMap = srcGroup.vendor |
| 151 | } |
| 152 | if srcMap != nil { |
| 153 | srcMap[relativeInstallDir] = append(srcMap[relativeInstallDir], srcBaseFileInstallBaseFileTuple{ |
| 154 | srcBaseFile: filepath.Base(srcPath), |
| 155 | installBaseFile: filepath.Base(destPath), |
| 156 | }) |
| 157 | } |
| 158 | return |
| 159 | } |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | func uniqueExistingProductCopyFileMap(ctx android.LoadHookContext) map[string]string { |
| 164 | seen := make(map[string]bool) |
| 165 | filtered := make(map[string]string) |
| 166 | |
| 167 | for src, dest := range ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse.ProductCopyFiles { |
| 168 | if _, ok := seen[dest]; !ok { |
| 169 | if optionalPath := android.ExistentPathForSource(ctx, src); optionalPath.Valid() { |
| 170 | seen[dest] = true |
| 171 | filtered[src] = dest |
| 172 | } |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | return filtered |
| 177 | } |
| 178 | |
| 179 | type partitionToInstallPath struct { |
| 180 | name string |
| 181 | installPath string |
| 182 | } |
| 183 | |
| 184 | func processProductCopyFiles(ctx android.LoadHookContext) map[string]*prebuiltSrcGroupByInstallPartition { |
| 185 | // Filter out duplicate dest entries and non existing src entries |
| 186 | productCopyFileMap := uniqueExistingProductCopyFileMap(ctx) |
| 187 | |
| 188 | // System is intentionally added at the last to consider the scenarios where |
| 189 | // non-system partitions are installed as part of the system partition |
| 190 | partitionToInstallPathList := []partitionToInstallPath{ |
| 191 | {name: "vendor", installPath: ctx.DeviceConfig().VendorPath()}, |
| 192 | {name: "product", installPath: ctx.DeviceConfig().ProductPath()}, |
| 193 | {name: "system_ext", installPath: ctx.DeviceConfig().SystemExtPath()}, |
| 194 | {name: "system", installPath: "system"}, |
| 195 | } |
| 196 | |
| 197 | groupedSources := map[string]*prebuiltSrcGroupByInstallPartition{} |
| 198 | for _, src := range android.SortedKeys(productCopyFileMap) { |
| 199 | dest := productCopyFileMap[src] |
| 200 | srcFileDir := filepath.Dir(src) |
| 201 | if _, ok := groupedSources[srcFileDir]; !ok { |
| 202 | groupedSources[srcFileDir] = newPrebuiltSrcGroupByInstallPartition() |
| 203 | } |
| 204 | appendIfCorrectInstallPartition(partitionToInstallPathList, dest, filepath.Base(src), groupedSources[srcFileDir]) |
| 205 | } |
| 206 | |
| 207 | return groupedSources |
| 208 | } |
| 209 | |
| 210 | type prebuiltModuleProperties struct { |
| 211 | Name *string |
| 212 | |
| 213 | Soc_specific *bool |
| 214 | Product_specific *bool |
| 215 | System_ext_specific *bool |
| 216 | |
| 217 | Srcs []string |
| 218 | Dsts []string |
| 219 | |
| 220 | No_full_install *bool |
| 221 | |
| 222 | NamespaceExportedToMake bool |
| 223 | |
| 224 | Visibility []string |
| 225 | } |
| 226 | |
| 227 | // Split relative_install_path to a separate struct, because it is not supported for every |
| 228 | // modules listed in [etcInstallPathToFactoryMap] |
| 229 | type prebuiltSubdirProperties struct { |
| 230 | // If the base file name of the src and dst all match, dsts property does not need to be |
| 231 | // set, and only relative_install_path can be set. |
| 232 | Relative_install_path *string |
| 233 | } |
| 234 | |
| 235 | var ( |
| 236 | etcInstallPathToFactoryList = map[string]android.ModuleFactory{ |
| 237 | "": etc.PrebuiltRootFactory, |
| 238 | "avb": etc.PrebuiltAvbFactory, |
| 239 | "bin": etc.PrebuiltBinaryFactory, |
| 240 | "bt_firmware": etc.PrebuiltBtFirmwareFactory, |
| 241 | "cacerts": etc.PrebuiltEtcCaCertsFactory, |
| 242 | "dsp": etc.PrebuiltDSPFactory, |
| 243 | "etc": etc.PrebuiltEtcFactory, |
| 244 | "etc/dsp": etc.PrebuiltDSPFactory, |
| 245 | "etc/firmware": etc.PrebuiltFirmwareFactory, |
| 246 | "firmware": etc.PrebuiltFirmwareFactory, |
| 247 | "fonts": etc.PrebuiltFontFactory, |
| 248 | "framework": etc.PrebuiltFrameworkFactory, |
| 249 | "lib": etc.PrebuiltRenderScriptBitcodeFactory, |
| 250 | "lib64": etc.PrebuiltRenderScriptBitcodeFactory, |
| 251 | "lib/rfsa": etc.PrebuiltRFSAFactory, |
| 252 | "media": etc.PrebuiltMediaFactory, |
| 253 | "odm": etc.PrebuiltOdmFactory, |
| 254 | "overlay": etc.PrebuiltOverlayFactory, |
| 255 | "priv-app": etc.PrebuiltPrivAppFactory, |
| 256 | "res": etc.PrebuiltResFactory, |
| 257 | "rfs": etc.PrebuiltRfsFactory, |
| 258 | "tts": etc.PrebuiltVoicepackFactory, |
| 259 | "usr/share": etc.PrebuiltUserShareFactory, |
| 260 | "usr/hyphen-data": etc.PrebuiltUserHyphenDataFactory, |
| 261 | "usr/keylayout": etc.PrebuiltUserKeyLayoutFactory, |
| 262 | "usr/keychars": etc.PrebuiltUserKeyCharsFactory, |
| 263 | "usr/srec": etc.PrebuiltUserSrecFactory, |
| 264 | "usr/idc": etc.PrebuiltUserIdcFactory, |
| 265 | "vendor_dlkm": etc.PrebuiltVendorDlkmFactory, |
| 266 | "wallpaper": etc.PrebuiltWallpaperFactory, |
| 267 | "wlc_upt": etc.PrebuiltWlcUptFactory, |
| 268 | } |
| 269 | ) |
| 270 | |
| 271 | func createPrebuiltEtcModule(ctx android.LoadHookContext, partition, srcDir, destDir string, destFiles []srcBaseFileInstallBaseFileTuple) string { |
| 272 | moduleProps := &prebuiltModuleProperties{} |
| 273 | propsList := []interface{}{moduleProps} |
| 274 | |
| 275 | // generated module name follows the pattern: |
| 276 | // <install partition>-<src file path>-<relative install path from partition root>-<install file extension> |
| 277 | // Note that all path separators are replaced with "_" in the name |
| 278 | moduleName := partition |
| 279 | if !android.InList(srcDir, []string{"", "."}) { |
| 280 | moduleName += fmt.Sprintf("-%s", strings.ReplaceAll(srcDir, string(filepath.Separator), "_")) |
| 281 | } |
| 282 | if !android.InList(destDir, []string{"", "."}) { |
| 283 | moduleName += fmt.Sprintf("-%s", strings.ReplaceAll(destDir, string(filepath.Separator), "_")) |
| 284 | } |
| 285 | if len(destFiles) > 0 { |
| 286 | if ext := filepath.Ext(destFiles[0].srcBaseFile); ext != "" { |
| 287 | moduleName += fmt.Sprintf("-%s", strings.TrimPrefix(ext, ".")) |
| 288 | } |
| 289 | } |
| 290 | moduleProps.Name = proptools.StringPtr(moduleName) |
| 291 | |
| 292 | allCopyFileNamesUnchanged := true |
| 293 | var srcBaseFiles, installBaseFiles []string |
| 294 | for _, tuple := range destFiles { |
| 295 | if tuple.srcBaseFile != tuple.installBaseFile { |
| 296 | allCopyFileNamesUnchanged = false |
| 297 | } |
| 298 | srcBaseFiles = append(srcBaseFiles, tuple.srcBaseFile) |
| 299 | installBaseFiles = append(installBaseFiles, tuple.installBaseFile) |
| 300 | } |
| 301 | |
| 302 | // Find out the most appropriate module type to generate |
| 303 | var etcInstallPathKey string |
| 304 | for _, etcInstallPath := range android.SortedKeys(etcInstallPathToFactoryList) { |
| 305 | // Do not break when found but iterate until the end to find a module with more |
| 306 | // specific install path |
| 307 | if strings.HasPrefix(destDir, etcInstallPath) { |
| 308 | etcInstallPathKey = etcInstallPath |
| 309 | } |
| 310 | } |
| 311 | destDir, _ = filepath.Rel(etcInstallPathKey, destDir) |
| 312 | |
| 313 | // Set partition specific properties |
| 314 | switch partition { |
| 315 | case "system_ext": |
| 316 | moduleProps.System_ext_specific = proptools.BoolPtr(true) |
| 317 | case "product": |
| 318 | moduleProps.Product_specific = proptools.BoolPtr(true) |
| 319 | case "vendor": |
| 320 | moduleProps.Soc_specific = proptools.BoolPtr(true) |
| 321 | } |
| 322 | |
| 323 | // Set appropriate srcs, dsts, and releative_install_path based on |
| 324 | // the source and install file names |
| 325 | if allCopyFileNamesUnchanged { |
| 326 | moduleProps.Srcs = srcBaseFiles |
| 327 | |
| 328 | // Specify relative_install_path if it is not installed in the root directory of the |
| 329 | // partition |
| 330 | if !android.InList(destDir, []string{"", "."}) { |
| 331 | propsList = append(propsList, &prebuiltSubdirProperties{ |
| 332 | Relative_install_path: proptools.StringPtr(destDir), |
| 333 | }) |
| 334 | } |
| 335 | } else { |
| 336 | moduleProps.Srcs = srcBaseFiles |
| 337 | dsts := []string{} |
| 338 | for _, installBaseFile := range installBaseFiles { |
| 339 | dsts = append(dsts, filepath.Join(destDir, installBaseFile)) |
| 340 | } |
| 341 | moduleProps.Dsts = dsts |
| 342 | } |
| 343 | |
| 344 | moduleProps.No_full_install = proptools.BoolPtr(true) |
| 345 | moduleProps.NamespaceExportedToMake = true |
| 346 | moduleProps.Visibility = []string{"//visibility:public"} |
| 347 | |
| 348 | ctx.CreateModuleInDirectory(etcInstallPathToFactoryList[etcInstallPathKey], srcDir, propsList...) |
| 349 | |
| 350 | return moduleName |
| 351 | } |
| 352 | |
| 353 | func createPrebuiltEtcModulesForPartition(ctx android.LoadHookContext, partition, srcDir string, destDirFilesMap map[string][]srcBaseFileInstallBaseFileTuple) (ret []string) { |
| 354 | for _, destDir := range android.SortedKeys(destDirFilesMap) { |
| 355 | ret = append(ret, createPrebuiltEtcModule(ctx, partition, srcDir, destDir, destDirFilesMap[destDir])) |
| 356 | } |
| 357 | return ret |
| 358 | } |
| 359 | |
| 360 | // Creates prebuilt_* modules based on the install paths and returns the list of generated |
| 361 | // module names |
| 362 | func createPrebuiltEtcModules(ctx android.LoadHookContext) (ret []string) { |
| 363 | groupedSources := processProductCopyFiles(ctx) |
| 364 | for _, srcDir := range android.SortedKeys(groupedSources) { |
| 365 | groupedSource := groupedSources[srcDir] |
| 366 | ret = append(ret, createPrebuiltEtcModulesForPartition(ctx, "system", srcDir, groupedSource.system)...) |
| 367 | ret = append(ret, createPrebuiltEtcModulesForPartition(ctx, "system_ext", srcDir, groupedSource.system_ext)...) |
| 368 | ret = append(ret, createPrebuiltEtcModulesForPartition(ctx, "product", srcDir, groupedSource.product)...) |
| 369 | ret = append(ret, createPrebuiltEtcModulesForPartition(ctx, "vendor", srcDir, groupedSource.vendor)...) |
| 370 | } |
| 371 | |
| 372 | return ret |
| 373 | } |
| 374 | |
| 375 | func generatedPartitions(ctx android.LoadHookContext) []string { |
| 376 | generatedPartitions := []string{"system"} |
| 377 | if ctx.DeviceConfig().SystemExtPath() == "system_ext" { |
| 378 | generatedPartitions = append(generatedPartitions, "system_ext") |
| 379 | } |
| 380 | if ctx.DeviceConfig().BuildingVendorImage() && ctx.DeviceConfig().VendorPath() == "vendor" { |
| 381 | generatedPartitions = append(generatedPartitions, "vendor") |
| 382 | } |
| 383 | if ctx.DeviceConfig().BuildingProductImage() && ctx.DeviceConfig().ProductPath() == "product" { |
| 384 | generatedPartitions = append(generatedPartitions, "product") |
| 385 | } |
| 386 | if ctx.DeviceConfig().BuildingOdmImage() && ctx.DeviceConfig().OdmPath() == "odm" { |
| 387 | generatedPartitions = append(generatedPartitions, "odm") |
| 388 | } |
| 389 | if ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse.BuildingSystemDlkmImage { |
| 390 | generatedPartitions = append(generatedPartitions, "system_dlkm") |
| 391 | } |
| 392 | return generatedPartitions |
| 393 | } |
| 394 | |
| 395 | func createFsGenState(ctx android.LoadHookContext, generatedPrebuiltEtcModuleNames []string) *FsGenState { |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 396 | return ctx.Config().Once(fsGenStateOnceKey, func() interface{} { |
| 397 | partitionVars := ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse |
| 398 | candidates := android.FirstUniqueStrings(android.Concat(partitionVars.ProductPackages, partitionVars.ProductPackagesDebug)) |
Jihoon Kang | 675d468 | 2024-10-24 23:45:11 +0000 | [diff] [blame^] | 399 | candidates = android.Concat(candidates, generatedPrebuiltEtcModuleNames) |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 400 | |
| 401 | return &FsGenState{ |
| 402 | depCandidates: candidates, |
Jihoon Kang | 83f135b | 2024-11-01 22:56:07 +0000 | [diff] [blame] | 403 | fsDeps: map[string]*multilibDeps{ |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 404 | // These additional deps are added according to the cuttlefish system image bp. |
Jihoon Kang | 83f135b | 2024-11-01 22:56:07 +0000 | [diff] [blame] | 405 | "system": { |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 406 | "com.android.apex.cts.shim.v1_prebuilt": defaultDepCandidateProps(ctx.Config()), |
| 407 | "dex_bootjars": defaultDepCandidateProps(ctx.Config()), |
| 408 | "framework_compatibility_matrix.device.xml": defaultDepCandidateProps(ctx.Config()), |
Jihoon Kang | 675d468 | 2024-10-24 23:45:11 +0000 | [diff] [blame^] | 409 | "init.environ.rc-soong": defaultDepCandidateProps(ctx.Config()), |
| 410 | "libclang_rt.asan": defaultDepCandidateProps(ctx.Config()), |
| 411 | "libcompiler_rt": defaultDepCandidateProps(ctx.Config()), |
| 412 | "libdmabufheap": defaultDepCandidateProps(ctx.Config()), |
| 413 | "libgsi": defaultDepCandidateProps(ctx.Config()), |
| 414 | "llndk.libraries.txt": defaultDepCandidateProps(ctx.Config()), |
| 415 | "logpersist.start": defaultDepCandidateProps(ctx.Config()), |
| 416 | "update_engine_sideload": defaultDepCandidateProps(ctx.Config()), |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 417 | }, |
Jihoon Kang | 83f135b | 2024-11-01 22:56:07 +0000 | [diff] [blame] | 418 | "vendor": { |
Spandan Das | 168098c | 2024-10-28 19:44:34 +0000 | [diff] [blame] | 419 | "fs_config_files_vendor": defaultDepCandidateProps(ctx.Config()), |
| 420 | "fs_config_dirs_vendor": defaultDepCandidateProps(ctx.Config()), |
| 421 | generatedModuleName(ctx.Config(), "vendor-build.prop"): defaultDepCandidateProps(ctx.Config()), |
Spandan Das | 49cc3e8 | 2024-10-23 20:54:01 +0000 | [diff] [blame] | 422 | }, |
Jihoon Kang | 83f135b | 2024-11-01 22:56:07 +0000 | [diff] [blame] | 423 | "odm": { |
Spandan Das | c571716 | 2024-11-01 18:33:57 +0000 | [diff] [blame] | 424 | // fs_config_* files are automatically installed for all products with odm partitions. |
| 425 | // https://cs.android.com/android/_/android/platform/build/+/e4849e87ab660b59a6501b3928693db065ee873b:tools/fs_config/Android.mk;l=34;drc=8d6481b92c4b4e9b9f31a61545b6862090fcc14b;bpv=1;bpt=0 |
| 426 | "fs_config_files_odm": defaultDepCandidateProps(ctx.Config()), |
| 427 | "fs_config_dirs_odm": defaultDepCandidateProps(ctx.Config()), |
| 428 | }, |
Jihoon Kang | 83f135b | 2024-11-01 22:56:07 +0000 | [diff] [blame] | 429 | "product": {}, |
| 430 | "system_ext": { |
Spandan Das | d9875bc | 2024-10-17 21:36:17 +0000 | [diff] [blame] | 431 | // VNDK apexes are automatically included. |
| 432 | // This hardcoded list will need to be updated if `PRODUCT_EXTRA_VNDK_VERSIONS` is updated. |
| 433 | // https://cs.android.com/android/_/android/platform/build/+/adba533072b00c53ac0f198c550a3cbd7a00e4cd:core/main.mk;l=984;bpv=1;bpt=0;drc=174db7b179592cf07cbfd2adb0119486fda911e7 |
| 434 | "com.android.vndk.v30": defaultDepCandidateProps(ctx.Config()), |
| 435 | "com.android.vndk.v31": defaultDepCandidateProps(ctx.Config()), |
| 436 | "com.android.vndk.v32": defaultDepCandidateProps(ctx.Config()), |
| 437 | "com.android.vndk.v33": defaultDepCandidateProps(ctx.Config()), |
| 438 | "com.android.vndk.v34": defaultDepCandidateProps(ctx.Config()), |
| 439 | }, |
Spandan Das | 5e33642 | 2024-11-01 22:31:20 +0000 | [diff] [blame] | 440 | "system_dlkm": {}, |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 441 | }, |
Jihoon Kang | 675d468 | 2024-10-24 23:45:11 +0000 | [diff] [blame^] | 442 | soongGeneratedPartitions: generatedPartitions(ctx), |
Spandan Das | e1860e4 | 2024-10-24 22:29:50 +0000 | [diff] [blame] | 443 | fsDepsMutex: sync.Mutex{}, |
| 444 | moduleToInstallationProps: map[string]installationProperties{}, |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 445 | } |
| 446 | }).(*FsGenState) |
| 447 | } |
| 448 | |
Jihoon Kang | 83f135b | 2024-11-01 22:56:07 +0000 | [diff] [blame] | 449 | func checkDepModuleInMultipleNamespaces(mctx android.BottomUpMutatorContext, foundDeps multilibDeps, module string, partitionName string) { |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 450 | otherNamespace := mctx.Namespace().Path |
| 451 | if val, found := foundDeps[module]; found && otherNamespace != "." && !android.InList(val.Namespace, []string{".", otherNamespace}) { |
| 452 | mctx.ModuleErrorf("found in multiple namespaces(%s and %s) when including in %s partition", val.Namespace, otherNamespace, partitionName) |
| 453 | } |
| 454 | } |
| 455 | |
Jihoon Kang | 83f135b | 2024-11-01 22:56:07 +0000 | [diff] [blame] | 456 | func appendDepIfAppropriate(mctx android.BottomUpMutatorContext, deps *multilibDeps, installPartition string) { |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 457 | checkDepModuleInMultipleNamespaces(mctx, *deps, mctx.Module().Name(), installPartition) |
| 458 | if _, ok := (*deps)[mctx.Module().Name()]; ok { |
| 459 | // Prefer the namespace-specific module over the platform module |
| 460 | if mctx.Namespace().Path != "." { |
| 461 | (*deps)[mctx.Module().Name()].Namespace = mctx.Namespace().Path |
| 462 | } |
| 463 | (*deps)[mctx.Module().Name()].Arch = append((*deps)[mctx.Module().Name()].Arch, mctx.Module().Target().Arch.ArchType) |
| 464 | } else { |
| 465 | multilib, _ := mctx.Module().DecodeMultilib(mctx) |
| 466 | (*deps)[mctx.Module().Name()] = &depCandidateProps{ |
| 467 | Namespace: mctx.Namespace().Path, |
| 468 | Multilib: multilib, |
| 469 | Arch: []android.ArchType{mctx.Module().Target().Arch.ArchType}, |
| 470 | } |
| 471 | } |
| 472 | } |
mrziwang | 8f86c88 | 2024-10-03 12:34:33 -0700 | [diff] [blame] | 473 | |
| 474 | func collectDepsMutator(mctx android.BottomUpMutatorContext) { |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 475 | fsGenState := mctx.Config().Get(fsGenStateOnceKey).(*FsGenState) |
mrziwang | 8f86c88 | 2024-10-03 12:34:33 -0700 | [diff] [blame] | 476 | |
| 477 | m := mctx.Module() |
Spandan Das | fcc07c0 | 2024-10-21 23:33:43 +0000 | [diff] [blame] | 478 | if m.Target().Os.Class == android.Device && slices.Contains(fsGenState.depCandidates, m.Name()) { |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 479 | installPartition := m.PartitionTag(mctx.DeviceConfig()) |
| 480 | fsGenState.fsDepsMutex.Lock() |
| 481 | // Only add the module as dependency when: |
| 482 | // - its enabled |
| 483 | // - its namespace is included in PRODUCT_SOONG_NAMESPACES |
| 484 | if m.Enabled(mctx) && m.ExportedToMake() { |
| 485 | appendDepIfAppropriate(mctx, fsGenState.fsDeps[installPartition], installPartition) |
| 486 | } |
| 487 | fsGenState.fsDepsMutex.Unlock() |
| 488 | } |
Spandan Das | e1860e4 | 2024-10-24 22:29:50 +0000 | [diff] [blame] | 489 | // store the map of module to (required,overrides) even if the module is not in PRODUCT_PACKAGES. |
| 490 | // the module might be installed transitively. |
| 491 | if m.Target().Os.Class == android.Device && m.Enabled(mctx) && m.ExportedToMake() { |
| 492 | fsGenState.fsDepsMutex.Lock() |
| 493 | fsGenState.moduleToInstallationProps[m.Name()] = installationProperties{ |
| 494 | Required: m.RequiredModuleNames(mctx), |
| 495 | Overrides: m.Overrides(), |
| 496 | } |
| 497 | fsGenState.fsDepsMutex.Unlock() |
| 498 | } |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 499 | } |
| 500 | |
| 501 | type depsStruct struct { |
| 502 | Deps []string |
| 503 | } |
| 504 | |
| 505 | type multilibDepsStruct struct { |
| 506 | Common depsStruct |
| 507 | Lib32 depsStruct |
| 508 | Lib64 depsStruct |
| 509 | Both depsStruct |
| 510 | Prefer32 depsStruct |
| 511 | } |
| 512 | |
| 513 | type packagingPropsStruct struct { |
Jihoon Kang | 26cfe3c | 2024-10-30 18:53:51 +0000 | [diff] [blame] | 514 | High_priority_deps []string |
| 515 | Deps []string |
| 516 | Multilib multilibDepsStruct |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 517 | } |
| 518 | |
| 519 | func fullyQualifiedModuleName(moduleName, namespace string) string { |
| 520 | if namespace == "." { |
| 521 | return moduleName |
| 522 | } |
| 523 | return fmt.Sprintf("//%s:%s", namespace, moduleName) |
| 524 | } |
| 525 | |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 526 | func getBitness(archTypes []android.ArchType) (ret []string) { |
| 527 | for _, archType := range archTypes { |
| 528 | if archType.Multilib == "" { |
| 529 | ret = append(ret, android.COMMON_VARIANT) |
| 530 | } else { |
| 531 | ret = append(ret, archType.Bitness()) |
| 532 | } |
| 533 | } |
| 534 | return ret |
| 535 | } |
| 536 | |
| 537 | func setDepsMutator(mctx android.BottomUpMutatorContext) { |
Spandan Das | e1860e4 | 2024-10-24 22:29:50 +0000 | [diff] [blame] | 538 | removeOverriddenDeps(mctx) |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 539 | fsGenState := mctx.Config().Get(fsGenStateOnceKey).(*FsGenState) |
| 540 | fsDeps := fsGenState.fsDeps |
| 541 | soongGeneratedPartitionMap := getAllSoongGeneratedPartitionNames(mctx.Config(), fsGenState.soongGeneratedPartitions) |
| 542 | m := mctx.Module() |
| 543 | if partition, ok := soongGeneratedPartitionMap[m.Name()]; ok { |
mrziwang | 2a506cf | 2024-10-17 15:38:37 -0700 | [diff] [blame] | 544 | depsStruct := generateDepStruct(*fsDeps[partition]) |
| 545 | if err := proptools.AppendMatchingProperties(m.GetProperties(), depsStruct, nil); err != nil { |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 546 | mctx.ModuleErrorf(err.Error()) |
mrziwang | 8f86c88 | 2024-10-03 12:34:33 -0700 | [diff] [blame] | 547 | } |
| 548 | } |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 549 | } |
| 550 | |
Spandan Das | e1860e4 | 2024-10-24 22:29:50 +0000 | [diff] [blame] | 551 | // removeOverriddenDeps collects PRODUCT_PACKAGES and (transitive) required deps. |
| 552 | // it then removes any modules which appear in `overrides` of the above list. |
| 553 | func removeOverriddenDeps(mctx android.BottomUpMutatorContext) { |
| 554 | mctx.Config().Once(fsGenRemoveOverridesOnceKey, func() interface{} { |
| 555 | fsGenState := mctx.Config().Get(fsGenStateOnceKey).(*FsGenState) |
| 556 | fsDeps := fsGenState.fsDeps |
| 557 | overridden := map[string]bool{} |
| 558 | allDeps := []string{} |
| 559 | |
| 560 | // Step 1: Initialization: Append PRODUCT_PACKAGES to the queue |
| 561 | for _, fsDep := range fsDeps { |
| 562 | for depName, _ := range *fsDep { |
| 563 | allDeps = append(allDeps, depName) |
| 564 | } |
| 565 | } |
| 566 | |
| 567 | // Step 2: Process the queue, and add required modules to the queue. |
| 568 | i := 0 |
| 569 | for { |
| 570 | if i == len(allDeps) { |
| 571 | break |
| 572 | } |
| 573 | depName := allDeps[i] |
| 574 | for _, overrides := range fsGenState.moduleToInstallationProps[depName].Overrides { |
| 575 | overridden[overrides] = true |
| 576 | } |
| 577 | // add required dep to the queue. |
| 578 | allDeps = append(allDeps, fsGenState.moduleToInstallationProps[depName].Required...) |
| 579 | i += 1 |
| 580 | } |
| 581 | |
| 582 | // Step 3: Delete all the overridden modules. |
| 583 | for overridden, _ := range overridden { |
| 584 | for partition, _ := range fsDeps { |
| 585 | delete(*fsDeps[partition], overridden) |
| 586 | } |
| 587 | } |
| 588 | return nil |
| 589 | }) |
| 590 | } |
| 591 | |
Jihoon Kang | 26cfe3c | 2024-10-30 18:53:51 +0000 | [diff] [blame] | 592 | var HighPriorityDeps = []string{} |
| 593 | |
mrziwang | 2a506cf | 2024-10-17 15:38:37 -0700 | [diff] [blame] | 594 | func generateDepStruct(deps map[string]*depCandidateProps) *packagingPropsStruct { |
| 595 | depsStruct := packagingPropsStruct{} |
| 596 | for depName, depProps := range deps { |
| 597 | bitness := getBitness(depProps.Arch) |
| 598 | fullyQualifiedDepName := fullyQualifiedModuleName(depName, depProps.Namespace) |
Jihoon Kang | 26cfe3c | 2024-10-30 18:53:51 +0000 | [diff] [blame] | 599 | if android.InList(depName, HighPriorityDeps) { |
| 600 | depsStruct.High_priority_deps = append(depsStruct.High_priority_deps, fullyQualifiedDepName) |
| 601 | } else if android.InList("32", bitness) && android.InList("64", bitness) { |
mrziwang | 2a506cf | 2024-10-17 15:38:37 -0700 | [diff] [blame] | 602 | // If both 32 and 64 bit variants are enabled for this module |
| 603 | switch depProps.Multilib { |
| 604 | case string(android.MultilibBoth): |
| 605 | depsStruct.Multilib.Both.Deps = append(depsStruct.Multilib.Both.Deps, fullyQualifiedDepName) |
| 606 | case string(android.MultilibCommon), string(android.MultilibFirst): |
| 607 | depsStruct.Deps = append(depsStruct.Deps, fullyQualifiedDepName) |
| 608 | case "32": |
| 609 | depsStruct.Multilib.Lib32.Deps = append(depsStruct.Multilib.Lib32.Deps, fullyQualifiedDepName) |
| 610 | case "64", "darwin_universal": |
| 611 | depsStruct.Multilib.Lib64.Deps = append(depsStruct.Multilib.Lib64.Deps, fullyQualifiedDepName) |
| 612 | case "prefer32", "first_prefer32": |
| 613 | depsStruct.Multilib.Prefer32.Deps = append(depsStruct.Multilib.Prefer32.Deps, fullyQualifiedDepName) |
| 614 | default: |
| 615 | depsStruct.Multilib.Both.Deps = append(depsStruct.Multilib.Both.Deps, fullyQualifiedDepName) |
| 616 | } |
| 617 | } else if android.InList("64", bitness) { |
| 618 | // If only 64 bit variant is enabled |
| 619 | depsStruct.Multilib.Lib64.Deps = append(depsStruct.Multilib.Lib64.Deps, fullyQualifiedDepName) |
| 620 | } else if android.InList("32", bitness) { |
| 621 | // If only 32 bit variant is enabled |
| 622 | depsStruct.Multilib.Lib32.Deps = append(depsStruct.Multilib.Lib32.Deps, fullyQualifiedDepName) |
| 623 | } else { |
| 624 | // If only common variant is enabled |
| 625 | depsStruct.Multilib.Common.Deps = append(depsStruct.Multilib.Common.Deps, fullyQualifiedDepName) |
| 626 | } |
| 627 | } |
Jihoon Kang | 4e5d8de | 2024-10-19 01:59:58 +0000 | [diff] [blame] | 628 | depsStruct.Deps = android.SortedUniqueStrings(depsStruct.Deps) |
| 629 | depsStruct.Multilib.Lib32.Deps = android.SortedUniqueStrings(depsStruct.Multilib.Lib32.Deps) |
| 630 | depsStruct.Multilib.Lib64.Deps = android.SortedUniqueStrings(depsStruct.Multilib.Lib64.Deps) |
| 631 | depsStruct.Multilib.Prefer32.Deps = android.SortedUniqueStrings(depsStruct.Multilib.Prefer32.Deps) |
| 632 | depsStruct.Multilib.Both.Deps = android.SortedUniqueStrings(depsStruct.Multilib.Both.Deps) |
| 633 | depsStruct.Multilib.Common.Deps = android.SortedUniqueStrings(depsStruct.Multilib.Common.Deps) |
| 634 | |
mrziwang | 2a506cf | 2024-10-17 15:38:37 -0700 | [diff] [blame] | 635 | return &depsStruct |
| 636 | } |
| 637 | |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 638 | type filesystemCreatorProps struct { |
| 639 | Generated_partition_types []string `blueprint:"mutated"` |
| 640 | Unsupported_partition_types []string `blueprint:"mutated"` |
| 641 | } |
| 642 | |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 643 | type filesystemCreator struct { |
| 644 | android.ModuleBase |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 645 | |
| 646 | properties filesystemCreatorProps |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 647 | } |
| 648 | |
| 649 | func filesystemCreatorFactory() android.Module { |
| 650 | module := &filesystemCreator{} |
| 651 | |
Cole Faust | 6978879 | 2024-10-10 11:00:36 -0700 | [diff] [blame] | 652 | android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibCommon) |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 653 | module.AddProperties(&module.properties) |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 654 | android.AddLoadHook(module, func(ctx android.LoadHookContext) { |
Jihoon Kang | 675d468 | 2024-10-24 23:45:11 +0000 | [diff] [blame^] | 655 | generatedPrebuiltEtcModuleNames := createPrebuiltEtcModules(ctx) |
| 656 | createFsGenState(ctx, generatedPrebuiltEtcModuleNames) |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 657 | module.createInternalModules(ctx) |
| 658 | }) |
| 659 | |
| 660 | return module |
| 661 | } |
| 662 | |
| 663 | func (f *filesystemCreator) createInternalModules(ctx android.LoadHookContext) { |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 664 | soongGeneratedPartitions := &ctx.Config().Get(fsGenStateOnceKey).(*FsGenState).soongGeneratedPartitions |
| 665 | for _, partitionType := range *soongGeneratedPartitions { |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 666 | if f.createPartition(ctx, partitionType) { |
| 667 | f.properties.Generated_partition_types = append(f.properties.Generated_partition_types, partitionType) |
| 668 | } else { |
| 669 | f.properties.Unsupported_partition_types = append(f.properties.Unsupported_partition_types, partitionType) |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 670 | _, *soongGeneratedPartitions = android.RemoveFromList(partitionType, *soongGeneratedPartitions) |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 671 | } |
| 672 | } |
Jihoon Kang | f1c79ca | 2024-10-09 20:18:38 +0000 | [diff] [blame] | 673 | f.createDeviceModule(ctx) |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 674 | } |
| 675 | |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 676 | func generatedModuleName(cfg android.Config, suffix string) string { |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 677 | prefix := "soong" |
| 678 | if cfg.HasDeviceProduct() { |
| 679 | prefix = cfg.DeviceProduct() |
| 680 | } |
Jihoon Kang | f1c79ca | 2024-10-09 20:18:38 +0000 | [diff] [blame] | 681 | return fmt.Sprintf("%s_generated_%s", prefix, suffix) |
| 682 | } |
| 683 | |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 684 | func generatedModuleNameForPartition(cfg android.Config, partitionType string) string { |
| 685 | return generatedModuleName(cfg, fmt.Sprintf("%s_image", partitionType)) |
Jihoon Kang | f1c79ca | 2024-10-09 20:18:38 +0000 | [diff] [blame] | 686 | } |
| 687 | |
| 688 | func (f *filesystemCreator) createDeviceModule(ctx android.LoadHookContext) { |
| 689 | baseProps := &struct { |
| 690 | Name *string |
| 691 | }{ |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 692 | Name: proptools.StringPtr(generatedModuleName(ctx.Config(), "device")), |
Jihoon Kang | f1c79ca | 2024-10-09 20:18:38 +0000 | [diff] [blame] | 693 | } |
| 694 | |
Priyanka Advani (xWF) | dafaa7f | 2024-10-21 22:55:13 +0000 | [diff] [blame] | 695 | // Currently, only the system and system_ext partition module is created. |
Jihoon Kang | f1c79ca | 2024-10-09 20:18:38 +0000 | [diff] [blame] | 696 | partitionProps := &filesystem.PartitionNameProperties{} |
| 697 | if android.InList("system", f.properties.Generated_partition_types) { |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 698 | partitionProps.System_partition_name = proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "system")) |
Jihoon Kang | f1c79ca | 2024-10-09 20:18:38 +0000 | [diff] [blame] | 699 | } |
Spandan Das | 7a46f6c | 2024-10-14 18:41:18 +0000 | [diff] [blame] | 700 | if android.InList("system_ext", f.properties.Generated_partition_types) { |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 701 | partitionProps.System_ext_partition_name = proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "system_ext")) |
Spandan Das | 7a46f6c | 2024-10-14 18:41:18 +0000 | [diff] [blame] | 702 | } |
Spandan Das | e3b6531 | 2024-10-22 00:27:27 +0000 | [diff] [blame] | 703 | if android.InList("vendor", f.properties.Generated_partition_types) { |
| 704 | partitionProps.Vendor_partition_name = proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "vendor")) |
| 705 | } |
Jihoon Kang | 6dd13b6 | 2024-10-22 23:21:02 +0000 | [diff] [blame] | 706 | if android.InList("product", f.properties.Generated_partition_types) { |
| 707 | partitionProps.Product_partition_name = proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "product")) |
| 708 | } |
Spandan Das | c571716 | 2024-11-01 18:33:57 +0000 | [diff] [blame] | 709 | if android.InList("odm", f.properties.Generated_partition_types) { |
| 710 | partitionProps.Odm_partition_name = proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "odm")) |
| 711 | } |
Jihoon Kang | f1c79ca | 2024-10-09 20:18:38 +0000 | [diff] [blame] | 712 | |
| 713 | ctx.CreateModule(filesystem.AndroidDeviceFactory, baseProps, partitionProps) |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 714 | } |
| 715 | |
Jihoon Kang | 6850d8f | 2024-10-17 20:45:58 +0000 | [diff] [blame] | 716 | func partitionSpecificFsProps(fsProps *filesystem.FilesystemProperties, partitionType string) { |
| 717 | switch partitionType { |
| 718 | case "system": |
| 719 | fsProps.Build_logtags = proptools.BoolPtr(true) |
| 720 | // https://source.corp.google.com/h/googleplex-android/platform/build//639d79f5012a6542ab1f733b0697db45761ab0f3:core/packaging/flags.mk;l=21;drc=5ba8a8b77507f93aa48cc61c5ba3f31a4d0cbf37;bpv=1;bpt=0 |
| 721 | fsProps.Gen_aconfig_flags_pb = proptools.BoolPtr(true) |
Spandan Das | a8fa6b4 | 2024-10-23 00:45:29 +0000 | [diff] [blame] | 722 | // Identical to that of the generic_system_image |
| 723 | fsProps.Fsverity.Inputs = []string{ |
| 724 | "etc/boot-image.prof", |
| 725 | "etc/dirty-image-objects", |
| 726 | "etc/preloaded-classes", |
| 727 | "etc/classpaths/*.pb", |
| 728 | "framework/*", |
| 729 | "framework/*/*", // framework/{arch} |
| 730 | "framework/oat/*/*", // framework/oat/{arch} |
| 731 | } |
| 732 | fsProps.Fsverity.Libs = []string{":framework-res{.export-package.apk}"} |
| 733 | case "system_ext": |
| 734 | fsProps.Fsverity.Inputs = []string{ |
| 735 | "framework/*", |
| 736 | "framework/*/*", // framework/{arch} |
| 737 | "framework/oat/*/*", // framework/oat/{arch} |
| 738 | } |
| 739 | fsProps.Fsverity.Libs = []string{":framework-res{.export-package.apk}"} |
Jihoon Kang | 6850d8f | 2024-10-17 20:45:58 +0000 | [diff] [blame] | 740 | case "product": |
| 741 | fsProps.Gen_aconfig_flags_pb = proptools.BoolPtr(true) |
| 742 | case "vendor": |
| 743 | fsProps.Gen_aconfig_flags_pb = proptools.BoolPtr(true) |
Spandan Das | 69464c3 | 2024-10-25 20:08:06 +0000 | [diff] [blame] | 744 | fsProps.Symlinks = []filesystem.SymlinkDefinition{ |
| 745 | filesystem.SymlinkDefinition{ |
| 746 | Target: proptools.StringPtr("/odm"), |
| 747 | Name: proptools.StringPtr("vendor/odm"), |
| 748 | }, |
| 749 | filesystem.SymlinkDefinition{ |
| 750 | Target: proptools.StringPtr("/vendor_dlkm/lib/modules"), |
| 751 | Name: proptools.StringPtr("vendor/lib/modules"), |
| 752 | }, |
| 753 | } |
| 754 | fsProps.Base_dir = proptools.StringPtr("vendor") |
Spandan Das | c571716 | 2024-11-01 18:33:57 +0000 | [diff] [blame] | 755 | case "odm": |
| 756 | fsProps.Symlinks = []filesystem.SymlinkDefinition{ |
| 757 | filesystem.SymlinkDefinition{ |
| 758 | Target: proptools.StringPtr("/odm_dlkm/lib/modules"), |
| 759 | Name: proptools.StringPtr("odm/lib/modules"), |
| 760 | }, |
| 761 | } |
| 762 | fsProps.Base_dir = proptools.StringPtr("odm") |
| 763 | |
Jihoon Kang | 6850d8f | 2024-10-17 20:45:58 +0000 | [diff] [blame] | 764 | } |
| 765 | } |
Spandan Das | cbe641a | 2024-10-14 21:07:34 +0000 | [diff] [blame] | 766 | |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 767 | // Creates a soong module to build the given partition. Returns false if we can't support building |
| 768 | // it. |
| 769 | func (f *filesystemCreator) createPartition(ctx android.LoadHookContext, partitionType string) bool { |
mrziwang | 4b0ca97 | 2024-10-17 14:56:19 -0700 | [diff] [blame] | 770 | baseProps := generateBaseProps(proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), partitionType))) |
| 771 | |
| 772 | fsProps, supported := generateFsProps(ctx, partitionType) |
| 773 | if !supported { |
| 774 | return false |
mrziwang | a077b94 | 2024-10-16 16:00:06 -0700 | [diff] [blame] | 775 | } |
mrziwang | a077b94 | 2024-10-16 16:00:06 -0700 | [diff] [blame] | 776 | |
Spandan Das | 8fe68dc | 2024-10-29 18:20:11 +0000 | [diff] [blame] | 777 | if partitionType == "vendor" || partitionType == "product" { |
Spandan Das | 173256b | 2024-10-31 19:59:30 +0000 | [diff] [blame] | 778 | fsProps.Linkerconfig.Gen_linker_config = proptools.BoolPtr(true) |
| 779 | fsProps.Linkerconfig.Linker_config_srcs = f.createLinkerConfigSourceFilegroups(ctx, partitionType) |
Spandan Das | 312cc41 | 2024-10-29 18:20:11 +0000 | [diff] [blame] | 780 | } |
| 781 | |
Spandan Das | 5e33642 | 2024-11-01 22:31:20 +0000 | [diff] [blame] | 782 | if partitionType == "system_dlkm" { |
| 783 | kernelModules := ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse.SystemKernelModules |
| 784 | f.createPrebuiltKernelModules(ctx, partitionType, kernelModules) |
| 785 | } |
| 786 | |
mrziwang | 4b0ca97 | 2024-10-17 14:56:19 -0700 | [diff] [blame] | 787 | var module android.Module |
| 788 | if partitionType == "system" { |
| 789 | module = ctx.CreateModule(filesystem.SystemImageFactory, baseProps, fsProps) |
Spandan Das | 5e33642 | 2024-11-01 22:31:20 +0000 | [diff] [blame] | 790 | } else if partitionType == "system_dlkm" { |
| 791 | // Do not set partition_type. build/soong/android/paths#modulePartition currently does not support dlkm |
| 792 | // partitions. Since `android_filesystem` uses a partition based filter, setting the partition here |
| 793 | // would result in missing in entries. |
| 794 | module = ctx.CreateModule(filesystem.FilesystemFactory, baseProps, fsProps) |
mrziwang | 4b0ca97 | 2024-10-17 14:56:19 -0700 | [diff] [blame] | 795 | } else { |
| 796 | // Explicitly set the partition. |
| 797 | fsProps.Partition_type = proptools.StringPtr(partitionType) |
| 798 | module = ctx.CreateModule(filesystem.FilesystemFactory, baseProps, fsProps) |
| 799 | } |
| 800 | module.HideFromMake() |
Spandan Das | 168098c | 2024-10-28 19:44:34 +0000 | [diff] [blame] | 801 | if partitionType == "vendor" { |
| 802 | // Create a build prop for vendor |
| 803 | vendorBuildProps := &struct { |
| 804 | Name *string |
| 805 | Vendor *bool |
| 806 | Stem *string |
| 807 | Product_config *string |
| 808 | }{ |
| 809 | Name: proptools.StringPtr(generatedModuleName(ctx.Config(), "vendor-build.prop")), |
| 810 | Vendor: proptools.BoolPtr(true), |
| 811 | Stem: proptools.StringPtr("build.prop"), |
| 812 | Product_config: proptools.StringPtr(":product_config"), |
| 813 | } |
| 814 | vendorBuildProp := ctx.CreateModule( |
| 815 | android.BuildPropFactory, |
| 816 | vendorBuildProps, |
| 817 | ) |
| 818 | vendorBuildProp.HideFromMake() |
| 819 | } |
mrziwang | 4b0ca97 | 2024-10-17 14:56:19 -0700 | [diff] [blame] | 820 | return true |
| 821 | } |
| 822 | |
Spandan Das | 5e33642 | 2024-11-01 22:31:20 +0000 | [diff] [blame] | 823 | // createPrebuiltKernelModules creates `prebuilt_kernel_modules`. These modules will be added to deps of the |
| 824 | // autogenerated *_dlkm filsystem modules. |
| 825 | // The input `kernelModules` is a space separated list of .ko files in the workspace. This will be partitioned per directory |
| 826 | // and a `prebuilt_kernel_modules` will be created per partition. |
| 827 | // These autogenerated modules will be subsequently added to the deps of the top level *_dlkm android_filesystem |
| 828 | func (f *filesystemCreator) createPrebuiltKernelModules(ctx android.LoadHookContext, partitionType string, kernelModules []string) { |
| 829 | // Partition the files per directory |
| 830 | dirToFiles := map[string][]string{} |
| 831 | for _, kernelModule := range kernelModules { |
| 832 | dir := filepath.Dir(kernelModule) |
| 833 | base := filepath.Base(kernelModule) |
| 834 | dirToFiles[dir] = append(dirToFiles[dir], base) |
| 835 | } |
| 836 | // Create a prebuilt_kernel_modules module per partition |
| 837 | fsGenState := ctx.Config().Get(fsGenStateOnceKey).(*FsGenState) |
| 838 | for index, dir := range android.SortedKeys(dirToFiles) { |
| 839 | name := generatedModuleName(ctx.Config(), fmt.Sprintf("%s-kernel-modules-%s", partitionType, strconv.Itoa(index))) |
| 840 | props := &struct { |
| 841 | Name *string |
| 842 | Srcs []string |
| 843 | }{ |
| 844 | Name: proptools.StringPtr(name), |
| 845 | Srcs: dirToFiles[dir], |
| 846 | } |
| 847 | kernelModule := ctx.CreateModuleInDirectory( |
| 848 | kernel.PrebuiltKernelModulesFactory, |
| 849 | dir, |
| 850 | props, |
| 851 | ) |
| 852 | kernelModule.HideFromMake() |
| 853 | // Add to deps |
| 854 | (*fsGenState.fsDeps[partitionType])[name] = defaultDepCandidateProps(ctx.Config()) |
| 855 | } |
| 856 | } |
| 857 | |
Spandan Das | 8fe68dc | 2024-10-29 18:20:11 +0000 | [diff] [blame] | 858 | // createLinkerConfigSourceFilegroups creates filegroup modules to generate linker.config.pb for the following partitions |
| 859 | // 1. vendor: Using PRODUCT_VENDOR_LINKER_CONFIG_FRAGMENTS (space separated file list) |
| 860 | // 1. product: Using PRODUCT_PRODUCT_LINKER_CONFIG_FRAGMENTS (space separated file list) |
| 861 | // It creates a filegroup for each file in the fragment list |
Spandan Das | 312cc41 | 2024-10-29 18:20:11 +0000 | [diff] [blame] | 862 | // The filegroup modules are then added to `linker_config_srcs` of the autogenerated vendor `android_filesystem`. |
Spandan Das | 8fe68dc | 2024-10-29 18:20:11 +0000 | [diff] [blame] | 863 | func (f *filesystemCreator) createLinkerConfigSourceFilegroups(ctx android.LoadHookContext, partitionType string) []string { |
Spandan Das | 312cc41 | 2024-10-29 18:20:11 +0000 | [diff] [blame] | 864 | ret := []string{} |
| 865 | partitionVars := ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse |
Spandan Das | 8fe68dc | 2024-10-29 18:20:11 +0000 | [diff] [blame] | 866 | var linkerConfigSrcs []string |
| 867 | if partitionType == "vendor" { |
| 868 | linkerConfigSrcs = android.FirstUniqueStrings(partitionVars.VendorLinkerConfigSrcs) |
| 869 | } else if partitionType == "product" { |
| 870 | linkerConfigSrcs = android.FirstUniqueStrings(partitionVars.ProductLinkerConfigSrcs) |
| 871 | } else { |
| 872 | ctx.ModuleErrorf("linker.config.pb is only supported for vendor and product partitions. For system partition, use `android_system_image`") |
| 873 | } |
| 874 | |
| 875 | if len(linkerConfigSrcs) > 0 { |
Spandan Das | 312cc41 | 2024-10-29 18:20:11 +0000 | [diff] [blame] | 876 | // Create a filegroup, and add `:<filegroup_name>` to ret. |
| 877 | for index, linkerConfigSrc := range linkerConfigSrcs { |
| 878 | dir := filepath.Dir(linkerConfigSrc) |
| 879 | base := filepath.Base(linkerConfigSrc) |
Spandan Das | 8fe68dc | 2024-10-29 18:20:11 +0000 | [diff] [blame] | 880 | fgName := generatedModuleName(ctx.Config(), fmt.Sprintf("%s-linker-config-src%s", partitionType, strconv.Itoa(index))) |
Spandan Das | 312cc41 | 2024-10-29 18:20:11 +0000 | [diff] [blame] | 881 | srcs := []string{base} |
| 882 | fgProps := &struct { |
| 883 | Name *string |
| 884 | Srcs proptools.Configurable[[]string] |
| 885 | }{ |
| 886 | Name: proptools.StringPtr(fgName), |
| 887 | Srcs: proptools.NewSimpleConfigurable(srcs), |
| 888 | } |
| 889 | ctx.CreateModuleInDirectory( |
| 890 | android.FileGroupFactory, |
| 891 | dir, |
| 892 | fgProps, |
| 893 | ) |
| 894 | ret = append(ret, ":"+fgName) |
| 895 | } |
| 896 | } |
| 897 | return ret |
| 898 | } |
| 899 | |
mrziwang | 4b0ca97 | 2024-10-17 14:56:19 -0700 | [diff] [blame] | 900 | type filesystemBaseProperty struct { |
| 901 | Name *string |
| 902 | Compile_multilib *string |
| 903 | } |
| 904 | |
| 905 | func generateBaseProps(namePtr *string) *filesystemBaseProperty { |
| 906 | return &filesystemBaseProperty{ |
| 907 | Name: namePtr, |
| 908 | Compile_multilib: proptools.StringPtr("both"), |
| 909 | } |
| 910 | } |
| 911 | |
| 912 | func generateFsProps(ctx android.EarlyModuleContext, partitionType string) (*filesystem.FilesystemProperties, bool) { |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 913 | fsProps := &filesystem.FilesystemProperties{} |
| 914 | |
mrziwang | 4b0ca97 | 2024-10-17 14:56:19 -0700 | [diff] [blame] | 915 | partitionVars := ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse |
| 916 | specificPartitionVars := partitionVars.PartitionQualifiedVariables[partitionType] |
| 917 | |
| 918 | // BOARD_SYSTEMIMAGE_FILE_SYSTEM_TYPE |
| 919 | fsType := specificPartitionVars.BoardFileSystemType |
| 920 | if fsType == "" { |
| 921 | fsType = "ext4" //default |
| 922 | } |
| 923 | fsProps.Type = proptools.StringPtr(fsType) |
| 924 | if filesystem.GetFsTypeFromString(ctx, *fsProps.Type).IsUnknown() { |
| 925 | // Currently the android_filesystem module type only supports a handful of FS types like ext4, erofs |
| 926 | return nil, false |
| 927 | } |
| 928 | |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 929 | // Don't build this module on checkbuilds, the soong-built partitions are still in-progress |
| 930 | // and sometimes don't build. |
| 931 | fsProps.Unchecked_module = proptools.BoolPtr(true) |
| 932 | |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 933 | // BOARD_AVB_ENABLE |
| 934 | fsProps.Use_avb = proptools.BoolPtr(partitionVars.BoardAvbEnable) |
| 935 | // BOARD_AVB_KEY_PATH |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 936 | fsProps.Avb_private_key = proptools.StringPtr(specificPartitionVars.BoardAvbKeyPath) |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 937 | // BOARD_AVB_ALGORITHM |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 938 | fsProps.Avb_algorithm = proptools.StringPtr(specificPartitionVars.BoardAvbAlgorithm) |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 939 | // BOARD_AVB_SYSTEM_ROLLBACK_INDEX |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 940 | if rollbackIndex, err := strconv.ParseInt(specificPartitionVars.BoardAvbRollbackIndex, 10, 64); err == nil { |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 941 | fsProps.Rollback_index = proptools.Int64Ptr(rollbackIndex) |
| 942 | } |
| 943 | |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 944 | fsProps.Partition_name = proptools.StringPtr(partitionType) |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 945 | |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 946 | fsProps.Base_dir = proptools.StringPtr(partitionType) |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 947 | |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 948 | fsProps.Is_auto_generated = proptools.BoolPtr(true) |
| 949 | |
Jihoon Kang | 6850d8f | 2024-10-17 20:45:58 +0000 | [diff] [blame] | 950 | partitionSpecificFsProps(fsProps, partitionType) |
| 951 | |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 952 | // system_image properties that are not set: |
| 953 | // - filesystemProperties.Avb_hash_algorithm |
| 954 | // - filesystemProperties.File_contexts |
| 955 | // - filesystemProperties.Dirs |
| 956 | // - filesystemProperties.Symlinks |
| 957 | // - filesystemProperties.Fake_timestamp |
| 958 | // - filesystemProperties.Uuid |
| 959 | // - filesystemProperties.Mount_point |
| 960 | // - filesystemProperties.Include_make_built_files |
| 961 | // - filesystemProperties.Build_logtags |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 962 | // - systemImageProperties.Linker_config_src |
mrziwang | 4b0ca97 | 2024-10-17 14:56:19 -0700 | [diff] [blame] | 963 | |
| 964 | return fsProps, true |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 965 | } |
| 966 | |
| 967 | func (f *filesystemCreator) createDiffTest(ctx android.ModuleContext, partitionType string) android.Path { |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 968 | partitionModuleName := generatedModuleNameForPartition(ctx.Config(), partitionType) |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 969 | systemImage := ctx.GetDirectDepWithTag(partitionModuleName, generatedFilesystemDepTag) |
| 970 | filesystemInfo, ok := android.OtherModuleProvider(ctx, systemImage, filesystem.FilesystemProvider) |
| 971 | if !ok { |
| 972 | ctx.ModuleErrorf("Expected module %s to provide FileysystemInfo", partitionModuleName) |
| 973 | } |
| 974 | makeFileList := android.PathForArbitraryOutput(ctx, fmt.Sprintf("target/product/%s/obj/PACKAGING/%s_intermediates/file_list.txt", ctx.Config().DeviceName(), partitionType)) |
| 975 | // For now, don't allowlist anything. The test will fail, but that's fine in the current |
| 976 | // early stages where we're just figuring out what we need |
Jihoon Kang | 9e866c8 | 2024-10-07 22:39:18 +0000 | [diff] [blame] | 977 | emptyAllowlistFile := android.PathForModuleOut(ctx, fmt.Sprintf("allowlist_%s.txt", partitionModuleName)) |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 978 | android.WriteFileRule(ctx, emptyAllowlistFile, "") |
Jihoon Kang | 9e866c8 | 2024-10-07 22:39:18 +0000 | [diff] [blame] | 979 | diffTestResultFile := android.PathForModuleOut(ctx, fmt.Sprintf("diff_test_%s.txt", partitionModuleName)) |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 980 | |
| 981 | builder := android.NewRuleBuilder(pctx, ctx) |
| 982 | builder.Command().BuiltTool("file_list_diff"). |
| 983 | Input(makeFileList). |
| 984 | Input(filesystemInfo.FileListFile). |
Jihoon Kang | 9e866c8 | 2024-10-07 22:39:18 +0000 | [diff] [blame] | 985 | Text(partitionModuleName). |
| 986 | FlagWithInput("--allowlists ", emptyAllowlistFile) |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 987 | builder.Command().Text("touch").Output(diffTestResultFile) |
| 988 | builder.Build(partitionModuleName+" diff test", partitionModuleName+" diff test") |
| 989 | return diffTestResultFile |
| 990 | } |
| 991 | |
| 992 | func createFailingCommand(ctx android.ModuleContext, message string) android.Path { |
| 993 | hasher := sha256.New() |
| 994 | hasher.Write([]byte(message)) |
| 995 | filename := fmt.Sprintf("failing_command_%x.txt", hasher.Sum(nil)) |
| 996 | file := android.PathForModuleOut(ctx, filename) |
| 997 | builder := android.NewRuleBuilder(pctx, ctx) |
| 998 | builder.Command().Textf("echo %s", proptools.NinjaAndShellEscape(message)) |
| 999 | builder.Command().Text("exit 1 #").Output(file) |
| 1000 | builder.Build("failing command "+filename, "failing command "+filename) |
| 1001 | return file |
| 1002 | } |
| 1003 | |
| 1004 | type systemImageDepTagType struct { |
| 1005 | blueprint.BaseDependencyTag |
| 1006 | } |
| 1007 | |
| 1008 | var generatedFilesystemDepTag systemImageDepTagType |
| 1009 | |
| 1010 | func (f *filesystemCreator) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 1011 | for _, partitionType := range f.properties.Generated_partition_types { |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 1012 | ctx.AddDependency(ctx.Module(), generatedFilesystemDepTag, generatedModuleNameForPartition(ctx.Config(), partitionType)) |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 1013 | } |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 1014 | } |
| 1015 | |
| 1016 | func (f *filesystemCreator) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 1017 | if ctx.ModuleDir() != "build/soong/fsgen" { |
| 1018 | ctx.ModuleErrorf("There can only be one soong_filesystem_creator in build/soong/fsgen") |
| 1019 | } |
| 1020 | f.HideFromMake() |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 1021 | |
Jihoon Kang | 4e5d8de | 2024-10-19 01:59:58 +0000 | [diff] [blame] | 1022 | var content strings.Builder |
| 1023 | generatedBp := android.PathForModuleOut(ctx, "soong_generated_product_config.bp") |
| 1024 | for _, partition := range ctx.Config().Get(fsGenStateOnceKey).(*FsGenState).soongGeneratedPartitions { |
| 1025 | content.WriteString(generateBpContent(ctx, partition)) |
| 1026 | content.WriteString("\n") |
| 1027 | } |
| 1028 | android.WriteFileRule(ctx, generatedBp, content.String()) |
| 1029 | |
mrziwang | 8f86c88 | 2024-10-03 12:34:33 -0700 | [diff] [blame] | 1030 | ctx.Phony("product_config_to_bp", generatedBp) |
| 1031 | |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 1032 | var diffTestFiles []android.Path |
| 1033 | for _, partitionType := range f.properties.Generated_partition_types { |
Jihoon Kang | 72f812f | 2024-10-17 18:46:24 +0000 | [diff] [blame] | 1034 | diffTestFile := f.createDiffTest(ctx, partitionType) |
| 1035 | diffTestFiles = append(diffTestFiles, diffTestFile) |
| 1036 | ctx.Phony(fmt.Sprintf("soong_generated_%s_filesystem_test", partitionType), diffTestFile) |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 1037 | } |
| 1038 | for _, partitionType := range f.properties.Unsupported_partition_types { |
Jihoon Kang | 72f812f | 2024-10-17 18:46:24 +0000 | [diff] [blame] | 1039 | diffTestFile := createFailingCommand(ctx, fmt.Sprintf("Couldn't build %s partition", partitionType)) |
| 1040 | diffTestFiles = append(diffTestFiles, diffTestFile) |
| 1041 | ctx.Phony(fmt.Sprintf("soong_generated_%s_filesystem_test", partitionType), diffTestFile) |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 1042 | } |
| 1043 | ctx.Phony("soong_generated_filesystem_tests", diffTestFiles...) |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 1044 | } |
mrziwang | 8f86c88 | 2024-10-03 12:34:33 -0700 | [diff] [blame] | 1045 | |
mrziwang | 8f86c88 | 2024-10-03 12:34:33 -0700 | [diff] [blame] | 1046 | func generateBpContent(ctx android.EarlyModuleContext, partitionType string) string { |
mrziwang | 4b0ca97 | 2024-10-17 14:56:19 -0700 | [diff] [blame] | 1047 | fsProps, fsTypeSupported := generateFsProps(ctx, partitionType) |
| 1048 | if !fsTypeSupported { |
| 1049 | return "" |
mrziwang | 8f86c88 | 2024-10-03 12:34:33 -0700 | [diff] [blame] | 1050 | } |
Spandan Das | c571716 | 2024-11-01 18:33:57 +0000 | [diff] [blame] | 1051 | if partitionType == "vendor" || partitionType == "odm" { |
Spandan Das | 69464c3 | 2024-10-25 20:08:06 +0000 | [diff] [blame] | 1052 | return "" // TODO: Handle struct props |
| 1053 | } |
mrziwang | 8f86c88 | 2024-10-03 12:34:33 -0700 | [diff] [blame] | 1054 | |
mrziwang | 4b0ca97 | 2024-10-17 14:56:19 -0700 | [diff] [blame] | 1055 | baseProps := generateBaseProps(proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), partitionType))) |
mrziwang | 2a506cf | 2024-10-17 15:38:37 -0700 | [diff] [blame] | 1056 | deps := ctx.Config().Get(fsGenStateOnceKey).(*FsGenState).fsDeps[partitionType] |
| 1057 | depProps := generateDepStruct(*deps) |
mrziwang | 8f86c88 | 2024-10-03 12:34:33 -0700 | [diff] [blame] | 1058 | |
mrziwang | 4b0ca97 | 2024-10-17 14:56:19 -0700 | [diff] [blame] | 1059 | result, err := proptools.RepackProperties([]interface{}{baseProps, fsProps, depProps}) |
mrziwang | 8f86c88 | 2024-10-03 12:34:33 -0700 | [diff] [blame] | 1060 | if err != nil { |
| 1061 | ctx.ModuleErrorf(err.Error()) |
| 1062 | } |
| 1063 | |
Jihoon Kang | 4e5d8de | 2024-10-19 01:59:58 +0000 | [diff] [blame] | 1064 | moduleType := "android_filesystem" |
| 1065 | if partitionType == "system" { |
| 1066 | moduleType = "android_system_image" |
| 1067 | } |
| 1068 | |
mrziwang | 8f86c88 | 2024-10-03 12:34:33 -0700 | [diff] [blame] | 1069 | file := &parser.File{ |
| 1070 | Defs: []parser.Definition{ |
| 1071 | &parser.Module{ |
Jihoon Kang | 4e5d8de | 2024-10-19 01:59:58 +0000 | [diff] [blame] | 1072 | Type: moduleType, |
mrziwang | 8f86c88 | 2024-10-03 12:34:33 -0700 | [diff] [blame] | 1073 | Map: *result, |
| 1074 | }, |
| 1075 | }, |
| 1076 | } |
| 1077 | bytes, err := parser.Print(file) |
| 1078 | if err != nil { |
| 1079 | ctx.ModuleErrorf(err.Error()) |
| 1080 | } |
| 1081 | return strings.TrimSpace(string(bytes)) |
| 1082 | } |