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 PATH = env.get("PATH", "")
28 subprojects_path = os.path.join(options.builddir, "subprojects")
29 for proj in os.listdir(subprojects_path):
30 projpath = os.path.join(subprojects_path, proj)
31 if not os.path.exists(projpath):
32 print("Subproject %s does not exist in %s.,\n"
33 " Make sure to build everything properly "
34 "and try again." % (proj, projpath))
37 toolsdir = os.path.join(projpath, "tools")
38 if os.path.exists(toolsdir):
39 prepend_env_var(env, "PATH", toolsdir)
41 prepend_env_var(env, "GST_PLUGIN_PATH", projpath)
43 prepend_env_var(env, "GST_PLUGIN_PATH", os.path.join(SCRIPTDIR, 'subprojects',
44 'gst-python', 'plugin'))
45 env["CURRENT_GST"] = os.path.normpath(SCRIPTDIR)
46 env["GST_VALIDATE_SCENARIOS_PATH"] = os.path.normpath(
47 "%s/subprojects/gst-devtools/validate/data/scenarios" % SCRIPTDIR)
48 env["GST_VALIDATE_PLUGIN_PATH"] = os.path.normpath(
49 "%s/subprojects/gst-devtools/validate/plugins" % options.builddir)
50 env["GST_VALIDATE_APPS_DIR"] = os.path.normpath(
51 "%s/subprojects/gst-editing-services/tests/validate" % SCRIPTDIR)
52 prepend_env_var(env, "PATH", os.path.normpath(
53 "%s/subprojects/gst-devtools/validate/tools" % options.builddir))
54 prepend_env_var(env, "PATH", os.path.join(SCRIPTDIR, 'meson'))
55 env["PATH"] += os.pathsep + PATH
56 env["GST_VERSION"] = options.gst_version
57 env["GST_ENV"] = 'gst-' + options.gst_version
58 env["GST_PLUGIN_SYSTEM_PATH"] = ""
59 env["GST_PLUGIN_SCANNER"] = os.path.normpath(
60 "%s/subprojects/gstreamer/libs/gst/helpers/gst-plugin-scanner" % options.builddir)
61 env["GST_PTP_HELPER"] = os.path.normpath(
62 "%s/subprojects/gstreamer/libs/gst/helpers/gst-ptp-helper" % options.builddir)
63 env["GST_REGISTRY"] = os.path.normpath(options.builddir + "/registry.dat")
65 filename = "meson.build"
66 sharedlib_reg = re.compile(r'\.so|\.dylib|\.dll')
67 typelib_reg = re.compile(r'.*\.typelib$')
70 lib_path_envvar = 'PATH'
71 elif platform.system() == 'Darwin':
72 lib_path_envvar = 'DYLD_LIBRARY_PATH'
74 lib_path_envvar = 'LD_LIBRARY_PATH'
76 meson, mesonconf, mesonintrospect = get_meson()
77 targets_s = subprocess.check_output([sys.executable, mesonintrospect, options.builddir, '--targets'])
78 targets = json.loads(targets_s.decode())
79 for target in targets:
80 filename = target['filename']
81 root = os.path.dirname(filename)
82 if typelib_reg.search(filename):
83 prepend_env_var(env, "GI_TYPELIB_PATH",
84 os.path.join(options.builddir, root))
85 elif sharedlib_reg.search(filename):
86 if target.get('type') != "shared library":
89 if os.path.normpath("lib/gstreamer-1.0") in os.path.normpath(target.get('install_filename')):
92 prepend_env_var(env, lib_path_envvar,
93 os.path.join(options.builddir, root))
98 def python_env(options, unset_env=False):
100 Setup our overrides_hack.py as sitecustomize.py script in user
101 site-packages if unset_env=False, else unset, previously set
104 subprojects_path = os.path.join(options.builddir, "subprojects")
105 gst_python_path = os.path.join(SCRIPTDIR, "subprojects", "gst-python")
106 if not os.path.exists(os.path.join(subprojects_path, "gst-python")) or \
107 not os.path.exists(gst_python_path):
110 sitepackages = site.getusersitepackages()
114 sitecustomize = os.path.join(sitepackages, "sitecustomize.py")
115 overrides_hack = os.path.join(gst_python_path, "testsuite", "overrides_hack.py")
118 if os.path.exists(sitecustomize):
119 if os.path.realpath(sitecustomize) == overrides_hack:
120 print("Customize user site script already linked to the GStreamer one")
123 old_sitecustomize = os.path.join(sitepackages,
124 "old.sitecustomize.gstuninstalled.py")
125 shutil.move(sitecustomize, old_sitecustomize)
126 elif not os.path.exists(sitepackages):
127 os.makedirs(sitepackages)
129 os.symlink(overrides_hack, sitecustomize)
130 return os.path.realpath(sitecustomize) == overrides_hack
132 if not os.path.realpath(sitecustomize) == overrides_hack:
135 os.remove(sitecustomize)
136 old_sitecustomize = os.path.join(sitepackages,
137 "old.sitecustomize.gstuninstalled.py")
139 if os.path.exists(old_sitecustomize):
140 shutil.move(old_sitecustomize, sitecustomize)
145 if __name__ == "__main__":
146 parser = argparse.ArgumentParser(prog="gstreamer-uninstalled")
148 parser.add_argument("--builddir",
149 default=os.path.join(SCRIPTDIR, "build"),
150 help="The meson build directory")
151 parser.add_argument("--gst-version", default="master",
152 help="The GStreamer major version")
153 options, args = parser.parse_known_args()
155 if not os.path.exists(options.builddir):
156 print("GStreamer not built in %s\n\nBuild it and try again" %
162 args = [os.environ.get("COMSPEC", r"C:\WINDOWS\system32\cmd.exe")]
164 args = [os.environ.get("SHELL", os.path.realpath("/bin/sh"))]
165 if "bash" in args[0]:
166 bashrc = os.path.expanduser('~/.bashrc')
167 if os.path.exists(bashrc):
168 tmprc = tempfile.NamedTemporaryFile(mode='w')
169 with open(bashrc, 'r') as src:
170 shutil.copyfileobj(src, tmprc)
171 tmprc.write('\nexport PS1="[gst-%s] $PS1"' % options.gst_version)
173 # Let the GC remove the tmp file
174 args.append("--rcfile")
175 args.append(tmprc.name)
176 python_set = python_env(options)
178 exit(subprocess.call(args, env=get_subprocess_env(options)))
179 except subprocess.CalledProcessError as e:
183 python_env(options, unset_env=True)