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 some_overrides_built = False
156 for override_path in [os.path.join("subprojects", "gst-editing-services", "bindings", "python", "gi", "overrides"),
157 os.path.join("subprojects", "gst-python", "gi", "overrides")]:
158 if os.path.exists(os.path.join(SCRIPTDIR, override_path)):
159 some_overrides_built = True
163 prepend_env_var(env, "PYGOBJECT_OVERRIDES_PATH", os.path.join(SCRIPTDIR, override_path))
164 prepend_env_var(env, "PYGOBJECT_OVERRIDES_PATH", os.path.join(options.builddir, override_path))
166 if not some_overrides_built:
170 sitepackages = get_python_lib()
172 sitepackages = site.getusersitepackages()
174 sitecustomize = os.path.join(
175 subprocess.check_output([sys.executable, '-c', 'import site; print(site.USER_SITE)'],
176 env={"PYTHONUSERBASE": PREFIX_DIR}).decode().strip("\n"), "sitecustomize.py")
178 custom_user_sitepackage = os.path.dirname(sitecustomize)
179 os.makedirs(custom_user_sitepackage, exist_ok=True)
180 with open(sitecustomize, "w") as f:
184 for override_path in os.environ.get("PYGOBJECT_OVERRIDES_PATH", "").split(os.pathsep):
185 gi.overrides.__path__.insert(0, override_path)
188 env["PYTHONUSERBASE"] = PREFIX_DIR
190 prepend_env_var(env, "PYTHONPATH", sitepackages)
192 if __name__ == "__main__":
193 parser = argparse.ArgumentParser(prog="gstreamer-uninstalled")
195 parser.add_argument("--builddir",
196 default=DEFAULT_BUILDDIR,
197 help="The meson build directory")
198 parser.add_argument("--srcdir",
200 help="The top level source directory")
201 parser.add_argument("--gst-version", default="master",
202 help="The GStreamer major version")
203 options, args = parser.parse_known_args()
205 if not os.path.exists(options.builddir):
206 print("GStreamer not built in %s\n\nBuild it and try again" %
209 options.builddir = os.path.abspath(options.builddir)
211 if not os.path.exists(options.srcdir):
212 print("The specified source dir does not exist" %
218 args = [os.environ.get("COMSPEC", r"C:\WINDOWS\system32\cmd.exe")]
220 args = [os.environ.get("SHELL", os.path.realpath("/bin/sh"))]
221 if "bash" in args[0]:
222 bashrc = os.path.expanduser('~/.bashrc')
223 if os.path.exists(bashrc):
224 tmprc = tempfile.NamedTemporaryFile(mode='w')
225 with open(bashrc, 'r') as src:
226 shutil.copyfileobj(src, tmprc)
227 tmprc.write('\nexport PS1="[gst-%s] $PS1"' % options.gst_version)
229 # Let the GC remove the tmp file
230 args.append("--rcfile")
231 args.append(tmprc.name)
233 exit(subprocess.call(args, cwd=options.srcdir, close_fds=False,
234 env=get_subprocess_env(options)))
235 except subprocess.CalledProcessError as e: