aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lakeconfig.lua252
-rw-r--r--lakefile43
2 files changed, 295 insertions, 0 deletions
diff --git a/lakeconfig.lua b/lakeconfig.lua
new file mode 100644
index 0000000..ffe5ad7
--- /dev/null
+++ b/lakeconfig.lua
@@ -0,0 +1,252 @@
1local io = require "io"
2io.stdout:setvbuf"no"
3io.stderr:setvbuf"no"
4
5function 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
12end
13
14if not L then
15
16local 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
25end
26
27local 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
36end
37
38local 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
51end
52
53function L(...)
54 return expand({}, {...})
55end
56
57end
58
59J = J or path.join
60
61IF = IF or lake.choose or choose
62
63DIR_SEP = package.config:sub(1,1)
64
65function prequire(...)
66 local ok, mod = pcall(require, ...)
67 if ok then return mod end
68end
69
70function 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
76end
77
78function each_join(dir, list)
79 for i, v in ipairs(list) do
80 list[i] = path.join(dir, v)
81 end
82 return list
83end
84
85function 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
96end
97
98function 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
109end
110
111local TESTS = {}
112
113function 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!'))
122end
123
124function 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!'))
133end
134
135function 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
147end
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
166else
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
174end
175
176function 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
182end
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
194function 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)
218end
219
220-----------------------
221-- needs --
222-----------------------
223
224lake.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 }
230end)
231
232lake.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 }
238end)
239
240lake.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 }
246end)
247
248lake.define_need('pthread', function()
249 return {
250 libs = 'pthread';
251 }
252end) \ No newline at end of file
diff --git a/lakefile b/lakefile
new file mode 100644
index 0000000..95e5d8e
--- /dev/null
+++ b/lakefile
@@ -0,0 +1,43 @@
1PROJECT = 'llthreads'
2
3INITLAKEFILE()
4
5DEFINES = L{DEFINES,
6 IF(WINDOWS, 'DLL_EXPORT', '');
7 IF(not MSVC, 'USE_PTHREAD', '');
8}
9
10core = c.shared{PROJECT,
11 base = 'src',
12 src = '*.c',
13 needs = LUA_NEED,
14 defines = DEFINES,
15 dynamic = DYNAMIC,
16 strip = true,
17 libs = IF(not MSVC, 'pthread');
18}
19
20target('build', core)
21
22install = target('install', {
23 file.group{odir=LIBDIR; src = core };
24 file.group{odir=TESTDIR; src = J('test', '*'); recurse = true };
25})
26
27target('test', install, function()
28 run_test('test_register_llthreads.lua')
29 run_test('test_join_timeout.lua')
30 run_test('test_llthreads.lua')
31 run_test('test_table_copy.lua')
32 run_test('test_threads.lua')
33 run_test('test_join_timeout.lua')
34 run_test('test_join_detach.lua')
35 run_test('test_register_ffi.lua')
36 run_test('test_logger.lua')
37 run_test('test_pass_cfunction.lua')
38
39 if not test_summary() then
40 quit("test fail")
41 end
42end)
43