-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathbuild.py
46 lines (35 loc) · 1.13 KB
/
build.py
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
# Copyright (c) 2020 6WIND S.A.
# SPDX-License-Identifier: BSD-3-Clause
import os
import shlex
from typing import List
import cffi
HERE = os.path.dirname(__file__)
BUILDER = cffi.FFI()
with open(os.path.join(HERE, "cdefs.h"), encoding="utf-8") as f:
BUILDER.cdef(f.read())
def search_paths(env_var: str) -> List[str]:
paths = []
for p in os.environ.get(env_var, "").strip().split(":"):
p = p.strip()
if p:
paths.append(p)
return paths
HEADERS = search_paths("SYSREPO_HEADERS")
LIBRARIES = search_paths("SYSREPO_LIBRARIES")
EXTRA_CFLAGS = ["-Werror", "-std=c99"]
EXTRA_CFLAGS += shlex.split(os.environ.get("SYSREPO_EXTRA_CFLAGS", ""))
EXTRA_LDFLAGS = shlex.split(os.environ.get("SYSREPO_EXTRA_LDFLAGS", ""))
with open(os.path.join(HERE, "source.c"), encoding="utf-8") as f:
BUILDER.set_source(
"_sysrepo",
f.read(),
libraries=["sysrepo", "yang"],
extra_compile_args=EXTRA_CFLAGS,
extra_link_args=EXTRA_LDFLAGS,
include_dirs=HEADERS,
library_dirs=LIBRARIES,
py_limited_api=False,
)
if __name__ == "__main__":
BUILDER.compile()