[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

[PATCH/RFC v3] Optionally allow binaries to run against older SQLite

From: Jonathan Nieder <jrnieder_at_gmail.com>
Date: Fri, 4 Nov 2011 01:24:17 -0500

Daniel Shahaf wrote:
> On Wednesday, November 02, 2011 4:25 PM, "Jonathan Nieder" <jrnieder_at_gmail.com> wrote:

>> I'm not very happy about putting -DSVN_SQLITE_COMPAT_VERSION in CFLAGS
>> --- does subversion have a config.h somewhere?
>
> http://s.apache.org/xy-problem --- Why do you think you need config.h?

Sorry, that was cryptic of me. The -DSVN_SQLITE_COMPAT_VERSION looked
lonely on the command line not surrounded by settings like -DHAVE_INT
and -DHAVE_PRINTF --- I was afraid there might be some other idiom I
was missing.

I'm happy keeping it in CFLAGS.

Your other comments looked reasonable, too. Details:

 - best to define SVN_SQLITE_MIN_VERSION_NUMBER in the header
   that uses it, instead of relying on sqlite.c being the only source
   file that does version checks. Fixed.

 - there were no unpatched instances of SQLITE_VERSION_NUMBER, but
   there was one unpatched instance of SQLITE_VERSION. So now I do

        -DSVN_SQLITE_MIN_VERSION_NUMBER=1002003
        -DSVN_SQLITE_MIN_VERSION="1.2.3"

 - it would be simple to make the configure script take care of the
   default for SVN_SQLITE_MIN_VERSION_NUMBER instead of the header
   doing so, but I prefer the latter since it means you can use
   "gcc -c" directly to build without remembering the -D
   option and still have a chance of the result working. So I've
   left that alone for now.

 - assignment to $2 in sqlite.m4 could be replaced by

        ver_num=`expr ...`
        $2=$ver_num

   or:

        result_var="$2"
        ...
        eval "$result_var=\$ver_num"

   Left untouched for now.

[[[
Introduce a --enable-sqlite-compatibility-version=X.Y.Z option for
./configure to allow people building Subversion to specify how old the
system being deployed on might be. Setting the compatibility version
to an older version turns on code in subversion that works around
infelicities in older versions and relaxes the version check ("SQLite
compiled for 3.7.4, but running with 3.7.3") at initialization time.

If the compat version is set to a version before the minimum supported
version (3.6.18), the build will fail early so the person building can
adjust her expectations.

The default for the compat version is the currently installed version,
so there should be no change in behavior for users not passing this
option to the configure script.

* subversion/include/private/svn_dep_compat.h
  (SVN_SQLITE_MIN_VERSION_NUMBER, SVN_SQLITE_MIN_VERSION): Set to
    SQLITE_VERSION_NUMBER, SQLITE_VERSION if undefined.
  (SQLITE_VERSION_AT_LEAST): Check SVN_SQLITE_MIN_VERSION_NUMBER instead
    of SQLITE_VERSION_NUMBER.

* subversion/libsvn_subr/sqlite.c (init_sqlite): Check sqlite version
    against SVN_SQLITE_MIN_VERSION_NUMBER instead of SQLITE_VERSION_NUMBER.

* configure.ac: Provide a --enable-sqlite-compatibility-version switch
    that sets SVN_SQLITE_MIN_VERSION_NUMBER and SVN_SQLITE_MIN_VERSION.

* build/ac-macros/sqlite.m4
  (SVN_SQLITE_VERNUM_PARSE): Make it reusable (in particular for
    configure.ac), by taking a version string and a variable to store the
    corresponding version number as arguments.
  (SVN_SQLITE_MIN_VERNUM_PARSE): Simplify by calling
    SVN_SQLITE_VERNUM_PARSE.
  (SVN_SQLITE_PKG_CONFIG): Adapt SVN_SQLITE_VERNUM_PARSE call to the new
    calling convention.
]]]

Index: subversion/include/private/svn_dep_compat.h
===================================================================
--- subversion/include/private/svn_dep_compat.h (revision 1197399)
+++ subversion/include/private/svn_dep_compat.h (working copy)
@@ -107,6 +107,32 @@
 #endif /* SERF_VERSION_AT_LEAST */
 
+/**
+ * By default, if libsvn is built against one version of SQLite
+ * and then run using an older version, svn will error out:
+ *
+ * svn: Couldn't perform atomic initialization
+ * svn: SQLite compiled for 3.7.4, but running with 3.7.3
+ *
+ * That can be annoying when building on a modern system in order
+ * to deploy on a less modern one. So these constants allow one
+ * to specify how old the system being deployed on might be.
+ * For example,
+ *
+ * EXTRA_CFLAGS += -DSVN_SQLITE_MIN_VERSION_NUMBER=3007003
+ * EXTRA_CFLAGS += '-DSVN_SQLITE_MIN_VERSION="3.7.3"'
+ *
+ * turns on code that works around infelicities in older versions
+ * as far back as 3.7.3 and relaxes the check at initialization time
+ * to permit them.
+ *
+ * @since New in 1.8.
+ */
+#ifndef SVN_SQLITE_MIN_VERSION_NUMBER
+#define SVN_SQLITE_MIN_VERSION_NUMBER SQLITE_VERSION_NUMBER
+#define SVN_SQLITE_MIN_VERSION SQLITE_VERSION
+#endif /* SVN_SQLITE_MIN_VERSION_NUMBER */
+
 /**
  * Check at compile time if the SQLite version is at least a certain
  * level.
  * @param major The major version component of the version checked
@@ -120,7 +146,7 @@
  */
 #ifndef SQLITE_VERSION_AT_LEAST
 #define SQLITE_VERSION_AT_LEAST(major,minor,patch) \
-((major*1000000 + minor*1000 + patch) <= SQLITE_VERSION_NUMBER)
+((major*1000000 + minor*1000 + patch) <= SVN_SQLITE_MIN_VERSION_NUMBER)
 #endif /* SQLITE_VERSION_AT_LEAST */
 
 #ifdef __cplusplus
Index: subversion/libsvn_subr/sqlite.c
===================================================================
--- subversion/libsvn_subr/sqlite.c (revision 1197399)
+++ subversion/libsvn_subr/sqlite.c (working copy)
@@ -606,12 +606,12 @@
 static svn_error_t *
 init_sqlite(void *baton, apr_pool_t *pool)
 {
- if (sqlite3_libversion_number() < SQLITE_VERSION_NUMBER)
+ if (sqlite3_libversion_number() < SVN_SQLITE_MIN_VERSION_NUMBER)
     {
       return svn_error_createf(
                     SVN_ERR_SQLITE_ERROR, NULL,
                     _("SQLite compiled for %s, but running with %s"),
- SQLITE_VERSION, sqlite3_libversion());
+ SVN_SQLITE_MIN_VERSION, sqlite3_libversion());
     }
 
 #if APR_HAS_THREADS
Index: configure.ac
===================================================================
--- configure.ac (revision 1197399)
+++ configure.ac (working copy)
@@ -172,6 +172,18 @@
 SVN_LIB_SQLITE(${SQLITE_MINIMUM_VER}, ${SQLITE_RECOMMENDED_VER},
                ${SQLITE_URL})
 
+AC_ARG_ENABLE(sqlite-compatibility-version,
+ AS_HELP_STRING([--enable-sqlite-compatibility-version=X.Y.Z],
+ [Allow binary to run against older SQLite]),
+ [sqlite_compat_ver=$enableval],[sqlite_compat_ver=no])
+
+if test -n "$sqlite_compat_ver" && test "$sqlite_compat_ver" != no; then
+ SVN_SQLITE_VERNUM_PARSE([$sqlite_compat_ver],
+ [sqlite_compat_ver_num])
+ CFLAGS="-DSVN_SQLITE_MIN_VERSION='\"$sqlite_compat_ver\"' $CFLAGS"
+ CFLAGS="-DSVN_SQLITE_MIN_VERSION_NUMBER=$sqlite_compat_ver_num $CFLAGS"
+fi
+
 dnl Set up a number of directories ---------------------
 
 dnl Create SVN_BINDIR for proper substitution
Index: build/ac-macros/sqlite.m4
===================================================================
--- build/ac-macros/sqlite.m4 (revision 1197399)
+++ build/ac-macros/sqlite.m4 (working copy)
@@ -106,7 +106,7 @@
       sqlite_version=`$PKG_CONFIG $SQLITE_PKGNAME --modversion --silence-errors`
 
       if test -n "$sqlite_version"; then
- SVN_SQLITE_VERNUM_PARSE
+ SVN_SQLITE_VERNUM_PARSE([$sqlite_version], [sqlite_ver_num])
 
         if test "$sqlite_ver_num" -ge "$sqlite_min_ver_num"; then
           AC_MSG_RESULT([$sqlite_version])
@@ -198,20 +198,22 @@
   fi
 ])
 
