refactor(toolchain): fix --plugin-path on non-Xcode toolchains #1610
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Depending on a swift_compiler_plugin target currently adds:
to the compiler action. It's ok when using an Xcode toolchain, but when used with a standalone non-apple cc_toolchain (such as one from llvm_toolchain for instance), DEVELOPER_DIR will not be set, therefore causing the swift worker executable to either crash (on MacOS) or just return the empty string (on Linux). None of which are particularly helpful.
The right thing to do, from a swift perspective, would be to return a path inside the swift toolchain currently in use, regardless of whether we're using an Xcode toolchain or an alternative toolchain.
In this commit, we're therefore changing the meaning of the variable currently named
__BAZEL_CUSTOM_XCODE_TOOLCHAIN_PATH__. It is currently meant to contain the name of the xcode toolchain when set through the TOOLCHAINS variable (in --action_env), and nothing otherwise. We're repurposing it to always return the swift toolchain location, regardless of the toolchain currently in use. When using TOOLCHAINS, it will return the path to the toolchain, and when using DEVELOPER_DIR, it will return the swift toolchain path inside the Xcode folder.To reflect its new meaning, we're giving it a new name by the same occasion: BAZEL_SWIFT_TOOLCHAIN_PATH. Which just so happens, is also the private name it is given inside bazel_substitutions.cc.
Finally, we're making use of that new variable in
swift_compiler_plugin(), so --plugin-path work in non-Xcode environments.