aboutsummaryrefslogtreecommitdiff
path: root/compiler_wrapper/env.go
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2021-07-15 02:04:13 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2021-07-15 02:04:13 +0000
commitc72a0e5f0d0e5ac38313e63ff50cd18ab0a9c77c (patch)
tree73936aba47fe1dc71e9cc05af9747036e935608c /compiler_wrapper/env.go
parentb75f321fc8978b92ce3db6886ccb966768f0c7a8 (diff)
parent4e4201457e5f51a132101c611c79ccff9f713c8b (diff)
downloadtoolchain-utils-android12-mainline-captiveportallogin-release.tar.gz
Snap for 7550930 from 4e4201457e5f51a132101c611c79ccff9f713c8b to mainline-captiveportallogin-releaseandroid-mainline-12.0.0_r6android-mainline-12.0.0_r23android12-mainline-captiveportallogin-release
Change-Id: Iedfae00fc40c41956a3a0b9a7b94674329a6130a
Diffstat (limited to 'compiler_wrapper/env.go')
-rw-r--r--compiler_wrapper/env.go26
1 files changed, 16 insertions, 10 deletions
diff --git a/compiler_wrapper/env.go b/compiler_wrapper/env.go
index 56b3a913..2c48ad30 100644
--- a/compiler_wrapper/env.go
+++ b/compiler_wrapper/env.go
@@ -28,19 +28,25 @@ type processEnv struct {
}
func newProcessEnv() (env, error) {
- // Note: We are not using os.getwd() as this sometimes uses the value of the PWD
- // env variable. This has the following problems:
- // - if PWD=/proc/self/cwd, os.getwd() will return "/proc/self/cwd",
- // and we need to read the link to get the actual wd. However, we can't always
- // do this as we are calculating
- // the path to clang, and following a symlinked cwd first would make
- // this calculation invalid.
- // - the old python wrapper doesn't respect the PWD env variable either, so if we
- // did we would fail the comparison to the old wrapper.
- wd, err := os.Readlink("/proc/self/cwd")
+ wd, err := os.Getwd()
if err != nil {
return nil, wrapErrorwithSourceLocf(err, "failed to read working directory")
}
+
+ // Note: On Linux, Getwd may resolve to /proc/self/cwd, since it checks the PWD environment
+ // variable. We need to read the link to get the actual working directory. We can't always
+ // do this as we are calculating the path to clang, since following a symlinked cwd first
+ // would make this calculation invalid.
+ //
+ // FIXME(gbiv): It's not clear why always Readlink()ing here an issue. crrev.com/c/1764624
+ // might provide helpful context?
+ if wd == "/proc/self/cwd" {
+ wd, err = os.Readlink(wd)
+ if err != nil {
+ return nil, wrapErrorwithSourceLocf(err, "resolving /proc/self/cwd")
+ }
+ }
+
return &processEnv{wd: wd}, nil
}