linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Yordan Karadzhov (VMware)" <y.karadz@gmail.com>
To: linux-trace-devel@vger.kernel.org
Cc: "Yordan Karadzhov (VMware)" <y.karadz@gmail.com>
Subject: [PATCH] trace-cruncher: Check required library versions before building
Date: Thu, 24 Feb 2022 10:52:33 +0200	[thread overview]
Message-ID: <20220224085233.112129-1-y.karadz@gmail.com> (raw)

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


             reply	other threads:[~2022-02-24  8:52 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-24  8:52 Yordan Karadzhov (VMware) [this message]
2022-02-24 14:21 ` [PATCH] trace-cruncher: Check required library versions before building Steven Rostedt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220224085233.112129-1-y.karadz@gmail.com \
    --to=y.karadz@gmail.com \
    --cc=linux-trace-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).