summaryrefslogtreecommitdiff
path: root/shared/paths.go
diff options
context:
space:
mode:
author Lukacs T. Berki <lberki@google.com> 2021-02-26 14:27:36 +0100
committer Lukacs T. Berki <lberki@google.com> 2021-03-03 09:14:22 +0100
commit7690c099539884c8c4a94429eed54573586321be (patch)
tree6c947227785120140c4bc8fc1b7083833ae58a21 /shared/paths.go
parent3bed960399dad2f97f75ef33e1ab407b84d3e6c7 (diff)
cd to / before running soong_build .
This lets one avoid any decisions as to when to chdir there during its execution and leads to better sandboxing because the pwd doesn't leak to init() functions anymore. Test: Manual. Change-Id: I1560da8ed3a621249426f9e8908aa890c21e13ba
Diffstat (limited to 'shared/paths.go')
-rw-r--r--shared/paths.go15
1 files changed, 15 insertions, 0 deletions
diff --git a/shared/paths.go b/shared/paths.go
index 1b9ff6098..fca8b4c15 100644
--- a/shared/paths.go
+++ b/shared/paths.go
@@ -30,6 +30,21 @@ type SharedPaths interface {
BazelMetricsDir() string
}
+// Joins the path strings in the argument list, taking absolute paths into
+// account. That is, if one of the strings is an absolute path, the ones before
+// are ignored.
+func JoinPath(base string, rest ...string) string {
+ result := base
+ for _, next := range rest {
+ if filepath.IsAbs(next) {
+ result = next
+ } else {
+ result = filepath.Join(result, next)
+ }
+ }
+ return result
+}
+
// Given the out directory, returns the root of the temp directory (to be cleared at the start of each execution of Soong)
func TempDirForOutDir(outDir string) (tempPath string) {
return filepath.Join(outDir, ".temp")