-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmake.py
More file actions
106 lines (83 loc) · 2.62 KB
/
Copy pathmake.py
File metadata and controls
106 lines (83 loc) · 2.62 KB
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
96
97
98
99
100
101
102
103
104
105
106
import argparse
import subprocess
import sys
from pathlib import Path
def log(level, message):
print(f"[{level}] {message}")
def error(message, should_exit=False):
log("ERROR", message)
if should_exit:
sys.exit(1)
def info(message):
log("INFO", message)
ROOT = Path(__file__).resolve().parent
def python():
venv_dir = Path(VENV_DIR)
if sys.platform == "win32":
return str(venv_dir / "Scripts" / "python.exe")
else:
return str(venv_dir / "bin" / "python")
def subcommand_setup():
build_dir = Path(BUILD_DIR)
venv_dir = Path(VENV_DIR)
build_dir.mkdir(parents=True, exist_ok=True)
subprocess.run([sys.executable, "-m", "venv", str(venv_dir)], check=True)
subprocess.run(
[python(), "-m", "pip", "install", "-r", "requirements.dev.txt"], check=True
)
try:
subprocess.run(["cmake", "-S", ".", "-B", str(build_dir)], check=True)
except subprocess.CalledProcessError as e:
error(f"CMake configure failed with exit code {e.returncode}")
def subcommand_build():
command = ["cmake", "--build", BUILD_DIR]
if FORCE_BUILD:
command.append("--clean-first")
subprocess.run(command, check=True)
def subcommand_test():
subprocess.run(
[python(), "-m", "pytest", f"--build-dir={BUILD_DIR}", "-v"],
cwd=ROOT,
check=True,
)
if __name__ == "__main__":
parser = argparse.ArgumentParser(
prog="make.py", description="Lambda Discipline build tool"
)
parser.add_argument(
"--build-dir",
default="cmake-build-debug",
help="CMake build directory (default: %(default)s)",
)
parser.add_argument(
"--force",
action="store_true",
help="Clean before building",
)
parser.add_argument(
"--warnings-as-errors",
action="store_true",
help="Treat compiler warnings as errors",
)
parser.add_argument(
"--venv-dir",
default="venv",
help="Python virtual environment directory (default: %(default)s)",
)
subparsers = parser.add_subparsers(dest="command", required=True)
subparsers.add_parser(
"setup", help="Create venv, install dependencies, and configure CMake"
)
subparsers.add_parser("build", help="Build the project")
subparsers.add_parser("test", help="Run tests")
args = parser.parse_args()
BUILD_DIR = args.build_dir
VENV_DIR = args.venv_dir
FORCE_BUILD = args.force
match args.command:
case "setup":
subcommand_setup()
case "build":
subcommand_build()
case "test":
subcommand_test()