Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cargo_wrapper.py - gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3ab35ab7dc1ca9e82ea9743b43c58bc78cc3b104 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env python3

import glob
import os
import os.path
import shutil
import subprocess
import sys

PLUGIN_DIRS = ['audio', 'generic', 'net', 'text', 'utils', 'video']

command, meson_build_dir, meson_current_source_dir, meson_build_root, target, include, extra_env, prefix, libdir = sys.argv[
    1:10]
include = include.split(',')

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(':')
pkg_config_path.append(os.path.join(meson_build_root, 'meson-uninstalled'))
env['PKG_CONFIG_PATH'] = ':'.join(pkg_config_path)

if len(extra_env) > 0:
    for e in extra_env.split(','):
        k, v = e.split(':')
        env[k] = v

if command == 'build':
    # cargo build
    ext = sys.argv[10]
    # when using --default-library=both 2 extensions are passed
    try:
        ext2 = sys.argv[11]
    except IndexError:
        ext2 = None

    # Build with the 'static' feature enforcing the minimal gst version required for static builds
    cargo_cmd = ['cargo', 'cbuild', '--features', 'static']
    if target == 'release':
        cargo_cmd.append('--release')
elif command == 'test':
    # cargo test
    cargo_cmd = ['cargo', 'ctest', '--no-fail-fast', '--color=always']
else:
    print("Unknown command:", command)
    sys.exit(1)

cargo_cmd.extend(
    ['--manifest-path', os.path.join(meson_current_source_dir, 'Cargo.toml')])

cargo_cmd.extend(['--prefix', prefix, '--libdir',
                  os.path.join(prefix, libdir)])


def run(cargo_cmd, env):
    try:
        subprocess.run(cargo_cmd, env=env, check=True)
    except subprocess.SubprocessError:
        sys.exit(1)


for p in include:
    cargo_cmd.extend(['-p', p])
run(cargo_cmd, env)

if command == 'build':
    target_dir = os.path.join(cargo_target_dir, '**', target)
    # Copy so files to build dir
    for f in glob.glob(os.path.join(target_dir, '*.' + ext), recursive=True):
        shutil.copy(f, meson_build_dir)
    if ext2:
        for f in glob.glob(os.path.join(target_dir, '*.' + ext2), recursive=True):
            shutil.copy(f, meson_build_dir)
    # Copy generated pkg-config files
    for f in glob.glob(os.path.join(target_dir, '*.pc'), recursive=True):
        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)