blob: 3f0864810881ac21e1f543da5277524db5a6c0a1 [file] [log] [blame]
Jiyong Park6f0f6882020-11-12 13:14:30 +09001// Copyright (C) 2020 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
15package filesystem
16
17import (
Jooyung Han65f402b2022-04-21 14:24:04 +090018 "crypto/sha256"
Jiyong Park6f0f6882020-11-12 13:14:30 +090019 "fmt"
Jooyung Han65f402b2022-04-21 14:24:04 +090020 "io"
Inseob Kim14199b02021-02-09 21:18:31 +090021 "path/filepath"
Cole Faust4a2a7c92024-03-12 12:44:40 -070022 "slices"
Nikita Ioffe2c8cdc62024-03-27 22:19:30 +000023 "strconv"
Inseob Kim14199b02021-02-09 21:18:31 +090024 "strings"
Jiyong Park6f0f6882020-11-12 13:14:30 +090025
26 "android/soong/android"
Jooyung Hane6067592023-03-16 13:11:17 +090027 "android/soong/cc"
Spandan Das71be42d2024-11-20 18:34:16 +000028 "android/soong/java"
Spandan Das92631882024-10-28 22:49:38 +000029 "android/soong/linkerconfig"
Jiyong Park65b62242020-11-25 12:44:59 +090030
31 "github.com/google/blueprint"
Jiyong Park71baa762021-01-18 21:11:03 +090032 "github.com/google/blueprint/proptools"
Jiyong Park6f0f6882020-11-12 13:14:30 +090033)
34
35func init() {
Jooyung Han9706cbc2021-04-15 22:43:48 +090036 registerBuildComponents(android.InitRegistrationContext)
Spandan Das71be42d2024-11-20 18:34:16 +000037 registerMutators(android.InitRegistrationContext)
Jooyung Han9706cbc2021-04-15 22:43:48 +090038}
39
40func registerBuildComponents(ctx android.RegistrationContext) {
Cole Faust92ccbe22024-10-03 14:38:37 -070041 ctx.RegisterModuleType("android_filesystem", FilesystemFactory)
Jiyong Parkf46b1af2024-04-05 18:13:33 +090042 ctx.RegisterModuleType("android_filesystem_defaults", filesystemDefaultsFactory)
Jihoon Kang98047cf2024-10-02 17:13:54 +000043 ctx.RegisterModuleType("android_system_image", SystemImageFactory)
Jiyong Parkbc485482022-11-15 22:31:49 +090044 ctx.RegisterModuleType("avb_add_hash_footer", avbAddHashFooterFactory)
Inseob Kim87230e62023-11-22 18:55:07 +090045 ctx.RegisterModuleType("avb_add_hash_footer_defaults", avbAddHashFooterDefaultsFactory)
Alice Wang000e3a32023-01-03 16:11:20 +000046 ctx.RegisterModuleType("avb_gen_vbmeta_image", avbGenVbmetaImageFactory)
Inseob Kim87230e62023-11-22 18:55:07 +090047 ctx.RegisterModuleType("avb_gen_vbmeta_image_defaults", avbGenVbmetaImageDefaultsFactory)
Jiyong Park6f0f6882020-11-12 13:14:30 +090048}
49
Spandan Das71be42d2024-11-20 18:34:16 +000050func registerMutators(ctx android.RegistrationContext) {
51 ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
52 ctx.BottomUp("add_autogenerated_rro_deps", addAutogeneratedRroDeps)
53 })
54}
55
Cole Fauste1676122024-12-03 17:32:25 -080056// Remember to add referenced files to implicits!
57var textFileProcessorRule = pctx.AndroidStaticRule("text_file_processing", blueprint.RuleParams{
58 Command: "build/soong/scripts/text_file_processor.py $in $out",
59 CommandDeps: []string{"build/soong/scripts/text_file_processor.py"},
60})
61
Jiyong Park6f0f6882020-11-12 13:14:30 +090062type filesystem struct {
63 android.ModuleBase
64 android.PackagingBase
Jiyong Parkf46b1af2024-04-05 18:13:33 +090065 android.DefaultableModuleBase
Jiyong Park65c49f52020-11-24 14:23:26 +090066
Jihoon Kang98047cf2024-10-02 17:13:54 +000067 properties FilesystemProperties
Jiyong Park71baa762021-01-18 21:11:03 +090068
Cole Faust4e9f5922024-11-13 16:09:23 -080069 output android.Path
Jiyong Park65c49f52020-11-24 14:23:26 +090070 installDir android.InstallPath
Jooyung Han0fbbc2b2022-03-25 12:35:46 +090071
Cole Faust4e9f5922024-11-13 16:09:23 -080072 fileListFile android.Path
Kiyoung Kim99a954d2024-06-21 14:22:20 +090073
74 // Keeps the entries installed from this filesystem
Jooyung Han0fbbc2b2022-03-25 12:35:46 +090075 entries []string
Kiyoung Kim67118212024-11-07 13:23:44 +090076
77 filesystemBuilder filesystemBuilder
Jiyong Park6f0f6882020-11-12 13:14:30 +090078}
79
Kiyoung Kim67118212024-11-07 13:23:44 +090080type filesystemBuilder interface {
81 BuildLinkerConfigFile(ctx android.ModuleContext, builder *android.RuleBuilder, rebasedDir android.OutputPath)
82 // Function that filters PackagingSpec in PackagingBase.GatherPackagingSpecs()
83 FilterPackagingSpec(spec android.PackagingSpec) bool
Inseob Kim3c0a0422024-11-05 17:21:37 +090084 // Function that modifies PackagingSpec in PackagingBase.GatherPackagingSpecs() to customize.
85 // For example, GSI system.img contains system_ext and product artifacts and their
86 // relPathInPackage need to be rebased to system/system_ext and system/system_product.
87 ModifyPackagingSpec(spec *android.PackagingSpec)
Kiyoung Kim23be5bb2024-11-27 00:50:30 +000088
89 // Function to check if the filesystem should not use `vintf_fragments` property,
90 // but use `vintf_fragment` module type instead
91 ShouldUseVintfFragmentModuleOnly() bool
Kiyoung Kim67118212024-11-07 13:23:44 +090092}
93
94var _ filesystemBuilder = (*filesystem)(nil)
95
Spandan Das69464c32024-10-25 20:08:06 +000096type SymlinkDefinition struct {
Inseob Kim14199b02021-02-09 21:18:31 +090097 Target *string
98 Name *string
99}
100
Jihoon Kang0a453892024-12-09 22:16:26 +0000101// CopyWithNamePrefix returns a new [SymlinkDefinition] with prefix added to Name.
102func (s *SymlinkDefinition) CopyWithNamePrefix(prefix string) SymlinkDefinition {
103 return SymlinkDefinition{
104 Target: s.Target,
105 Name: proptools.StringPtr(filepath.Join(prefix, proptools.String(s.Name))),
106 }
107}
108
Jihoon Kang98047cf2024-10-02 17:13:54 +0000109type FilesystemProperties struct {
Jiyong Park71baa762021-01-18 21:11:03 +0900110 // When set to true, sign the image with avbtool. Default is false.
111 Use_avb *bool
112
113 // Path to the private key that avbtool will use to sign this filesystem image.
114 // TODO(jiyong): allow apex_key to be specified here
115 Avb_private_key *string `android:"path"`
116
Shikha Panwar01403bb2022-12-22 12:22:57 +0000117 // Signing algorithm for avbtool. Default is SHA256_RSA4096.
Jiyong Park71baa762021-01-18 21:11:03 +0900118 Avb_algorithm *string
Jiyong Park11a65972021-02-01 21:09:38 +0900119
Shikha Panwar01403bb2022-12-22 12:22:57 +0000120 // Hash algorithm used for avbtool (for descriptors). This is passed as hash_algorithm to
121 // avbtool. Default used by avbtool is sha1.
Shikha Panware6f30632022-12-21 12:54:45 +0000122 Avb_hash_algorithm *string
123
Spandan Dase5c393c2024-12-12 19:25:07 +0000124 // The security patch passed to as the com.android.build.<type>.security_patch avb property.
125 Security_patch *string
126
Cole Fauste1676122024-12-03 17:32:25 -0800127 // Whether or not to use forward-error-correction codes when signing with AVB. Defaults to true.
128 Use_fec *bool
129
Nikita Ioffe2c8cdc62024-03-27 22:19:30 +0000130 // The index used to prevent rollback of the image. Only used if use_avb is true.
131 Rollback_index *int64
132
Jiyong Parkac4076d2021-03-15 23:21:30 +0900133 // Name of the partition stored in vbmeta desc. Defaults to the name of this module.
134 Partition_name *string
135
Spandan Dasc35d6fb2024-10-10 17:51:14 +0000136 // Type of the filesystem. Currently, ext4, erofs, cpio, and compressed_cpio are supported. Default
Jiyong Park837cdb22021-02-05 00:17:14 +0900137 // is ext4.
Jiyong Park11a65972021-02-01 21:09:38 +0900138 Type *string
Inseob Kimcc8e5362021-02-03 14:05:24 +0900139
Cole Faust9a24d902024-03-18 15:38:12 -0700140 // Identifies which partition this is for //visibility:any_system_image (and others) visibility
141 // checks, and will be used in the future for API surface checks.
142 Partition_type *string
143
Cole Faust0d467052024-12-04 17:19:19 -0800144 // file_contexts file to make image. Currently, only ext4 is supported. These file contexts
145 // will be compiled with sefcontext_compile
Inseob Kimcc8e5362021-02-03 14:05:24 +0900146 File_contexts *string `android:"path"`
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900147
Cole Faust0d467052024-12-04 17:19:19 -0800148 // The selinux file contexts, after having already run them through sefcontext_compile
149 Precompiled_file_contexts *string `android:"path"`
150
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900151 // Base directory relative to root, to which deps are installed, e.g. "system". Default is "."
152 // (root).
153 Base_dir *string
Inseob Kim14199b02021-02-09 21:18:31 +0900154
155 // Directories to be created under root. e.g. /dev, /proc, etc.
Cole Faustd9c6a5b2024-05-21 14:54:00 -0700156 Dirs proptools.Configurable[[]string]
Inseob Kim14199b02021-02-09 21:18:31 +0900157
Jihoon Kang1a478e52024-12-19 01:15:33 +0000158 // List of filesystem modules to include in creating the partition. The root directory of
159 // the provided filesystem modules are included in creating the partition.
160 // This is only supported for cpio and compressed cpio filesystem types.
161 Include_files_of []string
162
Inseob Kim14199b02021-02-09 21:18:31 +0900163 // Symbolic links to be created under root with "ln -sf <target> <name>".
Spandan Das69464c32024-10-25 20:08:06 +0000164 Symlinks []SymlinkDefinition
Jooyung Han65f402b2022-04-21 14:24:04 +0900165
166 // Seconds since unix epoch to override timestamps of file entries
167 Fake_timestamp *string
168
169 // When set, passed to mkuserimg_mke2fs --mke2fs_uuid & --mke2fs_hash_seed.
170 // Otherwise, they'll be set as random which might cause indeterministic build output.
171 Uuid *string
Inseob Kim376d72f2023-11-01 15:40:25 +0900172
173 // Mount point for this image. Default is "/"
174 Mount_point *string
Cole Faust4a2a7c92024-03-12 12:44:40 -0700175
176 // If set to the name of a partition ("system", "vendor", etc), this filesystem module
177 // will also include the contents of the make-built staging directories. If any soong
178 // modules would be installed to the same location as a make module, they will overwrite
179 // the make version.
180 Include_make_built_files string
Inseob Kim53391842024-03-29 17:44:07 +0900181
Inseob Kimb7b84572024-04-30 10:51:47 +0900182 // When set, builds etc/event-log-tags file by merging logtags from all dependencies.
183 // Default is false
184 Build_logtags *bool
185
Justin Yun74f3f302024-05-07 14:32:14 +0900186 // Install aconfig_flags.pb file for the modules installed in this partition.
187 Gen_aconfig_flags_pb *bool
188
Cole Faust34592c02024-12-13 11:20:24 -0800189 // List of names of other filesystem partitions to import their aconfig flags from.
190 // This is used for the system partition to import system_ext's aconfig flags, as currently
191 // those are considered one "container": aosp/3261300
192 Import_aconfig_flags_from []string
193
Inseob Kim53391842024-03-29 17:44:07 +0900194 Fsverity fsverityProperties
Cole Faust92ccbe22024-10-03 14:38:37 -0700195
196 // If this property is set to true, the filesystem will call ctx.UncheckedModule(), causing
197 // it to not be built on checkbuilds. Used for the automatic migration from make to soong
198 // build modules, where we want to emit some not-yet-working filesystems and we don't want them
199 // to be built.
200 Unchecked_module *bool `blueprint:"mutated"`
Spandan Dasc35d6fb2024-10-10 17:51:14 +0000201
202 Erofs ErofsProperties
Jihoon Kang0d545b82024-10-11 00:21:57 +0000203
mrziwang1a6291f2024-11-07 14:29:25 -0800204 F2fs F2fsProperties
205
Spandan Das2047a4c2024-11-11 21:24:58 +0000206 Linker_config LinkerConfigProperties
Spandan Das92631882024-10-28 22:49:38 +0000207
Jihoon Kang0d545b82024-10-11 00:21:57 +0000208 // Determines if the module is auto-generated from Soong or not. If the module is
209 // auto-generated, its deps are exempted from visibility enforcement.
210 Is_auto_generated *bool
Jihoon Kang6c03c8e2024-11-18 21:30:22 +0000211
212 // Path to the dev nodes description file. This is only needed for building the ramdisk
213 // partition and should not be explicitly specified.
214 Dev_nodes_description_file *string `android:"path" blueprint:"mutated"`
Spandan Das71be42d2024-11-20 18:34:16 +0000215
216 // Additional dependencies used for building android products
217 Android_filesystem_deps AndroidFilesystemDeps
218}
219
220type AndroidFilesystemDeps struct {
221 System *string
222 System_ext *string
Spandan Dasc35d6fb2024-10-10 17:51:14 +0000223}
224
225// Additional properties required to generate erofs FS partitions.
226type ErofsProperties struct {
227 // Compressor and Compression level passed to mkfs.erofs. e.g. (lz4hc,9)
228 // Please see external/erofs-utils/README for complete documentation.
229 Compressor *string
230
231 // Used as --compress-hints for mkfs.erofs
232 Compress_hints *string `android:"path"`
233
234 Sparse *bool
Jiyong Park71baa762021-01-18 21:11:03 +0900235}
236
mrziwang1a6291f2024-11-07 14:29:25 -0800237// Additional properties required to generate f2fs FS partitions.
238type F2fsProperties struct {
239 Sparse *bool
240}
241
Spandan Das173256b2024-10-31 19:59:30 +0000242type LinkerConfigProperties struct {
243
244 // Build a linker.config.pb file
245 Gen_linker_config *bool
246
247 // List of files (in .json format) that will be converted to a linker config file (in .pb format).
248 // The linker config file be installed in the filesystem at /etc/linker.config.pb
249 Linker_config_srcs []string `android:"path"`
250}
251
Jiyong Park65c49f52020-11-24 14:23:26 +0900252// android_filesystem packages a set of modules and their transitive dependencies into a filesystem
253// image. The filesystem images are expected to be mounted in the target device, which means the
254// modules in the filesystem image are built for the target device (i.e. Android, not Linux host).
255// The modules are placed in the filesystem image just like they are installed to the ordinary
256// partitions like system.img. For example, cc_library modules are placed under ./lib[64] directory.
Cole Faust92ccbe22024-10-03 14:38:37 -0700257func FilesystemFactory() android.Module {
Jiyong Park6f0f6882020-11-12 13:14:30 +0900258 module := &filesystem{}
Kiyoung Kim67118212024-11-07 13:23:44 +0900259 module.filesystemBuilder = module
Cole Faust2cfe6962024-09-17 11:31:14 -0700260 initFilesystemModule(module, module)
Jiyong Parkfa616132021-04-20 11:36:40 +0900261 return module
262}
263
Cole Faust2cfe6962024-09-17 11:31:14 -0700264func initFilesystemModule(module android.DefaultableModule, filesystemModule *filesystem) {
265 module.AddProperties(&filesystemModule.properties)
266 android.InitPackageModule(filesystemModule)
267 filesystemModule.PackagingBase.DepsCollectFirstTargetOnly = true
Jihoon Kang79196c52024-10-30 18:49:47 +0000268 filesystemModule.PackagingBase.AllowHighPriorityDeps = true
Jiyong Park6f0f6882020-11-12 13:14:30 +0900269 android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
Jiyong Parkf46b1af2024-04-05 18:13:33 +0900270 android.InitDefaultableModule(module)
Jihoon Kang6c03c8e2024-11-18 21:30:22 +0000271
272 android.AddLoadHook(module, func(ctx android.LoadHookContext) {
273 filesystemModule.setDevNodesDescriptionProp()
274 })
Jiyong Park6f0f6882020-11-12 13:14:30 +0900275}
276
Jihoon Kang0d545b82024-10-11 00:21:57 +0000277type depTag struct {
Jiyong Park12a719c2021-01-07 15:31:24 +0900278 blueprint.BaseDependencyTag
Jooyung Han092ef812021-03-10 15:40:34 +0900279 android.PackagingItemAlwaysDepTag
Jihoon Kang0d545b82024-10-11 00:21:57 +0000280}
281
282var dependencyTag = depTag{}
283
284type depTagWithVisibilityEnforcementBypass struct {
285 depTag
286}
287
Spandan Das71be42d2024-11-20 18:34:16 +0000288type interPartitionDepTag struct {
289 blueprint.BaseDependencyTag
290}
291
292var interPartitionDependencyTag = interPartitionDepTag{}
293
Jihoon Kang1a478e52024-12-19 01:15:33 +0000294var interPartitionInstallDependencyTag = interPartitionDepTag{}
295
Jihoon Kang0d545b82024-10-11 00:21:57 +0000296var _ android.ExcludeFromVisibilityEnforcementTag = (*depTagWithVisibilityEnforcementBypass)(nil)
297
298func (t depTagWithVisibilityEnforcementBypass) ExcludeFromVisibilityEnforcement() {}
299
300var dependencyTagWithVisibilityEnforcementBypass = depTagWithVisibilityEnforcementBypass{}
Jiyong Park65b62242020-11-25 12:44:59 +0900301
Jihoon Kang6c03c8e2024-11-18 21:30:22 +0000302// ramdiskDevNodesDescription is the name of the filegroup module that provides the file that
303// contains the description of dev nodes added to the CPIO archive for the ramdisk partition.
304const ramdiskDevNodesDescription = "ramdisk_node_list"
305
306func (f *filesystem) setDevNodesDescriptionProp() {
307 if proptools.String(f.properties.Partition_name) == "ramdisk" {
308 f.properties.Dev_nodes_description_file = proptools.StringPtr(":" + ramdiskDevNodesDescription)
309 }
310}
311
Jiyong Park6f0f6882020-11-12 13:14:30 +0900312func (f *filesystem) DepsMutator(ctx android.BottomUpMutatorContext) {
Jihoon Kang0d545b82024-10-11 00:21:57 +0000313 if proptools.Bool(f.properties.Is_auto_generated) {
314 f.AddDeps(ctx, dependencyTagWithVisibilityEnforcementBypass)
315 } else {
316 f.AddDeps(ctx, dependencyTag)
317 }
Spandan Das71be42d2024-11-20 18:34:16 +0000318 if f.properties.Android_filesystem_deps.System != nil {
319 ctx.AddDependency(ctx.Module(), interPartitionDependencyTag, proptools.String(f.properties.Android_filesystem_deps.System))
320 }
321 if f.properties.Android_filesystem_deps.System_ext != nil {
322 ctx.AddDependency(ctx.Module(), interPartitionDependencyTag, proptools.String(f.properties.Android_filesystem_deps.System_ext))
323 }
Cole Faust34592c02024-12-13 11:20:24 -0800324 for _, partition := range f.properties.Import_aconfig_flags_from {
325 ctx.AddDependency(ctx.Module(), importAconfigDependencyTag, partition)
326 }
Jihoon Kang1a478e52024-12-19 01:15:33 +0000327 for _, partition := range f.properties.Include_files_of {
328 ctx.AddDependency(ctx.Module(), interPartitionInstallDependencyTag, partition)
329 }
Jiyong Park6f0f6882020-11-12 13:14:30 +0900330}
331
Jiyong Park11a65972021-02-01 21:09:38 +0900332type fsType int
333
334const (
335 ext4Type fsType = iota
Spandan Dasc35d6fb2024-10-10 17:51:14 +0000336 erofsType
mrziwang1a6291f2024-11-07 14:29:25 -0800337 f2fsType
Jiyong Park11a65972021-02-01 21:09:38 +0900338 compressedCpioType
Jiyong Park837cdb22021-02-05 00:17:14 +0900339 cpioType // uncompressed
Jiyong Park11a65972021-02-01 21:09:38 +0900340 unknown
341)
342
Spandan Das7a46f6c2024-10-14 18:41:18 +0000343func (fs fsType) IsUnknown() bool {
344 return fs == unknown
345}
346
Cole Faust92ccbe22024-10-03 14:38:37 -0700347type FilesystemInfo struct {
348 // A text file containing the list of paths installed on the partition.
349 FileListFile android.Path
Jihoon Kang1a478e52024-12-19 01:15:33 +0000350
351 // Root directory of the installed partition
352 Rootdir android.Path
353
354 // A text file containing the hash value of the metadata and the content hashes
355 // of Rootdir
356 DirectoryHashFile android.Path
Cole Faust92ccbe22024-10-03 14:38:37 -0700357}
358
359var FilesystemProvider = blueprint.NewProvider[FilesystemInfo]()
360
Spandan Das7a46f6c2024-10-14 18:41:18 +0000361func GetFsTypeFromString(ctx android.EarlyModuleContext, typeStr string) fsType {
Jiyong Park11a65972021-02-01 21:09:38 +0900362 switch typeStr {
363 case "ext4":
364 return ext4Type
Spandan Dasc35d6fb2024-10-10 17:51:14 +0000365 case "erofs":
366 return erofsType
mrziwang1a6291f2024-11-07 14:29:25 -0800367 case "f2fs":
368 return f2fsType
Jiyong Park11a65972021-02-01 21:09:38 +0900369 case "compressed_cpio":
370 return compressedCpioType
Jiyong Park837cdb22021-02-05 00:17:14 +0900371 case "cpio":
372 return cpioType
Jiyong Park11a65972021-02-01 21:09:38 +0900373 default:
Jiyong Park11a65972021-02-01 21:09:38 +0900374 return unknown
375 }
376}
377
Spandan Das7a46f6c2024-10-14 18:41:18 +0000378func (f *filesystem) fsType(ctx android.ModuleContext) fsType {
379 typeStr := proptools.StringDefault(f.properties.Type, "ext4")
380 fsType := GetFsTypeFromString(ctx, typeStr)
381 if fsType == unknown {
382 ctx.PropertyErrorf("type", "%q not supported", typeStr)
383 }
384 return fsType
385}
386
Jiyong Park65c49f52020-11-24 14:23:26 +0900387func (f *filesystem) installFileName() string {
388 return f.BaseModuleName() + ".img"
389}
390
Inseob Kim53391842024-03-29 17:44:07 +0900391func (f *filesystem) partitionName() string {
392 return proptools.StringDefault(f.properties.Partition_name, f.Name())
393}
394
Kiyoung Kim67118212024-11-07 13:23:44 +0900395func (f *filesystem) FilterPackagingSpec(ps android.PackagingSpec) bool {
Jiyong Park7e7d4af2024-05-01 12:36:10 +0000396 // Filesystem module respects the installation semantic. A PackagingSpec from a module with
397 // IsSkipInstall() is skipped.
Cole Faust76a6e952024-11-07 16:56:45 -0800398 if ps.SkipInstall() {
399 return false
Spandan Das6d056502024-10-21 15:40:32 +0000400 }
Cole Faust76a6e952024-11-07 16:56:45 -0800401 if proptools.Bool(f.properties.Is_auto_generated) { // TODO (spandandas): Remove this.
402 pt := f.PartitionType()
Cole Faustc88cff12024-11-12 13:24:05 -0800403 return ps.Partition() == pt || strings.HasPrefix(ps.Partition(), pt+"/")
Cole Faust76a6e952024-11-07 16:56:45 -0800404 }
405 return true
Jiyong Park7e7d4af2024-05-01 12:36:10 +0000406}
407
Inseob Kim3c0a0422024-11-05 17:21:37 +0900408func (f *filesystem) ModifyPackagingSpec(ps *android.PackagingSpec) {
Cole Faustc88cff12024-11-12 13:24:05 -0800409 // Sometimes, android.modulePartition() returns a path with >1 path components.
410 // This makes the partition field of packagingSpecs have multiple components, like
411 // "system/product". Right now, the filesystem module doesn't look at the partition field
412 // when deciding what path to install the file under, only the RelPathInPackage field, so
413 // we move the later path components from partition to relPathInPackage. This should probably
414 // be revisited in the future.
415 prefix := f.PartitionType() + "/"
416 if strings.HasPrefix(ps.Partition(), prefix) {
417 subPartition := strings.TrimPrefix(ps.Partition(), prefix)
418 ps.SetPartition(f.PartitionType())
419 ps.SetRelPathInPackage(filepath.Join(subPartition, ps.RelPathInPackage()))
420 }
Inseob Kim3c0a0422024-11-05 17:21:37 +0900421}
422
Jiyong Park6f0f6882020-11-12 13:14:30 +0900423var pctx = android.NewPackageContext("android/soong/filesystem")
424
425func (f *filesystem) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jiyong Parkf46b1af2024-04-05 18:13:33 +0900426 validatePartitionType(ctx, f)
Kiyoung Kim23be5bb2024-11-27 00:50:30 +0000427 if f.filesystemBuilder.ShouldUseVintfFragmentModuleOnly() {
428 f.validateVintfFragments(ctx)
429 }
Jihoon Kang1a478e52024-12-19 01:15:33 +0000430
431 if len(f.properties.Include_files_of) > 0 && !android.InList(f.fsType(ctx), []fsType{compressedCpioType, cpioType}) {
432 ctx.PropertyErrorf("include_files_of", "include_files_of is only supported for cpio and compressed cpio filesystem types.")
433 }
434
435 var rootDir android.OutputPath
Jiyong Park11a65972021-02-01 21:09:38 +0900436 switch f.fsType(ctx) {
mrziwang1a6291f2024-11-07 14:29:25 -0800437 case ext4Type, erofsType, f2fsType:
Jihoon Kang1a478e52024-12-19 01:15:33 +0000438 f.output, rootDir = f.buildImageUsingBuildImage(ctx)
Jiyong Park11a65972021-02-01 21:09:38 +0900439 case compressedCpioType:
Jihoon Kang1a478e52024-12-19 01:15:33 +0000440 f.output, rootDir = f.buildCpioImage(ctx, true)
Jiyong Park837cdb22021-02-05 00:17:14 +0900441 case cpioType:
Jihoon Kang1a478e52024-12-19 01:15:33 +0000442 f.output, rootDir = f.buildCpioImage(ctx, false)
Jiyong Park11a65972021-02-01 21:09:38 +0900443 default:
444 return
445 }
446
447 f.installDir = android.PathForModuleInstall(ctx, "etc")
448 ctx.InstallFile(f.installDir, f.installFileName(), f.output)
mrziwang555d1332024-06-07 11:15:33 -0700449 ctx.SetOutputFiles([]android.Path{f.output}, "")
Kiyoung Kim99a954d2024-06-21 14:22:20 +0900450
Jihoon Kang1a478e52024-12-19 01:15:33 +0000451 if f.partitionName() == "recovery" {
452 rootDir = rootDir.Join(ctx, "root")
453 }
454
455 rootDirHash := android.PathForModuleOut(ctx, "rootdir-hash.txt")
456 ctx.Build(pctx, android.BuildParams{
457 Rule: android.WriteDirectoryHash,
458 Output: rootDirHash,
459 Implicit: f.output,
460 Args: map[string]string{
461 "dir": rootDir.String(),
462 },
463 })
464
Cole Faust4e9f5922024-11-13 16:09:23 -0800465 fileListFile := android.PathForModuleOut(ctx, "fileList")
466 android.WriteFileRule(ctx, fileListFile, f.installedFilesList())
Cole Faust92ccbe22024-10-03 14:38:37 -0700467
468 android.SetProvider(ctx, FilesystemProvider, FilesystemInfo{
Jihoon Kang1a478e52024-12-19 01:15:33 +0000469 FileListFile: fileListFile,
470 Rootdir: rootDir,
471 DirectoryHashFile: rootDirHash,
Cole Faust92ccbe22024-10-03 14:38:37 -0700472 })
Jihoon Kang1a478e52024-12-19 01:15:33 +0000473
Cole Faust4e9f5922024-11-13 16:09:23 -0800474 f.fileListFile = fileListFile
Cole Faust92ccbe22024-10-03 14:38:37 -0700475
476 if proptools.Bool(f.properties.Unchecked_module) {
477 ctx.UncheckedModule()
478 }
Kiyoung Kim99a954d2024-06-21 14:22:20 +0900479}
480
Kiyoung Kim23be5bb2024-11-27 00:50:30 +0000481func (f *filesystem) validateVintfFragments(ctx android.ModuleContext) {
482 visitedModule := map[string]bool{}
483 packagingSpecs := f.gatherFilteredPackagingSpecs(ctx)
484
485 moduleInFileSystem := func(mod android.Module) bool {
486 for _, ps := range android.OtherModuleProviderOrDefault(
487 ctx, mod, android.InstallFilesProvider).PackagingSpecs {
488 if _, ok := packagingSpecs[ps.RelPathInPackage()]; ok {
489 return true
490 }
491 }
492 return false
493 }
494
495 ctx.WalkDeps(func(child, parent android.Module) bool {
496 if visitedModule[child.Name()] {
497 return false
498 }
499 if !moduleInFileSystem(child) {
500 visitedModule[child.Name()] = true
501 return true
502 }
503 if vintfFragments := child.VintfFragments(ctx); vintfFragments != nil {
504 ctx.PropertyErrorf(
505 "vintf_fragments",
506 "Module %s is referenced by soong-defined filesystem %s with property vintf_fragments(%s) in use."+
507 " Use vintf_fragment_modules property instead.",
508 child.Name(),
509 f.BaseModuleName(),
510 strings.Join(vintfFragments, ", "),
511 )
512 }
513 visitedModule[child.Name()] = true
514 return true
515 })
516}
517
Cole Faust4e9f5922024-11-13 16:09:23 -0800518func (f *filesystem) appendToEntry(ctx android.ModuleContext, installedFile android.Path) {
Spandan Das420e16a2024-12-11 18:10:52 +0000519 partitionBaseDir := android.PathForModuleOut(ctx, f.rootDirString(), proptools.String(f.properties.Base_dir)).String() + "/"
Kiyoung Kim99a954d2024-06-21 14:22:20 +0900520
521 relPath, inTargetPartition := strings.CutPrefix(installedFile.String(), partitionBaseDir)
522 if inTargetPartition {
523 f.entries = append(f.entries, relPath)
524 }
525}
526
527func (f *filesystem) installedFilesList() string {
528 installedFilePaths := android.FirstUniqueStrings(f.entries)
529 slices.Sort(installedFilePaths)
530
531 return strings.Join(installedFilePaths, "\n")
Jiyong Park11a65972021-02-01 21:09:38 +0900532}
533
Jiyong Parkf46b1af2024-04-05 18:13:33 +0900534func validatePartitionType(ctx android.ModuleContext, p partition) {
535 if !android.InList(p.PartitionType(), validPartitions) {
536 ctx.PropertyErrorf("partition_type", "partition_type must be one of %s, found: %s", validPartitions, p.PartitionType())
537 }
538
539 ctx.VisitDirectDepsWithTag(android.DefaultsDepTag, func(m android.Module) {
540 if fdm, ok := m.(*filesystemDefaults); ok {
541 if p.PartitionType() != fdm.PartitionType() {
542 ctx.PropertyErrorf("partition_type",
543 "%s doesn't match with the partition type %s of the filesystem default module %s",
544 p.PartitionType(), fdm.PartitionType(), m.Name())
545 }
546 }
547 })
548}
549
Cole Faust3b806d32024-03-11 15:15:03 -0700550// Copy extra files/dirs that are not from the `deps` property to `rootDir`, checking for conflicts with files
551// already in `rootDir`.
552func (f *filesystem) buildNonDepsFiles(ctx android.ModuleContext, builder *android.RuleBuilder, rootDir android.OutputPath) {
Inseob Kim14199b02021-02-09 21:18:31 +0900553 // create dirs and symlinks
Cole Faustd9c6a5b2024-05-21 14:54:00 -0700554 for _, dir := range f.properties.Dirs.GetOrDefault(ctx, nil) {
Inseob Kim14199b02021-02-09 21:18:31 +0900555 // OutputPath.Join verifies dir
556 builder.Command().Text("mkdir -p").Text(rootDir.Join(ctx, dir).String())
557 }
558
559 for _, symlink := range f.properties.Symlinks {
560 name := strings.TrimSpace(proptools.String(symlink.Name))
561 target := strings.TrimSpace(proptools.String(symlink.Target))
562
563 if name == "" {
564 ctx.PropertyErrorf("symlinks", "Name can't be empty")
565 continue
566 }
567
568 if target == "" {
569 ctx.PropertyErrorf("symlinks", "Target can't be empty")
570 continue
571 }
572
573 // OutputPath.Join verifies name. don't need to verify target.
574 dst := rootDir.Join(ctx, name)
Cole Faust3b806d32024-03-11 15:15:03 -0700575 builder.Command().Textf("(! [ -e %s -o -L %s ] || (echo \"%s already exists from an earlier stage of the build\" && exit 1))", dst, dst, dst)
Inseob Kim14199b02021-02-09 21:18:31 +0900576 builder.Command().Text("mkdir -p").Text(filepath.Dir(dst.String()))
577 builder.Command().Text("ln -sf").Text(proptools.ShellEscape(target)).Text(dst.String())
Kiyoung Kim99a954d2024-06-21 14:22:20 +0900578 f.appendToEntry(ctx, dst)
Inseob Kim14199b02021-02-09 21:18:31 +0900579 }
Jihoon Kang89e8a692024-12-18 19:28:33 +0000580
581 // https://cs.android.com/android/platform/superproject/main/+/main:build/make/core/Makefile;l=2835;drc=b186569ef00ff2f2a1fab28aedc75ebc32bcd67b
582 if f.partitionName() == "recovery" {
583 builder.Command().Text("mkdir -p").Text(rootDir.Join(ctx, "root/linkerconfig").String())
584 builder.Command().Text("touch").Text(rootDir.Join(ctx, "root/linkerconfig/ld.config.txt").String())
585 }
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900586}
587
Inseob Kim33f95a92024-07-11 15:44:49 +0900588func (f *filesystem) copyPackagingSpecs(ctx android.ModuleContext, builder *android.RuleBuilder, specs map[string]android.PackagingSpec, rootDir, rebasedDir android.WritablePath) []string {
589 rootDirSpecs := make(map[string]android.PackagingSpec)
590 rebasedDirSpecs := make(map[string]android.PackagingSpec)
591
592 for rel, spec := range specs {
593 if spec.Partition() == "root" {
594 rootDirSpecs[rel] = spec
595 } else {
596 rebasedDirSpecs[rel] = spec
597 }
598 }
599
600 dirsToSpecs := make(map[android.WritablePath]map[string]android.PackagingSpec)
601 dirsToSpecs[rootDir] = rootDirSpecs
602 dirsToSpecs[rebasedDir] = rebasedDirSpecs
603
604 return f.CopySpecsToDirs(ctx, builder, dirsToSpecs)
605}
606
Justin Yun34baa2e2024-08-30 21:11:33 +0900607func (f *filesystem) copyFilesToProductOut(ctx android.ModuleContext, builder *android.RuleBuilder, rebasedDir android.OutputPath) {
Justin Yun2cc42502024-09-11 14:10:20 +0900608 if f.Name() != ctx.Config().SoongDefinedSystemImage() {
Justin Yun34baa2e2024-08-30 21:11:33 +0900609 return
610 }
611 installPath := android.PathForModuleInPartitionInstall(ctx, f.partitionName())
612 builder.Command().Textf("cp -prf %s/* %s", rebasedDir, installPath)
613}
614
Spandan Das420e16a2024-12-11 18:10:52 +0000615func (f *filesystem) rootDirString() string {
616 return f.partitionName()
617}
618
Jihoon Kang1a478e52024-12-19 01:15:33 +0000619func (f *filesystem) buildImageUsingBuildImage(ctx android.ModuleContext) (android.Path, android.OutputPath) {
Spandan Das420e16a2024-12-11 18:10:52 +0000620 rootDir := android.PathForModuleOut(ctx, f.rootDirString()).OutputPath
Cole Faust3b806d32024-03-11 15:15:03 -0700621 rebasedDir := rootDir
622 if f.properties.Base_dir != nil {
623 rebasedDir = rootDir.Join(ctx, *f.properties.Base_dir)
624 }
625 builder := android.NewRuleBuilder(pctx, ctx)
626 // Wipe the root dir to get rid of leftover files from prior builds
627 builder.Command().Textf("rm -rf %s && mkdir -p %s", rootDir, rootDir)
Inseob Kim53391842024-03-29 17:44:07 +0900628 specs := f.gatherFilteredPackagingSpecs(ctx)
Inseob Kim33f95a92024-07-11 15:44:49 +0900629 f.entries = f.copyPackagingSpecs(ctx, builder, specs, rootDir, rebasedDir)
Cole Faust3b806d32024-03-11 15:15:03 -0700630
631 f.buildNonDepsFiles(ctx, builder, rootDir)
Cole Faust4a2a7c92024-03-12 12:44:40 -0700632 f.addMakeBuiltFiles(ctx, builder, rootDir)
Inseob Kim53391842024-03-29 17:44:07 +0900633 f.buildFsverityMetadataFiles(ctx, builder, specs, rootDir, rebasedDir)
Inseob Kimb7b84572024-04-30 10:51:47 +0900634 f.buildEventLogtagsFile(ctx, builder, rebasedDir)
Justin Yun74f3f302024-05-07 14:32:14 +0900635 f.buildAconfigFlagsFiles(ctx, builder, specs, rebasedDir)
Kiyoung Kim67118212024-11-07 13:23:44 +0900636 f.filesystemBuilder.BuildLinkerConfigFile(ctx, builder, rebasedDir)
Justin Yun34baa2e2024-08-30 21:11:33 +0900637 f.copyFilesToProductOut(ctx, builder, rebasedDir)
Jiyong Park6f0f6882020-11-12 13:14:30 +0900638
Nikita Ioffe519015f2022-12-23 15:36:29 +0000639 // run host_init_verifier
640 // Ideally we should have a concept of pluggable linters that verify the generated image.
641 // While such concept is not implement this will do.
642 // TODO(b/263574231): substitute with pluggable linter.
643 builder.Command().
644 BuiltTool("host_init_verifier").
645 FlagWithArg("--out_system=", rootDir.String()+"/system")
646
Jiyong Park72678312021-01-18 17:29:49 +0900647 propFile, toolDeps := f.buildPropFile(ctx)
Cole Fauste1676122024-12-03 17:32:25 -0800648
649 // Most of the time, if build_image were to call a host tool, it accepts the path to the
650 // host tool in a field in the prop file. However, it doesn't have that option for fec, which
651 // it expects to just be on the PATH. Add fec to the PATH.
652 fec := ctx.Config().HostToolPath(ctx, "fec")
653 pathToolDirs := []string{filepath.Dir(fec.String())}
654
Cole Faust4e9f5922024-11-13 16:09:23 -0800655 output := android.PathForModuleOut(ctx, f.installFileName())
Cole Fauste1676122024-12-03 17:32:25 -0800656 builder.Command().
657 Textf("PATH=%s:$PATH", strings.Join(pathToolDirs, ":")).
658 BuiltTool("build_image").
Jiyong Park6f0f6882020-11-12 13:14:30 +0900659 Text(rootDir.String()). // input directory
660 Input(propFile).
Jiyong Park72678312021-01-18 17:29:49 +0900661 Implicits(toolDeps).
Cole Fauste1676122024-12-03 17:32:25 -0800662 Implicit(fec).
Spandan Dasba273222024-12-12 19:25:07 +0000663 FlagWithArg("--build_datetime_file ", ctx.Config().Getenv("BUILD_DATETIME_FILE")).
Jiyong Park11a65972021-02-01 21:09:38 +0900664 Output(output).
Jiyong Park6f0f6882020-11-12 13:14:30 +0900665 Text(rootDir.String()) // directory where to find fs_config_files|dirs
666
667 // rootDir is not deleted. Might be useful for quick inspection.
Colin Crossf1a035e2020-11-16 17:32:30 -0800668 builder.Build("build_filesystem_image", fmt.Sprintf("Creating filesystem %s", f.BaseModuleName()))
Jiyong Park65c49f52020-11-24 14:23:26 +0900669
Jihoon Kang1a478e52024-12-19 01:15:33 +0000670 return output, rootDir
Jiyong Park65c49f52020-11-24 14:23:26 +0900671}
672
Cole Faust4e9f5922024-11-13 16:09:23 -0800673func (f *filesystem) buildFileContexts(ctx android.ModuleContext) android.Path {
Inseob Kimcc8e5362021-02-03 14:05:24 +0900674 builder := android.NewRuleBuilder(pctx, ctx)
675 fcBin := android.PathForModuleOut(ctx, "file_contexts.bin")
676 builder.Command().BuiltTool("sefcontext_compile").
677 FlagWithOutput("-o ", fcBin).
678 Input(android.PathForModuleSrc(ctx, proptools.String(f.properties.File_contexts)))
679 builder.Build("build_filesystem_file_contexts", fmt.Sprintf("Creating filesystem file contexts for %s", f.BaseModuleName()))
Cole Faust4e9f5922024-11-13 16:09:23 -0800680 return fcBin
Inseob Kimcc8e5362021-02-03 14:05:24 +0900681}
682
Cole Faust4e9f5922024-11-13 16:09:23 -0800683func (f *filesystem) buildPropFile(ctx android.ModuleContext) (android.Path, android.Paths) {
Jiyong Park72678312021-01-18 17:29:49 +0900684 var deps android.Paths
Cole Faustcec230a2024-03-07 15:51:12 -0800685 var propFileString strings.Builder
Jiyong Park72678312021-01-18 17:29:49 +0900686 addStr := func(name string, value string) {
Cole Faustcec230a2024-03-07 15:51:12 -0800687 propFileString.WriteString(name)
688 propFileString.WriteRune('=')
689 propFileString.WriteString(value)
690 propFileString.WriteRune('\n')
Jiyong Park72678312021-01-18 17:29:49 +0900691 }
692 addPath := func(name string, path android.Path) {
Cole Faustcec230a2024-03-07 15:51:12 -0800693 addStr(name, path.String())
Jiyong Park72678312021-01-18 17:29:49 +0900694 deps = append(deps, path)
695 }
696
Jiyong Park11a65972021-02-01 21:09:38 +0900697 // Type string that build_image.py accepts.
698 fsTypeStr := func(t fsType) string {
699 switch t {
Spandan Das94668822024-10-09 20:51:33 +0000700 // TODO(372522486): add more types like f2fs, erofs, etc.
Jiyong Park11a65972021-02-01 21:09:38 +0900701 case ext4Type:
702 return "ext4"
Spandan Dasc35d6fb2024-10-10 17:51:14 +0000703 case erofsType:
704 return "erofs"
mrziwang1a6291f2024-11-07 14:29:25 -0800705 case f2fsType:
706 return "f2fs"
Jiyong Park11a65972021-02-01 21:09:38 +0900707 }
708 panic(fmt.Errorf("unsupported fs type %v", t))
709 }
710
711 addStr("fs_type", fsTypeStr(f.fsType(ctx)))
Inseob Kim376d72f2023-11-01 15:40:25 +0900712 addStr("mount_point", proptools.StringDefault(f.properties.Mount_point, "/"))
Jiyong Park72678312021-01-18 17:29:49 +0900713 addStr("use_dynamic_partition_size", "true")
714 addPath("ext_mkuserimg", ctx.Config().HostToolPath(ctx, "mkuserimg_mke2fs"))
715 // b/177813163 deps of the host tools have to be added. Remove this.
716 for _, t := range []string{"mke2fs", "e2fsdroid", "tune2fs"} {
717 deps = append(deps, ctx.Config().HostToolPath(ctx, t))
718 }
719
Jiyong Park71baa762021-01-18 21:11:03 +0900720 if proptools.Bool(f.properties.Use_avb) {
721 addStr("avb_hashtree_enable", "true")
722 addPath("avb_avbtool", ctx.Config().HostToolPath(ctx, "avbtool"))
723 algorithm := proptools.StringDefault(f.properties.Avb_algorithm, "SHA256_RSA4096")
724 addStr("avb_algorithm", algorithm)
Cole Fauste1676122024-12-03 17:32:25 -0800725 if f.properties.Avb_private_key != nil {
726 key := android.PathForModuleSrc(ctx, *f.properties.Avb_private_key)
727 addPath("avb_key_path", key)
728 }
Inseob Kim53391842024-03-29 17:44:07 +0900729 addStr("partition_name", f.partitionName())
Cole Fauste1676122024-12-03 17:32:25 -0800730 avb_add_hashtree_footer_args := ""
731 if !proptools.BoolDefault(f.properties.Use_fec, true) {
732 avb_add_hashtree_footer_args += " --do_not_generate_fec"
733 }
Shikha Panware6f30632022-12-21 12:54:45 +0000734 if hashAlgorithm := proptools.String(f.properties.Avb_hash_algorithm); hashAlgorithm != "" {
735 avb_add_hashtree_footer_args += " --hash_algorithm " + hashAlgorithm
736 }
Nikita Ioffe2c8cdc62024-03-27 22:19:30 +0000737 if f.properties.Rollback_index != nil {
738 rollbackIndex := proptools.Int(f.properties.Rollback_index)
739 if rollbackIndex < 0 {
740 ctx.PropertyErrorf("rollback_index", "Rollback index must be non-negative")
741 }
742 avb_add_hashtree_footer_args += " --rollback_index " + strconv.Itoa(rollbackIndex)
743 }
Cole Fauste1676122024-12-03 17:32:25 -0800744 avb_add_hashtree_footer_args += fmt.Sprintf(" --prop com.android.build.%s.os_version:%s", f.partitionName(), ctx.Config().PlatformVersionLastStable())
Cole Faustefeb5c42024-12-16 10:47:26 -0800745 // We're not going to add BuildFingerPrintFile as a dep. If it changed, it's likely because
746 // the build number changed, and we don't want to trigger rebuilds solely based on the build
747 // number.
Cole Fauste1676122024-12-03 17:32:25 -0800748 avb_add_hashtree_footer_args += fmt.Sprintf(" --prop com.android.build.%s.fingerprint:{CONTENTS_OF:%s}", f.partitionName(), ctx.Config().BuildFingerprintFile(ctx))
Spandan Dase5c393c2024-12-12 19:25:07 +0000749 if f.properties.Security_patch != nil && proptools.String(f.properties.Security_patch) != "" {
750 avb_add_hashtree_footer_args += fmt.Sprintf(" --prop com.android.build.%s.security_patch:%s", f.partitionName(), proptools.String(f.properties.Security_patch))
751 }
Shikha Panware6f30632022-12-21 12:54:45 +0000752 addStr("avb_add_hashtree_footer_args", avb_add_hashtree_footer_args)
Jiyong Park71baa762021-01-18 21:11:03 +0900753 }
754
Cole Faust0d467052024-12-04 17:19:19 -0800755 if f.properties.File_contexts != nil && f.properties.Precompiled_file_contexts != nil {
756 ctx.ModuleErrorf("file_contexts and precompiled_file_contexts cannot both be set")
757 } else if f.properties.File_contexts != nil {
Inseob Kimcc8e5362021-02-03 14:05:24 +0900758 addPath("selinux_fc", f.buildFileContexts(ctx))
Cole Faust0d467052024-12-04 17:19:19 -0800759 } else if f.properties.Precompiled_file_contexts != nil {
760 src := android.PathForModuleSrc(ctx, *f.properties.Precompiled_file_contexts)
761 if src != nil {
762 addPath("selinux_fc", src)
763 }
Inseob Kimcc8e5362021-02-03 14:05:24 +0900764 }
Jooyung Han65f402b2022-04-21 14:24:04 +0900765 if timestamp := proptools.String(f.properties.Fake_timestamp); timestamp != "" {
766 addStr("timestamp", timestamp)
767 }
768 if uuid := proptools.String(f.properties.Uuid); uuid != "" {
769 addStr("uuid", uuid)
770 addStr("hash_seed", uuid)
771 }
mrziwang1a6291f2024-11-07 14:29:25 -0800772
Cole Faust43a52c72024-11-26 12:46:08 -0800773 // TODO(b/381120092): This should only be added if none of the size-related properties are set,
774 // but currently soong built partitions don't have size properties. Make code:
775 // https://cs.android.com/android/platform/superproject/main/+/main:build/make/core/Makefile;l=2262;drc=39cd33701c9278db0e7e481a090605f428d5b12d
776 // Make uses system_disable_sparse but disable_sparse has the same effect, and we shouldn't need
777 // to qualify it because each partition gets its own property file built.
778 addStr("disable_sparse", "true")
779
mrziwang1a6291f2024-11-07 14:29:25 -0800780 fst := f.fsType(ctx)
781 switch fst {
782 case erofsType:
783 // Add erofs properties
Cole Faust3e730972024-12-03 13:12:08 -0800784 addStr("erofs_default_compressor", proptools.StringDefault(f.properties.Erofs.Compressor, "lz4hc,9"))
785 if f.properties.Erofs.Compress_hints != nil {
786 src := android.PathForModuleSrc(ctx, *f.properties.Erofs.Compress_hints)
787 addPath("erofs_default_compress_hints", src)
Spandan Dasc35d6fb2024-10-10 17:51:14 +0000788 }
789 if proptools.BoolDefault(f.properties.Erofs.Sparse, true) {
790 // https://source.corp.google.com/h/googleplex-android/platform/build/+/88b1c67239ca545b11580237242774b411f2fed9:core/Makefile;l=2292;bpv=1;bpt=0;drc=ea8f34bc1d6e63656b4ec32f2391e9d54b3ebb6b
791 addStr("erofs_sparse_flag", "-s")
792 }
mrziwang1a6291f2024-11-07 14:29:25 -0800793 case f2fsType:
794 if proptools.BoolDefault(f.properties.F2fs.Sparse, true) {
795 // https://source.corp.google.com/h/googleplex-android/platform/build/+/88b1c67239ca545b11580237242774b411f2fed9:core/Makefile;l=2294;drc=ea8f34bc1d6e63656b4ec32f2391e9d54b3ebb6b;bpv=1;bpt=0
796 addStr("f2fs_sparse_flag", "-S")
797 }
Spandan Dasc35d6fb2024-10-10 17:51:14 +0000798 }
mrziwang1a6291f2024-11-07 14:29:25 -0800799 f.checkFsTypePropertyError(ctx, fst, fsTypeStr(fst))
Spandan Dasc35d6fb2024-10-10 17:51:14 +0000800
Cole Fauste1676122024-12-03 17:32:25 -0800801 propFilePreProcessing := android.PathForModuleOut(ctx, "prop_pre_processing")
802 android.WriteFileRuleVerbatim(ctx, propFilePreProcessing, propFileString.String())
Cole Faust4e9f5922024-11-13 16:09:23 -0800803 propFile := android.PathForModuleOut(ctx, "prop")
Cole Fauste1676122024-12-03 17:32:25 -0800804 ctx.Build(pctx, android.BuildParams{
Cole Faustefeb5c42024-12-16 10:47:26 -0800805 Rule: textFileProcessorRule,
806 Input: propFilePreProcessing,
807 Output: propFile,
Cole Fauste1676122024-12-03 17:32:25 -0800808 })
Jiyong Park72678312021-01-18 17:29:49 +0900809 return propFile, deps
810}
811
mrziwang1a6291f2024-11-07 14:29:25 -0800812// This method checks if there is any property set for the fstype(s) other than
813// the current fstype.
814func (f *filesystem) checkFsTypePropertyError(ctx android.ModuleContext, t fsType, fs string) {
815 raiseError := func(otherFsType, currentFsType string) {
816 errMsg := fmt.Sprintf("%s is non-empty, but FS type is %s\n. Please delete %s properties if this partition should use %s\n", otherFsType, currentFsType, otherFsType, currentFsType)
817 ctx.PropertyErrorf(otherFsType, errMsg)
818 }
819
820 if t != erofsType {
821 if f.properties.Erofs.Compressor != nil || f.properties.Erofs.Compress_hints != nil || f.properties.Erofs.Sparse != nil {
822 raiseError("erofs", fs)
823 }
824 }
825 if t != f2fsType {
826 if f.properties.F2fs.Sparse != nil {
827 raiseError("f2fs", fs)
828 }
829 }
830}
831
Jihoon Kang1a478e52024-12-19 01:15:33 +0000832func includeFilesRootDir(ctx android.ModuleContext) (rootDirs android.Paths, hashFiles android.Paths) {
833 ctx.VisitDirectDepsWithTag(interPartitionInstallDependencyTag, func(m android.Module) {
834 if fsProvider, ok := android.OtherModuleProvider(ctx, m, FilesystemProvider); ok {
835 rootDirs = append(rootDirs, fsProvider.Rootdir)
836 hashFiles = append(hashFiles, fsProvider.DirectoryHashFile)
837 } else {
838 ctx.PropertyErrorf("include_files_of", "only filesystem modules can be listed in "+
839 "include_files_of but %s is not a filesystem module", m.Name())
840 }
841 })
842 return rootDirs, hashFiles
843}
844
845func (f *filesystem) buildCpioImage(ctx android.ModuleContext, compressed bool) (android.Path, android.OutputPath) {
Jiyong Park11a65972021-02-01 21:09:38 +0900846 if proptools.Bool(f.properties.Use_avb) {
847 ctx.PropertyErrorf("use_avb", "signing compresed cpio image using avbtool is not supported."+
848 "Consider adding this to bootimg module and signing the entire boot image.")
849 }
850
Inseob Kimcc8e5362021-02-03 14:05:24 +0900851 if proptools.String(f.properties.File_contexts) != "" {
852 ctx.PropertyErrorf("file_contexts", "file_contexts is not supported for compressed cpio image.")
853 }
854
Cole Faust4a2a7c92024-03-12 12:44:40 -0700855 if f.properties.Include_make_built_files != "" {
856 ctx.PropertyErrorf("include_make_built_files", "include_make_built_files is not supported for compressed cpio image.")
857 }
858
Spandan Das420e16a2024-12-11 18:10:52 +0000859 rootDir := android.PathForModuleOut(ctx, f.rootDirString()).OutputPath
Cole Faust3b806d32024-03-11 15:15:03 -0700860 rebasedDir := rootDir
861 if f.properties.Base_dir != nil {
862 rebasedDir = rootDir.Join(ctx, *f.properties.Base_dir)
863 }
864 builder := android.NewRuleBuilder(pctx, ctx)
865 // Wipe the root dir to get rid of leftover files from prior builds
866 builder.Command().Textf("rm -rf %s && mkdir -p %s", rootDir, rootDir)
Inseob Kim53391842024-03-29 17:44:07 +0900867 specs := f.gatherFilteredPackagingSpecs(ctx)
Inseob Kim33f95a92024-07-11 15:44:49 +0900868 f.entries = f.copyPackagingSpecs(ctx, builder, specs, rootDir, rebasedDir)
Cole Faust3b806d32024-03-11 15:15:03 -0700869
870 f.buildNonDepsFiles(ctx, builder, rootDir)
Inseob Kim53391842024-03-29 17:44:07 +0900871 f.buildFsverityMetadataFiles(ctx, builder, specs, rootDir, rebasedDir)
Inseob Kimb7b84572024-04-30 10:51:47 +0900872 f.buildEventLogtagsFile(ctx, builder, rebasedDir)
Justin Yun74f3f302024-05-07 14:32:14 +0900873 f.buildAconfigFlagsFiles(ctx, builder, specs, rebasedDir)
Kiyoung Kim67118212024-11-07 13:23:44 +0900874 f.filesystemBuilder.BuildLinkerConfigFile(ctx, builder, rebasedDir)
Justin Yun34baa2e2024-08-30 21:11:33 +0900875 f.copyFilesToProductOut(ctx, builder, rebasedDir)
Jiyong Park11a65972021-02-01 21:09:38 +0900876
Jihoon Kang1a478e52024-12-19 01:15:33 +0000877 rootDirs, hashFiles := includeFilesRootDir(ctx)
878
Cole Faust4e9f5922024-11-13 16:09:23 -0800879 output := android.PathForModuleOut(ctx, f.installFileName())
Jiyong Park837cdb22021-02-05 00:17:14 +0900880 cmd := builder.Command().
Jiyong Park11a65972021-02-01 21:09:38 +0900881 BuiltTool("mkbootfs").
Jiyong Park837cdb22021-02-05 00:17:14 +0900882 Text(rootDir.String()) // input directory
Jihoon Kang1a478e52024-12-19 01:15:33 +0000883
884 for i := range len(rootDirs) {
885 cmd.Text(rootDirs[i].String())
886 }
887 cmd.Implicits(hashFiles)
888
Jihoon Kang6c03c8e2024-11-18 21:30:22 +0000889 if nodeList := f.properties.Dev_nodes_description_file; nodeList != nil {
890 cmd.FlagWithInput("-n ", android.PathForModuleSrc(ctx, proptools.String(nodeList)))
891 }
Jiyong Park837cdb22021-02-05 00:17:14 +0900892 if compressed {
893 cmd.Text("|").
894 BuiltTool("lz4").
895 Flag("--favor-decSpeed"). // for faster boot
896 Flag("-12"). // maximum compression level
897 Flag("-l"). // legacy format for kernel
898 Text(">").Output(output)
899 } else {
900 cmd.Text(">").Output(output)
901 }
Jiyong Park11a65972021-02-01 21:09:38 +0900902
903 // rootDir is not deleted. Might be useful for quick inspection.
Jiyong Park837cdb22021-02-05 00:17:14 +0900904 builder.Build("build_cpio_image", fmt.Sprintf("Creating filesystem %s", f.BaseModuleName()))
Jiyong Park11a65972021-02-01 21:09:38 +0900905
Jihoon Kang1a478e52024-12-19 01:15:33 +0000906 return output, rootDir
Jiyong Park11a65972021-02-01 21:09:38 +0900907}
908
Cole Faust4a2a7c92024-03-12 12:44:40 -0700909var validPartitions = []string{
910 "system",
911 "userdata",
912 "cache",
913 "system_other",
914 "vendor",
915 "product",
916 "system_ext",
917 "odm",
918 "vendor_dlkm",
919 "odm_dlkm",
920 "system_dlkm",
Cole Faust76a6e952024-11-07 16:56:45 -0800921 "ramdisk",
Cole Faust24938e22024-11-18 14:01:58 -0800922 "vendor_ramdisk",
Jihoon Kang3216c982024-12-02 19:42:20 +0000923 "recovery",
Cole Faust4a2a7c92024-03-12 12:44:40 -0700924}
925
926func (f *filesystem) addMakeBuiltFiles(ctx android.ModuleContext, builder *android.RuleBuilder, rootDir android.Path) {
927 partition := f.properties.Include_make_built_files
928 if partition == "" {
929 return
930 }
931 if !slices.Contains(validPartitions, partition) {
932 ctx.PropertyErrorf("include_make_built_files", "Expected one of %#v, found %q", validPartitions, partition)
933 return
934 }
935 stampFile := fmt.Sprintf("target/product/%s/obj/PACKAGING/%s_intermediates/staging_dir.stamp", ctx.Config().DeviceName(), partition)
936 fileListFile := fmt.Sprintf("target/product/%s/obj/PACKAGING/%s_intermediates/file_list.txt", ctx.Config().DeviceName(), partition)
937 stagingDir := fmt.Sprintf("target/product/%s/%s", ctx.Config().DeviceName(), partition)
938
939 builder.Command().BuiltTool("merge_directories").
940 Implicit(android.PathForArbitraryOutput(ctx, stampFile)).
941 Text("--ignore-duplicates").
942 FlagWithInput("--file-list", android.PathForArbitraryOutput(ctx, fileListFile)).
943 Text(rootDir.String()).
944 Text(android.PathForArbitraryOutput(ctx, stagingDir).String())
945}
946
Inseob Kimb7b84572024-04-30 10:51:47 +0900947func (f *filesystem) buildEventLogtagsFile(ctx android.ModuleContext, builder *android.RuleBuilder, rebasedDir android.OutputPath) {
948 if !proptools.Bool(f.properties.Build_logtags) {
949 return
950 }
951
Inseob Kimb7b84572024-04-30 10:51:47 +0900952 etcPath := rebasedDir.Join(ctx, "etc")
953 eventLogtagsPath := etcPath.Join(ctx, "event-log-tags")
954 builder.Command().Text("mkdir").Flag("-p").Text(etcPath.String())
Cole Fauste4506af2024-12-11 14:14:50 -0800955 builder.Command().Text("cp").Input(android.MergedLogtagsPath(ctx)).Text(eventLogtagsPath.String())
Kiyoung Kim99a954d2024-06-21 14:22:20 +0900956
957 f.appendToEntry(ctx, eventLogtagsPath)
Inseob Kimb7b84572024-04-30 10:51:47 +0900958}
959
Kiyoung Kim67118212024-11-07 13:23:44 +0900960func (f *filesystem) BuildLinkerConfigFile(ctx android.ModuleContext, builder *android.RuleBuilder, rebasedDir android.OutputPath) {
Spandan Das2047a4c2024-11-11 21:24:58 +0000961 if !proptools.Bool(f.properties.Linker_config.Gen_linker_config) {
Spandan Das92631882024-10-28 22:49:38 +0000962 return
963 }
964
Spandan Das918191e2024-10-31 18:27:23 +0000965 provideModules, _ := f.getLibsForLinkerConfig(ctx)
Cole Faustfee27012024-12-13 14:10:31 -0800966 intermediateOutput := android.PathForModuleOut(ctx, "linker.config.pb")
967 linkerconfig.BuildLinkerConfig(ctx, android.PathsForModuleSrc(ctx, f.properties.Linker_config.Linker_config_srcs), provideModules, nil, intermediateOutput)
Spandan Das92631882024-10-28 22:49:38 +0000968 output := rebasedDir.Join(ctx, "etc", "linker.config.pb")
Cole Faustfee27012024-12-13 14:10:31 -0800969 builder.Command().Text("cp").Input(intermediateOutput).Output(output)
Spandan Das92631882024-10-28 22:49:38 +0000970
971 f.appendToEntry(ctx, output)
972}
973
Kiyoung Kim23be5bb2024-11-27 00:50:30 +0000974func (f *filesystem) ShouldUseVintfFragmentModuleOnly() bool {
975 return false
976}
977
Jiyong Parkf46b1af2024-04-05 18:13:33 +0900978type partition interface {
979 PartitionType() string
980}
981
Cole Faust9a24d902024-03-18 15:38:12 -0700982func (f *filesystem) PartitionType() string {
983 return proptools.StringDefault(f.properties.Partition_type, "system")
984}
985
Jiyong Parkf46b1af2024-04-05 18:13:33 +0900986var _ partition = (*filesystem)(nil)
987
Jiyong Park65c49f52020-11-24 14:23:26 +0900988var _ android.AndroidMkEntriesProvider = (*filesystem)(nil)
989
990// Implements android.AndroidMkEntriesProvider
991func (f *filesystem) AndroidMkEntries() []android.AndroidMkEntries {
992 return []android.AndroidMkEntries{android.AndroidMkEntries{
993 Class: "ETC",
994 OutputFile: android.OptionalPathForPath(f.output),
995 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
Colin Crossaa255532020-07-03 13:18:24 -0700996 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
Colin Crossc68db4b2021-11-11 18:59:15 -0800997 entries.SetString("LOCAL_MODULE_PATH", f.installDir.String())
Jiyong Park65c49f52020-11-24 14:23:26 +0900998 entries.SetString("LOCAL_INSTALLED_MODULE_STEM", f.installFileName())
Kiyoung Kim99a954d2024-06-21 14:22:20 +0900999 entries.SetString("LOCAL_FILESYSTEM_FILELIST", f.fileListFile.String())
Jiyong Park65c49f52020-11-24 14:23:26 +09001000 },
1001 },
1002 }}
Jiyong Park6f0f6882020-11-12 13:14:30 +09001003}
Jiyong Park12a719c2021-01-07 15:31:24 +09001004
1005// Filesystem is the public interface for the filesystem struct. Currently, it's only for the apex
1006// package to have access to the output file.
1007type Filesystem interface {
1008 android.Module
1009 OutputPath() android.Path
Jiyong Park972e06c2021-03-15 23:32:49 +09001010
1011 // Returns the output file that is signed by avbtool. If this module is not signed, returns
1012 // nil.
1013 SignedOutputPath() android.Path
Jiyong Park12a719c2021-01-07 15:31:24 +09001014}
1015
1016var _ Filesystem = (*filesystem)(nil)
1017
1018func (f *filesystem) OutputPath() android.Path {
1019 return f.output
1020}
Jiyong Park972e06c2021-03-15 23:32:49 +09001021
1022func (f *filesystem) SignedOutputPath() android.Path {
1023 if proptools.Bool(f.properties.Use_avb) {
1024 return f.OutputPath()
1025 }
1026 return nil
1027}
Jooyung Han0fbbc2b2022-03-25 12:35:46 +09001028
1029// Filter the result of GatherPackagingSpecs to discard items targeting outside "system" partition.
1030// Note that "apex" module installs its contents to "apex"(fake partition) as well
1031// for symbol lookup by imitating "activated" paths.
1032func (f *filesystem) gatherFilteredPackagingSpecs(ctx android.ModuleContext) map[string]android.PackagingSpec {
Inseob Kim3c0a0422024-11-05 17:21:37 +09001033 specs := f.PackagingBase.GatherPackagingSpecsWithFilterAndModifier(ctx, f.filesystemBuilder.FilterPackagingSpec, f.filesystemBuilder.ModifyPackagingSpec)
Jooyung Han0fbbc2b2022-03-25 12:35:46 +09001034 return specs
1035}
Jooyung Han65f402b2022-04-21 14:24:04 +09001036
1037func sha1sum(values []string) string {
1038 h := sha256.New()
1039 for _, value := range values {
1040 io.WriteString(h, value)
1041 }
1042 return fmt.Sprintf("%x", h.Sum(nil))
1043}
Jooyung Hane6067592023-03-16 13:11:17 +09001044
1045// Base cc.UseCoverage
1046
1047var _ cc.UseCoverage = (*filesystem)(nil)
1048
Colin Crosse1a85552024-06-14 12:17:37 -07001049func (*filesystem) IsNativeCoverageNeeded(ctx cc.IsNativeCoverageNeededContext) bool {
Jooyung Hane6067592023-03-16 13:11:17 +09001050 return ctx.Device() && ctx.DeviceConfig().NativeCoverageEnabled()
1051}
Jiyong Parkf46b1af2024-04-05 18:13:33 +09001052
1053// android_filesystem_defaults
1054
1055type filesystemDefaults struct {
1056 android.ModuleBase
1057 android.DefaultsModuleBase
1058
Inseob Kim3c0a0422024-11-05 17:21:37 +09001059 properties FilesystemProperties
Jiyong Parkf46b1af2024-04-05 18:13:33 +09001060}
1061
1062// android_filesystem_defaults is a default module for android_filesystem and android_system_image
1063func filesystemDefaultsFactory() android.Module {
1064 module := &filesystemDefaults{}
1065 module.AddProperties(&module.properties)
1066 module.AddProperties(&android.PackagingProperties{})
1067 android.InitDefaultsModule(module)
1068 return module
1069}
1070
1071func (f *filesystemDefaults) PartitionType() string {
1072 return proptools.StringDefault(f.properties.Partition_type, "system")
1073}
1074
1075var _ partition = (*filesystemDefaults)(nil)
1076
1077func (f *filesystemDefaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1078 validatePartitionType(ctx, f)
1079}
Spandan Das918191e2024-10-31 18:27:23 +00001080
1081// getLibsForLinkerConfig returns
1082// 1. A list of libraries installed in this filesystem
1083// 2. A list of dep libraries _not_ installed in this filesystem
1084//
1085// `linkerconfig.BuildLinkerConfig` will convert these two to a linker.config.pb for the filesystem
1086// (1) will be added to --provideLibs if they are C libraries with a stable interface (has stubs)
1087// (2) will be added to --requireLibs if they are C libraries with a stable interface (has stubs)
1088func (f *filesystem) getLibsForLinkerConfig(ctx android.ModuleContext) ([]android.Module, []android.Module) {
1089 // we need "Module"s for packaging items
1090 modulesInPackageByModule := make(map[android.Module]bool)
1091 modulesInPackageByName := make(map[string]bool)
1092
1093 deps := f.gatherFilteredPackagingSpecs(ctx)
1094 ctx.WalkDeps(func(child, parent android.Module) bool {
1095 for _, ps := range android.OtherModuleProviderOrDefault(
1096 ctx, child, android.InstallFilesProvider).PackagingSpecs {
Spandan Dasecf667f2024-12-05 00:58:56 +00001097 if _, ok := deps[ps.RelPathInPackage()]; ok && ps.Partition() == f.PartitionType() {
Spandan Das918191e2024-10-31 18:27:23 +00001098 modulesInPackageByModule[child] = true
1099 modulesInPackageByName[child.Name()] = true
1100 return true
1101 }
1102 }
1103 return true
1104 })
1105
1106 provideModules := make([]android.Module, 0, len(modulesInPackageByModule))
1107 for mod := range modulesInPackageByModule {
1108 provideModules = append(provideModules, mod)
1109 }
1110
1111 var requireModules []android.Module
1112 ctx.WalkDeps(func(child, parent android.Module) bool {
1113 _, parentInPackage := modulesInPackageByModule[parent]
1114 _, childInPackageName := modulesInPackageByName[child.Name()]
1115
1116 // When parent is in the package, and child (or its variant) is not, this can be from an interface.
1117 if parentInPackage && !childInPackageName {
1118 requireModules = append(requireModules, child)
1119 }
1120 return true
1121 })
1122
1123 return provideModules, requireModules
1124}
Cole Faust26bdac52024-11-19 13:37:53 -08001125
1126// Checks that the given file doesn't exceed the given size, and will also print a warning
1127// if it's nearing the maximum size. Equivalent to assert-max-image-size in make:
1128// https://cs.android.com/android/platform/superproject/main/+/main:build/make/core/definitions.mk;l=3455;drc=993c4de29a02a6accd60ceaaee153307e1a18d10
1129func assertMaxImageSize(builder *android.RuleBuilder, image android.Path, maxSize int64, addAvbLater bool) {
1130 if addAvbLater {
1131 // The value 69632 is derived from MAX_VBMETA_SIZE + MAX_FOOTER_SIZE in avbtool.
1132 // Logic copied from make:
1133 // https://cs.android.com/android/platform/superproject/main/+/main:build/make/core/Makefile;l=228;drc=a6a0007ef24e16c0b79f439beac4a118416717e6
1134 maxSize -= 69632
1135 }
1136 cmd := builder.Command()
1137 cmd.Textf(`file="%s"; maxsize="%d";`+
1138 `total=$(stat -c "%%s" "$file" | tr -d '\n');`+
1139 `if [ "$total" -gt "$maxsize" ]; then `+
1140 ` echo "error: $file too large ($total > $maxsize)";`+
1141 ` false;`+
1142 `elif [ "$total" -gt $((maxsize - 32768)) ]; then `+
1143 ` echo "WARNING: $file approaching size limit ($total now; limit $maxsize)";`+
1144 `fi`,
1145 image, maxSize)
1146 cmd.Implicit(image)
1147}
Spandan Das71be42d2024-11-20 18:34:16 +00001148
1149// addAutogeneratedRroDeps walks the transitive closure of vendor and product partitions.
1150// It visits apps installed in system and system_ext partitions, and adds the autogenerated
1151// RRO modules to its own deps.
1152func addAutogeneratedRroDeps(ctx android.BottomUpMutatorContext) {
1153 f, ok := ctx.Module().(*filesystem)
1154 if !ok {
1155 return
1156 }
1157 thisPartition := f.PartitionType()
1158 if thisPartition != "vendor" && thisPartition != "product" {
Cole Faust34592c02024-12-13 11:20:24 -08001159 if f.properties.Android_filesystem_deps.System != nil {
1160 ctx.PropertyErrorf("android_filesystem_deps.system", "only vendor or product partitions can use android_filesystem_deps")
1161 }
1162 if f.properties.Android_filesystem_deps.System_ext != nil {
1163 ctx.PropertyErrorf("android_filesystem_deps.system_ext", "only vendor or product partitions can use android_filesystem_deps")
1164 }
Spandan Das71be42d2024-11-20 18:34:16 +00001165 return
1166 }
1167 ctx.WalkDeps(func(child, parent android.Module) bool {
1168 depTag := ctx.OtherModuleDependencyTag(child)
1169 if parent.Name() == f.Name() && depTag != interPartitionDependencyTag {
1170 return false // This is a module listed in deps of vendor/product filesystem
1171 }
1172 if vendorOverlay := java.AutogeneratedRroModuleName(ctx, child.Name(), "vendor"); ctx.OtherModuleExists(vendorOverlay) && thisPartition == "vendor" {
1173 ctx.AddFarVariationDependencies(nil, dependencyTagWithVisibilityEnforcementBypass, vendorOverlay)
1174 }
1175 if productOverlay := java.AutogeneratedRroModuleName(ctx, child.Name(), "product"); ctx.OtherModuleExists(productOverlay) && thisPartition == "product" {
1176 ctx.AddFarVariationDependencies(nil, dependencyTagWithVisibilityEnforcementBypass, productOverlay)
1177 }
1178 return true
1179 })
1180}