Commit 8c041c2f by Stéphane Graber

Merge pull request #1031 from GreatFruitOmsk/pypi

python-lxc: enable standalone builds
parents 95ca286d f2fec475
......@@ -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__/
......
......@@ -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
......
......@@ -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 --no-pkg-config
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 \
......
......@@ -25,14 +25,91 @@
#include <Python.h>
#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
/* From sys/personality.h */
#define PER_LINUX 0x0000
#define PER_LINUX32 0x0008
/* 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;
}
/* 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;
......
......@@ -22,30 +22,45 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
# USA
import os, os.path
import os
import subprocess
from distutils.core import setup, Extension
from distutils.command.build_ext import build_ext as BuildExtCommand
# 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@"])
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):
args = [pkg_config_executable, '--variable', name, 'lxc']
output = subprocess.check_output(args,
universal_newlines=True)
return output.rstrip('\n')
try:
includedir = get_pkg_config_var('includedir')
libdir = get_pkg_config_var('libdir')
builddir, top_srcdir, top_builddir = map(lambda d: os.path.relpath(d, srcdir),
[builddir, top_srcdir, top_builddir])
self.compiler.add_include_dir(includedir)
self.compiler.add_library_dir(libdir)
os.chdir(srcdir)
except subprocess.CalledProcessError:
pass
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'])
super(LxcBuildExtCommand, self).build_extensions()
setup(name='_lxc',
......@@ -53,5 +68,6 @@ setup(name='_lxc',
description='LXC',
packages=['lxc'],
package_dir={'lxc': 'lxc'},
ext_modules=[module],
options={'build': {'build_base': os.path.join(builddir, 'build')}})
ext_modules=[Extension('_lxc', sources=['lxc.c'], libraries=['lxc'])],
cmdclass={'build_ext': LxcBuildExtCommand},
)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment