gst-env: spawn a shell to execute commands on windows
authorJordan Petridis <jordan@centricular.com>
Mon, 9 May 2022 09:46:19 +0000 (12:46 +0300)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Sun, 15 May 2022 09:34:58 +0000 (09:34 +0000)
On windows, if you are not using built-in commands you need
to pass the full path of your executable into the subprocess.call/
Popen syscall. ex `c:/foo/bar/baz.exe`. This get's long and is
not ergonomic when you want to run trivial task like:

`gst-env.py ninja` or `gst-inspect0.0` or `gst-validate-launcher`

Instead, on windows, always launch a shell to be able to resolve
the executable from the PATH.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2397>

gst-env.py

index d4a0ef6..51fb913 100755 (executable)
@@ -547,18 +547,26 @@ if __name__ == "__main__":
         gst_version += '-' + os.path.basename(options.wine)
 
     env = get_subprocess_env(options, gst_version)
-    if not args:
-        if os.name == 'nt':
-            shell = get_windows_shell()
-            if shell == 'powershell.exe':
-                args = ['powershell.exe']
-                args += ['-NoLogo', '-NoExit']
+    if os.name == 'nt':
+        shell = get_windows_shell()
+        if shell == 'powershell.exe':
+            new_args = ['powershell.exe']
+            new_args += ['-NoLogo']
+            if not args:
                 prompt = 'function global:prompt {  "[gst-' + gst_version + '"+"] PS " + $PWD + "> "}'
-                args += ['-Command', prompt]
+                new_args += ['-NoExit', '-Command', prompt]
             else:
-                args = [os.environ.get("COMSPEC", r"C:\WINDOWS\system32\cmd.exe")]
-                args += ['/k', 'prompt [gst-{}] $P$G'.format(gst_version)]
+                new_args += ['-NonInteractive', '-Command'] + args
+            args = new_args
         else:
+            new_args = [os.environ.get("COMSPEC", r"C:\WINDOWS\system32\cmd.exe")]
+            if not args:
+                new_args += ['/k', 'prompt [gst-{}] $P$G'.format(gst_version)]
+            else:
+                new_args += ['/c', 'start', '/b', '/wait'] + args
+            args = new_args
+    if not args:
+        if os.name != 'nt':
             args = [os.environ.get("SHELL", os.path.realpath("/bin/sh"))]
         if args[0].endswith('bash') and not str_to_bool(os.environ.get("GST_BUILD_DISABLE_PS1_OVERRIDE", r"FALSE")):
             # Let the GC remove the tmp file