diff --git a/common.py b/common.py index a9eca335b1..5cea742027 100644 --- a/common.py +++ b/common.py @@ -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' diff --git a/gst-uninstalled.py b/gst-uninstalled.py index 03b9416f96..78c5ec1188 100755 --- a/gst-uninstalled.py +++ b/gst-uninstalled.py @@ -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