Skip to content

Commit

Permalink
Suppress macholib header parse error
Browse files Browse the repository at this point in the history
Macholib raises ValueError when failing to parse files which can be used
to detect if the file is a Mach-O object.
It is also raised on Mach-O objects it doesn't know how to handle.

Checking for this error means `_is_macho_file` is redundant.
  • Loading branch information
HexDecimal committed Jan 16, 2025
1 parent 881a4cb commit 529158a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
4 changes: 4 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ rules on making a good Changelog.
- `delocate-merge` now supports libraries with missing or unusual extensions.
[#228](https://github.com/matthew-brett/delocate/issues/228)
- Now supports library files ending in parentheses.
- Fixed `Unknown Mach-O header` error when encountering a fat static library.
These files will be ignored until
[macholib](https://github.com/ronaldoussoren/macholib) supports them.
[#229](https://github.com/matthew-brett/delocate/issues/229)

### Removed

Expand Down
16 changes: 12 additions & 4 deletions delocate/delocating.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
from .pkginfo import read_pkg_info, write_pkg_info
from .tmpdirs import TemporaryDirectory
from .tools import (
_is_macho_file,
_remove_absolute_rpaths,
dir2zip,
find_package_dirs,
Expand Down Expand Up @@ -599,9 +598,16 @@ def _get_macos_min_version(dylib_path: Path) -> Iterator[tuple[str, Version]]:
Version
The minimum macOS version.
"""
if not _is_macho_file(dylib_path):
return
for header in MachO(dylib_path).headers:
try:
macho = MachO(dylib_path)
except ValueError as exc:
if str(exc.args[0]).startswith(
("Unknown fat header magic", "Unknown Mach-O header")
):
return # Not a recognised Mach-O object file
raise # Unexpected error

Check warning on line 608 in delocate/delocating.py

View check run for this annotation

Codecov / codecov/patch

delocate/delocating.py#L608

Added line #L608 was not covered by tests

for header in macho.headers:
for cmd in header.commands:
if cmd[0].cmd == LC_BUILD_VERSION:
version = cmd[1].minos
Expand Down Expand Up @@ -798,6 +804,8 @@ def _calculate_minimum_wheel_name(
all_library_versions: dict[str, dict[Version, list[Path]]] = {}

for lib in wheel_dir.glob("**/*"):
if lib.is_dir():
continue
for arch, version in _get_macos_min_version(lib):
all_library_versions.setdefault(arch.lower(), {}).setdefault(
version, []
Expand Down

0 comments on commit 529158a

Please sign in to comment.