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 prepend_env_var(env, "GST_PLUGIN_PATH", options.builddir)
28 prepend_env_var(env, "GST_PLUGIN_PATH", os.path.join(SCRIPTDIR, 'subprojects',
29 'gst-python', 'plugin'))
30 env["CURRENT_GST"] = os.path.normpath(SCRIPTDIR)
31 env["GST_VALIDATE_SCENARIOS_PATH"] = os.path.normpath(
32 "%s/subprojects/gst-devtools/validate/data/scenarios" % SCRIPTDIR)
33 env["GST_VALIDATE_PLUGIN_PATH"] = os.path.normpath(
34 "%s/subprojects/gst-devtools/validate/plugins" % options.builddir)
35 env["GST_VALIDATE_APPS_DIR"] = os.path.normpath(
36 "%s/subprojects/gst-editing-services/tests/validate" % SCRIPTDIR)
37 prepend_env_var(env, "PATH", os.path.normpath(
38 "%s/subprojects/gst-devtools/validate/tools" % options.builddir))
39 prepend_env_var(env, "PATH", os.path.join(SCRIPTDIR, 'meson'))
40 env["GST_VERSION"] = options.gst_version
41 env["GST_ENV"] = 'gst-' + options.gst_version
42 env["GST_PLUGIN_SYSTEM_PATH"] = ""
43 env["GST_PLUGIN_SCANNER"] = os.path.normpath(
44 "%s/subprojects/gstreamer/libs/gst/helpers/gst-plugin-scanner" % options.builddir)
45 env["GST_PTP_HELPER"] = os.path.normpath(
46 "%s/subprojects/gstreamer/libs/gst/helpers/gst-ptp-helper" % options.builddir)
47 env["GST_REGISTRY"] = os.path.normpath(options.builddir + "/registry.dat")
49 sharedlib_reg = re.compile(r'\.so|\.dylib|\.dll')
50 typelib_reg = re.compile(r'.*\.typelib$')
53 lib_path_envvar = 'PATH'
54 elif platform.system() == 'Darwin':
55 lib_path_envvar = 'DYLD_LIBRARY_PATH'
57 lib_path_envvar = 'LD_LIBRARY_PATH'
59 meson, mesonconf, mesonintrospect = get_meson()
60 targets_s = subprocess.check_output([sys.executable, mesonintrospect, options.builddir, '--targets'])
61 targets = json.loads(targets_s.decode())
63 for target in targets:
64 filename = target['filename']
65 root = os.path.dirname(filename)
66 if typelib_reg.search(filename):
67 prepend_env_var(env, "GI_TYPELIB_PATH",
68 os.path.join(options.builddir, root))
69 elif sharedlib_reg.search(filename):
70 if target.get('type') != "shared library":
73 if os.path.normpath("lib/gstreamer-1.0") in os.path.normpath(target.get('install_filename')):
76 prepend_env_var(env, lib_path_envvar,
77 os.path.join(options.builddir, root))
78 elif target.get('type') == 'executable' and target.get('installed'):
79 paths.add(os.path.join(options.builddir, root))
82 prepend_env_var(env, 'PATH', p)
85 encoding_targets = set()
86 if '--installed' in subprocess.check_output([mesonintrospect, '-h']).decode():
87 installed_s = subprocess.check_output([sys.executable, mesonintrospect,
88 options.builddir, '--installed'])
89 for path, installpath in json.loads(installed_s.decode()).items():
90 if path.endswith('.prs'):
91 presets.add(os.path.dirname(path))
92 elif path.endswith('.gep'):
94 os.path.abspath(os.path.join(os.path.dirname(path), '..')))
96 prepend_env_var(env, 'GST_PRESET_PATH', p)
98 for t in encoding_targets:
99 prepend_env_var(env, 'GST_ENCODING_TARGET_PATH', t)
104 def python_env(options, unset_env=False):
106 Setup our overrides_hack.py as sitecustomize.py script in user
107 site-packages if unset_env=False, else unset, previously set
110 subprojects_path = os.path.join(options.builddir, "subprojects")
111 gst_python_path = os.path.join(SCRIPTDIR, "subprojects", "gst-python")
112 if not os.path.exists(os.path.join(subprojects_path, "gst-python")) or \
113 not os.path.exists(gst_python_path):
116 sitepackages = site.getusersitepackages()
120 sitecustomize = os.path.join(sitepackages, "sitecustomize.py")
121 overrides_hack = os.path.join(gst_python_path, "testsuite", "overrides_hack.py")
124 if os.path.exists(sitecustomize):
125 if os.path.realpath(sitecustomize) == overrides_hack:
126 print("Customize user site script already linked to the GStreamer one")
129 old_sitecustomize = os.path.join(sitepackages,
130 "old.sitecustomize.gstuninstalled.py")
131 shutil.move(sitecustomize, old_sitecustomize)
132 elif not os.path.exists(sitepackages):
133 os.makedirs(sitepackages)
135 os.symlink(overrides_hack, sitecustomize)
136 return os.path.realpath(sitecustomize) == overrides_hack
138 if not os.path.realpath(sitecustomize) == overrides_hack:
141 os.remove(sitecustomize)
142 old_sitecustomize = os.path.join(sitepackages,
143 "old.sitecustomize.gstuninstalled.py")
145 if os.path.exists(old_sitecustomize):
146 shutil.move(old_sitecustomize, sitecustomize)
151 if __name__ == "__main__":
152 parser = argparse.ArgumentParser(prog="gstreamer-uninstalled")
154 parser.add_argument("--builddir",
155 default=os.path.join(SCRIPTDIR, "build"),
156 help="The meson build directory")
157 parser.add_argument("--gst-version", default="master",
158 help="The GStreamer major version")
159 options, args = parser.parse_known_args()
161 if not os.path.exists(options.builddir):
162 print("GStreamer not built in %s\n\nBuild it and try again" %
168 args = [os.environ.get("COMSPEC", r"C:\WINDOWS\system32\cmd.exe")]
170 args = [os.environ.get("SHELL", os.path.realpath("/bin/sh"))]
171 if "bash" in args[0]:
172 bashrc = os.path.expanduser('~/.bashrc')
173 if os.path.exists(bashrc):
174 tmprc = tempfile.NamedTemporaryFile(mode='w')
175 with open(bashrc, 'r') as src:
176 shutil.copyfileobj(src, tmprc)
177 tmprc.write('\nexport PS1="[gst-%s] $PS1"' % options.gst_version)
179 # Let the GC remove the tmp file
180 args.append("--rcfile")
181 args.append(tmprc.name)
182 python_set = python_env(options)
184 exit(subprocess.call(args, env=get_subprocess_env(options)))
185 except subprocess.CalledProcessError as e:
189 python_env(options, unset_env=True)