-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.py
executable file
·94 lines (72 loc) · 2.36 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
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
#!/usr/bin/env python3
"""
Run meson and ninja to build the ots static libs from source.
"""
import sys
from pathlib import Path
import os
import subprocess
import shutil
import errno
import argparse
ROOT = Path(__file__).parent.resolve()
BUILD_ROOT = ROOT / "src" / "ots" / "build"
BUILD_DIR = BUILD_ROOT / "meson"
SRC_DIR = ROOT / "src"
OTS_SRC_DIR = SRC_DIR / "ots"
SUB_DIR = OTS_SRC_DIR / "subprojects"
if 'manylinux' in os.environ.get("AUDITWHEEL_PLAT", ''):
os.environ["PATH"] += os.pathsep + os.path.dirname(sys.executable)
TOOLS = {
"meson": os.environ.get("MESON_EXE", "meson"),
"ninja": os.environ.get("NINJA_EXE", "ninja"),
}
MESON_CMD = [
TOOLS["meson"],
"--backend=ninja",
"--buildtype=release",
"--strip",
"--default-library=static",
"--force-fallback-for=libbrotlidec,liblz4",
str(BUILD_DIR),
str(OTS_SRC_DIR),
]
NINJA_CMD = [TOOLS["ninja"], "-C", str(BUILD_DIR)]
class ExecutableNotFound(FileNotFoundError):
def __init__(self, name, path):
msg = f"{name} executable not found: '{path}'"
super().__init__(errno.ENOENT, msg)
def check_tools():
for name, path in TOOLS.items():
if shutil.which(path) is None:
raise ExecutableNotFound(name, path)
def configure(reconfigure=False):
print(f"build.py: Running {' '.join(MESON_CMD)}")
if not (BUILD_DIR / "build.ninja").exists():
subprocess.run(MESON_CMD, check=True, env=os.environ)
elif reconfigure:
subprocess.run(MESON_CMD + ["--reconfigure"],
check=True,
env=os.environ)
def make(*targets, clean=False):
print(f"build.py: Running {' '.join(NINJA_CMD)}")
targets = list(targets)
if clean:
subprocess.run(NINJA_CMD + ["-t", "clean"] + targets,
check=True,
env=os.environ)
subprocess.run(NINJA_CMD + targets, check=True, env=os.environ)
def main(args=None):
parser = argparse.ArgumentParser()
parser.add_argument("-f", "--force", action="store_true")
parser.add_argument("targets", nargs="*")
options = parser.parse_args(args)
check_tools()
try:
configure(reconfigure=options.force)
make(*options.targets, clean=options.force)
except subprocess.CalledProcessError as e:
return e.returncode
return 0
if __name__ == "__main__":
sys.exit(main())