From 76e677f93ec5f9d66cbb3311500f71b23fdf6207 Mon Sep 17 00:00:00 2001 From: Jeongik Cha Date: Thu, 21 Dec 2023 16:39:15 +0900 Subject: [PATCH] Extract zip_deps preparation work as a script If there are lots of files to be packaged, it causes `Argument list too long` error. So I extracted that as a separate script with WriteExecutableFileRuleVerbatim, and the method do sharding for long input. Bug: 314933937 Test: define large system_image definition Change-Id: Ibf692d4db6da6b7a536cb5b53b15c545e07ff262 --- android/packaging.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/android/packaging.go b/android/packaging.go index 503bb97e0..2506378d7 100644 --- a/android/packaging.go +++ b/android/packaging.go @@ -17,6 +17,7 @@ package android import ( "fmt" "path/filepath" + "strings" "github.com/google/blueprint" ) @@ -240,6 +241,9 @@ func (p *PackagingBase) GatherPackagingSpecs(ctx ModuleContext) map[string]Packa // entries into the specified directory. func (p *PackagingBase) CopySpecsToDir(ctx ModuleContext, builder *RuleBuilder, specs map[string]PackagingSpec, dir WritablePath) (entries []string) { seenDir := make(map[string]bool) + preparerPath := PathForModuleOut(ctx, "preparer.sh") + cmd := builder.Command().Tool(preparerPath) + var sb strings.Builder for _, k := range SortedKeys(specs) { ps := specs[k] destPath := filepath.Join(dir.String(), ps.relPathInPackage) @@ -247,18 +251,21 @@ func (p *PackagingBase) CopySpecsToDir(ctx ModuleContext, builder *RuleBuilder, entries = append(entries, ps.relPathInPackage) if _, ok := seenDir[destDir]; !ok { seenDir[destDir] = true - builder.Command().Text("mkdir").Flag("-p").Text(destDir) + sb.WriteString(fmt.Sprintf("mkdir -p %s\n", destDir)) } if ps.symlinkTarget == "" { - builder.Command().Text("cp").Input(ps.srcPath).Text(destPath) + cmd.Implicit(ps.srcPath) + sb.WriteString(fmt.Sprintf("cp %s %s\n", ps.srcPath, destPath)) } else { - builder.Command().Text("ln").Flag("-sf").Text(ps.symlinkTarget).Text(destPath) + sb.WriteString(fmt.Sprintf("ln -sf %s %s\n", ps.symlinkTarget, destPath)) } if ps.executable { - builder.Command().Text("chmod").Flag("a+x").Text(destPath) + sb.WriteString(fmt.Sprintf("chmod a+x %s\n", destPath)) } } + WriteExecutableFileRuleVerbatim(ctx, preparerPath, sb.String()) + return entries }