Howdy guys,

One of the TODO items I put in the swig-py3 branch README is to provide a
more useful error message if the user tries to build the swig-py bindings,
but they are disabled/failed to configure. There are several failure modes
that would prevent the Python binding from building, however currently if
they are not successfully configured and the user types 'make swig-py' this
is what they get:

$ make swig-py
/usr/bin/swig
-I/home/tscurti/working/oss/subversion/swig-py3-4/py2-build/subversion
-I/home/tscurti/working/oss/subversion/swig-py3-4/py2-build/../subversion/include
-I/home/tscurti/working/oss/subversion/swig-py3-4/py2-build/../subversion/bindings/swig
-I/home/tscurti/working/oss/subversion/swig-py3-4/py2-build/../subversion/bindings/swig/include
-I/home/tscurti/working/oss/subversion/swig-py3-4/py2-build/../subversion/bindings/swig/proxy
-I/home/tscurti/working/oss/subversion/swig-py3-4/py2-build/subversion/bindings/swig/proxy
-I/usr/include/apr-1  -I/usr/include/apr-1   none  -o
subversion/bindings/swig/python/svn_client.c
../subversion/bindings/swig/svn_client.i
swig error : Unrecognized option none
Use 'swig -help' for available options.
make: *** [../build-outputs.mk:286:
subversion/bindings/swig/python/svn_client.c] Error 1

Which isn't very helpful. I even kinda knew this, and it was still a
confusing message when I first tried doing a test build on the macos
BuildBot recently. (Luckily Brane dug through the log quickly and found the
issue [1].)

So instead with the attached patch you get something like:

$ make swig-py
SWIG Python bindings not configured, py3c library not found
make: *** [Makefile:924: verify-swig-py] Error 1

or for the more generic case

$ make swig-py
SWIG Python bindings not configured, check config.log for details
make: *** [Makefile:924: verify-swig-py] Error 1

I think it is clear these errors are more meaningful, but I'd like thoughts
on:

1) Whether I should bother
2) My implementation
3) Whether you think I should add similar functionality to the other (SWIG)
bindings

Proposed patch attached.

Troy
--
1: https://wilderness.apache.org/channels/?f=svn-dev/2018-12-27
Index: Makefile.in
===================================================================
--- Makefile.in	(revision 1849851)
+++ Makefile.in	(working copy)
@@ -150,6 +150,7 @@
 SWIG_PY_COMPILE = @SWIG_PY_COMPILE@
 SWIG_PY_LINK = @SWIG_PY_LINK@
 SWIG_PY_LIBS = @SWIG_PY_LIBS@
+SWIG_PY_ERRMSG = @SWIG_PY_ERRMSG@
 SWIG_PL_INCLUDES = @SWIG_PL_INCLUDES@
 SWIG_RB_INCLUDES = @SWIG_RB_INCLUDES@ -I$(SWIG_SRC_DIR)/ruby/libsvn_swig_ruby
 SWIG_RB_COMPILE = @SWIG_RB_COMPILE@
@@ -419,6 +420,8 @@
 extraclean: local-extraclean
 install: local-install revision-install
 
+swig-py: verify-swig-py
+
 @INCLUDE_OUTPUTS@
 
 local-all: @BUILD_RULES@ @TRANSFORM_LIBTOOL_SCRIPTS@
@@ -917,6 +920,12 @@
 $(SWIG_PY_DIR)/libsvn:
 	mkdir $(SWIG_PY_DIR)/libsvn
 
+verify-swig-py:
+	@if test -n "$(SWIG_PY_ERRMSG)"; then \
+    echo "$(SWIG_PY_ERRMSG)"; \
+    exit 1; \
+  fi
+
 copy-swig-py: autogen-swig-py $(SWIG_PY_DIR)/libsvn
 	@for f in $(SWIG_PY_SRC_DIR)/*.py $(SWIG_PY_DIR)/*.py; do \
 	  ! [ -f "$$f" ] || cp -pf $$f $(SWIG_PY_DIR)/libsvn; \
Index: build/ac-macros/swig.m4
===================================================================
--- build/ac-macros/swig.m4	(revision 1849851)
+++ build/ac-macros/swig.m4	(working copy)
@@ -103,6 +103,7 @@
   SWIG_PY_COMPILE="none"
   SWIG_PY_LINK="none"
   SWIG_PY_OPTS="none"
+  SWIG_PY_ERRMSG="SWIG Python bindings not configured, check config.log for details"
   if test "$PYTHON" != "none"; then
     AC_MSG_NOTICE([Configuring python swig binding])
 
@@ -112,6 +113,7 @@
     SWIG_PY_INCLUDES="\$(SWIG_INCLUDES) $ac_cv_python_includes"
 
     if test "$ac_cv_python_includes" = "none"; then
+      SWIG_PY_ERRMSG="SWIG Python bindings not configured, no distutils found"
       AC_MSG_WARN([python bindings cannot be built without distutils module])
     else
 
@@ -125,11 +127,13 @@
       CPPFLAGS="$save_cppflags"
 
       if test "$python_header_found" = "no"; then
+        SWIG_PY_ERRMSG="SWIG Python bindings not configured, no Python.h found"
         AC_MSG_WARN([Python.h not found; disabling python swig bindings])
       else
         SVN_PY3C()
 
         if test "$py3c_found" = "no"; then
+          SWIG_PY_ERRMSG="SWIG Python bindings not configured, py3c library not found"
           AC_MSG_WARN([py3c library not found; disabling python swig bindings])
         else
           AC_CACHE_CHECK([for compiling Python extensions], [ac_cv_python_compile],[
@@ -193,6 +197,9 @@
                              ["$svn_cv_pycfmt_apr_int64_t"],
                              [Define to the Python/C API format character suitable]
                              [ for apr_int64_t])
+
+          dnl SWIG Python bindings successfully configured, clear the error message
+          SWIG_PY_ERRMSG=""
         fi
             
       fi
@@ -341,6 +348,7 @@
   AC_SUBST(SWIG_PY_LINK)
   AC_SUBST(SWIG_PY_LIBS)
   AC_SUBST(SWIG_PY_OPTS)
+  AC_SUBST(SWIG_PY_ERRMSG)
   AC_SUBST(SWIG_PL_INCLUDES)
   AC_SUBST(SWIG_PL_LINK)
   AC_SUBST(SWIG_RB_LINK)

Reply via email to