Revert "Clean environment variables to account for sandbox work directory."

This reverts commit 0af8ea14fc950d1121260dc6c02fa9a5b0ceb77d.

Reason for revert: <Droidmonitor created revert due to b/363848580. Will be verifying through ABTD before submission.>

Change-Id: Iafba28897ad27df67ef8ae8904454196c482216d
diff --git a/ui/build/config.go b/ui/build/config.go
index 90b98f5..dfe0dfe 100644
--- a/ui/build/config.go
+++ b/ui/build/config.go
@@ -214,10 +214,6 @@
 		sandboxConfig:         &SandboxConfig{},
 		ninjaWeightListSource: DEFAULT,
 	}
-	wd, err := os.Getwd()
-	if err != nil {
-		ctx.Fatalln("Failed to get working directory:", err)
-	}
 
 	// Skip soong tests by default on Linux
 	if runtime.GOOS == "linux" {
@@ -249,13 +245,17 @@
 
 	// Make sure OUT_DIR is set appropriately
 	if outDir, ok := ret.environ.Get("OUT_DIR"); ok {
-		ret.environ.Set("OUT_DIR", ret.sandboxPath(wd, filepath.Clean(outDir)))
+		ret.environ.Set("OUT_DIR", filepath.Clean(outDir))
 	} else {
 		outDir := "out"
 		if baseDir, ok := ret.environ.Get("OUT_DIR_COMMON_BASE"); ok {
-			outDir = filepath.Join(baseDir, filepath.Base(wd))
+			if wd, err := os.Getwd(); err != nil {
+				ctx.Fatalln("Failed to get working directory:", err)
+			} else {
+				outDir = filepath.Join(baseDir, filepath.Base(wd))
+			}
 		}
-		ret.environ.Set("OUT_DIR", ret.sandboxPath(wd, outDir))
+		ret.environ.Set("OUT_DIR", outDir)
 	}
 
 	// loadEnvConfig needs to know what the OUT_DIR is, so it should
@@ -350,9 +350,6 @@
 
 		// Use config.useN2 instead.
 		"SOONG_USE_N2",
-
-		// Leaks usernames into environment.
-		"HOME",
 	)
 
 	if ret.UseGoma() || ret.ForceUseGoma() {
@@ -364,12 +361,12 @@
 	ret.environ.Set("PYTHONDONTWRITEBYTECODE", "1")
 
 	tmpDir := absPath(ctx, ret.TempDir())
-	ret.environ.Set("TMPDIR", ret.sandboxPath(wd, tmpDir))
+	ret.environ.Set("TMPDIR", tmpDir)
 
 	// Always set ASAN_SYMBOLIZER_PATH so that ASAN-based tools can symbolize any crashes
 	symbolizerPath := filepath.Join("prebuilts/clang/host", ret.HostPrebuiltTag(),
 		"llvm-binutils-stable/llvm-symbolizer")
-	ret.environ.Set("ASAN_SYMBOLIZER_PATH", ret.sandboxPath(wd, absPath(ctx, symbolizerPath)))
+	ret.environ.Set("ASAN_SYMBOLIZER_PATH", absPath(ctx, symbolizerPath))
 
 	// Precondition: the current directory is the top of the source tree
 	checkTopDir(ctx)
@@ -423,18 +420,15 @@
 
 	ret.configureLocale(ctx)
 
-	newPath := []string{ret.sandboxPath(wd, filepath.Join(absJavaHome, "bin"))}
+	newPath := []string{filepath.Join(absJavaHome, "bin")}
 	if path, ok := ret.environ.Get("PATH"); ok && path != "" {
-		entries := strings.Split(path, string(filepath.ListSeparator))
-		for _, ent := range entries {
-			newPath = append(newPath, ret.sandboxPath(wd, ent))
-		}
+		newPath = append(newPath, path)
 	}
 
 	ret.environ.Unset("OVERRIDE_ANDROID_JAVA_HOME")
-	ret.environ.Set("JAVA_HOME", ret.sandboxPath(wd, absJavaHome))
-	ret.environ.Set("ANDROID_JAVA_HOME", ret.sandboxPath(wd, javaHome))
-	ret.environ.Set("ANDROID_JAVA8_HOME", ret.sandboxPath(wd, java8Home))
+	ret.environ.Set("JAVA_HOME", absJavaHome)
+	ret.environ.Set("ANDROID_JAVA_HOME", javaHome)
+	ret.environ.Set("ANDROID_JAVA8_HOME", java8Home)
 	ret.environ.Set("PATH", strings.Join(newPath, string(filepath.ListSeparator)))
 
 	// b/286885495, https://bugzilla.redhat.com/show_bug.cgi?id=2227130: some versions of Fedora include patches
@@ -450,7 +444,7 @@
 		ret.buildDateTime = strconv.FormatInt(time.Now().Unix(), 10)
 	}
 
-	ret.environ.Set("BUILD_DATETIME_FILE", ret.sandboxPath(wd, buildDateTimeFile))
+	ret.environ.Set("BUILD_DATETIME_FILE", buildDateTimeFile)
 
 	if _, ok := ret.environ.Get("BUILD_USERNAME"); !ok {
 		username := "unknown"
@@ -461,7 +455,6 @@
 		}
 		ret.environ.Set("BUILD_USERNAME", username)
 	}
-	ret.environ.Set("PWD", ret.sandboxPath(wd, wd))
 
 	if ret.UseRBE() {
 		for k, v := range getRBEVars(ctx, Config{ret}) {
@@ -1303,19 +1296,6 @@
 	return err == nil
 }
 
-func (c *configImpl) sandboxPath(base, in string) string {
-	if !c.UseABFS() {
-		return in
-	}
-
-	rel, err := filepath.Rel(base, in)
-	if err != nil {
-		return in
-	}
-
-	return filepath.Join(abfsSrcDir, rel)
-}
-
 func (c *configImpl) UseRBE() bool {
 	// These alternate modes of running Soong do not use RBE / reclient.
 	if c.Queryview() || c.JsonModuleGraph() {
@@ -1736,11 +1716,6 @@
 }
 
 func (c *configImpl) SkipMetricsUpload() bool {
-	// b/362625275 - Metrics upload sometimes prevents abfs unmount
-	if c.UseABFS() {
-		return true
-	}
-
 	return c.skipMetricsUpload
 }
 
diff --git a/ui/build/path.go b/ui/build/path.go
index 075bf2e..51ebff1 100644
--- a/ui/build/path.go
+++ b/ui/build/path.go
@@ -57,22 +57,6 @@
 	return ret
 }
 
-func updatePathForSandbox(config Config) {
-	wd, err := os.Getwd()
-	if err != nil {
-		return
-	}
-
-	var newPath []string
-	if path, ok := config.Environment().Get("PATH"); ok && path != "" {
-		entries := strings.Split(path, string(filepath.ListSeparator))
-		for _, ent := range entries {
-			newPath = append(newPath, config.sandboxPath(wd, ent))
-		}
-	}
-	config.Environment().Set("PATH", strings.Join(newPath, string(filepath.ListSeparator)))
-}
-
 // SetupLitePath is the "lite" version of SetupPath used for dumpvars, or other
 // places that does not need the full logging capabilities of path_interposer,
 // wants the minimal performance overhead, and still get the benefits of $PATH
@@ -137,7 +121,6 @@
 	// Set $PATH to be the directories containing the host tool symlinks, and
 	// the prebuilts directory for the current host OS.
 	config.Environment().Set("PATH", myPath)
-	updatePathForSandbox(config)
 	config.pathReplaced = true
 }
 
@@ -282,6 +265,5 @@
 	// Replace the $PATH variable with the path_interposer symlinks, and
 	// checked-in prebuilts.
 	config.Environment().Set("PATH", myPath)
-	updatePathForSandbox(config)
 	config.pathReplaced = true
 }
diff --git a/ui/build/sandbox_linux.go b/ui/build/sandbox_linux.go
index 6c46000..d9ca854 100644
--- a/ui/build/sandbox_linux.go
+++ b/ui/build/sandbox_linux.go
@@ -187,17 +187,8 @@
 	return args
 }
 
-func (c *Cmd) workDir() string {
-	if !c.config.UseABFS() {
-		wd, _ := os.Getwd()
-		return wd
-	}
-
-	return abfsSrcDir
-}
-
 func (c *Cmd) wrapSandbox() {
-	wd := c.workDir()
+	wd, _ := os.Getwd()
 
 	var sandboxArgs []string
 	sandboxArgs = append(sandboxArgs,
@@ -235,7 +226,7 @@
 	)
 
 	sandboxArgs = append(sandboxArgs,
-		c.readMountArgs()...,
+		c.readMountArgs()...
 	)
 
 	sandboxArgs = append(sandboxArgs,