mirror of
https://gitlab.com/libvirt/libvirt-python.git
synced 2025-12-23 12:23:47 +03:00
setup: override 'build_ext' / 'build_py' commands rather than 'build'
We override the 'build' command to invoke the code generator before the extensions are compiled. The 'build' command, however, is merely a wrapper around several other commands. It is possible for the user to directly invoke those commands, in which case our code generator won't get a chance to run: $ python setup.py build_ext running build_ext building 'libvirtmod' extension creating build/temp.linux-x86_64-3.10 creating build/temp.linux-x86_64-3.10/build gcc ..snip... -c build/libvirt.c -o build/temp.linux-x86_64-3.10/build/libvirt.o cc1: fatal error: build/libvirt.c: No such file or directory compilation terminated. error: command '/usr/lib64/ccache/gcc' failed with exit code 1 To solve this we instead override 'build_ext' and 'build_py'. This in turn means we call the generator to emit C code separately from Python code. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
29
setup.py
29
setup.py
@@ -1,7 +1,8 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from distutils.core import setup, Extension, Command
|
||||
from distutils.command.build import build
|
||||
from distutils.command.build_ext import build_ext
|
||||
from distutils.command.build_py import build_py
|
||||
from distutils.command.sdist import sdist
|
||||
from distutils.util import get_platform
|
||||
|
||||
@@ -132,19 +133,32 @@ def get_module_lists():
|
||||
# Custom commands #
|
||||
###################
|
||||
|
||||
class my_build(build):
|
||||
class my_build_ext(build_ext):
|
||||
|
||||
def run(self):
|
||||
check_minimum_libvirt_version()
|
||||
apis = get_api_xml_files()
|
||||
|
||||
subprocess.check_call([sys.executable, "generator.py", "libvirt", apis[0]])
|
||||
subprocess.check_call([sys.executable, "generator.py", "libvirt-qemu", apis[1]])
|
||||
subprocess.check_call([sys.executable, "generator.py", "libvirt", apis[0], "c"])
|
||||
subprocess.check_call([sys.executable, "generator.py", "libvirt-qemu", apis[1], "c"])
|
||||
if have_libvirt_lxc():
|
||||
subprocess.check_call([sys.executable, "generator.py", "libvirt-lxc", apis[2]])
|
||||
subprocess.check_call([sys.executable, "generator.py", "libvirt-lxc", apis[2], "c"])
|
||||
|
||||
build_ext.run(self)
|
||||
|
||||
class my_build_py(build_py):
|
||||
|
||||
def run(self):
|
||||
check_minimum_libvirt_version()
|
||||
apis = get_api_xml_files()
|
||||
|
||||
subprocess.check_call([sys.executable, "generator.py", "libvirt", apis[0], "py"])
|
||||
subprocess.check_call([sys.executable, "generator.py", "libvirt-qemu", apis[1], "py"])
|
||||
if have_libvirt_lxc():
|
||||
subprocess.check_call([sys.executable, "generator.py", "libvirt-lxc", apis[2], "py"])
|
||||
shutil.copy('libvirtaio.py', 'build')
|
||||
|
||||
build.run(self)
|
||||
build_py.run(self)
|
||||
|
||||
class my_sdist(sdist):
|
||||
user_options = sdist.user_options
|
||||
@@ -324,7 +338,8 @@ of recent versions of Linux (and other OSes).''',
|
||||
'': 'build'
|
||||
},
|
||||
cmdclass = {
|
||||
'build': my_build,
|
||||
'build_ext': my_build_ext,
|
||||
'build_py': my_build_py,
|
||||
'clean': my_clean,
|
||||
'sdist': my_sdist,
|
||||
'test': my_test
|
||||
|
||||
Reference in New Issue
Block a user