-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.py
executable file
·131 lines (107 loc) · 3.63 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import os
import subprocess
import sys
def get_all_in(path, extensions):
out_set = set()
for root, dirs, files in os.walk(path):
for f in files:
for ext in extensions:
if f.endswith(ext):
full_file_path = os.path.join(root, f)
assert(full_file_path not in out_set)
out_set.add(full_file_path)
break
return out_set;
def build_all_except(cc, src_path, exclude, extensions, flags, out):
actual_excludes = set()
for excl in exclude:
actual_excludes.add(os.path.join(src_path, excl))
exclude = actual_excludes
src_files = get_all_in(src_path, extensions)
args = [cc]
args += flags
args.append("-o" + out)
for src_f in src_files:
if src_f not in exclude:
args.append(src_f)
return args;
def print_command(command):
for arg in command:
print(arg, end=" ")
print()
def build_release():
commands = build_all_except(compiler, "src", set(), extensions, ["-DNO_INCLUDE_ASSERTS", "-DNO_TESTS", "-O2"], "out/whippet.out")
#print_command(commands)
subprocess.run(commands)
def build_debug():
commands = build_all_except(compiler, "src", set(), extensions, ["-DDEBUG", "-DVERSION_NAME=\"DEBUG BUILD\"", "-Wall", "-Wpedantic", "-g" ], "out/a.out")
print_command(commands)
subprocess.run(commands)
def y_n_prompt(msg):
inp = "";
while inp.lower() not in ("y", "yes", "n", "no"):
inp = input(msg + " (y/n): ")
if inp.lower() in ("y", "yes"):
return True
elif inp.lower() in ("n", "no"):
return False
assert(False)
def build_custom():
print(
"""1. Rich terminal interface
The interactive prompt can run in either basic or rich mode. The rich mode provides more features (line editing, history, highlighting)
but may potentially be less stable and portable. This setting is simply for what the program should default to, and can be set on startup
manually by using the --terminal-basic or --terminal-rich arguments.
""")
rich_term = y_n_prompt("Use rich terminal by default?")
print(
"""2. Manual approval of commands and file handling
This setting controls whether the interpreter will (by default) ask for permission when attempting to run external programs/commands
or open files for reading or writing. This makes accidental or unwanted execution of programs or editing of files, either due to
user error or bugs in the interpreter, less likely.
This can manually be selected on startup with the --manual-approve and --no-manual-approve arguments.
""")
manual_approve = y_n_prompt("Use manual approval by default?")
print(
"""3. Assertions
Assertions make the code safer and easier to debug, but potentially slower running and more crash-prone (as the program will immedietely close down
on an assertion failure, instead of potentially missbehaving").
""")
keep_asserts = y_n_prompt("Keep asserts?")
flags = ["-DNO_TESTS", "-O2"]
if rich_term:
flags.append("-DSETTING_RICH_TERMINAL=1")
else:
flags.append("-DSETTING_RICH_TERMINAL=0")
if manual_approve:
flags.append("-DSETTING_APPROVE_COMMANDS=1")
else:
flags.append("-DSETTING_APPROVE_COMMANDS=0")
if not keep_asserts:
flags.append("-DNO_INCLUDE_ASSERTS")
commands = build_all_except(compiler, "src", set(), extensions, flags, "out/c_whippet.out")
print_command(commands);
subprocess.run(commands);
compiler = "cc"
extensions = [".c"]
if len(sys.argv) == 2 and sys.argv[1] == "d":
build_debug()
else:
while True:
print("Select build option:")
print("1. Release")
print("2. Debug")
print("3. Custom (recommended)")
print("Q. Quit")
i = input(":")
if i == "1":
build_release()
break
elif i == "2":
build_debug()
break
elif i == "3":
build_custom()
break
elif i.lower() in ("q", "quit"):
break