13 from common import get_meson
15 SCRIPTDIR = os.path.abspath(os.path.dirname(__file__))
18 def prepend_env_var(env, var, value):
19 env[var] = os.pathsep + value + os.pathsep + env.get(var, "")
20 env[var] = env[var].replace(os.pathsep + os.pathsep, os.pathsep).strip(os.pathsep)
23 def get_subprocess_env(options):
24 env = os.environ.copy()
26 PATH = env.get("PATH", "")
27 subprojects_path = os.path.join(options.builddir, "subprojects")
28 for proj in os.listdir(subprojects_path):
29 projpath = os.path.join(subprojects_path, proj)
30 if not os.path.exists(projpath):
31 print("Subproject %s does not exist in %s.,\n"
32 " Make sure to build everything properly "
33 "and try again." % (proj, projpath))
36 toolsdir = os.path.join(projpath, "tools")
37 if os.path.exists(toolsdir):
38 prepend_env_var(env, "PATH", toolsdir)
40 prepend_env_var(env, "GST_PLUGIN_PATH", projpath)
42 prepend_env_var(env, "GST_PLUGIN_PATH", os.path.join(SCRIPTDIR, 'subprojects',
43 'gst-python', 'plugin'))
44 env["CURRENT_GST"] = os.path.normpath(SCRIPTDIR)
45 env["GST_VALIDATE_SCENARIOS_PATH"] = os.path.normpath(
46 "%s/subprojects/gst-devtools/validate/data/scenarios" % SCRIPTDIR)
47 env["GST_VALIDATE_PLUGIN_PATH"] = os.path.normpath(
48 "%s/subprojects/gst-devtools/validate/plugins" % options.builddir)
49 env["GST_VALIDATE_APPS_DIR"] = os.path.normpath(
50 "%s/subprojects/gst-editing-services/tests/validate" % SCRIPTDIR)
51 prepend_env_var(env, "PATH", os.path.normpath(
52 "%s/subprojects/gst-devtools/validate/tools" % options.builddir))
53 prepend_env_var(env, "PATH", os.path.join(SCRIPTDIR, 'meson'))
54 env["PATH"] += os.pathsep + PATH
55 env["GST_VERSION"] = options.gst_version
56 env["GST_ENV"] = 'gst-' + options.gst_version
57 env["GST_PLUGIN_SYSTEM_PATH"] = ""
58 env["GST_PLUGIN_SCANNER"] = os.path.normpath(
59 "%s/subprojects/gstreamer/libs/gst/helpers/gst-plugin-scanner" % options.builddir)
60 env["GST_PTP_HELPER"] = os.path.normpath(
61 "%s/subprojects/gstreamer/libs/gst/helpers/gst-ptp-helper" % options.builddir)
62 env["GST_REGISTRY"] = os.path.normpath(options.builddir + "/registry.dat")
64 filename = "meson.build"
65 sharedlib_reg = re.compile(r'\.so|\.dylib|\.dll')
66 typelib_reg = re.compile(r'.*\.typelib$')
69 lib_path_envvar = 'PATH'
70 elif platform.system() == 'Darwin':
71 lib_path_envvar = 'DYLD_LIBRARY_PATH'
73 lib_path_envvar = 'LD_LIBRARY_PATH'
75 meson, mesonconf, mesonintrospect = get_meson()
76 targets_s = subprocess.check_output([mesonintrospect, options.builddir, '--targets'])
77 targets = json.loads(targets_s.decode())
78 for target in targets:
79 filename = target['filename']
80 root = os.path.dirname(filename)
81 if typelib_reg.search(filename):
82 prepend_env_var(env, "GI_TYPELIB_PATH",
83 os.path.join(options.builddir, root))
84 elif sharedlib_reg.search(filename):
85 if target.get('type') != "shared library":
88 if "lib/gstreamer-1.0" in os.path.normpath(target.get('install_filename')):
91 prepend_env_var(env, lib_path_envvar,
92 os.path.join(options.builddir, root))
97 def python_env(options, unset_env=False):
99 Setup our overrides_hack.py as sitecustomize.py script in user
100 site-packages if unset_env=False, else unset, previously set
103 subprojects_path = os.path.join(options.builddir, "subprojects")
104 gst_python_path = os.path.join(SCRIPTDIR, "subprojects", "gst-python")
105 if not os.path.exists(os.path.join(subprojects_path, "gst-python")) or \
106 not os.path.exists(gst_python_path):
109 sitepackages = site.getusersitepackages()
113 sitecustomize = os.path.join(sitepackages, "sitecustomize.py")
114 overrides_hack = os.path.join(gst_python_path, "testsuite", "overrides_hack.py")
117 if os.path.exists(sitecustomize):
118 if os.path.realpath(sitecustomize) == overrides_hack:
119 print("Customize user site script already linked to the GStreamer one")
122 old_sitecustomize = os.path.join(sitepackages,
123 "old.sitecustomize.gstuninstalled.py")
124 shutil.move(sitecustomize, old_sitecustomize)
125 elif not os.path.exists(sitepackages):
126 os.makedirs(sitepackages)
128 os.symlink(overrides_hack, sitecustomize)
129 return os.path.realpath(sitecustomize) == overrides_hack
131 if not os.path.realpath(sitecustomize) == overrides_hack:
134 os.remove(sitecustomize)
135 old_sitecustomize = os.path.join(sitepackages,
136 "old.sitecustomize.gstuninstalled.py")
138 if os.path.exists(old_sitecustomize):
139 shutil.move(old_sitecustomize, sitecustomize)
144 if __name__ == "__main__":
145 parser = argparse.ArgumentParser(prog="gstreamer-uninstalled")
147 parser.add_argument("--builddir",
148 default=os.path.join(SCRIPTDIR, "build"),
149 help="The meson build directory")
150 parser.add_argument("--gst-version", default="master",
151 help="The GStreamer major version")
152 options, args = parser.parse_known_args()
154 if not os.path.exists(options.builddir):
155 print("GStreamer not built in %s\n\nBuild it and try again" %
161 args = [os.environ.get("COMSPEC", r"C:\WINDOWS\system32\cmd.exe")]
163 args = [os.environ.get("SHELL", os.path.realpath("/bin/sh"))]
164 if "bash" in args[0]:
165 bashrc = os.path.expanduser('~/.bashrc')
166 if os.path.exists(bashrc):
167 tmprc = tempfile.NamedTemporaryFile(mode='w')
168 with open(bashrc, 'r') as src:
169 shutil.copyfileobj(src, tmprc)
170 tmprc.write('\nexport PS1="[gst-%s] $PS1"' % options.gst_version)
172 # Let the GC remove the tmp file
173 args.append("--rcfile")
174 args.append(tmprc.name)
175 python_set = python_env(options)
177 exit(subprocess.call(args, env=get_subprocess_env(options)))
178 except subprocess.CalledProcessError as e:
182 python_env(options, unset_env=True)