forked from duckdb/duckdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_compile.py
86 lines (69 loc) · 2.22 KB
/
test_compile.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
import os
import sys
import amalgamation
import pickle
import subprocess
# where to cache which files have already been compiled
cache_file = 'amalgamation.cache'
ignored_files = ['utf8proc_data.cpp']
RESUME_AUTO = 0
RESUME_ALWAYS = 1
RESUME_NEVER = 2
# resume behavior
# by default, we resume if the previous test_compile was run on the same commit hash as this one
resume = RESUME_AUTO
for arg in sys.argv:
if arg == '--resume':
resume = RESUME_ALWAYS
elif arg == '--restart':
cache = RESUME_NEVER
if resume == RESUME_NEVER:
try:
os.remove(cache_file)
except:
pass
def get_git_hash():
proc = subprocess.Popen(['git', 'rev-parse', 'HEAD'], stdout=subprocess.PIPE)
return proc.stdout.read().strip()
current_hash = get_git_hash()
# load the cache, and check the commit hash
try:
with open(cache_file, 'rb') as cf:
cache = pickle.load(cf)
if resume == RESUME_AUTO:
# auto resume, check
if cache['commit_hash'] != current_hash:
cache = {}
except:
cache = {}
cache['commit_hash'] = current_hash
def try_compilation(fpath, cache):
if fpath in cache:
return
print(fpath)
cmd = (
'clang++ -std=c++11 -Wno-deprecated -Wno-writable-strings -S -MMD -MF dependencies.d -o deps.s '
+ fpath
+ ' '
+ ' '.join(["-I" + x for x in amalgamation.include_paths])
)
ret = os.system(cmd)
if ret != 0:
raise Exception('Failed compilation of file "' + fpath + '"!\n Command: ' + cmd)
cache[fpath] = True
with open(cache_file, 'wb') as cf:
pickle.dump(cache, cf)
def compile_dir(dir, cache):
files = os.listdir(dir)
files.sort()
for fname in files:
if fname in amalgamation.excluded_compilation_files or fname in ignored_files:
continue
fpath = os.path.join(dir, fname)
if os.path.isdir(fpath):
compile_dir(fpath, cache)
elif fname.endswith('.cpp') or fname.endswith('.hpp') or fname.endswith('.c') or fname.endswith('.cc'):
try_compilation(fpath, cache)
# compile all files in the src directory (including headers!) individually
for cdir in amalgamation.compile_directories:
compile_dir(cdir, cache)