summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorL. E. Segovia <amy@centricular.com>2024-02-03 12:13:11 +0000
committerL. E. Segovia <amy@centricular.com>2024-02-08 01:29:47 +0000
commit9aa7aaf393fa009fd7b397e63ceba2608852a60a (patch)
tree81472419c38b87d74de7524be590901912e662ec
parente50f5a085b81fd34fbf59ebeb3fdc64800dbe741 (diff)
gst-plugins-rs: Enable superstripping on macOS too
This hadn't actually been tested on the CI before, which revealed a ton of semantic issues between raw `subprocess.run` or `subprocess.check_call` calls and the equivalent `cerbero.shell` functionality. The main issue was that not only was the glob never parsed, the output was being happily ignored. Co-authored-by: Nirbheek Chauhan <nirbheek@centricular.com> Part-of: <https://gitlab.freedesktop.org/gstreamer/cerbero/-/merge_requests/1341>
-rw-r--r--cerbero/build/build.py15
-rw-r--r--recipes/gst-plugins-rs.recipe95
2 files changed, 72 insertions, 38 deletions
diff --git a/cerbero/build/build.py b/cerbero/build/build.py
index 56d25ae5..54756d3c 100644
--- a/cerbero/build/build.py
+++ b/cerbero/build/build.py
@@ -1241,12 +1241,17 @@ class Cargo(Build, ModifyEnvBase):
'''
Gets one of the LLVM tools matching the current Rust toolchain.
'''
- root_dir = subprocess.run([self.config.cargo_home + '/bin/rustc',
- '--print', 'sysroot'], capture_text=True, text=True, check=True).stdout.strip()
- tools = glob.glob(f'**/{tool}', root_dir=root_dir)
+ root_dir = shell.check_output(
+ ["rustc", "--print", "sysroot"], env=self.env
+ ).strip()
+
+ tools = list(Path(root_dir).glob(f"**/{tool}"))
+
if len(tools) == 0:
- raise FatalError('Rust {tool} tool not found, try re-running bootstrap')
- return (Path(root_dir) / tools[0]).resolve()
+ raise FatalError(
+ f"Rust {tool} tool not found at {root_dir}, try re-running bootstrap"
+ )
+ return tools[0]
def get_cargo_toml_version(self):
tomllib = self.config.find_toml_module()
diff --git a/recipes/gst-plugins-rs.recipe b/recipes/gst-plugins-rs.recipe
index e9e05480..19744909 100644
--- a/recipes/gst-plugins-rs.recipe
+++ b/recipes/gst-plugins-rs.recipe
@@ -1,11 +1,11 @@
# -*- Mode: Python -*- vi:si:et:sw=4:sts=4:ts=4:syntax=python
from custom import GStreamer
+from cerbero.errors import FatalError
from cerbero.utils import messages as m
from cerbero.utils import shell, determine_num_cargo_jobs
from pathlib import Path
import re
import shutil
-import subprocess
import tempfile
@@ -74,14 +74,14 @@ class Recipe(recipe.Recipe):
'gst-plugins-bad-1.0', 'dav1d']
def enable_plugin(self, name, category):
- if LibraryType.SHARED in self.library_type:
+ if self.library_type in (LibraryType.SHARED, LibraryType.BOTH):
attr = f'files_plugins_{category}'
if not hasattr(self, attr):
setattr(self, attr, [])
self.update_categories()
f = getattr(self, attr)
f += [f'%(libdir)s/gstreamer-1.0/libgst{name}%(mext)s']
- if LibraryType.STATIC in self.library_type:
+ if self.library_type in (LibraryType.STATIC, LibraryType.BOTH):
attr = f'files_plugins_{category}_devel'
if not hasattr(self, attr):
setattr(self, attr, [])
@@ -92,12 +92,10 @@ class Recipe(recipe.Recipe):
]
def prepare(self):
- # See "static plugins" bullet point in phase 2 at
- # https://gitlab.freedesktop.org/gstreamer/cerbero/-/issues/381
if self.config.target_platform in (Platform.IOS, Platform.ANDROID):
self.library_type = LibraryType.STATIC
else:
- self.library_type = LibraryType.SHARED
+ self.library_type = LibraryType.BOTH
if self.config.target_platform != Platform.LINUX or self.config.cross_compiling():
self.deps.append('openssl')
@@ -181,20 +179,20 @@ class Recipe(recipe.Recipe):
if self.config.target_platform in (Platform.ANDROID, Platform.LINUX):
shell.new_call([self.env['STRIP'], '--wildcard', '--strip-all',
'--keep-symbol=gst_plugin_*', f], self.config.prefix, env=self.env)
- elif self.config.target_platform == Platform.IOS:
+ elif self.config.target_platform in (Platform.IOS, Platform.DARWIN):
# Unlike ELF, for MachO Apple wants you to do
# Single-Object Prelink
- source = Path(f)
+ source = Path(self.config.prefix) / f
# Only global symbols
# Only symbol names
# Use portable output format
# Skip undefined symbols
# Write pathname of the object file
- manifest = subprocess.check_output([self.get_llvm_tool('nm'),
- '-gjPUA', source.absolute()],
- universal_newlines=True,
- text=True)
+ manifest = shell.check_output(
+ [self.get_llvm_tool("llvm-nm"), "-gjPUA", source.absolute()],
+ env=self.env,
+ )
# Now we need to match the symbols to the pattern
@@ -213,8 +211,8 @@ class Recipe(recipe.Recipe):
# List those symbols that will be kept
symbols_to_keep = set()
- for line in manifest.stdout.splitlines():
- data = line.split(' ')
+ for line in manifest.splitlines():
+ data = line.split(sep=" ")
symbol = data[1]
if symbol_pattern.match(symbol):
@@ -229,38 +227,69 @@ class Recipe(recipe.Recipe):
for symbol in symbols_to_keep:
f.write(f'{symbol}\n')
- m.log(f'Symbols to preserve in {source.absolute()}:')
+ m.log(
+ f"Symbols to preserve in {source.absolute()}:", self.logfile
+ )
for symbol in symbols_to_keep:
- m.log(f'\t{symbol}')
+ m.log(f"\t{symbol}", self.logfile)
# Unpack archive
- m.log(f"Unpacking {source.absolute()} with ar")
+ m.log(f"Unpacking {source.absolute()} with ar", self.logfile)
shell.new_call(
[shutil.which('ar'), 'xv', source.absolute()], cmd_dir=tmp, logfile=self.logfile)
# Now everything is flat in the pwd
- print('Performing Single-Object Prelinking')
+ m.log("Performing Single-Object Prelinking", self.logfile)
prelinked_obj = (
Path(tmp) / source.name).with_suffix('.prelinked.o')
- cmd = ' '.join([
- shutil.which('ld'),
- '-r',
- '-exported_symbols_list',
- module,
- '-o',
- prelinked_obj,
- '*.o',
- ])
- shell.new_call(cmd, cmd_dir=tmp,
- shell=True, logfile=self.logfile)
+
+ ld = shutil.which("ld")
+
+ if ld is None:
+ raise FatalError(f'ld not found')
+
+ # DO NOT split this into an array unless
+ # you wrap this into a 'sh -c' call.
+ # It needs the glob to be parsed by the shell!
+ shell.new_call(
+ ' '.join([
+ ld,
+ "-r",
+ "-exported_symbols_list",
+ str(module.absolute()),
+ "-o",
+ str(prelinked_obj.absolute()),
+ "*.o",
+ ]),
+ cmd_dir=tmp,
+ logfile=self.logfile,
+ )
# With the stripping done, all files now need to be rearchived
dest = Path(tmp) / source.name
- print(f'Repacking library to {dest.absolute()}')
- shell.new_call([shutil.which('libtool'), '-static', '-o',
- dest.absolute(), prelinked_obj.absolute()], logfile=self.logfile)
+ m.log(f"Repacking library to {dest.absolute()}", self.logfile)
+
+ libtool = shutil.which("libtool")
+
+ if libtool is None:
+ raise FatalError(f'libtool not found')
+
+ # (again) DO NOT split this into an array unless
+ # you wrap this into a 'sh -c' call.
+ # It needs the glob to be parsed by the shell!
+ shell.new_call(
+ ' '.join([
+ libtool,
+ "-static",
+ str(prelinked_obj.absolute()),
+ "-o",
+ str(dest.absolute()),
+ ]),
+ cmd_dir=tmp,
+ logfile=self.logfile,
+ )
# And now we paper over
- os.replace(dest.absolute(), f)
+ os.replace(dest.absolute(), source.absolute())
super().post_install()