diff options
author | android-build-team Robot <android-build-team-robot@google.com> | 2021-06-17 19:05:20 +0000 |
---|---|---|
committer | android-build-team Robot <android-build-team-robot@google.com> | 2021-06-17 19:05:20 +0000 |
commit | 1fc276040d574012e4f46891409fa93b6f0fec11 (patch) | |
tree | 73936aba47fe1dc71e9cc05af9747036e935608c /compiler_wrapper/env.go | |
parent | b75f321fc8978b92ce3db6886ccb966768f0c7a8 (diff) | |
parent | 4e4201457e5f51a132101c611c79ccff9f713c8b (diff) | |
download | toolchain-utils-1fc276040d574012e4f46891409fa93b6f0fec11.tar.gz |
Snap for 7468467 from 4e4201457e5f51a132101c611c79ccff9f713c8b to mainline-mediaprovider-releaseandroid-mainline-12.0.0_r90android-mainline-12.0.0_r76android-mainline-12.0.0_r48android-mainline-12.0.0_r31android-mainline-12.0.0_r121android-mainline-12.0.0_r11android-mainline-12.0.0_r106aml_mpr_311911090android12-mainline-mediaprovider-release
Change-Id: I025bd1851bc27970c5b4ef6a391e3e8edb26d9b4
Diffstat (limited to 'compiler_wrapper/env.go')
-rw-r--r-- | compiler_wrapper/env.go | 26 |
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 } |