import pathlib
from distutils.sysconfig import get_python_lib
+from distutils.util import strtobool
-from common import get_meson
-from common import git
+from scripts.common import get_meson
+from scripts.common import git
+from scripts.common import win32_get_short_path_name
SCRIPTDIR = os.path.dirname(os.path.realpath(__file__))
PREFIX_DIR = os.path.join(SCRIPTDIR, 'prefix')
DEFAULT_BUILDDIR = os.path.join(SCRIPTDIR, '_build')
+def listify(o):
+ if isinstance(o, str):
+ return [o]
+ if isinstance(o, list):
+ return o
+ raise AssertionError('Object {!r} must be a string or a list'.format(o))
+
+def stringify(o):
+ if isinstance(o, str):
+ return o
+ if isinstance(o, list):
+ if len(o) == 1:
+ return o[0]
+ raise AssertionError('Did not expect object {!r} to have more than one element'.format(o))
+ raise AssertionError('Object {!r} must be a string or a list'.format(o))
+
def prepend_env_var(env, var, value):
- env[var] = os.pathsep + value + os.pathsep + env.get(var, "")
+ # Try not to exceed maximum length limits for env vars on Windows
+ if os.name is 'nt':
+ value = win32_get_short_path_name(value)
+ env_val = env.get(var, '')
+ val = os.pathsep + value + os.pathsep
+ # Don't add the same value twice
+ if val in env_val or env_val.startswith(value + os.pathsep):
+ return
+ env[var] = val + env_val
env[var] = env[var].replace(os.pathsep + os.pathsep, os.pathsep).strip(os.pathsep)
sharedlib_reg = re.compile(r'\.so|\.dylib|\.dll')
typelib_reg = re.compile(r'.*\.typelib$')
- pluginpath_reg = re.compile(r'lib.*' + re.escape(os.path.normpath('/gstreamer-1.0/')))
if os.name is 'nt':
lib_path_envvar = 'PATH'
'gst-python', 'plugin'))
prepend_env_var(env, "GST_PLUGIN_PATH", os.path.join(PREFIX_DIR, 'lib',
'gstreamer-1.0'))
- prepend_env_var(env, "PATH", os.path.join(PREFIX_DIR, 'bin'))
- prepend_env_var(env, lib_path_envvar, os.path.join(PREFIX_DIR, 'lib'))
prepend_env_var(env, "GST_VALIDATE_SCENARIOS_PATH", os.path.join(
PREFIX_DIR, 'share', 'gstreamer-1.0', 'validate', 'scenarios'))
prepend_env_var(env, "GI_TYPELIB_PATH", os.path.join(PREFIX_DIR, 'lib',
'lib', 'girepository-1.0'))
prepend_env_var(env, "PKG_CONFIG_PATH", os.path.join(PREFIX_DIR, 'lib', 'pkgconfig'))
+ # gst-indent
+ prepend_env_var(env, "PATH", os.path.join(SCRIPTDIR, 'gstreamer', 'tools'))
+
+ # Library and binary search paths
+ prepend_env_var(env, "PATH", os.path.join(PREFIX_DIR, 'bin'))
+ if lib_path_envvar != 'PATH':
+ prepend_env_var(env, lib_path_envvar, os.path.join(PREFIX_DIR, 'lib'))
+ elif 'QMAKE' in os.environ:
+ # There's no RPATH on Windows, so we need to set PATH for the qt5 DLLs
+ prepend_env_var(env, 'PATH', os.path.dirname(os.environ['QMAKE']))
+
meson = get_meson()
targets_s = subprocess.check_output(meson + ['introspect', options.builddir, '--targets'])
targets = json.loads(targets_s.decode())
paths = set()
mono_paths = set()
+ srcdir_path = pathlib.Path(options.srcdir)
for target in targets:
- filename = target['filename']
- root = os.path.dirname(filename)
- if filename.endswith('.dll'):
- mono_paths.add(os.path.join(options.builddir, root))
- if typelib_reg.search(filename):
- prepend_env_var(env, "GI_TYPELIB_PATH",
- os.path.join(options.builddir, root))
- elif sharedlib_reg.search(filename):
- if target.get('type') != "shared library":
- continue
-
- if target.get('installed') and pluginpath_reg.search(os.path.normpath(target.get('install_filename'))):
- prepend_env_var(env, "GST_PLUGIN_PATH", os.path.join(options.builddir, root))
+ filenames = listify(target['filename'])
+ for filename in filenames:
+ if filename.startswith(options.sysroot):
+ filename = filename[len(options.sysroot):]
+ root = os.path.dirname(filename)
+ if srcdir_path / "subprojects/gst-devtools/validate/plugins" in (srcdir_path / root).parents:
continue
-
- prepend_env_var(env, lib_path_envvar,
- os.path.join(options.builddir, root))
- elif target.get('type') == 'executable' and target.get('installed'):
- paths.add(os.path.join(options.builddir, root))
+ if filename.endswith('.dll'):
+ mono_paths.add(os.path.join(options.builddir, root))
+ if typelib_reg.search(filename):
+ prepend_env_var(env, "GI_TYPELIB_PATH",
+ os.path.join(options.builddir, root))
+ elif sharedlib_reg.search(filename):
+ if not target['type'].startswith('shared'):
+ continue
+
+ prepend_env_var(env, lib_path_envvar,
+ os.path.join(options.builddir, root))
+ elif target['type'] == 'executable' and target['installed']:
+ paths.add(os.path.join(options.builddir, root))
+
+ with open(os.path.join(options.builddir, 'GstPluginsPath.json')) as f:
+ for plugin_path in json.load(f):
+ prepend_env_var(env, 'GST_PLUGIN_PATH', plugin_path)
for p in paths:
prepend_env_var(env, 'PATH', p)
if os.path.exists(uninstalled):
pkg_dirs.add(os.path.dirname(path))
+ if path.endswith('gstomx.conf'):
+ prepend_env_var(env, 'GST_OMX_CONFIG_DIR', os.path.dirname(path))
+
for p in presets:
prepend_env_var(env, 'GST_PRESET_PATH', p)
return env
+def get_windows_shell():
+ command = ['powershell.exe' ,'-noprofile', '-executionpolicy', 'bypass', '-file', 'cmd_or_ps.ps1']
+ result = subprocess.check_output(command)
+ return result.decode().strip()
+
# https://stackoverflow.com/questions/1871549/determine-if-python-is-running-inside-virtualenv
def in_venv():
return (hasattr(sys, 'real_prefix') or
parser.add_argument("--srcdir",
default=SCRIPTDIR,
help="The top level source directory")
+ parser.add_argument("--sysroot",
+ default='',
+ help="The sysroot path used during cross-compilation")
options, args = parser.parse_known_args()
if not os.path.exists(options.builddir):
if not args:
if os.name is 'nt':
- args = [os.environ.get("COMSPEC", r"C:\WINDOWS\system32\cmd.exe")]
- args += ['/k', 'prompt [gst-{}] $P$G'.format(gst_version)]
+ shell = get_windows_shell()
+ if shell == 'powershell.exe':
+ args = ['powershell.exe']
+ args += ['-NoLogo', '-NoExit']
+ prompt = 'function global:prompt { "[gst-' + gst_version + '"+"] PS " + $PWD + "> "}'
+ args += ['-Command', prompt]
+ else:
+ args = [os.environ.get("COMSPEC", r"C:\WINDOWS\system32\cmd.exe")]
+ args += ['/k', 'prompt [gst-{}] $P$G'.format(gst_version)]
else:
args = [os.environ.get("SHELL", os.path.realpath("/bin/sh"))]
- if "bash" in args[0]:
+ if "bash" in args[0] and not strtobool(os.environ.get("GST_BUILD_DISABLE_PS1_OVERRIDE", r"FALSE")):
bashrc = os.path.expanduser('~/.bashrc')
if os.path.exists(bashrc):
tmprc = tempfile.NamedTemporaryFile(mode='w')
args.append("--rcfile")
args.append(tmprc.name)
try:
- exit(subprocess.call(args, cwd=options.srcdir, close_fds=False,
+ exit(subprocess.call(args, close_fds=False,
env=get_subprocess_env(options, gst_version)))
except subprocess.CalledProcessError as e:
exit(e.returncode)