Debian Codegraph @

tests/integration/testrpath/setup.py

raw
1 from __future__ import annotations
2
3 import os
4 import subprocess
5
6 from setuptools import Extension, setup
7 from setuptools.command.build_ext import build_ext
8
9 USE_DTAGS = os.getenv("DTAG") != "none"
10
11
12 class BuildExt(build_ext):
13 def run(self) -> None:
14 use_runpath = os.getenv("DTAG") == "runpath"
15 dtags_kind_flag = "--enable-new-dtags" if use_runpath else "--disable-new-dtags"
16 dtags = f"-Wl,{dtags_kind_flag} -Wl,-rpath=$ORIGIN/../b" if USE_DTAGS else ""
17
18 cmd = f"gcc -fPIC -shared -o b/libb.so {dtags} b/b.c"
19 subprocess.check_call(cmd.split())
20
21 dtags = f"-Wl,{dtags_kind_flag} -Wl,-rpath=$ORIGIN/../b" if USE_DTAGS else ""
22 cmd = f"gcc -fPIC -shared -o a/liba.so {dtags} -Ib a/a.c -Lb -lb"
23 subprocess.check_call(cmd.split())
24 super().run()
25
26
27 setup(
28 name="testrpath",
29 version="0.0.1",
30 packages=["testrpath"],
31 package_dir={"": "src"},
32 cmdclass={"build_ext": BuildExt},
33 ext_modules=[
34 Extension(
35 "testrpath/testrpath",
36 sources=["src/testrpath/testrpath.c"],
37 include_dirs=["a"],
38 libraries=["a"],
39 library_dirs=["a"] if USE_DTAGS else ["a", "b"],
40 ),
41 ],
42 )