Skip to content

Commit

Permalink
Fixed error on Big Sur when deployment target = 11 (#386)
Browse files Browse the repository at this point in the history
Fixes #385.

Co-authored-by: FX Coudert <[email protected]>
  • Loading branch information
Czaki and fxcoudert authored Dec 4, 2020
1 parent 39b6397 commit e6102e5
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 10 deletions.
16 changes: 10 additions & 6 deletions src/wheel/macosx_libfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,15 +350,16 @@ def calculate_macosx_platform_tag(archive_root, platform_tag):
"""
prefix, base_version, suffix = platform_tag.split('-')
base_version = tuple([int(x) for x in base_version.split(".")])
if len(base_version) >= 2:
base_version = base_version[0:2]

base_version = base_version[:2]
if base_version[0] > 10:
base_version = (base_version[0], 0)
assert len(base_version) == 2
if "MACOSX_DEPLOYMENT_TARGET" in os.environ:
deploy_target = tuple([int(x) for x in os.environ[
"MACOSX_DEPLOYMENT_TARGET"].split(".")])
if len(deploy_target) >= 2:
deploy_target = deploy_target[0:2]
deploy_target = deploy_target[:2]
if deploy_target[0] > 10:
deploy_target = (deploy_target[0], 0)
if deploy_target < base_version:
sys.stderr.write(
"[WARNING] MACOSX_DEPLOYMENT_TARGET is set to a lower value ({}) than the "
Expand All @@ -378,7 +379,10 @@ def calculate_macosx_platform_tag(archive_root, platform_tag):
lib_path = os.path.join(dirpath, filename)
min_ver = extract_macosx_min_system_version(lib_path)
if min_ver is not None:
versions_dict[lib_path] = min_ver[0:2]
min_ver = min_ver[0:2]
if min_ver[0] > 10:
min_ver = (min_ver[0], 0)
versions_dict[lib_path] = min_ver

if len(versions_dict) > 0:
base_version = max(base_version, max(versions_dict.values()))
Expand Down
28 changes: 24 additions & 4 deletions tests/test_macosx_libfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ def test_read_from_dylib():
("test_lib_10_10_386.dylib", "10.10.0"),
("test_lib_10_14_386.dylib", "10.14.0"),
("test_lib_multiple_fat.dylib", "10.14.0"),
("test_lib_10_10_10.dylib", "10.10.10")
("test_lib_10_10_10.dylib", "10.10.10"),
("test_lib_11.dylib", "11.0.0"),
]
for file_name, ver in versions:
extracted = extract_macosx_min_system_version(
Expand All @@ -48,14 +49,14 @@ class TestGetPlatformMacosx:
def test_simple(self, monkeypatch):
dirname = os.path.dirname(__file__)
dylib_dir = os.path.join(dirname, "testdata", "macosx_minimal_system_version")
monkeypatch.setattr(distutils.util, "get_platform", return_factory("macosx-10.14-x86_64"))
assert get_platform(dylib_dir) == "macosx_10_14_x86_64"
monkeypatch.setattr(distutils.util, "get_platform", return_factory("macosx-11.0-x86_64"))
assert get_platform(dylib_dir) == "macosx_11_0_x86_64"

def test_version_bump(self, monkeypatch, capsys):
dirname = os.path.dirname(__file__)
dylib_dir = os.path.join(dirname, "testdata", "macosx_minimal_system_version")
monkeypatch.setattr(distutils.util, "get_platform", return_factory("macosx-10.9-x86_64"))
assert get_platform(dylib_dir) == "macosx_10_14_x86_64"
assert get_platform(dylib_dir) == "macosx_11_0_x86_64"
captured = capsys.readouterr()
assert "[WARNING] This wheel needs a higher macOS version than" in captured.err

Expand Down Expand Up @@ -127,6 +128,25 @@ def test_warning_on_to_low_env_variable(self, monkeypatch, capsys):
captured = capsys.readouterr()
assert "MACOSX_DEPLOYMENT_TARGET is set to a lower value (10.8) than the" in captured.err

def test_get_platform_bigsur_env(self, monkeypatch):
dirname = os.path.dirname(__file__)
dylib_dir = os.path.join(dirname, "testdata", "macosx_minimal_system_version")
monkeypatch.setattr(distutils.util, "get_platform", return_factory("macosx-10.9-x86_64"))
monkeypatch.setenv("MACOSX_DEPLOYMENT_TARGET", "11")
monkeypatch.setattr(os, "walk", return_factory(
[(dylib_dir, [], ["test_lib_10_6.dylib", "test_lib_10_10_fat.dylib"])]
))
assert get_platform(dylib_dir) == "macosx_11_0_x86_64"

def test_get_platform_bigsur_platform(self, monkeypatch):
dirname = os.path.dirname(__file__)
dylib_dir = os.path.join(dirname, "testdata", "macosx_minimal_system_version")
monkeypatch.setattr(distutils.util, "get_platform", return_factory("macosx-11-x86_64"))
monkeypatch.setattr(os, "walk", return_factory(
[(dylib_dir, [], ["test_lib_10_6.dylib", "test_lib_10_10_fat.dylib"])]
))
assert get_platform(dylib_dir) == "macosx_11_0_x86_64"


def test_get_platform_linux(monkeypatch):
monkeypatch.setattr(distutils.util, "get_platform", return_factory("linux_x86_64"))
Expand Down
Binary file not shown.

1 comment on commit e6102e5

@emeryberger
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fix does not address the bug (same one) which happens on Apple Silicon platforms.

Please sign in to comment.