Skip to content

Commit

Permalink
meson: Handle features detection for gst version in a script
Browse files Browse the repository at this point in the history
Instead of having a big list of features in the meson.build file, we
reuse the information from the Cargo.toml files

This refactors the dependencies to handle that new use case

There were issue in previous handling and only activating the `webrtc`
plugin was failing because the list of features incorrect.

Fixes https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/issues/295

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1130>
  • Loading branch information
thiblahute authored and GStreamer Marge Bot committed Mar 12, 2023
1 parent f7c8940 commit f88552e
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 44 deletions.
92 changes: 70 additions & 22 deletions dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
PARSER = ArgumentParser()
PARSER.add_argument('src_dir', type=Path)
PARSER.add_argument('plugins', nargs='*')
PARSER.add_argument('--features', action="store_true", help="Get list of features to activate")
PARSER.add_argument('--gst-version', help="Get list of features to activate")


# Map plugin name to directory name, for those that does not match.
Expand All @@ -38,27 +40,73 @@
'textwrap': 'wrap',
}

class CargoAnalyzer:
def __init__(self):
self.src_dir = None
self.plugins = None
self.features = False
self.gst_version = "1.18"

if __name__ == "__main__":
opts = PARSER.parse_args()

with (opts.src_dir / 'Cargo.toml').open('rb') as f:
crates = tomllib.load(f)['workspace']['members']
deps = set()
for p in opts.plugins:
assert p.startswith('gst')
name = p[3:]
name = RENAMES.get(name, name)
crate_path = None
for crate in crates:
if Path(crate).name == name:
crate_path = opts.src_dir / crate / 'Cargo.toml'
assert crate_path
with crate_path.open('rb') as f:
data = tomllib.load(f)
try:
requires = data['package']['metadata']['capi']['pkg_config']['requires_private']
except KeyError:
def extract_version(self, feature_name):
if feature_name.startswith('v'):
verindex = 1
elif feature_name.startswith('gst'):
verindex = 3
else:
return None

(majver, minver) = feature_name[verindex:].split("_")
return (int(majver), int(minver))

def extract_features(self, cargo_data):
features = cargo_data['features']
wanted_features = set()
gst_version_major = int(self.gst_version.split('.')[0])
gst_version_minor = int(self.gst_version.split('.')[1])
for (name, value) in features.items():
version = self.extract_version(name)

if version is None:
continue
(majver, minver) = version

if gst_version_major < majver or gst_version_minor < minver:
continue
deps.update([i.strip().replace('>', "|>").replace('<', "|<").replace("==", "|==") for i in requires.split(',')])
print(','.join(deps))
wanted_features |= set(value)
if name.startswith("gst"):
# Required for some reason for rswebrtc which has a specific feature
wanted_features |= {f"{cargo_data['package']['name']}/{name}"}

return wanted_features

def run(self):
with (opts.src_dir / 'Cargo.toml').open('rb') as f:
crates = tomllib.load(f)['workspace']['members']
res = set()
for name in opts.plugins:
if name.startswith('gst'):
name = name[3:]

name = RENAMES.get(name, name)
crate_path = None
for crate in crates:
if Path(crate).name == name:
crate_path = opts.src_dir / crate / 'Cargo.toml'
assert crate_path
with crate_path.open('rb') as f:
data = tomllib.load(f)
if opts.features:
res |= self.extract_features(data)
else:
try:
requires = data['package']['metadata']['capi']['pkg_config']['requires_private']
except KeyError:
continue
res.update([i.strip().replace('>', "|>").replace('<', "|<").replace("==", "|==") for i in requires.split(',')])
return res

if __name__ == "__main__":
analyzer = CargoAnalyzer()
opts = PARSER.parse_args(namespace=analyzer)

print(','.join(analyzer.run()))
28 changes: 6 additions & 22 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -315,28 +315,6 @@ if get_option('gtk4').allowed()
endif
endif

if gst_dep.version().version_compare('>=1.21')
components = [
'', '-app', '-audio', '-base', '-check',
'-rtp', '-sdp', '-utils', '-video', '-webrtc',
]
if get_option('tracers').allowed()
components += '-plugin-tracers'
endif
if get_option('threadshare').allowed()
components += '-net'
endif
if get_option('mp4').allowed() or get_option('fmp4').allowed()
components += '-pbutils'
endif
foreach c: components
features += f'gst@c@/v1_22'
endforeach
if get_option('webrtc').allowed()
features += 'gst-plugin-webrtc/gst1_22'
endif
endif

if get_option('rav1e').allowed() and find_program('nasm', required: false).found()
features += 'gst-plugin-rav1e/asm'
endif
Expand All @@ -359,6 +337,12 @@ foreach plugin_name, details: plugins
if plugin_deps_found
packages += f'gst-plugin-@plugin_name@'
features += details.get('features', [])
extra_features = run_command('dependencies.py', meson.current_source_dir(), plugin_name,
'--feature', '--gst-version', gst_dep.version(), capture: true, check: true).stdout().strip()
if extra_features != ''
features += extra_features.split(',')
endif

examples += details.get('examples', [])
lib = details.get('library')
if default_library in ['shared', 'both']
Expand Down

0 comments on commit f88552e

Please sign in to comment.