[lxc-devel] [lxc/master] python-lxc: enable standalone builds
GreatFruitOmsk on Github
lxc-bot at linuxcontainers.org
Fri May 27 12:11:57 UTC 2016
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 565 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20160527/e2d2a8c3/attachment.bin>
-------------- next part --------------
From d51f78ed31f88c0d69def88eec38d76cef685b9e Mon Sep 17 00:00:00 2001
From: Aleksandr Mezin <mezin.alexander at gmail.com>
Date: Thu, 26 May 2016 16:03:57 +0600
Subject: [PATCH 1/5] python-lxc: don't use private lxc/namespace.h
Signed-off-by: Aleksandr Mezin <mezin.alexander at gmail.com>
---
src/python-lxc/lxc.c | 30 +++++++++++++++++++++++++++++-
1 file changed, 29 insertions(+), 1 deletion(-)
diff --git a/src/python-lxc/lxc.c b/src/python-lxc/lxc.c
index 4f637d0..61c192c 100644
--- a/src/python-lxc/lxc.c
+++ b/src/python-lxc/lxc.c
@@ -26,10 +26,38 @@
#include "structmember.h"
#include <lxc/lxccontainer.h>
#include "lxc/utils.h"
-#include "lxc/namespace.h"
#include "lxc/confile.h"
#include <stdio.h>
#include <sys/wait.h>
+#include <sched.h>
+
+/*
+ * CLONE_* definitions copied from lxc/namespace.h
+ */
+#ifndef CLONE_FS
+# define CLONE_FS 0x00000200
+#endif
+#ifndef CLONE_NEWNS
+# define CLONE_NEWNS 0x00020000
+#endif
+#ifndef CLONE_NEWCGROUP
+# define CLONE_NEWCGROUP 0x02000000
+#endif
+#ifndef CLONE_NEWUTS
+# define CLONE_NEWUTS 0x04000000
+#endif
+#ifndef CLONE_NEWIPC
+# define CLONE_NEWIPC 0x08000000
+#endif
+#ifndef CLONE_NEWUSER
+# define CLONE_NEWUSER 0x10000000
+#endif
+#ifndef CLONE_NEWPID
+# define CLONE_NEWPID 0x20000000
+#endif
+#ifndef CLONE_NEWNET
+# define CLONE_NEWNET 0x40000000
+#endif
/* Helper functions */
From 0fbd2f6a8976d27743a532ac6d7cbf384a4cb307 Mon Sep 17 00:00:00 2001
From: Aleksandr Mezin <mezin.alexander at gmail.com>
Date: Thu, 26 May 2016 16:07:28 +0600
Subject: [PATCH 2/5] python-lxc: don't use private lxc/utils.h
Signed-off-by: Aleksandr Mezin <mezin.alexander at gmail.com>
---
src/python-lxc/lxc.c | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)
diff --git a/src/python-lxc/lxc.c b/src/python-lxc/lxc.c
index 61c192c..fbbabdb 100644
--- a/src/python-lxc/lxc.c
+++ b/src/python-lxc/lxc.c
@@ -25,7 +25,6 @@
#include <Python.h>
#include "structmember.h"
#include <lxc/lxccontainer.h>
-#include "lxc/utils.h"
#include "lxc/confile.h"
#include <stdio.h>
#include <sys/wait.h>
@@ -61,6 +60,23 @@
/* Helper functions */
+/* Copied from lxc/utils.c */
+static int lxc_wait_for_pid_status(pid_t pid)
+{
+ int status, ret;
+
+again:
+ ret = waitpid(pid, &status, 0);
+ if (ret == -1) {
+ if (errno == EINTR)
+ goto again;
+ return -1;
+ }
+ if (ret != pid)
+ goto again;
+ return status;
+}
+
char**
convert_tuple_to_char_pointer_array(PyObject *argv) {
int argc;
From 58a44782d9a9a24c4f671526918fc58c74fad48c Mon Sep 17 00:00:00 2001
From: Aleksandr Mezin <mezin.alexander at gmail.com>
Date: Fri, 27 May 2016 15:13:18 +0600
Subject: [PATCH 3/5] python-lxc: don't use private lxc/confile.h
Signed-off-by: Aleksandr Mezin <mezin.alexander at gmail.com>
---
src/python-lxc/lxc.c | 35 ++++++++++++++++++++++++++++++++++-
1 file changed, 34 insertions(+), 1 deletion(-)
diff --git a/src/python-lxc/lxc.c b/src/python-lxc/lxc.c
index fbbabdb..b69116d 100644
--- a/src/python-lxc/lxc.c
+++ b/src/python-lxc/lxc.c
@@ -25,7 +25,6 @@
#include <Python.h>
#include "structmember.h"
#include <lxc/lxccontainer.h>
-#include "lxc/confile.h"
#include <stdio.h>
#include <sys/wait.h>
#include <sched.h>
@@ -58,6 +57,10 @@
# define CLONE_NEWNET 0x40000000
#endif
+/* From sys/personality.h */
+#define PER_LINUX 0x0000
+#define PER_LINUX32 0x0008
+
/* Helper functions */
/* Copied from lxc/utils.c */
@@ -77,6 +80,36 @@ static int lxc_wait_for_pid_status(pid_t pid)
return status;
}
+/* Copied from lxc/confile.c, with HAVE_SYS_PERSONALITY_H check removed */
+signed long lxc_config_parse_arch(const char *arch)
+{
+ struct per_name {
+ char *name;
+ unsigned long per;
+ } pername[] = {
+ { "x86", PER_LINUX32 },
+ { "linux32", PER_LINUX32 },
+ { "i386", PER_LINUX32 },
+ { "i486", PER_LINUX32 },
+ { "i586", PER_LINUX32 },
+ { "i686", PER_LINUX32 },
+ { "athlon", PER_LINUX32 },
+ { "linux64", PER_LINUX },
+ { "x86_64", PER_LINUX },
+ { "amd64", PER_LINUX },
+ };
+ size_t len = sizeof(pername) / sizeof(pername[0]);
+
+ size_t i;
+
+ for (i = 0; i < len; i++) {
+ if (!strcmp(pername[i].name, arch))
+ return pername[i].per;
+ }
+
+ return -1;
+}
+
char**
convert_tuple_to_char_pointer_array(PyObject *argv) {
int argc;
From 00d98acd9fc067a590ef43d4c6eb02d567da923c Mon Sep 17 00:00:00 2001
From: Aleksandr Mezin <mezin.alexander at gmail.com>
Date: Fri, 27 May 2016 15:38:42 +0600
Subject: [PATCH 4/5] python-lxc: pass include/library dirs as arguments to
setup.py
Signed-off-by: Aleksandr Mezin <mezin.alexander at gmail.com>
---
.gitignore | 1 -
configure.ac | 1 -
src/python-lxc/Makefile.am | 14 ++++++++----
src/python-lxc/setup.py | 34 +++++++++++++++++++++++++++
src/python-lxc/setup.py.in | 57 ----------------------------------------------
5 files changed, 43 insertions(+), 64 deletions(-)
create mode 100644 src/python-lxc/setup.py
delete mode 100644 src/python-lxc/setup.py.in
diff --git a/.gitignore b/.gitignore
index adc965e..a2a34e2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -66,7 +66,6 @@ src/lxc/lxc-wait
src/lxc/lxc-user-nic
src/lxc/version.h
-src/python-lxc/setup.py
src/python-lxc/build/
src/python-lxc/lxc/__pycache__/
diff --git a/configure.ac b/configure.ac
index 9475b0e..13820ef 100644
--- a/configure.ac
+++ b/configure.ac
@@ -847,7 +847,6 @@ AC_CONFIG_FILES([
src/lxc/lxc.functions
src/lxc/version.h
src/python-lxc/Makefile
- src/python-lxc/setup.py
src/lua-lxc/Makefile
diff --git a/src/python-lxc/Makefile.am b/src/python-lxc/Makefile.am
index 4a014df..cbb2747 100644
--- a/src/python-lxc/Makefile.am
+++ b/src/python-lxc/Makefile.am
@@ -6,21 +6,25 @@ else
DISTSETUPOPTS=
endif
+INSTALL_OPTS := install --prefix=$(prefix) --no-compile $(DISTSETUPOPTS)
+CALL_SETUP_PY := cd @srcdir@ && $(PYTHON) setup.py build -b @abs_builddir@/build
+
all:
- $(PYTHON) setup.py build
+ $(CALL_SETUP_PY) build_ext -I @abs_top_srcdir@/src -L @abs_top_builddir@/src/lxc
install:
- if [ "$(DESTDIR)" = "" ]; then \
- $(PYTHON) setup.py install --prefix=$(prefix) --no-compile $(DISTSETUPOPTS); \
+ if [ -z "$(DESTDIR)" ]; then \
+ $(CALL_SETUP_PY) $(INSTALL_OPTS); \
else \
- $(PYTHON) setup.py install --root=$(DESTDIR) --prefix=$(prefix) --no-compile $(DISTSETUPOPTS); \
+ $(CALL_SETUP_PY) $(INSTALL_OPTS) --root=$(DESTDIR); \
fi
clean-local:
- rm -rf build
+ rm -rf @builddir@/build
endif
EXTRA_DIST = \
+ setup.py \
lxc.c \
lxc/__init__.py \
examples/api_test.py \
diff --git a/src/python-lxc/setup.py b/src/python-lxc/setup.py
new file mode 100644
index 0000000..d8cb166
--- /dev/null
+++ b/src/python-lxc/setup.py
@@ -0,0 +1,34 @@
+#!/usr/bin/env python3
+#
+# python-lxc: Python bindings for LXC
+#
+# (C) Copyright Canonical Ltd. 2012
+#
+# Authors:
+# Stéphane Graber <stgraber at ubuntu.com>
+#
+# 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
+
+from distutils.core import setup, Extension
+
+
+setup(name='_lxc',
+ version='0.1',
+ description='LXC',
+ packages=['lxc'],
+ package_dir={'lxc': 'lxc'},
+ ext_modules=[Extension('_lxc', sources=['lxc.c'], libraries=['lxc'])],
+ )
diff --git a/src/python-lxc/setup.py.in b/src/python-lxc/setup.py.in
deleted file mode 100644
index fcb676e..0000000
--- a/src/python-lxc/setup.py.in
+++ /dev/null
@@ -1,57 +0,0 @@
-#!/usr/bin/env python3
-#
-# python-lxc: Python bindings for LXC
-#
-# (C) Copyright Canonical Ltd. 2012
-#
-# Authors:
-# Stéphane Graber <stgraber at ubuntu.com>
-#
-# 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
-
-import os, os.path
-from distutils.core import setup, Extension
-
-# Distutils doesn't cope well with source files that have relative paths going
-# up in the directory tree: it tries to navigate outside of the build dir and
-# fails miserably. Therefore, we will instead cd to the source directory,
-# run this script from there, but write the build products to the correct path.
-#
-# Since we will be changing directories before building, we must transform
-# all the path variables to their forms relative to srcdir.
-
-srcdir, builddir, top_srcdir, top_builddir = map(os.path.abspath,
- ["@srcdir@", "@builddir@", "@top_srcdir@", "@top_builddir@"])
-
-builddir, top_srcdir, top_builddir = map(lambda d: os.path.relpath(d, srcdir),
- [builddir, top_srcdir, top_builddir])
-
-os.chdir(srcdir)
-
-module = Extension('_lxc', sources=['lxc.c'],
- include_dirs=[os.path.join(top_srcdir, 'src'),
- os.path.join(top_builddir, 'src')],
- library_dirs=[os.path.join(top_builddir, 'src/lxc')],
- libraries=['lxc'])
-
-
-setup(name='_lxc',
- version='0.1',
- description='LXC',
- packages=['lxc'],
- package_dir={'lxc': 'lxc'},
- ext_modules=[module],
- options={'build': {'build_base': os.path.join(builddir, 'build')}})
From bc5822447b70839757e88b81a91c73ec10a05f1a Mon Sep 17 00:00:00 2001
From: Aleksandr Mezin <mezin.alexander at gmail.com>
Date: Fri, 27 May 2016 17:58:15 +0600
Subject: [PATCH 5/5] python-lxc: search for lxc library and headers using
pkg-config
Signed-off-by: Aleksandr Mezin <mezin.alexander at gmail.com>
---
src/python-lxc/Makefile.am | 2 +-
src/python-lxc/setup.py | 38 ++++++++++++++++++++++++++++++++++++++
2 files changed, 39 insertions(+), 1 deletion(-)
diff --git a/src/python-lxc/Makefile.am b/src/python-lxc/Makefile.am
index cbb2747..4a2b86e 100644
--- a/src/python-lxc/Makefile.am
+++ b/src/python-lxc/Makefile.am
@@ -10,7 +10,7 @@ INSTALL_OPTS := install --prefix=$(prefix) --no-compile $(DISTSETUPOPTS)
CALL_SETUP_PY := cd @srcdir@ && $(PYTHON) setup.py build -b @abs_builddir@/build
all:
- $(CALL_SETUP_PY) build_ext -I @abs_top_srcdir@/src -L @abs_top_builddir@/src/lxc
+ $(CALL_SETUP_PY) build_ext -I @abs_top_srcdir@/src -L @abs_top_builddir@/src/lxc --no-pkg-config
install:
if [ -z "$(DESTDIR)" ]; then \
diff --git a/src/python-lxc/setup.py b/src/python-lxc/setup.py
index d8cb166..bbbb764 100644
--- a/src/python-lxc/setup.py
+++ b/src/python-lxc/setup.py
@@ -22,7 +22,44 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
# USA
+import os
+import subprocess
+
from distutils.core import setup, Extension
+from distutils.command.build_ext import build_ext as BuildExtCommand
+
+
+class LxcBuildExtCommand(BuildExtCommand):
+ user_options = BuildExtCommand.user_options + [
+ ('no-pkg-config', None,
+ "don't use pkg-config to detect include/library paths")
+ ]
+
+ def initialize_options(self):
+ super(LxcBuildExtCommand, self).initialize_options()
+ self.no_pkg_config = False
+
+ def build_extensions(self):
+ if not self.no_pkg_config:
+ pkg_config_executable = os.environ.get('PKG_CONFIG_EXECUTABLE',
+ 'pkg-config')
+
+ def get_pkg_config_var(name):
+ return subprocess.check_output([pkg_config_executable,
+ '--variable', name, 'lxc'],
+ universal_newlines=True)
+
+ try:
+ includedir = get_pkg_config_var('includedir')
+ libdir = get_pkg_config_var('libdir')
+
+ self.compiler.add_include_dir(includedir)
+ self.compiler.add_library_dir(libdir)
+
+ except subprocess.CalledProcessError:
+ pass
+
+ super(LxcBuildExtCommand, self).build_extensions()
setup(name='_lxc',
@@ -31,4 +68,5 @@
packages=['lxc'],
package_dir={'lxc': 'lxc'},
ext_modules=[Extension('_lxc', sources=['lxc.c'], libraries=['lxc'])],
+ cmdclass={'build_ext': LxcBuildExtCommand},
)
More information about the lxc-devel
mailing list