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