-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.py
116 lines (88 loc) · 3.25 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
import sys
import os
import subprocess
import shutil
from pynt import task
deps = [
{ "kind":"file",
"id":"json",
"in":"./deps/json/json.lua",
"out":"./build/json"
}
]
def _add_depenency(id):
deps.append(
{
"kind":"folder",
"id":id,
"in":"./deps/"+id+"/src/"+id,
"out":"./src"
})
#_add_depenency("nxgamelib")
#_add_depenency("opticum")
def _compile_fnl(src, dst):
x = subprocess.run(["fennel", "--compile", src], capture_output=True)
print("<-> compiling " + str(src) + " => " + str(dst))
if x.returncode != 0:
print(x.stderr.decode() or x.stdout.decode())
sys.exit()
else:
os.makedirs(os.path.dirname(dst), exist_ok=True)
with open(dst, "wb") as handle:
handle.write(x.stdout)
def _compile_recursive(src_root, dst_root):
for x, subfolder, files in os.walk(src_root):
for item in files:
src_filename = os.path.join(x, item)
dst_filename = src_filename.replace(src_root, dst_root, 1).replace('.fnl', '.lua')
_compile_fnl(src_filename, dst_filename)
def _clean_build():
shutil.rmtree("./build", ignore_errors=True)
def _clean_pycache():
shutil.rmtree("./__pycache__", ignore_errors=True)
def _clean_depcopy():
for d in deps:
shutil.rmtree(os.path.join("./src", d["id"]), ignore_errors=True)
@task()
def clean():
'''clean build folder and __pycache__'''
_clean_build()
_clean_pycache()
_clean_depcopy()
@task()
def dupdate():
'''update dependencies'''
#_clean_depcopy()
#os.makedirs(os.path.dirname("./deps"), exist_ok=True)
for d in deps:
if d["kind"] == "folder":
x = subprocess.run(["mkdir", "-p", os.path.join(d["out"])], capture_output=True)
y = subprocess.run(["cp", "-r", os.path.join(d["in"]), os.path.join(d["out"])], capture_output=True)
elif d["kind"] == "file":
x = subprocess.run(["mkdir", "-p", os.path.join(d["out"])], capture_output=True)
y = subprocess.run(["cp", os.path.join(d["in"]), os.path.join(d["out"])], capture_output=True)
#elif d["kind"] == "git":
# print("<-> cloning " + d["location"] + " into " + os.path.join("./deps", d["name"]))
# x = subprocess.run(["git", "clone", d["location"], os.path.join("./deps", d["name"])], capture_output=True)
# print("<-> moving " + os.path.join("./deps", d["name"], "src") + " to " + os.path.join("./src", d["name"]))
# #HACK
# y = subprocess.run(["cp", "-r", os.path.join("./deps", d["name"], "src"), os.path.join("./src", d["name"])], capture_output=True)
@task()
def assets():
'''copy asset folder'''
x = subprocess.run(["mkdir", "-p", os.path.join("./build", "assets")], capture_output=True)
y = subprocess.run(["cp", "-r", os.path.join("./assets"), os.path.join("./build")], capture_output=True)
@task(clean, dupdate, assets)
def build():
'''build entire project'''
_compile_recursive("./src", "./build")
@task()
def wipe():
'''wipe downloaded dependencies'''
shutil.rmtree(os.path.join("./deps"), ignore_errors=True)
@task(build)
def debug():
os.chdir("./build/")
p = subprocess.Popen(["love", "."])
p.wait()
__DEFAULT__=build