pylibfdt: fix swig build in install

A 'pip install' is silently broken unless the tree is dirty and contains
pylibfdt/libfdt.py. The problem is a known issue[1] with SWIG and
setuptools where the 'build_py' stage needing module.py runs before
the 'build_ext' stage which generates it. The work-around is to override
'build_py' to run 'build_ext' first.

[1] https://stackoverflow.com/questions/50239473/building-a-module-with-setuptools-and-swig

Signed-off-by: Rob Herring <robh@kernel.org>
Message-Id: <20220203180408.611645-2-robh@kernel.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
Rob Herring 2022-02-03 12:04:07 -06:00 committed by David Gibson
parent 26c54f840d
commit c001fc01a4
2 changed files with 8 additions and 1 deletions

View file

@ -6,7 +6,6 @@ include GPL
include BSD-2-Clause include BSD-2-Clause
include setup.py include setup.py
include pylibfdt/libfdt.i include pylibfdt/libfdt.i
include pylibfdt/*.py
include libfdt/libfdt.h include libfdt/libfdt.h
include libfdt/fdt.h include libfdt/fdt.h
include libfdt/libfdt_env.h include libfdt/libfdt_env.h

View file

@ -11,6 +11,8 @@ Written by Simon Glass <sjg@chromium.org>
""" """
from setuptools import setup, Extension from setuptools import setup, Extension
from setuptools.command.build_py import build_py as _build_py
import os import os
import re import re
import sys import sys
@ -40,11 +42,17 @@ libfdt_module = Extension(
swig_opts=['-I' + os.path.join(srcdir, 'libfdt')], swig_opts=['-I' + os.path.join(srcdir, 'libfdt')],
) )
class build_py(_build_py):
def run(self):
self.run_command("build_ext")
return super().run()
setup( setup(
name='libfdt', name='libfdt',
use_scm_version={ use_scm_version={
"root": srcdir, "root": srcdir,
}, },
cmdclass = {'build_py' : build_py},
setup_requires = ['setuptools_scm'], setup_requires = ['setuptools_scm'],
author='Simon Glass', author='Simon Glass',
author_email='sjg@chromium.org', author_email='sjg@chromium.org',