-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathbam.lua
executable file
·321 lines (258 loc) · 10.9 KB
/
bam.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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
BUILD_PATH = "local"
EXTERNALS_PATH = 'external'
GTEST_PATH = PathJoin( EXTERNALS_PATH, 'gtest' )
function dl_type_lib( tlc_file, dltlc, dl_tests )
local output_path = PathJoin( BUILD_PATH, 'generated' )
local out_file = PathJoin( output_path, PathFilename( PathBase( tlc_file ) ) )
local out_header = out_file .. ".h"
local out_lib = out_file .. ".bin"
local out_lib_h = out_file .. ".bin.h"
local out_lib_txt_h = out_file .. ".txt.h"
local BIN2HEX = _bam_exe .. " -e tool/bin2hex.lua"
if family == "windows" then
dltlc = string.gsub( dltlc, "/", "\\" )
end
AddJob( out_lib, "tlc " .. out_lib, dltlc .. " -o " .. out_lib .. " " .. tlc_file, tlc_file )
AddJob( out_lib_h, "tlc " .. out_lib_h, BIN2HEX .. " dst=" .. out_lib_h .. " src=" .. out_lib, out_lib )
AddJob( out_lib_txt_h, "tlc " .. out_lib_h, BIN2HEX .. " dst=" .. out_lib_txt_h .. " src=" .. tlc_file, tlc_file )
AddJob( out_header, "tlc " .. out_header, dltlc .. " -c -o " .. out_header .. " " .. tlc_file, tlc_file )
AddDependency( tlc_file, dltlc )
AddDependency( dl_tests, out_lib_h )
end
function DefaultSettings( platform, config, compiler )
local settings = {}
settings.debug = 0
settings.optimize = 0
settings._is_settingsobject = true
settings.invoke_count = 0
settings.config = config
settings.platform = platform
-- SetCommonSettings(settings)
settings.config_name = ""
settings.config_ext = ""
settings.labelprefix = ""
-- add all tools
for _, tool in pairs(_bam_tools) do
tool(settings)
end
-- lock the table and return
TableLock(settings)
settings.cc.includes:Add("include")
settings.cc.includes:Add("local")
local output_path = PathJoin( BUILD_PATH, PathJoin( PathJoin( platform, compiler ), config ) )
local output_func = function(settings, path) return PathJoin(output_path, PathFilename(PathBase(path)) .. settings.config_ext) end
settings.cc.Output = output_func
settings.lib.Output = output_func
settings.dll.Output = output_func
settings.link.Output = output_func
return settings
end
function get_compiler()
compiler = ScriptArgs["compiler"]
if family == "windows" then
local has_msvs = {}
for i=8,30 do
has_msvs[i] = os.getenv('VS' .. i .. '0COMNTOOLS') ~= nil
end
if compiler == nil then
for i=30,8,-1 do
if has_msvs[i] then
compiler = 'msvs' .. i
break
end
end
else
for i=8,30 do
if compiler == ('msvs' .. i) then
if not has_msvs[i] then
print( compiler .. ' is not installed on this machine' )
os.exit(1)
end
break
end
end
end
if compiler == nil then
compiler = 'gcc'
end
end
return compiler
end
function DefaultGCCLike( platform, config, compiler )
local settings = DefaultSettings( platform, config, compiler )
if compiler == 'gcc' then
SetDriversGCC(settings)
elseif compiler == 'clang' then
SetDriversClang(settings)
else
return
end
if config == "debug" then
settings.cc.flags:Add("-O0", "-g")
elseif config == "coverage" then
settings.cc.flags:Add("-O0", "-g", "--coverage")
settings.link.flags:Add("--coverage")
elseif config == "release" then
settings.cc.flags:Add("-O2")
elseif config == "sanitizer" then
settings.cc.flags:Add("-O0", "-g", "-fno-omit-frame-pointer", "-fsanitize=undefined", "-fno-sanitize-recover=all")
settings.link.flags:Add("-fsanitize=undefined", "-fno-sanitize-recover=all")
else
print( config .. ' is not a valid configuration' )
os.exit(1)
end
local arch = platform == 'linux_x86' and '-m32' or '-m64'
settings.cc.flags:Add( arch )
settings.dll.flags:Add( arch )
settings.link.flags:Add( arch )
settings.link.libs:Add( 'rt' )
return settings
end
function DefaultMSVC( build_platform, config, compiler )
local settings = DefaultSettings( build_platform, config, compiler )
SetDriversCL(settings)
if config == "debug" then
settings.cc.flags:Add("/Od", "/MDd", "/Z7", "/D \"_DEBUG\"", "/EHsc", "/GS-")
settings.dll.flags:Add("/DEBUG")
settings.link.flags:Add("/DEBUG")
elseif config == "release" then
settings.cc.flags:Add("/Ox", "/Ot", "/MD", "/D \"NDEBUG\"", "/EHsc")
else
print( config .. ' is not a valid configuration' )
os.exit(1)
end
return settings
end
function make_gtest_settings( base_settings )
local settings = TableDeepCopy( base_settings )
settings.cc.includes:Add( GTEST_PATH )
settings.cc.includes:Add( PathJoin( GTEST_PATH, 'include' ) )
return settings
end
function make_dl_settings( base_settings )
local settings = TableDeepCopy( base_settings )
-- build dl on high warning level!
if settings.platform == 'linux_x86' or settings.platform == 'linux_x86_64' then
settings.cc.flags:Add("-Wall","-Werror", "-Wextra", "-Wconversion", "-Wstrict-aliasing=2")
else
settings.cc.flags:Add("/W4", "/WX")
settings.cc.flags_c:Add("/TP")
end
return settings
end
function make_dl_so_settings( base_settings )
local settings = make_dl_settings( base_settings )
if settings.platform == 'linux_x86_64' then
settings.cc.flags:Add( "-fPIC" )
end
local output_path = PathJoin( BUILD_PATH, PathJoin( settings.platform, settings.config ) )
local dll_path = PathJoin( output_path, 'dll' )
settings.cc.Output = function(settings, path) return PathJoin( dll_path, PathFilename(PathBase(path)) .. settings.config_ext) end
return settings
end
function make_test_settings( base_settings )
local settings = TableDeepCopy( base_settings )
if settings.platform == 'linux_x86' or settings.platform == 'linux_x86_64' then
settings.cc.flags:Add("-Wall","-Werror", "-Wextra", "-Wconversion", "-Wstrict-aliasing=2")
settings.cc.flags_cxx:Add("-std=c++11") -- enabled to test out sized enums.
else
--[[
/EHsc only on unittest
/wd4324 = warning C4324: 'SA128BitAlignedType' : structure was padded due to __declspec(align())
/wd4127 = warning C4127: conditional expression is constant.
--]]
settings.cc.flags:Add("/W4", "/WX", "/EHsc", "/wd4324", "/wd4127")
settings.cc.flags_c:Add("/TP")
end
settings.cc.includes:Add( PathJoin( PathJoin( EXTERNALS_PATH, 'gtest' ), 'include' ) )
if settings.platform == "linux_x86_64" or settings.platform == "linux_x86" then
settings.link.libs:Add( "pthread" )
end
return settings
end
------------------------ BUILD ------------------------
local compiler = get_compiler()
print( 'compiler used "' .. compiler .. '"')
settings =
{
linux_x86 = {
debug = DefaultGCCLike( "linux_x86", "debug", compiler ),
release = DefaultGCCLike( "linux_x86", "release", compiler ),
sanitizer = DefaultGCCLike( "linux_x86", "sanitizer", compiler ),
},
linux_x86_64 = {
debug = DefaultGCCLike( "linux_x86_64", "debug", compiler ),
coverage = DefaultGCCLike( "linux_x86_64", "coverage", compiler ),
release = DefaultGCCLike( "linux_x86_64", "release", compiler ),
sanitizer = DefaultGCCLike( "linux_x86_64", "sanitizer", compiler )
},
win32 = {
debug = DefaultMSVC( "win32", "debug", compiler ),
release = DefaultMSVC( "win32", "release", compiler )
},
winx64 = {
debug = DefaultMSVC( "winx64", "debug", compiler ),
release = DefaultMSVC( "winx64", "release", compiler )
}
}
build_platform = ScriptArgs["platform"]
config = ScriptArgs["config"]
if not build_platform then error( "platform need to be set. example \"platform=linux_x86\"" ) end
if not config then error( "config need to be set. example \"config=debug\"" ) end
platform_settings = settings[build_platform]
if not platform_settings then error( build_platform .. " is not a supported platform" ) end
build_settings = platform_settings[config]
if not build_settings then error( config .. " is not a supported configuration" ) end
build_settings = settings[ build_platform ][ config ]
dl_settings = make_dl_settings ( build_settings )
dl_so_settings = make_dl_so_settings( build_settings )
test_settings = make_test_settings ( build_settings )
gtest_settings = make_gtest_settings( build_settings )
gtest_lib = StaticLibrary( gtest_settings, "gtest", Compile( gtest_settings, Collect( PathJoin( GTEST_PATH, "src/gtest-all.cc" ) ) ) )
dl_lib = StaticLibrary( dl_settings, "dl", Compile( dl_settings, Collect( "src/*.cpp" ) ) )
dl_shared = SharedLibrary( dl_settings, "dlsh", Compile( dl_so_settings, Collect( "src/*.cpp" ) ) )
dl_settings.cc.includes:Add('tool/dlpack')
getopt = Compile( dl_settings, CollectRecursive( "tool/dlpack/*.c" ) )
dl_pack = Link( build_settings, "dlpack", Compile( dl_settings, CollectRecursive("tool/dlpack/*.cpp") ), getopt, dl_lib )
dltlc = Link( build_settings, "dltlc", Compile( dl_settings, CollectRecursive("tool/dltlc/*.cpp") ), getopt, dl_lib )
dl_tests = Link( test_settings, "dl_tests", Compile( test_settings, Collect("tests/*.cpp") ), dl_lib, gtest_lib )
dlbench = Link( test_settings, "dlbench", Compile( test_settings, Collect("benchmark/*.cpp") ), dl_lib )
tl1 = dl_type_lib( "tests/sized_enums.tld", dltlc, dl_tests )
tl2 = dl_type_lib( "tests/unittest.tld", dltlc, dl_tests )
tl3 = dl_type_lib( "tests/unittest2.tld", dltlc, dl_tests )
tl4 = dl_type_lib( "tests/small.tld", dltlc, dl_tests )
tlbench = dl_type_lib( "benchmark/dlbench.tld", dltlc, dl_tests )
dl_test_valid_c = Compile( dl_settings, Collect( "tests/*.c" ), tl1, tl2, tl3, tl4, tlbench )
local test_args = ""
local py_test_args = ""
if ScriptArgs["test_filter"] then
test_args = " --gtest_filter=" .. ScriptArgs["test_filter"]
py_test_args = " " .. ScriptArgs["test_filter"]
end
if family == "windows" then
AddJob( "test", "unittest c", string.gsub( dl_tests, "/", "\\" ) .. test_args, dl_tests, "local/generated/unittest.bin" )
SkipOutputVerification("test")
else
local valgrind_flags = " -v --leak-check=full --track-origins=yes "
AddJob( "test", "unittest c", dl_tests .. test_args, dl_tests, "local/generated/unittest.bin" )
AddJob( "test_valgrind", "unittest valgrind", "valgrind" .. valgrind_flags .. dl_tests .. test_args, dl_tests, "local/generated/unittest.bin" )
AddJob( "test_gdb", "unittest gdb", "gdb --args " .. dl_tests .. test_args, dl_tests, "local/generated/unittest.bin" )
SkipOutputVerification("test")
SkipOutputVerification("test_valgrind")
SkipOutputVerification("test_gdb")
end
AddJob( "benchmark", "benchmark", dlbench, dlbench )
SkipOutputVerification("benchmark")
PYTHON = "python"
if family == "windows" then -- hackery hack
PYTHON = "C:\\Python27\\python.exe"
end
dl_tests_py = "tests/python_bindings/dl_tests.py"
AddJob( "test_py",
"unittest python",
PYTHON .. " " .. dl_tests_py .. " " .. dl_shared .. " " .. py_test_args,
dl_tests_py,
dl_shared, "local/generated/unittest.bin" )
-- do not run unittest as default, only run
PseudoTarget( "dl_default", dl_pack, dltlc, dl_tests, dl_shared, dlbench, dl_test_valid_c )
DefaultTarget( "dl_default" )