Merge "spec: Fix to have valid release version when building each plugin" into tizen_...
[platform/upstream/gstreamer.git] / gst-env.py
index 42907fa..ab74730 100755 (executable)
@@ -18,8 +18,7 @@ import signal
 from functools import lru_cache
 from pathlib import PurePath, Path
 
-from distutils.sysconfig import get_python_lib
-from distutils.util import strtobool
+from typing import Any
 
 from scripts.common import get_meson
 from scripts.common import git
@@ -55,6 +54,16 @@ done
 BASH_COMPLETION_PATHS = [SCRIPTDIR + '/subprojects/gstreamer/data/bash-completion/completions']
 BASH_COMPLETION_PATHS += [SCRIPTDIR + '/subprojects/gst-devtools/validate/data/bash-completion/completions']
 
+
+def str_to_bool(value: Any) -> bool:
+    """Return whether the provided string (or any value really) represents true. Otherwise false.
+    Just like plugin server stringToBoolean.
+    """
+    if not value:
+        return False
+    return str(value).lower() in ("y", "yes", "t", "true", "on", "1")
+
+
 def listify(o):
     if isinstance(o, str):
         return [o]
@@ -72,6 +81,8 @@ def stringify(o):
     raise AssertionError('Object {!r} must be a string or a list'.format(o))
 
 def prepend_env_var(env, var, value, sysroot):
+    if var is None:
+        return
     if value.startswith(sysroot):
         value = value[len(sysroot):]
     # Try not to exceed maximum length limits for env vars on Windows
@@ -239,18 +250,27 @@ def get_subprocess_env(options, gst_version):
 
     env["CURRENT_GST"] = os.path.normpath(SCRIPTDIR)
     env["GST_VERSION"] = gst_version
-    env["GST_VALIDATE_SCENARIOS_PATH"] = os.path.normpath(
-        "%s/subprojects/gst-devtools/validate/data/scenarios" % SCRIPTDIR)
+    prepend_env_var (env, "GST_VALIDATE_SCENARIOS_PATH", os.path.normpath(
+        "%s/subprojects/gst-devtools/validate/data/scenarios" % SCRIPTDIR),
+        options.sysroot)
     env["GST_VALIDATE_PLUGIN_PATH"] = os.path.normpath(
         "%s/subprojects/gst-devtools/validate/plugins" % options.builddir)
-    env["GST_VALIDATE_APPS_DIR"] = os.path.normpath(
-        "%s/subprojects/gst-editing-services/tests/validate" % SCRIPTDIR)
+    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_REGISTRY"] = os.path.normpath(options.builddir + "/registry.dat")
     prepend_env_var(env, "PATH", os.path.normpath(
         "%s/subprojects/gst-devtools/validate/tools" % options.builddir),
         options.sysroot)
 
+    prepend_env_var (env, "GST_VALIDATE_SCENARIOS_PATH", os.path.normpath(
+        "%s/subprojects/gst-examples/webrtc/check/validate/scenarios" %
+        SCRIPTDIR), options.sysroot)
+    prepend_env_var (env, "GST_VALIDATE_APPS_DIR", os.path.normpath(
+        "%s/subprojects/gst-examples/webrtc/check/validate/apps" %
+        SCRIPTDIR), options.sysroot)
+
     if options.wine:
         return get_wine_subprocess_env(options, env)
 
@@ -266,7 +286,8 @@ def get_subprocess_env(options, gst_version):
     if os.name == 'nt':
         lib_path_envvar = 'PATH'
     elif platform.system() == 'Darwin':
-        lib_path_envvar = 'DYLD_LIBRARY_PATH'
+        # RPATH is sufficient on macOS, and DYLD_LIBRARY_PATH can cause issues with dynamic linker path priority
+        lib_path_envvar = None
     else:
         lib_path_envvar = 'LD_LIBRARY_PATH'
 
@@ -290,13 +311,17 @@ def get_subprocess_env(options, gst_version):
                     options.sysroot)
 
     # gst-indent
-    prepend_env_var(env, "PATH", os.path.join(SCRIPTDIR, 'gstreamer', 'tools'),
+    prepend_env_var(env, "PATH", os.path.join(SCRIPTDIR, 'scripts'),
                     options.sysroot)
 
     # tools: gst-launch-1.0, gst-inspect-1.0
     prepend_env_var(env, "PATH", os.path.join(options.builddir, 'subprojects',
                                               'gstreamer', 'tools'),
                     options.sysroot)
+    # plugin scanner and generator
+    prepend_env_var(env, "PATH", os.path.join(options.builddir, 'subprojects',
+                                              'gstreamer', 'docs'),
+                    options.sysroot)
     prepend_env_var(env, "PATH", os.path.join(options.builddir, 'subprojects',
                                               'gst-plugins-base', 'tools'),
                     options.sysroot)
@@ -358,7 +383,7 @@ def get_subprocess_env(options, gst_version):
                                 os.path.join(options.builddir, root),
                                 options.sysroot)
 
