12 SCRIPTDIR = os.path.abspath(os.path.dirname(__file__))
15 def prepend_env_var(env, var, value):
16 env[var] = os.pathsep + value + os.pathsep + env.get(var, "")
17 env[var] = env[var].replace(os.pathsep + os.pathsep, os.pathsep).strip(os.pathsep)
20 def get_subprocess_env(options):
21 env = os.environ.copy()
23 PATH = env.get("PATH", "")
24 subprojects_path = os.path.join(options.builddir, "subprojects")
25 for proj in os.listdir(subprojects_path):
26 projpath = os.path.join(subprojects_path, proj)
27 if not os.path.exists(projpath):
28 print("Subproject %s does not exist in %s.,\n"
29 " Make sure to build everything properly "
30 "and try again." % (proj, projpath))
33 toolsdir = os.path.join(projpath, "tools")
34 if os.path.exists(toolsdir):
35 prepend_env_var(env, "PATH", toolsdir)
37 prepend_env_var(env, "GST_PLUGIN_PATH", projpath)
39 prepend_env_var(env, "GST_PLUGIN_PATH", os.path.join(SCRIPTDIR, 'subprojects',
40 'gst-python', 'plugin'))
41 env["CURRENT_GST"] = os.path.normpath(SCRIPTDIR)
42 env["GST_VALIDATE_SCENARIOS_PATH"] = os.path.normpath(
43 "%s/subprojects/gst-devtools/validate/data/scenarios" % SCRIPTDIR)
44 env["GST_VALIDATE_PLUGIN_PATH"] = os.path.normpath(
45 "%s/subprojects/gst-devtools/validate/plugins" % options.builddir)
46 env["GST_VALIDATE_APPS_DIR"] = os.path.normpath(
47 "%s/subprojects/gst-editing-services/tests/validate" % SCRIPTDIR)
48 prepend_env_var(env, "PATH", os.path.normpath(
49 "%s/subprojects/gst-devtools/validate/tools" % options.builddir))
50 prepend_env_var(env, "PATH", os.path.join(SCRIPTDIR, 'meson'))
51 env["PATH"] += os.pathsep + PATH
52 env["GST_VERSION"] = options.gst_version
53 env["GST_ENV"] = 'gst-' + options.gst_version
54 env["GST_PLUGIN_SYSTEM_PATH"] = ""
55 env["GST_PLUGIN_SCANNER"] = os.path.normpath(
56 "%s/subprojects/gstreamer/libs/gst/helpers/gst-plugin-scanner" % options.builddir)
57 env["GST_PTP_HELPER"] = os.path.normpath(
58 "%s/subprojects/gstreamer/libs/gst/helpers/gst-ptp-helper" % options.builddir)
59 env["GST_REGISTRY"] = os.path.normpath(options.builddir + "/registry.dat")
61 filename = "meson.build"
62 sharedlib_reg = re.compile(r'\.so$|\.dylib$')
63 typelib_reg = re.compile(r'.*\.typelib$')
64 for root, dirnames, filenames in os.walk(os.path.join(options.builddir,
68 for filename in filenames:
69 if typelib_reg.search(filename) and not has_typelib:
71 prepend_env_var(env, "GI_TYPELIB_PATH",
72 os.path.join(options.builddir, root))
75 elif sharedlib_reg.search(filename) and not has_shared:
77 prepend_env_var(env, "LD_LIBRARY_PATH",
78 os.path.join(options.builddir, root))
79 prepend_env_var(env, "DYLD_LIBRARY_PATH",
80 os.path.join(options.builddir, root))
87 def python_env(options, unset_env=False):
89 Setup our overrides_hack.py as sitecustomize.py script in user
90 site-packages if unset_env=False, else unset, previously set
93 subprojects_path = os.path.join(options.builddir, "subprojects")
94 gst_python_path = os.path.join(SCRIPTDIR, "subprojects", "gst-python")
95 if not os.path.exists(os.path.join(subprojects_path, "gst-python")) or \
96 not os.path.exists(gst_python_path):
99 sitepackages = site.getusersitepackages()
103 sitecustomize = os.path.join(sitepackages, "sitecustomize.py")
104 overrides_hack = os.path.join(gst_python_path, "testsuite", "overrides_hack.py")
107 if os.path.exists(sitecustomize):
108 if os.path.realpath(sitecustomize) == overrides_hack:
109 print("Customize user site script already linked to the GStreamer one")
112 old_sitecustomize = os.path.join(sitepackages,
113 "old.sitecustomize.gstuninstalled.py")
114 shutil.move(sitecustomize, old_sitecustomize)
115 elif not os.path.exists(sitepackages):
116 os.makedirs(sitepackages)
118 os.symlink(overrides_hack, sitecustomize)
119 return os.path.realpath(sitecustomize) == overrides_hack
121 if not os.path.realpath(sitecustomize) == overrides_hack:
124 os.remove(sitecustomize)
125 old_sitecustomize = os.path.join(sitepackages,
126 "old.sitecustomize.gstuninstalled.py")
128 if os.path.exists(old_sitecustomize):
129 shutil.move(old_sitecustomize, sitecustomize)
134 if __name__ == "__main__":
135 parser = argparse.ArgumentParser(prog="gstreamer-uninstalled")
137 parser.add_argument("--builddir",
138 default=os.path.join(SCRIPTDIR, "build"),
139 help="The meson build directory")
140 parser.add_argument("--gst-version", default="master",
141 help="The GStreamer major version")
142 options, args = parser.parse_known_args()
144 if not os.path.exists(options.builddir):
145 print("GStreamer not built in %s\n\nBuild it and try again" %
151 args = [os.environ.get("COMSPEC", r"C:\WINDOWS\system32\cmd.exe")]
153 args = [os.environ.get("SHELL", os.path.realpath("/bin/sh"))]
154 if "bash" in args[0]:
155 bashrc = os.path.expanduser('~/.bashrc')
156 if os.path.exists(bashrc):
157 tmprc = tempfile.NamedTemporaryFile(mode='w')
158 with open(bashrc, 'r') as src:
159 shutil.copyfileobj(src, tmprc)
160 tmprc.write('\nexport PS1="[gst-%s] $PS1"' % options.gst_version)
162 # Let the GC remove the tmp file
163 args.append("--rcfile")
164 args.append(tmprc.name)
165 python_set = python_env(options)
167 exit(subprocess.call(args, env=get_subprocess_env(options)))
168 except subprocess.CalledProcessError as e:
172 python_env(options, unset_env=True)