15 from distutils.sysconfig import get_python_lib
17 from common import get_meson
19 SCRIPTDIR = os.path.dirname(os.path.realpath(__file__))
20 PREFIX_DIR = os.path.join(SCRIPTDIR, 'prefix')
21 # Use '_build' as the builddir instead of 'build'
22 DEFAULT_BUILDDIR = os.path.join(SCRIPTDIR, 'build')
23 if not os.path.exists(DEFAULT_BUILDDIR):
24 DEFAULT_BUILDDIR = os.path.join(SCRIPTDIR, '_build')
27 def prepend_env_var(env, var, value):
28 env[var] = os.pathsep + value + os.pathsep + env.get(var, "")
29 env[var] = env[var].replace(os.pathsep + os.pathsep, os.pathsep).strip(os.pathsep)
32 def get_subprocess_env(options):
33 env = os.environ.copy()
35 env["CURRENT_GST"] = os.path.normpath(SCRIPTDIR)
36 env["GST_VALIDATE_SCENARIOS_PATH"] = os.path.normpath(
37 "%s/subprojects/gst-devtools/validate/data/scenarios" % SCRIPTDIR)
38 env["GST_VALIDATE_PLUGIN_PATH"] = os.path.normpath(
39 "%s/subprojects/gst-devtools/validate/plugins" % options.builddir)
40 env["GST_VALIDATE_APPS_DIR"] = os.path.normpath(
41 "%s/subprojects/gst-editing-services/tests/validate" % SCRIPTDIR)
42 prepend_env_var(env, "PATH", os.path.normpath(
43 "%s/subprojects/gst-devtools/validate/tools" % options.builddir))
44 prepend_env_var(env, "PATH", os.path.join(SCRIPTDIR, 'meson'))
45 env["GST_VERSION"] = options.gst_version
46 env["GST_ENV"] = 'gst-' + options.gst_version
47 env["GST_PLUGIN_SYSTEM_PATH"] = ""
48 env["GST_PLUGIN_SCANNER"] = os.path.normpath(
49 "%s/subprojects/gstreamer/libs/gst/helpers/gst-plugin-scanner" % options.builddir)
50 env["GST_PTP_HELPER"] = os.path.normpath(
51 "%s/subprojects/gstreamer/libs/gst/helpers/gst-ptp-helper" % options.builddir)
52 env["GST_REGISTRY"] = os.path.normpath(options.builddir + "/registry.dat")
54 sharedlib_reg = re.compile(r'\.so|\.dylib|\.dll')
55 typelib_reg = re.compile(r'.*\.typelib$')
56 pluginpath_reg = re.compile(r'lib.*' + re.escape(os.path.normpath('/gstreamer-1.0/')))
59 lib_path_envvar = 'PATH'
60 elif platform.system() == 'Darwin':
61 lib_path_envvar = 'DYLD_LIBRARY_PATH'
63 lib_path_envvar = 'LD_LIBRARY_PATH'
65 prepend_env_var(env, "GST_PLUGIN_PATH", os.path.join(SCRIPTDIR, 'subprojects',
66 'gst-python', 'plugin'))
67 prepend_env_var(env, "GST_PLUGIN_PATH", os.path.join(PREFIX_DIR, 'lib',
69 prepend_env_var(env, "PATH", os.path.join(PREFIX_DIR, 'bin'))
70 prepend_env_var(env, lib_path_envvar, os.path.join(PREFIX_DIR, 'lib'))
71 prepend_env_var(env, "GST_VALIDATE_SCENARIOS_PATH", os.path.join(
72 PREFIX_DIR, 'share', 'gstreamer-1.0', 'validate', 'scenarios'))
73 prepend_env_var(env, "GI_TYPELIB_PATH", os.path.join(PREFIX_DIR, 'lib',
74 'lib', 'girepository-1.0'))
75 prepend_env_var(env, "PKG_CONFIG_PATH", os.path.join(PREFIX_DIR, 'lib', 'pkgconfig'))
76 setup_python_env(options, env)
79 targets_s = subprocess.check_output([sys.executable, meson, 'introspect', options.builddir, '--targets'])
80 targets = json.loads(targets_s.decode())
83 for target in targets:
84 filename = target['filename']
85 root = os.path.dirname(filename)
86 if filename.endswith('.dll'):
87 mono_paths.add(os.path.join(options.builddir, root))
88 if typelib_reg.search(filename):
89 prepend_env_var(env, "GI_TYPELIB_PATH",
90 os.path.join(options.builddir, root))
91 elif sharedlib_reg.search(filename):
92 if target.get('type') != "shared library":
95 if target.get('installed') and pluginpath_reg.search(os.path.normpath(target.get('install_filename'))):
96 prepend_env_var(env, "GST_PLUGIN_PATH", os.path.join(options.builddir, root))
99 prepend_env_var(env, lib_path_envvar,
100 os.path.join(options.builddir, root))
101 elif target.get('type') == 'executable' and target.get('installed'):
102 paths.add(os.path.join(options.builddir, root))
105 prepend_env_var(env, 'PATH', p)
109 prepend_env_var(env, "MONO_PATH", p)
112 encoding_targets = set()
114 if '--installed' in subprocess.check_output([sys.executable, meson, 'introspect', '-h']).decode():
115 installed_s = subprocess.check_output([sys.executable, meson, 'introspect',
116 options.builddir, '--installed'])
117 for path, installpath in json.loads(installed_s.decode()).items():
118 if path.endswith('.prs'):
119 presets.add(os.path.dirname(path))
120 elif path.endswith('.gep'):
121 encoding_targets.add(
122 os.path.abspath(os.path.join(os.path.dirname(path), '..')))
123 elif path.endswith('.pc'):
124 # Is there a -uninstalled pc file for this file?
125 uninstalled = "{0}-uninstalled.pc".format(path[:-3])
126 if os.path.exists(uninstalled):
127 pkg_dirs.add(os.path.dirname(path))
130 prepend_env_var(env, 'GST_PRESET_PATH', p)
132 for t in encoding_targets:
133 prepend_env_var(env, 'GST_ENCODING_TARGET_PATH', t)
135 for pkg_dir in pkg_dirs:
136 prepend_env_var(env, "PKG_CONFIG_PATH", pkg_dir)
137 prepend_env_var(env, "PKG_CONFIG_PATH", os.path.join(options.builddir,
142 mesonpath = os.path.join(SCRIPTDIR, "meson")
143 if os.path.join(mesonpath):
144 # Add meson/ into PYTHONPATH if we are using a local meson
145 prepend_env_var(env, 'PYTHONPATH', mesonpath)
149 # https://stackoverflow.com/questions/1871549/determine-if-python-is-running-inside-virtualenv
151 return (hasattr(sys, 'real_prefix') or
152 (hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix))
154 def setup_python_env(options, env):
155 subprojects_path = os.path.join(options.builddir, "subprojects")
156 gst_python_path = os.path.join(SCRIPTDIR, "subprojects", "gst-python")
157 if not os.path.exists(os.path.join(subprojects_path, "gst-python")) or \
158 not os.path.exists(gst_python_path):
162 sitepackages = get_python_lib()
164 sitepackages = site.getusersitepackages()
166 sitecustomize = os.path.join(
167 subprocess.check_output([sys.executable, '-c', 'import site; print(site.USER_SITE)'],
168 env={"PYTHONUSERBASE": PREFIX_DIR}).decode().strip("\n"), "sitecustomize.py")
169 overrides_hack = os.path.join(gst_python_path, "testsuite", "overrides_hack.py")
170 mesonconfig = os.path.join(gst_python_path, "testsuite", "mesonconfig.py")
171 mesonconfig_link = os.path.join(sitepackages, "mesonconfig.py")
173 os.makedirs(os.path.dirname(sitecustomize), exist_ok=True)
174 with contextlib.suppress(FileExistsError):
175 os.symlink(overrides_hack, sitecustomize)
176 with contextlib.suppress(FileExistsError):
177 os.symlink(mesonconfig, mesonconfig_link)
179 env["PYTHONUSERBASE"] = PREFIX_DIR
181 prepend_env_var(env, "PYTHONPATH", sitepackages)
183 if __name__ == "__main__":
184 parser = argparse.ArgumentParser(prog="gstreamer-uninstalled")
186 parser.add_argument("--builddir",
187 default=DEFAULT_BUILDDIR,
188 help="The meson build directory")
189 parser.add_argument("--srcdir",
191 help="The top level source directory")
192 parser.add_argument("--gst-version", default="master",
193 help="The GStreamer major version")
194 options, args = parser.parse_known_args()
196 if not os.path.exists(options.builddir):
197 print("GStreamer not built in %s\n\nBuild it and try again" %
200 options.builddir = os.path.abspath(options.builddir)
202 if not os.path.exists(options.srcdir):
203 print("The specified source dir does not exist" %
209 args = [os.environ.get("COMSPEC", r"C:\WINDOWS\system32\cmd.exe")]
211 args = [os.environ.get("SHELL", os.path.realpath("/bin/sh"))]
212 if "bash" in args[0]:
213 bashrc = os.path.expanduser('~/.bashrc')
214 if os.path.exists(bashrc):
215 tmprc = tempfile.NamedTemporaryFile(mode='w')
216 with open(bashrc, 'r') as src:
217 shutil.copyfileobj(src, tmprc)
218 tmprc.write('\nexport PS1="[gst-%s] $PS1"' % options.gst_version)
220 # Let the GC remove the tmp file
221 args.append("--rcfile")
222 args.append(tmprc.name)
224 exit(subprocess.call(args, cwd=options.srcdir, close_fds=False,
225 env=get_subprocess_env(options)))
226 except subprocess.CalledProcessError as e: