2016-08-24 15:10:21 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import argparse
|
2019-06-21 20:40:34 +00:00
|
|
|
import glob
|
2016-11-19 21:01:44 +00:00
|
|
|
import json
|
2016-09-05 14:54:46 +00:00
|
|
|
import os
|
2016-11-19 21:01:44 +00:00
|
|
|
import platform
|
2016-09-05 14:54:46 +00:00
|
|
|
import re
|
2020-01-06 13:22:54 +00:00
|
|
|
import shlex
|
2016-11-02 18:40:54 +00:00
|
|
|
import shutil
|
2016-08-24 15:10:21 +00:00
|
|
|
import subprocess
|
2016-11-02 18:40:54 +00:00
|
|
|
import tempfile
|
2018-10-27 15:59:29 +00:00
|
|
|
import pathlib
|
2019-12-18 20:44:30 +00:00
|
|
|
import signal
|
2020-07-23 11:02:44 +00:00
|
|
|
from functools import lru_cache
|
|
|
|
from pathlib import PurePath, Path
|
2022-11-04 10:14:55 +00:00
|
|
|
from sys import exit
|
2016-08-24 15:10:21 +00:00
|
|
|
|
2021-11-17 02:39:43 +00:00
|
|
|
from typing import Any
|
2018-01-19 20:04:09 +00:00
|
|
|
|
2018-11-12 23:23:14 +00:00
|
|
|
from scripts.common import get_meson
|
|
|
|
from scripts.common import git
|
|
|
|
from scripts.common import win32_get_short_path_name
|
2019-08-03 02:22:16 +00:00
|
|
|
from scripts.common import get_wine_shortpath
|
2016-08-24 15:10:21 +00:00
|
|
|
|
2017-09-15 12:24:54 +00:00
|
|
|
SCRIPTDIR = os.path.dirname(os.path.realpath(__file__))
|
2017-08-21 14:57:29 +00:00
|
|
|
PREFIX_DIR = os.path.join(SCRIPTDIR, 'prefix')
|
2020-04-16 14:08:29 +00:00
|
|
|
# Look for the following build dirs: `build` `_build` `builddir`
|
2018-05-05 15:05:12 +00:00
|
|
|
DEFAULT_BUILDDIR = os.path.join(SCRIPTDIR, 'build')
|
|
|
|
if not os.path.exists(DEFAULT_BUILDDIR):
|
|
|
|
DEFAULT_BUILDDIR = os.path.join(SCRIPTDIR, '_build')
|
2020-04-16 14:08:29 +00:00
|
|
|
if not os.path.exists(DEFAULT_BUILDDIR):
|
|
|
|
DEFAULT_BUILDDIR = os.path.join(SCRIPTDIR, 'builddir')
|
2016-08-24 15:10:21 +00:00
|
|
|
|
2019-09-19 10:45:03 +00:00
|
|
|
TYPELIB_REG = re.compile(r'.*\.typelib$')
|
|
|
|
SHAREDLIB_REG = re.compile(r'\.so|\.dylib|\.dll')
|
|
|
|
|
2019-11-02 15:27:16 +00:00
|
|
|
# libdir is expanded from option of the same name listed in the `meson
|
|
|
|
# introspect --buildoptions` output.
|
|
|
|
GSTPLUGIN_FILEPATH_REG_TEMPLATE = r'.*/{libdir}/gstreamer-1.0/[^/]+$'
|
|
|
|
GSTPLUGIN_FILEPATH_REG = None
|
2016-08-24 15:10:21 +00:00
|
|
|
|
2022-02-16 09:17:23 +00:00
|
|
|
BC_RC = '''
|
2021-02-26 10:13:45 +00:00
|
|
|
BASH_COMPLETION_SCRIPTS="{bash_completions}"
|
|
|
|
BASH_COMPLETION_PATHS="{bash_completions_paths}"
|
|
|
|
for p in $BASH_COMPLETION_PATHS; do
|
|
|
|
for f in $BASH_COMPLETION_SCRIPTS; do
|
|
|
|
[ -f "$p/$f" ] && . "$p/$f"
|
|
|
|
done
|
|
|
|
done
|
|
|
|
'''
|
|
|
|
BASH_COMPLETION_PATHS = [SCRIPTDIR + '/subprojects/gstreamer/data/bash-completion/completions']
|
|
|
|
BASH_COMPLETION_PATHS += [SCRIPTDIR + '/subprojects/gst-devtools/validate/data/bash-completion/completions']
|
|
|
|
|
2021-11-17 02:39:43 +00:00
|
|
|
|
|
|
|
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")
|
|
|
|
|
|
|
|
|
2019-02-14 08:31:52 +00:00
|
|
|
def listify(o):
|
|
|
|
if isinstance(o, str):
|
|
|
|
return [o]
|
|
|
|
if isinstance(o, list):
|
|
|
|
return o
|
|
|
|
raise AssertionError('Object {!r} must be a string or a list'.format(o))
|
|
|
|
|
2022-02-16 09:17:23 +00:00
|
|
|
|
2019-02-14 08:31:52 +00:00
|
|
|
def stringify(o):
|
|
|
|
if isinstance(o, str):
|
|
|
|
return o
|
|
|
|
if isinstance(o, list):
|
|
|
|
if len(o) == 1:
|
|
|
|
return o[0]
|
|
|
|
raise AssertionError('Did not expect object {!r} to have more than one element'.format(o))
|
|
|
|
raise AssertionError('Object {!r} must be a string or a list'.format(o))
|
|
|
|
|
2022-02-16 09:17:23 +00:00
|
|
|
|
2019-06-05 01:04:45 +00:00
|
|
|
def prepend_env_var(env, var, value, sysroot):
|
2021-08-24 08:23:37 +00:00
|
|
|
if var is None:
|
|
|
|
return
|
2019-06-05 01:04:45 +00:00
|
|
|
if value.startswith(sysroot):
|
|
|
|
value = value[len(sysroot):]
|
2019-04-15 10:04:44 +00:00
|
|
|
# Try not to exceed maximum length limits for env vars on Windows
|
2019-11-11 11:41:23 +00:00
|
|
|
if os.name == 'nt':
|
2019-04-15 10:04:44 +00:00
|
|
|
value = win32_get_short_path_name(value)
|
2019-04-15 10:02:36 +00:00
|
|
|
env_val = env.get(var, '')
|
|
|
|
val = os.pathsep + value + os.pathsep
|
|
|
|
# Don't add the same value twice
|
|
|
|
if val in env_val or env_val.startswith(value + os.pathsep):
|
|
|
|
return
|
|
|
|
env[var] = val + env_val
|
2016-08-24 15:10:21 +00:00
|
|
|
env[var] = env[var].replace(os.pathsep + os.pathsep, os.pathsep).strip(os.pathsep)
|
|
|
|
|
2022-02-16 09:17:23 +00:00
|
|
|
|
2020-07-23 10:59:53 +00:00
|
|
|
def get_target_install_filename(target, filename):
|
|
|
|
'''
|
|
|
|
Checks whether this file is one of the files installed by the target
|
|
|
|
'''
|
|
|
|
basename = os.path.basename(filename)
|
|
|
|
for install_filename in listify(target['install_filename']):
|
|
|
|
if install_filename.endswith(basename):
|
|
|
|
return install_filename
|
|
|
|
return None
|
|
|
|
|
2022-02-16 09:17:23 +00:00
|
|
|
|
2020-07-23 11:02:44 +00:00
|
|
|
def get_pkgconfig_variable_from_pcfile(pcfile, varname):
|
|
|
|
variables = {}
|
|
|
|
substre = re.compile('\$\{[^${}]+\}')
|
gst-env: use Path.open() in get_pkgconfig_variable_from_pcfile()
The pcfile argument passed to get_target_install_filename() is
guaranteed to be a Path() object so use the .open() method to open the
file instead of the standard open() function.
This makes it possible to run gst-env.py on older systems with pyhton3.5
where the standard open() function cannot handle Path arguments.
The change fixes errors like the following:
-----------------------------------------------------------------------
$ ninja -C build/ devenv
ninja: Entering directory `build/'
[0/1] Running external command devenv
Traceback (most recent call last):
File "/home/ao2/gst-build/gst-env.py", line 493, in <module>
env = get_subprocess_env(options, gst_version)
File "/home/ao2/gst-build/gst-env.py", line 342, in get_subprocess_env
elif is_gio_module(target, filename, options.builddir):
File "/home/ao2/gst-build/gst-env.py", line 121, in is_gio_module
giomoduledir = PurePath(get_pkgconfig_variable(builddir, 'gio-2.0', 'giomoduledir'))
File "/home/ao2/gst-build/gst-env.py", line 110, in get_pkgconfig_variable
return get_pkgconfig_variable_from_pcfile(pcfile, varname)
File "/home/ao2/gst-build/gst-env.py", line 89, in get_pkgconfig_variable_from_pcfile
with open(pcfile, 'r', encoding='utf-8') as f:
TypeError: invalid file: PosixPath('/home/ao2/gst-build/build/meson-private/gio-2.0.pc')
FAILED: meson-devenv
-----------------------------------------------------------------------
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-build/-/merge_requests/192>
2020-09-24 11:50:09 +00:00
|
|
|
with pcfile.open('r', encoding='utf-8') as f:
|
2020-07-23 11:02:44 +00:00
|
|
|
for line in f:
|
|
|
|
if '=' not in line:
|
|
|
|
continue
|
|
|
|
key, value = line[:-1].split('=', 1)
|
|
|
|
subst = {}
|
|
|
|
for each in substre.findall(value):
|
|
|
|
substkey = each[2:-1]
|
|
|
|
subst[each] = variables.get(substkey, '')
|
|
|
|
for k, v in subst.items():
|
|
|
|
value = value.replace(k, v)
|
|
|
|
variables[key] = value
|
|
|
|
return variables.get(varname, '')
|
|
|
|
|
2022-02-16 09:17:23 +00:00
|
|
|
|
2020-07-23 11:02:44 +00:00
|
|
|
@lru_cache()
|
|
|
|
def get_pkgconfig_variable(builddir, pcname, varname):
|
|
|
|
'''
|
|
|
|
Parsing isn't perfect, but it's good enough.
|
|
|
|
'''
|
|
|
|
pcfile = Path(builddir) / 'meson-private' / (pcname + '.pc')
|
|
|
|
if pcfile.is_file():
|
|
|
|
return get_pkgconfig_variable_from_pcfile(pcfile, varname)
|
|
|
|
return subprocess.check_output(['pkg-config', pcname, '--variable=' + varname],
|
|
|
|
universal_newlines=True, encoding='utf-8')
|
|
|
|
|
|
|
|
|
|
|
|
def is_gio_module(target, filename, builddir):
|
|
|
|
if target['type'] != 'shared module':
|
|
|
|
return False
|
|
|
|
install_filename = get_target_install_filename(target, filename)
|
|
|
|
if not install_filename:
|
|
|
|
return False
|
|
|
|
giomoduledir = PurePath(get_pkgconfig_variable(builddir, 'gio-2.0', 'giomoduledir'))
|
|
|
|
fpath = PurePath(install_filename)
|
|
|
|
if fpath.parent != giomoduledir:
|
|
|
|
return False
|
|
|
|
return True
|
2020-07-23 10:59:53 +00:00
|
|
|
|
2022-02-16 09:17:23 +00:00
|
|
|
|
2019-09-19 10:45:03 +00:00
|
|
|
def is_library_target_and_not_plugin(target, filename):
|
|
|
|
'''
|
|
|
|
Don't add plugins to PATH/LD_LIBRARY_PATH because:
|
|
|
|
1. We don't need to
|
|
|
|
2. It causes us to exceed the PATH length limit on Windows and Wine
|
|
|
|
'''
|
2020-07-23 11:02:44 +00:00
|
|
|
if target['type'] != 'shared library':
|
2019-09-19 10:45:03 +00:00
|
|
|
return False
|
|
|
|
# Check if this output of that target is a shared library
|
|
|
|
if not SHAREDLIB_REG.search(filename):
|
|
|
|
return False
|
|
|
|
# Check if it's installed to the gstreamer plugin location
|
2020-07-23 10:59:53 +00:00
|
|
|
install_filename = get_target_install_filename(target, filename)
|
|
|
|
if not install_filename:
|
2019-09-19 10:45:03 +00:00
|
|
|
return False
|
2019-11-02 15:27:16 +00:00
|
|
|
global GSTPLUGIN_FILEPATH_REG
|
|
|
|
if GSTPLUGIN_FILEPATH_REG is None:
|
|
|
|
GSTPLUGIN_FILEPATH_REG = re.compile(GSTPLUGIN_FILEPATH_REG_TEMPLATE)
|
2019-09-19 10:45:03 +00:00
|
|
|
if GSTPLUGIN_FILEPATH_REG.search(install_filename.replace('\\', '/')):
|
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
2022-02-16 09:17:23 +00:00
|
|
|
|
2019-12-18 22:09:37 +00:00
|
|
|
def is_binary_target_and_in_path(target, filename, bindir):
|
|
|
|
if target['type'] != 'executable':
|
|
|
|
return False
|
|
|
|
# Check if this file installed by this target is installed to bindir
|
2020-07-23 10:59:53 +00:00
|
|
|
install_filename = get_target_install_filename(target, filename)
|
|
|
|
if not install_filename:
|
2019-12-18 22:09:37 +00:00
|
|
|
return False
|
|
|
|
fpath = PurePath(install_filename)
|
|
|
|
if fpath.parent != bindir:
|
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
2016-09-05 14:54:46 +00:00
|
|
|
|
2019-08-03 02:22:16 +00:00
|
|
|
def get_wine_subprocess_env(options, env):
|
|
|
|
with open(os.path.join(options.builddir, 'meson-info', 'intro-buildoptions.json')) as f:
|
|
|
|
buildoptions = json.load(f)
|
|
|
|
|
|
|
|
prefix, = [o for o in buildoptions if o['name'] == 'prefix']
|
|
|
|
path = os.path.normpath(os.path.join(prefix['value'], 'bin'))
|
|
|
|
prepend_env_var(env, "PATH", path, options.sysroot)
|
|
|
|
wine_path = get_wine_shortpath(
|
|
|
|
options.wine.split(' '),
|
|
|
|
[path] + env.get('WINEPATH', '').split(';')
|
|
|
|
)
|
|
|
|
if options.winepath:
|
|
|
|
wine_path += ';' + options.winepath
|
|
|
|
env['WINEPATH'] = wine_path
|
|
|
|
env['WINEDEBUG'] = 'fixme-all'
|
|
|
|
|
|
|
|
return env
|
|
|
|
|
2022-02-16 09:17:23 +00:00
|
|
|
|
2019-06-21 20:40:34 +00:00
|
|
|
def setup_gdb(options):
|
|
|
|
python_paths = set()
|
2020-01-14 23:02:20 +00:00
|
|
|
|
|
|
|
if not shutil.which('gdb'):
|
|
|
|
return python_paths
|
|
|
|
|
2020-06-15 13:36:22 +00:00
|
|
|
bdir = pathlib.Path(options.builddir).resolve()
|
2019-06-21 20:40:34 +00:00
|
|
|
for libpath, gdb_path in [
|
2020-01-14 23:02:20 +00:00
|
|
|
(os.path.join("subprojects", "gstreamer", "gst"),
|
|
|
|
os.path.join("subprojects", "gstreamer", "libs", "gst", "helpers")),
|
|
|
|
(os.path.join("subprojects", "glib", "gobject"), None),
|
|
|
|
(os.path.join("subprojects", "glib", "glib"), None)]:
|
2019-06-21 20:40:34 +00:00
|
|
|
|
|
|
|
if not gdb_path:
|
|
|
|
gdb_path = libpath
|
|
|
|
|
2020-06-15 13:36:22 +00:00
|
|
|
autoload_path = (pathlib.Path(bdir) / 'gdb-auto-load').joinpath(*bdir.parts[1:]) / libpath
|
|
|
|
autoload_path.mkdir(parents=True, exist_ok=True)
|
|
|
|
for gdb_helper in glob.glob(str(bdir / gdb_path / "*-gdb.py")):
|
|
|
|
python_paths.add(str(bdir / gdb_path))
|
2019-06-21 20:40:34 +00:00
|
|
|
python_paths.add(os.path.join(options.srcdir, gdb_path))
|
|
|
|
try:
|
2020-06-15 14:18:30 +00:00
|
|
|
if os.name == 'nt':
|
|
|
|
shutil.copy(gdb_helper, str(autoload_path / os.path.basename(gdb_helper)))
|
|
|
|
else:
|
|
|
|
os.symlink(gdb_helper, str(autoload_path / os.path.basename(gdb_helper)))
|
|
|
|
except (FileExistsError, shutil.SameFileError):
|
2019-06-21 20:40:34 +00:00
|
|
|
pass
|
|
|
|
|
2020-06-15 13:36:22 +00:00
|
|
|
gdbinit_line = 'add-auto-load-scripts-directory {}\n'.format(bdir / 'gdb-auto-load')
|
2019-06-21 20:40:34 +00:00
|
|
|
try:
|
|
|
|
with open(os.path.join(options.srcdir, '.gdbinit'), 'r') as f:
|
|
|
|
if gdbinit_line in f.readlines():
|
|
|
|
return python_paths
|
|
|
|
except FileNotFoundError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
with open(os.path.join(options.srcdir, '.gdbinit'), 'a') as f:
|
|
|
|
f.write(gdbinit_line)
|
|
|
|
|
|
|
|
return python_paths
|
|
|
|
|
2022-02-16 09:17:23 +00:00
|
|
|
|
|
|
|
def is_bash_completion_available(options):
|
|
|
|
return os.path.exists(os.path.join(options.builddir, 'subprojects/gstreamer/data/bash-completion/helpers/gst'))
|
|
|
|
|
2019-08-03 02:22:16 +00:00
|
|
|
|
2018-08-17 14:33:09 +00:00
|
|
|
def get_subprocess_env(options, gst_version):
|
2016-08-24 15:10:21 +00:00
|
|
|
env = os.environ.copy()
|
|
|
|
|
2016-10-20 21:12:53 +00:00
|
|
|
env["CURRENT_GST"] = os.path.normpath(SCRIPTDIR)
|
2019-08-03 02:22:16 +00:00
|
|
|
env["GST_VERSION"] = gst_version
|
2022-02-16 09:17:23 +00:00
|
|
|
prepend_env_var(env, "GST_VALIDATE_SCENARIOS_PATH", os.path.normpath(
|
2021-04-30 21:37:31 +00:00
|
|
|
"%s/subprojects/gst-devtools/validate/data/scenarios" % SCRIPTDIR),
|
|
|
|
options.sysroot)
|
2016-08-24 15:10:21 +00:00
|
|
|
env["GST_VALIDATE_PLUGIN_PATH"] = os.path.normpath(
|
|
|
|
"%s/subprojects/gst-devtools/validate/plugins" % options.builddir)
|
2022-02-16 09:17:23 +00:00
|
|
|
prepend_env_var(env, "GST_VALIDATE_APPS_DIR", os.path.normpath(
|
2021-04-30 21:37:31 +00:00
|
|
|
"%s/subprojects/gst-editing-services/tests/validate" % SCRIPTDIR),
|
|
|
|
options.sysroot)
|
2022-06-14 10:37:13 +00:00
|
|
|
env["GST_ENV"] = gst_version
|
2019-08-03 02:22:16 +00:00
|
|
|
env["GST_REGISTRY"] = os.path.normpath(options.builddir + "/registry.dat")
|
2016-08-24 15:10:21 +00:00
|
|
|
prepend_env_var(env, "PATH", os.path.normpath(
|
2019-06-05 01:04:45 +00:00
|
|
|
"%s/subprojects/gst-devtools/validate/tools" % options.builddir),
|
|
|
|
options.sysroot)
|
2019-08-03 02:22:16 +00:00
|
|
|
|
2022-02-16 09:17:23 +00:00
|
|
|
prepend_env_var(env, "GST_VALIDATE_SCENARIOS_PATH", os.path.normpath(
|
2021-04-30 21:37:31 +00:00
|
|
|
"%s/subprojects/gst-examples/webrtc/check/validate/scenarios" %
|
|
|
|
SCRIPTDIR), options.sysroot)
|
2022-02-16 09:17:23 +00:00
|
|
|
prepend_env_var(env, "GST_VALIDATE_APPS_DIR", os.path.normpath(
|
2021-04-30 21:37:31 +00:00
|
|
|
"%s/subprojects/gst-examples/webrtc/check/validate/apps" %
|
|
|
|
SCRIPTDIR), options.sysroot)
|
|
|
|
|
2019-08-03 02:22:16 +00:00
|
|
|
if options.wine:
|
|
|
|
return get_wine_subprocess_env(options, env)
|
|
|
|
|
2019-06-05 01:04:45 +00:00
|
|
|
prepend_env_var(env, "PATH", os.path.join(SCRIPTDIR, 'meson'),
|
|
|
|
options.sysroot)
|
2019-08-03 02:22:16 +00:00
|
|
|
|
2016-08-24 15:10:21 +00:00
|
|
|
env["GST_PLUGIN_SYSTEM_PATH"] = ""
|
|
|
|
env["GST_PLUGIN_SCANNER"] = os.path.normpath(
|
|
|
|
"%s/subprojects/gstreamer/libs/gst/helpers/gst-plugin-scanner" % options.builddir)
|
|
|
|
env["GST_PTP_HELPER"] = os.path.normpath(
|
ptp-helper: Rewrite in Rust for portability and security
This works on Linux, Android, Windows, macOS, FreeBSD, NetBSD, OpenBSD,
DragonFlyBSD, Solaris and Illumos.
Newly supported compared to the C version is Windows.
Compared to the C version various error paths are handled more correctly
and a couple of memory leaks are fixed. Otherwise it should work identically.
The minimum required Rust version for compiling this is 1.48, i.e. the
version currently in Debian stable. On Windows, Rust 1.54 is needed at
least.
Fixes https://gitlab.freedesktop.org/gstreamer/gstreamer/-/issues/1259
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3889>
2023-02-03 22:55:39 +00:00
|
|
|
"%s/subprojects/gstreamer/libs/gst/helpers/ptp/gst-ptp-helper" % options.builddir)
|
2016-09-05 14:54:46 +00:00
|
|
|
|
2019-11-11 11:41:23 +00:00
|
|
|
if os.name == 'nt':
|
2016-11-19 13:11:55 +00:00
|
|
|
lib_path_envvar = 'PATH'
|
|
|
|
elif platform.system() == 'Darwin':
|
2023-01-10 19:43:30 +00:00
|
|
|
# DYLD_LIBRARY_PATH is stripped when new shells are spawned and can
|
|
|
|
# cause issues with runtime linker resolution, so only set it when
|
|
|
|
# using --only-environment
|
2021-08-24 08:23:37 +00:00
|
|
|
lib_path_envvar = None
|
2023-01-10 19:43:30 +00:00
|
|
|
if options.only_environment:
|
|
|
|
lib_path_envvar = 'DYLD_LIBRARY_PATH'
|
2016-11-19 13:11:55 +00:00
|
|
|
else:
|
|
|
|
lib_path_envvar = 'LD_LIBRARY_PATH'
|
|
|
|
|
2017-03-14 22:31:11 +00:00
|
|
|
prepend_env_var(env, "GST_PLUGIN_PATH", os.path.join(SCRIPTDIR, 'subprojects',
|
2019-06-05 01:04:45 +00:00
|
|
|
'gst-python', 'plugin'),
|
|
|
|
options.sysroot)
|
2017-08-21 14:57:29 +00:00
|
|
|
prepend_env_var(env, "GST_PLUGIN_PATH", os.path.join(PREFIX_DIR, 'lib',
|
2019-06-05 01:04:45 +00:00
|
|
|
'gstreamer-1.0'),
|
|
|
|
options.sysroot)
|
2019-05-16 20:12:05 +00:00
|
|
|
prepend_env_var(env, "GST_PLUGIN_PATH", os.path.join(options.builddir, 'subprojects',
|
2019-06-05 01:04:45 +00:00
|
|
|
'libnice', 'gst'),
|
|
|
|
options.sysroot)
|
|
|
|
prepend_env_var(env, "GST_VALIDATE_SCENARIOS_PATH",
|
|
|
|
os.path.join(PREFIX_DIR, 'share', 'gstreamer-1.0',
|
|
|
|
'validate', 'scenarios'),
|
|
|
|
options.sysroot)
|
2017-08-21 14:57:29 +00:00
|
|
|
prepend_env_var(env, "GI_TYPELIB_PATH", os.path.join(PREFIX_DIR, 'lib',
|
2019-06-05 01:04:45 +00:00
|
|
|
'lib', 'girepository-1.0'),
|
|
|
|
options.sysroot)
|
|
|
|
prepend_env_var(env, "PKG_CONFIG_PATH", os.path.join(PREFIX_DIR, 'lib', 'pkgconfig'),
|
|
|
|
options.sysroot)
|
2017-03-14 22:31:11 +00:00
|
|
|
|
2019-05-11 09:03:18 +00:00
|
|
|
# gst-indent
|
2021-10-05 12:51:08 +00:00
|
|
|
prepend_env_var(env, "PATH", os.path.join(SCRIPTDIR, 'scripts'),
|
2019-06-05 01:04:45 +00:00
|
|
|
options.sysroot)
|
2019-05-11 09:03:18 +00:00
|
|
|
|
2019-11-02 09:44:57 +00:00
|
|
|
# tools: gst-launch-1.0, gst-inspect-1.0
|
|
|
|
prepend_env_var(env, "PATH", os.path.join(options.builddir, 'subprojects',
|
|
|
|
'gstreamer', 'tools'),
|
|
|
|
options.sysroot)
|
2021-12-26 18:01:24 +00:00
|
|
|
# plugin scanner and generator
|
|
|
|
prepend_env_var(env, "PATH", os.path.join(options.builddir, 'subprojects',
|
|
|
|
'gstreamer', 'docs'),
|
|
|
|
options.sysroot)
|
2019-11-02 09:44:57 +00:00
|
|
|
prepend_env_var(env, "PATH", os.path.join(options.builddir, 'subprojects',
|
|
|
|
'gst-plugins-base', 'tools'),
|
|
|
|
options.sysroot)
|
|
|
|
|
2019-04-01 18:25:14 +00:00
|
|
|
# Library and binary search paths
|
2019-06-05 01:04:45 +00:00
|
|
|
prepend_env_var(env, "PATH", os.path.join(PREFIX_DIR, 'bin'),
|
|
|
|
options.sysroot)
|
2019-04-01 18:25:14 +00:00
|
|
|
if lib_path_envvar != 'PATH':
|
2019-06-05 01:04:45 +00:00
|
|
|
prepend_env_var(env, lib_path_envvar, os.path.join(PREFIX_DIR, 'lib'),
|
|
|
|
options.sysroot)
|
2019-07-19 16:00:54 +00:00
|
|
|
prepend_env_var(env, lib_path_envvar, os.path.join(PREFIX_DIR, 'lib64'),
|
|
|
|
options.sysroot)
|
2019-04-01 18:25:14 +00:00
|
|
|
elif 'QMAKE' in os.environ:
|
|
|
|
# There's no RPATH on Windows, so we need to set PATH for the qt5 DLLs
|
2019-06-05 01:04:45 +00:00
|
|
|
prepend_env_var(env, 'PATH', os.path.dirname(os.environ['QMAKE']),
|
|
|
|
options.sysroot)
|
2019-04-01 18:25:14 +00:00
|
|
|
|
2017-12-18 15:55:11 +00:00
|
|
|
meson = get_meson()
|
2018-08-10 21:20:14 +00:00
|
|
|
targets_s = subprocess.check_output(meson + ['introspect', options.builddir, '--targets'])
|
2016-11-19 21:01:44 +00:00
|
|
|
targets = json.loads(targets_s.decode())
|
2016-12-14 20:13:53 +00:00
|
|
|
paths = set()
|
2017-08-22 19:29:58 +00:00
|
|
|
mono_paths = set()
|
2018-11-23 14:42:03 +00:00
|
|
|
srcdir_path = pathlib.Path(options.srcdir)
|
2019-11-02 15:27:16 +00:00
|
|
|
|
|
|
|
build_options_s = subprocess.check_output(meson + ['introspect', options.builddir, '--buildoptions'])
|
|
|
|
build_options = json.loads(build_options_s.decode())
|
|
|
|
libdir, = [o['value'] for o in build_options if o['name'] == 'libdir']
|
2019-12-18 22:09:37 +00:00
|
|
|
libdir = PurePath(libdir)
|
|
|
|
prefix, = [o['value'] for o in build_options if o['name'] == 'prefix']
|
|
|
|
bindir, = [o['value'] for o in build_options if o['name'] == 'bindir']
|
|
|
|
prefix = PurePath(prefix)
|
|
|
|
bindir = prefix / bindir
|
2019-11-02 15:27:16 +00:00
|
|
|
|
|
|
|
global GSTPLUGIN_FILEPATH_REG_TEMPLATE
|
2019-12-18 22:09:37 +00:00
|
|
|
GSTPLUGIN_FILEPATH_REG_TEMPLATE = GSTPLUGIN_FILEPATH_REG_TEMPLATE.format(libdir=libdir.as_posix())
|
2019-11-02 15:27:16 +00:00
|
|
|
|
2016-11-19 21:01:44 +00:00
|
|
|
for target in targets:
|
2019-02-14 08:31:52 +00:00
|
|
|
filenames = listify(target['filename'])
|
2020-07-23 10:35:06 +00:00
|
|
|
if not target['installed']:
|
|
|
|
continue
|
2019-02-14 08:31:52 +00:00
|
|
|
for filename in filenames:
|
|
|
|
root = os.path.dirname(filename)
|
|
|
|
if srcdir_path / "subprojects/gst-devtools/validate/plugins" in (srcdir_path / root).parents:
|
2016-11-19 21:01:44 +00:00
|
|
|
continue
|
2019-02-14 08:31:52 +00:00
|
|
|
if filename.endswith('.dll'):
|
|
|
|
mono_paths.add(os.path.join(options.builddir, root))
|
2019-09-19 10:45:03 +00:00
|
|
|
if TYPELIB_REG.search(filename):
|
2019-02-14 08:31:52 +00:00
|
|
|
prepend_env_var(env, "GI_TYPELIB_PATH",
|
2019-06-05 01:04:45 +00:00
|
|
|
os.path.join(options.builddir, root),
|
|
|
|
options.sysroot)
|
2019-09-19 10:45:03 +00:00
|
|
|
elif is_library_target_and_not_plugin(target, filename):
|
2019-02-14 08:31:52 +00:00
|
|
|
prepend_env_var(env, lib_path_envvar,
|
2019-06-05 01:04:45 +00:00
|
|
|
os.path.join(options.builddir, root),
|
|
|
|
options.sysroot)
|
2019-12-18 22:09:37 +00:00
|
|
|
elif is_binary_target_and_in_path(target, filename, bindir):
|
2019-02-14 08:31:52 +00:00
|
|
|
paths.add(os.path.join(options.builddir, root))
|
2020-07-23 11:02:44 +00:00
|
|
|
elif is_gio_module(target, filename, options.builddir):
|
|
|
|
prepend_env_var(env, 'GIO_EXTRA_MODULES',
|
|
|
|
os.path.join(options.builddir, root),
|
|
|
|
options.sysroot)
|
2016-12-14 20:13:53 +00:00
|
|
|
|
2022-02-17 20:44:30 +00:00
|
|
|
# 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
|
2018-11-11 23:06:04 +00:00
|
|
|
|
2020-07-21 19:07:13 +00:00
|
|
|
# Sort to iterate in a consistent order (`set`s and `hash`es are randomized)
|
|
|
|
for p in sorted(paths):
|
2019-06-05 01:04:45 +00:00
|
|
|
prepend_env_var(env, 'PATH', p, options.sysroot)
|
2016-09-05 14:54:46 +00:00
|
|
|
|
2017-08-22 19:29:58 +00:00
|
|
|
if os.name != 'nt':
|
2020-07-21 19:07:13 +00:00
|
|
|
for p in sorted(mono_paths):
|
2019-06-05 01:04:45 +00:00
|
|
|
prepend_env_var(env, "MONO_PATH", p, options.sysroot)
|
2017-08-22 19:29:58 +00:00
|
|
|
|
2016-12-19 13:10:58 +00:00
|
|
|
presets = set()
|
|
|
|
encoding_targets = set()
|
2019-06-21 20:40:34 +00:00
|
|
|
python_dirs = setup_gdb(options)
|
2021-10-14 20:01:01 +00:00
|
|
|
overrides_dirs = set()
|
2018-08-10 21:20:14 +00:00
|
|
|
if '--installed' in subprocess.check_output(meson + ['introspect', '-h']).decode():
|
|
|
|
installed_s = subprocess.check_output(meson + ['introspect', options.builddir, '--installed'])
|
2016-12-19 13:10:58 +00:00
|
|
|
for path, installpath in json.loads(installed_s.decode()).items():
|
2018-10-27 15:59:29 +00:00
|
|
|
installpath_parts = pathlib.Path(installpath).parts
|
|
|
|
|
|
|
|
# We want to add all python modules to the PYTHONPATH
|
|
|
|
# in a manner consistent with the way they would be imported:
|
|
|
|
# For example if the source path /home/meh/foo/bar.py
|
|
|
|
# is to be installed in /usr/lib/python/site-packages/foo/bar.py,
|
|
|
|
# we want to add /home/meh to the PYTHONPATH.
|
|
|
|
# This will only work for projects where the paths to be installed
|
|
|
|
# mirror the installed directory layout, for example if the path
|
|
|
|
# is /home/meh/baz/bar.py and the install path is
|
|
|
|
# /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.
|
2023-01-27 14:47:22 +00:00
|
|
|
py_package = None
|
2018-10-27 15:59:29 +00:00
|
|
|
if 'site-packages' in installpath_parts:
|
2023-01-27 14:47:22 +00:00
|
|
|
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:])
|
2018-10-27 15:59:29 +00:00
|
|
|
if path.endswith(install_subpath):
|
2021-10-14 20:01:01 +00:00
|
|
|
if os.path.commonprefix(["gi/overrides", install_subpath]):
|
|
|
|
overrides_dirs.add(os.path.dirname(path))
|
|
|
|
else:
|
2022-02-16 09:17:23 +00:00
|
|
|
python_dirs.add(path[:len(install_subpath) * -1])
|
2018-10-27 15:59:29 +00:00
|
|
|
|
2016-12-19 13:10:58 +00:00
|
|
|
if path.endswith('.prs'):
|
|
|
|
presets.add(os.path.dirname(path))
|
|
|
|
elif path.endswith('.gep'):
|
|
|
|
encoding_targets.add(
|
|
|
|
os.path.abspath(os.path.join(os.path.dirname(path), '..')))
|
2017-01-04 11:10:56 +00:00
|
|
|
|
2019-01-04 11:58:37 +00:00
|
|
|
if path.endswith('gstomx.conf'):
|
2019-06-05 01:04:45 +00:00
|
|
|
prepend_env_var(env, 'GST_OMX_CONFIG_DIR', os.path.dirname(path),
|
|
|
|
options.sysroot)
|
2019-01-04 11:58:37 +00:00
|
|
|
|
2020-07-21 19:07:13 +00:00
|
|
|
for p in sorted(presets):
|
2019-06-05 01:04:45 +00:00
|
|
|
prepend_env_var(env, 'GST_PRESET_PATH', p, options.sysroot)
|
2016-12-19 13:10:58 +00:00
|
|
|
|
2020-07-21 19:07:13 +00:00
|
|
|
for t in sorted(encoding_targets):
|
2019-06-05 01:04:45 +00:00
|
|
|
prepend_env_var(env, 'GST_ENCODING_TARGET_PATH', t, options.sysroot)
|
2016-12-19 13:10:58 +00:00
|
|
|
|
2020-06-12 13:29:17 +00:00
|
|
|
# Check if meson has generated -uninstalled pkgconfig files
|
|
|
|
meson_uninstalled = pathlib.Path(options.builddir) / 'meson-uninstalled'
|
|
|
|
if meson_uninstalled.is_dir():
|
|
|
|
prepend_env_var(env, 'PKG_CONFIG_PATH', str(meson_uninstalled), options.sysroot)
|
|
|
|
|
2020-07-21 19:07:13 +00:00
|
|
|
for python_dir in sorted(python_dirs):
|
2019-06-05 01:04:45 +00:00
|
|
|
prepend_env_var(env, 'PYTHONPATH', python_dir, options.sysroot)
|
2018-10-27 15:59:29 +00:00
|
|
|
|
2021-10-14 20:01:01 +00:00
|
|
|
for python_dir in sorted(overrides_dirs):
|
|
|
|
prepend_env_var(env, '_GI_OVERRIDES_PATH', python_dir, options.sysroot)
|
|
|
|
|
2017-01-27 19:54:21 +00:00
|
|
|
mesonpath = os.path.join(SCRIPTDIR, "meson")
|
|
|
|
if os.path.join(mesonpath):
|
|
|
|
# Add meson/ into PYTHONPATH if we are using a local meson
|
2019-06-05 01:04:45 +00:00
|
|
|
prepend_env_var(env, 'PYTHONPATH', mesonpath, options.sysroot)
|
2017-01-27 19:54:21 +00:00
|
|
|
|
2021-10-14 20:01:01 +00:00
|
|
|
# Ensure that gst-python/gi is used first
|
|
|
|
prepend_env_var(env, "PYTHONPATH", os.path.join(SCRIPTDIR, 'subprojects', 'gst-python'),
|
|
|
|
options.sysroot)
|
|
|
|
|
2019-05-25 10:02:37 +00:00
|
|
|
# For devhelp books
|
2019-12-21 19:01:47 +00:00
|
|
|
if 'XDG_DATA_DIRS' not in env or not env['XDG_DATA_DIRS']:
|
2019-05-25 10:02:37 +00:00
|
|
|
# Preserve default paths when empty
|
2019-06-05 01:04:45 +00:00
|
|
|
prepend_env_var(env, 'XDG_DATA_DIRS', '/usr/local/share/:/usr/share/', '')
|
2019-05-25 10:02:37 +00:00
|
|
|
|
2022-02-16 09:17:23 +00:00
|
|
|
prepend_env_var(env, 'XDG_DATA_DIRS', os.path.join(options.builddir,
|
|
|
|
'subprojects',
|
|
|
|
'gst-docs',
|
|
|
|
'GStreamer-doc'),
|
|
|
|
options.sysroot)
|
2019-05-25 10:02:37 +00:00
|
|
|
|
2019-12-21 19:01:47 +00:00
|
|
|
if 'XDG_CONFIG_DIRS' not in env or not env['XDG_CONFIG_DIRS']:
|
|
|
|
# Preserve default paths when empty
|
|
|
|
prepend_env_var(env, 'XDG_CONFIG_DIRS', '/etc/local/xdg:/etc/xdg', '')
|
|
|
|
|
|
|
|
prepend_env_var(env, "XDG_CONFIG_DIRS", os.path.join(PREFIX_DIR, 'etc', 'xdg'),
|
|
|
|
options.sysroot)
|
|
|
|
|
2016-08-24 15:10:21 +00:00
|
|
|
return env
|
|
|
|
|
2022-02-16 09:17:23 +00:00
|
|
|
|
2019-01-24 17:13:08 +00:00
|
|
|
def get_windows_shell():
|
2022-02-16 09:17:23 +00:00
|
|
|
command = ['powershell.exe', '-noprofile', '-executionpolicy', 'bypass', '-file',
|
2020-10-31 02:51:16 +00:00
|
|
|
os.path.join(SCRIPTDIR, 'data', 'misc', 'cmd_or_ps.ps1')]
|
|
|
|
result = subprocess.check_output(command)
|
2019-01-24 17:13:08 +00:00
|
|
|
return result.decode().strip()
|
|
|
|
|
2022-02-16 09:17:23 +00:00
|
|
|
|
2016-08-24 15:10:21 +00:00
|
|
|
if __name__ == "__main__":
|
2020-05-11 10:31:57 +00:00
|
|
|
parser = argparse.ArgumentParser(prog="gst-env")
|
2016-08-24 15:10:21 +00:00
|
|
|
|
|
|
|
parser.add_argument("--builddir",
|
2018-05-05 15:05:12 +00:00
|
|
|
default=DEFAULT_BUILDDIR,
|
2016-08-24 15:10:21 +00:00
|
|
|
help="The meson build directory")
|
2017-04-05 22:25:31 +00:00
|
|
|
parser.add_argument("--srcdir",
|
|
|
|
default=SCRIPTDIR,
|
|
|
|
help="The top level source directory")
|
2019-05-06 20:07:28 +00:00
|
|
|
parser.add_argument("--sysroot",
|
|
|
|
default='',
|
|
|
|
help="The sysroot path used during cross-compilation")
|
2019-08-03 02:22:16 +00:00
|
|
|
parser.add_argument("--wine",
|
|
|
|
default='',
|
|
|
|
help="Build a wine env based on specified wine command")
|
|
|
|
parser.add_argument("--winepath",
|
|
|
|
default='',
|
2019-06-21 20:40:34 +00:00
|
|
|
help="Extra path to set to WINEPATH.")
|
2020-01-06 13:22:54 +00:00
|
|
|
parser.add_argument("--only-environment",
|
|
|
|
action='store_true',
|
|
|
|
default=False,
|
|
|
|
help="Do not start a shell, only print required environment.")
|
2016-09-06 03:00:17 +00:00
|
|
|
options, args = parser.parse_known_args()
|
2016-08-24 15:10:21 +00:00
|
|
|
|
|
|
|
if not os.path.exists(options.builddir):
|
|
|
|
print("GStreamer not built in %s\n\nBuild it and try again" %
|
|
|
|
options.builddir)
|
|
|
|
exit(1)
|
2018-05-05 13:08:00 +00:00
|
|
|
options.builddir = os.path.abspath(options.builddir)
|
2016-08-24 15:10:21 +00:00
|
|
|
|
2017-04-05 22:25:31 +00:00
|
|
|
if not os.path.exists(options.srcdir):
|
|
|
|
print("The specified source dir does not exist" %
|
|
|
|
options.srcdir)
|
|
|
|
exit(1)
|
|
|
|
|
2018-08-17 14:33:09 +00:00
|
|
|
# The following incantation will retrieve the current branch name.
|
2020-03-25 12:43:10 +00:00
|
|
|
try:
|
2022-02-16 09:17:23 +00:00
|
|
|
gst_version = git("rev-parse", "--symbolic-full-name", "--abbrev-ref", "HEAD",
|
|
|
|
repository_path=options.srcdir).strip('\n')
|
2020-03-25 12:43:10 +00:00
|
|
|
except subprocess.CalledProcessError:
|
2022-02-16 09:17:23 +00:00
|
|
|
gst_version = "unknown"
|
2018-08-17 14:33:09 +00:00
|
|
|
|
2019-08-03 02:22:16 +00:00
|
|
|
if options.wine:
|
|
|
|
gst_version += '-' + os.path.basename(options.wine)
|
|
|
|
|
2019-12-22 14:46:25 +00:00
|
|
|
env = get_subprocess_env(options, gst_version)
|
2022-05-09 09:46:19 +00:00
|
|
|
if os.name == 'nt':
|
|
|
|
shell = get_windows_shell()
|
2022-06-02 18:22:03 +00:00
|
|
|
if shell in ['powershell.exe', 'pwsh.exe']:
|
|
|
|
new_args = [shell, '-NoLogo']
|
2022-05-09 09:46:19 +00:00
|
|
|
if not args:
|
2022-06-14 10:37:13 +00:00
|
|
|
prompt = 'function global:prompt { "[' + gst_version + '"+"] PS " + $PWD + "> "}'
|
2022-05-09 09:46:19 +00:00
|
|
|
new_args += ['-NoExit', '-Command', prompt]
|
2019-01-24 17:13:08 +00:00
|
|
|
else:
|
2022-05-09 09:46:19 +00:00
|
|
|
new_args += ['-NonInteractive', '-Command'] + args
|
|
|
|
args = new_args
|
2016-10-17 14:42:07 +00:00
|
|
|
else:
|
2022-05-09 09:46:19 +00:00
|
|
|
new_args = [os.environ.get("COMSPEC", r"C:\WINDOWS\system32\cmd.exe")]
|
|
|
|
if not args:
|
2022-06-14 10:37:13 +00:00
|
|
|
new_args += ['/k', 'prompt [{}] $P$G'.format(gst_version)]
|
2022-05-09 09:46:19 +00:00
|
|
|
else:
|
|
|
|
new_args += ['/c', 'start', '/b', '/wait'] + args
|
|
|
|
args = new_args
|
|
|
|
if not args:
|
|
|
|
if os.name != 'nt':
|
2016-10-17 14:42:07 +00:00
|
|
|
args = [os.environ.get("SHELL", os.path.realpath("/bin/sh"))]
|
2023-01-10 21:17:50 +00:00
|
|
|
prompt_export = f'export PS1="[{gst_version}] $PS1"'
|
2021-11-17 02:39:43 +00:00
|
|
|
if args[0].endswith('bash') and not str_to_bool(os.environ.get("GST_BUILD_DISABLE_PS1_OVERRIDE", r"FALSE")):
|
2019-12-22 14:46:25 +00:00
|
|
|
# Let the GC remove the tmp file
|
2019-07-29 03:22:55 +00:00
|
|
|
tmprc = tempfile.NamedTemporaryFile(mode='w')
|
2016-11-02 18:40:54 +00:00
|
|
|
bashrc = os.path.expanduser('~/.bashrc')
|
|
|
|
if os.path.exists(bashrc):
|
|
|
|
with open(bashrc, 'r') as src:
|
|
|
|
shutil.copyfileobj(src, tmprc)
|
2023-01-10 21:17:50 +00:00
|
|
|
tmprc.write('\n' + prompt_export)
|
2019-07-29 03:22:55 +00:00
|
|
|
tmprc.flush()
|
2021-02-26 10:13:45 +00:00
|
|
|
if is_bash_completion_available(options):
|
|
|
|
bash_completions_files = []
|
|
|
|
for p in BASH_COMPLETION_PATHS:
|
|
|
|
if os.path.exists(p):
|
2022-02-16 09:17:23 +00:00
|
|
|
bash_completions_files += os.listdir(path=p)
|
2021-02-26 10:13:45 +00:00
|
|
|
bc_rc = BC_RC.format(bash_completions=' '.join(bash_completions_files), bash_completions_paths=' '.join(BASH_COMPLETION_PATHS))
|
|
|
|
tmprc.write(bc_rc)
|
|
|
|
tmprc.flush()
|
2019-07-29 03:22:55 +00:00
|
|
|
args.append("--rcfile")
|
|
|
|
args.append(tmprc.name)
|
2019-12-22 14:46:25 +00:00
|
|
|
elif args[0].endswith('fish'):
|
2023-01-10 21:17:50 +00:00
|
|
|
prompt_export = None # FIXME
|
2019-12-18 20:44:30 +00:00
|
|
|
# Ignore SIGINT while using fish as the shell to make it behave
|
|
|
|
# like other shells such as bash and zsh.
|
|
|
|
# See: https://gitlab.freedesktop.org/gstreamer/gst-build/issues/18
|
|
|
|
signal.signal(signal.SIGINT, lambda x, y: True)
|
2019-12-18 21:09:01 +00:00
|
|
|
# Set the prompt
|
|
|
|
args.append('--init-command')
|
|
|
|
prompt_cmd = '''functions --copy fish_prompt original_fish_prompt
|
|
|
|
function fish_prompt
|
2022-06-14 10:37:13 +00:00
|
|
|
echo -n '[{}] '(original_fish_prompt)
|
2019-12-18 21:09:01 +00:00
|
|
|
end'''.format(gst_version)
|
|
|
|
args.append(prompt_cmd)
|
2019-12-22 14:46:25 +00:00
|
|
|
elif args[0].endswith('zsh'):
|
2023-01-10 21:17:50 +00:00
|
|
|
prompt_export = f'export PROMPT="[{gst_version}] $PROMPT"'
|
2019-12-22 14:46:25 +00:00
|
|
|
tmpdir = tempfile.TemporaryDirectory()
|
|
|
|
# Let the GC remove the tmp file
|
|
|
|
tmprc = open(os.path.join(tmpdir.name, '.zshrc'), 'w')
|
|
|
|
zshrc = os.path.expanduser('~/.zshrc')
|
|
|
|
if os.path.exists(zshrc):
|
|
|
|
with open(zshrc, 'r') as src:
|
|
|
|
shutil.copyfileobj(src, tmprc)
|
2023-01-10 21:17:50 +00:00
|
|
|
tmprc.write('\n' + prompt_export)
|
2019-12-22 14:46:25 +00:00
|
|
|
tmprc.flush()
|
|
|
|
env['ZDOTDIR'] = tmpdir.name
|
2016-08-24 15:10:21 +00:00
|
|
|
try:
|
2020-01-06 13:22:54 +00:00
|
|
|
if options.only_environment:
|
|
|
|
for name, value in env.items():
|
|
|
|
print('{}={}'.format(name, shlex.quote(value)))
|
|
|
|
print('export {}'.format(name))
|
2023-01-10 21:17:50 +00:00
|
|
|
if prompt_export:
|
|
|
|
print(prompt_export)
|
2020-01-06 13:22:54 +00:00
|
|
|
else:
|
2021-10-08 14:54:22 +00:00
|
|
|
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)
|
2020-01-06 13:22:54 +00:00
|
|
|
exit(subprocess.call(args, close_fds=False, env=env))
|
|
|
|
|
2016-08-24 15:10:21 +00:00
|
|
|
except subprocess.CalledProcessError as e:
|
|
|
|
exit(e.returncode)
|