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

Fix CMAKE_ARGS that may have spaces inside quotes #727

Merged
merged 10 commits into from Apr 29, 2024

Conversation

vyasr
Copy link
Contributor

@vyasr vyasr commented Apr 26, 2024

The current logic for parsing CMAKE_ARGS assumes that it is safe to split the string on spaces. However, this may not be the case for all variables; some variables must be passed with spaces in them, but inside quotes. The CMAKE_<LANG>_FLAGS are a prime example of this. Quoting from the docs:

This value is a command-line string fragment. Therefore, multiple options should be separated by spaces, and options with spaces should be quoted.

To support this, the split needs to be done with a regular expression instead of a simple string split.

I left a note in the test regarding the fact that this behavior is sensitive to quotes. I don't know if we can or should do anything about that, though.

Copy link

codecov bot commented Apr 26, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.97%. Comparing base (60d5152) to head (59bff0c).
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #727      +/-   ##
==========================================
+ Coverage   81.88%   81.97%   +0.08%     
==========================================
  Files          68       68              
  Lines        3886     3888       +2     
==========================================
+ Hits         3182     3187       +5     
+ Misses        704      701       -3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@henryiii
Copy link
Collaborator

What about using shlex.split?

@henryiii
Copy link
Collaborator

henryiii commented Apr 27, 2024

Also, a unit test might be a lot cheaper than an integration test just for this function. Edit: I moved it to a C-based test, it only takes 2 seconds, so I think that's fine.

@henryiii henryiii force-pushed the fix/cmake_args_quoted_spaces branch from c7013ae to 3565421 Compare April 29, 2024 05:12
vyasr and others added 9 commits April 29, 2024 02:48
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
@henryiii henryiii force-pushed the fix/cmake_args_quoted_spaces branch from 1b1faaa to c18c0d4 Compare April 29, 2024 06:49
@henryiii
Copy link
Collaborator

Thoughts on this version with she’s.split?

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
@henryiii henryiii merged commit a5be87e into scikit-build:main Apr 29, 2024
44 of 46 checks passed
@vyasr vyasr deleted the fix/cmake_args_quoted_spaces branch April 30, 2024 03:57
@vyasr
Copy link
Contributor Author

vyasr commented Apr 30, 2024

Wow that was quick. Sorry I didn't get a chance to respond in time. My thoughts:

  • The shlex.split version is definitely better, it just didn't occur to me at the time since I rarely use that module and I reached for a regex by default.
  • I'm glad you were able to get a faster compile by using C instead of C++. I do think an integration test is better than just a unit test here because there are multiple levels of translation happening from the environment variable to what your source code actually sees, and I probably wouldn't trust a unit test to catch all cases. For example, the issue with the difference between double and single quotes only shows up if you actually get to the point of executing a compile line (of course, in this case actually doing anything with that information is probably out of scope, but I wouldn't have necessarily predicted that a priori).

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