From 7690c099539884c8c4a94429eed54573586321be Mon Sep 17 00:00:00 2001 From: "Lukacs T. Berki" Date: Fri, 26 Feb 2021 14:27:36 +0100 Subject: 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 --- shared/paths.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'shared/paths.go') 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") -- cgit v1.2.3-59-g8ed1b