diff mbox series

trace-cruncher: Check required library versions before building

Message ID 20220224085233.112129-1-y.karadz@gmail.com (mailing list archive)
State Accepted
Headers show
Series trace-cruncher: Check required library versions before building | expand

Commit Message

Yordan Karadzhov Feb. 24, 2022, 8:52 a.m. UTC
Do not build trace-cruncher if the minimum version required for some
of the third party libraries is not found.

Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
---
 setup.py | 52 +++++++++++++++++++++++++++++++++++++---------------
 1 file changed, 37 insertions(+), 15 deletions(-)

Comments

Steven Rostedt Feb. 24, 2022, 2:21 p.m. UTC | #1
On Thu, 24 Feb 2022 10:52:33 +0200
"Yordan Karadzhov (VMware)" <y.karadz@gmail.com> wrote:

>      include_dirs = [np.get_include()]
> -    include_dirs.extend(pkg_traceevent['include_dirs'])
> -    include_dirs.extend(pkg_ftracepy['include_dirs'])
> -    include_dirs.extend(pkg_tracecmd['include_dirs'])
> -    include_dirs.extend(pkg_kshark['include_dirs'])
> +    libs_required = [('libtraceevent', '1.5.0'),
> +                     ('libtracefs',    '1.3.0'),

Nice :-)

-- Steve

> +                     ('libkshark',     '2.0.1')]
> +    libs_found = []
diff mbox series

Patch

diff --git a/setup.py b/setup.py
index 4d7e727..c9c0142 100644
--- a/setup.py
+++ b/setup.py
@@ -5,6 +5,7 @@  SPDX-License-Identifier: LGPL-2.1
 
 Copyright 2019 VMware Inc, Yordan Karadzhov (VMware) <y.karadz@gmail.com>
 """
+import sys
 
 from setuptools import setup, find_packages
 from distutils.core import Extension
@@ -13,24 +14,45 @@  from Cython.Build import cythonize
 import pkgconfig as pkg
 import numpy as np
 
+def version_check(lib, lib_version, min_version):
+    min_v = min_version.split('.')
+    lib_v = pkg.modversion(lib).split('.')
+    if lib_v[2] == 'dev':
+        lib_v[2] = '0'
+
+    if tuple(map(int, lib_v)) < tuple(map(int, min_v)):
+        print('{0} v{1} is required'.format(lib, min_version))
+        return False
+    return True
+
+def add_library(lib, min_version,
+                libs_found,
+                library_dirs,
+                include_dirs):
+    pkg_info = pkg.parse(lib)
+    lib_version = pkg.modversion(lib)
+    if version_check(lib, lib_version, min_version):
+        include_dirs.extend(pkg_info['include_dirs'])
+        library_dirs.extend(pkg_info['library_dirs'])
+        libs_found.extend([(lib, lib_version)])
 
 def third_party_paths():
-    pkg_traceevent = pkg.parse('libtraceevent')
-    pkg_ftracepy = pkg.parse('libtracefs')
-    pkg_tracecmd = pkg.parse('libtracecmd')
-    pkg_kshark = pkg.parse('libkshark')
-
+    library_dirs = []
     include_dirs = [np.get_include()]
-    include_dirs.extend(pkg_traceevent['include_dirs'])
-    include_dirs.extend(pkg_ftracepy['include_dirs'])
-    include_dirs.extend(pkg_tracecmd['include_dirs'])
-    include_dirs.extend(pkg_kshark['include_dirs'])
+    libs_required = [('libtraceevent', '1.5.0'),
+                     ('libtracefs',    '1.3.0'),
+                     ('libkshark',     '2.0.1')]
+    libs_found = []
+
+    for lib in libs_required:
+        add_library(lib[0], lib[1],
+                    libs_found,
+                    library_dirs,
+                    include_dirs)
+
+    if len(libs_found) < len(libs_required):
+        sys.exit(1)
 
-    library_dirs = []
-    library_dirs.extend(pkg_traceevent['library_dirs'])
-    library_dirs.extend(pkg_ftracepy['library_dirs'])
-    library_dirs.extend(pkg_tracecmd['library_dirs'])
-    library_dirs.extend(pkg_kshark['library_dirs'])
     library_dirs = list(set(library_dirs))
 
     return include_dirs, library_dirs
@@ -52,7 +74,7 @@  def main():
                           sources=['src/ftracepy.c', 'src/ftracepy-utils.c'],
                           libraries=['traceevent', 'tracefs'])
 
-    cythonize('src/npdatawrapper.pyx', language_level = "3")
+    cythonize('src/npdatawrapper.pyx', language_level = '3')
     module_data = extension(name='tracecruncher.npdatawrapper',
                             sources=['src/npdatawrapper.c'],
                             libraries=['kshark'])