Support response files with quoted args
https://github.com/bazel-contrib/toolchains_llvm/pull/245 introduced a regression where clang response files were read and expanded into args on the command line.
This was a regression because response files support quoted args:
$ cat args
"-O3"
"main.cc"
$ clang @args # success
but cc_wrapper.sh will expand this to
$ clang '"-O3"' '"main.cc"'
clang: error: no such file or directory: '"-O3"'
clang: error: no such file or directory: '"main.cc"'
clang: error: no input files
This is not just a theoretical concern: golang (which is using a c++ linker for its cgo integration) is explicitly quoting its strings in the response files: https://github.com/golang/go/blob/ecc06f0db79193a4fe16138148c7eb26d9af96f1/src/cmd/link/internal/ld/lib.go#L2123-L2124
This PR solves this by processing what's inside the quotes instead of the string as a whole. As a bonus, this will also support multiple (quoted or unquoted) args on a single line, which is something clang supports but toolchains_llvm does not. The fix is inspired by https://stackoverflow.com/a/17346794 but modified to support args starting with $ (need to be passed through).
Note that another related fix is https://github.com/bazel-contrib/toolchains_llvm/pull/430, which passes through the response files to clang. That PR would also be great to support very long arg lists, but we still need this PR to properly call sanitize_option for quoted args.
CI is red
CI is red
This was because some args are like $ORIGIN/_solib_k8/_U_A_Atoolchains_Ullvm++llvm+llvm_Utoolchain_S_S_Comp___Ulib with $ORIGIN was now being expanded instead of passed through. I've proposed a fix but I am not super happy with the readability.
@faximan Could you rebase and resolve the conflict?