X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=src%2Fbindings%2Fpython%2Fbt2%2Fsetup.py.in;h=3c81447ea80a2d8dd928f43aba69feea2bf7f980;hb=d5689f248e1ba03a717e00dc8b0847457d47bef1;hp=0d1ca724c38f910b43bb0f805bc9bb68238da148;hpb=5ce6587ec3f88d44a90ff285aeb7ab07aea9bed7;p=babeltrace.git diff --git a/src/bindings/python/bt2/setup.py.in b/src/bindings/python/bt2/setup.py.in index 0d1ca724..3c81447e 100644 --- a/src/bindings/python/bt2/setup.py.in +++ b/src/bindings/python/bt2/setup.py.in @@ -5,6 +5,8 @@ import sys import os +import shutil +import subprocess # Distutils was removed in Python 3.12, use setuptools as an alternative. if sys.version_info >= (3, 12): @@ -114,10 +116,44 @@ def our_get_config_vars(*args): sysconfig.get_config_vars = our_get_config_vars +# Returns 'True' when running on a MinGW system. +def is_mingw(): + return sys.platform == "win32" and shutil.which("cygpath") != None + + +# On MinGW systems run 'cygpath -m' on 'path', on other systems return 'path' as-is. +def cygpath_m(path: str): + if is_mingw(): + return subprocess.check_output( + 'cygpath -m "{}"'.format(path), shell=True, encoding="utf-8" + ).strip("\n") + + return path + + +# On MinGW systems, check CFLAGS and CPPFLAGS for absolute include paths +# (starts with '-I/') and convert them to valid Windows paths using cygpath. +if is_mingw(): + for flagvar in ["CFLAGS", "CPPFLAGS"]: + cur_flags = os.getenv(flagvar) + if cur_flags != None: + new_flags = "" + for flag in cur_flags.split(): + if flag.startswith("-I/"): + flag = "-I{}".format(cygpath_m(flag[2:])) + + new_flags += " {}".format(flag) + + os.environ[flagvar] = new_flags + + def main(): babeltrace_ext = Extension( "bt2._native_bt", - sources=["bt2/native_bt.c", "@srcdir@/bt2/logging.c"], + sources=[ + "bt2/native_bt.c", + cygpath_m("@srcdir@/bt2/logging.c"), + ], libraries=["babeltrace2", "glib-2.0"], extra_objects=[ "@top_builddir@/src/autodisc/.libs/libautodisc.a",