From 76cb8cbc7e3b7d6f9169ac9cd4ea41d62a097043 Mon Sep 17 00:00:00 2001 From: javrin Date: Thu, 10 Aug 2023 23:06:06 +0000 Subject: [PATCH] Address cmake build failures on Windows in powershell and pwsh Signed-off-by: javrin --- src/rez/tests/test_build.py | 2 +- src/rezplugins/shell/_utils/powershell_base.py | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/rez/tests/test_build.py b/src/rez/tests/test_build.py index 7f45a5a66..4c2a51e67 100644 --- a/src/rez/tests/test_build.py +++ b/src/rez/tests/test_build.py @@ -135,7 +135,7 @@ def _test_build_sup_world(self): stdout = proc.communicate()[0] self.assertEqual('hola amigo', stdout.strip()) - @per_available_shell(include=["cmd", "gitbash"]) + @per_available_shell() @program_dependent("cmake", "make") @platform_dependent(["windows"]) @install_dependent() diff --git a/src/rezplugins/shell/_utils/powershell_base.py b/src/rezplugins/shell/_utils/powershell_base.py index 2957a6de8..d0c942bbd 100644 --- a/src/rezplugins/shell/_utils/powershell_base.py +++ b/src/rezplugins/shell/_utils/powershell_base.py @@ -248,7 +248,9 @@ def normalize_path(self, path): This isn't explicitely necessary on Windows since around Windows 7, PowerShell has supported mixed slashes as a path separator. However, - we can still call this method to normalize paths for consistency. + we can still call this method to normalize paths for consistency, and + have better interoperability with some software such as cmake which + prefer forward slashes e.g. GH issue #1321. Args: path (str): Path to normalize. @@ -261,7 +263,8 @@ def normalize_path(self, path): return path if platform_.name == "windows": - normalized_path = path.replace("/", "\\") + path = os.path.normpath(path) + normalized_path = path.replace("\\", "/") if path != normalized_path: log("PowerShellBase normalize_path()") log("Path normalized: {!r} -> {!r}".format(path, normalized_path)) @@ -354,6 +357,8 @@ def join(cls, command): if isinstance(command, six.string_types): return command + find_unsafe = re.compile(r'[^\w@%+`:,./-]').search + replacements = [ # escape ` as `` ('`', "``"), @@ -362,7 +367,7 @@ def join(cls, command): ('"', '`"') ] - joined = shlex_join(command, replacements=replacements) + joined = shlex_join(command, unsafe_regex=find_unsafe, replacements=replacements) # add call operator in case executable gets quotes applied # https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_operators?view=powershell-7.1#call-operator-