AcademySoftwareFoundation / rez

An integrated package configuration, build and deployment system for software
https://rez.readthedocs.io
Apache License 2.0
921 stars 329 forks source link

REZ_USED_IMPLICIT_PACKAGES tilde expansion on windows #1717

Closed cfxegbert closed 3 weeks ago

cfxegbert commented 3 months ago

On Windows the first tilde on the REZ_USED_IMPLICIT_PACKAGES is being expanded to %HOMEDRIVE%%HOMEPATH%. This is using the default config which under rez-3.x is using PowerShell as the default shell. I know Microsoft is changing the behavior of ~ in PowerShell.

Environment

To Reproduce

  1. rez-env
  2. Get-ChildItem -Path Env:\REZ_USED_IMPLICIT_PACKAGES

Expected behavior

REZ_USED_IMPLICIT_PACKAGES="~platform==windows ~arch==AMD64 ~os=windows-10.0.19044.SP0"

Actual behavior

REZ_USED_IMPLICIT_PACKAGES="C:\Users\platform==windows ~arch==AMD64 ~os==windows-10.0.19044.SP0"

cfxegbert commented 2 months ago

It ends up this is how os.path.expanduser works on windows. On unix if there is a string that is not a path separator after ~ it check for the existence of the user, on windows if the user isn't the current user it just blindly changes ~ to 'USERPROFILE'.

Looks like I can fix this by changing https://github.com/AcademySoftwareFoundation/rez/blob/main/src/rez/resolved_context.py#L1982 to

executor.setenv("REZ_USED_IMPLICIT_PACKAGES", EscapedString(implicit_str, is_literal=True))

Trying to figure out if I should use EscapedString on all the REZ_USED variables

JeanChristopheMorinPerso commented 2 months ago

It could make sense yes.