linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] trace-cruncher: Check required library versions before building
@ 2022-02-24  8:52 Yordan Karadzhov (VMware)
  2022-02-24 14:21 ` Steven Rostedt
  0 siblings, 1 reply; 2+ messages in thread
From: Yordan Karadzhov (VMware) @ 2022-02-24  8:52 UTC (permalink / raw)
  To: linux-trace-devel; +Cc: Yordan Karadzhov (VMware)

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(-)

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'])
-- 
2.32.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-02-24 14:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-02-24  8:52 [PATCH] trace-cruncher: Check required library versions before building Yordan Karadzhov (VMware)
2022-02-24 14:21 ` Steven Rostedt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).