MacOS - BundleUtilities adds Python Interpreter to app and doesn't do fixup on it - proposed solution included
The context of this bug is trying to build a MacOS package or app with Cmake that requires Python3, as installed by the command line tool port
.
The BundleUtilities part of cmake copies the Python Framework into the app, fixes up the Python library, but does NOT fix up the Python interpreter. This means the Python interpreter is pointing to external resources (outside the app), which causes verify_app to fail correctly.
I created a sample project to reproduce the bug:
https://gitlab.kitware.com/andrew.trapani/cmake-basic-hellopython-macos-app
There is a proposed fix on stack overflow here, by user "Dmitry Mikushin":
https://stackoverflow.com/a/59513729/3325798
The fix finds the python interpreter and runs fix_up on it, making it point to internal app resources.
I verified the proposed fix works in the linked sample project and in our internal, larger project.
Hopefully this makes tracking down the bug and fixing it easier.
The proposed fix, copied from Dmitry Mikushin's answer on SO:
--- a/BundleUtilities.cmake 2019-12-28 02:10:43.000000000 +0100
+++ b/BundleUtilities.cmake 2019-12-28 09:39:26.000000000 +0100
@@ -982,6 +984,13 @@
message(STATUS "fixup_bundle: cleaning up...")
clear_bundle_keys(keys)
+ # Recursively discover and fix all subsequent executables.
+ get_bundle_all_executables("${bundle}" file_list)
+ list(REMOVE_ITEM file_list "${app}" ${CFG_IGNORE_ITEM})
+ list(LENGTH file_list nexecutables)
+ if (${nexecutables} GREATER 0)
+ list(GET file_list 0 f)
+ message(STATUS "fixup_bundle: fixing newly discovered executable ${f}...")
+ fixup_bundle("${f}" "" "${dirs}" IGNORE_ITEM ${CFG_IGNORE_ITEM} ${app})
+ endif()
+
message(STATUS "fixup_bundle: verifying...")
verify_app("${app}" IGNORE_ITEM "${CFG_IGNORE_ITEM}")
else()