2016-08-24 15:10:21 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import argparse
|
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
|
2016-08-24 15:10:21 +00:00
|
|
|
|
2016-11-19 21:01:44 +00:00
|
|
|
from common import get_meson
|
2016-08-24 15:10:21 +00:00
|
|
|
|
2016-09-06 03:00:17 +00:00
|
|
|
SCRIPTDIR = os.path.abspath(os.path.dirname(__file__))
|
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
|
|
|
|
2016-08-24 15:10:21 +00:00
|
|
|
def get_subprocess_env(options):
|
|
|
|
env = os.environ.copy()
|
|
|
|
|
|
|
|
PATH = env.get("PATH", "")
|
|
|
|
subprojects_path = os.path.join(options.builddir, "subprojects")
|
|
|
|
for proj in os.listdir(subprojects_path):
|
|
|
|
projpath = os.path.join(subprojects_path, proj)
|
|
|
|
if not os.path.exists(projpath):
|
|
|
|
print("Subproject %s does not exist in %s.,\n"
|
|
|
|
" Make sure to build everything properly "
|
|
|
|
"and try again." % (proj, projpath))
|
|
|
|
exit(1)
|
|
|
|
|
|
|
|
toolsdir = os.path.join(projpath, "tools")
|
|
|
|
if os.path.exists(toolsdir):
|
|
|
|
prepend_env_var(env, "PATH", toolsdir)
|
|
|
|
|
|
|
|
prepend_env_var(env, "GST_PLUGIN_PATH", projpath)
|
|
|
|
|
2016-11-03 14:46:34 +00:00
|
|
|
prepend_env_var(env, "GST_PLUGIN_PATH", os.path.join(SCRIPTDIR, 'subprojects',
|
|
|
|
'gst-python', 'plugin'))
|
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'))
|
2016-08-24 15:10:21 +00:00
|
|
|
env["PATH"] += os.pathsep + PATH
|
|
|
|
env["GST_VERSION"] = options.gst_version
|
2016-11-02 18:40:54 +00:00
|
|
|
env["GST_ENV"] = 'gst-' + options.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
|
|
|
|
|
|
|
filename = "meson.build"
|
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$')
|
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'
|
|
|
|
|
2016-11-19 21:01:44 +00:00
|
|
|
meson, mesonconf, mesonintrospect = get_meson()
|
2016-11-19 13:18:33 +00:00
|
|
|
targets_s = subprocess.check_output([sys.executable, mesonintrospect, options.builddir, '--targets'])
|
2016-11-19 21:01:44 +00:00
|
|
|
targets = json.loads(targets_s.decode())
|
|
|
|
for target in targets:
|
|
|
|
filename = target['filename']
|
|
|
|
root = os.path.dirname(filename)
|
|
|
|
if typelib_reg.search(filename):
|
|
|
|
prepend_env_var(env, "GI_TYPELIB_PATH",
|
|
|
|
os.path.join(options.builddir, root))
|
|
|
|
elif sharedlib_reg.search(filename):
|
|
|
|
if target.get('type') != "shared library":
|
|
|
|
continue
|
|
|
|
|
2016-11-19 13:18:33 +00:00
|
|
|
if os.path.normpath("lib/gstreamer-1.0") in os.path.normpath(target.get('install_filename')):
|
2016-11-19 21:01:44 +00:00
|
|
|
continue
|
|
|
|
|
|
|
|
prepend_env_var(env, lib_path_envvar,
|
|
|
|
os.path.join(options.builddir, root))
|
2016-09-05 14:54:46 +00:00
|
|
|
|
2016-08-24 15:10:21 +00:00
|
|
|
return env
|
|
|
|
|
|
|
|
|
2016-11-03 14:46:34 +00:00
|
|
|
def python_env(options, unset_env=False):
|
|
|
|
"""
|
|
|
|
Setup our overrides_hack.py as sitecustomize.py script in user
|
|
|
|
site-packages if unset_env=False, else unset, previously set
|
|
|
|
env.
|
|
|
|
"""
|
|
|
|
subprojects_path = os.path.join(options.builddir, "subprojects")
|
|
|
|
gst_python_path = os.path.join(SCRIPTDIR, "subprojects", "gst-python")
|
|
|
|
if not os.path.exists(os.path.join(subprojects_path, "gst-python")) or \
|
|
|
|
not os.path.exists(gst_python_path):
|
|
|
|
return False
|
|
|
|
|
|
|
|
sitepackages = site.getusersitepackages()
|
|
|
|
if not sitepackages:
|
|
|
|
return False
|
|
|
|
|
|
|
|
sitecustomize = os.path.join(sitepackages, "sitecustomize.py")
|
|
|
|
overrides_hack = os.path.join(gst_python_path, "testsuite", "overrides_hack.py")
|
|
|
|
|
|
|
|
if not unset_env:
|
|
|
|
if os.path.exists(sitecustomize):
|
|
|
|
if os.path.realpath(sitecustomize) == overrides_hack:
|
|
|
|
print("Customize user site script already linked to the GStreamer one")
|
|
|
|
return False
|
|
|
|
|
|
|
|
old_sitecustomize = os.path.join(sitepackages,
|
|
|
|
"old.sitecustomize.gstuninstalled.py")
|
|
|
|
shutil.move(sitecustomize, old_sitecustomize)
|
|
|
|
elif not os.path.exists(sitepackages):
|
|
|
|
os.makedirs(sitepackages)
|
|
|
|
|
|
|
|
os.symlink(overrides_hack, sitecustomize)
|
|
|
|
return os.path.realpath(sitecustomize) == overrides_hack
|
|
|
|
else:
|
|
|
|
if not os.path.realpath(sitecustomize) == overrides_hack:
|
|
|
|
return False
|
|
|
|
|
|
|
|
os.remove(sitecustomize)
|
|
|
|
old_sitecustomize = os.path.join(sitepackages,
|
|
|
|
"old.sitecustomize.gstuninstalled.py")
|
|
|
|
|
|
|
|
if os.path.exists(old_sitecustomize):
|
|
|
|
shutil.move(old_sitecustomize, sitecustomize)
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
2016-08-24 15:10:21 +00:00
|
|
|
if __name__ == "__main__":
|
|
|
|
parser = argparse.ArgumentParser(prog="gstreamer-uninstalled")
|
|
|
|
|
|
|
|
parser.add_argument("--builddir",
|
|
|
|
default=os.path.join(SCRIPTDIR, "build"),
|
|
|
|
help="The meson build directory")
|
|
|
|
parser.add_argument("--gst-version", default="master",
|
2016-08-26 03:10:07 +00:00
|
|
|
help="The GStreamer major version")
|
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)
|
|
|
|
|
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")]
|
|
|
|
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)
|
|
|
|
tmprc.write('\nexport PS1="[gst-%s] $PS1"' % options.gst_version)
|
|
|
|
tmprc.flush()
|
|
|
|
# Let the GC remove the tmp file
|
|
|
|
args.append("--rcfile")
|
|
|
|
args.append(tmprc.name)
|
2016-11-03 14:46:34 +00:00
|
|
|
python_set = python_env(options)
|
2016-08-24 15:10:21 +00:00
|
|
|
try:
|
2016-10-10 23:58:05 +00:00
|
|
|
exit(subprocess.call(args, env=get_subprocess_env(options)))
|
2016-08-24 15:10:21 +00:00
|
|
|
except subprocess.CalledProcessError as e:
|
|
|
|
exit(e.returncode)
|
2016-11-03 14:46:34 +00:00
|
|
|
finally:
|
|
|
|
if python_set:
|
|
|
|
python_env(options, unset_env=True)
|