gst-uninstalled: Try to use short names for env vars on Windows

Try even harder to not hit the maximum length limit for env var values
on Windows. Reduces the size by ~1000 characters on my machine.
This commit is contained in:
Nirbheek Chauhan 2019-04-15 15:34:44 +05:30
parent c786776f27
commit d422c2b791
2 changed files with 25 additions and 0 deletions

View file

@ -10,6 +10,27 @@ import subprocess
ROOTDIR = os.path.abspath(os.path.dirname(__file__))
if os.name is 'nt':
import ctypes
from ctypes import wintypes
_GetShortPathNameW = ctypes.windll.kernel32.GetShortPathNameW
_GetShortPathNameW.argtypes = [wintypes.LPCWSTR, wintypes.LPWSTR, wintypes.DWORD]
_GetShortPathNameW.restype = wintypes.DWORD
def win32_get_short_path_name(long_name):
"""
Gets the short path name of a given long path.
http://stackoverflow.com/a/23598461/200291
"""
output_buf_size = 0
while True:
output_buf = ctypes.create_unicode_buffer(output_buf_size)
needed = _GetShortPathNameW(long_name, output_buf, output_buf_size)
if output_buf_size >= needed:
return output_buf.value
else:
output_buf_size = needed
class Colors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'

View file

@ -18,6 +18,7 @@ from distutils.util import strtobool
from common import get_meson
from common import git
from common import win32_get_short_path_name
SCRIPTDIR = os.path.dirname(os.path.realpath(__file__))
PREFIX_DIR = os.path.join(SCRIPTDIR, 'prefix')
@ -44,6 +45,9 @@ def stringify(o):
raise AssertionError('Object {!r} must be a string or a list'.format(o))
def prepend_env_var(env, var, value):
# Try not to exceed maximum length limits for env vars on Windows
if os.name is 'nt':
value = win32_get_short_path_name(value)
env_val = env.get(var, '')
val = os.pathsep + value + os.pathsep
# Don't add the same value twice