Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Dependency Scanning] Unify path-escaping handling using TSC's spm_shellEscaped #1354

Merged
merged 1 commit into from May 8, 2023

Conversation

artemcm
Copy link
Contributor

@artemcm artemcm commented May 5, 2023

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 (inside libSwiftScan). 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 by libSwiftScan.

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

…ellEscaped

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 (inside libSwiftScan). In order for them to be correclty tokenized, we must ensure that all the various filepaths 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 by libSwiftScan.

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
@artemcm artemcm requested a review from nkcsgexi May 5, 2023 23:26
@artemcm
Copy link
Contributor Author

artemcm commented May 5, 2023

@swift-ci test

Copy link
Member

@nkcsgexi nkcsgexi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@artemcm artemcm merged commit 2310c7b into apple:main May 8, 2023
3 checks passed
@artemcm artemcm deleted the LibSwiftScanPathsEscape branch May 8, 2023 15:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants