Commit a180fd98 authored by Cole Robinson's avatar Cole Robinson

setup.py: Allow running --help or clean without pkg-config

If pkg-config isn't installed, or a too old libvirt, we can't even
do 'python setup.py --help' without throwing an exception.

Have the pkg-config checks and validation only throw an exception if
being called from the 'build' step.

https://bugzilla.redhat.com/show_bug.cgi?id=1074170
parent 115760f6
...@@ -24,19 +24,24 @@ MIN_LIBVIRT_LXC = "1.0.2" ...@@ -24,19 +24,24 @@ MIN_LIBVIRT_LXC = "1.0.2"
if not os.path.exists("build"): if not os.path.exists("build"):
os.mkdir("build") os.mkdir("build")
pkgcfg = distutils.spawn.find_executable("pkg-config") _pkgcfg = -1
def get_pkgcfg(do_fail=True):
if pkgcfg is None: global _pkgcfg
raise Exception("pkg-config binary is required to compile libvirt-python") if _pkgcfg == -1:
_pkgcfg = distutils.spawn.find_executable("pkg-config")
spawn([pkgcfg, if _pkgcfg is None and do_fail:
"--print-errors", raise Exception("pkg-config binary is required to compile libvirt-python")
"--atleast-version=%s" % MIN_LIBVIRT, return _pkgcfg
"libvirt"])
def check_minimum_libvirt_version():
spawn([get_pkgcfg(),
"--print-errors",
"--atleast-version=%s" % MIN_LIBVIRT,
"libvirt"])
def have_libvirt_lxc(): def have_libvirt_lxc():
try: try:
spawn([pkgcfg, spawn([get_pkgcfg(),
"--atleast-version=%s" % MIN_LIBVIRT_LXC, "--atleast-version=%s" % MIN_LIBVIRT_LXC,
"libvirt"]) "libvirt"])
return True return True
...@@ -45,7 +50,7 @@ def have_libvirt_lxc(): ...@@ -45,7 +50,7 @@ def have_libvirt_lxc():
def get_pkgconfig_data(args, mod, required=True): def get_pkgconfig_data(args, mod, required=True):
"""Run pkg-config to and return content associated with it""" """Run pkg-config to and return content associated with it"""
f = os.popen("%s %s %s" % (pkgcfg, " ".join(args), mod)) f = os.popen("%s %s %s" % (get_pkgcfg(), " ".join(args), mod))
line = f.readline() line = f.readline()
if line is not None: if line is not None:
...@@ -78,6 +83,9 @@ def get_module_lists(): ...@@ -78,6 +83,9 @@ def get_module_lists():
Determine which modules we are actually building, and all their Determine which modules we are actually building, and all their
required config required config
""" """
if get_pkgcfg(do_fail=False) is None:
return [], []
c_modules = [] c_modules = []
py_modules = [] py_modules = []
ldflags = get_pkgconfig_data(["--libs-only-L"], "libvirt", False) ldflags = get_pkgconfig_data(["--libs-only-L"], "libvirt", False)
...@@ -130,6 +138,7 @@ def get_module_lists(): ...@@ -130,6 +138,7 @@ def get_module_lists():
class my_build(build): class my_build(build):
def run(self): def run(self):
check_minimum_libvirt_version()
apis = get_api_xml_files() apis = get_api_xml_files()
self.spawn([sys.executable, "generator.py", "libvirt", apis[0]]) self.spawn([sys.executable, "generator.py", "libvirt", apis[0]])
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment