From 42c5e4fe2b21a8f70f62e0153d0098b3d186259f Mon Sep 17 00:00:00 2001 From: Thibault Saunier Date: Thu, 1 Aug 2019 17:13:29 -0700 Subject: wine: Try to get the short paths when generating WINEPATH The size of WINEPATH is limited (1024 [until recently]), we can very easily reach that limit, and even the new one (2048) so try to keep path as small as possible by using the shortPath version of paths. Also assert that we do not reach the new hard limit. And avoid having duplicates in the list of path. [until recently]: https://bugs.winehq.org/show_bug.cgi?id=45810 --- mesonbuild/mesonlib.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'mesonbuild/mesonlib.py') 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(';') -- cgit v1.1