10 SCRIPTDIR = os.path.abspath(os.path.dirname(__file__))
13 def prepend_env_var(env, var, value):
14 env[var] = os.pathsep + value + os.pathsep + env.get(var, "")
15 env[var] = env[var].replace(os.pathsep + os.pathsep, os.pathsep).strip(os.pathsep)
18 def set_prompt_var(options, env):
21 env["PS1"] = "[gst-%s] %s" % (options.gst_version, ps1)
23 prompt = env.get("PROMPT")
25 env["PROMPT"] = "[gst-%s] %s" % (options.gst_version, prompt)
28 def get_subprocess_env(options):
29 env = os.environ.copy()
31 PATH = env.get("PATH", "")
32 subprojects_path = os.path.join(options.builddir, "subprojects")
33 for proj in os.listdir(subprojects_path):
34 projpath = os.path.join(subprojects_path, proj)
35 if not os.path.exists(projpath):
36 print("Subproject %s does not exist in %s.,\n"
37 " Make sure to build everything properly "
38 "and try again." % (proj, projpath))
41 envvars_file = os.path.join(projpath, os.path.basename(projpath) + "-uninstalled-envvars.py")
42 if os.path.exists(envvars_file):
43 envvars_env = {"envvars": {}}
44 with open(envvars_file) as f:
45 code = compile(f.read(), envvars_file, 'exec')
46 exec(code, None, envvars_env)
47 for var, value in envvars_env["envvars"].items():
48 if var.startswith("+"):
49 prepend_env_var(env, var, value.strip("+"))
53 toolsdir = os.path.join(projpath, "tools")
54 if os.path.exists(toolsdir):
55 prepend_env_var(env, "PATH", toolsdir)
57 prepend_env_var(env, "GST_PLUGIN_PATH", projpath)
59 env["CURRENT_GST"] = os.path.normpath(SCRIPTDIR + "/subprojects")
60 env["GST_VALIDATE_SCENARIOS_PATH"] = os.path.normpath(
61 "%s/subprojects/gst-devtools/validate/data/scenarios" % SCRIPTDIR)
62 env["GST_VALIDATE_PLUGIN_PATH"] = os.path.normpath(
63 "%s/subprojects/gst-devtools/validate/plugins" % options.builddir)
64 env["GST_VALIDATE_APPS_DIR"] = os.path.normpath(
65 "%s/subprojects/gst-editing-services/tests/validate" % SCRIPTDIR)
66 prepend_env_var(env, "PATH", os.path.normpath(
67 "%s/subprojects/gst-devtools/validate/tools" % options.builddir))
68 prepend_env_var(env, "PATH", os.path.join(SCRIPTDIR, 'meson'))
69 env["PATH"] += os.pathsep + PATH
70 env["GST_VERSION"] = options.gst_version
71 env["GST_PLUGIN_SYSTEM_PATH"] = ""
72 env["GST_PLUGIN_SCANNER"] = os.path.normpath(
73 "%s/subprojects/gstreamer/libs/gst/helpers/gst-plugin-scanner" % options.builddir)
74 env["GST_PTP_HELPER"] = os.path.normpath(
75 "%s/subprojects/gstreamer/libs/gst/helpers/gst-ptp-helper" % options.builddir)
76 env["GST_REGISTRY"] = os.path.normpath(options.builddir + "/registry.dat")
77 prepend_env_var(env, 'PYTHONPATH', ':'.join(site.getsitepackages()))
78 env["PYTHONPATH"] = env["PYTHONPATH"] + ':' + os.path.normpath(
79 options.builddir + '/subprojects/gst-python')
81 filename = "meson.build"
82 sharedlib_reg = re.compile(r'\.so$|\.dylib$')
83 typelib_reg = re.compile(r'.*\.typelib$')
84 for root, dirnames, filenames in os.walk(os.path.join(options.builddir,
88 for filename in filenames:
89 if typelib_reg.search(filename) and not has_typelib:
91 prepend_env_var(env, "GI_TYPELIB_PATH",
92 os.path.join(options.builddir, root))
95 elif sharedlib_reg.search(filename) and not has_shared:
97 prepend_env_var(env, "LD_LIBRARY_PATH",
98 os.path.join(options.builddir, root))
99 prepend_env_var(env, "DYLD_LIBRARY_PATH",
100 os.path.join(options.builddir, root))
105 set_prompt_var(options, env)
110 if __name__ == "__main__":
111 parser = argparse.ArgumentParser(prog="gstreamer-uninstalled")
113 parser.add_argument("--builddir",
114 default=os.path.join(SCRIPTDIR, "build"),
115 help="The meson build directory")
116 parser.add_argument("--gst-version", default="master",
117 help="The GStreamer major version")
118 options, args = parser.parse_known_args()
120 if not os.path.exists(options.builddir):
121 print("GStreamer not built in %s\n\nBuild it and try again" %
127 args = [os.environ.get("COMSPEC", r"C:\WINDOWS\system32\cmd.exe")]
129 args = [os.environ.get("SHELL", os.path.realpath("/bin/sh"))]
130 if args[0] == "/bin/bash":
131 args.append("--noprofile")
134 exit(subprocess.call(args, env=get_subprocess_env(options)))
135 except subprocess.CalledProcessError as e: