diff options
author | Simon Glass <sjg@chromium.org> | 2022-07-30 20:57:11 -0600 |
---|---|---|
committer | Simon Glass <sjg@chromium.org> | 2022-10-29 07:36:33 -0600 |
commit | 6b08fb5cc44f8d32260a17a4f04c5bfa8dd5f18f (patch) | |
tree | c52361084761b2d12d16bdabb994dbfb166a4cbb /scripts/dtc/pylibfdt/setup.py | |
parent | 529b2c2d9c757b3ed7d898c90ab7611f1b0c9d0f (diff) |
fdt: Move to setuptools
The distutils package is deprecated. The upstream libfdt repo uses
setuptools for building the pylibfdt module, so bring in that code,
suitably modified for U-Boot. Also bring in the README.
The modifications include setting the version correctly, making use of
the environment variables provided by the Makefile and various tweaks
to the directories.
Note that the version omits the minus character at the start of
EXTRAVERSION, since this creates a warning. The build is really just used
within U-Boot itself, so it doesn't matter too much if the version matches
upstream, or exactly matches U-Boot.
Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'scripts/dtc/pylibfdt/setup.py')
-rwxr-xr-x | scripts/dtc/pylibfdt/setup.py | 57 |
1 files changed, 48 insertions, 9 deletions
diff --git a/scripts/dtc/pylibfdt/setup.py b/scripts/dtc/pylibfdt/setup.py index 992cdec30f5..ec1fc5002b0 100755 --- a/scripts/dtc/pylibfdt/setup.py +++ b/scripts/dtc/pylibfdt/setup.py @@ -1,11 +1,13 @@ #!/usr/bin/env python3 +# SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) """ setup.py file for SWIG libfdt Copyright (C) 2017 Google, Inc. Written by Simon Glass <sjg@chromium.org> -SPDX-License-Identifier: GPL-2.0+ BSD-2-Clause +This script is modified from the upstream version, to fit in with the U-Boot +build system. Files to be built into the extension are provided in SOURCES C flags to use are provided in CPPFLAGS @@ -18,14 +20,29 @@ allows this script to be run stand-alone, e.g.: ./pylibfdt/setup.py install [--prefix=...] """ -from distutils.core import setup, Extension +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: + long_description = fh.read() + # Decodes a Makefile assignment line into key and value (and plus for +=) RE_KEY_VALUE = re.compile('(?P<key>\w+) *(?P<plus>[+])?= *(?P<value>.*)$') +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 os.path.join(srcdir, '..') + +top_builddir = get_top_builddir() def ParseMakefile(fname): """Parse a Makefile to obtain its variables. @@ -86,7 +103,7 @@ def GetEnvFromMakefiles(): makevars = ParseMakefile(os.path.join(basedir, 'libfdt', 'Makefile.libfdt')) files = makevars['LIBFDT_SRCS'].split() files = [os.path.join(basedir, 'libfdt', fname) for fname in files] - files.append('pylibfdt/libfdt.i') + files.append('libfdt.i') cflags = ['-I%s' % basedir, '-I%s/libfdt' % basedir] objdir = '' return swig_opts, version, files, cflags, objdir @@ -107,17 +124,39 @@ if not all((swig_opts, version, files, cflags, objdir)): libfdt_module = Extension( '_libfdt', - sources = files, - extra_compile_args = cflags, - swig_opts = swig_opts, + sources=files, + include_dirs=[os.path.join(srcdir, 'libfdt')], + library_dirs=[os.path.join(top_builddir, 'libfdt')], + swig_opts=swig_opts, ) +class build_py(_build_py): + def run(self): + self.run_command("build_ext") + return super().run() + setup( name='libfdt', - version= version, - author='Simon Glass <sjg@chromium.org>', + version=version, + cmdclass = {'build_py' : build_py}, + author='Simon Glass', + author_email='sjg@chromium.org', description='Python binding for libfdt', ext_modules=[libfdt_module], package_dir={'': objdir}, - py_modules=['pylibfdt/libfdt'], + py_modules=['libfdt'], + + long_description=long_description, + long_description_content_type="text/plain", + url="https://git.kernel.org/pub/scm/utils/dtc/dtc.git", + license="BSD", + license_files=["GPL", "BSD-2-Clause"], + + classifiers=[ + "Programming Language :: Python :: 3", + "License :: OSI Approved :: BSD License", + "License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)", + "Operating System :: OS Independent", + ], + ) |