[PATCH 2/2] pylibfdt: Compile and build libfdt directly into shim library

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



The interactions between pylibfdt setup.py and the host and build system
is fragile. setup.py can be called directly or via pip, tox, pytest, etc.
Building the SWIG shim library needs the libfdt headers and library .so
file. These can be located in the source tree, the OOT build directory,
or several locations in the host filesystem if installed.

Furthermore, the SWIG shim library is tightly coupled to the version of
libfdt it is built against. Specifically, all functions defined in the
libfdt.h header used for the build must resolve at runtime whether they
are used or not. IOW, the installed libfdt must be the same version (or
newer?) than what pylibfdt was built against.

The typical way to solve this problem would be to allow user provided
library and include directories, but this doesn't seem to work too well
with setup.py. While setup.py sub-commands can take such options, it
doesn't work with implicit commands (e.g. an 'install' triggers 'build')
or pip.

The simplest solution to all this is just build libfdt into the shim
library. This avoids any possibility of version mismatches. The python
setuptools already knows how to compile C files in extensions, we just need
to list the files.

Cc: Simon Glass <sjg@xxxxxxxxxxxx>
Cc: Hector Oron <zumbi@xxxxxxxxxx>
Cc: Peter Robinson <pbrobinson@xxxxxxxxx>
Cc: Marc-André Lureau <marcandre.lureau@xxxxxxxxxx>
Cc: Natanael Copa <ncopa@xxxxxxxxxxxxxxx>
Signed-off-by: Rob Herring <robh@xxxxxxxxxx>
---
RFC because this leaves the meson integration broken and I suspect the
distro folks (Cc'ed here) won't really like duplicating libfdt. Note that
the 'shim' alone is about 3x the size of libfdt.

IMO, the meson wrapper should just be removed. Python users know how to
run setup.py or pip. Why add a layer of indirection?
---
 MANIFEST.in |  4 +---
 setup.py    | 43 +++++++++++++++++--------------------------
 2 files changed, 18 insertions(+), 29 deletions(-)

diff --git a/MANIFEST.in b/MANIFEST.in
index 6e7244d195e6..45243f7f0057 100644
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -6,9 +6,7 @@ include GPL
 include BSD-2-Clause
 include setup.py
 include pylibfdt/libfdt.i
-include libfdt/libfdt.h
-include libfdt/fdt.h
-include libfdt/libfdt_env.h
+include libfdt/*
 include tests/test_pylibfdt.py
 include tests/test_tree1.dts
 include tests/test_props.dts
diff --git a/setup.py b/setup.py
index a8e54a361512..ba8ff556c44d 100755
--- a/setup.py
+++ b/setup.py
@@ -13,33 +13,26 @@ Written by Simon Glass <sjg@xxxxxxxxxxxx>
 from setuptools import setup, Extension
 from setuptools.command.build_py import build_py as _build_py
 
-import os
-import re
-import sys
-
-srcdir = os.path.dirname(__file__)
-
-with open(os.path.join(srcdir, "README"), "r") as fh:
+with open("README", "r") as fh:
     long_description = fh.read()
 
-def get_top_builddir():
-    if '--top-builddir' in sys.argv:
-        index = sys.argv.index('--top-builddir')
-        sys.argv.pop(index)
-        return sys.argv.pop(index)
-    else:
-        return srcdir
-
-top_builddir = get_top_builddir()
-
 libfdt_module = Extension(
     '_libfdt',
-    sources=[os.path.join(srcdir, 'pylibfdt/libfdt.i')],
+    sources=['pylibfdt/libfdt.i',
+             'libfdt/fdt.c',
+             'libfdt/fdt_ro.c',
+             'libfdt/fdt_rw.c',
+             'libfdt/fdt_sw.c',
+             'libfdt/fdt_wip.c',
+             'libfdt/fdt_addresses.c',
+             'libfdt/fdt_check.c',
+             'libfdt/fdt_empty_tree.c',
+             'libfdt/fdt_overlay.c',
+             'libfdt/fdt_strerror.c',
+             ],
     define_macros=[('PY_SSIZE_T_CLEAN', None)],
-    include_dirs=[os.path.join(srcdir, 'libfdt')],
-    libraries=['fdt'],
-    library_dirs=[os.path.join(top_builddir, 'libfdt')],
-    swig_opts=['-I' + os.path.join(srcdir, 'libfdt')],
+    include_dirs=['libfdt'],
+    swig_opts=['-Ilibfdt'],
 )
 
 class build_py(_build_py):
@@ -49,16 +42,14 @@ class build_py(_build_py):
 
 setup(
     name='libfdt',
-    use_scm_version={
-        "root": srcdir,
-    },
+    use_scm_version=True,
     cmdclass = {'build_py' : build_py},
     setup_requires = ['setuptools_scm'],
     author='Simon Glass',
     author_email='sjg@xxxxxxxxxxxx',
     description='Python binding for libfdt',
     ext_modules=[libfdt_module],
-    package_dir={'': os.path.join(srcdir, 'pylibfdt')},
+    package_dir={'': 'pylibfdt'},
     py_modules=['libfdt'],
 
     long_description=long_description,
-- 
2.32.0




[Index of Archives]     [Device Tree]     [Device Tree Spec]     [Linux Driver Backports]     [Video for Linux]     [Linux USB Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]

  Powered by Linux