Visitar URL original
bpo-45774: Autoconfiscate SQLite detection (GH-29507) by erlend-aasland · Pull Request #29507 · python/cpython · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Prelim pkg-config support
  • Loading branch information
Erlend E. Aasland
Erlend E. Aasland committed Nov 16, 2021
commit 1a33d5c192e71397883063ad02792fcac7718e11
9 changes: 9 additions & 0 deletions Makefile.pre.in
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,14 @@ LIBEXPAT_HEADERS= \

LIBEXPAT_A= Modules/expat/libexpat.a

#
# SQLite stuff
#

# For setup.py
PY_SQLITE_CFLAGS=@PY_SQLITE_CFLAGS@
PY_SQLITE_LDFLAGS=@PY_SQLITE_LDFLAGS@
Comment thread
erlend-aasland marked this conversation as resolved.
Outdated

#########################################################################
# Rules

Expand Down Expand Up @@ -2471,6 +2479,7 @@ MODULE__SHA512_DEPS=$(srcdir)/Modules/hashlib.h
MODULE__SOCKET_DEPS=$(srcdir)/Modules/socketmodule.h
MODULE__SSL_DEPS=$(srcdir)/Modules/_ssl.h $(srcdir)/Modules/_ssl/cert.c $(srcdir)/Modules/_ssl/debughelpers.c $(srcdir)/Modules/_ssl/misc.c $(srcdir)/Modules/_ssl_data.h $(srcdir)/Modules/_ssl_data_111.h $(srcdir)/Modules/_ssl_data_300.h $(srcdir)/Modules/socketmodule.h
MODULE__TESTCAPI_DEPS=$(srcdir)/Modules/testcapi_long.h
MODULE__SQLITE3_DEPS=$(srcdir)/Modules/_sqlite/connection.h $(srcdir)/Modules/_sqlite/cursor.h $(srcdir)/Modules/_sqlite/microprotocols.h $(srcdir)/Modules/_sqlite/module.h $(srcdir)/Modules/_sqlite/prepare_protocol.h $(srcdir)/Modules/_sqlite/row.h $(srcdir)/Modules/_sqlite/util.h

# IF YOU PUT ANYTHING HERE IT WILL GO AWAY
# Local Variables:
Expand Down
2 changes: 1 addition & 1 deletion Modules/Setup
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ time timemodule.c
#_dbm _dbmmodule.c -lgdbm_compat -DUSE_GDBM_COMPAT
#_gdbm _gdbmmodule.c -lgdbm
#_lzma _lzmamodule.c -llzma
#_sqlite3 _sqlite/connection.c _sqlite/cursor.c _sqlite/microprotocols.c _sqlite/module.c _sqlite/prepare_protocol.c _sqlite/row.c _sqlite/statement.c _sqlite/util.c -lsqlite3
#_sqlite3 _sqlite/connection.c _sqlite/cursor.c _sqlite/microprotocols.c _sqlite/module.c _sqlite/prepare_protocol.c _sqlite/row.c _sqlite/statement.c _sqlite/util.c $(PY_SQLITE_LDFLAGS)
Comment thread
erlend-aasland marked this conversation as resolved.
Outdated
#_uuid _uuidmodule.c -luuid
#zlib zlibmodule.c -lz

Expand Down
22 changes: 20 additions & 2 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,8 @@ DFLAGS
DTRACE
TCLTK_LIBS
TCLTK_INCLUDES
PY_SQLITE_LDFLAGS
PY_SQLITE_CFLAGS
LIBMPDEC_INTERNAL
LIBMPDEC_LDFLAGS
LIBMPDEC_CFLAGS
Expand Down Expand Up @@ -10921,10 +10923,21 @@ if test "$have_glibc_memmove_bug" = yes; then
as_fn_append LIBMPDEC_CFLAGS " -U_FORTIFY_SOURCE"
fi



if test ! -z "$PKG_CONFIG"; then
as_fn_append PY_SQLITE_CFLAGS "`"$PKG_CONFIG" sqlite3 --cflags-only-I 2>/dev/null`"
as_fn_append PY_SQLITE_LDFLAGS "`"$PKG_CONFIG" sqlite3 --libs-only-L 2>/dev/null`"
fi

save_CFLAGS=$CFLAGS
save_LDFLAGS=$LDFLAGS
as_fn_append CFLAGS "$PY_SQLITE_CFLAGS"
as_fn_append LDFLAGS "$PY_SQLITE_LDFLAGS"

ac_fn_c_check_header_mongrel "$LINENO" "sqlite3.h" "ac_cv_header_sqlite3_h" "$ac_includes_default"
if test "x$ac_cv_header_sqlite3_h" = xyes; then :

save_LIBS=$LIBS
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for sqlite3_open_v2 in -lsqlite3" >&5
$as_echo_n "checking for sqlite3_open_v2 in -lsqlite3... " >&6; }
if ${ac_cv_lib_sqlite3_sqlite3_open_v2+:} false; then :
Expand Down Expand Up @@ -10983,8 +10996,11 @@ main ()
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :


$as_echo "#define HAVE_LIBSQLITE3 1" >>confdefs.h

as_fn_append PY_SQLITE_LDFLAGS " -lsqlite3"

fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext

Expand Down Expand Up @@ -11032,12 +11048,14 @@ else
have_sqlite3_load_extension=no
fi

LIBS=$save_LIBS

fi



CFLAGS=$save_CFLAGS
LDFLAGS=$save_LDFLAGS

# Check for support for loadable sqlite extensions
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for --enable-loadable-sqlite-extensions" >&5
$as_echo_n "checking for --enable-loadable-sqlite-extensions... " >&6; }
Expand Down
24 changes: 20 additions & 4 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -3165,9 +3165,20 @@ if test "$have_glibc_memmove_bug" = yes; then
AS_VAR_APPEND([LIBMPDEC_CFLAGS], [" -U_FORTIFY_SOURCE"])
fi

dnl Check for SQLite library
dnl Check for SQLite library. Use pkg-config if available.
AC_SUBST([PY_SQLITE_CFLAGS])
AC_SUBST([PY_SQLITE_LDFLAGS])
if test ! -z "$PKG_CONFIG"; then
AS_VAR_APPEND([PY_SQLITE_CFLAGS], ["`"$PKG_CONFIG" sqlite3 --cflags-only-I 2>/dev/null`"])
AS_VAR_APPEND([PY_SQLITE_LDFLAGS], ["`"$PKG_CONFIG" sqlite3 --libs-only-L 2>/dev/null`"])
Comment thread
erlend-aasland marked this conversation as resolved.
Outdated
fi

AS_VAR_COPY([save_CFLAGS], [CFLAGS])
AS_VAR_COPY([save_LDFLAGS], [LDFLAGS])
AS_VAR_APPEND([CFLAGS], ["$PY_SQLITE_CFLAGS"])
AS_VAR_APPEND([LDFLAGS], ["$PY_SQLITE_LDFLAGS"])

AC_CHECK_HEADER([sqlite3.h], [
AS_VAR_COPY([save_LIBS], [LIBS])
AC_CHECK_LIB([sqlite3], [sqlite3_open_v2], [
AC_COMPILE_IFELSE([
AC_LANG_PROGRAM([
Expand All @@ -3176,14 +3187,19 @@ AC_CHECK_HEADER([sqlite3.h], [
# error "SQLite 3.7.15 or higher required"
#endif
], [])
], [AC_DEFINE([HAVE_LIBSQLITE3], [1], [Define if SQLite > 3.7.15 is found])])
], [
AC_DEFINE([HAVE_LIBSQLITE3], [1], [Define if SQLite > 3.7.15 is found])
AS_VAR_APPEND([PY_SQLITE_LDFLAGS], [" -lsqlite3"])
])
])
AC_CHECK_LIB([sqlite3], [sqlite3_load_extension],
[have_sqlite3_load_extension=yes],
[have_sqlite3_load_extension=no])
AS_VAR_COPY([LIBS], [save_LIBS])
])

AS_VAR_COPY([CFLAGS], [save_CFLAGS])
AS_VAR_COPY([LDFLAGS], [save_LDFLAGS])

# Check for support for loadable sqlite extensions
AC_MSG_CHECKING(for --enable-loadable-sqlite-extensions)
AC_ARG_ENABLE(loadable-sqlite-extensions,
Expand Down
21 changes: 17 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -1359,7 +1359,13 @@ def detect_sqlite(self):
self.missing.append("_sqlite3")
return

sqlite_srcs = [
cflags = parse_cflags(sysconfig.get_config_var("PY_SQLITE_CFLAGS"))
include_dirs, define_macros, undef_macros, extra_compile_args = cflags

ldflags = parse_ldflags(sysconfig.get_config_var("PY_SQLITE_LDFLAGS"))
library_dirs, libraries, extra_link_args = ldflags

sources = [
"_sqlite/connection.c",
"_sqlite/cursor.c",
"_sqlite/microprotocols.c",
Expand All @@ -1369,9 +1375,16 @@ def detect_sqlite(self):
"_sqlite/statement.c",
"_sqlite/util.c",
]
self.add(Extension("_sqlite3", sqlite_srcs,
include_dirs=["Modules/_sqlite"],
libraries=["sqlite3",]))
library_dirs.append("Modules/_sqlite")
self.add(Extension("_sqlite3",
include_dirs=include_dirs,
define_macros=define_macros,
undef_macros=undef_macros,
extra_compile_args=extra_compile_args,
library_dirs=library_dirs,
libraries=libraries,
extra_link_args=extra_link_args,
sources=sources))

def detect_platform_specific_exts(self):
# Unix-only modules
Expand Down