Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion Lib/test/test_build_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,26 @@ def test_libpython_static(self):
with open(value['static'], 'rb') as f:
self.assertEqual(f.read(8), b'!<arch>\n')

@needs_installed_python
@unittest.skipIf(
is_android or is_apple_mobile,
"Android and iOS run tests via a custom testbed method that doesn't ship libpython"
)
@unittest.skipIf(
sys.platform == 'cygwin',
"Cygwin installs the DLL in BINDIR and the import library in LIBPL, "
"not in LIBDIR"
)
def test_libpython_dynamic(self):
value = self.data.get('libpython', {})
if 'dynamic' not in value:
self.skipTest("No dynamic libpython")

if sysconfig._installation_is_relocated():
self.skipTest("Installation is relocated")

self.assertTrue(os.path.isfile(value['dynamic']))


@unittest.skipIf(
generate_build_details is None,
Expand Down Expand Up @@ -303,8 +323,14 @@ def test_framework(self):
# a libpython3.X.a symlink to the framework's shared library instead.
libpython = self.generate_libpython(
LDLIBRARY='Python.framework/Versions/3.X/Python',
STATIC_LIBPYTHON=1, PYTHONFRAMEWORK='Python')
STATIC_LIBPYTHON=1, PYTHONFRAMEWORK='Python',
PYTHONFRAMEWORKPREFIX='/Library/Frameworks')
self.assertNotIn('static', libpython)
# The dynamic library is the framework binary, which is installed at
# PYTHONFRAMEWORKPREFIX/LDLIBRARY.
self.assertEqual(
libpython['dynamic'],
'/Library/Frameworks/Python.framework/Versions/3.X/Python')


if __name__ == '__main__':
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fix ``libpython.dynamic`` in the :pep:`739` ``build-details.json`` file for
macOS and iOS framework builds. It now points at the framework's library
instead of a nonexistent path under :file:`lib/`.
10 changes: 9 additions & 1 deletion Tools/build/generate-build-details.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ def generate_data(schema_version: str) -> collections.defaultdict[str, Any]:
# The static library is only installed into LIBDIR when it is also
# LDLIBRARY; otherwise it is only installed into LIBPL.
static_library_dir = LIBPL if has_dynamic_library else LIBDIR
# In framework builds, LDLIBRARY is the path of the framework library
# relative to PYTHONFRAMEWORKPREFIX (e.g.
# Python.framework/Versions/3.X/Python), not a file in LIBDIR.
if sysconfig.get_config_var('PYTHONFRAMEWORK'):
dynamic_library_dir = sysconfig.get_config_var('PYTHONFRAMEWORKPREFIX')
else:
dynamic_library_dir = LIBDIR
elif os.name == 'nt':
# Windows can only use a dynamic library or a static library.
# If it's using a dynamic library, sys.dllhandle will be set.
Expand All @@ -99,6 +106,7 @@ def generate_data(schema_version: str) -> collections.defaultdict[str, Any]:
has_dynamic_library = hasattr(sys, 'dllhandle')
has_static_library = not has_dynamic_library
static_library_dir = LIBDIR
dynamic_library_dir = LIBDIR
else:
raise NotADirectoryError(f'Unknown platform: {os.name}')

Expand All @@ -119,7 +127,7 @@ def generate_data(schema_version: str) -> collections.defaultdict[str, Any]:
data['abi']['stable_abi_suffix'] = suffix
break

data['libpython']['dynamic'] = os.path.join(LIBDIR, LDLIBRARY)
data['libpython']['dynamic'] = os.path.join(dynamic_library_dir, LDLIBRARY)
# FIXME: Not sure if windows has a different dll for the stable ABI, and
# even if it does, currently we don't have a way to get its name.
if PY3LIBRARY:
Expand Down
Loading