-
Notifications
You must be signed in to change notification settings - Fork 0
/
build
executable file
·76 lines (52 loc) · 2.26 KB
/
build
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
#!/usr/bin/env python3
import os
import argparse
import multiprocessing
project_name = 'eel'
def print_env(name):
print(f"env[{name}] = {os.environ[name]}")
def set_compiler_build_environs():
os.environ["CC"] = "clang"
os.environ["CXX"] = "clang++"
def get_cmake_dir():
return build_args.out_dir if build_args.out_dir is not None \
else 'cmake-build-release' if build_args.build_release \
else 'cmake-build-debug'
def get_cmake_build_type():
return "Debug" if build_args.build_release is not True else "Release"
def mkdir_if_not_exists(path):
try:
os.mkdir(path)
except FileExistsError:
return
def build_compiler():
build_dir = get_cmake_dir()
build_type = get_cmake_build_type()
set_compiler_build_environs()
print(f"Build mode: {build_type}")
print(f"Build dir: {build_dir}\n")
print_env("CC")
print_env("CXX")
print("Creating `antlr-build`")
mkdir_if_not_exists("antlr-build")
os.system(f"cmake -S . -B {get_cmake_dir()} -G \"Unix Makefiles\" -DCMAKE_BUILD_TYPE={build_type} -Wno-deprecated")
print(f"Entering `{build_dir}`")
os.chdir(build_dir)
print("Building project")
os.system(f"cmake --build . -j {build_args.threads}")
global_parser = argparse.ArgumentParser(description=f'Build tool for {project_name}.')
subcommand_parsers = global_parser.add_subparsers(dest='subcommand')
build_parser = subcommand_parsers.add_parser('build', description=f'Build the project')
build_parser.add_argument('--release', '-R', action='store_true', dest='build_release')
build_parser.add_argument('--out', '-o', action='store', dest='out_dir')
build_parser.add_argument('--skip-cmake', action='store_true', dest='skip_cmake')
build_parser.add_argument('-j', action='store', dest='threads', default=multiprocessing.cpu_count())
build_args = build_parser.parse_args()
run_parser = subcommand_parsers.add_parsers('run', description=f'Run the project')
run_parser.add_argument('--release', '-R', action='store_true', dest='build_release')
run_parser.add_argument('--dir', '-D', action='store', dest='build_dir')
subcommand = global_parser.subcommand
if subcommand == "build":
build_compiler()
elif subcommand == "run":
print("run command is not currently implemented") # TODO