-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwscript
More file actions
229 lines (176 loc) · 6.72 KB
/
wscript
File metadata and controls
229 lines (176 loc) · 6.72 KB
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
# -*- coding: utf-8 -*-
import sys
import ws.test
import ws.snapshot
import waflib.Scripting
import os
from os import path
import shutil
from subprocess import Popen, PIPE, check_output
from glob import glob
top = '.'
out = 'build'
SNAPSHOT_VERSION = "0.1.2"
def distclean(ctx):
try:
# Wipe the `.cache` dir.
shutil.rmtree(path.join(top, ".cache"))
except:
# I think this is the point.
pass
# Clean the rest of the files.
waflib.Scripting.distclean(ctx)
def options(ctx):
# Add an option to specify an existing arrow compiler for the boostrap
# process.
ctx.add_option("--with-arrow", action='store', dest='arrow')
# Add a --with-llvm-config option to specify what binary to use here
# instead of the standard `llvm-config`.
ctx.add_option(
'--with-llvm-config', action='store', default='llvm-config',
dest='llvm_config')
# Add a --quick / -q option (for quick building)
ctx.add_option("-q", action="store_true", default=False,
dest="quick_build")
def llvm_config(ctx, *args):
command = [ctx.env.LLVM_CONFIG]
command.extend(args)
return check_output(command).decode("utf-8").strip()
def configure(ctx):
# Load preconfigured tools.
ctx.load('c_config')
# Ensure that we receive a path to an existing arrow compiler.
if not ctx.options.arrow:
# Attempt to get a snapshot for this platform.
try:
ctx.env.ARROW_SNAPSHOT = ws.snapshot.get_snapshot(SNAPSHOT_VERSION)
except ws.snapshot.SnapshotNotFound:
ctx.fatal("An existing arrow compiler is needed for the "
"boostrap process; specify one with \"--with-arrow\"")
else:
ctx.env.ARROW_SNAPSHOT = ctx.options.arrow
# Report the compiler to be used.
ctx.msg("Checking for 'arrow' (Arrow compiler)", ctx.env.ARROW_SNAPSHOT)
# Check for the llvm compiler.
ctx.find_program('llc', var='LLC')
ctx.find_program('lli', var='LLI')
ctx.find_program('opt', var='OPT')
# Check for gcc.
# NOTE: We only depend on this for the linking phase.
ctx.find_program('gcc', var='GCC')
ctx.find_program('g++', var='GXX')
# Check for the `llvm-config`.
ctx.find_program('llvm-config', var="LLVM_CONFIG")
# Use `llvm-config` to discover configuration
ctx.env.LLVM_LDFLAGS = llvm_config(ctx, "--ldflags")
ctx.env.LLVM_LIBS = llvm_config(ctx, "--libs", "all")
# Store addl. options
ctx.env.QUICK_BUILD = ctx.options.quick_build
# Get the version of the current package.
ver = check_output(
["git", "describe", "--always", "--tag"]).strip().decode()
ver_parts = ver.split("-")
if len(ver_parts) == 1:
ctx.env.VERSION = ver
else:
ctx.env.VERSION = '+'.join([ver_parts[0],
ver_parts[1] + "." + ver_parts[2]])
def _link(ctx, source, target, name):
libs = ctx.env.LLVM_LIBS
ldflags = ctx.env.LLVM_LDFLAGS
rule = "${GXX} -o${TGT} ${SRC} %s %s" % (libs, ldflags)
if sys.version_info[0] == 2:
rule = rule.encode()
ctx(rule=rule,
source=source,
target=target,
name=name)
def build(ctx):
# Write a configuration file that contains the version.
cfg = path.join(ctx.bldnode.abspath(), "cfg/_version.as")
try:
os.makedirs(path.dirname(cfg))
except:
pass
with open(cfg, "w") as stream:
stream.write("let VERSION = '%s';\n" % ctx.env.VERSION)
# Build the stage-0 compiler from the fetched snapshot
# Compile the compiler from llvm IL into native object code.
ctx(rule="${LLC} -filetype=obj -o=${TGT} ${ARROW_SNAPSHOT}",
target="stage0/arrow.o")
# Link the compiler into a final executable.
_link(ctx, "stage0/arrow.o", "stage0/arrow", "stage0")
# Take the stage-1 compiler (the one that we have through
# reasons unknown to us). Use this to compile the stage-2 compiler.
# Compile the compiler to the llvm IL.
ctx(rule="./stage0/arrow -L ../src -L ./cfg ${SRC} | ${OPT} -O3 -o=${TGT}",
source="src/compiler.as",
target="stage1/arrow.ll",
after="stage0")
# Compile the compiler from llvm IL into native object code.
ctx(rule="${LLC} -filetype=obj -o=${TGT} ${SRC}",
source="stage1/arrow.ll",
target="stage1/arrow.o")
# Link the compiler into a final executable.
_link(ctx, "stage1/arrow.o", "stage1/arrow", "stage1")
if ctx.env.QUICK_BUILD:
# Copy the stage1 compiler to "build/arrow"
ctx(rule="cp ${SRC} ${TGT}",
source="stage1/arrow",
target="arrow")
return
# Use the newly compiled stage-1 to compile the stage-2 compiler
# Compile the compiler to the llvm IL.
ctx(rule="./stage1/arrow -L ../src -L ./cfg ${SRC} | ${OPT} -O3 -o=${TGT}",
source="src/compiler.as",
target="stage2/arrow.ll",
after="stage1")
# Compile the compiler from llvm IL into native object code.
ctx(rule="${LLC} -filetype=obj -o=${TGT} ${SRC}",
source="stage2/arrow.ll",
target="stage2/arrow.o")
# Link the compiler into a final executable.
_link(ctx, "stage2/arrow.o", "stage2/arrow", "stage2")
# TODO: Run the test suite on the stage-3 compiler
# TODO: Do a bit-by-bit equality check on both compilers
# Copy the stage2 compiler to "build/arrow"
ctx(rule="cp ${SRC} ${TGT}",
source="stage2/arrow",
target="arrow")
def test(ctx):
print(ws.test._sep("test session starts", "="))
print(ws.test._sep("tokenize", "-"))
ws.test._test_tokenizer(ctx)
print(ws.test._sep("parse", "-"))
ws.test._test_parser(ctx)
print(ws.test._sep("parse-fail", "-"))
ws.test._test_parser_fail(ctx)
print(ws.test._sep("run", "-"))
ws.test._test_run(ctx)
print(ws.test._sep("run-fail", "-"))
ws.test._test_run_fail(ctx)
ws.test._print_report()
def _test_tokenize(ctx):
print(ws.test._sep("test session starts", "="))
print(ws.test._sep("tokenize", "-"))
ws.test._test_tokenizer(ctx)
print(ws.test._sep("tokenize-fail", "-"))
ws.test._test_tokenizer_fail(ctx)
ws.test._print_report()
globals()["test:tokenize"] = _test_tokenize
def _test_parse(ctx):
print(ws.test._sep("test session starts", "="))
print(ws.test._sep("parse", "-"))
ws.test._test_parser(ctx)
print(ws.test._sep("parse-fail", "-"))
ws.test._test_parser_fail(ctx)
ws.test._print_report()
globals()["test:parse"] = _test_parse
def _test_run(ctx):
print(ws.test._sep("test session starts", "="))
print(ws.test._sep("run", "-"))
ws.test._test_run(ctx)
print(ws.test._sep("run-fail", "-"))
ws.test._test_run_fail(ctx)
ws.test._print_report()
globals()["test:run"] = _test_run