aboutsummaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorJeff Gaston <jeffrygaston@google.com>2017-11-06 13:33:14 -0800
committerJeff Gaston <jeffrygaston@google.com>2017-11-08 13:44:03 -0800
commit8a88db5a3521170daa7fd3b4ca020a2d9234c117 (patch)
tree43f5cbf7705e9e6498ca4908a63402cd26be4b5f /cmd
parent437d23c3ad184841ab8c3907a34f339c5c3c312f (diff)
downloadbuild_soong-8a88db5a3521170daa7fd3b4ca020a2d9234c117.tar.gz
build_soong-8a88db5a3521170daa7fd3b4ca020a2d9234c117.tar.bz2
build_soong-8a88db5a3521170daa7fd3b4ca020a2d9234c117.zip
Have sbox remove its output directory before running
Bug: 38205169 Test: m -j Change-Id: I73abb9921596c96fa056449bdf8250c2928bceda
Diffstat (limited to 'cmd')
-rw-r--r--cmd/sbox/sbox.go28
1 files changed, 23 insertions, 5 deletions
diff --git a/cmd/sbox/sbox.go b/cmd/sbox/sbox.go
index 4b008eb8..558bc3fb 100644
--- a/cmd/sbox/sbox.go
+++ b/cmd/sbox/sbox.go
@@ -45,6 +45,7 @@ func init() {
flag.StringVar(&depfileOut, "depfile-out", "",
"file path of the depfile to generate. This value will replace '__SBOX_DEPFILE__' in the command and will be treated as an output but won't be added to __SBOX_OUT_FILES__")
+
}
func usageViolation(violation string) {
@@ -53,10 +54,11 @@ func usageViolation(violation string) {
}
fmt.Fprintf(os.Stderr,
- "Usage: sbox -c <commandToRun> --sandbox-path <sandboxPath> --output-root <outputRoot> [--depfile-out depFile] <outputFile> [<outputFile>...]\n"+
+ "Usage: sbox -c <commandToRun> --sandbox-path <sandboxPath> --output-root <outputRoot> --overwrite [--depfile-out depFile] <outputFile> [<outputFile>...]\n"+
"\n"+
- "Runs <commandToRun> and moves each <outputFile> out of <sandboxPath>\n"+
- "and into <outputRoot>\n")
+ "Deletes <outputRoot>,"+
+ "runs <commandToRun>,"+
+ "and moves each <outputFile> out of <sandboxPath> and into <outputRoot>\n")
flag.PrintDefaults()
@@ -101,7 +103,19 @@ func run() error {
// all outputs
var allOutputs []string
- os.MkdirAll(sandboxesRoot, 0777)
+ // setup directories
+ err := os.MkdirAll(sandboxesRoot, 0777)
+ if err != nil {
+ return err
+ }
+ err = os.RemoveAll(outputRoot)
+ if err != nil {
+ return err
+ }
+ err = os.MkdirAll(outputRoot, 0777)
+ if err != nil {
+ return err
+ }
tempDir, err := ioutil.TempDir(sandboxesRoot, "sbox")
@@ -207,7 +221,11 @@ func run() error {
if len(outputRoot) != 0 {
destPath = filepath.Join(outputRoot, filePath)
}
- err := os.Rename(tempPath, destPath)
+ err := os.MkdirAll(filepath.Dir(destPath), 0777)
+ if err != nil {
+ return err
+ }
+ err = os.Rename(tempPath, destPath)
if err != nil {
return err
}