Skip to content

Commit c712997

Browse files
authored
Preserve Python executables (#369)
1 parent 254ef66 commit c712997

3 files changed

Lines changed: 18 additions & 2 deletions

File tree

‎Makefile‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,10 @@ $$(PYTHON_XCFRAMEWORK-$(os))/Info.plist: \
641641
2>&1 | tee -a $$(PYTHON_INSTALL-macosx)/python-$(os).codesign.log
642642
find $$(PYTHON_FRAMEWORK-macosx) -name "*.so" -type f -exec codesign -s - --preserve-metadata=identifier,entitlements,flags,runtime -f {} \; \
643643
2>&1 | tee -a $$(PYTHON_INSTALL-macosx)/python-$(os).codesign.log
644+
find $$(PYTHON_INSTALL_VERSION-macosx)/bin -type f -perm +111 -exec sh -c 'file "$$$$1" | grep -q Mach-O' _ {} \; -exec codesign -s - --preserve-metadata=identifier,entitlements,flags,runtime -f {} \; \
645+
2>&1 | tee -a $$(PYTHON_INSTALL-macosx)/python-$(os).codesign.log
646+
codesign -s - --preserve-metadata=identifier,entitlements,flags,runtime -f $$(PYTHON_INSTALL_VERSION-macosx)/Resources/Python.app \
647+
2>&1 | tee -a $$(PYTHON_INSTALL-macosx)/python-$(os).codesign.log
644648
codesign -s - --preserve-metadata=identifier,entitlements,flags,runtime -f $$(PYTHON_FRAMEWORK-macosx) \
645649
2>&1 | tee -a $$(PYTHON_INSTALL-macosx)/python-$(os).codesign.log
646650

‎patch/Python/release.macOS.exclude‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
._Python
77
._Resources
88
Resources/._Python.app
9-
Resources/Python.app
109
Versions/._Current
1110
Versions/*/.__CodeSignature
1211
Versions/*/._bin
@@ -17,7 +16,9 @@ Versions/*/._include
1716
Versions/*/._lib
1817
Versions/*/._Resources
1918
Versions/*/._share
20-
Versions/*/bin
19+
Versions/*/bin/idle*
20+
Versions/*/bin/pydoc*
21+
Versions/*/bin/python*-config
2122
Versions/*/etc
2223
Versions/*/Frameworks
2324
Versions/*/lib/python*/idlelib

‎patch/make-relocatable.sh‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,15 @@ for module in `find . -name "*.dylib" -type f -o -name "*.so" -type f`; do
2424
done
2525
fi
2626
done
27+
for exe in `find bin Resources/Python.app/Contents/MacOS -type f -perm +111`; do
28+
if [ "$(otool -L ${exe} 2>/dev/null | grep -c /Library/Frameworks/Python.framework)" != "0" ]; then
29+
echo Rewrite references to Python library in ${exe}
30+
install_name_tool -change /Library/Frameworks/Python.framework/Versions/${PYTHON_VER}/Python @rpath/Python.framework/Versions/${PYTHON_VER}/Python ${exe}
31+
# Add an rpath pointing at the directory that contains Python.framework
32+
# (one level up per path component, plus 3 for Python.framework/Versions/X.Y)
33+
depth=$(( $(echo ${exe} | tr -cd '/' | wc -c) + 3 ))
34+
rpath=@executable_path$(printf '/..%.0s' $(seq ${depth}))
35+
install_name_tool -add_rpath ${rpath} ${exe}
36+
fi
37+
done
2738
popd

0 commit comments

Comments
 (0)