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" |
mrziwang | 8f86c88 | 2024-10-03 12:34:33 -0700 | [diff] [blame] | 20 | "slices" |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 21 | "strconv" |
mrziwang | 8f86c88 | 2024-10-03 12:34:33 -0700 | [diff] [blame] | 22 | "strings" |
| 23 | "sync" |
| 24 | |
| 25 | "android/soong/android" |
| 26 | "android/soong/filesystem" |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 27 | |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 28 | "github.com/google/blueprint" |
mrziwang | 8f86c88 | 2024-10-03 12:34:33 -0700 | [diff] [blame] | 29 | "github.com/google/blueprint/parser" |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 30 | "github.com/google/blueprint/proptools" |
| 31 | ) |
| 32 | |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 33 | var pctx = android.NewPackageContext("android/soong/fsgen") |
| 34 | |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 35 | func init() { |
| 36 | registerBuildComponents(android.InitRegistrationContext) |
| 37 | } |
| 38 | |
| 39 | func registerBuildComponents(ctx android.RegistrationContext) { |
| 40 | ctx.RegisterModuleType("soong_filesystem_creator", filesystemCreatorFactory) |
mrziwang | 8f86c88 | 2024-10-03 12:34:33 -0700 | [diff] [blame] | 41 | ctx.PreDepsMutators(RegisterCollectFileSystemDepsMutators) |
| 42 | } |
| 43 | |
| 44 | func RegisterCollectFileSystemDepsMutators(ctx android.RegisterMutatorsContext) { |
| 45 | ctx.BottomUp("fs_collect_deps", collectDepsMutator).MutatesGlobalState() |
| 46 | } |
| 47 | |
mrziwang | c7e58c9 | 2024-10-11 09:49:48 -0700 | [diff] [blame] | 48 | var fsDepsMutex = sync.Mutex{} |
mrziwang | 8f86c88 | 2024-10-03 12:34:33 -0700 | [diff] [blame] | 49 | var collectFsDepsOnceKey = android.NewOnceKey("CollectFsDeps") |
| 50 | var depCandidatesOnceKey = android.NewOnceKey("DepCandidates") |
| 51 | |
| 52 | func collectDepsMutator(mctx android.BottomUpMutatorContext) { |
| 53 | // These additional deps are added according to the cuttlefish system image bp. |
| 54 | fsDeps := mctx.Config().Once(collectFsDepsOnceKey, func() interface{} { |
Jihoon Kang | ac2d1ba | 2024-10-12 01:44:47 +0000 | [diff] [blame] | 55 | deps := []string{ |
| 56 | "android_vintf_manifest", |
| 57 | "com.android.apex.cts.shim.v1_prebuilt", |
| 58 | "dex_bootjars", |
| 59 | "framework_compatibility_matrix.device.xml", |
| 60 | "idc_data", |
| 61 | "init.environ.rc-soong", |
| 62 | "keychars_data", |
| 63 | "keylayout_data", |
| 64 | "libclang_rt.asan", |
| 65 | "libcompiler_rt", |
| 66 | "libdmabufheap", |
| 67 | "libgsi", |
| 68 | "llndk.libraries.txt", |
| 69 | "logpersist.start", |
| 70 | "preloaded-classes", |
| 71 | "public.libraries.android.txt", |
| 72 | "update_engine_sideload", |
mrziwang | 8f86c88 | 2024-10-03 12:34:33 -0700 | [diff] [blame] | 73 | } |
| 74 | return &deps |
Jihoon Kang | ac2d1ba | 2024-10-12 01:44:47 +0000 | [diff] [blame] | 75 | }).(*[]string) |
mrziwang | 8f86c88 | 2024-10-03 12:34:33 -0700 | [diff] [blame] | 76 | |
| 77 | depCandidates := mctx.Config().Once(depCandidatesOnceKey, func() interface{} { |
| 78 | partitionVars := mctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse |
| 79 | candidates := slices.Concat(partitionVars.ProductPackages, partitionVars.ProductPackagesDebug) |
| 80 | return &candidates |
| 81 | }).(*[]string) |
| 82 | |
| 83 | m := mctx.Module() |
mrziwang | 8f86c88 | 2024-10-03 12:34:33 -0700 | [diff] [blame] | 84 | if slices.Contains(*depCandidates, m.Name()) { |
Jihoon Kang | ac2d1ba | 2024-10-12 01:44:47 +0000 | [diff] [blame] | 85 | if installInSystem(mctx, m) { |
| 86 | fsDepsMutex.Lock() |
| 87 | *fsDeps = append(*fsDeps, m.Name()) |
| 88 | fsDepsMutex.Unlock() |
mrziwang | 8f86c88 | 2024-10-03 12:34:33 -0700 | [diff] [blame] | 89 | } |
| 90 | } |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 91 | } |
| 92 | |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 93 | type filesystemCreatorProps struct { |
| 94 | Generated_partition_types []string `blueprint:"mutated"` |
| 95 | Unsupported_partition_types []string `blueprint:"mutated"` |
| 96 | } |
| 97 | |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 98 | type filesystemCreator struct { |
| 99 | android.ModuleBase |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 100 | |
| 101 | properties filesystemCreatorProps |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | func filesystemCreatorFactory() android.Module { |
| 105 | module := &filesystemCreator{} |
| 106 | |
Cole Faust | 6978879 | 2024-10-10 11:00:36 -0700 | [diff] [blame] | 107 | android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibCommon) |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 108 | module.AddProperties(&module.properties) |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 109 | android.AddLoadHook(module, func(ctx android.LoadHookContext) { |
| 110 | module.createInternalModules(ctx) |
| 111 | }) |
| 112 | |
| 113 | return module |
| 114 | } |
| 115 | |
| 116 | func (f *filesystemCreator) createInternalModules(ctx android.LoadHookContext) { |
Spandan Das | 7a46f6c | 2024-10-14 18:41:18 +0000 | [diff] [blame] | 117 | partitionTypes := []string{"system"} |
| 118 | if ctx.DeviceConfig().SystemExtPath() == "system_ext" { // system_ext exists |
| 119 | partitionTypes = append(partitionTypes, "system_ext") |
| 120 | } |
| 121 | for _, partitionType := range partitionTypes { |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 122 | if f.createPartition(ctx, partitionType) { |
| 123 | f.properties.Generated_partition_types = append(f.properties.Generated_partition_types, partitionType) |
| 124 | } else { |
| 125 | f.properties.Unsupported_partition_types = append(f.properties.Unsupported_partition_types, partitionType) |
| 126 | } |
| 127 | } |
Jihoon Kang | f1c79ca | 2024-10-09 20:18:38 +0000 | [diff] [blame] | 128 | f.createDeviceModule(ctx) |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 129 | } |
| 130 | |
Jihoon Kang | ac2d1ba | 2024-10-12 01:44:47 +0000 | [diff] [blame] | 131 | func (f *filesystemCreator) generatedModuleName(cfg android.Config, suffix string) string { |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 132 | prefix := "soong" |
| 133 | if cfg.HasDeviceProduct() { |
| 134 | prefix = cfg.DeviceProduct() |
| 135 | } |
Jihoon Kang | f1c79ca | 2024-10-09 20:18:38 +0000 | [diff] [blame] | 136 | return fmt.Sprintf("%s_generated_%s", prefix, suffix) |
| 137 | } |
| 138 | |
Jihoon Kang | ac2d1ba | 2024-10-12 01:44:47 +0000 | [diff] [blame] | 139 | func (f *filesystemCreator) generatedModuleNameForPartition(cfg android.Config, partitionType string) string { |
| 140 | return f.generatedModuleName(cfg, fmt.Sprintf("%s_image", partitionType)) |
Jihoon Kang | f1c79ca | 2024-10-09 20:18:38 +0000 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | func (f *filesystemCreator) createDeviceModule(ctx android.LoadHookContext) { |
| 144 | baseProps := &struct { |
| 145 | Name *string |
| 146 | }{ |
Jihoon Kang | ac2d1ba | 2024-10-12 01:44:47 +0000 | [diff] [blame] | 147 | Name: proptools.StringPtr(f.generatedModuleName(ctx.Config(), "device")), |
Jihoon Kang | f1c79ca | 2024-10-09 20:18:38 +0000 | [diff] [blame] | 148 | } |
| 149 | |
Spandan Das | 7a46f6c | 2024-10-14 18:41:18 +0000 | [diff] [blame] | 150 | // Currently, only the system and system_ext partition module is created. |
Jihoon Kang | f1c79ca | 2024-10-09 20:18:38 +0000 | [diff] [blame] | 151 | partitionProps := &filesystem.PartitionNameProperties{} |
| 152 | if android.InList("system", f.properties.Generated_partition_types) { |
Jihoon Kang | ac2d1ba | 2024-10-12 01:44:47 +0000 | [diff] [blame] | 153 | partitionProps.System_partition_name = proptools.StringPtr(f.generatedModuleNameForPartition(ctx.Config(), "system")) |
Jihoon Kang | f1c79ca | 2024-10-09 20:18:38 +0000 | [diff] [blame] | 154 | } |
Spandan Das | 7a46f6c | 2024-10-14 18:41:18 +0000 | [diff] [blame] | 155 | if android.InList("system_ext", f.properties.Generated_partition_types) { |
| 156 | partitionProps.System_ext_partition_name = proptools.StringPtr(f.generatedModuleNameForPartition(ctx.Config(), "system_ext")) |
| 157 | } |
Jihoon Kang | f1c79ca | 2024-10-09 20:18:38 +0000 | [diff] [blame] | 158 | |
| 159 | ctx.CreateModule(filesystem.AndroidDeviceFactory, baseProps, partitionProps) |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 160 | } |
| 161 | |
Spandan Das | cbe641a | 2024-10-14 21:07:34 +0000 | [diff] [blame^] | 162 | var ( |
| 163 | // https://source.corp.google.com/h/googleplex-android/platform/build/+/639d79f5012a6542ab1f733b0697db45761ab0f3:core/packaging/flags.mk;l=21;drc=5ba8a8b77507f93aa48cc61c5ba3f31a4d0cbf37;bpv=1;bpt=0 |
| 164 | partitionsWithAconfig = []string{"system", "product", "vendor"} |
| 165 | ) |
| 166 | |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 167 | // Creates a soong module to build the given partition. Returns false if we can't support building |
| 168 | // it. |
| 169 | func (f *filesystemCreator) createPartition(ctx android.LoadHookContext, partitionType string) bool { |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 170 | baseProps := &struct { |
| 171 | Name *string |
| 172 | }{ |
Jihoon Kang | ac2d1ba | 2024-10-12 01:44:47 +0000 | [diff] [blame] | 173 | Name: proptools.StringPtr(f.generatedModuleNameForPartition(ctx.Config(), partitionType)), |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 174 | } |
| 175 | |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 176 | fsProps := &filesystem.FilesystemProperties{} |
| 177 | |
| 178 | // Don't build this module on checkbuilds, the soong-built partitions are still in-progress |
| 179 | // and sometimes don't build. |
| 180 | fsProps.Unchecked_module = proptools.BoolPtr(true) |
| 181 | |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 182 | partitionVars := ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 183 | specificPartitionVars := partitionVars.PartitionQualifiedVariables[partitionType] |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 184 | |
| 185 | // BOARD_AVB_ENABLE |
| 186 | fsProps.Use_avb = proptools.BoolPtr(partitionVars.BoardAvbEnable) |
| 187 | // BOARD_AVB_KEY_PATH |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 188 | fsProps.Avb_private_key = proptools.StringPtr(specificPartitionVars.BoardAvbKeyPath) |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 189 | // BOARD_AVB_ALGORITHM |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 190 | fsProps.Avb_algorithm = proptools.StringPtr(specificPartitionVars.BoardAvbAlgorithm) |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 191 | // BOARD_AVB_SYSTEM_ROLLBACK_INDEX |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 192 | if rollbackIndex, err := strconv.ParseInt(specificPartitionVars.BoardAvbRollbackIndex, 10, 64); err == nil { |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 193 | fsProps.Rollback_index = proptools.Int64Ptr(rollbackIndex) |
| 194 | } |
| 195 | |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 196 | fsProps.Partition_name = proptools.StringPtr(partitionType) |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 197 | // BOARD_SYSTEMIMAGE_FILE_SYSTEM_TYPE |
Spandan Das | 7a46f6c | 2024-10-14 18:41:18 +0000 | [diff] [blame] | 198 | fsType := specificPartitionVars.BoardFileSystemType |
| 199 | if fsType == "" { |
| 200 | fsType = "ext4" //default |
| 201 | } |
| 202 | fsProps.Type = proptools.StringPtr(fsType) |
| 203 | if filesystem.GetFsTypeFromString(ctx, *fsProps.Type).IsUnknown() { |
| 204 | // Currently the android_filesystem module type only supports a handful of FS types like ext4, erofs |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 205 | return false |
| 206 | } |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 207 | |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 208 | fsProps.Base_dir = proptools.StringPtr(partitionType) |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 209 | |
Spandan Das | cbe641a | 2024-10-14 21:07:34 +0000 | [diff] [blame^] | 210 | fsProps.Gen_aconfig_flags_pb = proptools.BoolPtr(android.InList(partitionType, partitionsWithAconfig)) |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 211 | |
| 212 | // Identical to that of the generic_system_image |
| 213 | fsProps.Fsverity.Inputs = []string{ |
| 214 | "etc/boot-image.prof", |
| 215 | "etc/dirty-image-objects", |
| 216 | "etc/preloaded-classes", |
| 217 | "etc/classpaths/*.pb", |
| 218 | "framework/*", |
| 219 | "framework/*/*", // framework/{arch} |
| 220 | "framework/oat/*/*", // framework/oat/{arch} |
| 221 | } |
| 222 | |
| 223 | // system_image properties that are not set: |
| 224 | // - filesystemProperties.Avb_hash_algorithm |
| 225 | // - filesystemProperties.File_contexts |
| 226 | // - filesystemProperties.Dirs |
| 227 | // - filesystemProperties.Symlinks |
| 228 | // - filesystemProperties.Fake_timestamp |
| 229 | // - filesystemProperties.Uuid |
| 230 | // - filesystemProperties.Mount_point |
| 231 | // - filesystemProperties.Include_make_built_files |
| 232 | // - filesystemProperties.Build_logtags |
| 233 | // - filesystemProperties.Fsverity.Libs |
| 234 | // - systemImageProperties.Linker_config_src |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 235 | var module android.Module |
| 236 | if partitionType == "system" { |
| 237 | module = ctx.CreateModule(filesystem.SystemImageFactory, baseProps, fsProps) |
| 238 | } else { |
Spandan Das | cbe641a | 2024-10-14 21:07:34 +0000 | [diff] [blame^] | 239 | // Explicitly set the partition. |
| 240 | fsProps.Partition_type = proptools.StringPtr(partitionType) |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 241 | module = ctx.CreateModule(filesystem.FilesystemFactory, baseProps, fsProps) |
| 242 | } |
| 243 | module.HideFromMake() |
| 244 | return true |
| 245 | } |
| 246 | |
| 247 | func (f *filesystemCreator) createDiffTest(ctx android.ModuleContext, partitionType string) android.Path { |
Jihoon Kang | ac2d1ba | 2024-10-12 01:44:47 +0000 | [diff] [blame] | 248 | partitionModuleName := f.generatedModuleNameForPartition(ctx.Config(), partitionType) |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 249 | systemImage := ctx.GetDirectDepWithTag(partitionModuleName, generatedFilesystemDepTag) |
| 250 | filesystemInfo, ok := android.OtherModuleProvider(ctx, systemImage, filesystem.FilesystemProvider) |
| 251 | if !ok { |
| 252 | ctx.ModuleErrorf("Expected module %s to provide FileysystemInfo", partitionModuleName) |
| 253 | } |
| 254 | makeFileList := android.PathForArbitraryOutput(ctx, fmt.Sprintf("target/product/%s/obj/PACKAGING/%s_intermediates/file_list.txt", ctx.Config().DeviceName(), partitionType)) |
| 255 | // For now, don't allowlist anything. The test will fail, but that's fine in the current |
| 256 | // early stages where we're just figuring out what we need |
Jihoon Kang | 9e866c8 | 2024-10-07 22:39:18 +0000 | [diff] [blame] | 257 | emptyAllowlistFile := android.PathForModuleOut(ctx, fmt.Sprintf("allowlist_%s.txt", partitionModuleName)) |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 258 | android.WriteFileRule(ctx, emptyAllowlistFile, "") |
Jihoon Kang | 9e866c8 | 2024-10-07 22:39:18 +0000 | [diff] [blame] | 259 | diffTestResultFile := android.PathForModuleOut(ctx, fmt.Sprintf("diff_test_%s.txt", partitionModuleName)) |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 260 | |
| 261 | builder := android.NewRuleBuilder(pctx, ctx) |
| 262 | builder.Command().BuiltTool("file_list_diff"). |
| 263 | Input(makeFileList). |
| 264 | Input(filesystemInfo.FileListFile). |
Jihoon Kang | 9e866c8 | 2024-10-07 22:39:18 +0000 | [diff] [blame] | 265 | Text(partitionModuleName). |
| 266 | FlagWithInput("--allowlists ", emptyAllowlistFile) |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 267 | builder.Command().Text("touch").Output(diffTestResultFile) |
| 268 | builder.Build(partitionModuleName+" diff test", partitionModuleName+" diff test") |
| 269 | return diffTestResultFile |
| 270 | } |
| 271 | |
| 272 | func createFailingCommand(ctx android.ModuleContext, message string) android.Path { |
| 273 | hasher := sha256.New() |
| 274 | hasher.Write([]byte(message)) |
| 275 | filename := fmt.Sprintf("failing_command_%x.txt", hasher.Sum(nil)) |
| 276 | file := android.PathForModuleOut(ctx, filename) |
| 277 | builder := android.NewRuleBuilder(pctx, ctx) |
| 278 | builder.Command().Textf("echo %s", proptools.NinjaAndShellEscape(message)) |
| 279 | builder.Command().Text("exit 1 #").Output(file) |
| 280 | builder.Build("failing command "+filename, "failing command "+filename) |
| 281 | return file |
| 282 | } |
| 283 | |
| 284 | type systemImageDepTagType struct { |
| 285 | blueprint.BaseDependencyTag |
| 286 | } |
| 287 | |
| 288 | var generatedFilesystemDepTag systemImageDepTagType |
| 289 | |
| 290 | func (f *filesystemCreator) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 291 | for _, partitionType := range f.properties.Generated_partition_types { |
Jihoon Kang | ac2d1ba | 2024-10-12 01:44:47 +0000 | [diff] [blame] | 292 | ctx.AddDependency(ctx.Module(), generatedFilesystemDepTag, f.generatedModuleNameForPartition(ctx.Config(), partitionType)) |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 293 | } |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | func (f *filesystemCreator) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 297 | if ctx.ModuleDir() != "build/soong/fsgen" { |
| 298 | ctx.ModuleErrorf("There can only be one soong_filesystem_creator in build/soong/fsgen") |
| 299 | } |
| 300 | f.HideFromMake() |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 301 | |
mrziwang | 8f86c88 | 2024-10-03 12:34:33 -0700 | [diff] [blame] | 302 | content := generateBpContent(ctx, "system") |
| 303 | generatedBp := android.PathForOutput(ctx, "soong_generated_product_config.bp") |
| 304 | android.WriteFileRule(ctx, generatedBp, content) |
| 305 | ctx.Phony("product_config_to_bp", generatedBp) |
| 306 | |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 307 | var diffTestFiles []android.Path |
| 308 | for _, partitionType := range f.properties.Generated_partition_types { |
| 309 | diffTestFiles = append(diffTestFiles, f.createDiffTest(ctx, partitionType)) |
| 310 | } |
| 311 | for _, partitionType := range f.properties.Unsupported_partition_types { |
| 312 | diffTestFiles = append(diffTestFiles, createFailingCommand(ctx, fmt.Sprintf("Couldn't build %s partition", partitionType))) |
| 313 | } |
| 314 | ctx.Phony("soong_generated_filesystem_tests", diffTestFiles...) |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 315 | } |
mrziwang | 8f86c88 | 2024-10-03 12:34:33 -0700 | [diff] [blame] | 316 | |
Jihoon Kang | ac2d1ba | 2024-10-12 01:44:47 +0000 | [diff] [blame] | 317 | func installInSystem(ctx android.BottomUpMutatorContext, m android.Module) bool { |
| 318 | return m.PartitionTag(ctx.DeviceConfig()) == "system" && !m.InstallInData() && |
| 319 | !m.InstallInTestcases() && !m.InstallInSanitizerDir() && !m.InstallInVendorRamdisk() && |
| 320 | !m.InstallInDebugRamdisk() && !m.InstallInRecovery() && !m.InstallInOdm() && |
| 321 | !m.InstallInVendor() |
mrziwang | 8f86c88 | 2024-10-03 12:34:33 -0700 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | // TODO: assemble baseProps and fsProps here |
| 325 | func generateBpContent(ctx android.EarlyModuleContext, partitionType string) string { |
| 326 | // Currently only system partition is supported |
| 327 | if partitionType != "system" { |
| 328 | return "" |
| 329 | } |
| 330 | |
Jihoon Kang | ac2d1ba | 2024-10-12 01:44:47 +0000 | [diff] [blame] | 331 | deps := ctx.Config().Get(collectFsDepsOnceKey).(*[]string) |
mrziwang | 8f86c88 | 2024-10-03 12:34:33 -0700 | [diff] [blame] | 332 | depProps := &android.PackagingProperties{ |
Jihoon Kang | ac2d1ba | 2024-10-12 01:44:47 +0000 | [diff] [blame] | 333 | Deps: android.NewSimpleConfigurable(android.SortedUniqueStrings(*deps)), |
mrziwang | 8f86c88 | 2024-10-03 12:34:33 -0700 | [diff] [blame] | 334 | } |
| 335 | |
| 336 | result, err := proptools.RepackProperties([]interface{}{depProps}) |
| 337 | if err != nil { |
| 338 | ctx.ModuleErrorf(err.Error()) |
| 339 | } |
| 340 | |
| 341 | file := &parser.File{ |
| 342 | Defs: []parser.Definition{ |
| 343 | &parser.Module{ |
| 344 | Type: "module", |
| 345 | Map: *result, |
| 346 | }, |
| 347 | }, |
| 348 | } |
| 349 | bytes, err := parser.Print(file) |
| 350 | if err != nil { |
| 351 | ctx.ModuleErrorf(err.Error()) |
| 352 | } |
| 353 | return strings.TrimSpace(string(bytes)) |
| 354 | } |