Sandbox soong_build by changing to root directory
This relands I12a0f907753fefd1997ab8b4ea2ac331234093cf along with
a fix to blueprint for absolute paths.
Store the current working directory and then change to the root
directory so that all file accesses must go through helpers in
the android package that properly track dependencies.
Change-Id: I24ac485677aa102eec1a2521d16820da6ee1ae77
Fixes: 146437378
Test: m checkbuild
Test: m OUT_DIR=/tmp/out nothing
diff --git a/env/env.go b/env/env.go
index bf58a99..a98e1f6 100644
--- a/env/env.go
+++ b/env/env.go
@@ -27,7 +27,7 @@
type envFileEntry struct{ Key, Value string }
type envFileData []envFileEntry
-func WriteEnvFile(filename string, envDeps map[string]string) error {
+func EnvFileContents(envDeps map[string]string) ([]byte, error) {
contents := make(envFileData, 0, len(envDeps))
for key, value := range envDeps {
contents = append(contents, envFileEntry{key, value})
@@ -37,17 +37,12 @@
data, err := json.MarshalIndent(contents, "", " ")
if err != nil {
- return err
+ return nil, err
}
data = append(data, '\n')
- err = ioutil.WriteFile(filename, data, 0664)
- if err != nil {
- return err
- }
-
- return nil
+ return data, nil
}
func StaleEnvFile(filename string) (bool, error) {