]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
build: Make setup.py run from srcdir to avoid distutils errors
authorDaniel Miranda <danielkza2@gmail.com>
Mon, 25 Aug 2014 21:16:43 +0000 (18:16 -0300)
committerStéphane Graber <stgraber@ubuntu.com>
Mon, 25 Aug 2014 23:10:47 +0000 (19:10 -0400)
distutils can't handle paths to source files containing '..'. It will
try to navigate away from the build directory and fail. To fix that,
before building the python module, transform all the path variables then
cd to the srcdir, and set the build directory manually.

This is hopefully the last needed fix to use separate build and
source diretories.

Signed-off-by: Daniel Miranda <danielkza2@gmail.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
src/python-lxc/setup.py.in

index 31e849c166d36b94969532ccfa9ac74bbadcb241..3b4b1feec3bfe54417a7ec92525c077498a88947 100644 (file)
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301
 # USA
 
+import os, os.path
 from distutils.core import setup, Extension
 
-module = Extension('_lxc', sources=['@srcdir@/lxc.c'],
-                   include_dirs=['@top_builddir@/src', '@top_srcdir@/src'],
-                   library_dirs=['@top_builddir@/src/lxc'], libraries=['lxc'])
+# 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': '@srcdir@/lxc'},
-      ext_modules=[module])
+      package_dir={'lxc': 'lxc'},
+      ext_modules=[module],
+      options={'build': {'build_base': os.path.join(builddir, 'build')}})