blob: 6e1e78a69ec20af15764a90f0788752e334202ee [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"
22 "strings"
Jiyong Park6f0f6882020-11-12 13:14:30 +090023
24 "android/soong/android"
Jiyong Park65b62242020-11-25 12:44:59 +090025
26 "github.com/google/blueprint"
Jiyong Park71baa762021-01-18 21:11:03 +090027 "github.com/google/blueprint/proptools"
Jiyong Park6f0f6882020-11-12 13:14:30 +090028)
29
30func init() {
Jooyung Han9706cbc2021-04-15 22:43:48 +090031 registerBuildComponents(android.InitRegistrationContext)
32}
33
34func registerBuildComponents(ctx android.RegistrationContext) {
35 ctx.RegisterModuleType("android_filesystem", filesystemFactory)
Jiyong Parkfa616132021-04-20 11:36:40 +090036 ctx.RegisterModuleType("android_system_image", systemImageFactory)
Jiyong Park6f0f6882020-11-12 13:14:30 +090037}
38
39type filesystem struct {
40 android.ModuleBase
41 android.PackagingBase
Jiyong Park65c49f52020-11-24 14:23:26 +090042
Jiyong Park71baa762021-01-18 21:11:03 +090043 properties filesystemProperties
44
Jiyong Parkfa616132021-04-20 11:36:40 +090045 // Function that builds extra files under the root directory and returns the files
46 buildExtraFiles func(ctx android.ModuleContext, root android.OutputPath) android.OutputPaths
47
Jooyung Han0fbbc2b2022-03-25 12:35:46 +090048 // Function that filters PackagingSpecs returned by PackagingBase.GatherPackagingSpecs()
49 filterPackagingSpecs func(specs map[string]android.PackagingSpec)
50
Jiyong Park65c49f52020-11-24 14:23:26 +090051 output android.OutputPath
52 installDir android.InstallPath
Jooyung Han0fbbc2b2022-03-25 12:35:46 +090053
54 // For testing. Keeps the result of CopyDepsToZip()
55 entries []string
Jiyong Park6f0f6882020-11-12 13:14:30 +090056}
57
Inseob Kim14199b02021-02-09 21:18:31 +090058type symlinkDefinition struct {
59 Target *string
60 Name *string
61}
62
Jiyong Park71baa762021-01-18 21:11:03 +090063type filesystemProperties struct {
64 // When set to true, sign the image with avbtool. Default is false.
65 Use_avb *bool
66
67 // Path to the private key that avbtool will use to sign this filesystem image.
68 // TODO(jiyong): allow apex_key to be specified here
69 Avb_private_key *string `android:"path"`
70
71 // Hash and signing algorithm for avbtool. Default is SHA256_RSA4096.
72 Avb_algorithm *string
Jiyong Park11a65972021-02-01 21:09:38 +090073
Jiyong Parkac4076d2021-03-15 23:21:30 +090074 // Name of the partition stored in vbmeta desc. Defaults to the name of this module.
75 Partition_name *string
76
Jiyong Park837cdb22021-02-05 00:17:14 +090077 // Type of the filesystem. Currently, ext4, cpio, and compressed_cpio are supported. Default
78 // is ext4.
Jiyong Park11a65972021-02-01 21:09:38 +090079 Type *string
Inseob Kimcc8e5362021-02-03 14:05:24 +090080
81 // file_contexts file to make image. Currently, only ext4 is supported.
82 File_contexts *string `android:"path"`
Inseob Kim2ce1b5d2021-02-15 17:01:04 +090083
84 // Base directory relative to root, to which deps are installed, e.g. "system". Default is "."
85 // (root).
86 Base_dir *string
Inseob Kim14199b02021-02-09 21:18:31 +090087
88 // Directories to be created under root. e.g. /dev, /proc, etc.
89 Dirs []string
90
91 // Symbolic links to be created under root with "ln -sf <target> <name>".
92 Symlinks []symlinkDefinition
Jooyung Han65f402b2022-04-21 14:24:04 +090093
94 // Seconds since unix epoch to override timestamps of file entries
95 Fake_timestamp *string
96
97 // When set, passed to mkuserimg_mke2fs --mke2fs_uuid & --mke2fs_hash_seed.
98 // Otherwise, they'll be set as random which might cause indeterministic build output.
99 Uuid *string
Jiyong Park71baa762021-01-18 21:11:03 +0900100}
101
Jiyong Park65c49f52020-11-24 14:23:26 +0900102// android_filesystem packages a set of modules and their transitive dependencies into a filesystem
103// image. The filesystem images are expected to be mounted in the target device, which means the
104// modules in the filesystem image are built for the target device (i.e. Android, not Linux host).
105// The modules are placed in the filesystem image just like they are installed to the ordinary
106// partitions like system.img. For example, cc_library modules are placed under ./lib[64] directory.
Jiyong Park6f0f6882020-11-12 13:14:30 +0900107func filesystemFactory() android.Module {
108 module := &filesystem{}
Jiyong Parkfa616132021-04-20 11:36:40 +0900109 initFilesystemModule(module)
110 return module
111}
112
113func initFilesystemModule(module *filesystem) {
Jiyong Park71baa762021-01-18 21:11:03 +0900114 module.AddProperties(&module.properties)
Jiyong Park6f0f6882020-11-12 13:14:30 +0900115 android.InitPackageModule(module)
116 android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
Jiyong Park6f0f6882020-11-12 13:14:30 +0900117}
118
Jiyong Park12a719c2021-01-07 15:31:24 +0900119var dependencyTag = struct {
120 blueprint.BaseDependencyTag
Jooyung Han092ef812021-03-10 15:40:34 +0900121 android.PackagingItemAlwaysDepTag
Jiyong Park12a719c2021-01-07 15:31:24 +0900122}{}
Jiyong Park65b62242020-11-25 12:44:59 +0900123
Jiyong Park6f0f6882020-11-12 13:14:30 +0900124func (f *filesystem) DepsMutator(ctx android.BottomUpMutatorContext) {
Jiyong Park65b62242020-11-25 12:44:59 +0900125 f.AddDeps(ctx, dependencyTag)
Jiyong Park6f0f6882020-11-12 13:14:30 +0900126}
127
Jiyong Park11a65972021-02-01 21:09:38 +0900128type fsType int
129
130const (
131 ext4Type fsType = iota
132 compressedCpioType
Jiyong Park837cdb22021-02-05 00:17:14 +0900133 cpioType // uncompressed
Jiyong Park11a65972021-02-01 21:09:38 +0900134 unknown
135)
136
137func (f *filesystem) fsType(ctx android.ModuleContext) fsType {
138 typeStr := proptools.StringDefault(f.properties.Type, "ext4")
139 switch typeStr {
140 case "ext4":
141 return ext4Type
142 case "compressed_cpio":
143 return compressedCpioType
Jiyong Park837cdb22021-02-05 00:17:14 +0900144 case "cpio":
145 return cpioType
Jiyong Park11a65972021-02-01 21:09:38 +0900146 default:
147 ctx.PropertyErrorf("type", "%q not supported", typeStr)
148 return unknown
149 }
150}
151
Jiyong Park65c49f52020-11-24 14:23:26 +0900152func (f *filesystem) installFileName() string {
153 return f.BaseModuleName() + ".img"
154}
155
Jiyong Park6f0f6882020-11-12 13:14:30 +0900156var pctx = android.NewPackageContext("android/soong/filesystem")
157
158func (f *filesystem) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jiyong Park11a65972021-02-01 21:09:38 +0900159 switch f.fsType(ctx) {
160 case ext4Type:
161 f.output = f.buildImageUsingBuildImage(ctx)
162 case compressedCpioType:
Jiyong Park837cdb22021-02-05 00:17:14 +0900163 f.output = f.buildCpioImage(ctx, true)
164 case cpioType:
165 f.output = f.buildCpioImage(ctx, false)
Jiyong Park11a65972021-02-01 21:09:38 +0900166 default:
167 return
168 }
169
170 f.installDir = android.PathForModuleInstall(ctx, "etc")
171 ctx.InstallFile(f.installDir, f.installFileName(), f.output)
172}
173
Jiyong Parkfa616132021-04-20 11:36:40 +0900174// root zip will contain extra files/dirs that are not from the `deps` property.
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900175func (f *filesystem) buildRootZip(ctx android.ModuleContext) android.OutputPath {
176 rootDir := android.PathForModuleGen(ctx, "root").OutputPath
177 builder := android.NewRuleBuilder(pctx, ctx)
178 builder.Command().Text("rm -rf").Text(rootDir.String())
179 builder.Command().Text("mkdir -p").Text(rootDir.String())
180
Inseob Kim14199b02021-02-09 21:18:31 +0900181 // create dirs and symlinks
182 for _, dir := range f.properties.Dirs {
183 // OutputPath.Join verifies dir
184 builder.Command().Text("mkdir -p").Text(rootDir.Join(ctx, dir).String())
185 }
186
187 for _, symlink := range f.properties.Symlinks {
188 name := strings.TrimSpace(proptools.String(symlink.Name))
189 target := strings.TrimSpace(proptools.String(symlink.Target))
190
191 if name == "" {
192 ctx.PropertyErrorf("symlinks", "Name can't be empty")
193 continue
194 }
195
196 if target == "" {
197 ctx.PropertyErrorf("symlinks", "Target can't be empty")
198 continue
199 }
200
201 // OutputPath.Join verifies name. don't need to verify target.
202 dst := rootDir.Join(ctx, name)
203
204 builder.Command().Text("mkdir -p").Text(filepath.Dir(dst.String()))
205 builder.Command().Text("ln -sf").Text(proptools.ShellEscape(target)).Text(dst.String())
206 }
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900207
Jiyong Parkfa616132021-04-20 11:36:40 +0900208 // create extra files if there's any
209 rootForExtraFiles := android.PathForModuleGen(ctx, "root-extra").OutputPath
210 var extraFiles android.OutputPaths
211 if f.buildExtraFiles != nil {
212 extraFiles = f.buildExtraFiles(ctx, rootForExtraFiles)
213 for _, f := range extraFiles {
214 rel, _ := filepath.Rel(rootForExtraFiles.String(), f.String())
215 if strings.HasPrefix(rel, "..") {
216 panic(fmt.Errorf("%q is not under %q\n", f, rootForExtraFiles))
217 }
218 }
219 }
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900220
Jiyong Parkfa616132021-04-20 11:36:40 +0900221 // Zip them all
222 zipOut := android.PathForModuleGen(ctx, "root.zip").OutputPath
223 zipCommand := builder.Command().BuiltTool("soong_zip")
224 zipCommand.FlagWithOutput("-o ", zipOut).
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900225 FlagWithArg("-C ", rootDir.String()).
226 Flag("-L 0"). // no compression because this will be unzipped soon
227 FlagWithArg("-D ", rootDir.String()).
228 Flag("-d") // include empty directories
Jiyong Parkfa616132021-04-20 11:36:40 +0900229 if len(extraFiles) > 0 {
230 zipCommand.FlagWithArg("-C ", rootForExtraFiles.String())
231 for _, f := range extraFiles {
232 zipCommand.FlagWithInput("-f ", f)
233 }
234 }
235
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900236 builder.Command().Text("rm -rf").Text(rootDir.String())
237
238 builder.Build("zip_root", fmt.Sprintf("zipping root contents for %s", ctx.ModuleName()))
239 return zipOut
240}
241
Jiyong Park11a65972021-02-01 21:09:38 +0900242func (f *filesystem) buildImageUsingBuildImage(ctx android.ModuleContext) android.OutputPath {
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900243 depsZipFile := android.PathForModuleOut(ctx, "deps.zip").OutputPath
Jooyung Han0fbbc2b2022-03-25 12:35:46 +0900244 f.entries = f.CopyDepsToZip(ctx, f.gatherFilteredPackagingSpecs(ctx), depsZipFile)
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900245
246 builder := android.NewRuleBuilder(pctx, ctx)
247 depsBase := proptools.StringDefault(f.properties.Base_dir, ".")
248 rebasedDepsZip := android.PathForModuleOut(ctx, "rebased_deps.zip").OutputPath
249 builder.Command().
250 BuiltTool("zip2zip").
251 FlagWithInput("-i ", depsZipFile).
252 FlagWithOutput("-o ", rebasedDepsZip).
253 Text("**/*:" + proptools.ShellEscape(depsBase)) // zip2zip verifies depsBase
Jiyong Park6f0f6882020-11-12 13:14:30 +0900254
255 rootDir := android.PathForModuleOut(ctx, "root").OutputPath
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900256 rootZip := f.buildRootZip(ctx)
Jiyong Park6f0f6882020-11-12 13:14:30 +0900257 builder.Command().
Colin Crossf1a035e2020-11-16 17:32:30 -0800258 BuiltTool("zipsync").
Jiyong Park6f0f6882020-11-12 13:14:30 +0900259 FlagWithArg("-d ", rootDir.String()). // zipsync wipes this. No need to clear.
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900260 Input(rootZip).
261 Input(rebasedDepsZip)
Jiyong Park6f0f6882020-11-12 13:14:30 +0900262
Jiyong Park72678312021-01-18 17:29:49 +0900263 propFile, toolDeps := f.buildPropFile(ctx)
Jiyong Park11a65972021-02-01 21:09:38 +0900264 output := android.PathForModuleOut(ctx, f.installFileName()).OutputPath
Colin Crossf1a035e2020-11-16 17:32:30 -0800265 builder.Command().BuiltTool("build_image").
Jiyong Park6f0f6882020-11-12 13:14:30 +0900266 Text(rootDir.String()). // input directory
267 Input(propFile).
Jiyong Park72678312021-01-18 17:29:49 +0900268 Implicits(toolDeps).
Jiyong Park11a65972021-02-01 21:09:38 +0900269 Output(output).
Jiyong Park6f0f6882020-11-12 13:14:30 +0900270 Text(rootDir.String()) // directory where to find fs_config_files|dirs
271
272 // rootDir is not deleted. Might be useful for quick inspection.
Colin Crossf1a035e2020-11-16 17:32:30 -0800273 builder.Build("build_filesystem_image", fmt.Sprintf("Creating filesystem %s", f.BaseModuleName()))
Jiyong Park65c49f52020-11-24 14:23:26 +0900274
Jiyong Park11a65972021-02-01 21:09:38 +0900275 return output
Jiyong Park65c49f52020-11-24 14:23:26 +0900276}
277
Inseob Kimcc8e5362021-02-03 14:05:24 +0900278func (f *filesystem) buildFileContexts(ctx android.ModuleContext) android.OutputPath {
279 builder := android.NewRuleBuilder(pctx, ctx)
280 fcBin := android.PathForModuleOut(ctx, "file_contexts.bin")
281 builder.Command().BuiltTool("sefcontext_compile").
282 FlagWithOutput("-o ", fcBin).
283 Input(android.PathForModuleSrc(ctx, proptools.String(f.properties.File_contexts)))
284 builder.Build("build_filesystem_file_contexts", fmt.Sprintf("Creating filesystem file contexts for %s", f.BaseModuleName()))
285 return fcBin.OutputPath
286}
287
Jooyung Han65f402b2022-04-21 14:24:04 +0900288// Calculates avb_salt from entry list (sorted) for deterministic output.
289func (f *filesystem) salt() string {
290 return sha1sum(f.entries)
291}
292
Jiyong Park72678312021-01-18 17:29:49 +0900293func (f *filesystem) buildPropFile(ctx android.ModuleContext) (propFile android.OutputPath, toolDeps android.Paths) {
294 type prop struct {
295 name string
296 value string
297 }
298
299 var props []prop
300 var deps android.Paths
301 addStr := func(name string, value string) {
302 props = append(props, prop{name, value})
303 }
304 addPath := func(name string, path android.Path) {
305 props = append(props, prop{name, path.String()})
306 deps = append(deps, path)
307 }
308
Jiyong Park11a65972021-02-01 21:09:38 +0900309 // Type string that build_image.py accepts.
310 fsTypeStr := func(t fsType) string {
311 switch t {
312 // TODO(jiyong): add more types like f2fs, erofs, etc.
313 case ext4Type:
314 return "ext4"
315 }
316 panic(fmt.Errorf("unsupported fs type %v", t))
317 }
318
319 addStr("fs_type", fsTypeStr(f.fsType(ctx)))
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900320 addStr("mount_point", "/")
Jiyong Park72678312021-01-18 17:29:49 +0900321 addStr("use_dynamic_partition_size", "true")
322 addPath("ext_mkuserimg", ctx.Config().HostToolPath(ctx, "mkuserimg_mke2fs"))
323 // b/177813163 deps of the host tools have to be added. Remove this.
324 for _, t := range []string{"mke2fs", "e2fsdroid", "tune2fs"} {
325 deps = append(deps, ctx.Config().HostToolPath(ctx, t))
326 }
327
Jiyong Park71baa762021-01-18 21:11:03 +0900328 if proptools.Bool(f.properties.Use_avb) {
329 addStr("avb_hashtree_enable", "true")
330 addPath("avb_avbtool", ctx.Config().HostToolPath(ctx, "avbtool"))
331 algorithm := proptools.StringDefault(f.properties.Avb_algorithm, "SHA256_RSA4096")
332 addStr("avb_algorithm", algorithm)
333 key := android.PathForModuleSrc(ctx, proptools.String(f.properties.Avb_private_key))
334 addPath("avb_key_path", key)
335 addStr("avb_add_hashtree_footer_args", "--do_not_generate_fec")
Jiyong Parkac4076d2021-03-15 23:21:30 +0900336 partitionName := proptools.StringDefault(f.properties.Partition_name, f.Name())
337 addStr("partition_name", partitionName)
Jooyung Han65f402b2022-04-21 14:24:04 +0900338 addStr("avb_salt", f.salt())
Jiyong Park71baa762021-01-18 21:11:03 +0900339 }
340
Inseob Kimcc8e5362021-02-03 14:05:24 +0900341 if proptools.String(f.properties.File_contexts) != "" {
342 addPath("selinux_fc", f.buildFileContexts(ctx))
343 }
Jooyung Han65f402b2022-04-21 14:24:04 +0900344 if timestamp := proptools.String(f.properties.Fake_timestamp); timestamp != "" {
345 addStr("timestamp", timestamp)
346 }
347 if uuid := proptools.String(f.properties.Uuid); uuid != "" {
348 addStr("uuid", uuid)
349 addStr("hash_seed", uuid)
350 }
Jiyong Park72678312021-01-18 17:29:49 +0900351 propFile = android.PathForModuleOut(ctx, "prop").OutputPath
352 builder := android.NewRuleBuilder(pctx, ctx)
353 builder.Command().Text("rm").Flag("-rf").Output(propFile)
354 for _, p := range props {
355 builder.Command().
Jiyong Park3db465d2021-01-26 14:08:16 +0900356 Text("echo").
Jiyong Park72678312021-01-18 17:29:49 +0900357 Flag(`"` + p.name + "=" + p.value + `"`).
358 Text(">>").Output(propFile)
359 }
360 builder.Build("build_filesystem_prop", fmt.Sprintf("Creating filesystem props for %s", f.BaseModuleName()))
361 return propFile, deps
362}
363
Jiyong Park837cdb22021-02-05 00:17:14 +0900364func (f *filesystem) buildCpioImage(ctx android.ModuleContext, compressed bool) android.OutputPath {
Jiyong Park11a65972021-02-01 21:09:38 +0900365 if proptools.Bool(f.properties.Use_avb) {
366 ctx.PropertyErrorf("use_avb", "signing compresed cpio image using avbtool is not supported."+
367 "Consider adding this to bootimg module and signing the entire boot image.")
368 }
369
Inseob Kimcc8e5362021-02-03 14:05:24 +0900370 if proptools.String(f.properties.File_contexts) != "" {
371 ctx.PropertyErrorf("file_contexts", "file_contexts is not supported for compressed cpio image.")
372 }
373
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900374 depsZipFile := android.PathForModuleOut(ctx, "deps.zip").OutputPath
Jooyung Han0fbbc2b2022-03-25 12:35:46 +0900375 f.entries = f.CopyDepsToZip(ctx, f.gatherFilteredPackagingSpecs(ctx), depsZipFile)
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900376
377 builder := android.NewRuleBuilder(pctx, ctx)
378 depsBase := proptools.StringDefault(f.properties.Base_dir, ".")
379 rebasedDepsZip := android.PathForModuleOut(ctx, "rebased_deps.zip").OutputPath
380 builder.Command().
381 BuiltTool("zip2zip").
382 FlagWithInput("-i ", depsZipFile).
383 FlagWithOutput("-o ", rebasedDepsZip).
384 Text("**/*:" + proptools.ShellEscape(depsBase)) // zip2zip verifies depsBase
Jiyong Park11a65972021-02-01 21:09:38 +0900385
386 rootDir := android.PathForModuleOut(ctx, "root").OutputPath
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900387 rootZip := f.buildRootZip(ctx)
Jiyong Park11a65972021-02-01 21:09:38 +0900388 builder.Command().
389 BuiltTool("zipsync").
390 FlagWithArg("-d ", rootDir.String()). // zipsync wipes this. No need to clear.
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900391 Input(rootZip).
392 Input(rebasedDepsZip)
Jiyong Park11a65972021-02-01 21:09:38 +0900393
394 output := android.PathForModuleOut(ctx, f.installFileName()).OutputPath
Jiyong Park837cdb22021-02-05 00:17:14 +0900395 cmd := builder.Command().
Jiyong Park11a65972021-02-01 21:09:38 +0900396 BuiltTool("mkbootfs").
Jiyong Park837cdb22021-02-05 00:17:14 +0900397 Text(rootDir.String()) // input directory
398 if compressed {
399 cmd.Text("|").
400 BuiltTool("lz4").
401 Flag("--favor-decSpeed"). // for faster boot
402 Flag("-12"). // maximum compression level
403 Flag("-l"). // legacy format for kernel
404 Text(">").Output(output)
405 } else {
406 cmd.Text(">").Output(output)
407 }
Jiyong Park11a65972021-02-01 21:09:38 +0900408
409 // rootDir is not deleted. Might be useful for quick inspection.
Jiyong Park837cdb22021-02-05 00:17:14 +0900410 builder.Build("build_cpio_image", fmt.Sprintf("Creating filesystem %s", f.BaseModuleName()))
Jiyong Park11a65972021-02-01 21:09:38 +0900411
412 return output
413}
414
Jiyong Park65c49f52020-11-24 14:23:26 +0900415var _ android.AndroidMkEntriesProvider = (*filesystem)(nil)
416
417// Implements android.AndroidMkEntriesProvider
418func (f *filesystem) AndroidMkEntries() []android.AndroidMkEntries {
419 return []android.AndroidMkEntries{android.AndroidMkEntries{
420 Class: "ETC",
421 OutputFile: android.OptionalPathForPath(f.output),
422 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
Colin Crossaa255532020-07-03 13:18:24 -0700423 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
Colin Crossc68db4b2021-11-11 18:59:15 -0800424 entries.SetString("LOCAL_MODULE_PATH", f.installDir.String())
Jiyong Park65c49f52020-11-24 14:23:26 +0900425 entries.SetString("LOCAL_INSTALLED_MODULE_STEM", f.installFileName())
426 },
427 },
428 }}
Jiyong Park6f0f6882020-11-12 13:14:30 +0900429}
Jiyong Park12a719c2021-01-07 15:31:24 +0900430
Jiyong Park940dfd42021-02-04 15:37:34 +0900431var _ android.OutputFileProducer = (*filesystem)(nil)
432
433// Implements android.OutputFileProducer
434func (f *filesystem) OutputFiles(tag string) (android.Paths, error) {
435 if tag == "" {
436 return []android.Path{f.output}, nil
437 }
438 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
439}
440
Jiyong Park12a719c2021-01-07 15:31:24 +0900441// Filesystem is the public interface for the filesystem struct. Currently, it's only for the apex
442// package to have access to the output file.
443type Filesystem interface {
444 android.Module
445 OutputPath() android.Path
Jiyong Park972e06c2021-03-15 23:32:49 +0900446
447 // Returns the output file that is signed by avbtool. If this module is not signed, returns
448 // nil.
449 SignedOutputPath() android.Path
Jiyong Park12a719c2021-01-07 15:31:24 +0900450}
451
452var _ Filesystem = (*filesystem)(nil)
453
454func (f *filesystem) OutputPath() android.Path {
455 return f.output
456}
Jiyong Park972e06c2021-03-15 23:32:49 +0900457
458func (f *filesystem) SignedOutputPath() android.Path {
459 if proptools.Bool(f.properties.Use_avb) {
460 return f.OutputPath()
461 }
462 return nil
463}
Jooyung Han0fbbc2b2022-03-25 12:35:46 +0900464
465// Filter the result of GatherPackagingSpecs to discard items targeting outside "system" partition.
466// Note that "apex" module installs its contents to "apex"(fake partition) as well
467// for symbol lookup by imitating "activated" paths.
468func (f *filesystem) gatherFilteredPackagingSpecs(ctx android.ModuleContext) map[string]android.PackagingSpec {
469 specs := f.PackagingBase.GatherPackagingSpecs(ctx)
470 if f.filterPackagingSpecs != nil {
471 f.filterPackagingSpecs(specs)
472 }
473 return specs
474}
Jooyung Han65f402b2022-04-21 14:24:04 +0900475
476func sha1sum(values []string) string {
477 h := sha256.New()
478 for _, value := range values {
479 io.WriteString(h, value)
480 }
481 return fmt.Sprintf("%x", h.Sum(nil))
482}