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