File: build_tests.py

package info (click to toggle)
libgpiod 2.2.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,108 kB
  • sloc: ansic: 26,612; sh: 7,554; cpp: 4,944; python: 2,426; makefile: 811; xml: 49
file content (95 lines) | stat: -rw-r--r-- 2,400 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# SPDX-License-Identifier: GPL-2.0-or-later
# SPDX-FileCopyrightText: 2023 Phil Howard <phil@gadgetoid.com>

"""
Bring up just enough of setuptools/distutils in order to build the gpiod
test module C extensions.

Set "build_temp" and "build_lib" so that our source directory is not
polluted with artefacts in build/

Builds:

    tests/gpiosim/_ext.<target>.so
    tests/procname/_ext.<target>.so

"""

import glob
import tempfile
from os import getenv, path

from setuptools import Distribution, Extension
from setuptools.command.build_ext import build_ext

TOP_SRCDIR = getenv("TOP_SRCDIR", "../../")
TOP_BUILDDIR = getenv("TOP_BUILDDIR", "../../")

# __version__
with open("gpiod/version.py", "r") as fd:
    exec(fd.read())

# The tests are run in-place with PYTHONPATH set to bindings/python
# so we need the gpiod extension module too.
gpiod_ext = Extension(
    "gpiod._ext",
    sources=glob.glob("gpiod/ext/*.c"),
    define_macros=[("_GNU_SOURCE", "1")],
    libraries=["gpiod"],
    extra_compile_args=["-Wall", "-Wextra"],
    include_dirs=[
        path.join(TOP_SRCDIR, "include"),
    ],
    library_dirs=[
        path.join(TOP_BUILDDIR, "lib/.libs"),
    ],
)

gpiosim_ext = Extension(
    "tests.gpiosim._ext",
    sources=["tests/gpiosim/ext.c"],
    define_macros=[("_GNU_SOURCE", "1")],
    libraries=["gpiosim"],
    extra_compile_args=["-Wall", "-Wextra"],
    include_dirs=[
        path.join(TOP_SRCDIR, "include"),
        path.join(TOP_SRCDIR, "tests/gpiosim"),
    ],
    library_dirs=[
        path.join(TOP_BUILDDIR, "lib/.libs"),
        path.join(TOP_BUILDDIR, "tests/gpiosim/.libs"),
    ],
)

procname_ext = Extension(
    "tests.procname._ext",
    sources=["tests/procname/ext.c"],
    define_macros=[("_GNU_SOURCE", "1")],
    extra_compile_args=["-Wall", "-Wextra"],
)

dist = Distribution(
    {
        "name": "gpiod",
        "ext_modules": [gpiosim_ext, procname_ext, gpiod_ext],
        "version": __version__,
        "platforms": ["linux"],
    }
)

try:
    from setuptools.logging import configure

    configure()
except ImportError:
    from distutils.log import DEBUG, set_verbosity

    set_verbosity(DEBUG)

with tempfile.TemporaryDirectory(prefix="libgpiod-") as temp_dir:
    command = build_ext(dist)
    command.inplace = True
    command.build_temp = temp_dir
    command.build_lib = temp_dir
    command.finalize_options()
    command.run()