diff options
author | Jiyong Park <jiyong@google.com> | 2021-01-18 17:29:49 +0900 |
---|---|---|
committer | Jiyong Park <jiyong@google.com> | 2021-01-20 08:35:52 +0900 |
commit | 72678310860dddf5d74e08d94a13d5f0aa745933 (patch) | |
tree | 08f95df6c690105d6240964460c8d9f2703b9f18 /filesystem | |
parent | b47dcf7f0d290f140e32460846aacb795a02b060 (diff) |
Refactor filesystem.go to make it easy to build prop file
The creation of the prop file is refactored to a function.
Bug: 172415113
Test: m
Change-Id: I969bf4a2476f7a4aa9571945d3645d7af52ff09a
Diffstat (limited to 'filesystem')
-rw-r--r-- | filesystem/filesystem.go | 52 |
1 files changed, 41 insertions, 11 deletions
diff --git a/filesystem/filesystem.go b/filesystem/filesystem.go index 2b3fbaeac..1f72dce3f 100644 --- a/filesystem/filesystem.go +++ b/filesystem/filesystem.go @@ -72,21 +72,12 @@ func (f *filesystem) GenerateAndroidBuildActions(ctx android.ModuleContext) { FlagWithArg("-d ", rootDir.String()). // zipsync wipes this. No need to clear. Input(zipFile) - mkuserimg := ctx.Config().HostToolPath(ctx, "mkuserimg_mke2fs") - propFile := android.PathForModuleOut(ctx, "prop").OutputPath - // TODO(jiyong): support more filesystem types other than ext4 - propsText := fmt.Sprintf(`mount_point=system\n`+ - `fs_type=ext4\n`+ - `use_dynamic_partition_size=true\n`+ - `ext_mkuserimg=%s\n`, mkuserimg.String()) - builder.Command().Text("echo").Flag("-e").Flag(`"` + propsText + `"`). - Text(">").Output(propFile). - Implicit(mkuserimg) - + propFile, toolDeps := f.buildPropFile(ctx) f.output = android.PathForModuleOut(ctx, f.installFileName()).OutputPath builder.Command().BuiltTool("build_image"). Text(rootDir.String()). // input directory Input(propFile). + Implicits(toolDeps). Output(f.output). Text(rootDir.String()) // directory where to find fs_config_files|dirs @@ -97,6 +88,45 @@ func (f *filesystem) GenerateAndroidBuildActions(ctx android.ModuleContext) { ctx.InstallFile(f.installDir, f.installFileName(), f.output) } +func (f *filesystem) buildPropFile(ctx android.ModuleContext) (propFile android.OutputPath, toolDeps android.Paths) { + type prop struct { + name string + value string + } + + var props []prop + var deps android.Paths + addStr := func(name string, value string) { + props = append(props, prop{name, value}) + } + addPath := func(name string, path android.Path) { + props = append(props, prop{name, path.String()}) + deps = append(deps, path) + } + + // TODO(jiyong): support more filesystem types other than ext4 + addStr("fs_type", "ext4") + addStr("mount_point", "system") + addStr("use_dynamic_partition_size", "true") + addPath("ext_mkuserimg", ctx.Config().HostToolPath(ctx, "mkuserimg_mke2fs")) + // b/177813163 deps of the host tools have to be added. Remove this. + for _, t := range []string{"mke2fs", "e2fsdroid", "tune2fs"} { + deps = append(deps, ctx.Config().HostToolPath(ctx, t)) + } + + propFile = android.PathForModuleOut(ctx, "prop").OutputPath + builder := android.NewRuleBuilder(pctx, ctx) + builder.Command().Text("rm").Flag("-rf").Output(propFile) + for _, p := range props { + builder.Command(). + Text("echo").Flag("-e"). + Flag(`"` + p.name + "=" + p.value + `"`). + Text(">>").Output(propFile) + } + builder.Build("build_filesystem_prop", fmt.Sprintf("Creating filesystem props for %s", f.BaseModuleName())) + return propFile, deps +} + var _ android.AndroidMkEntriesProvider = (*filesystem)(nil) // Implements android.AndroidMkEntriesProvider |