-
Notifications
You must be signed in to change notification settings - Fork 22
/
lakeconfig.lua
252 lines (217 loc) · 5.28 KB
/
lakeconfig.lua
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
local io = require "io"
io.stdout:setvbuf"no"
io.stderr:setvbuf"no"
function vc_version()
local VER = lake.compiler_version()
MSVC_VER = ({
[15] = '9';
[16] = '10';
})[VER.MAJOR] or ''
return MSVC_VER
end
if not L then
local function arkey(t)
assert(type(t) == 'table')
local keys = {}
for k in pairs(t) do
assert(type(k) == 'number')
table.insert(keys, k)
end
table.sort(keys)
return keys
end
local function ikeys(t)
local keys = arkey(t)
local i = 0
return function()
i = i + 1
local k = keys[i]
if k == nil then return end
return k, t[k]
end
end
local function expand(arr, t)
if t == nil then return arr end
if type(t) ~= 'table' then
table.insert(arr, t)
return arr
end
for _, v in ikeys(t) do
expand(arr, v)
end
return arr
end
function L(...)
return expand({}, {...})
end
end
J = J or path.join
IF = IF or lake.choose or choose
DIR_SEP = package.config:sub(1,1)
function prequire(...)
local ok, mod = pcall(require, ...)
if ok then return mod end
end
function clone(t, o)
o = o or {}
for k, v in pairs(t) do
if o[k] == nil then o[k] = v end
end
return o
end
function each_join(dir, list)
for i, v in ipairs(list) do
list[i] = path.join(dir, v)
end
return list
end
function run(file, cwd)
print()
print("run " .. file)
if not TESTING then
if cwd then lake.chdir(cwd) end
local status, code = utils.execute( LUA_RUNNER .. ' ' .. file )
if cwd then lake.chdir("<") end
print()
return status, code
end
return true, 0
end
function exec(file, cwd)
print()
print("exec " .. file)
if not TESTING then
if cwd then lake.chdir(cwd) end
local status, code = utils.execute( file )
if cwd then lake.chdir("<") end
print()
return status, code
end
return true, 0
end
local TESTS = {}
function run_test(name, params)
local test_dir = TESTDIR or J(ROOT, 'test')
local cmd = J(test_dir, name)
if params then cmd = cmd .. ' ' .. params end
local ok = run(cmd, test_dir)
table.insert(TESTS, {cmd = cmd, result = ok})
print("TEST " .. name .. (ok and ' - pass!' or ' - fail!'))
end
function exec_test(name, params)
local test_dir = TESTDIR or J(ROOT, 'test')
local cmd = J(test_dir, name)
if params then cmd = cmd .. ' ' .. params end
local ok = exec(cmd, test_dir)
table.insert(TESTS, {cmd = cmd, result = ok})
print("TEST " .. name .. (ok and ' - pass!' or ' - fail!'))
end
function test_summary()
local ok = true
print("")
print("------------------------------------")
print("Number of tests:", #TESTS)
for _, t in ipairs(TESTS) do
ok = ok and t.result
print((t.result and ' Pass' or ' Fail') .. " - TEST " .. t.cmd)
end
print("------------------------------------")
print("")
return ok
end
--[[spawn]] if WINDOWS then
function spawn(file, cwd)
local winapi = prequire "winapi"
if not winapi then
quit('needs winapi for spawn!')
return false
end
print("spawn " .. file)
if not TESTING then
if cwd then lake.chdir(cwd) end
assert(winapi.shell_exec(nil, LUA_RUNNER, file, cwd))
if cwd then lake.chdir("<") end
print()
end
return true
end
else
function spawn(file, cwd)
print("spawn " .. file)
if not TESTING then
assert(run(file .. ' &', cwd))
end
return true
end
end
function as_bool(v,d)
if v == nil then return not not d end
local n = tonumber(v)
if n == 0 then return false end
if n then return true end
return false
end
--- set global variables
-- LUA_NEED
-- LUA_DIR
-- LUA_RUNNER
-- ROOT
-- LUADIR
-- LIBDIR
-- TESTDIR
-- DOCDIR
-- DYNAMIC
function INITLAKEFILE()
if LUA_VER == '5.3' then
LUA_NEED = 'lua53'
LUA_DIR = ENV.LUA_DIR_5_3 or ENV.LUA_DIR
LUA_RUNNER = LUA_RUNNER or 'lua53'
elseif LUA_VER == '5.2' then
LUA_NEED = 'lua52'
LUA_DIR = ENV.LUA_DIR_5_2 or ENV.LUA_DIR
LUA_RUNNER = LUA_RUNNER or 'lua52'
elseif LUA_VER == '5.1' then
LUA_NEED = 'lua51'
LUA_DIR = ENV.LUA_DIR
LUA_RUNNER = LUA_RUNNER or 'lua'
else
LUA_NEED = 'lua'
LUA_DIR = ENV.LUA_DIR
LUA_RUNNER = LUA_RUNNER or 'lua'
end
ROOT = ROOT or J( LUA_DIR, 'libs', PROJECT )
LUADIR = LUADIR or J( ROOT, 'share' )
LIBDIR = LIBDIR or J( ROOT, 'share' )
TESTDIR = TESTDIR or J( ROOT, 'test' )
DOCDIR = DOCDIR or J( ROOT, 'doc' )
DYNAMIC = as_bool(DYNAMIC, false)
end
-----------------------
-- needs --
-----------------------
lake.define_need('lua53', function()
return {
incdir = J(ENV.LUA_DIR_5_3, 'include');
libdir = J(ENV.LUA_DIR_5_3, 'lib');
libs = {'lua53'};
}
end)
lake.define_need('lua52', function()
return {
incdir = J(ENV.LUA_DIR_5_2, 'include');
libdir = J(ENV.LUA_DIR_5_2, 'lib');
libs = {'lua52'};
}
end)
lake.define_need('lua51', function()
return {
incdir = J(ENV.LUA_DIR, 'include');
libdir = J(ENV.LUA_DIR, 'lib');
libs = {'lua5.1'};
}
end)
lake.define_need('pthread', function()
return {
libs = 'pthread';
}
end)