rtpjpegdepay: fix logic error when checking if an EOI is present
[platform/upstream/gstreamer.git] / gst-env.py
index b43598a..a1868c1 100755 (executable)
@@ -14,6 +14,7 @@ import pathlib
 import signal
 from functools import lru_cache
 from pathlib import PurePath, Path
+from sys import exit
 
 from typing import Any
 
@@ -265,7 +266,7 @@ def get_subprocess_env(options, gst_version):
     prepend_env_var(env, "GST_VALIDATE_APPS_DIR", os.path.normpath(
         "%s/subprojects/gst-editing-services/tests/validate" % SCRIPTDIR),
         options.sysroot)
-    env["GST_ENV"] = 'gst-' + gst_version
+    env["GST_ENV"] = gst_version
     env["GST_REGISTRY"] = os.path.normpath(options.builddir + "/registry.dat")
     prepend_env_var(env, "PATH", os.path.normpath(
         "%s/subprojects/gst-devtools/validate/tools" % options.builddir),
@@ -390,10 +391,16 @@ def get_subprocess_env(options, gst_version):
                                 os.path.join(options.builddir, root),
                                 options.sysroot)
 
-    with open(os.path.join(options.gstbuilddir, 'GstPluginsPath.json')) as f:
-        for plugin_path in json.load(f):
-            prepend_env_var(env, 'GST_PLUGIN_PATH', plugin_path,
-                            options.sysroot)
+    # Search for the Plugin paths file either in the build directory root
+    # or check if gstreamer is a subproject of another project
+    for sub_directories in [[], ['subprojects', 'gstreamer']]:
+        plugin_paths = os.path.join(options.builddir, *sub_directories, 'GstPluginsPath.json')
+        if os.path.exists(plugin_paths):
+            with open(plugin_paths) as f:
+                for plugin_path in json.load(f):
+                    prepend_env_var(env, 'GST_PLUGIN_PATH', plugin_path,
+                                    options.sysroot)
+            break
 
     # Sort to iterate in a consistent order (`set`s and `hash`es are randomized)
     for p in sorted(paths):
@@ -423,8 +430,13 @@ def get_subprocess_env(options, gst_version):
             # /usr/lib/site-packages/foo/bar.py , we will not add anything
             # to PYTHONPATH, but the current approach works with pygobject
             # and gst-python at least.
+            py_package = None
             if 'site-packages' in installpath_parts:
-                install_subpath = os.path.join(*installpath_parts[installpath_parts.index('site-packages') + 1:])
+                py_package = 'site-packages'
+            elif 'dist-packages' in installpath_parts:
+                py_package = 'dist-packages'
+            if  py_package:
+                install_subpath = os.path.join(*installpath_parts[installpath_parts.index(py_package) + 1:])
                 if path.endswith(install_subpath):
                     if os.path.commonprefix(["gi/overrides", install_subpath]):
                         overrides_dirs.add(os.path.dirname(path))
@@ -501,9 +513,6 @@ if __name__ == "__main__":
     parser.add_argument("--builddir",
                         default=DEFAULT_BUILDDIR,
                         help="The meson build directory")
-    parser.add_argument("--gstbuilddir",
-                        default=None,
-                        help="The meson GStreamer build directory (defaults to builddir)")
     parser.add_argument("--srcdir",
                         default=SCRIPTDIR,
                         help="The top level source directory")
@@ -526,16 +535,7 @@ if __name__ == "__main__":
         print("GStreamer not built in %s\n\nBuild it and try again" %
               options.builddir)
         exit(1)
-
-    if options.gstbuilddir and not os.path.exists(options.gstbuilddir):
-        print("GStreamer is not built in %s\n\nBuild it and try again" %
-              options.gstbuilddir)
-        exit(1)
-    elif not options.gstbuilddir:
-        options.gstbuilddir = options.builddir
-
     options.builddir = os.path.abspath(options.builddir)
-    options.gstbuilddir = os.path.abspath(options.gstbuilddir)
 
     if not os.path.exists(options.srcdir):
         print("The specified source dir does not exist" %
@@ -553,18 +553,25 @@ 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']
-                prompt = 'function global:prompt {  "[gst-' + gst_version + '"+"] PS " + $PWD + "> "}'
-                args += ['-Command', prompt]
+    if os.name == 'nt':
+        shell = get_windows_shell()
+        if shell in ['powershell.exe', 'pwsh.exe']:
+            new_args = [shell, '-NoLogo']
+            if not args:
+                prompt = 'function global:prompt {  "[' + gst_version + '"+"] PS " + $PWD + "> "}'
+                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 [{}] $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
@@ -573,7 +580,7 @@ if __name__ == "__main__":
             if os.path.exists(bashrc):
                 with open(bashrc, 'r') as src:
                     shutil.copyfileobj(src, tmprc)
-            tmprc.write('\nexport PS1="[gst-%s] $PS1"' % gst_version)
+            tmprc.write('\nexport PS1="[%s] $PS1"' % gst_version)
             tmprc.flush()
             if is_bash_completion_available(options):
                 bash_completions_files = []
@@ -594,7 +601,7 @@ if __name__ == "__main__":
             args.append('--init-command')
             prompt_cmd = '''functions --copy fish_prompt original_fish_prompt
             function fish_prompt
-                echo -n '[gst-{}] '(original_fish_prompt)
+                echo -n '[{}] '(original_fish_prompt)
             end'''.format(gst_version)
             args.append(prompt_cmd)
         elif args[0].endswith('zsh'):
@@ -605,7 +612,7 @@ if __name__ == "__main__":
             if os.path.exists(zshrc):
                 with open(zshrc, 'r') as src:
                     shutil.copyfileobj(src, tmprc)
-            tmprc.write('\nexport PROMPT="[gst-{}] $PROMPT"'.format(gst_version))
+            tmprc.write('\nexport PROMPT="[{}] $PROMPT"'.format(gst_version))
             tmprc.flush()
             env['ZDOTDIR'] = tmpdir.name
     try: