8000 bpo-45723: Add helpers for save/restore env (GH-29637) by erlend-aasland · Pull Request #29637 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-45723: Add helpers for save/restore env (GH-29637) #29637

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Nov 22, 2021
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
Next Next commit
bpo-45723: Add helpers for save/restore env
PoC: Apply to SQLite check.
  • Loading branch information
Erlend E. Aasland committed Nov 19, 2021
commit 65796278cba5fd4a3beba20d91a8cc56a847bb84
40 changes: 22 additions & 18 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -2806,6 +2806,7 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu




if test "$srcdir" != . -a "$srcdir" != "$(pwd)"; then
# If we're building out-of-tree, we need to make sure the following
# resources get picked up before their $srcdir counterparts.
Expand Down Expand Up @@ -11022,16 +11023,17 @@ fi
as_fn_append LIBSQLITE3_CFLAGS ' -I$(srcdir)/Modules/_sqlite'

save_CFLAGS=$CFLAGS
save_CPPFLAGS=$CPPFLAGS
save_LDFLAGS=$LDFLAGS
save_LIBS=$LIBS
CPPFLAGS="$LIBSQLITE3_CFLAGS $CFLAGS"
LDFLAGS="$LIBSQLITE3_LIBS $LDFLAGS"
save_CPPFLAGS=$CPPFLAGS
save_LDFLAGS=$LDFLAGS
save_LIBS=$LIBS

CPPFLAGS="$LIBSQLITE3_CFLAGS $CFLAGS"
LDFLAGS="$LIBSQLITE3_LIBS $LDFLAGS"

ac_fn_c_check_header_mongrel "$LINENO" "sqlite3.h" "ac_cv_header_sqlite3_h" "$ac_includes_default"
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 :