-    with open(os.path.join(options.builddir, 'GstPluginsPath.json')) as f:
+    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)
@@ -374,6 +399,7 @@ def get_subprocess_env(options, gst_version):
     presets = set()
     encoding_targets = set()
     python_dirs = setup_gdb(options)
+    overrides_dirs = set()
     if '--installed' in subprocess.check_output(meson + ['introspect', '-h']).decode():
         installed_s = subprocess.check_output(meson + ['introspect', options.builddir, '--installed'])
         for path, installpath in json.loads(installed_s.decode()).items():
@@ -394,7 +420,10 @@ def get_subprocess_env(options, gst_version):
             if 'site-packages' in installpath_parts:
                 install_subpath = os.path.join(*installpath_parts[installpath_parts.index('site-packages') + 1:])
                 if path.endswith(install_subpath):
-                    python_dirs.add(path[:len (install_subpath) * -1])
+                    if os.path.commonprefix(["gi/overrides", install_subpath]):
+                        overrides_dirs.add(os.path.dirname(path))
+                    else:
+                        python_dirs.add(path[:len (install_subpath) * -1])
 
             if path.endswith('.prs'):
                 presets.add(os.path.dirname(path))
@@ -420,11 +449,18 @@ def get_subprocess_env(options, gst_version):
     for python_dir in sorted(python_dirs):
         prepend_env_var(env, 'PYTHONPATH', python_dir, options.sysroot)
 
+    for python_dir in sorted(overrides_dirs):
+        prepend_env_var(env, '_GI_OVERRIDES_PATH', python_dir, options.sysroot)
+
     mesonpath = os.path.join(SCRIPTDIR, "meson")
     if os.path.join(mesonpath):
         # Add meson/ into PYTHONPATH if we are using a local meson
         prepend_env_var(env, 'PYTHONPATH', mesonpath, options.sysroot)
 
+    # Ensure that gst-python/gi is used first
+    prepend_env_var(env, "PYTHONPATH", os.path.join(SCRIPTDIR, 'subprojects', 'gst-python'),
+                    options.sysroot)
+
     # For devhelp books
     if 'XDG_DATA_DIRS' not in env or not env['XDG_DATA_DIRS']:
         # Preserve default paths when empty
@@ -446,8 +482,9 @@ def get_subprocess_env(options, gst_version):
     return env
 
 def get_windows_shell():
-    command = ['powershell.exe' ,'-noprofile', '-executionpolicy', 'bypass', '-file', 'cmd_or_ps.ps1']
-    result = subprocess.check_output(command, cwd=SCRIPTDIR)
+    command = ['powershell.exe' ,'-noprofile', '-executionpolicy', 'bypass', '-file',
+        os.path.join(SCRIPTDIR, 'data', 'misc', 'cmd_or_ps.ps1')]
+    result = subprocess.check_output(command)
     return result.decode().strip()
 
 if __name__ == "__main__":
@@ -456,6 +493,9 @@ 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")
@@ -478,7 +518,16 @@ 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" %
@@ -509,7 +558,7 @@ if __name__ == "__main__":
                 args += ['/k', 'prompt [gst-{}] $P$G'.format(gst_version)]
         else:
             args = [os.environ.get("SHELL", os.path.realpath("/bin/sh"))]
-        if args[0].endswith('bash') and not strtobool(os.environ.get("GST_BUILD_DISABLE_PS1_OVERRIDE", r"FALSE")):
+        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
             tmprc = tempfile.NamedTemporaryFile(mode='w')
             bashrc = os.path.expanduser('~/.bashrc')
@@ -557,6 +606,10 @@ if __name__ == "__main__":
                 print('{}={}'.format(name, shlex.quote(value)))
                 print('export {}'.format(name))
         else:
+            if os.environ.get("CI_PROJECT_NAME"):
+                print("Ignoring SIGINT when running on the CI,"
+                      " as we get spurious sigint in there for some reason.")
+                signal.signal(signal.SIGINT, signal.SIG_IGN)
             exit(subprocess.call(args, close_fds=False, env=env))
 
     except subprocess.CalledProcessError as e: