Debian Codegraph @

bindings/python/build_tests.py

raw symbols SCIP
1 # SPDX-License-Identifier: GPL-2.0-or-later
2 # SPDX-FileCopyrightText: 2023 Phil Howard <[email protected]>
3
4 """
5 Bring up just enough of setuptools/distutils in order to build the gpiod
6 test module C extensions.
7
8 Set "build_temp" and "build_lib" so that our source directory is not
9 polluted with artefacts in build/
10
11 Builds:
12
13 tests/gpiosim/_ext.<target>.so
14 tests/procname/_ext.<target>.so
15
16 """
17
18 import glob
19 import tempfile
20 from os import getenv, path
21
22 from setuptools import Distribution, Extension
23 from setuptools.command.build_ext import build_ext
24
25 TOP_SRCDIR = getenv("TOP_SRCDIR", "../../")
26 TOP_BUILDDIR = getenv("TOP_BUILDDIR", "../../")
27
28 # __version__
29 with open("gpiod/version.py", "r") as fd:
30 exec(fd.read())
31
32 # The tests are run in-place with PYTHONPATH set to bindings/python
33 # so we need the gpiod extension module too.
34 gpiod_ext = Extension(
35 "gpiod._ext",
36 sources=glob.glob("gpiod/ext/*.c"),
37 define_macros=[("_GNU_SOURCE", "1")],
38 libraries=["gpiod"],
39 extra_compile_args=["-Wall", "-Wextra"],
40 include_dirs=[
41 path.join(TOP_SRCDIR, "include"),
42 ],
43 library_dirs=[
44 path.join(TOP_BUILDDIR, "lib/.libs"),
45 ],
46 )
47
48 gpiosim_ext = Extension(
49 "tests.gpiosim._ext",
50 sources=["tests/gpiosim/ext.c"],
51 define_macros=[("_GNU_SOURCE", "1")],
52 libraries=["gpiosim"],
53 extra_compile_args=["-Wall", "-Wextra"],
54 include_dirs=[
55 path.join(TOP_SRCDIR, "include"),
56 path.join(TOP_SRCDIR, "tests/gpiosim"),
57 ],
58 library_dirs=[
59 path.join(TOP_BUILDDIR, "lib/.libs"),
60 path.join(TOP_BUILDDIR, "tests/gpiosim/.libs"),
61 ],
62 )
63
64 procname_ext = Extension(
65 "tests.procname._ext",
66 sources=["tests/procname/ext.c"],
67 define_macros=[("_GNU_SOURCE", "1")],
68 extra_compile_args=["-Wall", "-Wextra"],
69 )
70
71 dist = Distribution(
72 {
73 "name": "gpiod",
74 "ext_modules": [gpiosim_ext, procname_ext, gpiod_ext],
75 "version": __version__,
76 "platforms": ["linux"],
77 }
78 )
79
80 try:
81 from setuptools.logging import configure
82
83 configure()
84 except ImportError:
85 from distutils.log import DEBUG, set_verbosity
86
87 set_verbosity(DEBUG)
88
89 with tempfile.TemporaryDirectory(prefix="libgpiod-") as temp_dir:
90 command = build_ext(dist)
91 command.inplace = True
92 command.build_temp = temp_dir
93 command.build_lib = temp_dir
94 command.finalize_options()
95 command.run()