-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathbuild.py
56 lines (47 loc) · 1.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
# encoding=utf-8
import sys
import os
sys.path.append("src/python")
import mp_encode
def compile_and_save(fpath, target):
print("compile %s to %s" % (fpath, target))
c = mp_encode.Compiler()
code = c.compile_to_c_code(fpath)
fp = open(target, "w+")
fp.write(code)
fp.close()
def do_build_core():
names = ["mp_init", "mp_tokenize", "mp_parse", "mp_encode", "mp_opcode", "pyeval", "repl"]
for name in names:
source = "./src/python/%s.py" % name
target = "./src/gen/%s.gen.c" % name
compile_and_save(source, target)
def do_build():
print("current path: %s" % os.getcwd())
print("python interpreter: %s" % sys.executable)
do_build_core()
print("compile python files done!")
os.system("make clean && make")
def do_build_user():
names = ["main"]
for name in names:
source = "./pack/%s.py" % name
target = "./pack/%s.gen.c" % name
compile_and_save(source, target)
def build_pack():
print("current path: %s" % os.getcwd())
print("python interpreter: %s" % sys.executable)
do_build_core()
do_build_user()
print("compile python files done!")
os.system("make pack")
def main():
arg1 = ""
if len(sys.argv) >= 2:
arg1 = sys.argv[1]
if arg1 == "pack":
build_pack()
return
do_build()
if __name__ == "__main__":
main()