2019-11-19 08:56:01 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import glob
|
|
|
|
import os
|
|
|
|
import os.path
|
|
|
|
import shutil
|
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
|
2020-11-26 15:12:42 +00:00
|
|
|
PLUGIN_DIRS = ['audio', 'generic', 'net', 'text', 'utils', 'video']
|
|
|
|
|
2021-09-22 06:57:42 +00:00
|
|
|
command, meson_build_dir, meson_current_source_dir, meson_build_root, target, include, extra_env, prefix, libdir = sys.argv[
|
2020-11-26 15:50:04 +00:00
|
|
|
1:10]
|
2021-09-22 06:57:42 +00:00
|
|
|
include = include.split(',')
|
2019-11-19 08:56:01 +00:00
|
|
|
|
|
|
|
cargo_target_dir = os.path.join(meson_build_dir, 'target')
|
|
|
|
|
|
|
|
env = os.environ.copy()
|
|
|
|
env['CARGO_TARGET_DIR'] = cargo_target_dir
|
|
|
|
|
|
|
|
pkg_config_path = env.get('PKG_CONFIG_PATH', '').split(':')
|
2020-10-23 14:00:34 +00:00
|
|
|
pkg_config_path.append(os.path.join(meson_build_root, 'meson-uninstalled'))
|
2019-11-19 08:56:01 +00:00
|
|
|
env['PKG_CONFIG_PATH'] = ':'.join(pkg_config_path)
|
|
|
|
|
2020-01-17 04:53:43 +00:00
|
|
|
if len(extra_env) > 0:
|
|
|
|
for e in extra_env.split(','):
|
|
|
|
k, v = e.split(':')
|
|
|
|
env[k] = v
|
|
|
|
|
2020-01-07 06:10:12 +00:00
|
|
|
if command == 'build':
|
|
|
|
# cargo build
|
2020-11-26 15:50:04 +00:00
|
|
|
ext = sys.argv[10]
|
2020-11-16 14:23:51 +00:00
|
|
|
# when using --default-library=both 2 extensions are passed
|
|
|
|
try:
|
2020-11-26 15:50:04 +00:00
|
|
|
ext2 = sys.argv[11]
|
2020-11-16 14:23:51 +00:00
|
|
|
except IndexError:
|
|
|
|
ext2 = None
|
|
|
|
|
2020-11-26 15:12:42 +00:00
|
|
|
# Build with the 'static' feature enforcing the minimal gst version required for static builds
|
|
|
|
cargo_cmd = ['cargo', 'cbuild', '--features', 'static']
|
2020-01-07 06:10:12 +00:00
|
|
|
if target == 'release':
|
|
|
|
cargo_cmd.append('--release')
|
2020-01-07 08:36:39 +00:00
|
|
|
elif command == 'test':
|
|
|
|
# cargo test
|
2020-11-26 15:12:42 +00:00
|
|
|
cargo_cmd = ['cargo', 'ctest', '--no-fail-fast', '--color=always']
|
2020-01-07 06:10:12 +00:00
|
|
|
else:
|
|
|
|
print("Unknown command:", command)
|
|
|
|
sys.exit(1)
|
2019-11-19 08:56:01 +00:00
|
|
|
|
2021-11-02 09:18:13 +00:00
|
|
|
cargo_cmd.extend(
|
|
|
|
['--manifest-path', os.path.join(meson_current_source_dir, 'Cargo.toml')])
|
|
|
|
|
2020-11-26 15:50:04 +00:00
|
|
|
cargo_cmd.extend(['--prefix', prefix, '--libdir',
|
|
|
|
os.path.join(prefix, libdir)])
|
|
|
|
|
2020-01-02 04:07:55 +00:00
|
|
|
|
2020-11-26 15:12:42 +00:00
|
|
|
def run(cargo_cmd, env):
|
|
|
|
try:
|
|
|
|
subprocess.run(cargo_cmd, env=env, check=True)
|
|
|
|
except subprocess.SubprocessError:
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
|
2021-09-22 06:57:42 +00:00
|
|
|
for p in include:
|
|
|
|
cargo_cmd.extend(['-p', p])
|
|
|
|
run(cargo_cmd, env)
|
2019-11-19 08:56:01 +00:00
|
|
|
|
2020-01-07 06:10:12 +00:00
|
|
|
if command == 'build':
|
2021-04-16 11:21:38 +00:00
|
|
|
target_dir = os.path.join(cargo_target_dir, '**', target)
|
2020-01-07 06:10:12 +00:00
|
|
|
# Copy so files to build dir
|
2021-04-16 11:21:38 +00:00
|
|
|
for f in glob.glob(os.path.join(target_dir, '*.' + ext), recursive=True):
|
2020-01-07 06:10:12 +00:00
|
|
|
shutil.copy(f, meson_build_dir)
|
2020-11-16 14:23:51 +00:00
|
|
|
if ext2:
|
2021-04-16 11:21:38 +00:00
|
|
|
for f in glob.glob(os.path.join(target_dir, '*.' + ext2), recursive=True):
|
2020-11-16 14:23:51 +00:00
|
|
|
shutil.copy(f, meson_build_dir)
|
2020-11-26 15:50:04 +00:00
|
|
|
# Copy generated pkg-config files
|
2021-04-16 11:21:38 +00:00
|
|
|
for f in glob.glob(os.path.join(target_dir, '*.pc'), recursive=True):
|
2020-11-26 15:50:04 +00:00
|
|
|
shutil.copy(f, meson_build_dir)
|
|
|
|
|
|
|
|
# Move -uninstalled.pc to meson-uninstalled
|
|
|
|
uninstalled = os.path.join(meson_build_dir, 'meson-uninstalled')
|
|
|
|
if not os.path.exists(uninstalled):
|
|
|
|
os.mkdir(uninstalled)
|
|
|
|
for f in glob.glob(os.path.join(meson_build_dir, '*-uninstalled.pc')):
|
|
|
|
# move() does not allow us to update the file so remove it if it already exists
|
|
|
|
dest = os.path.join(uninstalled, os.path.basename(f))
|
|
|
|
if os.path.exists(dest):
|
|
|
|
os.unlink(dest)
|
|
|
|
shutil.move(f, uninstalled)
|