From 48b60d22bca0158d194b78481ff86b0ac251243f Mon Sep 17 00:00:00 2001 From: Brentley Jones Date: Mon, 21 Mar 2022 10:48:08 -0500 Subject: [PATCH] osx_cc_wrapper: Only expand existing response files (#15090) Closes #13044 Applies the changes suggested in https://github.com/bazelbuild/bazel/pull/13044#issuecomment-783539568 Not all arguments starting with `@` represent response files, e.g. `-install_name @rpath/...` or `-Xlinker -rpath -Xlinker @loader_path/...` do not refer to response files and attempting to read them as such will fail the build. Users don't always have control over these arguments, meaning transforming them to `-Wl,-install_name,@rpath/...` or `-Wl,-rpath,@loader_path/...` is not always an option. E.g. as described in https://github.com/bazelbuild/bazel/pull/13044#issuecomment-779380394 where these flags are emitted by the Haskell compiler GHC (see https://github.com/bazelbuild/bazel/pull/13044#issuecomment-782228172 for their reasoning). With this change `osx_cc_wrapper` will only interpret arguments starting with `@` as response files if the corresponding file exists and is readable. This is analogous to the behavior defined in `wrapped_clang.cc`. See https://github.com/bazelbuild/bazel/pull/13044#issuecomment-783539568 for discussion. Closes #13148. PiperOrigin-RevId: 436207868 (cherry picked from commit efb2b80953983dce499d453a9f55a74ffaf8c42d) Co-authored-by: Andreas Herrmann --- tools/cpp/osx_cc_wrapper.sh | 2 +- tools/cpp/osx_cc_wrapper.sh.tpl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/cpp/osx_cc_wrapper.sh b/tools/cpp/osx_cc_wrapper.sh index 8c9c111a750587..bd8f12f26a9747 100755 --- a/tools/cpp/osx_cc_wrapper.sh +++ b/tools/cpp/osx_cc_wrapper.sh @@ -53,7 +53,7 @@ function parse_option() { # let parse the option list for i in "$@"; do - if [[ "$i" = @* ]]; then + if [[ "$i" = @* && -r "${i:1}" ]]; then while IFS= read -r opt do parse_option "$opt" diff --git a/tools/cpp/osx_cc_wrapper.sh.tpl b/tools/cpp/osx_cc_wrapper.sh.tpl index 28bd47ba1a4a97..25ed2ece8e8b4e 100644 --- a/tools/cpp/osx_cc_wrapper.sh.tpl +++ b/tools/cpp/osx_cc_wrapper.sh.tpl @@ -52,7 +52,7 @@ function parse_option() { # let parse the option list for i in "$@"; do - if [[ "$i" = @* ]]; then + if [[ "$i" = @* && -r "${i:1}" ]]; then while IFS= read -r opt do parse_option "$opt"