summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNirbheek Chauhan <nirbheek@centricular.com>2020-01-15 00:14:05 +0530
committerNirbheek Chauhan <nirbheek@centricular.com>2020-01-15 00:14:05 +0530
commit3b32cc802bd92fe04f6443f3d065d23a7f497265 (patch)
tree38c19026801c1a1c9a4c5fcc32aa08307327f733
parent4e41acb0224d851f2fc4610d7c8a84c5d6c88a9e (diff)
downloadmeson-fix-windowsapps-msys.tar.gz
find_program: Always use USERPROFILE instead of HOMEfix-windowsapps-msys
On MSYS2 and MSYS, Python reads HOME instead of USERPROFILE, which gets the path wrong. Serves me right for not writing a test!!
-rw-r--r--mesonbuild/dependencies/base.py5
-rwxr-xr-xrun_unittests.py8
2 files changed, 12 insertions, 1 deletions
diff --git a/mesonbuild/dependencies/base.py b/mesonbuild/dependencies/base.py
index d7fa53206..d2d115e63 100644
--- a/mesonbuild/dependencies/base.py
+++ b/mesonbuild/dependencies/base.py
@@ -1817,10 +1817,13 @@ class ExternalProgram:
@staticmethod
@functools.lru_cache(maxsize=None)
def _windows_sanitize_path(path: str) -> str:
+ # Ensure that we use USERPROFILE even when inside MSYS, MSYS2, Cygwin, etc.
+ if 'USERPROFILE' not in os.environ:
+ return path
# Ignore executables in the WindowsApps directory which are
# zero-sized wrappers that magically open the Windows Store to
# install the application.
- appstore_dir = Path.home() / 'AppData' / 'Local' / 'Microsoft' / 'WindowsApps'
+ appstore_dir = Path(os.environ['USERPROFILE']) / 'AppData' / 'Local' / 'Microsoft' / 'WindowsApps'
paths = []
for each in path.split(os.pathsep):
if Path(each) != appstore_dir:
diff --git a/run_unittests.py b/run_unittests.py
index 898f05e54..bd7266aba 100755
--- a/run_unittests.py
+++ b/run_unittests.py
@@ -4542,6 +4542,14 @@ class WindowsTests(BasePlatformTests):
self.assertTrue(prog.found(), msg='test-script-ext.py not found in PATH')
self.assertPathEqual(prog.get_command()[0], python_command[0])
self.assertPathBasenameEqual(prog.get_path(), 'test-script-ext.py')
+ # Ensure that WindowsApps gets removed from PATH
+ path = os.environ['PATH']
+ if 'WindowsApps' not in path:
+ username = os.environ['USERNAME']
+ appstore_dir = r'C:\Users\{}\AppData\Local\Microsoft\WindowsApps'.format(username)
+ path = os.pathsep + appstore_dir
+ path = ExternalProgram._windows_sanitize_path(path)
+ self.assertNotIn('WindowsApps', path)
def test_ignore_libs(self):
'''