-dnl SVN_SQLITE_VERNUM_PARSE()
+dnl SVN_SQLITE_VERNUM_PARSE(version_string, result_var)
 dnl
-dnl Parse a x.y[.z] version string sqlite_version into a number sqlite_ver_num.
+dnl Parse a x.y[.z] version string version_string into a number result_var.
 AC_DEFUN(SVN_SQLITE_VERNUM_PARSE,
 [
- sqlite_major=`expr $sqlite_version : '\([[0-9]]*\)'`
- sqlite_minor=`expr $sqlite_version : '[[0-9]]*\.\([[0-9]]*\)'`
- sqlite_micro=`expr $sqlite_version : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'`
- if test -z "$sqlite_micro"; then
- sqlite_micro=0
+ version_string="$1"
+
+ major=`expr $version_string : '\([[0-9]]*\)'`
+ minor=`expr $version_string : '[[0-9]]*\.\([[0-9]]*\)'`
+ micro=`expr $version_string : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'`
+ if test -z "$micro"; then
+ micro=0
   fi
- sqlite_ver_num=`expr $sqlite_major \* 1000000 \
- \+ $sqlite_minor \* 1000 \
- \+ $sqlite_micro`
+ $2=`expr $major \* 1000000 \
+ \+ $minor \* 1000 \
+ \+ $micro`
 ])
 
 dnl SVN_SQLITE_MIN_VERNUM_PARSE()
@@ -220,12 +222,7 @@
 dnl sqlite_min_ver_num.
 AC_DEFUN(SVN_SQLITE_MIN_VERNUM_PARSE,
 [
- sqlite_min_major=`expr $SQLITE_MINIMUM_VER : '\([[0-9]]*\)'`
- sqlite_min_minor=`expr $SQLITE_MINIMUM_VER : '[[0-9]]*\.\([[0-9]]*\)'`
- sqlite_min_micro=`expr $SQLITE_MINIMUM_VER : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'`
- sqlite_min_ver_num=`expr $sqlite_min_major \* 1000000 \
- \+ $sqlite_min_minor \* 1000 \
- \+ $sqlite_min_micro`
+ SVN_SQLITE_VERNUM_PARSE([$SQLITE_MINIMUM_VER], [sqlite_min_ver_num])
 ])
 
 dnl SVN_DOWNLOAD_SQLITE()
Received on 2011-11-04 07:25:06 CET

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.