Skip to content

Commit 41e7a93

Browse files
committed
patching python build to include tk support
1 parent 86dc45e commit 41e7a93

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

builds/build_python_runtime.sh

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ if [[ "${PYTHON_MAJOR_VERSION}" == +(3.9) ]]; then
192192
# - `lib/python3.9/config-3.9-x86_64-linux-gnu/libpython3.9.a`
193193
find "${INSTALL_DIR}" -type f -name '*.a' -print -exec strip --strip-unneeded '{}' +
194194
elif ! find "${INSTALL_DIR}" -type f -name '*.a' -print -exec false '{}' +; then
195-
abort "Unexpected static libraries found!"
195+
abort "Unexpected static libraries found!"
196196
fi
197197

198198
# Bundle the Tk runtime shared libraries and data files so they remain available on the Heroku
@@ -217,6 +217,25 @@ done
217217
cp --dereference --target-directory "${INSTALL_DIR}/lib/" --verbose "${TK_RUNTIME_LIBS[@]}"
218218
cp --archive --target-directory "${INSTALL_DIR}/lib/" --verbose "${TK_LIBRARY_DIRS[@]}"
219219

220+
# Bundle the transitive runtime dependencies of Tk that aren't guaranteed to exist on the Heroku
221+
# run images (such as the X11 libraries). Skip standard C library components that are expected to
222+
# be present on the run image already to avoid overriding critical system libraries.
223+
mapfile -t tk_dependency_paths < <(ldd "${TK_RUNTIME_LIBS[@]}" | awk '/=> \\// { print $3 }' | sort --unique)
224+
for tk_dependency_path in "${tk_dependency_paths[@]}"; do
225+
tk_dependency_basename="$(basename "${tk_dependency_path}")"
226+
case "${tk_dependency_basename}" in
227+
ld-linux-*.so.* | libc.so.* | libm.so.* | libdl.so.* | libpthread.so.* | librt.so.* | libutil.so.* | libnsl.so.*)
228+
continue
229+
;;
230+
esac
231+
232+
if [[ -e "${INSTALL_DIR}/lib/${tk_dependency_basename}" ]]; then
233+
continue
234+
fi
235+
236+
cp --dereference --target-directory "${INSTALL_DIR}/lib/" --verbose "${tk_dependency_path}"
237+
done
238+
220239
# Remove unneeded test directories, similar to the official Docker Python images:
221240
# https://github.com/docker-library/python
222241
# This is a no-op on Python 3.11+, since --disable-test-modules will have prevented

0 commit comments

Comments
 (0)