summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Treehugger Robot <treehugger-gerrit@google.com> 2020-12-01 00:00:30 +0000
committer Gerrit Code Review <noreply-gerritcodereview@google.com> 2020-12-01 00:00:30 +0000
commit6e25bb9e5f2489ac59cea62c99d0fbc6a1ccf94e (patch)
treed93012e5aaf170f07b2dd61d766972b23839aa8e
parentbd8b0d26b20c3ee24be7c261b00ecb54676c6fc7 (diff)
parentb73daa588d8ed3c02f2e0f0d57675dfc468125c2 (diff)
Merge "Soong: use deterministic temp dir names in sbox"
-rw-r--r--cmd/sbox/sbox.go19
1 files changed, 18 insertions, 1 deletions
diff --git a/cmd/sbox/sbox.go b/cmd/sbox/sbox.go
index 633c6b2cb..a4f57ea1f 100644
--- a/cmd/sbox/sbox.go
+++ b/cmd/sbox/sbox.go
@@ -16,6 +16,8 @@ package main
import (
"bytes"
+ "crypto/sha1"
+ "encoding/hex"
"errors"
"flag"
"fmt"
@@ -121,7 +123,22 @@ func run() error {
return fmt.Errorf("failed to create %q: %w", sandboxesRoot, err)
}
- tempDir, err := ioutil.TempDir(sandboxesRoot, "sbox")
+ // This tool assumes that there are no two concurrent runs with the same
+ // manifestFile. It should therefore be safe to use the hash of the
+ // manifestFile as the temporary directory name. We do this because it
+ // makes the temporary directory name deterministic. There are some
+ // tools that embed the name of the temporary output in the output, and
+ // they otherwise cause non-determinism, which then poisons actions
+ // depending on this one.
+ hash := sha1.New()
+ hash.Write([]byte(manifestFile))
+ tempDir := filepath.Join(sandboxesRoot, "sbox", hex.EncodeToString(hash.Sum(nil)))
+
+ err = os.RemoveAll(tempDir)
+ if err != nil {
+ return err
+ }
+ err = os.MkdirAll(tempDir, 0777)
if err != nil {
return fmt.Errorf("failed to create temporary dir in %q: %w", sandboxesRoot, err)
}