From a06f0ca908470f5ef18ce78dac7922f026d0939c Mon Sep 17 00:00:00 2001 From: Adam Wolf Date: Thu, 15 Apr 2021 10:46:44 -0500 Subject: [PATCH] Clean up macOS Python3 paths --- CMakeLists.txt | 9 +++++---- kicad/CMakeLists.txt | 18 +++++++----------- pcbnew/pcbnew.cpp | 12 ++---------- 3 files changed, 14 insertions(+), 25 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ad04e1bbb1..7cdb1f212e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -844,12 +844,13 @@ if( KICAD_SCRIPTING OR KICAD_SCRIPTING_MODULES ) endif() if( APPLE ) - # change to add_compile_definitions() after minimum required CMake version is 3.12 - set_property( DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS PYTHON_MAJOR_MINOR_VERSION="${PYTHON_MAJOR_VERSION}.${PYTHON_MINOR_VERSION}") - #TODO put this into Resources/site-packages or something that's notarizable, but as it is we pull it in during bundling - set( PYTHON_DEST "${PYTHON_SITE_PACKAGE_PATH}" + set( OSX_BUNDLE_PYTHON_SITE_PACKAGES_DIR ${OSX_BUNDLE_LIB_DIR}/Python.framework/Versions/${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/lib/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/site-packages) + set( OSX_BUNDLE_INSTALL_PYTHON_SITE_PACKAGES_DIR "${OSX_BUNDLE_INSTALL_DIR}/${OSX_BUNDLE_PYTHON_SITE_PACKAGES_DIR}") + set( PYTHON_DEST "${OSX_BUNDLE_BUILD_DIR}/${OSX_BUNDLE_PYTHON_SITE_PACKAGES_DIR}" CACHE PATH "Python module install path." ) + # change to add_compile_definitions() after minimum required CMake version is 3.12 + set_property( DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS OSX_BUNDLE_PYTHON_SITE_PACKAGES_DIR="${OSX_BUNDLE_PYTHON_SITE_PACKAGES_DIR}") elseif( VCPKG_TOOLCHAIN ) set( PYTHON_DEST "${CMAKE_INSTALL_PREFIX}/bin/Lib/site-packages" CACHE PATH "Python module install path." diff --git a/kicad/CMakeLists.txt b/kicad/CMakeLists.txt index 54d4e2b325..7eb9496e1a 100644 --- a/kicad/CMakeLists.txt +++ b/kicad/CMakeLists.txt @@ -142,10 +142,10 @@ if( APPLE ) # Find python if it is requested if( ${SCRIPTING_HELPER} ) - file( GLOB WXPYTHON_DIR RELATIVE ${OSX_BUNDLE_INSTALL_LIB_DIR}/${PYTHON_LIB_DIR} ${OSX_BUNDLE_INSTALL_LIB_DIR}/${PYTHON_LIB_DIR}/wx-?.?-osx_cocoa ) - file( GLOB PYTHON_SCRIPTING_SO ${OSX_BUNDLE_INSTALL_LIB_DIR}/${PYTHON_LIB_DIR}/*.so ) + file( GLOB WXPYTHON_DIR RELATIVE ${OSX_BUNDLE_BUILD_DIR}/${OSX_BUNDLE_PYTHON_SITE_PACKAGES_DIR} ${OSX_BUNDLE_INSTALL_PYTHON_SITE_PACKAGES_DIR}/wx-?.?-osx_cocoa ) + file( GLOB PYTHON_SCRIPTING_SO ${OSX_BUNDLE_INSTALL_PYTHON_SITE_PACKAGES_DIR}/*.so ) set( BUNDLE_FIX_LIBS \${BUNDLE_FIX_LIBS} \${PYTHON_SCRIPTING_SO} ) - file( GLOB PYTHON_SCRIPTING_SO ${OSX_BUNDLE_INSTALL_LIB_DIR}/${PYTHON_LIB_DIR}/\${WXPYTHON_DIR}/wx/*.so ) + file( GLOB PYTHON_SCRIPTING_SO ${OSX_BUNDLE_INSTALL_PYTHON_SITE_PACKAGES_DIR}/\${WXPYTHON_DIR}/wx/*.so ) set( BUNDLE_FIX_LIBS \${BUNDLE_FIX_LIBS} \${PYTHON_SCRIPTING_SO} ) endif() @@ -172,11 +172,8 @@ if( APPLE ) execute_process( COMMAND cp -RP ${PYTHON_FRAMEWORK} ${OSX_BUNDLE_INSTALL_LIB_DIR}/) # We're using cp -RP because CMake's COPY_RESOLVED_BUNDLE... and COPY_DIRECTORY don't handle symlinks correctly - file( REMOVE GLOB ${OSX_BUNDLE_INSTALL_LIB_DIR}/Python.framework/Versions/3.8/lib/python3.8/site-packages/wx/*.dylib) - # Add any .so files in the site-packages directory to the list of things to fixup during fixup_bundle - set( PYTHON_SITE_PACKAGES_PATH ${OSX_BUNDLE_INSTALL_LIB_DIR}/Python.framework/Versions/3.8/lib/python3.8/site-packages) - file( GLOB_RECURSE PYTHON_SITE_PACKAGES_LIBS \${PYTHON_SITE_PACKAGES_PATH}/*.so ) + file( GLOB_RECURSE PYTHON_SITE_PACKAGES_LIBS ${OSX_BUNDLE_INSTALL_PYTHON_SITE_PACKAGES_DIR}/*.so ) set( BUNDLE_FIX_LIBS \${BUNDLE_FIX_LIBS} \${PYTHON_SITE_PACKAGES_LIBS} ) fixup_bundle( ${OSX_BUNDLE_INSTALL_BIN_DIR}/kicad @@ -188,13 +185,12 @@ if( APPLE ) # BundleUtilities clobbers the rpaths and install_names that we carefully setup in Python.framework, even if we mark Python things as IGNORE_ITEMs. # python/site-packages/_pcbnew.so - execute_process( COMMAND install_name_tool -change @executable_path/../../Contents/MacOS/Python.framework/Versions/3.8/Python @rpath/Python.framework/Python ${OSX_BUNDLE_INSTALL_LIB_DIR}/Python.framework/Versions/3.8/lib/python3.8/site-packages/_pcbnew.so ) - execute_process( COMMAND install_name_tool -change @executable_path/../../Contents/MacOS/Python.framework/Python @rpath/Python.framework/Python ${OSX_BUNDLE_INSTALL_LIB_DIR}/Python.framework/Versions/3.8/lib/python3.8/site-packages/_pcbnew.so ) - execute_process( COMMAND install_name_tool -change @executable_path/../../Contents/MacOS/Python.framework/Versions/3.8/Resources/Python.app/Contents/MacOS/Python @rpath/Python.framework/Python ${OSX_BUNDLE_INSTALL_LIB_DIR}/Python.framework/Versions/3.8/lib/python3.8/site-packages/_pcbnew.so ) + execute_process( COMMAND install_name_tool -change @executable_path/../../Contents/MacOS/Python.framework/Versions/3.8/Python @rpath/Python.framework/Python ${OSX_BUNDLE_INSTALL_PYTHON_SITE_PACKAGES_DIR}/_pcbnew.so ) + execute_process( COMMAND install_name_tool -change @executable_path/../../Contents/MacOS/Python.framework/Python @rpath/Python.framework/Python ${OSX_BUNDLE_INSTALL_PYTHON_SITE_PACKAGES_DIR}/_pcbnew.so ) + execute_process( COMMAND install_name_tool -change @executable_path/../../Contents/MacOS/Python.framework/Versions/3.8/Resources/Python.app/Contents/MacOS/Python @rpath/Python.framework/Python ${OSX_BUNDLE_INSTALL_PYTHON_SITE_PACKAGES_DIR}/_pcbnew.so ) # _pcbnew.kiface execute_process( COMMAND install_name_tool -change @executable_path/../../Contents/MacOS/Python @rpath/Python.framework/Python ${OSX_BUNDLE_INSTALL_KIFACE_DIR}/_pcbnew.kiface ) - execute_process( COMMAND install_name_tool -add_rpath @executable_path/../Frameworks ${OSX_BUNDLE_INSTALL_KIFACE_DIR}/_pcbnew.kiface ) # Python.framework/Versions/Current/bin/python3 diff --git a/pcbnew/pcbnew.cpp b/pcbnew/pcbnew.cpp index 2e885d67b2..36a68c6cf7 100644 --- a/pcbnew/pcbnew.cpp +++ b/pcbnew/pcbnew.cpp @@ -256,17 +256,9 @@ static bool scriptingSetup() pypath += wxT( ":" ) + wxString( wxGetenv("KICAD_PATH") ); } - // TODO: Can we just use PYTHON_DEST here once we set that correctly? + // OSX_BUNDLE_PYTHON_SITE_PACKAGES_DIR is provided via the build system. - wxString pythonMajorMinorVersion; - pythonMajorMinorVersion += wxT( PYTHON_MAJOR_MINOR_VERSION ); - - // Bundle Python folder (/Contents/Frameworks/Python.framework/Versions/x.y/lib/pythonx.y/site-packages) - // - pypath += wxT( ":" ) + Pgm().GetExecutablePath() + - wxT( "Contents/Frameworks/Python.framework/Versions/") + pythonMajorMinorVersion + - wxT("/lib/python") + pythonMajorMinorVersion - + wxT("/site-packages" ); + pypath += wxT( ":" ) + Pgm().GetExecutablePath() + wxT( OSX_BUNDLE_PYTHON_SITE_PACKAGES_DIR ); // Original content of $PYTHONPATH if( wxGetenv( wxT( "PYTHONPATH" ) ) != NULL )