[Kimchi-devel] [PATCH] Packaging: Discover and Build Plugins Automatically

zhshzhou at linux.vnet.ibm.com zhshzhou at linux.vnet.ibm.com
Wed Apr 9 09:43:24 UTC 2014


From: Zhou Zheng Sheng <zhshzhou at linux.vnet.ibm.com>

Though Kimchi can automatically discover and load plugin Python modules
when kimchid starts, the packaging subsystem is not as smart. Downstream
plugin developers have to insert entries in Kimchi configure.ac and
contrib/kimchi.spec.*.in to compile and package plugin files. This is
not scalable.

This patch proposes a mechanism to make packaging scripts smarter to
discover and build plugins dynamically, so that the plugin code is
actually "plugable" to the packaging subsystem. The plugin developer
just places the pluginX code to plugins/pluginX, then uses
"./autogen.sh --with-plugins=pluginX" to generate the packaging scripts
for pluginX. We no longer have to change upstream Kimchi configure.ac,
Makefile.am and kimchi.spec.*.in.

To compile with plugins, use the following command.
  ./autogen.sh --with-plugins=plugin1,plugin2,... && make

To build kimchi-plugin1.rpm, kimchi-plugin2.rpm and kimchi.rpm, use the
following command.
  ./autogen.sh --system --with-plugins=plugin1,plugin2 && make && make rpm

To build only kimchi.rpm, use the following command
  ./autogen.sh --system && make && make rpm

This patch makes use of the "include" functions in autoconf and RPM
spec. The basic idea is that each plugin provides two files as follow.
  plugins/PLUGIN_NAME/configure.m4
  plugins/PLUGIN_NAME/plugin.spec
Then autogen.sh catenates all plugins/{enabled_plugins}/configure.m4
into one big plugins/plugins.m4. In configure.ac, it includes
plugins/plugins.m4. When we invoke "make rpm", the Makefil scripts does
the similar catenation of plugins/{enabled_plugins}/plugin.spec into
plugins/plugins.spec, and have kimchi.spec include this file.

Since the Debian packaging system is a different story, future patches
shall be submitted to make Kimchi deb packaging code plugable.

Signed-off-by: Zhou Zheng Sheng <zhshzhou at linux.vnet.ibm.com>
---
 .gitignore                           |  2 ++
 Makefile.am                          | 14 ++++++++------
 autogen.sh                           | 13 +++++++++++++
 configure.ac                         |  7 ++++---
 contrib/kimchi.spec.fedora.in        |  4 ++++
 contrib/kimchi.spec.suse.in          |  4 ++++
 plugins/Makefile.am                  | 17 +++++++++++++++--
 plugins/sample/Makefile.am           | 14 +++++++++++++-
 plugins/sample/configure.m4          | 26 ++++++++++++++++++++++++++
 plugins/sample/plugin.spec           | 17 +++++++++++++++++
 plugins/sample/ui/config/Makefile.am |  6 +++++-
 11 files changed, 111 insertions(+), 13 deletions(-)
 create mode 100644 plugins/sample/configure.m4
 create mode 100644 plugins/sample/plugin.spec

diff --git a/.gitignore b/.gitignore
index 67878e2..324325b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -20,6 +20,8 @@ contrib/DEBIAN/control
 contrib/kimchi.spec.fedora
 contrib/kimchi.spec.suse
 contrib/make-deb.sh
+plugins/plugins.m4
+plugins/plugins.spec
 *.min.css
 *.min.js
 *.gmo
diff --git a/Makefile.am b/Makefile.am
index 6831b5d..b6a864c 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -35,9 +35,7 @@ EXTRA_DIST = \
 # When fixing a file to conform with pep8, add it to the WL here.
 # So it will be checked from now on.
 PEP8_WHITELIST = \
-	plugins/__init__.py \
-	plugins/sample/__init__.py \
-	plugins/sample/model.py \
+	plugins \
 	src/kimchi/asynctask.py \
 	src/kimchi/auth.py \
 	src/kimchi/cachebust.py \
@@ -122,10 +120,14 @@ kimchi.spec: contrib/kimchi.spec.fedora contrib/kimchi.spec.suse
 		/bin/false ;                                        \
 	fi
 
-rpm: dist kimchi.spec
+plugins/plugins.spec:
+	cd plugins; \
+	make plugins.spec
+
+rpm: dist kimchi.spec plugins/plugins.spec
 	$(MKDIR_P) rpm/BUILD rpm/RPMS rpm/SOURCES rpm/SPECS rpm/SRPMS
 	cp $(top_srcdir)/kimchi.spec rpm/SPECS/kimchi.spec
