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