summaryrefslogtreecommitdiff
path: root/filesystem/filesystem.go
diff options
context:
space:
mode:
authorInseob Kim <inseob@google.com>2021-02-15 17:01:04 +0900
committerInseob Kim <inseob@google.com>2021-02-17 13:07:18 +0900
commit2ce1b5dc3ab59d27ab85825d941d2e4c6bbeb654 (patch)
tree626f7a66418839ed55d29a1ca7c9d59f1fb175fe /filesystem/filesystem.go
parent404adeefdc26c833d27e290592214c2a2d541938 (diff)
Add base_dir property to filesystem
Deps have been installed to "system/" because of hard-coded mount point "system". Now they are installed to base_dir, and mount point is set to root. Bug: 179652970 Test: see contents of microdroid.img Change-Id: Ie03b539a1688db7002bb178823b39017a83ce840
Diffstat (limited to 'filesystem/filesystem.go')
-rw-r--r--filesystem/filesystem.go66
1 files changed, 57 insertions, 9 deletions
diff --git a/filesystem/filesystem.go b/filesystem/filesystem.go
index 76581548e..69496c998 100644
--- a/filesystem/filesystem.go
+++ b/filesystem/filesystem.go
@@ -54,6 +54,10 @@ type filesystemProperties struct {
// file_contexts file to make image. Currently, only ext4 is supported.
File_contexts *string `android:"path"`
+
+ // Base directory relative to root, to which deps are installed, e.g. "system". Default is "."
+ // (root).
+ Base_dir *string
}
// android_filesystem packages a set of modules and their transitive dependencies into a filesystem
@@ -124,16 +128,50 @@ func (f *filesystem) GenerateAndroidBuildActions(ctx android.ModuleContext) {
ctx.InstallFile(f.installDir, f.installFileName(), f.output)
}
+// root zip will contain stuffs like dirs or symlinks.
+func (f *filesystem) buildRootZip(ctx android.ModuleContext) android.OutputPath {
+ rootDir := android.PathForModuleGen(ctx, "root").OutputPath
+ builder := android.NewRuleBuilder(pctx, ctx)
+ builder.Command().Text("rm -rf").Text(rootDir.String())
+ builder.Command().Text("mkdir -p").Text(rootDir.String())
+
+ // Currently root.zip is empty, and just a placeholder now. Dirs and symlinks will be added.
+
+ zipOut := android.PathForModuleGen(ctx, "root.zip").OutputPath
+
+ builder.Command().
+ BuiltTool("soong_zip").
+ FlagWithOutput("-o ", zipOut).
+ FlagWithArg("-C ", rootDir.String()).
+ Flag("-L 0"). // no compression because this will be unzipped soon
+ FlagWithArg("-D ", rootDir.String()).
+ Flag("-d") // include empty directories
+ builder.Command().Text("rm -rf").Text(rootDir.String())
+
+ builder.Build("zip_root", fmt.Sprintf("zipping root contents for %s", ctx.ModuleName()))
+ return zipOut
+}
+
func (f *filesystem) buildImageUsingBuildImage(ctx android.ModuleContext) android.OutputPath {
- zipFile := android.PathForModuleOut(ctx, "temp.zip").OutputPath
- f.CopyDepsToZip(ctx, zipFile)
+ depsZipFile := android.PathForModuleOut(ctx, "deps.zip").OutputPath
+ f.CopyDepsToZip(ctx, depsZipFile)
- rootDir := android.PathForModuleOut(ctx, "root").OutputPath
builder := android.NewRuleBuilder(pctx, ctx)
+ depsBase := proptools.StringDefault(f.properties.Base_dir, ".")
+ rebasedDepsZip := android.PathForModuleOut(ctx, "rebased_deps.zip").OutputPath
+ builder.Command().
+ BuiltTool("zip2zip").
+ FlagWithInput("-i ", depsZipFile).
+ FlagWithOutput("-o ", rebasedDepsZip).
+ Text("**/*:" + proptools.ShellEscape(depsBase)) // zip2zip verifies depsBase
+
+ rootDir := android.PathForModuleOut(ctx, "root").OutputPath
+ rootZip := f.buildRootZip(ctx)
builder.Command().
BuiltTool("zipsync").
FlagWithArg("-d ", rootDir.String()). // zipsync wipes this. No need to clear.
- Input(zipFile)
+ Input(rootZip).
+ Input(rebasedDepsZip)
propFile, toolDeps := f.buildPropFile(ctx)
output := android.PathForModuleOut(ctx, f.installFileName()).OutputPath
@@ -187,7 +225,7 @@ func (f *filesystem) buildPropFile(ctx android.ModuleContext) (propFile android.
}
addStr("fs_type", fsTypeStr(f.fsType(ctx)))
- addStr("mount_point", "system")
+ addStr("mount_point", "/")
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.
@@ -233,15 +271,25 @@ func (f *filesystem) buildCpioImage(ctx android.ModuleContext, compressed bool)
ctx.PropertyErrorf("file_contexts", "file_contexts is not supported for compressed cpio image.")
}
- zipFile := android.PathForModuleOut(ctx, "temp.zip").OutputPath
- f.CopyDepsToZip(ctx, zipFile)
+ depsZipFile := android.PathForModuleOut(ctx, "deps.zip").OutputPath
+ f.CopyDepsToZip(ctx, depsZipFile)
- rootDir := android.PathForModuleOut(ctx, "root").OutputPath
builder := android.NewRuleBuilder(pctx, ctx)
+ depsBase := proptools.StringDefault(f.properties.Base_dir, ".")
+ rebasedDepsZip := android.PathForModuleOut(ctx, "rebased_deps.zip").OutputPath
+ builder.Command().
+ BuiltTool("zip2zip").
+ FlagWithInput("-i ", depsZipFile).
+ FlagWithOutput("-o ", rebasedDepsZip).
+ Text("**/*:" + proptools.ShellEscape(depsBase)) // zip2zip verifies depsBase
+
+ rootDir := android.PathForModuleOut(ctx, "root").OutputPath
+ rootZip := f.buildRootZip(ctx)
builder.Command().
BuiltTool("zipsync").
FlagWithArg("-d ", rootDir.String()). // zipsync wipes this. No need to clear.
- Input(zipFile)
+ Input(rootZip).
+ Input(rebasedDepsZip)
output := android.PathForModuleOut(ctx, f.installFileName()).OutputPath
cmd := builder.Command().