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