gst-uninstalled: Try to use short names for env vars on Windows
authorNirbheek Chauhan <nirbheek@centricular.com>
Mon, 15 Apr 2019 10:04:44 +0000 (15:34 +0530)
committerNirbheek Chauhan <nirbheek@centricular.com>
Mon, 15 Apr 2019 10:06:08 +0000 (15:36 +0530)
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.

common.py
gst-uninstalled.py

index a9eca33..5cea742 100644 (file)
--- 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'
index 03b9416..78c5ec1 100755 (executable)
@@ -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