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