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" |
| 27 | "android/soong/filesystem" |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 28 | |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 29 | "github.com/google/blueprint" |
mrziwang | 8f86c88 | 2024-10-03 12:34:33 -0700 | [diff] [blame] | 30 | "github.com/google/blueprint/parser" |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 31 | "github.com/google/blueprint/proptools" |
| 32 | ) |
| 33 | |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 34 | var pctx = android.NewPackageContext("android/soong/fsgen") |
| 35 | |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 36 | func init() { |
| 37 | registerBuildComponents(android.InitRegistrationContext) |
| 38 | } |
| 39 | |
| 40 | func registerBuildComponents(ctx android.RegistrationContext) { |
| 41 | ctx.RegisterModuleType("soong_filesystem_creator", filesystemCreatorFactory) |
mrziwang | 8f86c88 | 2024-10-03 12:34:33 -0700 | [diff] [blame] | 42 | ctx.PreDepsMutators(RegisterCollectFileSystemDepsMutators) |
| 43 | } |
| 44 | |
| 45 | func RegisterCollectFileSystemDepsMutators(ctx android.RegisterMutatorsContext) { |
| 46 | ctx.BottomUp("fs_collect_deps", collectDepsMutator).MutatesGlobalState() |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 47 | ctx.BottomUp("fs_set_deps", setDepsMutator) |
mrziwang | 8f86c88 | 2024-10-03 12:34:33 -0700 | [diff] [blame] | 48 | } |
| 49 | |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 50 | var fsGenStateOnceKey = android.NewOnceKey("FsGenState") |
Spandan Das | e1860e4 | 2024-10-24 22:29:50 +0000 | [diff] [blame] | 51 | var fsGenRemoveOverridesOnceKey = android.NewOnceKey("FsGenRemoveOverrides") |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 52 | |
| 53 | // Map of partition module name to its partition that may be generated by Soong. |
| 54 | // Note that it is not guaranteed that all modules returned by this function are successfully |
| 55 | // created. |
| 56 | func getAllSoongGeneratedPartitionNames(config android.Config, partitions []string) map[string]string { |
| 57 | ret := map[string]string{} |
| 58 | for _, partition := range partitions { |
| 59 | ret[generatedModuleNameForPartition(config, partition)] = partition |
| 60 | } |
| 61 | return ret |
| 62 | } |
| 63 | |
| 64 | type depCandidateProps struct { |
| 65 | Namespace string |
| 66 | Multilib string |
| 67 | Arch []android.ArchType |
| 68 | } |
| 69 | |
| 70 | // Map of module name to depCandidateProps |
| 71 | type multilibDeps *map[string]*depCandidateProps |
| 72 | |
| 73 | // Information necessary to generate the filesystem modules, including details about their |
| 74 | // dependencies |
| 75 | type FsGenState struct { |
| 76 | // List of modules in `PRODUCT_PACKAGES` and `PRODUCT_PACKAGES_DEBUG` |
| 77 | depCandidates []string |
| 78 | // Map of names of partition to the information of modules to be added as deps |
| 79 | fsDeps map[string]multilibDeps |
| 80 | // List of name of partitions to be generated by the filesystem_creator module |
| 81 | soongGeneratedPartitions []string |
| 82 | // Mutex to protect the fsDeps |
| 83 | fsDepsMutex sync.Mutex |
Spandan Das | e1860e4 | 2024-10-24 22:29:50 +0000 | [diff] [blame] | 84 | // Map of _all_ soong module names to their corresponding installation properties |
| 85 | moduleToInstallationProps map[string]installationProperties |
| 86 | } |
| 87 | |
| 88 | type installationProperties struct { |
| 89 | Required []string |
| 90 | Overrides []string |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | func newMultilibDeps() multilibDeps { |
| 94 | return &map[string]*depCandidateProps{} |
| 95 | } |
| 96 | |
| 97 | func defaultDepCandidateProps(config android.Config) *depCandidateProps { |
| 98 | return &depCandidateProps{ |
| 99 | Namespace: ".", |
| 100 | Arch: []android.ArchType{config.BuildArch}, |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | func createFsGenState(ctx android.LoadHookContext) *FsGenState { |
| 105 | return ctx.Config().Once(fsGenStateOnceKey, func() interface{} { |
| 106 | partitionVars := ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse |
| 107 | candidates := android.FirstUniqueStrings(android.Concat(partitionVars.ProductPackages, partitionVars.ProductPackagesDebug)) |
| 108 | |
| 109 | generatedPartitions := []string{"system"} |
| 110 | if ctx.DeviceConfig().SystemExtPath() == "system_ext" { |
| 111 | generatedPartitions = append(generatedPartitions, "system_ext") |
| 112 | } |
Spandan Das | e3b6531 | 2024-10-22 00:27:27 +0000 | [diff] [blame] | 113 | if ctx.DeviceConfig().BuildingVendorImage() && ctx.DeviceConfig().VendorPath() == "vendor" { |
| 114 | generatedPartitions = append(generatedPartitions, "vendor") |
| 115 | } |
Jihoon Kang | 6dd13b6 | 2024-10-22 23:21:02 +0000 | [diff] [blame] | 116 | if ctx.DeviceConfig().BuildingProductImage() && ctx.DeviceConfig().ProductPath() == "product" { |
| 117 | generatedPartitions = append(generatedPartitions, "product") |
| 118 | } |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 119 | |
| 120 | return &FsGenState{ |
| 121 | depCandidates: candidates, |
| 122 | fsDeps: map[string]multilibDeps{ |
| 123 | // These additional deps are added according to the cuttlefish system image bp. |
| 124 | "system": &map[string]*depCandidateProps{ |
| 125 | "com.android.apex.cts.shim.v1_prebuilt": defaultDepCandidateProps(ctx.Config()), |
| 126 | "dex_bootjars": defaultDepCandidateProps(ctx.Config()), |
| 127 | "framework_compatibility_matrix.device.xml": defaultDepCandidateProps(ctx.Config()), |
| 128 | "idc_data": defaultDepCandidateProps(ctx.Config()), |
| 129 | "init.environ.rc-soong": defaultDepCandidateProps(ctx.Config()), |
| 130 | "keychars_data": defaultDepCandidateProps(ctx.Config()), |
| 131 | "keylayout_data": defaultDepCandidateProps(ctx.Config()), |
| 132 | "libclang_rt.asan": defaultDepCandidateProps(ctx.Config()), |
| 133 | "libcompiler_rt": defaultDepCandidateProps(ctx.Config()), |
| 134 | "libdmabufheap": defaultDepCandidateProps(ctx.Config()), |
| 135 | "libgsi": defaultDepCandidateProps(ctx.Config()), |
| 136 | "llndk.libraries.txt": defaultDepCandidateProps(ctx.Config()), |
| 137 | "logpersist.start": defaultDepCandidateProps(ctx.Config()), |
| 138 | "preloaded-classes": defaultDepCandidateProps(ctx.Config()), |
| 139 | "public.libraries.android.txt": defaultDepCandidateProps(ctx.Config()), |
| 140 | "update_engine_sideload": defaultDepCandidateProps(ctx.Config()), |
| 141 | }, |
Spandan Das | 49cc3e8 | 2024-10-23 20:54:01 +0000 | [diff] [blame] | 142 | "vendor": &map[string]*depCandidateProps{ |
Spandan Das | 168098c | 2024-10-28 19:44:34 +0000 | [diff] [blame] | 143 | "fs_config_files_vendor": defaultDepCandidateProps(ctx.Config()), |
| 144 | "fs_config_dirs_vendor": defaultDepCandidateProps(ctx.Config()), |
| 145 | generatedModuleName(ctx.Config(), "vendor-build.prop"): defaultDepCandidateProps(ctx.Config()), |
Spandan Das | 49cc3e8 | 2024-10-23 20:54:01 +0000 | [diff] [blame] | 146 | }, |
Spandan Das | d9875bc | 2024-10-17 21:36:17 +0000 | [diff] [blame] | 147 | "odm": newMultilibDeps(), |
| 148 | "product": newMultilibDeps(), |
| 149 | "system_ext": &map[string]*depCandidateProps{ |
| 150 | // VNDK apexes are automatically included. |
| 151 | // This hardcoded list will need to be updated if `PRODUCT_EXTRA_VNDK_VERSIONS` is updated. |
| 152 | // https://cs.android.com/android/_/android/platform/build/+/adba533072b00c53ac0f198c550a3cbd7a00e4cd:core/main.mk;l=984;bpv=1;bpt=0;drc=174db7b179592cf07cbfd2adb0119486fda911e7 |
| 153 | "com.android.vndk.v30": defaultDepCandidateProps(ctx.Config()), |
| 154 | "com.android.vndk.v31": defaultDepCandidateProps(ctx.Config()), |
| 155 | "com.android.vndk.v32": defaultDepCandidateProps(ctx.Config()), |
| 156 | "com.android.vndk.v33": defaultDepCandidateProps(ctx.Config()), |
| 157 | "com.android.vndk.v34": defaultDepCandidateProps(ctx.Config()), |
| 158 | }, |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 159 | }, |
Spandan Das | e1860e4 | 2024-10-24 22:29:50 +0000 | [diff] [blame] | 160 | soongGeneratedPartitions: generatedPartitions, |
| 161 | fsDepsMutex: sync.Mutex{}, |
| 162 | moduleToInstallationProps: map[string]installationProperties{}, |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 163 | } |
| 164 | }).(*FsGenState) |
| 165 | } |
| 166 | |
| 167 | func checkDepModuleInMultipleNamespaces(mctx android.BottomUpMutatorContext, foundDeps map[string]*depCandidateProps, module string, partitionName string) { |
| 168 | otherNamespace := mctx.Namespace().Path |
| 169 | if val, found := foundDeps[module]; found && otherNamespace != "." && !android.InList(val.Namespace, []string{".", otherNamespace}) { |
| 170 | mctx.ModuleErrorf("found in multiple namespaces(%s and %s) when including in %s partition", val.Namespace, otherNamespace, partitionName) |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | func appendDepIfAppropriate(mctx android.BottomUpMutatorContext, deps *map[string]*depCandidateProps, installPartition string) { |
| 175 | checkDepModuleInMultipleNamespaces(mctx, *deps, mctx.Module().Name(), installPartition) |
| 176 | if _, ok := (*deps)[mctx.Module().Name()]; ok { |
| 177 | // Prefer the namespace-specific module over the platform module |
| 178 | if mctx.Namespace().Path != "." { |
| 179 | (*deps)[mctx.Module().Name()].Namespace = mctx.Namespace().Path |
| 180 | } |
| 181 | (*deps)[mctx.Module().Name()].Arch = append((*deps)[mctx.Module().Name()].Arch, mctx.Module().Target().Arch.ArchType) |
| 182 | } else { |
| 183 | multilib, _ := mctx.Module().DecodeMultilib(mctx) |
| 184 | (*deps)[mctx.Module().Name()] = &depCandidateProps{ |
| 185 | Namespace: mctx.Namespace().Path, |
| 186 | Multilib: multilib, |
| 187 | Arch: []android.ArchType{mctx.Module().Target().Arch.ArchType}, |
| 188 | } |
| 189 | } |
| 190 | } |
mrziwang | 8f86c88 | 2024-10-03 12:34:33 -0700 | [diff] [blame] | 191 | |
| 192 | func collectDepsMutator(mctx android.BottomUpMutatorContext) { |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 193 | fsGenState := mctx.Config().Get(fsGenStateOnceKey).(*FsGenState) |
mrziwang | 8f86c88 | 2024-10-03 12:34:33 -0700 | [diff] [blame] | 194 | |
| 195 | m := mctx.Module() |
Spandan Das | fcc07c0 | 2024-10-21 23:33:43 +0000 | [diff] [blame] | 196 | 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] | 197 | installPartition := m.PartitionTag(mctx.DeviceConfig()) |
| 198 | fsGenState.fsDepsMutex.Lock() |
| 199 | // Only add the module as dependency when: |
| 200 | // - its enabled |
| 201 | // - its namespace is included in PRODUCT_SOONG_NAMESPACES |
| 202 | if m.Enabled(mctx) && m.ExportedToMake() { |
| 203 | appendDepIfAppropriate(mctx, fsGenState.fsDeps[installPartition], installPartition) |
| 204 | } |
| 205 | fsGenState.fsDepsMutex.Unlock() |
| 206 | } |
Spandan Das | e1860e4 | 2024-10-24 22:29:50 +0000 | [diff] [blame] | 207 | // store the map of module to (required,overrides) even if the module is not in PRODUCT_PACKAGES. |
| 208 | // the module might be installed transitively. |
| 209 | if m.Target().Os.Class == android.Device && m.Enabled(mctx) && m.ExportedToMake() { |
| 210 | fsGenState.fsDepsMutex.Lock() |
| 211 | fsGenState.moduleToInstallationProps[m.Name()] = installationProperties{ |
| 212 | Required: m.RequiredModuleNames(mctx), |
| 213 | Overrides: m.Overrides(), |
| 214 | } |
| 215 | fsGenState.fsDepsMutex.Unlock() |
| 216 | } |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | type depsStruct struct { |
| 220 | Deps []string |
| 221 | } |
| 222 | |
| 223 | type multilibDepsStruct struct { |
| 224 | Common depsStruct |
| 225 | Lib32 depsStruct |
| 226 | Lib64 depsStruct |
| 227 | Both depsStruct |
| 228 | Prefer32 depsStruct |
| 229 | } |
| 230 | |
| 231 | type packagingPropsStruct struct { |
| 232 | Deps []string |
| 233 | Multilib multilibDepsStruct |
| 234 | } |
| 235 | |
| 236 | func fullyQualifiedModuleName(moduleName, namespace string) string { |
| 237 | if namespace == "." { |
| 238 | return moduleName |
| 239 | } |
| 240 | return fmt.Sprintf("//%s:%s", namespace, moduleName) |
| 241 | } |
| 242 | |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 243 | func getBitness(archTypes []android.ArchType) (ret []string) { |
| 244 | for _, archType := range archTypes { |
| 245 | if archType.Multilib == "" { |
| 246 | ret = append(ret, android.COMMON_VARIANT) |
| 247 | } else { |
| 248 | ret = append(ret, archType.Bitness()) |
| 249 | } |
| 250 | } |
| 251 | return ret |
| 252 | } |
| 253 | |
| 254 | func setDepsMutator(mctx android.BottomUpMutatorContext) { |
Spandan Das | e1860e4 | 2024-10-24 22:29:50 +0000 | [diff] [blame] | 255 | removeOverriddenDeps(mctx) |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 256 | fsGenState := mctx.Config().Get(fsGenStateOnceKey).(*FsGenState) |
| 257 | fsDeps := fsGenState.fsDeps |
| 258 | soongGeneratedPartitionMap := getAllSoongGeneratedPartitionNames(mctx.Config(), fsGenState.soongGeneratedPartitions) |
| 259 | m := mctx.Module() |
| 260 | if partition, ok := soongGeneratedPartitionMap[m.Name()]; ok { |
mrziwang | 2a506cf | 2024-10-17 15:38:37 -0700 | [diff] [blame] | 261 | depsStruct := generateDepStruct(*fsDeps[partition]) |
| 262 | if err := proptools.AppendMatchingProperties(m.GetProperties(), depsStruct, nil); err != nil { |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 263 | mctx.ModuleErrorf(err.Error()) |
mrziwang | 8f86c88 | 2024-10-03 12:34:33 -0700 | [diff] [blame] | 264 | } |
| 265 | } |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 266 | } |
| 267 | |
Spandan Das | e1860e4 | 2024-10-24 22:29:50 +0000 | [diff] [blame] | 268 | // removeOverriddenDeps collects PRODUCT_PACKAGES and (transitive) required deps. |
| 269 | // it then removes any modules which appear in `overrides` of the above list. |
| 270 | func removeOverriddenDeps(mctx android.BottomUpMutatorContext) { |
| 271 | mctx.Config().Once(fsGenRemoveOverridesOnceKey, func() interface{} { |
| 272 | fsGenState := mctx.Config().Get(fsGenStateOnceKey).(*FsGenState) |
| 273 | fsDeps := fsGenState.fsDeps |
| 274 | overridden := map[string]bool{} |
| 275 | allDeps := []string{} |
| 276 | |
| 277 | // Step 1: Initialization: Append PRODUCT_PACKAGES to the queue |
| 278 | for _, fsDep := range fsDeps { |
| 279 | for depName, _ := range *fsDep { |
| 280 | allDeps = append(allDeps, depName) |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | // Step 2: Process the queue, and add required modules to the queue. |
| 285 | i := 0 |
| 286 | for { |
| 287 | if i == len(allDeps) { |
| 288 | break |
| 289 | } |
| 290 | depName := allDeps[i] |
| 291 | for _, overrides := range fsGenState.moduleToInstallationProps[depName].Overrides { |
| 292 | overridden[overrides] = true |
| 293 | } |
| 294 | // add required dep to the queue. |
| 295 | allDeps = append(allDeps, fsGenState.moduleToInstallationProps[depName].Required...) |
| 296 | i += 1 |
| 297 | } |
| 298 | |
| 299 | // Step 3: Delete all the overridden modules. |
| 300 | for overridden, _ := range overridden { |
| 301 | for partition, _ := range fsDeps { |
| 302 | delete(*fsDeps[partition], overridden) |
| 303 | } |
| 304 | } |
| 305 | return nil |
| 306 | }) |
| 307 | } |
| 308 | |
mrziwang | 2a506cf | 2024-10-17 15:38:37 -0700 | [diff] [blame] | 309 | func generateDepStruct(deps map[string]*depCandidateProps) *packagingPropsStruct { |
| 310 | depsStruct := packagingPropsStruct{} |
| 311 | for depName, depProps := range deps { |
| 312 | bitness := getBitness(depProps.Arch) |
| 313 | fullyQualifiedDepName := fullyQualifiedModuleName(depName, depProps.Namespace) |
| 314 | if android.InList("32", bitness) && android.InList("64", bitness) { |
| 315 | // If both 32 and 64 bit variants are enabled for this module |
| 316 | switch depProps.Multilib { |
| 317 | case string(android.MultilibBoth): |
| 318 | depsStruct.Multilib.Both.Deps = append(depsStruct.Multilib.Both.Deps, fullyQualifiedDepName) |
| 319 | case string(android.MultilibCommon), string(android.MultilibFirst): |
| 320 | depsStruct.Deps = append(depsStruct.Deps, fullyQualifiedDepName) |
| 321 | case "32": |
| 322 | depsStruct.Multilib.Lib32.Deps = append(depsStruct.Multilib.Lib32.Deps, fullyQualifiedDepName) |
| 323 | case "64", "darwin_universal": |
| 324 | depsStruct.Multilib.Lib64.Deps = append(depsStruct.Multilib.Lib64.Deps, fullyQualifiedDepName) |
| 325 | case "prefer32", "first_prefer32": |
| 326 | depsStruct.Multilib.Prefer32.Deps = append(depsStruct.Multilib.Prefer32.Deps, fullyQualifiedDepName) |
| 327 | default: |
| 328 | depsStruct.Multilib.Both.Deps = append(depsStruct.Multilib.Both.Deps, fullyQualifiedDepName) |
| 329 | } |
| 330 | } else if android.InList("64", bitness) { |
| 331 | // If only 64 bit variant is enabled |
| 332 | depsStruct.Multilib.Lib64.Deps = append(depsStruct.Multilib.Lib64.Deps, fullyQualifiedDepName) |
| 333 | } else if android.InList("32", bitness) { |
| 334 | // If only 32 bit variant is enabled |
| 335 | depsStruct.Multilib.Lib32.Deps = append(depsStruct.Multilib.Lib32.Deps, fullyQualifiedDepName) |
| 336 | } else { |
| 337 | // If only common variant is enabled |
| 338 | depsStruct.Multilib.Common.Deps = append(depsStruct.Multilib.Common.Deps, fullyQualifiedDepName) |
| 339 | } |
| 340 | } |
Jihoon Kang | 4e5d8de | 2024-10-19 01:59:58 +0000 | [diff] [blame] | 341 | depsStruct.Deps = android.SortedUniqueStrings(depsStruct.Deps) |
| 342 | depsStruct.Multilib.Lib32.Deps = android.SortedUniqueStrings(depsStruct.Multilib.Lib32.Deps) |
| 343 | depsStruct.Multilib.Lib64.Deps = android.SortedUniqueStrings(depsStruct.Multilib.Lib64.Deps) |
| 344 | depsStruct.Multilib.Prefer32.Deps = android.SortedUniqueStrings(depsStruct.Multilib.Prefer32.Deps) |
| 345 | depsStruct.Multilib.Both.Deps = android.SortedUniqueStrings(depsStruct.Multilib.Both.Deps) |
| 346 | depsStruct.Multilib.Common.Deps = android.SortedUniqueStrings(depsStruct.Multilib.Common.Deps) |
| 347 | |
mrziwang | 2a506cf | 2024-10-17 15:38:37 -0700 | [diff] [blame] | 348 | return &depsStruct |
| 349 | } |
| 350 | |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 351 | type filesystemCreatorProps struct { |
| 352 | Generated_partition_types []string `blueprint:"mutated"` |
| 353 | Unsupported_partition_types []string `blueprint:"mutated"` |
| 354 | } |
| 355 | |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 356 | type filesystemCreator struct { |
| 357 | android.ModuleBase |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 358 | |
| 359 | properties filesystemCreatorProps |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | func filesystemCreatorFactory() android.Module { |
| 363 | module := &filesystemCreator{} |
| 364 | |
Cole Faust | 6978879 | 2024-10-10 11:00:36 -0700 | [diff] [blame] | 365 | android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibCommon) |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 366 | module.AddProperties(&module.properties) |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 367 | android.AddLoadHook(module, func(ctx android.LoadHookContext) { |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 368 | createFsGenState(ctx) |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 369 | module.createInternalModules(ctx) |
| 370 | }) |
| 371 | |
| 372 | return module |
| 373 | } |
| 374 | |
| 375 | func (f *filesystemCreator) createInternalModules(ctx android.LoadHookContext) { |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 376 | soongGeneratedPartitions := &ctx.Config().Get(fsGenStateOnceKey).(*FsGenState).soongGeneratedPartitions |
| 377 | for _, partitionType := range *soongGeneratedPartitions { |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 378 | if f.createPartition(ctx, partitionType) { |
| 379 | f.properties.Generated_partition_types = append(f.properties.Generated_partition_types, partitionType) |
| 380 | } else { |
| 381 | f.properties.Unsupported_partition_types = append(f.properties.Unsupported_partition_types, partitionType) |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 382 | _, *soongGeneratedPartitions = android.RemoveFromList(partitionType, *soongGeneratedPartitions) |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 383 | } |
| 384 | } |
Jihoon Kang | f1c79ca | 2024-10-09 20:18:38 +0000 | [diff] [blame] | 385 | f.createDeviceModule(ctx) |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 386 | } |
| 387 | |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 388 | func generatedModuleName(cfg android.Config, suffix string) string { |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 389 | prefix := "soong" |
| 390 | if cfg.HasDeviceProduct() { |
| 391 | prefix = cfg.DeviceProduct() |
| 392 | } |
Jihoon Kang | f1c79ca | 2024-10-09 20:18:38 +0000 | [diff] [blame] | 393 | return fmt.Sprintf("%s_generated_%s", prefix, suffix) |
| 394 | } |
| 395 | |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 396 | func generatedModuleNameForPartition(cfg android.Config, partitionType string) string { |
| 397 | return generatedModuleName(cfg, fmt.Sprintf("%s_image", partitionType)) |
Jihoon Kang | f1c79ca | 2024-10-09 20:18:38 +0000 | [diff] [blame] | 398 | } |
| 399 | |
| 400 | func (f *filesystemCreator) createDeviceModule(ctx android.LoadHookContext) { |
| 401 | baseProps := &struct { |
| 402 | Name *string |
| 403 | }{ |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 404 | Name: proptools.StringPtr(generatedModuleName(ctx.Config(), "device")), |
Jihoon Kang | f1c79ca | 2024-10-09 20:18:38 +0000 | [diff] [blame] | 405 | } |
| 406 | |
Priyanka Advani (xWF) | dafaa7f | 2024-10-21 22:55:13 +0000 | [diff] [blame] | 407 | // Currently, only the system and system_ext partition module is created. |
Jihoon Kang | f1c79ca | 2024-10-09 20:18:38 +0000 | [diff] [blame] | 408 | partitionProps := &filesystem.PartitionNameProperties{} |
| 409 | if android.InList("system", f.properties.Generated_partition_types) { |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 410 | partitionProps.System_partition_name = proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "system")) |
Jihoon Kang | f1c79ca | 2024-10-09 20:18:38 +0000 | [diff] [blame] | 411 | } |
Spandan Das | 7a46f6c | 2024-10-14 18:41:18 +0000 | [diff] [blame] | 412 | if android.InList("system_ext", f.properties.Generated_partition_types) { |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 413 | partitionProps.System_ext_partition_name = proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "system_ext")) |
Spandan Das | 7a46f6c | 2024-10-14 18:41:18 +0000 | [diff] [blame] | 414 | } |
Spandan Das | e3b6531 | 2024-10-22 00:27:27 +0000 | [diff] [blame] | 415 | if android.InList("vendor", f.properties.Generated_partition_types) { |
| 416 | partitionProps.Vendor_partition_name = proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "vendor")) |
| 417 | } |
Jihoon Kang | 6dd13b6 | 2024-10-22 23:21:02 +0000 | [diff] [blame] | 418 | if android.InList("product", f.properties.Generated_partition_types) { |
| 419 | partitionProps.Product_partition_name = proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "product")) |
| 420 | } |
Jihoon Kang | f1c79ca | 2024-10-09 20:18:38 +0000 | [diff] [blame] | 421 | |
| 422 | ctx.CreateModule(filesystem.AndroidDeviceFactory, baseProps, partitionProps) |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 423 | } |
| 424 | |
Jihoon Kang | 6850d8f | 2024-10-17 20:45:58 +0000 | [diff] [blame] | 425 | func partitionSpecificFsProps(fsProps *filesystem.FilesystemProperties, partitionType string) { |
| 426 | switch partitionType { |
| 427 | case "system": |
| 428 | fsProps.Build_logtags = proptools.BoolPtr(true) |
| 429 | // https://source.corp.google.com/h/googleplex-android/platform/build//639d79f5012a6542ab1f733b0697db45761ab0f3:core/packaging/flags.mk;l=21;drc=5ba8a8b77507f93aa48cc61c5ba3f31a4d0cbf37;bpv=1;bpt=0 |
| 430 | fsProps.Gen_aconfig_flags_pb = proptools.BoolPtr(true) |
Spandan Das | a8fa6b4 | 2024-10-23 00:45:29 +0000 | [diff] [blame] | 431 | // Identical to that of the generic_system_image |
| 432 | fsProps.Fsverity.Inputs = []string{ |
| 433 | "etc/boot-image.prof", |
| 434 | "etc/dirty-image-objects", |
| 435 | "etc/preloaded-classes", |
| 436 | "etc/classpaths/*.pb", |
| 437 | "framework/*", |
| 438 | "framework/*/*", // framework/{arch} |
| 439 | "framework/oat/*/*", // framework/oat/{arch} |
| 440 | } |
| 441 | fsProps.Fsverity.Libs = []string{":framework-res{.export-package.apk}"} |
| 442 | case "system_ext": |
| 443 | fsProps.Fsverity.Inputs = []string{ |
| 444 | "framework/*", |
| 445 | "framework/*/*", // framework/{arch} |
| 446 | "framework/oat/*/*", // framework/oat/{arch} |
| 447 | } |
| 448 | fsProps.Fsverity.Libs = []string{":framework-res{.export-package.apk}"} |
Jihoon Kang | 6850d8f | 2024-10-17 20:45:58 +0000 | [diff] [blame] | 449 | case "product": |
| 450 | fsProps.Gen_aconfig_flags_pb = proptools.BoolPtr(true) |
| 451 | case "vendor": |
| 452 | fsProps.Gen_aconfig_flags_pb = proptools.BoolPtr(true) |
Spandan Das | 69464c3 | 2024-10-25 20:08:06 +0000 | [diff] [blame] | 453 | fsProps.Symlinks = []filesystem.SymlinkDefinition{ |
| 454 | filesystem.SymlinkDefinition{ |
| 455 | Target: proptools.StringPtr("/odm"), |
| 456 | Name: proptools.StringPtr("vendor/odm"), |
| 457 | }, |
| 458 | filesystem.SymlinkDefinition{ |
| 459 | Target: proptools.StringPtr("/vendor_dlkm/lib/modules"), |
| 460 | Name: proptools.StringPtr("vendor/lib/modules"), |
| 461 | }, |
| 462 | } |
| 463 | fsProps.Base_dir = proptools.StringPtr("vendor") |
Jihoon Kang | 6850d8f | 2024-10-17 20:45:58 +0000 | [diff] [blame] | 464 | } |
| 465 | } |
Spandan Das | cbe641a | 2024-10-14 21:07:34 +0000 | [diff] [blame] | 466 | |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 467 | // Creates a soong module to build the given partition. Returns false if we can't support building |
| 468 | // it. |
| 469 | func (f *filesystemCreator) createPartition(ctx android.LoadHookContext, partitionType string) bool { |
mrziwang | 4b0ca97 | 2024-10-17 14:56:19 -0700 | [diff] [blame] | 470 | baseProps := generateBaseProps(proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), partitionType))) |
| 471 | |
| 472 | fsProps, supported := generateFsProps(ctx, partitionType) |
| 473 | if !supported { |
| 474 | return false |
mrziwang | a077b94 | 2024-10-16 16:00:06 -0700 | [diff] [blame] | 475 | } |
mrziwang | a077b94 | 2024-10-16 16:00:06 -0700 | [diff] [blame] | 476 | |
Spandan Das | 8fe68dc | 2024-10-29 18:20:11 +0000 | [diff] [blame] | 477 | if partitionType == "vendor" || partitionType == "product" { |
| 478 | fsProps.Linker_config_srcs = f.createLinkerConfigSourceFilegroups(ctx, partitionType) |
Spandan Das | 312cc41 | 2024-10-29 18:20:11 +0000 | [diff] [blame] | 479 | } |
| 480 | |
mrziwang | 4b0ca97 | 2024-10-17 14:56:19 -0700 | [diff] [blame] | 481 | var module android.Module |
| 482 | if partitionType == "system" { |
| 483 | module = ctx.CreateModule(filesystem.SystemImageFactory, baseProps, fsProps) |
| 484 | } else { |
| 485 | // Explicitly set the partition. |
| 486 | fsProps.Partition_type = proptools.StringPtr(partitionType) |
| 487 | module = ctx.CreateModule(filesystem.FilesystemFactory, baseProps, fsProps) |
| 488 | } |
| 489 | module.HideFromMake() |
Spandan Das | 168098c | 2024-10-28 19:44:34 +0000 | [diff] [blame] | 490 | if partitionType == "vendor" { |
| 491 | // Create a build prop for vendor |
| 492 | vendorBuildProps := &struct { |
| 493 | Name *string |
| 494 | Vendor *bool |
| 495 | Stem *string |
| 496 | Product_config *string |
| 497 | }{ |
| 498 | Name: proptools.StringPtr(generatedModuleName(ctx.Config(), "vendor-build.prop")), |
| 499 | Vendor: proptools.BoolPtr(true), |
| 500 | Stem: proptools.StringPtr("build.prop"), |
| 501 | Product_config: proptools.StringPtr(":product_config"), |
| 502 | } |
| 503 | vendorBuildProp := ctx.CreateModule( |
| 504 | android.BuildPropFactory, |
| 505 | vendorBuildProps, |
| 506 | ) |
| 507 | vendorBuildProp.HideFromMake() |
| 508 | } |
mrziwang | 4b0ca97 | 2024-10-17 14:56:19 -0700 | [diff] [blame] | 509 | return true |
| 510 | } |
| 511 | |
Spandan Das | 8fe68dc | 2024-10-29 18:20:11 +0000 | [diff] [blame] | 512 | // createLinkerConfigSourceFilegroups creates filegroup modules to generate linker.config.pb for the following partitions |
| 513 | // 1. vendor: Using PRODUCT_VENDOR_LINKER_CONFIG_FRAGMENTS (space separated file list) |
| 514 | // 1. product: Using PRODUCT_PRODUCT_LINKER_CONFIG_FRAGMENTS (space separated file list) |
| 515 | // It creates a filegroup for each file in the fragment list |
Spandan Das | 312cc41 | 2024-10-29 18:20:11 +0000 | [diff] [blame] | 516 | // 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] | 517 | func (f *filesystemCreator) createLinkerConfigSourceFilegroups(ctx android.LoadHookContext, partitionType string) []string { |
Spandan Das | 312cc41 | 2024-10-29 18:20:11 +0000 | [diff] [blame] | 518 | ret := []string{} |
| 519 | partitionVars := ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse |
Spandan Das | 8fe68dc | 2024-10-29 18:20:11 +0000 | [diff] [blame] | 520 | var linkerConfigSrcs []string |
| 521 | if partitionType == "vendor" { |
| 522 | linkerConfigSrcs = android.FirstUniqueStrings(partitionVars.VendorLinkerConfigSrcs) |
| 523 | } else if partitionType == "product" { |
| 524 | linkerConfigSrcs = android.FirstUniqueStrings(partitionVars.ProductLinkerConfigSrcs) |
| 525 | } else { |
| 526 | ctx.ModuleErrorf("linker.config.pb is only supported for vendor and product partitions. For system partition, use `android_system_image`") |
| 527 | } |
| 528 | |
| 529 | if len(linkerConfigSrcs) > 0 { |
Spandan Das | 312cc41 | 2024-10-29 18:20:11 +0000 | [diff] [blame] | 530 | // Create a filegroup, and add `:<filegroup_name>` to ret. |
| 531 | for index, linkerConfigSrc := range linkerConfigSrcs { |
| 532 | dir := filepath.Dir(linkerConfigSrc) |
| 533 | base := filepath.Base(linkerConfigSrc) |
Spandan Das | 8fe68dc | 2024-10-29 18:20:11 +0000 | [diff] [blame] | 534 | 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] | 535 | srcs := []string{base} |
| 536 | fgProps := &struct { |
| 537 | Name *string |
| 538 | Srcs proptools.Configurable[[]string] |
| 539 | }{ |
| 540 | Name: proptools.StringPtr(fgName), |
| 541 | Srcs: proptools.NewSimpleConfigurable(srcs), |
| 542 | } |
| 543 | ctx.CreateModuleInDirectory( |
| 544 | android.FileGroupFactory, |
| 545 | dir, |
| 546 | fgProps, |
| 547 | ) |
| 548 | ret = append(ret, ":"+fgName) |
| 549 | } |
| 550 | } |
| 551 | return ret |
| 552 | } |
| 553 | |
mrziwang | 4b0ca97 | 2024-10-17 14:56:19 -0700 | [diff] [blame] | 554 | type filesystemBaseProperty struct { |
| 555 | Name *string |
| 556 | Compile_multilib *string |
| 557 | } |
| 558 | |
| 559 | func generateBaseProps(namePtr *string) *filesystemBaseProperty { |
| 560 | return &filesystemBaseProperty{ |
| 561 | Name: namePtr, |
| 562 | Compile_multilib: proptools.StringPtr("both"), |
| 563 | } |
| 564 | } |
| 565 | |
| 566 | func generateFsProps(ctx android.EarlyModuleContext, partitionType string) (*filesystem.FilesystemProperties, bool) { |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 567 | fsProps := &filesystem.FilesystemProperties{} |
| 568 | |
mrziwang | 4b0ca97 | 2024-10-17 14:56:19 -0700 | [diff] [blame] | 569 | partitionVars := ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse |
| 570 | specificPartitionVars := partitionVars.PartitionQualifiedVariables[partitionType] |
| 571 | |
| 572 | // BOARD_SYSTEMIMAGE_FILE_SYSTEM_TYPE |
| 573 | fsType := specificPartitionVars.BoardFileSystemType |
| 574 | if fsType == "" { |
| 575 | fsType = "ext4" //default |
| 576 | } |
| 577 | fsProps.Type = proptools.StringPtr(fsType) |
| 578 | if filesystem.GetFsTypeFromString(ctx, *fsProps.Type).IsUnknown() { |
| 579 | // Currently the android_filesystem module type only supports a handful of FS types like ext4, erofs |
| 580 | return nil, false |
| 581 | } |
| 582 | |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 583 | // Don't build this module on checkbuilds, the soong-built partitions are still in-progress |
| 584 | // and sometimes don't build. |
| 585 | fsProps.Unchecked_module = proptools.BoolPtr(true) |
| 586 | |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 587 | // BOARD_AVB_ENABLE |
| 588 | fsProps.Use_avb = proptools.BoolPtr(partitionVars.BoardAvbEnable) |
| 589 | // BOARD_AVB_KEY_PATH |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 590 | fsProps.Avb_private_key = proptools.StringPtr(specificPartitionVars.BoardAvbKeyPath) |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 591 | // BOARD_AVB_ALGORITHM |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 592 | fsProps.Avb_algorithm = proptools.StringPtr(specificPartitionVars.BoardAvbAlgorithm) |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 593 | // BOARD_AVB_SYSTEM_ROLLBACK_INDEX |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 594 | if rollbackIndex, err := strconv.ParseInt(specificPartitionVars.BoardAvbRollbackIndex, 10, 64); err == nil { |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 595 | fsProps.Rollback_index = proptools.Int64Ptr(rollbackIndex) |
| 596 | } |
| 597 | |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 598 | fsProps.Partition_name = proptools.StringPtr(partitionType) |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 599 | |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 600 | fsProps.Base_dir = proptools.StringPtr(partitionType) |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 601 | |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 602 | fsProps.Is_auto_generated = proptools.BoolPtr(true) |
| 603 | |
Jihoon Kang | 6850d8f | 2024-10-17 20:45:58 +0000 | [diff] [blame] | 604 | partitionSpecificFsProps(fsProps, partitionType) |
| 605 | |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 606 | // system_image properties that are not set: |
| 607 | // - filesystemProperties.Avb_hash_algorithm |
| 608 | // - filesystemProperties.File_contexts |
| 609 | // - filesystemProperties.Dirs |
| 610 | // - filesystemProperties.Symlinks |
| 611 | // - filesystemProperties.Fake_timestamp |
| 612 | // - filesystemProperties.Uuid |
| 613 | // - filesystemProperties.Mount_point |
| 614 | // - filesystemProperties.Include_make_built_files |
| 615 | // - filesystemProperties.Build_logtags |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 616 | // - systemImageProperties.Linker_config_src |
mrziwang | 4b0ca97 | 2024-10-17 14:56:19 -0700 | [diff] [blame] | 617 | |
| 618 | return fsProps, true |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 619 | } |
| 620 | |
| 621 | func (f *filesystemCreator) createDiffTest(ctx android.ModuleContext, partitionType string) android.Path { |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 622 | partitionModuleName := generatedModuleNameForPartition(ctx.Config(), partitionType) |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 623 | systemImage := ctx.GetDirectDepWithTag(partitionModuleName, generatedFilesystemDepTag) |
| 624 | filesystemInfo, ok := android.OtherModuleProvider(ctx, systemImage, filesystem.FilesystemProvider) |
| 625 | if !ok { |
| 626 | ctx.ModuleErrorf("Expected module %s to provide FileysystemInfo", partitionModuleName) |
| 627 | } |
| 628 | makeFileList := android.PathForArbitraryOutput(ctx, fmt.Sprintf("target/product/%s/obj/PACKAGING/%s_intermediates/file_list.txt", ctx.Config().DeviceName(), partitionType)) |
| 629 | // For now, don't allowlist anything. The test will fail, but that's fine in the current |
| 630 | // early stages where we're just figuring out what we need |
Jihoon Kang | 9e866c8 | 2024-10-07 22:39:18 +0000 | [diff] [blame] | 631 | emptyAllowlistFile := android.PathForModuleOut(ctx, fmt.Sprintf("allowlist_%s.txt", partitionModuleName)) |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 632 | android.WriteFileRule(ctx, emptyAllowlistFile, "") |
Jihoon Kang | 9e866c8 | 2024-10-07 22:39:18 +0000 | [diff] [blame] | 633 | diffTestResultFile := android.PathForModuleOut(ctx, fmt.Sprintf("diff_test_%s.txt", partitionModuleName)) |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 634 | |
| 635 | builder := android.NewRuleBuilder(pctx, ctx) |
| 636 | builder.Command().BuiltTool("file_list_diff"). |
| 637 | Input(makeFileList). |
| 638 | Input(filesystemInfo.FileListFile). |
Jihoon Kang | 9e866c8 | 2024-10-07 22:39:18 +0000 | [diff] [blame] | 639 | Text(partitionModuleName). |
| 640 | FlagWithInput("--allowlists ", emptyAllowlistFile) |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 641 | builder.Command().Text("touch").Output(diffTestResultFile) |
| 642 | builder.Build(partitionModuleName+" diff test", partitionModuleName+" diff test") |
| 643 | return diffTestResultFile |
| 644 | } |
| 645 | |
| 646 | func createFailingCommand(ctx android.ModuleContext, message string) android.Path { |
| 647 | hasher := sha256.New() |
| 648 | hasher.Write([]byte(message)) |
| 649 | filename := fmt.Sprintf("failing_command_%x.txt", hasher.Sum(nil)) |
| 650 | file := android.PathForModuleOut(ctx, filename) |
| 651 | builder := android.NewRuleBuilder(pctx, ctx) |
| 652 | builder.Command().Textf("echo %s", proptools.NinjaAndShellEscape(message)) |
| 653 | builder.Command().Text("exit 1 #").Output(file) |
| 654 | builder.Build("failing command "+filename, "failing command "+filename) |
| 655 | return file |
| 656 | } |
| 657 | |
| 658 | type systemImageDepTagType struct { |
| 659 | blueprint.BaseDependencyTag |
| 660 | } |
| 661 | |
| 662 | var generatedFilesystemDepTag systemImageDepTagType |
| 663 | |
| 664 | func (f *filesystemCreator) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 665 | for _, partitionType := range f.properties.Generated_partition_types { |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 666 | ctx.AddDependency(ctx.Module(), generatedFilesystemDepTag, generatedModuleNameForPartition(ctx.Config(), partitionType)) |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 667 | } |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 668 | } |
| 669 | |
| 670 | func (f *filesystemCreator) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 671 | if ctx.ModuleDir() != "build/soong/fsgen" { |
| 672 | ctx.ModuleErrorf("There can only be one soong_filesystem_creator in build/soong/fsgen") |
| 673 | } |
| 674 | f.HideFromMake() |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 675 | |
Jihoon Kang | 4e5d8de | 2024-10-19 01:59:58 +0000 | [diff] [blame] | 676 | var content strings.Builder |
| 677 | generatedBp := android.PathForModuleOut(ctx, "soong_generated_product_config.bp") |
| 678 | for _, partition := range ctx.Config().Get(fsGenStateOnceKey).(*FsGenState).soongGeneratedPartitions { |
| 679 | content.WriteString(generateBpContent(ctx, partition)) |
| 680 | content.WriteString("\n") |
| 681 | } |
| 682 | android.WriteFileRule(ctx, generatedBp, content.String()) |
| 683 | |
mrziwang | 8f86c88 | 2024-10-03 12:34:33 -0700 | [diff] [blame] | 684 | ctx.Phony("product_config_to_bp", generatedBp) |
| 685 | |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 686 | var diffTestFiles []android.Path |
| 687 | for _, partitionType := range f.properties.Generated_partition_types { |
Jihoon Kang | 72f812f | 2024-10-17 18:46:24 +0000 | [diff] [blame] | 688 | diffTestFile := f.createDiffTest(ctx, partitionType) |
| 689 | diffTestFiles = append(diffTestFiles, diffTestFile) |
| 690 | ctx.Phony(fmt.Sprintf("soong_generated_%s_filesystem_test", partitionType), diffTestFile) |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 691 | } |
| 692 | for _, partitionType := range f.properties.Unsupported_partition_types { |
Jihoon Kang | 72f812f | 2024-10-17 18:46:24 +0000 | [diff] [blame] | 693 | diffTestFile := createFailingCommand(ctx, fmt.Sprintf("Couldn't build %s partition", partitionType)) |
| 694 | diffTestFiles = append(diffTestFiles, diffTestFile) |
| 695 | ctx.Phony(fmt.Sprintf("soong_generated_%s_filesystem_test", partitionType), diffTestFile) |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 696 | } |
| 697 | ctx.Phony("soong_generated_filesystem_tests", diffTestFiles...) |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 698 | } |
mrziwang | 8f86c88 | 2024-10-03 12:34:33 -0700 | [diff] [blame] | 699 | |
mrziwang | 8f86c88 | 2024-10-03 12:34:33 -0700 | [diff] [blame] | 700 | func generateBpContent(ctx android.EarlyModuleContext, partitionType string) string { |
mrziwang | 4b0ca97 | 2024-10-17 14:56:19 -0700 | [diff] [blame] | 701 | fsProps, fsTypeSupported := generateFsProps(ctx, partitionType) |
| 702 | if !fsTypeSupported { |
| 703 | return "" |
mrziwang | 8f86c88 | 2024-10-03 12:34:33 -0700 | [diff] [blame] | 704 | } |
Spandan Das | 69464c3 | 2024-10-25 20:08:06 +0000 | [diff] [blame] | 705 | if partitionType == "vendor" { |
| 706 | return "" // TODO: Handle struct props |
| 707 | } |
mrziwang | 8f86c88 | 2024-10-03 12:34:33 -0700 | [diff] [blame] | 708 | |
mrziwang | 4b0ca97 | 2024-10-17 14:56:19 -0700 | [diff] [blame] | 709 | baseProps := generateBaseProps(proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), partitionType))) |
mrziwang | 2a506cf | 2024-10-17 15:38:37 -0700 | [diff] [blame] | 710 | deps := ctx.Config().Get(fsGenStateOnceKey).(*FsGenState).fsDeps[partitionType] |
| 711 | depProps := generateDepStruct(*deps) |
mrziwang | 8f86c88 | 2024-10-03 12:34:33 -0700 | [diff] [blame] | 712 | |
mrziwang | 4b0ca97 | 2024-10-17 14:56:19 -0700 | [diff] [blame] | 713 | result, err := proptools.RepackProperties([]interface{}{baseProps, fsProps, depProps}) |
mrziwang | 8f86c88 | 2024-10-03 12:34:33 -0700 | [diff] [blame] | 714 | if err != nil { |
| 715 | ctx.ModuleErrorf(err.Error()) |
| 716 | } |
| 717 | |
Jihoon Kang | 4e5d8de | 2024-10-19 01:59:58 +0000 | [diff] [blame] | 718 | moduleType := "android_filesystem" |
| 719 | if partitionType == "system" { |
| 720 | moduleType = "android_system_image" |
| 721 | } |
| 722 | |
mrziwang | 8f86c88 | 2024-10-03 12:34:33 -0700 | [diff] [blame] | 723 | file := &parser.File{ |
| 724 | Defs: []parser.Definition{ |
| 725 | &parser.Module{ |
Jihoon Kang | 4e5d8de | 2024-10-19 01:59:58 +0000 | [diff] [blame] | 726 | Type: moduleType, |
mrziwang | 8f86c88 | 2024-10-03 12:34:33 -0700 | [diff] [blame] | 727 | Map: *result, |
| 728 | }, |
| 729 | }, |
| 730 | } |
| 731 | bytes, err := parser.Print(file) |
| 732 | if err != nil { |
| 733 | ctx.ModuleErrorf(err.Error()) |
| 734 | } |
| 735 | return strings.TrimSpace(string(bytes)) |
| 736 | } |