Don't use zip files when creating filesystems

The end result is a directory that's passed to build_image, so zipping
and then unzipping image contents will unnecessarily slow things down.

Bug: 329146343
Test: m microdroid --no-skip-soong-tests
Change-Id: I98223c60e8144d6c707832fcc03ba8fe94467e7b
This commit is contained in:
Cole Faust
2024-03-11 15:15:03 -07:00
parent ed9005b556
commit 3b806d3b88
3 changed files with 36 additions and 70 deletions

View File

@@ -11022,7 +11022,7 @@ func TestFileSystemShouldSkipApexLibraries(t *testing.T) {
} }
`) `)
inputs := result.ModuleForTests("myfilesystem", "android_common").Output("deps.zip").Implicits inputs := result.ModuleForTests("myfilesystem", "android_common").Output("myfilesystem.img").Implicits
android.AssertStringListDoesNotContain(t, "filesystem should not have libbar", android.AssertStringListDoesNotContain(t, "filesystem should not have libbar",
inputs.Strings(), inputs.Strings(),
"out/soong/.intermediates/libbar/android_arm64_armv8-a_shared/libbar.so") "out/soong/.intermediates/libbar/android_arm64_armv8-a_shared/libbar.so")

View File

@@ -183,13 +183,9 @@ func (f *filesystem) GenerateAndroidBuildActions(ctx android.ModuleContext) {
ctx.InstallFile(f.installDir, f.installFileName(), f.output) ctx.InstallFile(f.installDir, f.installFileName(), f.output)
} }
// root zip will contain extra files/dirs that are not from the `deps` property. // Copy extra files/dirs that are not from the `deps` property to `rootDir`, checking for conflicts with files
func (f *filesystem) buildRootZip(ctx android.ModuleContext) android.OutputPath { // already in `rootDir`.
rootDir := android.PathForModuleGen(ctx, "root").OutputPath func (f *filesystem) buildNonDepsFiles(ctx android.ModuleContext, builder *android.RuleBuilder, rootDir android.OutputPath) {
builder := android.NewRuleBuilder(pctx, ctx)
builder.Command().Text("rm -rf").Text(rootDir.String())
builder.Command().Text("mkdir -p").Text(rootDir.String())
// create dirs and symlinks // create dirs and symlinks
for _, dir := range f.properties.Dirs { for _, dir := range f.properties.Dirs {
// OutputPath.Join verifies dir // OutputPath.Join verifies dir
@@ -212,7 +208,7 @@ func (f *filesystem) buildRootZip(ctx android.ModuleContext) android.OutputPath
// OutputPath.Join verifies name. don't need to verify target. // OutputPath.Join verifies name. don't need to verify target.
dst := rootDir.Join(ctx, name) dst := rootDir.Join(ctx, name)
builder.Command().Textf("(! [ -e %s -o -L %s ] || (echo \"%s already exists from an earlier stage of the build\" && exit 1))", dst, dst, dst)
builder.Command().Text("mkdir -p").Text(filepath.Dir(dst.String())) builder.Command().Text("mkdir -p").Text(filepath.Dir(dst.String()))
builder.Command().Text("ln -sf").Text(proptools.ShellEscape(target)).Text(dst.String()) builder.Command().Text("ln -sf").Text(proptools.ShellEscape(target)).Text(dst.String())
} }
@@ -222,55 +218,33 @@ func (f *filesystem) buildRootZip(ctx android.ModuleContext) android.OutputPath
var extraFiles android.OutputPaths var extraFiles android.OutputPaths
if f.buildExtraFiles != nil { if f.buildExtraFiles != nil {
extraFiles = f.buildExtraFiles(ctx, rootForExtraFiles) extraFiles = f.buildExtraFiles(ctx, rootForExtraFiles)
for _, f := range extraFiles {
rel, _ := filepath.Rel(rootForExtraFiles.String(), f.String())
if strings.HasPrefix(rel, "..") {
panic(fmt.Errorf("%q is not under %q\n", f, rootForExtraFiles))
}
}
} }
// Zip them all for _, f := range extraFiles {
zipOut := android.PathForModuleGen(ctx, "root.zip").OutputPath rel, err := filepath.Rel(rootForExtraFiles.String(), f.String())
zipCommand := builder.Command().BuiltTool("soong_zip") if err != nil || strings.HasPrefix(rel, "..") {
zipCommand.FlagWithOutput("-o ", zipOut). ctx.ModuleErrorf("can't make %q relative to %q", f, rootForExtraFiles)
FlagWithArg("-C ", rootDir.String()). continue
Flag("-L 0"). // no compression because this will be unzipped soon
FlagWithArg("-D ", rootDir.String()).
Flag("-d") // include empty directories
if len(extraFiles) > 0 {
zipCommand.FlagWithArg("-C ", rootForExtraFiles.String())
for _, f := range extraFiles {
zipCommand.FlagWithInput("-f ", f)
} }
dst := rootDir.Join(ctx, rel)
builder.Command().Textf("(! [ -e %s -o -L %s ] || (echo \"%s already exists from an earlier stage of the build\" && exit 1))", dst, dst, dst)
builder.Command().Text("mkdir -p").Text(filepath.Dir(dst.String()))
builder.Command().Text("cp -P").Input(f).Output(dst)
} }
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 { func (f *filesystem) buildImageUsingBuildImage(ctx android.ModuleContext) android.OutputPath {
depsZipFile := android.PathForModuleOut(ctx, "deps.zip").OutputPath
f.entries = f.CopyDepsToZip(ctx, f.gatherFilteredPackagingSpecs(ctx), depsZipFile)
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 rootDir := android.PathForModuleOut(ctx, "root").OutputPath
rootZip := f.buildRootZip(ctx) rebasedDir := rootDir
builder.Command(). if f.properties.Base_dir != nil {
BuiltTool("zipsync"). rebasedDir = rootDir.Join(ctx, *f.properties.Base_dir)
FlagWithArg("-d ", rootDir.String()). // zipsync wipes this. No need to clear. }
Input(rootZip). builder := android.NewRuleBuilder(pctx, ctx)
Input(rebasedDepsZip) // Wipe the root dir to get rid of leftover files from prior builds
builder.Command().Textf("rm -rf %s && mkdir -p %s", rootDir, rootDir)
f.entries = f.CopySpecsToDir(ctx, builder, f.gatherFilteredPackagingSpecs(ctx), rebasedDir)
f.buildNonDepsFiles(ctx, builder, rootDir)
// run host_init_verifier // run host_init_verifier
// Ideally we should have a concept of pluggable linters that verify the generated image. // Ideally we should have a concept of pluggable linters that verify the generated image.
@@ -388,25 +362,17 @@ func (f *filesystem) buildCpioImage(ctx android.ModuleContext, compressed bool)
ctx.PropertyErrorf("file_contexts", "file_contexts is not supported for compressed cpio image.") ctx.PropertyErrorf("file_contexts", "file_contexts is not supported for compressed cpio image.")
} }
depsZipFile := android.PathForModuleOut(ctx, "deps.zip").OutputPath
f.entries = f.CopyDepsToZip(ctx, f.gatherFilteredPackagingSpecs(ctx), depsZipFile)
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 rootDir := android.PathForModuleOut(ctx, "root").OutputPath
rootZip := f.buildRootZip(ctx) rebasedDir := rootDir
builder.Command(). if f.properties.Base_dir != nil {
BuiltTool("zipsync"). rebasedDir = rootDir.Join(ctx, *f.properties.Base_dir)
FlagWithArg("-d ", rootDir.String()). // zipsync wipes this. No need to clear. }
Input(rootZip). builder := android.NewRuleBuilder(pctx, ctx)
Input(rebasedDepsZip) // Wipe the root dir to get rid of leftover files from prior builds
builder.Command().Textf("rm -rf %s && mkdir -p %s", rootDir, rootDir)
f.entries = f.CopySpecsToDir(ctx, builder, f.gatherFilteredPackagingSpecs(ctx), rebasedDir)
f.buildNonDepsFiles(ctx, builder, rootDir)
output := android.PathForModuleOut(ctx, f.installFileName()).OutputPath output := android.PathForModuleOut(ctx, f.installFileName()).OutputPath
cmd := builder.Command(). cmd := builder.Command().

View File

@@ -270,7 +270,7 @@ func TestFileSystemShouldInstallCoreVariantIfTargetBuildAppsIsSet(t *testing.T)
} }
`) `)
inputs := result.ModuleForTests("myfilesystem", "android_common").Output("deps.zip").Implicits inputs := result.ModuleForTests("myfilesystem", "android_common").Output("myfilesystem.img").Implicits
android.AssertStringListContains(t, "filesystem should have libbar even for unbundled build", android.AssertStringListContains(t, "filesystem should have libbar even for unbundled build",
inputs.Strings(), inputs.Strings(),
"out/soong/.intermediates/libbar/android_arm64_armv8-a_shared/libbar.so") "out/soong/.intermediates/libbar/android_arm64_armv8-a_shared/libbar.so")
@@ -314,7 +314,7 @@ func TestFileSystemWithCoverageVariants(t *testing.T) {
`) `)
filesystem := result.ModuleForTests("myfilesystem", "android_common_cov") filesystem := result.ModuleForTests("myfilesystem", "android_common_cov")
inputs := filesystem.Output("deps.zip").Implicits inputs := filesystem.Output("myfilesystem.img").Implicits
android.AssertStringListContains(t, "filesystem should have libfoo(cov)", android.AssertStringListContains(t, "filesystem should have libfoo(cov)",
inputs.Strings(), inputs.Strings(),
"out/soong/.intermediates/libfoo/android_arm64_armv8-a_shared_cov/libfoo.so") "out/soong/.intermediates/libfoo/android_arm64_armv8-a_shared_cov/libfoo.so")