blob: 665faaaeda16f21d35c47cfff3659c4129c42442 [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 (
18 "fmt"
Inseob Kim14199b02021-02-09 21:18:31 +090019 "path/filepath"
20 "strings"
Jiyong Park6f0f6882020-11-12 13:14:30 +090021
22 "android/soong/android"
Jiyong Park65b62242020-11-25 12:44:59 +090023
24 "github.com/google/blueprint"
Jiyong Park71baa762021-01-18 21:11:03 +090025 "github.com/google/blueprint/proptools"
Jiyong Park6f0f6882020-11-12 13:14:30 +090026)
27
28func init() {
Jooyung Han9706cbc2021-04-15 22:43:48 +090029 registerBuildComponents(android.InitRegistrationContext)
30}
31
32func registerBuildComponents(ctx android.RegistrationContext) {
33 ctx.RegisterModuleType("android_filesystem", filesystemFactory)
Jiyong Parkfa616132021-04-20 11:36:40 +090034 ctx.RegisterModuleType("android_system_image", systemImageFactory)
Jiyong Park6f0f6882020-11-12 13:14:30 +090035}
36
37type filesystem struct {
38 android.ModuleBase
39 android.PackagingBase
Jiyong Park65c49f52020-11-24 14:23:26 +090040
Jiyong Park71baa762021-01-18 21:11:03 +090041 properties filesystemProperties
42
Jiyong Parkfa616132021-04-20 11:36:40 +090043 // Function that builds extra files under the root directory and returns the files
44 buildExtraFiles func(ctx android.ModuleContext, root android.OutputPath) android.OutputPaths
45
Jooyung Han0fbbc2b2022-03-25 12:35:46 +090046 // Function that filters PackagingSpecs returned by PackagingBase.GatherPackagingSpecs()
47 filterPackagingSpecs func(specs map[string]android.PackagingSpec)
48
Jiyong Park65c49f52020-11-24 14:23:26 +090049 output android.OutputPath
50 installDir android.InstallPath
Jooyung Han0fbbc2b2022-03-25 12:35:46 +090051
52 // For testing. Keeps the result of CopyDepsToZip()
53 entries []string
Jiyong Park6f0f6882020-11-12 13:14:30 +090054}
55
Inseob Kim14199b02021-02-09 21:18:31 +090056type symlinkDefinition struct {
57 Target *string
58 Name *string
59}
60
Jiyong Park71baa762021-01-18 21:11:03 +090061type filesystemProperties struct {
62 // When set to true, sign the image with avbtool. Default is false.
63 Use_avb *bool
64
65 // Path to the private key that avbtool will use to sign this filesystem image.
66 // TODO(jiyong): allow apex_key to be specified here
67 Avb_private_key *string `android:"path"`
68
Shikha Panwar0493b452022-12-22 12:22:57 +000069 // Signing algorithm for avbtool. Default is SHA256_RSA4096.
Jiyong Park71baa762021-01-18 21:11:03 +090070 Avb_algorithm *string
Jiyong Park11a65972021-02-01 21:09:38 +090071
Shikha Panwar0493b452022-12-22 12:22:57 +000072 // Hash algorithm used for avbtool (for descriptors). This is passed as hash_algorithm to
73 // avbtool. Default used by avbtool is sha1.
Shikha Panwar00468442022-12-21 12:54:45 +000074 Avb_hash_algorithm *string
75
Jiyong Parkac4076d2021-03-15 23:21:30 +090076 // Name of the partition stored in vbmeta desc. Defaults to the name of this module.
77 Partition_name *string
78
Jiyong Park837cdb22021-02-05 00:17:14 +090079 // Type of the filesystem. Currently, ext4, cpio, and compressed_cpio are supported. Default
80 // is ext4.
Jiyong Park11a65972021-02-01 21:09:38 +090081 Type *string
Inseob Kimcc8e5362021-02-03 14:05:24 +090082
83 // file_contexts file to make image. Currently, only ext4 is supported.
84 File_contexts *string `android:"path"`
Inseob Kim2ce1b5d2021-02-15 17:01:04 +090085
86 // Base directory relative to root, to which deps are installed, e.g. "system". Default is "."
87 // (root).
88 Base_dir *string
Inseob Kim14199b02021-02-09 21:18:31 +090089
90 // Directories to be created under root. e.g. /dev, /proc, etc.
91 Dirs []string
92
93 // Symbolic links to be created under root with "ln -sf <target> <name>".
94 Symlinks []symlinkDefinition
Jiyong Park71baa762021-01-18 21:11:03 +090095}
96
Jiyong Park65c49f52020-11-24 14:23:26 +090097// android_filesystem packages a set of modules and their transitive dependencies into a filesystem
98// image. The filesystem images are expected to be mounted in the target device, which means the
99// modules in the filesystem image are built for the target device (i.e. Android, not Linux host).
100// The modules are placed in the filesystem image just like they are installed to the ordinary
101// partitions like system.img. For example, cc_library modules are placed under ./lib[64] directory.
Jiyong Park6f0f6882020-11-12 13:14:30 +0900102func filesystemFactory() android.Module {
103 module := &filesystem{}
Jiyong Parkfa616132021-04-20 11:36:40 +0900104 initFilesystemModule(module)
105 return module
106}
107
108func initFilesystemModule(module *filesystem) {
Jiyong Park71baa762021-01-18 21:11:03 +0900109 module.AddProperties(&module.properties)
Jiyong Park6f0f6882020-11-12 13:14:30 +0900110 android.InitPackageModule(module)
111 android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
Jiyong Park6f0f6882020-11-12 13:14:30 +0900112}
113
Jiyong Park12a719c2021-01-07 15:31:24 +0900114var dependencyTag = struct {
115 blueprint.BaseDependencyTag
Jooyung Han092ef812021-03-10 15:40:34 +0900116 android.PackagingItemAlwaysDepTag
Jiyong Park12a719c2021-01-07 15:31:24 +0900117}{}
Jiyong Park65b62242020-11-25 12:44:59 +0900118
Jiyong Park6f0f6882020-11-12 13:14:30 +0900119func (f *filesystem) DepsMutator(ctx android.BottomUpMutatorContext) {
Jiyong Park65b62242020-11-25 12:44:59 +0900120 f.AddDeps(ctx, dependencyTag)
Jiyong Park6f0f6882020-11-12 13:14:30 +0900121}
122
Jiyong Park11a65972021-02-01 21:09:38 +0900123type fsType int
124
125const (
126 ext4Type fsType = iota
127 compressedCpioType
Jiyong Park837cdb22021-02-05 00:17:14 +0900128 cpioType // uncompressed
Jiyong Park11a65972021-02-01 21:09:38 +0900129 unknown
130)
131
132func (f *filesystem) fsType(ctx android.ModuleContext) fsType {
133 typeStr := proptools.StringDefault(f.properties.Type, "ext4")
134 switch typeStr {
135 case "ext4":
136 return ext4Type
137 case "compressed_cpio":
138 return compressedCpioType
Jiyong Park837cdb22021-02-05 00:17:14 +0900139 case "cpio":
140 return cpioType
Jiyong Park11a65972021-02-01 21:09:38 +0900141 default:
142 ctx.PropertyErrorf("type", "%q not supported", typeStr)
143 return unknown
144 }
145}
146
Jiyong Park65c49f52020-11-24 14:23:26 +0900147func (f *filesystem) installFileName() string {
148 return f.BaseModuleName() + ".img"
149}
150
Jiyong Park6f0f6882020-11-12 13:14:30 +0900151var pctx = android.NewPackageContext("android/soong/filesystem")
152
153func (f *filesystem) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jiyong Park11a65972021-02-01 21:09:38 +0900154 switch f.fsType(ctx) {
155 case ext4Type:
156 f.output = f.buildImageUsingBuildImage(ctx)
157 case compressedCpioType:
Jiyong Park837cdb22021-02-05 00:17:14 +0900158 f.output = f.buildCpioImage(ctx, true)
159 case cpioType:
160 f.output = f.buildCpioImage(ctx, false)
Jiyong Park11a65972021-02-01 21:09:38 +0900161 default:
162 return
163 }
164
165 f.installDir = android.PathForModuleInstall(ctx, "etc")
166 ctx.InstallFile(f.installDir, f.installFileName(), f.output)
167}
168
Jiyong Parkfa616132021-04-20 11:36:40 +0900169// root zip will contain extra files/dirs that are not from the `deps` property.
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900170func (f *filesystem) buildRootZip(ctx android.ModuleContext) android.OutputPath {
171 rootDir := android.PathForModuleGen(ctx, "root").OutputPath
172 builder := android.NewRuleBuilder(pctx, ctx)
173 builder.Command().Text("rm -rf").Text(rootDir.String())
174 builder.Command().Text("mkdir -p").Text(rootDir.String())
175
Inseob Kim14199b02021-02-09 21:18:31 +0900176 // create dirs and symlinks
177 for _, dir := range f.properties.Dirs {
178 // OutputPath.Join verifies dir
179 builder.Command().Text("mkdir -p").Text(rootDir.Join(ctx, dir).String())
180 }
181
182 for _, symlink := range f.properties.Symlinks {
183 name := strings.TrimSpace(proptools.String(symlink.Name))
184 target := strings.TrimSpace(proptools.String(symlink.Target))
185
186 if name == "" {
187 ctx.PropertyErrorf("symlinks", "Name can't be empty")
188 continue
189 }
190
191 if target == "" {
192 ctx.PropertyErrorf("symlinks", "Target can't be empty")
193 continue
194 }
195
196 // OutputPath.Join verifies name. don't need to verify target.
197 dst := rootDir.Join(ctx, name)
198
199 builder.Command().Text("mkdir -p").Text(filepath.Dir(dst.String()))
200 builder.Command().Text("ln -sf").Text(proptools.ShellEscape(target)).Text(dst.String())
201 }
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900202
Jiyong Parkfa616132021-04-20 11:36:40 +0900203 // create extra files if there's any
204 rootForExtraFiles := android.PathForModuleGen(ctx, "root-extra").OutputPath
205 var extraFiles android.OutputPaths
206 if f.buildExtraFiles != nil {
207 extraFiles = f.buildExtraFiles(ctx, rootForExtraFiles)
208 for _, f := range extraFiles {
209 rel, _ := filepath.Rel(rootForExtraFiles.String(), f.String())
210 if strings.HasPrefix(rel, "..") {
211 panic(fmt.Errorf("%q is not under %q\n", f, rootForExtraFiles))
212 }
213 }
214 }
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900215
Jiyong Parkfa616132021-04-20 11:36:40 +0900216 // Zip them all
217 zipOut := android.PathForModuleGen(ctx, "root.zip").OutputPath
218 zipCommand := builder.Command().BuiltTool("soong_zip")
219 zipCommand.FlagWithOutput("-o ", zipOut).
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900220 FlagWithArg("-C ", rootDir.String()).
221 Flag("-L 0"). // no compression because this will be unzipped soon
222 FlagWithArg("-D ", rootDir.String()).
223 Flag("-d") // include empty directories
Jiyong Parkfa616132021-04-20 11:36:40 +0900224 if len(extraFiles) > 0 {
225 zipCommand.FlagWithArg("-C ", rootForExtraFiles.String())
226 for _, f := range extraFiles {
227 zipCommand.FlagWithInput("-f ", f)
228 }
229 }
230
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900231 builder.Command().Text("rm -rf").Text(rootDir.String())
232
233 builder.Build("zip_root", fmt.Sprintf("zipping root contents for %s", ctx.ModuleName()))
234 return zipOut
235}
236
Jiyong Park11a65972021-02-01 21:09:38 +0900237func (f *filesystem) buildImageUsingBuildImage(ctx android.ModuleContext) android.OutputPath {
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900238 depsZipFile := android.PathForModuleOut(ctx, "deps.zip").OutputPath
Jooyung Han0fbbc2b2022-03-25 12:35:46 +0900239 f.entries = f.CopyDepsToZip(ctx, f.gatherFilteredPackagingSpecs(ctx), depsZipFile)
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900240
241 builder := android.NewRuleBuilder(pctx, ctx)
242 depsBase := proptools.StringDefault(f.properties.Base_dir, ".")
243 rebasedDepsZip := android.PathForModuleOut(ctx, "rebased_deps.zip").OutputPath
244 builder.Command().
245 BuiltTool("zip2zip").
246 FlagWithInput("-i ", depsZipFile).
247 FlagWithOutput("-o ", rebasedDepsZip).
248 Text("**/*:" + proptools.ShellEscape(depsBase)) // zip2zip verifies depsBase
Jiyong Park6f0f6882020-11-12 13:14:30 +0900249
250 rootDir := android.PathForModuleOut(ctx, "root").OutputPath
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900251 rootZip := f.buildRootZip(ctx)
Jiyong Park6f0f6882020-11-12 13:14:30 +0900252 builder.Command().
Colin Crossf1a035e2020-11-16 17:32:30 -0800253 BuiltTool("zipsync").
Jiyong Park6f0f6882020-11-12 13:14:30 +0900254 FlagWithArg("-d ", rootDir.String()). // zipsync wipes this. No need to clear.
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900255 Input(rootZip).
256 Input(rebasedDepsZip)
Jiyong Park6f0f6882020-11-12 13:14:30 +0900257
Jiyong Park72678312021-01-18 17:29:49 +0900258 propFile, toolDeps := f.buildPropFile(ctx)
Jiyong Park11a65972021-02-01 21:09:38 +0900259 output := android.PathForModuleOut(ctx, f.installFileName()).OutputPath
Colin Crossf1a035e2020-11-16 17:32:30 -0800260 builder.Command().BuiltTool("build_image").
Jiyong Park6f0f6882020-11-12 13:14:30 +0900261 Text(rootDir.String()). // input directory
262 Input(propFile).
Jiyong Park72678312021-01-18 17:29:49 +0900263 Implicits(toolDeps).
Jiyong Park11a65972021-02-01 21:09:38 +0900264 Output(output).
Jiyong Park6f0f6882020-11-12 13:14:30 +0900265 Text(rootDir.String()) // directory where to find fs_config_files|dirs
266
267 // rootDir is not deleted. Might be useful for quick inspection.
Colin Crossf1a035e2020-11-16 17:32:30 -0800268 builder.Build("build_filesystem_image", fmt.Sprintf("Creating filesystem %s", f.BaseModuleName()))
Jiyong Park65c49f52020-11-24 14:23:26 +0900269
Jiyong Park11a65972021-02-01 21:09:38 +0900270 return output
Jiyong Park65c49f52020-11-24 14:23:26 +0900271}
272
Inseob Kimcc8e5362021-02-03 14:05:24 +0900273func (f *filesystem) buildFileContexts(ctx android.ModuleContext) android.OutputPath {
274 builder := android.NewRuleBuilder(pctx, ctx)
275 fcBin := android.PathForModuleOut(ctx, "file_contexts.bin")
276 builder.Command().BuiltTool("sefcontext_compile").
277 FlagWithOutput("-o ", fcBin).
278 Input(android.PathForModuleSrc(ctx, proptools.String(f.properties.File_contexts)))
279 builder.Build("build_filesystem_file_contexts", fmt.Sprintf("Creating filesystem file contexts for %s", f.BaseModuleName()))
280 return fcBin.OutputPath
281}
282
Jiyong Park72678312021-01-18 17:29:49 +0900283func (f *filesystem) buildPropFile(ctx android.ModuleContext) (propFile android.OutputPath, toolDeps android.Paths) {
284 type prop struct {
285 name string
286 value string
287 }
288
289 var props []prop
290 var deps android.Paths
291 addStr := func(name string, value string) {
292 props = append(props, prop{name, value})
293 }
294 addPath := func(name string, path android.Path) {
295 props = append(props, prop{name, path.String()})
296 deps = append(deps, path)
297 }
298
Jiyong Park11a65972021-02-01 21:09:38 +0900299 // Type string that build_image.py accepts.
300 fsTypeStr := func(t fsType) string {
301 switch t {
302 // TODO(jiyong): add more types like f2fs, erofs, etc.
303 case ext4Type:
304 return "ext4"
305 }
306 panic(fmt.Errorf("unsupported fs type %v", t))
307 }
308
309 addStr("fs_type", fsTypeStr(f.fsType(ctx)))
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900310 addStr("mount_point", "/")
Jiyong Park72678312021-01-18 17:29:49 +0900311 addStr("use_dynamic_partition_size", "true")
312 addPath("ext_mkuserimg", ctx.Config().HostToolPath(ctx, "mkuserimg_mke2fs"))
313 // b/177813163 deps of the host tools have to be added. Remove this.
314 for _, t := range []string{"mke2fs", "e2fsdroid", "tune2fs"} {
315 deps = append(deps, ctx.Config().HostToolPath(ctx, t))
316 }
317
Jiyong Park71baa762021-01-18 21:11:03 +0900318 if proptools.Bool(f.properties.Use_avb) {
319 addStr("avb_hashtree_enable", "true")
320 addPath("avb_avbtool", ctx.Config().HostToolPath(ctx, "avbtool"))
321 algorithm := proptools.StringDefault(f.properties.Avb_algorithm, "SHA256_RSA4096")
322 addStr("avb_algorithm", algorithm)
323 key := android.PathForModuleSrc(ctx, proptools.String(f.properties.Avb_private_key))
324 addPath("avb_key_path", key)
Shikha Panwar00468442022-12-21 12:54:45 +0000325 avb_add_hashtree_footer_args := "--do_not_generate_fec"
326 if hashAlgorithm := proptools.String(f.properties.Avb_hash_algorithm); hashAlgorithm != "" {
327 avb_add_hashtree_footer_args += " --hash_algorithm " + hashAlgorithm
328 }
329 addStr("avb_add_hashtree_footer_args", avb_add_hashtree_footer_args)
Jiyong Parkac4076d2021-03-15 23:21:30 +0900330 partitionName := proptools.StringDefault(f.properties.Partition_name, f.Name())
331 addStr("partition_name", partitionName)
Jiyong Park71baa762021-01-18 21:11:03 +0900332 }
333
Inseob Kimcc8e5362021-02-03 14:05:24 +0900334 if proptools.String(f.properties.File_contexts) != "" {
335 addPath("selinux_fc", f.buildFileContexts(ctx))
336 }
337
Jiyong Park72678312021-01-18 17:29:49 +0900338 propFile = android.PathForModuleOut(ctx, "prop").OutputPath
339 builder := android.NewRuleBuilder(pctx, ctx)
340 builder.Command().Text("rm").Flag("-rf").Output(propFile)
341 for _, p := range props {
342 builder.Command().
Jiyong Park3db465d2021-01-26 14:08:16 +0900343 Text("echo").
Jiyong Park72678312021-01-18 17:29:49 +0900344 Flag(`"` + p.name + "=" + p.value + `"`).
345 Text(">>").Output(propFile)
346 }
347 builder.Build("build_filesystem_prop", fmt.Sprintf("Creating filesystem props for %s", f.BaseModuleName()))
348 return propFile, deps
349}
350
Jiyong Park837cdb22021-02-05 00:17:14 +0900351func (f *filesystem) buildCpioImage(ctx android.ModuleContext, compressed bool) android.OutputPath {
Jiyong Park11a65972021-02-01 21:09:38 +0900352 if proptools.Bool(f.properties.Use_avb) {
353 ctx.PropertyErrorf("use_avb", "signing compresed cpio image using avbtool is not supported."+
354 "Consider adding this to bootimg module and signing the entire boot image.")
355 }
356
Inseob Kimcc8e5362021-02-03 14:05:24 +0900357 if proptools.String(f.properties.File_contexts) != "" {
358 ctx.PropertyErrorf("file_contexts", "file_contexts is not supported for compressed cpio image.")
359 }
360
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900361 depsZipFile := android.PathForModuleOut(ctx, "deps.zip").OutputPath
Jooyung Han0fbbc2b2022-03-25 12:35:46 +0900362 f.entries = f.CopyDepsToZip(ctx, f.gatherFilteredPackagingSpecs(ctx), depsZipFile)
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900363
364 builder := android.NewRuleBuilder(pctx, ctx)
365 depsBase := proptools.StringDefault(f.properties.Base_dir, ".")
366 rebasedDepsZip := android.PathForModuleOut(ctx, "rebased_deps.zip").OutputPath
367 builder.Command().
368 BuiltTool("zip2zip").
369 FlagWithInput("-i ", depsZipFile).
370 FlagWithOutput("-o ", rebasedDepsZip).
371 Text("**/*:" + proptools.ShellEscape(depsBase)) // zip2zip verifies depsBase
Jiyong Park11a65972021-02-01 21:09:38 +0900372
373 rootDir := android.PathForModuleOut(ctx, "root").OutputPath
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900374 rootZip := f.buildRootZip(ctx)
Jiyong Park11a65972021-02-01 21:09:38 +0900375 builder.Command().
376 BuiltTool("zipsync").
377 FlagWithArg("-d ", rootDir.String()). // zipsync wipes this. No need to clear.
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900378 Input(rootZip).
379 Input(rebasedDepsZip)
Jiyong Park11a65972021-02-01 21:09:38 +0900380
381 output := android.PathForModuleOut(ctx, f.installFileName()).OutputPath
Jiyong Park837cdb22021-02-05 00:17:14 +0900382 cmd := builder.Command().
Jiyong Park11a65972021-02-01 21:09:38 +0900383 BuiltTool("mkbootfs").
Jiyong Park837cdb22021-02-05 00:17:14 +0900384 Text(rootDir.String()) // input directory
385 if compressed {
386 cmd.Text("|").
387 BuiltTool("lz4").
388 Flag("--favor-decSpeed"). // for faster boot
389 Flag("-12"). // maximum compression level
390 Flag("-l"). // legacy format for kernel
391 Text(">").Output(output)
392 } else {
393 cmd.Text(">").Output(output)
394 }
Jiyong Park11a65972021-02-01 21:09:38 +0900395
396 // rootDir is not deleted. Might be useful for quick inspection.
Jiyong Park837cdb22021-02-05 00:17:14 +0900397 builder.Build("build_cpio_image", fmt.Sprintf("Creating filesystem %s", f.BaseModuleName()))
Jiyong Park11a65972021-02-01 21:09:38 +0900398
399 return output
400}
401
Jiyong Park65c49f52020-11-24 14:23:26 +0900402var _ android.AndroidMkEntriesProvider = (*filesystem)(nil)
403
404// Implements android.AndroidMkEntriesProvider
405func (f *filesystem) AndroidMkEntries() []android.AndroidMkEntries {
406 return []android.AndroidMkEntries{android.AndroidMkEntries{
407 Class: "ETC",
408 OutputFile: android.OptionalPathForPath(f.output),
409 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
Colin Crossaa255532020-07-03 13:18:24 -0700410 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
Colin Crossc68db4b2021-11-11 18:59:15 -0800411 entries.SetString("LOCAL_MODULE_PATH", f.installDir.String())
Jiyong Park65c49f52020-11-24 14:23:26 +0900412 entries.SetString("LOCAL_INSTALLED_MODULE_STEM", f.installFileName())
413 },
414 },
415 }}
Jiyong Park6f0f6882020-11-12 13:14:30 +0900416}
Jiyong Park12a719c2021-01-07 15:31:24 +0900417
Jiyong Park940dfd42021-02-04 15:37:34 +0900418var _ android.OutputFileProducer = (*filesystem)(nil)
419
420// Implements android.OutputFileProducer
421func (f *filesystem) OutputFiles(tag string) (android.Paths, error) {
422 if tag == "" {
423 return []android.Path{f.output}, nil
424 }
425 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
426}
427
Jiyong Park12a719c2021-01-07 15:31:24 +0900428// Filesystem is the public interface for the filesystem struct. Currently, it's only for the apex
429// package to have access to the output file.
430type Filesystem interface {
431 android.Module
432 OutputPath() android.Path
Jiyong Park972e06c2021-03-15 23:32:49 +0900433
434 // Returns the output file that is signed by avbtool. If this module is not signed, returns
435 // nil.
436 SignedOutputPath() android.Path
Jiyong Park12a719c2021-01-07 15:31:24 +0900437}
438
439var _ Filesystem = (*filesystem)(nil)
440
441func (f *filesystem) OutputPath() android.Path {
442 return f.output
443}
Jiyong Park972e06c2021-03-15 23:32:49 +0900444
445func (f *filesystem) SignedOutputPath() android.Path {
446 if proptools.Bool(f.properties.Use_avb) {
447 return f.OutputPath()
448 }
449 return nil
450}
Jooyung Han0fbbc2b2022-03-25 12:35:46 +0900451
452// Filter the result of GatherPackagingSpecs to discard items targeting outside "system" partition.
453// Note that "apex" module installs its contents to "apex"(fake partition) as well
454// for symbol lookup by imitating "activated" paths.
455func (f *filesystem) gatherFilteredPackagingSpecs(ctx android.ModuleContext) map[string]android.PackagingSpec {
456 specs := f.PackagingBase.GatherPackagingSpecs(ctx)
457 if f.filterPackagingSpecs != nil {
458 f.filterPackagingSpecs(specs)
459 }
460 return specs
461}