{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for sqlite3_open_v2 in -lsqlite3" >&5
{ $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 :
$as_echo_n "(cached) " >&6
Expand Down Expand Up @@ -11069,15 +11071,15 @@ fi
$as_echo "$ac_cv_lib_sqlite3_sqlite3_open_v2" >&6; }
if test "x$ac_cv_lib_sqlite3_sqlite3_open_v2" = xyes; then :

have_sqlite3=yes
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
have_sqlite3=yes
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */


#include <sqlite3.h>
#if SQLITE_VERSION_NUMBER < 3007015
# error "SQLite 3.7.15 or higher required"
#endif
#include <sqlite3.h>
#if SQLITE_VERSION_NUMBER < 3007015
# error "SQLite 3.7.15 or higher required"
#endif

int
main ()
Expand All @@ -11099,7 +11101,7 @@ else
have_sqlite3=no
fi

{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for sqlite3_load_extension in -lsqlite3" >&5
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for sqlite3_load_extension in -lsqlite3" >&5
$as_echo_n "checking for sqlite3_load_extension in -lsqlite3... " >&6; }
if ${ac_cv_lib_sqlite3_sqlite3_load_extension+:} false; then :
$as_echo_n "(cached) " >&6
Expand Down Expand Up @@ -11149,10 +11151,12 @@ fi



CFLAGS=$save_CFLAGS
CPPFLAGS=$save_CPPFLAGS
LDFLAGS=$save_LDFLAGS
LIBS=$save_LIBS
CFLAGS=$save_CFLAGS
CPPFLAGS=$save_CPPFLAGS
LDFLAGS=$save_LDFLAGS
LIBS=$save_LIBS



# Check for support for loadable sqlite extensions
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for --enable-loadable-sqlite-extensions" >&5
Expand Down
74 changes: 46 additions & 28 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,32 @@ m4_ifdef(
[AC_MSG_ERROR([Please install pkgconf's m4 macro package and re-run autoreconf])]
)dnl

dnl Helpers for saving and restoring environment variables:
dnl - _SAVE_VAR([VAR]) Helper for SAVE_ENV; stores VAR as save_VAR
dnl - _RESTORE_VAR([VAR]) Helper for RESTORE_ENV; restores VAR from save_VAR
dnl - SAVE_ENV Saves CFLAGS, LDFLAGS, LIBS, and CPPFLAGS
dnl - RESTORE_ENV Restores CFLAGS, LDFLAGS, LIBS, and CPPFLAGS
dnl - WITH_SAVE_ENV([SCRIPT]) Runs SCRIPT wrapped with SAVE_ENV/RESTORE_ENV
AC_DEFUN([_SAVE_VAR], [AS_VAR_COPY([save_][$1], [$1])])dnl
AC_DEFUN([_RESTORE_VAR], [AS_VAR_COPY([$1], [save_][$1])])dnl
AC_DEFUN([SAVE_ENV],
[_SAVE_VAR([CFLAGS])]
[_SAVE_VAR([CPPFLAGS])]
[_SAVE_VAR([LDFLAGS])]
[_SAVE_VAR([LIBS])]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the indention adds some extra space to the output:

save_CFLAGS=$CFLAGS
  save_CPPFLAGS=$CPPFLAGS
  save_LDFLAGS=$LDFLAGS
  save_LIBS=$LIBS

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. We can tweak the new macros to further minimise configure diffs. I think that could be worth it, as it would be easier to review future PRs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it look better with dcc2ba9 applied?

)dnl
AC_DEFUN([RESTORE_ENV],
[_RESTORE_VAR([CFLAGS])]
[_RESTORE_VAR([CPPFLAGS])]
[_RESTORE_VAR([LDFLAGS])]
[_RESTORE_VAR([LIBS])]
)dnl
AC_DEFUN([WITH_SAVE_ENV],
[SAVE_ENV]
[$1]
[RESTORE_ENV]
)dnl

AC_SUBST(BASECPPFLAGS)
if test "$srcdir" != . -a "$srcdir" != "$(pwd)"; then
# If we're building out-of-tree, we need to make sure the following
Expand Down Expand Up @@ -3175,34 +3201,26 @@ PKG_CHECK_MODULES(
AS_VAR_APPEND([LIBSQLITE3_CFLAGS], [' -I$(srcdir)/Modules/_sqlite'])

dnl bpo-45774/GH-29507: The CPP check in AC_CHECK_HEADER can fail on FreeBSD,
dnl hence CPPFLAGS instead of CFLAGS. We still need to save CFLAGS, because it
dnl is touched by AC_CHECK_HEADER.
AS_VAR_COPY([save_CFLAGS], [CFLAGS])
AS_VAR_COPY([save_CPPFLAGS], [CPPFLAGS])
AS_VAR_COPY([save_LDFLAGS], [LDFLAGS])
AS_VAR_COPY([save_LIBS], [LIBS])
CPPFLAGS="$LIBSQLITE3_CFLAGS $CFLAGS"
LDFLAGS="$LIBSQLITE3_LIBS $LDFLAGS"

AC_CHECK_HEADER([sqlite3.h], [
AC_CHECK_LIB([sqlite3], [sqlite3_open_v2], [
have_sqlite3=yes
AC_COMPILE_IFELSE([
AC_LANG_PROGRAM([
#include <sqlite3.h>
#if SQLITE_VERSION_NUMBER < 3007015
# error "SQLite 3.7.15 or higher required"
#endif
], [])
], [have_supported_sqlite3=yes], [have_supported_sqlite3=no])
], [have_sqlite3=no])
AC_CHECK_LIB([sqlite3], [sqlite3_load_extension])
])

AS_VAR_COPY([CFLAGS], [save_CFLAGS])
AS_VAR_COPY([CPPFLAGS], [save_CPPFLAGS])
AS_VAR_COPY([LDFLAGS], [save_LDFLAGS])
AS_VAR_COPY([LIBS], [save_LIBS])
dnl hence CPPFLAGS instead of CFLAGS.
WITH_SAVE_ENV(
CPPFLAGS="$LIBSQLITE3_CFLAGS $CFLAGS"
LDFLAGS="$LIBSQLITE3_LIBS $LDFLAGS"

AC_CHECK_HEADER([sqlite3.h], [
AC_CHECK_LIB([sqlite3], [sqlite3_open_v2], [
have_sqlite3=yes
AC_COMPILE_IFELSE([
AC_LANG_PROGRAM([
#include <sqlite3.h>
#if SQLITE_VERSION_NUMBER < 3007015
# error "SQLite 3.7.15 or higher required"
#endif
], [])
], [have_supported_sqlite3=yes], [have_supported_sqlite3=no])
], [have_sqlite3=no])
AC_CHECK_LIB([sqlite3], [sqlite3_load_extension])
])
)

# Check for support for loadable sqlite extensions
AC_MSG_CHECKING(for --enable-loadable-sqlite-extensions)
Expand Down
0