-	cp $(DIST_ARCHIVES) rpm/SOURCES
+	cp $(DIST_ARCHIVES) plugins/plugins.spec rpm/SOURCES
 	rpmbuild -ba --define "_topdir `pwd`/rpm" rpm/SPECS/kimchi.spec
 
 fedora-rpm: contrib/kimchi.spec.fedora
@@ -146,7 +148,7 @@ VERSION:
 		git describe --abbrev=0 > $@;                     \
 	fi
 
-.PHONY: deb install-deb rpm fedora-rpm suse-rpm ChangeLog VERSION
+.PHONY: deb install-deb rpm fedora-rpm suse-rpm ChangeLog VERSION plugins/plugins.spec
 
 clean-local:
 	rm -rf mo rpm
diff --git a/autogen.sh b/autogen.sh
index 0f22dba..75d85aa 100755
--- a/autogen.sh
+++ b/autogen.sh
@@ -1,5 +1,18 @@
 #!/bin/bash
 
+plugins_list=""
+for opts in "$@" ; do
+    if [[ "$opts" == "--with-plugins="* ]] ; then
+        plugins_list=${opts#--with-plugins=}
+        plugins_list=$(sed -e "s/,/ /g" <<< ${plugins_list})
+    fi
+done
+
+echo "" > plugins/plugins.m4
+for plugin in ${plugins_list}; do
+    cat plugins/${plugin}/configure.m4 >> plugins/plugins.m4
+done
+
 aclocal
 automake --add-missing
 autoreconf
diff --git a/configure.ac b/configure.ac
index a625f35..75be00d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -48,6 +48,10 @@ if test "x$PYFLAKES" = "x"; then
   AC_MSG_WARN([pyflakes not found])
 fi
 
+m4_include([plugins/plugins.m4])
+
+AC_SUBST([enabled_plugins], ["${enabled_plugins}"])
+
 
 AC_CONFIG_FILES([
     po/Makefile.in
@@ -61,9 +65,6 @@ AC_CONFIG_FILES([
     src/kimchi/control/vm/Makefile
     src/kimchi/model/Makefile
     plugins/Makefile
-    plugins/sample/Makefile
-    plugins/sample/ui/Makefile
-    plugins/sample/ui/config/Makefile
     ui/Makefile
     ui/css/Makefile
     ui/css/novnc/Makefile
diff --git a/contrib/kimchi.spec.fedora.in b/contrib/kimchi.spec.fedora.in
index bf80104..12b5f42 100644
--- a/contrib/kimchi.spec.fedora.in
+++ b/contrib/kimchi.spec.fedora.in
@@ -10,6 +10,7 @@ BuildRoot:	%{_topdir}/BUILD/%{name}-%{version}-%{release}
 Group:		System Environment/Base
 License:	LGPL/ASL2
 Source0:	%{name}-%{version}.tar.gz
+Source1:	plugins.spec
 Requires:	qemu-kvm
 Requires:	gettext-devel
 Requires:	libvirt
@@ -140,6 +141,7 @@ rm -rf $RPM_BUILD_ROOT
 %{python_sitelib}/kimchi/control/*.py*
 %{python_sitelib}/kimchi/control/vm/*.py*
 %{python_sitelib}/kimchi/model/*.py*
+%{python_sitelib}/kimchi/plugins/*.py*
 %{python_sitelib}/kimchi/API.json
 %{_datadir}/kimchi/doc/API.md
 %{_datadir}/kimchi/doc/README.md
@@ -192,6 +194,8 @@ rm -rf $RPM_BUILD_ROOT
 %{_initrddir}/kimchid
 %endif
 
+%include %{SOURCE1}
+
 %changelog
 * Tue Feb 11 2014 Crístian Viana <vianac at linux.vnet.ibm.com> 1.1.0
 - Add help pages and XSLT dependency
diff --git a/contrib/kimchi.spec.suse.in b/contrib/kimchi.spec.suse.in
index cba0899..8432dab 100644
--- a/contrib/kimchi.spec.suse.in
+++ b/contrib/kimchi.spec.suse.in
@@ -6,6 +6,7 @@ BuildRoot:	%{_topdir}/BUILD/%{name}-%{version}-%{release}
 Group:		System Environment/Base
 License:	LGPL/ASL2
 Source0:	%{name}-%{version}.tar.gz
+Source1:	plugins.spec
 Requires:	kvm
 Requires:	gettext-tools
 Requires:	libvirt
@@ -66,6 +67,7 @@ rm -rf $RPM_BUILD_ROOT
 %{python_sitelib}/kimchi/control/*.py*
 %{python_sitelib}/kimchi/control/vm/*.py*
 %{python_sitelib}/kimchi/model/*.py*
+%{python_sitelib}/kimchi/plugins/*.py*
 %{python_sitelib}/kimchi/API.json
 %{_datadir}/kimchi/doc/API.md
 %{_datadir}/kimchi/doc/README.md
@@ -108,6 +110,8 @@ rm -rf $RPM_BUILD_ROOT
 %{_sysconfdir}/kimchi/distros.d/gentoo.json
 %{_initrddir}/kimchid
 
+%include %{SOURCE1}
+
 %changelog
 * Tue Feb 11 2014 Crístian Viana <vianac at linux.vnet.ibm.com> 1.1.0
 - Add help pages and XSLT dependency
diff --git a/plugins/Makefile.am b/plugins/Makefile.am
index 2ceedae..2ec958f 100644
--- a/plugins/Makefile.am
+++ b/plugins/Makefile.am
@@ -17,6 +17,19 @@
 # License along with this library; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 
-SUBDIRS = sample
+SUBDIRS = $(enabled_plugins)
 
-EXTRA_DIST = __init__.py
+plugins_PYTHON = \
+	__init__.py
+
+pluginsdir = $(pythondir)/kimchi/plugins
+
+plugins.spec: $(SUBDIRS:%=%/plugin.spec) Makefile
+	echo "" > plugins.spec
+	for plugin in $(SUBDIRS); do \
+	    cat $$plugin/plugin.spec >> plugins.spec; \
+	done
+
+CLEANFILES = \
+	plugins.spec \
+	$(NULL)
diff --git a/plugins/sample/Makefile.am b/plugins/sample/Makefile.am
index e03a4c0..1d595c2 100644
--- a/plugins/sample/Makefile.am
+++ b/plugins/sample/Makefile.am
@@ -19,4 +19,16 @@
 
 SUBDIRS = ui
 
-EXTRA_DIST = API.json sample.conf $(wildcard *.py)
+sampledir = $(pythondir)/kimchi/plugins/sample
+
+confdir = $(sysconfdir)/kimchi/plugins.d
+
+sample_PYTHON = $(wildcard *.py)
+
+dist_conf_DATA = sample.conf
+
+EXTRA_DIST = API.json
+
+install-data-local:
+	$(MKDIR_P) $(DESTDIR)$(sampledir)
+	$(INSTALL_DATA) API.json $(DESTDIR)$(sampledir)/API.json
diff --git a/plugins/sample/configure.m4 b/plugins/sample/configure.m4
new file mode 100644
index 0000000..b5d65f9
--- /dev/null
+++ b/plugins/sample/configure.m4
@@ -0,0 +1,26 @@
+#
+# Kimchi
+#
+# Copyright IBM Corp, 2014
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
+
+enabled_plugins="${enabled_plugins} sample"
+
+AC_CONFIG_FILES([
+    plugins/sample/Makefile
+    plugins/sample/ui/Makefile
+    plugins/sample/ui/config/Makefile
+])
diff --git a/plugins/sample/plugin.spec b/plugins/sample/plugin.spec
new file mode 100644
index 0000000..9b6b03f
--- /dev/null
+++ b/plugins/sample/plugin.spec
@@ -0,0 +1,17 @@
+%package sample
+Summary:	Sample plugin for Kimchi.
+Requires:	%{name} = %{version}-%{release}
+
+%description sample
+Kimchi is a web server application application to manage KVM/Qemu
+virtual machines. Kimchi-sample is a sample plugin to demo how to write
+plugin for Kimchi.
+
+
+%files sample
+%attr(-,root,root)
+%{python_sitelib}/kimchi/plugins/sample/*.py*
+%{python_sitelib}/kimchi/plugins/sample/API.json
+%{_datadir}/kimchi/plugins/sample/ui/config/tab-ext.xml
+%{_sysconfdir}/kimchi/plugins.d/sample.conf
+
diff --git a/plugins/sample/ui/config/Makefile.am b/plugins/sample/ui/config/Makefile.am
index cf9e09e..eb05920 100644
--- a/plugins/sample/ui/config/Makefile.am
+++ b/plugins/sample/ui/config/Makefile.am
@@ -17,5 +17,9 @@
 # License along with this library; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 
-EXTRA_DIST = tab-ext.xml
+xmldir = $(datadir)/kimchi/plugins/sample/ui/config
+
+dist_xml_DATA = \
+	tab-ext.xml \
+	$(NULL)
 
-- 
1.8.5.3




More information about the Kimchi-devel mailing list