diff options
-rw-r--r-- | lakeconfig.lua | 252 | ||||
-rw-r--r-- | lakefile | 43 |
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 @@ | |||
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) | ||
247 | |||
248 | lake.define_need('pthread', function() | ||
249 | return { | ||
250 | libs = 'pthread'; | ||
251 | } | ||
252 | end) \ 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 @@ | |||
1 | PROJECT = 'llthreads' | ||
2 | |||
3 | INITLAKEFILE() | ||
4 | |||
5 | DEFINES = L{DEFINES, | ||
6 | IF(WINDOWS, 'DLL_EXPORT', ''); | ||
7 | IF(not MSVC, 'USE_PTHREAD', ''); | ||
8 | } | ||
9 | |||
10 | core = 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 | |||
20 | target('build', core) | ||
21 | |||
22 | install = target('install', { | ||
23 | file.group{odir=LIBDIR; src = core }; | ||
24 | file.group{odir=TESTDIR; src = J('test', '*'); recurse = true }; | ||
25 | }) | ||
26 | |||
27 | target('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 | ||
42 | end) | ||
43 | |||