2016-08-24 15:10:21 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import argparse
|
2018-07-23 15:11:03 +00:00
|
|
|
import contextlib
|
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
|
|
|
|
import site
|
2016-11-02 18:40:54 +00:00
|
|
|
import shutil
|
2016-08-24 15:10:21 +00:00
|
|
|
import subprocess
|
2016-11-19 13:18:33 +00:00
|
|
|
import sys
|
2016-11-02 18:40:54 +00:00
|
|
|
import tempfile
|
2018-10-27 15:59:29 +00:00
|
|
|
import pathlib
|
2016-08-24 15:10:21 +00:00
|
|
|
|
2018-01-19 20:04:09 +00:00
|
|
|
from distutils.sysconfig import get_python_lib
|
|
|
|
|
2016-11-19 21:01:44 +00:00
|
|
|
from common import get_meson
|
2018-08-17 14:33:09 +00:00
|
|
|
from common import git
|
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')
|
2018-05-05 15:05:12 +00:00
|
|
|
# Use '_build' as the builddir instead of 'build'
|
|
|
|
DEFAULT_BUILDDIR = os.path.join(SCRIPTDIR, 'build')
|
|
|
|
if not os.path.exists(DEFAULT_BUILDDIR):
|
|
|
|
DEFAULT_BUILDDIR = os.path.join(SCRIPTDIR, '_build')
|
2016-08-24 15:10:21 +00:00
|
|
|
|
|
|
|
|
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))
|
|
|
|
|
|
|
|
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))
|
|
|
|
|
2016-08-24 15:10:21 +00:00
|
|
|
def prepend_env_var(env, var, value):
|
|
|
|
env[var] = os.pathsep + value + os.pathsep + env.get(var, "")
|
|
|
|
env[var] = env[var].replace(os.pathsep + os.pathsep, os.pathsep).strip(os.pathsep)
|
|
|
|
|
2016-09-05 14:54:46 +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)
|
2016-08-24 15:10:21 +00:00
|
|
|
env["GST_VALIDATE_SCENARIOS_PATH"] = os.path.normpath(
|
|
|
|
"%s/subprojects/gst-devtools/validate/data/scenarios" % SCRIPTDIR)
|
|
|
|
env["GST_VALIDATE_PLUGIN_PATH"] = os.path.normpath(
|
|
|
|
"%s/subprojects/gst-devtools/validate/plugins" % options.builddir)
|
2016-09-05 17:47:50 +00:00
|
|
|
env["GST_VALIDATE_APPS_DIR"] = os.path.normpath(
|
|
|
|
"%s/subprojects/gst-editing-services/tests/validate" % SCRIPTDIR)
|
2016-08-24 15:10:21 +00:00
|
|
|
prepend_env_var(env, "PATH", os.path.normpath(
|
|
|
|
"%s/subprojects/gst-devtools/validate/tools" % options.builddir))
|
2016-10-10 23:14:50 +00:00
|
|
|
prepend_env_var(env, "PATH", os.path.join(SCRIPTDIR, 'meson'))
|
2018-08-17 14:33:09 +00:00
|
|
|
env["GST_VERSION"] = gst_version
|
|
|
|
env["GST_ENV"] = 'gst-' + gst_version
|
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(
|
|
|
|
"%s/subprojects/gstreamer/libs/gst/helpers/gst-ptp-helper" % options.builddir)
|
|
|
|
env["GST_REGISTRY"] = os.path.normpath(options.builddir + "/registry.dat")
|
2016-09-05 14:54:46 +00:00
|
|
|
|
2016-11-19 21:01:44 +00:00
|
|
|
sharedlib_reg = re.compile(r'\.so|\.dylib|\.dll')
|
2016-09-05 14:54:46 +00:00
|
|
|
typelib_reg = re.compile(r'.*\.typelib$')
|
2017-05-01 20:17:12 +00:00
|
|
|
pluginpath_reg = re.compile(r'lib.*' + re.escape(os.path.normpath('/gstreamer-1.0/')))
|
2016-11-19 13:11:55 +00:00
|
|
|
|
|
|
|
if os.name is 'nt':
|
|
|
|
lib_path_envvar = 'PATH'
|
|
|
|
elif platform.system() == 'Darwin':
|
|
|
|
lib_path_envvar = 'DYLD_LIBRARY_PATH'
|
|
|
|
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',
|
|
|
|
'gst-python', 'plugin'))
|
2017-08-21 14:57:29 +00:00
|
|
|
prepend_env_var(env, "GST_PLUGIN_PATH", os.path.join(PREFIX_DIR, 'lib',
|
|
|
|
'gstreamer-1.0'))
|
|
|
|
prepend_env_var(env, "PATH", os.path.join(PREFIX_DIR, 'bin'))
|
|
|
|
prepend_env_var(env, lib_path_envvar, os.path.join(PREFIX_DIR, 'lib'))
|
|
|
|
prepend_env_var(env, "GST_VALIDATE_SCENARIOS_PATH", os.path.join(
|
|
|
|
PREFIX_DIR, 'share', 'gstreamer-1.0', 'validate', 'scenarios'))
|
|
|
|
prepend_env_var(env, "GI_TYPELIB_PATH", os.path.join(PREFIX_DIR, 'lib',
|
|
|
|
'lib', 'girepository-1.0'))
|
2018-06-06 11:55:20 +00:00
|
|
|
prepend_env_var(env, "PKG_CONFIG_PATH", os.path.join(PREFIX_DIR, 'lib', 'pkgconfig'))
|
2017-03-14 22:31:11 +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)
|
2016-11-19 21:01:44 +00:00
|
|
|
for target in targets:
|
2019-02-14 08:31:52 +00:00
|
|
|
filenames = listify(target['filename'])
|
|
|
|
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))
|
|
|
|
if typelib_reg.search(filename):
|
|
|
|
prepend_env_var(env, "GI_TYPELIB_PATH",
|
|
|
|
os.path.join(options.builddir, root))
|
|
|
|
elif sharedlib_reg.search(filename):
|
|
|
|
if not target['type'].startswith('shared'):
|
|
|
|
continue
|
|
|
|
if target['installed']:
|
|
|
|
if pluginpath_reg.search(os.path.normpath(stringify(target['install_filename']))):
|
|
|
|
prepend_env_var(env, "GST_PLUGIN_PATH", os.path.join(options.builddir, root))
|
|
|
|
continue
|
|
|
|
|
|
|
|
prepend_env_var(env, lib_path_envvar,
|
|
|
|
os.path.join(options.builddir, root))
|
|
|
|
elif target['type'] == 'executable' and target['installed']:
|
|
|
|
paths.add(os.path.join(options.builddir, root))
|
2016-12-14 20:13:53 +00:00
|
|
|
|
|
|
|
for p in paths:
|
|
|
|
prepend_env_var(env, 'PATH', p)
|
2016-09-05 14:54:46 +00:00
|
|
|
|
2017-08-22 19:29:58 +00:00
|
|
|
if os.name != 'nt':
|
|
|
|
for p in mono_paths:
|
|
|
|
prepend_env_var(env, "MONO_PATH", p)
|
|
|
|
|
2016-12-19 13:10:58 +00:00
|
|
|
presets = set()
|
|
|
|
encoding_targets = set()
|
2017-01-04 11:10:56 +00:00
|
|
|
pkg_dirs = set()
|
2018-11-08 14:52:03 +00:00
|
|
|
python_dirs = set(["%s/subprojects/gstreamer/libs/gst/helpers/" % options.srcdir])
|
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
|
|
|
|
path_parts = pathlib.Path(path).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.
|
|
|
|
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])
|
|
|
|
|
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
|
|
|
elif path.endswith('.pc'):
|
|
|
|
# Is there a -uninstalled pc file for this file?
|
|
|
|
uninstalled = "{0}-uninstalled.pc".format(path[:-3])
|
|
|
|
if os.path.exists(uninstalled):
|
|
|
|
pkg_dirs.add(os.path.dirname(path))
|
|
|
|
|
2019-01-04 11:58:37 +00:00
|
|
|
if path.endswith('gstomx.conf'):
|
|
|
|
prepend_env_var(env, 'GST_OMX_CONFIG_DIR', os.path.dirname(path))
|
|
|
|
|
2016-12-19 13:10:58 +00:00
|
|
|
for p in presets:
|
|
|
|
prepend_env_var(env, 'GST_PRESET_PATH', p)
|
|
|
|
|
|
|
|
for t in encoding_targets:
|
|
|
|
prepend_env_var(env, 'GST_ENCODING_TARGET_PATH', t)
|
|
|
|
|
2017-01-04 11:10:56 +00:00
|
|
|
for pkg_dir in pkg_dirs:
|
|
|
|
prepend_env_var(env, "PKG_CONFIG_PATH", pkg_dir)
|
2017-03-28 17:32:24 +00:00
|
|
|
prepend_env_var(env, "PKG_CONFIG_PATH", os.path.join(options.builddir,
|
|
|
|
'subprojects',
|
|
|
|
'gst-plugins-good',
|
|
|
|
'pkgconfig'))
|
2017-01-04 11:10:56 +00:00
|
|
|
|
2018-10-27 15:59:29 +00:00
|
|
|
for python_dir in python_dirs:
|
|
|
|
prepend_env_var(env, 'PYTHONPATH', python_dir)
|
|
|
|
|
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
|
|
|
|
prepend_env_var(env, 'PYTHONPATH', mesonpath)
|
|
|
|
|
2016-08-24 15:10:21 +00:00
|
|
|
return env
|
|
|
|
|
2018-01-19 20:04:09 +00:00
|
|
|
# https://stackoverflow.com/questions/1871549/determine-if-python-is-running-inside-virtualenv
|
|
|
|
def in_venv():
|
|
|
|
return (hasattr(sys, 'real_prefix') or
|
|
|
|
(hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix))
|
2016-08-24 15:10:21 +00:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
parser = argparse.ArgumentParser(prog="gstreamer-uninstalled")
|
|
|
|
|
|
|
|
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")
|
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.
|
2018-08-31 11:31:24 +00:00
|
|
|
gst_version = git("rev-parse", "--symbolic-full-name", "--abbrev-ref", "HEAD",
|
|
|
|
repository_path=options.srcdir).strip('\n')
|
2018-08-17 14:33:09 +00:00
|
|
|
|
2016-09-06 03:00:17 +00:00
|
|
|
if not args:
|
2016-10-17 14:42:07 +00:00
|
|
|
if os.name is 'nt':
|
|
|
|
args = [os.environ.get("COMSPEC", r"C:\WINDOWS\system32\cmd.exe")]
|
2018-11-03 16:50:30 +00:00
|
|
|
args += ['/k', 'prompt [gst-{}] $P$G'.format(gst_version)]
|
2016-10-17 14:42:07 +00:00
|
|
|
else:
|
|
|
|
args = [os.environ.get("SHELL", os.path.realpath("/bin/sh"))]
|
2016-11-02 18:40:54 +00:00
|
|
|
if "bash" in args[0]:
|
|
|
|
bashrc = os.path.expanduser('~/.bashrc')
|
|
|
|
if os.path.exists(bashrc):
|
|
|
|
tmprc = tempfile.NamedTemporaryFile(mode='w')
|
|
|
|
with open(bashrc, 'r') as src:
|
|
|
|
shutil.copyfileobj(src, tmprc)
|
2018-08-17 14:33:09 +00:00
|
|
|
tmprc.write('\nexport PS1="[gst-%s] $PS1"' % gst_version)
|
2016-11-02 18:40:54 +00:00
|
|
|
tmprc.flush()
|
|
|
|
# Let the GC remove the tmp file
|
|
|
|
args.append("--rcfile")
|
|
|
|
args.append(tmprc.name)
|
2016-08-24 15:10:21 +00:00
|
|
|
try:
|
2018-11-23 18:13:49 +00:00
|
|
|
exit(subprocess.call(args, close_fds=False,
|
2018-08-17 14:33:09 +00:00
|
|
|
env=get_subprocess_env(options, gst_version)))
|
2016-08-24 15:10:21 +00:00
|
|
|
except subprocess.CalledProcessError as e:
|
|
|
|
exit(e.returncode)
|