Allow building with cmake on Windows - #2090
Conversation
a548e19 to
ce9ff60
Compare
maxnbk
left a comment
There was a problem hiding this comment.
Nicely done contribution.
Apart from this PR, we could use actual tests that use/generate the hello_world package, but I won't consider that a blocker for this particular PR merge.
I made a few suggestions are mostly cosmetic, or affect the way docs generate.
The only open question is the CMAKE_PREFIX_PATH one, or CMAKE_*_PATH, alternatively. I suspect the right thing to do would be the wildcard, since this is a new config value, and if someone needs to override the default config value, the result is effectively the same. I'm not just sure if there are any CMAKE path vars that are supposed to have the same treatment.
b08de0c to
e73f789
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2090 +/- ##
=======================================
Coverage 61.29% 61.29%
=======================================
Files 164 164
Lines 20568 20571 +3
Branches 3575 3576 +1
=======================================
+ Hits 12607 12609 +2
- Misses 7089 7090 +1
Partials 872 872 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
e73f789 to
585c224
Compare
|
The ruff issue was fixed, a rebase will pick it up. |
JeanChristopheMorinPerso
left a comment
There was a problem hiding this comment.
I think this is almost ready. I left a small comment to enhance the cmake utility a bit more.
| OUTPUT ${local_fc} | ||
| COMMAND ${CMAKE_COMMAND} -E make_directory ${pycopy_path} | ||
| COMMAND ${py_bin} -c 'import py_compile \; py_compile.compile(\"${fabs}\", \"${local_fc}\", None, True)' | ||
| COMMAND ${py_bin} -c "import py_compile; py_compile.compile('${fabs}', '${local_fc}', None, True)" |
There was a problem hiding this comment.
| COMMAND ${py_bin} -c "import py_compile; py_compile.compile('${fabs}', '${local_fc}', None, True)" | |
| COMMAND ${py_bin} -c "import sys; py_compile; py_compile.compile(sys.argv[1], sys.argv[2], None, True)" ${fabs} ${local_fc} |
I think this is safer as it will not fail if the path contains a backslash or a single quote (which I think is valid in Windows).
There was a problem hiding this comment.
This seems good to me, I'm wondering if it shouldn't be import sys; import py_compile; instead of just import sys; py_compile;?
- Introduced `non_pathed_env_vars` configuration to exclude specific variables from path normalization - Updated `_is_pathed_key` method to respect the new configuration - Added tests to verify behavior of non-pathed environment variables in Windows shell Signed-off-by: Gabriel Reed <gabrieljreed@gmail.com>
Signed-off-by: Gabriel Reed <gabrieljreed@gmail.com>
Signed-off-by: Gabriel Reed <gabrieljreed@gmail.com>
Signed-off-by: Gabriel Reed <gabrieljreed@gmail.com>
- Documentation improvements - Replace default value of non_pathed_env_vars from `CMAKE_MODULE_PATH` to `CMAKE_*_PATH` Signed-off-by: Gabriel Reed <gabrieljreed@gmail.com>
Signed-off-by: Gabriel Reed <gabrieljreed@gmail.com>
aa7f8ae to
b33d7f4
Compare
maxnbk
left a comment
There was a problem hiding this comment.
My comments were addressed, though @JeanChristopheMorinPerso might want to recheck his.
…uotes Signed-off-by: Gabriel Reed <gabrieljreed@gmail.com>
064671f to
f0ba2af
Compare
| # normalization applied, even if they match a pattern in :data:`pathed_env_vars`. | ||
| # This is useful for variables like ``CMAKE_MODULE_PATH`` which end in ``PATH`` | ||
| # but require forward slashes regardless of the shell. Wildcards are supported. | ||
| # Takes priority over :data:`pathed_env_vars`. |
There was a problem hiding this comment.
| # Takes priority over :data:`pathed_env_vars`. | |
| # Takes priority over :data:`pathed_env_vars`. | |
| # .. versionadded:: 3.5.0 |
JeanChristopheMorinPerso
left a comment
There was a problem hiding this comment.
This looks good to me if Stephen is good with it. I'm not a fan of adding a new setting just for that, but if it works, then let's go with it.
@maxnbk Since you're likely going to do the next release, I'm leaving the decision of which version to put in the versionadded sphinx directive.
Resolves #1321
Resolves #2123
Premise
Path normalization
On Windows, rez applies path normalization (converting forward slashes to back slashes) to any environment variable whose name matches the pattern in the
pathed_env_varsconfig setting, which defaults to*PATH. This is correct behavior for variables likePATH,PYTHONPATH, andLD_LIBRARY_PATH, which need native Windows path separators. However,CMAKE_MODULE_PATHalso matches*PATH, but Cmake requires forward slashes in this variable.Unterminated string literal in
rez_install_pythonWhen building rez packages on Windows that use
rez_install_python(withnmake), the build fails with a PythonSyntaxError: unterminated string literalThe root cause is in
InstallPython.cmake- theadd_custom_commandthat compiles.pyfiles into.pycuses single quotes around the Python-cargument.On Unix, make dispatches commands via
/bin/shwhere single quotes are valid string delimiters. On Windows,nmakedispatches viacmd.exe, where single quotes are literal characters, so Python receives'importas the start of an unterminated string literal.Changes
non_pathed_env_vars, which is an exclusion list that takes priority overpathed_env_vars.pathed_env_varsfnmatchwildcards aspathed_env_varsCMAKE_MODULE_PATHout of the box, since this is a known case where we don't want normalizationinstall_pythonmacro-cargumentVERBATIMkeyword toadd_custom_commandso Cmake handles all platform-specific argument quoting correctlyTests
hello_worldexample package on both Windows and Linux after settingbuild_system = "cmake"ActionInterpreter._is_pathed_keyandshell.set_envrez_install_pythoncmake macro, but I verified that it worked manually