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) { |
Jihoon Kang | ac2d1ba | 2024-10-12 01:44:47 +0000 | [diff] [blame] | 117 | for _, partitionType := range []string{"system"} { |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 118 | if f.createPartition(ctx, partitionType) { |
| 119 | f.properties.Generated_partition_types = append(f.properties.Generated_partition_types, partitionType) |
| 120 | } else { |
| 121 | f.properties.Unsupported_partition_types = append(f.properties.Unsupported_partition_types, partitionType) |
| 122 | } |
| 123 | } |
Jihoon Kang | f1c79ca | 2024-10-09 20:18:38 +0000 | [diff] [blame] | 124 | f.createDeviceModule(ctx) |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 125 | } |
| 126 | |
Jihoon Kang | ac2d1ba | 2024-10-12 01:44:47 +0000 | [diff] [blame] | 127 | func (f *filesystemCreator) generatedModuleName(cfg android.Config, suffix string) string { |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 128 | prefix := "soong" |
| 129 | if cfg.HasDeviceProduct() { |
| 130 | prefix = cfg.DeviceProduct() |
| 131 | } |
Jihoon Kang | f1c79ca | 2024-10-09 20:18:38 +0000 | [diff] [blame] | 132 | return fmt.Sprintf("%s_generated_%s", prefix, suffix) |
| 133 | } |
| 134 | |
Jihoon Kang | ac2d1ba | 2024-10-12 01:44:47 +0000 | [diff] [blame] | 135 | func (f *filesystemCreator) generatedModuleNameForPartition(cfg android.Config, partitionType string) string { |
| 136 | return f.generatedModuleName(cfg, fmt.Sprintf("%s_image", partitionType)) |
Jihoon Kang | f1c79ca | 2024-10-09 20:18:38 +0000 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | func (f *filesystemCreator) createDeviceModule(ctx android.LoadHookContext) { |
| 140 | baseProps := &struct { |
| 141 | Name *string |
| 142 | }{ |
Jihoon Kang | ac2d1ba | 2024-10-12 01:44:47 +0000 | [diff] [blame] | 143 | Name: proptools.StringPtr(f.generatedModuleName(ctx.Config(), "device")), |
Jihoon Kang | f1c79ca | 2024-10-09 20:18:38 +0000 | [diff] [blame] | 144 | } |
| 145 | |
Priyanka Advani (xWF) | 41e4c99 | 2024-10-11 16:53:20 +0000 | [diff] [blame] | 146 | // Currently, only the system partition module is created. |
Jihoon Kang | f1c79ca | 2024-10-09 20:18:38 +0000 | [diff] [blame] | 147 | partitionProps := &filesystem.PartitionNameProperties{} |
| 148 | if android.InList("system", f.properties.Generated_partition_types) { |
Jihoon Kang | ac2d1ba | 2024-10-12 01:44:47 +0000 | [diff] [blame] | 149 | partitionProps.System_partition_name = proptools.StringPtr(f.generatedModuleNameForPartition(ctx.Config(), "system")) |
Jihoon Kang | f1c79ca | 2024-10-09 20:18:38 +0000 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | ctx.CreateModule(filesystem.AndroidDeviceFactory, baseProps, partitionProps) |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | // Creates a soong module to build the given partition. Returns false if we can't support building |
| 156 | // it. |
| 157 | func (f *filesystemCreator) createPartition(ctx android.LoadHookContext, partitionType string) bool { |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 158 | baseProps := &struct { |
| 159 | Name *string |
| 160 | }{ |
Jihoon Kang | ac2d1ba | 2024-10-12 01:44:47 +0000 | [diff] [blame] | 161 | Name: proptools.StringPtr(f.generatedModuleNameForPartition(ctx.Config(), partitionType)), |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 162 | } |
| 163 | |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 164 | fsProps := &filesystem.FilesystemProperties{} |
| 165 | |
| 166 | // Don't build this module on checkbuilds, the soong-built partitions are still in-progress |
| 167 | // and sometimes don't build. |
| 168 | fsProps.Unchecked_module = proptools.BoolPtr(true) |
| 169 | |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 170 | partitionVars := ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 171 | specificPartitionVars := partitionVars.PartitionQualifiedVariables[partitionType] |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 172 | |
| 173 | // BOARD_AVB_ENABLE |
| 174 | fsProps.Use_avb = proptools.BoolPtr(partitionVars.BoardAvbEnable) |
| 175 | // BOARD_AVB_KEY_PATH |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 176 | fsProps.Avb_private_key = proptools.StringPtr(specificPartitionVars.BoardAvbKeyPath) |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 177 | // BOARD_AVB_ALGORITHM |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 178 | fsProps.Avb_algorithm = proptools.StringPtr(specificPartitionVars.BoardAvbAlgorithm) |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 179 | // BOARD_AVB_SYSTEM_ROLLBACK_INDEX |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 180 | if rollbackIndex, err := strconv.ParseInt(specificPartitionVars.BoardAvbRollbackIndex, 10, 64); err == nil { |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 181 | fsProps.Rollback_index = proptools.Int64Ptr(rollbackIndex) |
| 182 | } |
| 183 | |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 184 | fsProps.Partition_name = proptools.StringPtr(partitionType) |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 185 | // BOARD_SYSTEMIMAGE_FILE_SYSTEM_TYPE |
Priyanka Advani (xWF) | 41e4c99 | 2024-10-11 16:53:20 +0000 | [diff] [blame] | 186 | fsProps.Type = proptools.StringPtr(specificPartitionVars.BoardFileSystemType) |
| 187 | if *fsProps.Type != "ext4" { |
| 188 | // TODO(b/372522486): Support other FS types. |
| 189 | // Currently the android_filesystem module type only supports ext4: |
| 190 | // https://cs.android.com/android/platform/superproject/main/+/main:build/soong/filesystem/filesystem.go;l=416;drc=98047cfd07944b297a12d173453bc984806760d2 |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 191 | return false |
| 192 | } |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 193 | |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 194 | fsProps.Base_dir = proptools.StringPtr(partitionType) |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 195 | |
| 196 | fsProps.Gen_aconfig_flags_pb = proptools.BoolPtr(true) |
| 197 | |
| 198 | // Identical to that of the generic_system_image |
| 199 | fsProps.Fsverity.Inputs = []string{ |
| 200 | "etc/boot-image.prof", |
| 201 | "etc/dirty-image-objects", |
| 202 | "etc/preloaded-classes", |
| 203 | "etc/classpaths/*.pb", |
| 204 | "framework/*", |
| 205 | "framework/*/*", // framework/{arch} |
| 206 | "framework/oat/*/*", // framework/oat/{arch} |
| 207 | } |
| 208 | |
| 209 | // system_image properties that are not set: |
| 210 | // - filesystemProperties.Avb_hash_algorithm |
| 211 | // - filesystemProperties.File_contexts |
| 212 | // - filesystemProperties.Dirs |
| 213 | // - filesystemProperties.Symlinks |
| 214 | // - filesystemProperties.Fake_timestamp |
| 215 | // - filesystemProperties.Uuid |
| 216 | // - filesystemProperties.Mount_point |
| 217 | // - filesystemProperties.Include_make_built_files |
| 218 | // - filesystemProperties.Build_logtags |
| 219 | // - filesystemProperties.Fsverity.Libs |
| 220 | // - systemImageProperties.Linker_config_src |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 221 | var module android.Module |
| 222 | if partitionType == "system" { |
| 223 | module = ctx.CreateModule(filesystem.SystemImageFactory, baseProps, fsProps) |
| 224 | } else { |
| 225 | module = ctx.CreateModule(filesystem.FilesystemFactory, baseProps, fsProps) |
| 226 | } |
| 227 | module.HideFromMake() |
| 228 | return true |
| 229 | } |
| 230 | |
| 231 | func (f *filesystemCreator) createDiffTest(ctx android.ModuleContext, partitionType string) android.Path { |
Jihoon Kang | ac2d1ba | 2024-10-12 01:44:47 +0000 | [diff] [blame] | 232 | partitionModuleName := f.generatedModuleNameForPartition(ctx.Config(), partitionType) |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 233 | systemImage := ctx.GetDirectDepWithTag(partitionModuleName, generatedFilesystemDepTag) |
| 234 | filesystemInfo, ok := android.OtherModuleProvider(ctx, systemImage, filesystem.FilesystemProvider) |
| 235 | if !ok { |
| 236 | ctx.ModuleErrorf("Expected module %s to provide FileysystemInfo", partitionModuleName) |
| 237 | } |
| 238 | makeFileList := android.PathForArbitraryOutput(ctx, fmt.Sprintf("target/product/%s/obj/PACKAGING/%s_intermediates/file_list.txt", ctx.Config().DeviceName(), partitionType)) |
| 239 | // For now, don't allowlist anything. The test will fail, but that's fine in the current |
| 240 | // early stages where we're just figuring out what we need |
Jihoon Kang | 9e866c8 | 2024-10-07 22:39:18 +0000 | [diff] [blame] | 241 | emptyAllowlistFile := android.PathForModuleOut(ctx, fmt.Sprintf("allowlist_%s.txt", partitionModuleName)) |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 242 | android.WriteFileRule(ctx, emptyAllowlistFile, "") |
Jihoon Kang | 9e866c8 | 2024-10-07 22:39:18 +0000 | [diff] [blame] | 243 | diffTestResultFile := android.PathForModuleOut(ctx, fmt.Sprintf("diff_test_%s.txt", partitionModuleName)) |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 244 | |
| 245 | builder := android.NewRuleBuilder(pctx, ctx) |
| 246 | builder.Command().BuiltTool("file_list_diff"). |
| 247 | Input(makeFileList). |
| 248 | Input(filesystemInfo.FileListFile). |
Jihoon Kang | 9e866c8 | 2024-10-07 22:39:18 +0000 | [diff] [blame] | 249 | Text(partitionModuleName). |
| 250 | FlagWithInput("--allowlists ", emptyAllowlistFile) |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 251 | builder.Command().Text("touch").Output(diffTestResultFile) |
| 252 | builder.Build(partitionModuleName+" diff test", partitionModuleName+" diff test") |
| 253 | return diffTestResultFile |
| 254 | } |
| 255 | |
| 256 | func createFailingCommand(ctx android.ModuleContext, message string) android.Path { |
| 257 | hasher := sha256.New() |
| 258 | hasher.Write([]byte(message)) |
| 259 | filename := fmt.Sprintf("failing_command_%x.txt", hasher.Sum(nil)) |
| 260 | file := android.PathForModuleOut(ctx, filename) |
| 261 | builder := android.NewRuleBuilder(pctx, ctx) |
| 262 | builder.Command().Textf("echo %s", proptools.NinjaAndShellEscape(message)) |
| 263 | builder.Command().Text("exit 1 #").Output(file) |
| 264 | builder.Build("failing command "+filename, "failing command "+filename) |
| 265 | return file |
| 266 | } |
| 267 | |
| 268 | type systemImageDepTagType struct { |
| 269 | blueprint.BaseDependencyTag |
| 270 | } |
| 271 | |
| 272 | var generatedFilesystemDepTag systemImageDepTagType |
| 273 | |
| 274 | func (f *filesystemCreator) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 275 | for _, partitionType := range f.properties.Generated_partition_types { |
Jihoon Kang | ac2d1ba | 2024-10-12 01:44:47 +0000 | [diff] [blame] | 276 | ctx.AddDependency(ctx.Module(), generatedFilesystemDepTag, f.generatedModuleNameForPartition(ctx.Config(), partitionType)) |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 277 | } |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | func (f *filesystemCreator) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 281 | if ctx.ModuleDir() != "build/soong/fsgen" { |
| 282 | ctx.ModuleErrorf("There can only be one soong_filesystem_creator in build/soong/fsgen") |
| 283 | } |
| 284 | f.HideFromMake() |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 285 | |
mrziwang | 8f86c88 | 2024-10-03 12:34:33 -0700 | [diff] [blame] | 286 | content := generateBpContent(ctx, "system") |
| 287 | generatedBp := android.PathForOutput(ctx, "soong_generated_product_config.bp") |
| 288 | android.WriteFileRule(ctx, generatedBp, content) |
| 289 | ctx.Phony("product_config_to_bp", generatedBp) |
| 290 | |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 291 | var diffTestFiles []android.Path |
| 292 | for _, partitionType := range f.properties.Generated_partition_types { |
| 293 | diffTestFiles = append(diffTestFiles, f.createDiffTest(ctx, partitionType)) |
| 294 | } |
| 295 | for _, partitionType := range f.properties.Unsupported_partition_types { |
| 296 | diffTestFiles = append(diffTestFiles, createFailingCommand(ctx, fmt.Sprintf("Couldn't build %s partition", partitionType))) |
| 297 | } |
| 298 | ctx.Phony("soong_generated_filesystem_tests", diffTestFiles...) |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 299 | } |
mrziwang | 8f86c88 | 2024-10-03 12:34:33 -0700 | [diff] [blame] | 300 | |
Jihoon Kang | ac2d1ba | 2024-10-12 01:44:47 +0000 | [diff] [blame] | 301 | func installInSystem(ctx android.BottomUpMutatorContext, m android.Module) bool { |
| 302 | return m.PartitionTag(ctx.DeviceConfig()) == "system" && !m.InstallInData() && |
| 303 | !m.InstallInTestcases() && !m.InstallInSanitizerDir() && !m.InstallInVendorRamdisk() && |
| 304 | !m.InstallInDebugRamdisk() && !m.InstallInRecovery() && !m.InstallInOdm() && |
| 305 | !m.InstallInVendor() |
mrziwang | 8f86c88 | 2024-10-03 12:34:33 -0700 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | // TODO: assemble baseProps and fsProps here |
| 309 | func generateBpContent(ctx android.EarlyModuleContext, partitionType string) string { |
| 310 | // Currently only system partition is supported |
| 311 | if partitionType != "system" { |
| 312 | return "" |
| 313 | } |
| 314 | |
Jihoon Kang | ac2d1ba | 2024-10-12 01:44:47 +0000 | [diff] [blame] | 315 | deps := ctx.Config().Get(collectFsDepsOnceKey).(*[]string) |
mrziwang | 8f86c88 | 2024-10-03 12:34:33 -0700 | [diff] [blame] | 316 | depProps := &android.PackagingProperties{ |
Jihoon Kang | ac2d1ba | 2024-10-12 01:44:47 +0000 | [diff] [blame] | 317 | Deps: android.NewSimpleConfigurable(android.SortedUniqueStrings(*deps)), |
mrziwang | 8f86c88 | 2024-10-03 12:34:33 -0700 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | result, err := proptools.RepackProperties([]interface{}{depProps}) |
| 321 | if err != nil { |
| 322 | ctx.ModuleErrorf(err.Error()) |
| 323 | } |
| 324 | |
| 325 | file := &parser.File{ |
| 326 | Defs: []parser.Definition{ |
| 327 | &parser.Module{ |
| 328 | Type: "module", |
| 329 | Map: *result, |
| 330 | }, |
| 331 | }, |
| 332 | } |
| 333 | bytes, err := parser.Print(file) |
| 334 | if err != nil { |
| 335 | ctx.ModuleErrorf(err.Error()) |
| 336 | } |
| 337 | return strings.TrimSpace(string(bytes)) |
| 338 | } |