-
Notifications
You must be signed in to change notification settings - Fork 43
/
make.py
46 lines (39 loc) · 1.32 KB
/
make.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
#!/usr/bin/env python
import glob
import os
from pathlib import Path
FNL_ROOT = 'fnl'
LUA_ROOT = 'lua'
def get_files(root):
return [f for f in glob.iglob(root + '/**', recursive=True)
if os.path.isfile(f)]
fnlfiles = get_files(FNL_ROOT + "/")
luafiles = get_files(LUA_ROOT + "/")
# Compile source files which have been created or modified since the
# last build.
changes = False
for src in fnlfiles:
out = src.replace(FNL_ROOT, LUA_ROOT, 1).replace('.fnl', '.lua')
if (not os.path.exists(out)
or os.path.getmtime(src) > os.path.getmtime(out)):
changes = True
# Create parent directories if they don't exist.
Path(os.path.dirname(out)).mkdir(parents=True, exist_ok=True)
cmd = "fennel --compile " + src + " > " + out
print(cmd)
os.system(cmd)
if not changes:
print("nothing to compile")
# Remove leftover files whose sources have been deleted.
for out in luafiles:
if out not in map(lambda f: f
.replace(FNL_ROOT, LUA_ROOT, 1)
.replace('.fnl', '.lua'),
fnlfiles):
print("removing output file with missing source: " + out)
os.remove(out)
# Remove parent directories if they have become empty.
try:
os.removedirs(os.path.dirname(out))
except OSError:
pass