summaryrefslogtreecommitdiff
path: root/zip/zip.go
diff options
context:
space:
mode:
author Dan Albert <danalbert@google.com> 2023-07-13 17:41:04 +0000
committer Dan Albert <danalbert@google.com> 2023-07-13 18:45:32 +0000
commit1cec6d5000a1640f27eed162d2727bb33290f25c (patch)
tree0ba184f6de06fd3d58de4313f174b6a76e8a505a /zip/zip.go
parent2c59e460348952549d32334b95fc37e42542de7e (diff)
Add flag to skip writing output from soong_zip.
We want to measure how much of build time is spent on writing large zips to disk. We can do this by doing the rest of the work but skipping the write itself. Some local and trivial testing shows this is probably a lot of the cost of these rules: $ python -m timeit -s "import os" -r 10 "os.system('soong_zip -write_if_changed -o foo.zip -D prebuilts/sdk')" 1 loop, best of 10: 8.37 sec per loop $ python -m timeit -s "import os" -r 10 "os.system('soong_zip -o foo.zip -D prebuilts/sdk')" 1 loop, best of 10: 5.39 sec per loop $ python -m timeit -s "import os" -r 10 "os.system('soong_zip -n -o foo.zip -D prebuilts/sdk')" 1 loop, best of 10: 3.66 sec per loop Bug: None Test: treehugger Change-Id: I43acdb08d0e00efaba9e5d7add972a7ec41646d2
Diffstat (limited to 'zip/zip.go')
-rw-r--r--zip/zip.go7
1 files changed, 5 insertions, 2 deletions
diff --git a/zip/zip.go b/zip/zip.go
index 5e1a10462..30a2ee762 100644
--- a/zip/zip.go
+++ b/zip/zip.go
@@ -282,6 +282,7 @@ type ZipArgs struct {
StoreSymlinks bool
IgnoreMissingFiles bool
Sha256Checksum bool
+ DoNotWrite bool
Stderr io.Writer
Filesystem pathtools.FileSystem
@@ -400,7 +401,9 @@ func Zip(args ZipArgs) error {
var zipErr error
- if !args.WriteIfChanged {
+ if args.DoNotWrite {
+ out = io.Discard
+ } else if !args.WriteIfChanged {
f, err := os.Create(args.OutputFilePath)
if err != nil {
return err
@@ -421,7 +424,7 @@ func Zip(args ZipArgs) error {
return zipErr
}
- if args.WriteIfChanged {
+ if args.WriteIfChanged && !args.DoNotWrite {
err := pathtools.WriteFileIfChanged(args.OutputFilePath, buf.Bytes(), 0666)
if err != nil {
return err