Skip to content

Commit 9b8d567

Browse files
committed
Update lakefile
1 parent b6fa8cd commit 9b8d567

File tree

3 files changed

+262
-13
lines changed

3 files changed

+262
-13
lines changed

.travis.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ branches:
1515

1616
before_install:
1717
- bash .travis/setup_lua.sh
18-
- bash .travis/setup_zmq.sh
18+
- sudo apt-get install libzmq3 libzmq3-dev
19+
# - bash .travis/setup_zmq.sh
1920

2021
install:
2122
- sudo luarocks install lunitx

lakeconfig.lua

+246
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,246 @@
1+
local io = require "io"
2+
io.stdout:setvbuf"no"
3+
io.stderr:setvbuf"no"
4+
5+
function vc_version()
6+
local VER = lake.compiler_version()
7+
MSVC_VER = ({
8+
[15] = '9';
9+
[16] = '10';
10+
})[VER.MAJOR] or ''
11+
return MSVC_VER
12+
end
13+
14+
if not L then
15+
16+
local function arkey(t)
17+
assert(type(t) == 'table')
18+
local keys = {}
19+
for k in pairs(t) do
20+
assert(type(k) == 'number')
21+
table.insert(keys, k)
22+
end
23+
table.sort(keys)
24+
return keys
25+
end
26+
27+
local function ikeys(t)
28+
local keys = arkey(t)
29+
local i = 0
30+
return function()
31+
i = i + 1
32+
local k = keys[i]
33+
if k == nil then return end
34+
return k, t[k]
35+
end
36+
end
37+
38+
local function expand(arr, t)
39+
if t == nil then return arr end
40+
41+
if type(t) ~= 'table' then
42+
table.insert(arr, t)
43+
return arr
44+
end
45+
46+
for _, v in ikeys(t) do
47+
expand(arr, v)
48+
end
49+
50+
return arr
51+
end
52+
53+
function L(...)
54+
return expand({}, {...})
55+
end
56+
57+
end
58+
59+
J = J or path.join
60+
61+
IF = IF or lake.choose or choose
62+
63+
DIR_SEP = package.config:sub(1,1)
64+
65+
function prequire(...)
66+
local ok, mod = pcall(require, ...)
67+
if ok then return mod end
68+
end
69+
70+
function clone(t, o)
71+
o = o or {}
72+
for k, v in pairs(t) do
73+
if o[k] == nil then o[k] = v end
74+
end
75+
return o
76+
end
77+
78+
function each_join(dir, list)
79+
for i, v in ipairs(list) do
80+
list[i] = path.join(dir, v)
81+
end
82+
return list
83+
end
84+
85+
function run(file, cwd)
86+
print()
87+
print("run " .. file)
88+
if not TESTING then
89+
if cwd then lake.chdir(cwd) end
90+
local status, code = utils.execute( LUA_RUNNER .. ' ' .. file )
91+
if cwd then lake.chdir("<") end
92+
print()
93+
return status, code
94+
end
95+
return true, 0
96+
end
97+
98+
function exec(file, cwd)
99+
print()
100+
print("exec " .. file)
101+
if not TESTING then
102+
if cwd then lake.chdir(cwd) end
103+
local status, code = utils.execute( file )
104+
if cwd then lake.chdir("<") end
105+
print()
106+
return status, code
107+
end
108+
return true, 0
109+
end
110+
111+
local TESTS = {}
112+
113+
function run_test(name, params)
114+
local test_dir = TESTDIR or J(ROOT, 'test')
115+
local cmd = J(test_dir, name)
116+
if params then cmd = cmd .. ' ' .. params end
117+
local ok = run(cmd, test_dir)
118+
119+
table.insert(TESTS, {cmd = cmd, result = ok})
120+
121+
print("TEST " .. name .. (ok and ' - pass!' or ' - fail!'))
122+
end
123+
124+
function exec_test(name, params)
125+
local test_dir = TESTDIR or J(ROOT, 'test')
126+
local cmd = J(test_dir, name)
127+
if params then cmd = cmd .. ' ' .. params end
128+
local ok = exec(cmd, test_dir)
129+
130+
table.insert(TESTS, {cmd = cmd, result = ok})
131+
132+
print("TEST " .. name .. (ok and ' - pass!' or ' - fail!'))
133+
end
134+
135+
function test_summary()
136+
local ok = true
137+
print("")
138+
print("------------------------------------")
139+
print("Number of tests:", #TESTS)
140+
for _, t in ipairs(TESTS) do
141+
ok = ok and t.result
142+
print((t.result and ' Pass' or ' Fail') .. " - TEST " .. t.cmd)
143+
end
144+
print("------------------------------------")
145+
print("")
146+
return ok
147+
end
148+
149+
--[[spawn]] if WINDOWS then
150+
function spawn(file, cwd)
151+
local winapi = prequire "winapi"
152+
if not winapi then
153+
quit('needs winapi for spawn!')
154+
return false
155+
end
156+
157+
print("spawn " .. file)
158+
if not TESTING then
159+
if cwd then lake.chdir(cwd) end
160+
assert(winapi.shell_exec(nil, LUA_RUNNER, file, cwd))
161+
if cwd then lake.chdir("<") end
162+
print()
163+
end
164+
return true
165+
end
166+
else
167+
function spawn(file, cwd)
168+
print("spawn " .. file)
169+
if not TESTING then
170+
assert(run(file .. ' &', cwd))
171+
end
172+
return true
173+
end
174+
end
175+
176+
function as_bool(v,d)
177+
if v == nil then return not not d end
178+
local n = tonumber(v)
179+
if n == 0 then return false end
180+
if n then return true end
181+
return false
182+
end
183+
184+
--- set global variables
185+
-- LUA_NEED
186+
-- LUA_DIR
187+
-- LUA_RUNNER
188+
-- ROOT
189+
-- LUADIR
190+
-- LIBDIR
191+
-- TESTDIR
192+
-- DOCDIR
193+
-- DYNAMIC
194+
function INITLAKEFILE()
195+
if LUA_VER == '5.3' then
196+
LUA_NEED = 'lua53'
197+
LUA_DIR = ENV.LUA_DIR_5_3 or ENV.LUA_DIR
198+
LUA_RUNNER = LUA_RUNNER or 'lua53'
199+
elseif LUA_VER == '5.2' then
200+
LUA_NEED = 'lua52'
201+
LUA_DIR = ENV.LUA_DIR_5_2 or ENV.LUA_DIR
202+
LUA_RUNNER = LUA_RUNNER or 'lua52'
203+
elseif LUA_VER == '5.1' then
204+
LUA_NEED = 'lua51'
205+
LUA_DIR = ENV.LUA_DIR
206+
LUA_RUNNER = LUA_RUNNER or 'lua'
207+
else
208+
LUA_NEED = 'lua'
209+
LUA_DIR = ENV.LUA_DIR
210+
LUA_RUNNER = LUA_RUNNER or 'lua'
211+
end
212+
ROOT = ROOT or J( LUA_DIR, 'libs', PROJECT )
213+
LUADIR = LUADIR or J( ROOT, 'share' )
214+
LIBDIR = LIBDIR or J( ROOT, 'share' )
215+
TESTDIR = TESTDIR or J( ROOT, 'test' )
216+
DOCDIR = DOCDIR or J( ROOT, 'doc' )
217+
DYNAMIC = as_bool(DYNAMIC, false)
218+
end
219+
220+
-----------------------
221+
-- needs --
222+
-----------------------
223+
224+
lake.define_need('lua53', function()
225+
return {
226+
incdir = J(ENV.LUA_DIR_5_3, 'include');
227+
libdir = J(ENV.LUA_DIR_5_3, 'lib');
228+
libs = {'lua53'};
229+
}
230+
end)
231+
232+
lake.define_need('lua52', function()
233+
return {
234+
incdir = J(ENV.LUA_DIR_5_2, 'include');
235+
libdir = J(ENV.LUA_DIR_5_2, 'lib');
236+
libs = {'lua52'};
237+
}
238+
end)
239+
240+
lake.define_need('lua51', function()
241+
return {
242+
incdir = J(ENV.LUA_DIR, 'include');
243+
libdir = J(ENV.LUA_DIR, 'lib');
244+
libs = {'lua5.1'};
245+
}
246+
end)

lakefile

+14-12
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
PROJECT = 'log'
22

3-
J = path.join
4-
5-
if LUA_VER == '5.2' then
6-
LUA_DIR = ENV.LUA_DIR_5_2 or ENV.LUA_DIR
7-
else
8-
LUA_DIR = ENV.LUA_DIR
9-
end
10-
11-
INSTALL_DIR = INSTALL_DIR or J(LUA_DIR,'libs',PROJECT)
3+
INITLAKEFILE()
124

135
install = target('install', {
14-
file.group{odir=J(INSTALL_DIR, 'examples');recurse = true; src = J('examples', '*.*')};
15-
file.group{odir=J(INSTALL_DIR, 'lua' );recurse = true; src = J('lua', '*.*' )};
16-
file.group{odir=J(INSTALL_DIR, 'utils' );recurse = true; src = J('utils', '*.*' )};
6+
file.group{odir = LUA_DIR; recurse = true; src = J('lua', '*.*' )};
7+
file.group{odir = TESTDIR; recurse = true; src = J('test', '*.*' )};
8+
9+
file.group{odir = J(ROOT, 'examples');recurse = true; src = J('examples', '*.*')};
10+
file.group{odir = J(ROOT, 'utils' );recurse = true; src = J('utils', '*.*' )};
1711
})
12+
13+
target('test', install, function()
14+
run_test('test_basic.lua')
15+
run_test('test_file_writer.lua')
16+
if not test_summary() then
17+
quit("test fail")
18+
end
19+
end)

0 commit comments

Comments
 (0)