From 6a4edb13e61d52a2d8df2437ca21598ef85e291d Mon Sep 17 00:00:00 2001 From: amorphousWaste <20346603+amorphousWaste@users.noreply.github.com> Date: Thu, 24 Nov 2022 11:00:50 -0800 Subject: [PATCH] Add debugging output to path conversion Add path conversion info into file. Signed-off-by: amorphousWaste <20346603+amorphousWaste@users.noreply.github.com> --- .../shell/_utils/powershell_base.py | 46 ++++++++++++++++--- src/rezplugins/shell/_utils/windows.py | 15 +++--- src/rezplugins/shell/cmd.py | 18 ++++++-- src/rezplugins/shell/csh.py | 15 +++++- src/rezplugins/shell/gitbash.py | 16 ++++++- src/rezplugins/shell/sh.py | 14 +++++- 6 files changed, 102 insertions(+), 22 deletions(-) diff --git a/src/rezplugins/shell/_utils/powershell_base.py b/src/rezplugins/shell/_utils/powershell_base.py index a72a3892d..051d74d49 100644 --- a/src/rezplugins/shell/_utils/powershell_base.py +++ b/src/rezplugins/shell/_utils/powershell_base.py @@ -13,6 +13,7 @@ from rez.system import system from rez.utils.platform_ import platform_ from rez.utils.execution import Popen +from rez.utils.logging_ import print_debug from rez.util import shlex_join from .windows import convert_path @@ -250,7 +251,16 @@ def normalize_path(self, path): return path if platform_.name == "windows": - return convert_path(path, 'windows') + converted_path = convert_path(path, 'windows') + if path != converted_path: + print_debug( + 'Path converted: {} -> {}'.format(path, converted_path) + ) + self._addline( + '# Path converted: {} -> {}'.format(path, converted_path) + ) + return converted_path + else: return path @@ -261,21 +271,45 @@ def shebang(self): pass def setenv(self, key, value): - value = self.escape_string(value, is_path=self._is_pathed_key(key)) - self._addline('Set-Item -Path "Env:{0}" -Value "{1}"'.format(key, value)) + is_path = self._is_pathed_key(key) + new_value = self.escape_string(value, is_path=is_path) + + if is_path and value != new_value: + print_debug( + 'Path changed: {} -> {}'.format(value, new_value) + ) + self._addline( + '# Path value changed: {} -> {}'.format(value, new_value) + ) + + self._addline( + 'Set-Item -Path "Env:{0}" -Value "{1}"'.format(key, new_value) + ) def prependenv(self, key, value): - value = self.escape_string(value, is_path=self._is_pathed_key(key)) + is_path = self._is_pathed_key(key) + new_value = self.escape_string(value, is_path=is_path) + + if is_path and value != new_value: + self._addline( + '# Path value changed: {} -> {}'.format(value, new_value) + ) # Be careful about ambiguous case in pwsh on Linux where pathsep is : # so that the ${ENV:VAR} form has to be used to not collide. self._addline( 'Set-Item -Path "Env:{0}" -Value ("{1}{2}" + (Get-ChildItem "Env:{0}").Value)'.format( - key, value, self.pathsep) + key, new_value, self.pathsep) ) def appendenv(self, key, value): - value = self.escape_string(value, is_path=self._is_pathed_key(key)) + is_path = self._is_pathed_key(key) + new_value = self.escape_string(value, is_path=is_path) + + if is_path and value != new_value: + self._addline( + '# Path value changed: {} -> {}'.format(value, new_value) + ) # Be careful about ambiguous case in pwsh on Linux where pathsep is : # so that the ${ENV:VAR} form has to be used to not collide. diff --git a/src/rezplugins/shell/_utils/windows.py b/src/rezplugins/shell/_utils/windows.py index fb70f3447..329cfeee1 100644 --- a/src/rezplugins/shell/_utils/windows.py +++ b/src/rezplugins/shell/_utils/windows.py @@ -6,7 +6,7 @@ import re import subprocess from rez.utils.execution import Popen - +from rez.utils.logging_ import print_debug _drive_start_regex = re.compile(r"^([A-Za-z]):\\") _drive_regex_mixed = re.compile(r"([a-z]):/") @@ -38,20 +38,23 @@ def _repl(m): # Convert the path based on mode. if mode == 'mixed': - path = to_mixed_path(path) + new_path = to_mixed_path(path) elif mode == 'windows': - path = to_windows_path(path) + new_path = to_windows_path(path) else: - path = to_posix_path(path) + new_path = to_posix_path(path) # NOTE: This would be normal cygpath behavior, but the broader # implications of enabling it need extensive testing. # Leaving it up to the user for now. if force_fwdslash: # Backslash -> fwdslash - path = path.replace('\\', '/') + new_path = new_path.replace('\\', '/') - return path + if path != new_path: + print_debug('Path converted: {} -> {}'.format(path, new_path)) + + return new_path def to_posix_path(path): diff --git a/src/rezplugins/shell/cmd.py b/src/rezplugins/shell/cmd.py index 8d9b5f7ec..a842bb57a 100644 --- a/src/rezplugins/shell/cmd.py +++ b/src/rezplugins/shell/cmd.py @@ -5,7 +5,6 @@ """ Windows Command Prompt (DOS) shell. """ -from lib2to3.pytree import convert from rez.config import config from rez.rex import RexExecutor, expandable, OutputStyle, EscapedString from rez.shells import Shell @@ -296,11 +295,21 @@ def normalize_path(self, path): Returns: (str): Normalized file path. """ - return convert_path(path, 'windows') # Prevent path conversion if normalization is disabled in the config. if config.disable_normalization: return path + converted_path = convert_path(path, 'windows') + + if path != converted_path: + self._addline( + 'REM Path converted: {} -> {}'.format( + path, converted_path + ) + ) + + return converted_path + def _saferefenv(self, key): pass @@ -308,12 +317,13 @@ def shebang(self): pass def setenv(self, key, value): - value = self.escape_string( + new_value = self.escape_string( value, is_path=self._is_pathed_key(key), is_shell_path=self._is_shell_pathed_key(key), ) - self._addline('set %s=%s' % (key, value)) + + self._addline('set %s=%s' % (key, new_value)) def unsetenv(self, key): self._addline("set %s=" % key) diff --git a/src/rezplugins/shell/csh.py b/src/rezplugins/shell/csh.py index 74216921f..e7f8efc3b 100644 --- a/src/rezplugins/shell/csh.py +++ b/src/rezplugins/shell/csh.py @@ -14,6 +14,7 @@ from rez.util import shlex_join from rez.utils.execution import Popen from rez.utils.platform_ import platform_ +from rez.utils.logging_ import print_debug from rez.shells import UnixShell from rez.rex import EscapedString @@ -159,8 +160,18 @@ def _saferefenv(self, key): self._addline("if (!($?%s)) setenv %s" % (key, key)) def setenv(self, key, value): - value = self.escape_string(value, is_path=self._is_pathed_key(key)) - self._addline('setenv %s %s' % (key, value)) + is_path = self._is_pathed_key(key) or self._is_shell_pathed_key(key) + new_value = self.escape_string(value, is_path=self._is_pathed_key(key)) + + if is_path and value != new_value: + print_debug( + 'Path changed: {} -> {}'.format(value, new_value) + ) + self._addline( + '# Path value changed: {} -> {}'.format(value, new_value) + ) + + self._addline('setenv %s %s' % (key, new_value)) def unsetenv(self, key): self._addline("unsetenv %s" % key) diff --git a/src/rezplugins/shell/gitbash.py b/src/rezplugins/shell/gitbash.py index 9d1c323df..9fe6d39c0 100644 --- a/src/rezplugins/shell/gitbash.py +++ b/src/rezplugins/shell/gitbash.py @@ -112,11 +112,17 @@ def as_shell_path(self, path): Returns: (str): Transformed file path. """ - return convert_path(path, mode='mixed', force_fwdslash=True) # Prevent path conversion if normalization is disabled in the config. if config.disable_normalization: return path + converted_path = convert_path(path, mode='mixed', force_fwdslash=True) + if path != converted_path: + self._addline( + '# Path converted: {} -> {}'.format(path, converted_path) + ) + return converted_path + def normalize_path(self, path): """Normalize the path to fit the environment. For example, POSIX paths, Windows path, etc. If no transformation is @@ -128,11 +134,17 @@ def normalize_path(self, path): Returns: (str): Normalized file path. """ - return convert_path(path, mode='unix', force_fwdslash=True) # Prevent path conversion if normalization is disabled in the config. if config.disable_normalization: return path + converted_path = convert_path(path, mode='unix', force_fwdslash=True) + if path != converted_path: + self._addline( + '# Path converted: {} -> {}'.format(path, converted_path) + ) + return converted_path + def normalize_paths(self, value): """ This is a bit tricky in the case of gitbash. The problem we hit is that diff --git a/src/rezplugins/shell/sh.py b/src/rezplugins/shell/sh.py index 6372b6dc8..3267acf9f 100644 --- a/src/rezplugins/shell/sh.py +++ b/src/rezplugins/shell/sh.py @@ -12,6 +12,7 @@ from rez.config import config from rez.utils.execution import Popen from rez.utils.platform_ import platform_ +from rez.utils.logging_ import print_debug from rez.shells import UnixShell from rez.rex import EscapedString @@ -105,15 +106,24 @@ def _bind_interactive_rez(self): def setenv(self, key, value): is_implicit = key == 'REZ_USED_IMPLICIT_PACKAGES' + is_path = self._is_pathed_key(key) or self._is_shell_pathed_key(key) - value = self.escape_string( + new_value = self.escape_string( value, is_path=self._is_pathed_key(key), is_shell_path=self._is_shell_pathed_key(key), is_implicit=is_implicit, ) - self._addline('export %s=%s' % (key, value)) + if is_path and value != new_value: + print_debug( + 'Path value changed: {} -> {}'.format(value, new_value) + ) + self._addline( + '# Path value changed: {} -> {}'.format(value, new_value) + ) + + self._addline('export %s=%s' % (key, new_value)) def unsetenv(self, key): self._addline("unset %s" % key)