X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=src%2Fbindings%2Fpython%2Fbt2%2Fsetup.py.in;h=acb645096d8b2cc80c40515cb8fe1b8ddc5b7233;hb=afdd1f8201f579d81959ce85759dcc62fcc0a85d;hp=682cbbc0c52ac7630af93624be84bfd9d387e16b;hpb=e7d63bf32268fcaf9e1f5724cf4def49f3f9c081;p=babeltrace.git diff --git a/src/bindings/python/bt2/setup.py.in b/src/bindings/python/bt2/setup.py.in index 682cbbc0..acb64509 100644 --- a/src/bindings/python/bt2/setup.py.in +++ b/src/bindings/python/bt2/setup.py.in @@ -1,6 +1,7 @@ # The MIT License (MIT) # # Copyright (C) 2017 - Francis Deslauriers +# Copyright (C) 2020 - Jérémie Galarneau # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal @@ -21,6 +22,8 @@ # THE SOFTWARE. import sys +import os +import distutils.sysconfig from distutils.core import setup, Extension @@ -34,46 +37,113 @@ following command to your .bashrc/.zshrc: -------------------------------------------------------------------------------- """ +original_get_config_vars = distutils.sysconfig.get_config_vars + + +def get_cflags(): + cflags = os.environ.get('CFLAGS') + + if cflags is None: + [cflags] = original_get_config_vars('CFLAGS') + + return cflags + + +# distutils performs a similar transformation step on LDSHARED on +# darwin to use the overriden CC as the default command for LDSHARED +# (see distutils' customize_compiler() step in the sysconfig module). +# +# This takes it a step further by using our own LDFLAGS (when available) +# along with the overriden compiler and ensure that flags that are unsupported +# by either the Python interprter's CC or the overriden CC don't cause a +# build failure. +def get_ldshared(): + cc = os.environ.get('CC') + ldflags = os.environ.get('LDFLAGS') + [py_cc] = original_get_config_vars('CC') + [py_ldshared] = original_get_config_vars('LDSHARED') + + if not py_ldshared.startswith(py_cc): + return py_ldshared + + if cc and ldflags: + return '{} -shared {}'.format(cc, ldflags) + elif cc: + return cc + py_ldshared[len(py_cc) :] + elif ldflags: + return py_cc + py_ldshared[len(py_cc) :] + else: + return py_ldshared + + +def our_get_config_vars(*args): + overridden_config_vars = { + 'CFLAGS': get_cflags(), + 'LDSHARED': get_ldshared(), + } + + if len(args) == 0: + all_config_vars = original_get_config_vars() + for name in overridden_config_vars: + all_config_vars[name] = overridden_config_vars[name] + return all_config_vars + + subset_config_vars = [] + for name in args: + if name not in overridden_config_vars: + [var] = original_get_config_vars(name) + subset_config_vars.append(var) + continue + + subset_config_vars.append(overridden_config_vars[name]) + + return subset_config_vars + + +distutils.sysconfig.get_config_vars = our_get_config_vars + + def main(): - babeltrace_ext = Extension('bt2._native_bt', - sources=['bt2/native_bt.c', 'bt2/logging.c'], - libraries=['babeltrace2', 'glib-2.0'], - extra_objects=['@top_builddir@/src/logging/.libs/libbabeltrace2-logging.a', - '@top_builddir@/src/common/.libs/libbabeltrace2-common.a', - '@top_builddir@/src/py-common/.libs/libbabeltrace2-py-common.a']) - - dist = setup(name='bt2', - version='@PACKAGE_VERSION@', - description='Babeltrace 2 Python Bindings', - packages=['bt2'], - package_dir={'bt2': 'bt2'}, - options={'build': - { - 'build_base': 'build', - 'build_lib': 'build/build_lib' - }, - 'build_ext': - { - 'build_lib': 'build/build_lib' - } - }, - url='http://diamon.org/babeltrace', - ext_modules=[babeltrace_ext], - license='MIT', - classifiers=[ - 'Development Status :: 5 - Production/Stable', - 'Intended Audience :: Developers', - 'License :: OSI Approved :: The MIT License', - 'Programming Language :: Python :: 3' - 'Topic :: System :: Logging', - ]) - -# After the installation, we check that the install directory is included in -# the Python search path and we print a warning message when it's not. -# We need to do this because Python search path differs depending on the distro -# and some distros don't include any /usr/local/ in the search path. This is -# also useful for out-of-tree installs and tests. -# It's only relevant to make this check on the `install` command. + babeltrace_ext = Extension( + 'bt2._native_bt', + sources=['bt2/native_bt.c', '@srcdir@/bt2/logging.c'], + libraries=['babeltrace2', 'glib-2.0'], + extra_objects=[ + '@top_builddir@/src/autodisc/.libs/libbabeltrace2-autodisc.a', + '@top_builddir@/src/logging/.libs/libbabeltrace2-logging.a', + '@top_builddir@/src/common/.libs/libbabeltrace2-common.a', + '@top_builddir@/src/py-common/.libs/libbabeltrace2-py-common.a', + '@top_builddir@/src/string-format/.libs/libbabeltrace2-string-format.a', + ], + ) + + dist = setup( + name='bt2', + version='@PACKAGE_VERSION@', + description='Babeltrace 2 Python Bindings', + packages=['bt2'], + package_dir={'bt2': 'bt2'}, + options={ + 'build': {'build_base': 'build', 'build_lib': 'build/build_lib'}, + 'build_ext': {'build_lib': 'build/build_lib'}, + }, + url='https://babeltrace.org/', + ext_modules=[babeltrace_ext], + license='MIT', + classifiers=[ + 'Development Status :: 5 - Production/Stable', + 'Intended Audience :: Developers', + 'License :: OSI Approved :: The MIT License', + 'Programming Language :: Python :: 3' 'Topic :: System :: Logging', + ], + ) + + # After the installation, we check that the install directory is included in + # the Python search path and we print a warning message when it's not. + # We need to do this because Python search path differs depending on the distro + # and some distros don't include any /usr/local/ in the search path. This is + # also useful for out-of-tree installs and tests. + # It's only relevant to make this check on the `install` command. if 'install' in dist.command_obj: install_dir = dist.command_obj['install'].install_libbase @@ -83,5 +153,6 @@ def main(): # extra configuration is needed to use the bindings print(PY_PATH_WARN_MSG.format(install_dir, install_dir)) + if __name__ == "__main__": main()