aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/mesonlib.py
diff options
context:
space:
mode:
authorNirbheek Chauhan <nirbheek@centricular.com>2019-08-27 23:38:05 +0530
committerGitHub <noreply@github.com>2019-08-27 23:38:05 +0530
commit83c010a17aafe59f77f321982ea6790655b97075 (patch)
treebf7df8f862e44606d81201f3e1c44d100746807d /mesonbuild/mesonlib.py
parentfe645a0a9e2da230d2c500af1f5b2db5da1e364d (diff)
parent42c5e4fe2b21a8f70f62e0153d0098b3d186259f (diff)
downloadmeson-83c010a17aafe59f77f321982ea6790655b97075.zip
meson-83c010a17aafe59f77f321982ea6790655b97075.tar.gz
meson-83c010a17aafe59f77f321982ea6790655b97075.tar.bz2
Merge pull request #5756 from thiblahute/wine_shortpaths
wine: Try to get the short paths when generating WINEPATH
Diffstat (limited to 'mesonbuild/mesonlib.py')
-rw-r--r--mesonbuild/mesonlib.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/mesonbuild/mesonlib.py b/mesonbuild/mesonlib.py
index bf87f0f..1333027 100644
--- a/mesonbuild/mesonlib.py
+++ b/mesonbuild/mesonlib.py
@@ -22,6 +22,7 @@ import collections
from enum import Enum
from functools import lru_cache
import typing
+import uuid
from mesonbuild import mlog
@@ -1375,3 +1376,36 @@ try:
super().__init__(*args, **kwargs)
except ImportError:
ProgressBar = ProgressBarFallback
+
+
+def get_wine_shortpath(winecmd, wine_paths):
+
+ """ Get A short version of @wine_paths to avoid
+ reaching WINEPATH number of char limit.
+ """
+
+ seen = set()
+ wine_paths = [p for p in wine_paths if not (p in seen or seen.add(p))]
+
+ getShortPathScript = '%s.bat' % str(uuid.uuid4()).lower()[:5]
+ with open(getShortPathScript, mode='w') as f:
+ f.write("@ECHO OFF\nfor %%x in (%*) do (\n echo|set /p=;%~sx\n)\n")
+ f.flush()
+ try:
+ with open(os.devnull, 'w') as stderr:
+ wine_path = subprocess.check_output(
+ winecmd +
+ ['cmd', '/C', getShortPathScript] + wine_paths,
+ stderr=stderr).decode('utf-8')
+ except subprocess.CalledProcessError as e:
+ print("Could not get short paths: %s" % e)
+ wine_path = ';'.join(wine_paths)
+ finally:
+ os.remove(getShortPathScript)
+ if len(wine_path) > 2048:
+ raise MesonException(
+ 'WINEPATH size {} > 2048'
+ ' this will cause random failure.'.format(
+ len(wine_path)))
+
+ return wine_path.strip(';')