From a80ec6ff2bdb9367ac7d5c50c3ab7d83877bd7bb Mon Sep 17 00:00:00 2001 From: Lukas Slebodnik Date: Tue, 10 Feb 2015 17:22:03 +0100 Subject: [PATCH 12/15] BUILD: Add possibility to build python{2,3} bindings Resolves: https://fedorahosted.org/sssd/ticket/2574 Reviewed-by: Stephen Gallagher --- Makefile.am | 196 ++++++++++++++++++++++++++++++++--------- configure.ac | 49 +++++++++-- contrib/sssd.spec.in | 4 + src/conf_macros.m4 | 39 +++++--- src/tests/pyhbac-test.py | 22 ++++- src/tests/pysss_murmur-test.py | 22 ++++- 6 files changed, 267 insertions(+), 65 deletions(-) diff --git a/Makefile.am b/Makefile.am index 176c193d97389f14da6f202fef46579b2e2a2e59..14ee3dd528f0d89b3e0d2afdb99313e6c570234f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -299,12 +299,22 @@ noinst_LTLIBRARIES = pkglib_LTLIBRARIES = -if BUILD_PYTHON_BINDINGS -pyexec_LTLIBRARIES = \ - pysss.la \ - pyhbac.la \ - pysss_murmur.la \ - pysss_nss_idmap.la +if BUILD_PYTHON2_BINDINGS +py2exec_LTLIBRARIES = \ + _py2sss.la \ + _py2hbac.la \ + _py2sss_murmur.la \ + _py2sss_nss_idmap.la \ + $(NULL) +endif + +if BUILD_PYTHON3_BINDINGS +py3exec_LTLIBRARIES = \ + _py3sss.la \ + _py3hbac.la \ + _py3sss_murmur.la \ + _py3sss_nss_idmap.la \ + $(NULL) endif dist_noinst_SCRIPTS = \ @@ -2782,58 +2792,109 @@ sssd_pac_plugin_la_LDFLAGS = \ -avoid-version \ -module -if BUILD_PYTHON_BINDINGS +# python[23] bindings pysss_la_SOURCES = \ $(SSSD_TOOLS_OBJ) \ src/python/pysss.c -pysss_la_CFLAGS = \ - $(AM_CFLAGS) \ - $(PYTHON_CFLAGS) -pysss_la_LIBADD = \ - $(SSSD_INTERNAL_LTLIBS) \ - $(PYTHON_BINDINGS_LIBS) \ - $(PYTHON_LIBS) pysss_la_LDFLAGS = \ -avoid-version \ -module +_py2sss_la_SOURCES = $(pysss_la_SOURCES) +_py2sss_la_CFLAGS = \ + $(AM_CFLAGS) \ + $(PYTHON2_CFLAGS) +_py2sss_la_LIBADD = \ + $(SSSD_INTERNAL_LTLIBS) \ + $(PYTHON_BINDINGS_LIBS) \ + $(PYTHON2_LIBS) +_py2sss_la_LDFLAGS = $(pysss_la_LDFLAGS) + +_py3sss_la_SOURCES = $(pysss_la_SOURCES) +_py3sss_la_CFLAGS = \ + $(AM_CFLAGS) \ + $(PYTHON3_CFLAGS) +_py3sss_la_LIBADD = \ + $(SSSD_INTERNAL_LTLIBS) \ + $(PYTHON_BINDINGS_LIBS) \ + $(PYTHON3_LIBS) +_py3sss_la_LDFLAGS = $(pysss_la_LDFLAGS) + + pyhbac_la_SOURCES = \ src/python/pyhbac.c \ src/util/sss_python.c -pyhbac_la_CFLAGS = \ - $(AM_CFLAGS) \ - $(PYTHON_CFLAGS) -pyhbac_la_LIBADD = \ - $(PYTHON_LIBS) \ - libipa_hbac.la pyhbac_la_LDFLAGS = \ -avoid-version \ -module +_py2hbac_la_SOURCES = $(pyhbac_la_SOURCES) +_py2hbac_la_CFLAGS = \ + $(AM_CFLAGS) \ + $(PYTHON2_CFLAGS) +_py2hbac_la_LIBADD = \ + $(PYTHON2_LIBS) \ + libipa_hbac.la +_py2hbac_la_LDFLAGS = $(pyhbac_la_LDFLAGS) + +_py3hbac_la_SOURCES = $(pyhbac_la_SOURCES) +_py3hbac_la_CFLAGS = \ + $(AM_CFLAGS) \ + $(PYTHON3_CFLAGS) +_py3hbac_la_LIBADD = \ + $(PYTHON3_LIBS) \ + libipa_hbac.la +_py3hbac_la_LDFLAGS = $(pyhbac_la_LDFLAGS) + + pysss_murmur_la_SOURCES = \ src/python/pysss_murmur.c \ src/util/murmurhash3.c -pysss_murmur_la_CFLAGS = \ - $(AM_CFLAGS) \ - $(PYTHON_CFLAGS) -pysss_murmur_la_LIBADD = \ - $(PYTHON_LIBS) pysss_murmur_la_LDFLAGS = \ -avoid-version \ -module +_py2sss_murmur_la_SOURCES = $(pysss_murmur_la_SOURCES) +_py2sss_murmur_la_CFLAGS = \ + $(AM_CFLAGS) \ + $(PYTHON2_CFLAGS) +_py2sss_murmur_la_LIBADD = \ + $(PYTHON2_LIBS) +_py2sss_murmur_la_LDFLAGS = $(pysss_murmur_la_LDFLAGS) + +_py3sss_murmur_la_SOURCES = $(pysss_murmur_la_SOURCES) +_py3sss_murmur_la_CFLAGS = \ + $(AM_CFLAGS) \ + $(PYTHON3_CFLAGS) +_py3sss_murmur_la_LIBADD = \ + $(PYTHON3_LIBS) +_py3sss_murmur_la_LDFLAGS = $(pysss_murmur_la_LDFLAGS) + + pysss_nss_idmap_la_SOURCES = \ src/python/pysss_nss_idmap.c -pysss_nss_idmap_la_CFLAGS = \ - $(AM_CFLAGS) \ - $(PYTHON_CFLAGS) -pysss_nss_idmap_la_LIBADD = \ - $(PYTHON_LIBS) \ - libsss_nss_idmap.la pysss_nss_idmap_la_LDFLAGS = \ -avoid-version \ -module -endif + +_py2sss_nss_idmap_la_SOURCES = $(pysss_nss_idmap_la_SOURCES) +_py2sss_nss_idmap_la_CFLAGS = \ + $(AM_CFLAGS) \ + $(PYTHON2_CFLAGS) +_py2sss_nss_idmap_la_LIBADD = \ + $(PYTHON2_LIBS) \ + libsss_nss_idmap.la +_py2sss_nss_idmap_la_LDFLAGS = $(pysss_nss_idmap_la_LDFLAGS) + +_py3sss_nss_idmap_la_SOURCES = $(pysss_nss_idmap_la_SOURCES) +_py3sss_nss_idmap_la_CFLAGS = \ + $(AM_CFLAGS) \ + $(PYTHON3_CFLAGS) +_py3sss_nss_idmap_la_LIBADD = \ + $(PYTHON3_LIBS) \ + libsss_nss_idmap.la +_py3sss_nss_idmap_la_LDFLAGS = $(pysss_nss_idmap_la_LDFLAGS) +# end of python[23] bindings if BUILD_CIFS_IDMAP_PLUGIN cifs_idmap_sss_la_SOURCES = \ @@ -2995,17 +3056,51 @@ SSSSCONFIG_MODULES = endif all-local: ldb_mod_test_dir $(SSSDCONFIG_MODULES) -if BUILD_PYTHON_BINDINGS - cd $(builddir)/src/config; $(PYTHON) setup.py build --build-base $(abs_builddir)/src/config +if BUILD_PYTHON2_BINDINGS + cd $(builddir)/src/config; \ + $(PYTHON2) setup.py build --build-base $(abs_builddir)/src/config +endif +if BUILD_PYTHON3_BINDINGS + cd $(builddir)/src/config; \ + $(PYTHON3) setup.py build --build-base $(abs_builddir)/src/config endif install-exec-hook: installsssddirs -if BUILD_PYTHON_BINDINGS +if BUILD_PYTHON2_BINDINGS if [ "$(DESTDIR)" = "" ]; then \ - cd $(builddir)/src/config; $(PYTHON) setup.py build --build-base $(abs_builddir)/src/config install $(DISTSETUPOPTS) --prefix=$(PYTHON_PREFIX) --record=$(abs_builddir)/src/config/.files; \ + cd $(builddir)/src/config; \ + $(PYTHON2) setup.py build --build-base $(abs_builddir)/src/config \ + install $(DISTSETUPOPTS) --prefix=$(PYTHON2_PREFIX) \ + --record=$(abs_builddir)/src/config/.files2; \ else \ - cd $(builddir)/src/config; $(PYTHON) setup.py build --build-base $(abs_builddir)/src/config install $(DISTSETUPOPTS) --prefix=$(PYTHON_PREFIX) --root=$(DESTDIR) --record=$(abs_builddir)/src/config/.files; \ + cd $(builddir)/src/config; \ + $(PYTHON2) setup.py build --build-base $(abs_builddir)/src/config \ + install $(DISTSETUPOPTS) --prefix=$(PYTHON2_PREFIX) \ + --record=$(abs_builddir)/src/config/.files2 --root=$(DESTDIR); \ fi + cd $(DESTDIR)$(py2execdir) && \ + $(LN_S) _py2sss.so pysss.so ; \ + $(LN_S) _py2hbac.so pyhbac.so ; \ + $(LN_S) _py2sss_murmur.so pysss_murmur.so ; \ + $(LN_S) _py2sss_nss_idmap.so pysss_nss_idmap.so +endif +if BUILD_PYTHON3_BINDINGS + if [ "$(DESTDIR)" = "" ]; then \ + cd $(builddir)/src/config; \ + $(PYTHON3) setup.py build --build-base $(abs_builddir)/src/config \ + install $(DISTSETUPOPTS) --prefix=$(PYTHON3_PREFIX) \ + --record=$(abs_builddir)/src/config/.files3; \ + else \ + cd $(builddir)/src/config; \ + $(PYTHON3) setup.py build --build-base $(abs_builddir)/src/config \ + install $(DISTSETUPOPTS) --prefix=$(PYTHON3_PREFIX) \ + --record=$(abs_builddir)/src/config/.files3 --root=$(DESTDIR); \ + fi + cd $(DESTDIR)$(py3execdir) && \ + $(LN_S) _py3sss.so pysss.so ; \ + $(LN_S) _py3hbac.so pyhbac.so ; \ + $(LN_S) _py3sss_murmur.so pysss_murmur.so ; \ + $(LN_S) _py3sss_nss_idmap.so pysss_nss_idmap.so endif for doc in $(SSSD_DOCS); do \ $(MKDIR_P) $$doc $(DESTDIR)/$(docdir); \ @@ -3039,16 +3134,20 @@ install-data-hook: fi uninstall-hook: - if [ -f $(abs_builddir)/src/config/.files ]; then \ - cat $(abs_builddir)/src/config/.files | xargs -iq rm -f $(DESTDIR)/q; \ - rm $(abs_builddir)/src/config/.files ; \ + if [ -f $(abs_builddir)/src/config/.files2 ]; then \ + cat $(abs_builddir)/src/config/.files2 | xargs -iq rm -f $(DESTDIR)/q; \ + rm $(abs_builddir)/src/config/.files2 ; \ + fi + if [ -f $(abs_builddir)/src/config/.files3 ]; then \ + cat $(abs_builddir)/src/config/.files3 | xargs -iq rm -f $(DESTDIR)/q; \ + rm $(abs_builddir)/src/config/.files3 ; \ fi for doc in $(SSSD_DOCS); do \ rm -Rf $(DESTDIR)/$(docdir)/$$doc; \ done; clean-local: -if BUILD_PYTHON_BINDINGS +if BUILD_PYTHON2_BINDINGS if [ ! $(srcdir)/src/config/SSSDConfig/ipachangeconf.py -ef $(builddir)/src/config/SSSDConfig/ipachangeconf.py ]; then \ rm -f $(builddir)/src/config/SSSDConfig/ipachangeconf.py ; \ fi @@ -3059,7 +3158,20 @@ if BUILD_PYTHON_BINDINGS rm -f $(builddir)/src/config/SSSDConfig/*.pyc - cd $(builddir)/src/config; $(PYTHON) setup.py build --build-base $(abs_builddir)/src/config clean --all + cd $(builddir)/src/config; $(PYTHON2) setup.py build --build-base $(abs_builddir)/src/config clean --all +endif +if BUILD_PYTHON3_BINDINGS + if [ ! $(srcdir)/src/config/SSSDConfig/ipachangeconf.py -ef $(builddir)/src/config/SSSDConfig/ipachangeconf.py ]; then \ + rm -f $(builddir)/src/config/SSSDConfig/ipachangeconf.py ; \ + fi + + if [ ! $(srcdir)/src/config/SSSDConfig/ipachangeconf.py -ef $(builddir)/src/config/SSSDConfig/ipachangeconf.py ]; then \ + rm -f $(builddir)/src/config/SSSDConfig/sssd_upgrade_config.py ; \ + fi + + rm -f $(builddir)/src/config/SSSDConfig/__pycache__/*.pyc + + cd $(builddir)/src/config; $(PYTHON3) setup.py build --build-base $(abs_builddir)/src/config clean --all endif for doc in $(SSSD_DOCS); do \ rm -Rf $$doc; \ diff --git a/configure.ac b/configure.ac index f72e448528edcffb855504a38a179c400f98ac42..e30405f3a17ffd2c9899b6eb17af85ec9bc15234 100644 --- a/configure.ac +++ b/configure.ac @@ -117,7 +117,8 @@ WITH_KRB5_PLUGIN_PATH WITH_KRB5_RCACHE_DIR WITH_KRB5AUTHDATA_PLUGIN_PATH WITH_KRB5_CONF -WITH_PYTHON_BINDINGS +WITH_PYTHON2_BINDINGS +WITH_PYTHON3_BINDINGS WITH_CIFS_PLUGIN_PATH WITH_SELINUX WITH_NSCD @@ -247,16 +248,52 @@ AM_CONDITIONAL([HAVE_PROFILE_CATALOGS], [test "x$HAVE_PROFILE_CATALOGS" != "x"]) AM_CONDITIONAL([HAVE_MANPAGES], [test "x$HAVE_MANPAGES" != "x"]) AM_CONDITIONAL([HAVE_PO4A], [test "x$PO4A" != "xno"]) -if test x$HAVE_PYTHON_BINDINGS != x; then +if test x$HAVE_PYTHON2_BINDINGS = x1; then + AC_PATH_PROG(PYTHON2, python2) + PYTHON=$PYTHON2 AM_PATH_PYTHON([2.6]) - AM_PYTHON_CONFIG([python]) + AM_PYTHON_CONFIG([python2]) AM_CHECK_PYTHON_HEADERS([], - AC_MSG_ERROR([Could not find python headers])) + AC_MSG_ERROR([Could not find python2 headers])) AM_CHECK_PYTHON_COMPAT - AC_SUBST([PYTHON_CFLAGS]) - AC_SUBST([PYTHON_LIBS]) + + AC_SUBST([py2execdir], [$pyexecdir]) + AC_SUBST([python2dir], [$pythondir]) + AC_SUBST([PYTHON2_CFLAGS], [$PYTHON_CFLAGS]) + AC_SUBST([PYTHON2_LIBS], [$PYTHON_LIBS]) + AC_SUBST([PYTHON2_INCLUDES], [$PYTHON_INCLUDES]) + AC_SUBST([PYTHON2_VERSION], [$PYTHON_VERSION]) + AC_SUBST([PYTHON2_PREFIX], [$PYTHON_PREFIX]) + AC_SUBST([PYTHON2_EXEC_PREFIX], [$PYTHON_EXEC_PREFIX]) + + SSS_CLEAN_PYTHON_VARIABLES fi +if test x$HAVE_PYTHON3_BINDINGS = x1; then + AC_PATH_PROG(PYTHON3, python3) + PYTHON=$PYTHON3 + AM_PATH_PYTHON([3.3]) + AM_PYTHON_CONFIG([python3]) + AM_CHECK_PYTHON_HEADERS([], + AC_MSG_ERROR([Could not find python3 headers])) + AM_CHECK_PYTHON_COMPAT + + AC_SUBST([py3execdir], [$pyexecdir]) + AC_SUBST([python3dir], [$pythondir]) + AC_SUBST([PYTHON3_CFLAGS], [$PYTHON_CFLAGS]) + AC_SUBST([PYTHON3_LIBS], [$PYTHON_LIBS]) + AC_SUBST([PYTHON3_INCLUDES], [$PYTHON_INCLUDES]) + AC_SUBST([PYTHON3_VERSION], [$PYTHON_VERSION]) + AC_SUBST([PYTHON3_PREFIX], [$PYTHON_PREFIX]) + AC_SUBST([PYTHON3_EXEC_PREFIX], [$PYTHON_EXEC_PREFIX]) + + SSS_CLEAN_PYTHON_VARIABLES +fi + +AM_CONDITIONAL([BUILD_PYTHON_BINDINGS], + [test x"$with_python2_bindings" = xyes \ + -o x"$with_python3_bindings" = xyes]) + if test x$HAVE_SELINUX != x; then AM_CHECK_SELINUX AM_CHECK_SELINUX_LOGIN_DIR diff --git a/contrib/sssd.spec.in b/contrib/sssd.spec.in index 6d6f0b9294e2150549f36c64a11ace64be8a83cc..ecbb29dd9222578fdd2c8505770f0345684012f3 100644 --- a/contrib/sssd.spec.in +++ b/contrib/sssd.spec.in @@ -781,10 +781,12 @@ rm -rf $RPM_BUILD_ROOT %files -n python-sss %defattr(-,root,root,-) %{python_sitearch}/pysss.so +%{python_sitearch}/_py2sss.so %files -n python-sss-murmur %defattr(-,root,root,-) %{python_sitearch}/pysss_murmur.so +%{python_sitearch}/_py2sss_murmur.so %files -n libsss_idmap %defattr(-,root,root,-) @@ -825,10 +827,12 @@ rm -rf $RPM_BUILD_ROOT %files -n python-libsss_nss_idmap %defattr(-,root,root,-) %{python_sitearch}/pysss_nss_idmap.so +%{python_sitearch}/_py2sss_nss_idmap.so %files -n python-libipa_hbac %defattr(-,root,root,-) %{python_sitearch}/pyhbac.so +%{python_sitearch}/_py2hbac.so %files libwbclient %defattr(-,root,root,-) diff --git a/src/conf_macros.m4 b/src/conf_macros.m4 index 027490e524f321b9d444395e788aa7476dd916e9..ff49f84421ac6be8a2a5f5840283485ea16d671d 100644 --- a/src/conf_macros.m4 +++ b/src/conf_macros.m4 @@ -360,21 +360,38 @@ AC_DEFUN([WITH_KRB5_CONF], AC_DEFINE_UNQUOTED([KRB5_CONF_PATH], ["$KRB5_CONF_PATH"], [KRB5 configuration file]) ]) -AC_DEFUN([WITH_PYTHON_BINDINGS], - [ AC_ARG_WITH([python-bindings], - [AC_HELP_STRING([--with-python-bindings], - [Whether to build python bindings [yes]] - ) +AC_DEFUN([WITH_PYTHON2_BINDINGS], + [ AC_ARG_WITH([python2-bindings], + [AC_HELP_STRING([--with-python2-bindings], + [Whether to build python2 bindings [yes]]) ], [], - with_python_bindings=yes + [with_python2_bindings=yes] ) - if test x"$with_python_bindings" = xyes; then - HAVE_PYTHON_BINDINGS=1 - AC_SUBST(HAVE_PYTHON_BINDINGS) - AC_DEFINE_UNQUOTED(HAVE_PYTHON_BINDINGS, 1, [Build with python bindings]) + if test x"$with_python2_bindings" = xyes; then + AC_SUBST([HAVE_PYTHON2_BINDINGS], [1]) + AC_DEFINE_UNQUOTED([HAVE_PYTHON2_BINDINGS], [1], + [Build with python2 bindings]) fi - AM_CONDITIONAL([BUILD_PYTHON_BINDINGS], [test x"$with_python_bindings" = xyes]) + AM_CONDITIONAL([BUILD_PYTHON2_BINDINGS], + [test x"$with_python2_bindings" = xyes]) + ]) + +AC_DEFUN([WITH_PYTHON3_BINDINGS], + [ AC_ARG_WITH([python3-bindings], + [AC_HELP_STRING([--with-python3-bindings], + [Whether to build python3 bindings [yes]]) + ], + [], + [with_python3_bindings=no] + ) + if test x"$with_python3_bindings" = xyes; then + AC_SUBST([HAVE_PYTHON3_BINDINGS], [1]) + AC_DEFINE_UNQUOTED([HAVE_PYTHON3_BINDINGS], [1], + [Build with python3 bindings]) + fi + AM_CONDITIONAL([BUILD_PYTHON3_BINDINGS], + [test x"$with_python3_bindings" = xyes]) ]) AC_DEFUN([WITH_SELINUX], diff --git a/src/tests/pyhbac-test.py b/src/tests/pyhbac-test.py index 0abc5703dedb2466b4d99718b5b524951b8af95c..83958d7bffcccea375c79166ee7dfca6f9956cff 100755 --- a/src/tests/pyhbac-test.py +++ b/src/tests/pyhbac-test.py @@ -6,10 +6,9 @@ import sys import os import copy import sys +import errno -srcdir = os.getenv('builddir') -if not srcdir: - srcdir = "." +srcdir = os.getenv('builddir') or "." MODPATH = srcdir + "/.libs" #FIXME - is there a way to get this from libtool? if sys.version_info[0] > 2: @@ -41,6 +40,23 @@ class PyHbacImport(unittest.TestCase): def testImport(self): " Import the module and assert it comes from tree " try: + cwd_backup = os.getcwd() + + try: + os.unlink(MODPATH + "/pyhbac.so") + except OSError as e: + if e.errno == errno.ENOENT: + pass + else: + raise e + + os.chdir(MODPATH) + if sys.version_info[0] > 2: + os.symlink("_py3hbac.so", "pyhbac.so") + else: + os.symlink("_py2hbac.so", "pyhbac.so") + os.chdir(cwd_backup) + import pyhbac except ImportError as e: print("Could not load the pyhbac module. Please check if it is compiled", file=sys.stderr) diff --git a/src/tests/pysss_murmur-test.py b/src/tests/pysss_murmur-test.py index 0b28f45e67cb4b033516a585867085dba7b412e6..faa8bb2d33b9d94d380b8f7045ba45aa06ac4793 100755 --- a/src/tests/pysss_murmur-test.py +++ b/src/tests/pysss_murmur-test.py @@ -23,10 +23,9 @@ import unittest import sys import os import copy +import errno -srcdir = os.getenv('builddir') -if not srcdir: - srcdir = "." +srcdir = os.getenv('builddir') or "." MODPATH = srcdir + "/.libs" #FIXME - is there a way to get this from libtool? def compat_assertItemsEqual(this, expected_seq, actual_seq, msg=None): @@ -57,6 +56,23 @@ class PySssMurmurImport(unittest.TestCase): def testImport(self): " Import the module and assert it comes from tree " try: + cwd_backup = os.getcwd() + + try: + os.unlink(MODPATH + "/pysss_murmur.so") + except OSError as e: + if e.errno == errno.ENOENT: + pass + else: + raise e + + os.chdir(MODPATH) + if sys.version_info[0] > 2: + os.symlink("_py3sss_murmur.so", "pysss_murmur.so") + else: + os.symlink("_py2sss_murmur.so", "pysss_murmur.so") + os.chdir(cwd_backup) + import pysss_murmur except ImportError as e: print("Could not load the pysss_murmur module. Please check if it is compiled", file=sys.stderr) -- 2.1.0