[Dependency Scanning] Unify path-escaping handling using TSC's spm_shellEscaped #1354
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.
Command lines generated for
libSwiftScan
(either for actual dependency scanning queries, or for target-info queries) do not go through the shell, and are instead tokenized at the entry-points (insidelibSwiftScan
). In order for them to be correctly tokenized, we must ensure that all the various file paths are escaped in case they contain whitespace characters, to ensure they get treated as a whole path, rather than multiple strings.The driver previously relied on a separate mechanism to do this for libSwiftScan command lines, by getting the
ArgsResolver
to always escape.path
arguments. This turned out to be insufficient, because it happens to miss a whole class of paths specified on the command-line that the driver cannot/doesn't recognize as paths: arguments forwarded to tools, such as-Xcc
or-Xfrontend
or-Xclang-linker
. As a result, it is possible for such paths to end-up unescaped and fail to get tokenized correctly bylibSwiftScan
.Instead, this change switches the formulation of these command-lines to use the existing
spm_shellEscaped
mechanism from TSC which is a robust way to achieve exactly the desired behavior: produce shell-escaped command-line arguments by detecting flags/arguments that contain characters that would prevent correct tokenization: whitespaces, etc, and only quote-escaping them, and doing so in a platform-appropriate manner (e.g. using"
instead of'
on Windows)Resolves rdar://108971395