14 from common import get_meson
16 SCRIPTDIR = os.path.abspath(os.path.dirname(__file__))
19 def prepend_env_var(env, var, value):
20 env[var] = os.pathsep + value + os.pathsep + env.get(var, "")
21 env[var] = env[var].replace(os.pathsep + os.pathsep, os.pathsep).strip(os.pathsep)
24 def get_subprocess_env(options):
25 env = os.environ.copy()
27 env["CURRENT_GST"] = os.path.normpath(SCRIPTDIR)
28 env["GST_VALIDATE_SCENARIOS_PATH"] = os.path.normpath(
29 "%s/subprojects/gst-devtools/validate/data/scenarios" % SCRIPTDIR)
30 env["GST_VALIDATE_PLUGIN_PATH"] = os.path.normpath(
31 "%s/subprojects/gst-devtools/validate/plugins" % options.builddir)
32 env["GST_VALIDATE_APPS_DIR"] = os.path.normpath(
33 "%s/subprojects/gst-editing-services/tests/validate" % SCRIPTDIR)
34 prepend_env_var(env, "PATH", os.path.normpath(
35 "%s/subprojects/gst-devtools/validate/tools" % options.builddir))
36 prepend_env_var(env, "PATH", os.path.join(SCRIPTDIR, 'meson'))
37 env["GST_VERSION"] = options.gst_version
38 env["GST_ENV"] = 'gst-' + options.gst_version
39 env["GST_PLUGIN_SYSTEM_PATH"] = ""
40 env["GST_PLUGIN_SCANNER"] = os.path.normpath(
41 "%s/subprojects/gstreamer/libs/gst/helpers/gst-plugin-scanner" % options.builddir)
42 env["GST_PTP_HELPER"] = os.path.normpath(
43 "%s/subprojects/gstreamer/libs/gst/helpers/gst-ptp-helper" % options.builddir)
44 env["GST_REGISTRY"] = os.path.normpath(options.builddir + "/registry.dat")
46 sharedlib_reg = re.compile(r'\.so|\.dylib|\.dll')
47 typelib_reg = re.compile(r'.*\.typelib$')
48 pluginpath_reg = re.compile(r'lib.*' + re.escape(os.path.normpath('/gstreamer-1.0/')))
51 lib_path_envvar = 'PATH'
52 elif platform.system() == 'Darwin':
53 lib_path_envvar = 'DYLD_LIBRARY_PATH'
55 lib_path_envvar = 'LD_LIBRARY_PATH'
57 prepend_env_var(env, "GST_PLUGIN_PATH", os.path.join(SCRIPTDIR, 'subprojects',
58 'gst-python', 'plugin'))
60 meson, mesonconf, mesonintrospect = get_meson()
61 targets_s = subprocess.check_output([sys.executable, mesonintrospect, options.builddir, '--targets'])
62 targets = json.loads(targets_s.decode())
64 for target in targets:
65 filename = target['filename']
66 root = os.path.dirname(filename)
67 if typelib_reg.search(filename):
68 prepend_env_var(env, "GI_TYPELIB_PATH",
69 os.path.join(options.builddir, root))
70 elif sharedlib_reg.search(filename):
71 if target.get('type') != "shared library":
74 if target.get('installed') and pluginpath_reg.search(os.path.normpath(target.get('install_filename'))):
75 prepend_env_var(env, "GST_PLUGIN_PATH", os.path.join(options.builddir, root))
78 prepend_env_var(env, lib_path_envvar,
79 os.path.join(options.builddir, root))
80 elif target.get('type') == 'executable' and target.get('installed'):
81 paths.add(os.path.join(options.builddir, root))
84 prepend_env_var(env, 'PATH', p)
87 encoding_targets = set()
89 if '--installed' in subprocess.check_output([sys.executable, mesonintrospect, '-h']).decode():
90 installed_s = subprocess.check_output([sys.executable, mesonintrospect,
91 options.builddir, '--installed'])
92 for path, installpath in json.loads(installed_s.decode()).items():
93 if path.endswith('.prs'):
94 presets.add(os.path.dirname(path))
95 elif path.endswith('.gep'):
97 os.path.abspath(os.path.join(os.path.dirname(path), '..')))
98 elif path.endswith('.pc'):
99 # Is there a -uninstalled pc file for this file?
100 uninstalled = "{0}-uninstalled.pc".format(path[:-3])
101 if os.path.exists(uninstalled):
102 pkg_dirs.add(os.path.dirname(path))
105 prepend_env_var(env, 'GST_PRESET_PATH', p)
107 for t in encoding_targets:
108 prepend_env_var(env, 'GST_ENCODING_TARGET_PATH', t)
110 for pkg_dir in pkg_dirs:
111 prepend_env_var(env, "PKG_CONFIG_PATH", pkg_dir)
112 prepend_env_var(env, "PKG_CONFIG_PATH", os.path.join(options.builddir,
117 mesonpath = os.path.join(SCRIPTDIR, "meson")
118 if os.path.join(mesonpath):
119 # Add meson/ into PYTHONPATH if we are using a local meson
120 prepend_env_var(env, 'PYTHONPATH', mesonpath)
125 def python_env(options, unset_env=False):
127 Setup our overrides_hack.py as sitecustomize.py script in user
128 site-packages if unset_env=False, else unset, previously set
131 subprojects_path = os.path.join(options.builddir, "subprojects")
132 gst_python_path = os.path.join(SCRIPTDIR, "subprojects", "gst-python")
133 if not os.path.exists(os.path.join(subprojects_path, "gst-python")) or \
134 not os.path.exists(gst_python_path):
137 sitepackages = site.getusersitepackages()
141 sitecustomize = os.path.join(sitepackages, "sitecustomize.py")
142 overrides_hack = os.path.join(gst_python_path, "testsuite", "overrides_hack.py")
145 if os.path.exists(sitecustomize):
146 if os.path.realpath(sitecustomize) == overrides_hack:
147 print("Customize user site script already linked to the GStreamer one")
150 old_sitecustomize = os.path.join(sitepackages,
151 "old.sitecustomize.gstuninstalled.py")
152 shutil.move(sitecustomize, old_sitecustomize)
153 elif not os.path.exists(sitepackages):
154 os.makedirs(sitepackages)
156 os.symlink(overrides_hack, sitecustomize)
157 return os.path.realpath(sitecustomize) == overrides_hack
159 if not os.path.realpath(sitecustomize) == overrides_hack:
162 os.remove(sitecustomize)
163 old_sitecustomize = os.path.join(sitepackages,
164 "old.sitecustomize.gstuninstalled.py")
166 if os.path.exists(old_sitecustomize):
167 shutil.move(old_sitecustomize, sitecustomize)
172 if __name__ == "__main__":
173 parser = argparse.ArgumentParser(prog="gstreamer-uninstalled")
175 parser.add_argument("--builddir",
176 default=os.path.join(SCRIPTDIR, "build"),
177 help="The meson build directory")
178 parser.add_argument("--srcdir",
180 help="The top level source directory")
181 parser.add_argument("--gst-version", default="master",
182 help="The GStreamer major version")
183 options, args = parser.parse_known_args()
185 if not os.path.exists(options.builddir):
186 print("GStreamer not built in %s\n\nBuild it and try again" %
190 if not os.path.exists(options.srcdir):
191 print("The specified source dir does not exist" %
197 args = [os.environ.get("COMSPEC", r"C:\WINDOWS\system32\cmd.exe")]
199 args = [os.environ.get("SHELL", os.path.realpath("/bin/sh"))]
200 if "bash" in args[0]:
201 bashrc = os.path.expanduser('~/.bashrc')
202 if os.path.exists(bashrc):
203 tmprc = tempfile.NamedTemporaryFile(mode='w')
204 with open(bashrc, 'r') as src:
205 shutil.copyfileobj(src, tmprc)
206 tmprc.write('\nexport PS1="[gst-%s] $PS1"' % options.gst_version)
208 # Let the GC remove the tmp file
209 args.append("--rcfile")
210 args.append(tmprc.name)
211 python_set = python_env(options)
213 exit(subprocess.call(args, cwd=options.srcdir,
214 env=get_subprocess_env(options)))
215 except subprocess.CalledProcessError as e:
219 python_env(options, unset_env=True)