This repository has been archived by the owner on Jan 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathSConscript
executable file
·384 lines (333 loc) · 13.9 KB
/
SConscript
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
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
import os
import re
import string
Import(['env', 'ext_objs', 'ext_shobjs', 'extUV', 'version'])
# Additional warning for the these files
commonenv = env.Clone()
if commonenv['CC'] == 'cl':
commonenv.Append(CCFLAGS = ['/W3', '/WX'])
# Compiler settings validation
commonenv.Append(CCFLAGS = ['/sdl'])
else:
commonenv.Append(CCFLAGS = ['-Werror', '-Wall', '-Wextra', '-Wformat-security'])
commonenv.Append(CCFLAGS = ['-Wno-unused-parameter', '-Wno-unused-function', '-Wno-type-limits', '-Wno-missing-braces', '-Wno-attributes'])
commonenv.Append(CFLAGS = ['-Wstrict-prototypes'])
commonenv.Append(CPPPATH = ['#/inc'])
# Core libraries
libenv = commonenv.Clone()
libenv.Append(CPPDEFINES = ['MBEDTLS_USER_CONFIG_FILE=\\"mbedtls_config.h\\"'])
if env['PLATFORM'] == 'posix':
libenv.Append(CPPDEFINES = ['_GNU_SOURCE'])
libenv.Append(CPPPATH = ['#/ext/safestring/include', '#/ext', '#/ext/mbedtls/include'])
if extUV: libenv.Append(CPPPATH = ['#/ext/libuv/include'])
# Include the fuzzing hooks when the sanitizer is enabled
if env['PLATFORM'] == 'posix' and env['fsan'] == True:
libenv.Append(CPPDEFINES = ['DPS_USE_FUZZ'])
libenv.Install('#/build/dist/inc/dps', libenv.Glob('#/inc/dps/*.h'))
libenv.Install('#/build/dist/inc/dps/private', libenv.Glob('#/inc/dps/private/*.h'))
srcs = ['src/bitvec.c',
'src/cbor.c',
'src/cose.c',
'src/coap.c',
'src/dps.c',
'src/discovery.c',
'src/dispatcher.c',
'src/pub.c',
'src/sub.c',
'src/ack.c',
'src/dbg.c',
'src/err.c',
'src/event.c',
'src/history.c',
'src/json.c',
'src/keystore.c',
'src/synchronous.c',
'src/uuid.c',
'src/network.c',
'src/registration.c',
'src/resolver.c',
'src/topics.c',
'src/uv_extra.c',
'src/sha2.c',
'src/gcm.c',
'src/ec.c',
'src/hkdf.c',
'src/keywrap.c',
'src/mbedtls.c',
'src/queue.c']
if env['transport'] == 'udp':
srcs.extend(['src/multicast/network.c',
'src/udp/network.c'])
elif env['transport'] == 'dtls':
srcs.extend(['src/multicast/network.c',
'src/dtls/network.c'])
elif env['transport'] == 'tcp':
srcs.extend(['src/multicast/network.c',
'src/tcp/network.c'])
elif env['transport'] == 'pipe':
srcs.extend(['src/multicast/network.c',
'src/pipe/network.c'])
elif env['transport'] == 'fuzzer':
srcs.extend(['src/fuzzer/network.c'])
Depends(srcs, ext_objs)
objs = libenv.Object(srcs)
lib = libenv.Library('lib/dps', [objs, ext_objs])
installed_lib = libenv.Install('#/build/dist/lib', lib)
shobjs = libenv.SharedObject(srcs) + ext_shobjs
if libenv['CC'] == 'cl':
shlib = libenv.SharedLibrary('lib/dps_shared', shobjs + [env['DEF_FILE']], LIBS = env['DPS_LIBS'], SHLIBVERSION = version)
elif libenv['PLATFORM'] == 'win32':
shlib = libenv.SharedLibrary('lib/dps_shared', shobjs, LIBS = env['DPS_LIBS'])
else:
shlib = libenv.SharedLibrary('lib/dps_shared', shobjs, LIBS = env['DPS_LIBS'], SHLIBVERSION = version,
SHLINKFLAGS = '$SHLINKFLAGS -Wl,--version-script=' + env['DEF_FILE'])
libenv.InstallVersionedLib('#/build/dist/lib', shlib, SHLIBVERSION = version)
ns3srcs = ['src/bitvec.c',
'src/cbor.c',
'src/gcm.c',
'src/coap.c',
'src/cose.c',
'src/dps.c',
'src/pub.c',
'src/sha2.c',
'src/sub.c',
'src/ack.c',
'src/err.c',
'src/history.c',
'src/uuid.c',
'src/topics.c']
if env['PLATFORM'] == 'posix':
ns3shobjs = libenv.SharedObject(ns3srcs)
ns3shlib = libenv.SharedLibrary('lib/dps_ns3', ns3shobjs + ext_shobjs)
libenv.Install('#/build/dist/lib', ns3shlib)
swig_docs = []
if env['python']:
if env['PLATFORM'] == 'posix' or env['CC'] == 'cl':
# Using SWIG to build the python wrapper
pyenv = libenv.Clone()
pyenv.VariantDir('swig/py', 'swig')
pyenv.Append(LIBPATH = env['PY_LIBPATH'])
pyenv.Append(CPPPATH = env['PY_CPPPATH'])
pyenv.Append(LIBS = [lib, env['DPS_LIBS']])
# Documentation is only available which Doxygen is installed
try:
if pyenv.Doxygen:
pyenv.Append(SWIGFLAGS = ['-DINCLUDE_DOC'])
except AttributeError:
pass
# Python has platform specific naming conventions
pyenv['SHLIBPREFIX'] = '_'
if pyenv['CC'] == 'cl':
pyenv['SHLIBSUFFIX'] = '.pyd'
pyenv.Append(CCFLAGS = ['/EHsc'])
# Ignore warnings in generated code
pyenv.Append(CCFLAGS = ['/wd4244', '/wd4703'])
elif 'gcc' in pyenv['CC']:
pyenv.Append(CCFLAGS = ['-Wno-ignored-qualifiers', '-Wno-cast-function-type'])
elif 'clang' in pyenv['CC']:
pyenv.Append(CCFLAGS = ['-Wno-deprecated-register', '-Wno-ignored-qualifiers'])
pyenv.Append(SWIGFLAGS = ['-python', '-c++', '-Wextra', '-Werror', '-v', '-O'], SWIGPATH = ['#/inc', './swig/py'])
pyenv.Append(CPPPATH = ['swig', 'swig/py'])
# Build python module library
pyobjs = pyenv.SharedObject(['swig/py/dps.i'])
pylib = pyenv.SharedLibrary('./py/dps', shobjs + pyobjs)
pyenv.Install('#/build/dist/py', pylib)
pyenv.InstallAs('#/build/dist/py/dps.py', './swig/py/dps.py')
# Build documentation
swig_docs += ['swig/py/dps_doc.i']
else:
print('Python binding only supported on the posix platform or with the cl compiler')
exit()
if env['nodejs']:
if env['PLATFORM'] == 'posix':
# Use SWIG to build the node.js wrapper
nodeenv = libenv.Clone();
nodeenv.VariantDir('swig/js', 'swig')
nodeenv.Append(SWIGFLAGS = ['-javascript', '-node', '-c++', '-DV8_VERSION=0x04059937', '-Wextra', '-Werror', '-v', '-O'], SWIGPATH = ['#/inc', './swig/js'])
# There may be a bug with the SWIG builder - add -O to CPPFLAGS to get it passed on to the compiler
nodeenv.Append(CPPDEFINES = ['BUILDING_NODE_EXTENSION'])
nodeenv.Append(CCFLAGS = ['-std=c++11', '-O', '-Wno-unused-result', '-Wno-ignored-qualifiers'])
if 'gcc' in nodeenv['CC']:
nodeenv.Append(CCFLAGS = ['-Wno-cast-function-type'])
nodeenv.Append(CPPPATH = ['swig', 'swig/js'])
if env['target'] == 'yocto':
nodeenv.Append(CPPPATH = [os.getenv('SYSROOT') + '/usr/include/node'])
else:
nodeenv.Append(CPPPATH = ['/usr/include/node'])
nodeenv.Append(LIBS = [lib, env['DPS_LIBS']])
nodeobjs = nodeenv.SharedObject(['swig/js/dps.i'])
nodedps = nodeenv.SharedLibrary('lib/nodedps', shobjs + nodeobjs)
nodeenv.InstallAs('#/build/dist/js/dps.node', nodedps)
# Build documentation
swig_docs += ['swig/js/dps.jsdoc']
else:
print('Node.js binding only supported on the posix platform')
exit()
goimport1_re = re.compile(r'^import\s+"([^"]+)"', re.M)
goimportn_re = re.compile(r'^import\s+\(([^)]+)\)', re.M)
def gosrc_scanner(node, env, path):
imports = []
contents = node.get_text_contents()
for i in goimport1_re.findall(contents) + goimportn_re.findall(contents):
for j in i.split():
pkg = j.strip('\"')
imports += env.Glob('{}/src/{}/*.go'.format(env['GOPATH'], pkg))
imports += env.Glob('{}/pkg/{}_{}/{}{}'.format(env['GOPATH'], env['ENV']['GOOS'], env['ENV']['GOARCH'], pkg, env['LIBSUFFIX']))
# Special case for dps.go: any src file importing it also depends on the DPS libraries
if any('dps.go' in str(i) for i in imports):
imports += lib
return imports
go_scanner = Scanner(function = gosrc_scanner,
skeys = ['.go'])
def gopkg_generator(target, source, env, for_signature):
t = str(target[0]).replace(os.path.sep, '/')
t = os.path.splitext(re.sub(r'.*/go/pkg/[^/]+/', r'', t))[0]
return 'go install -a {}'.format(t)
def gopkg_emitter(target, source, env):
src = 'dps/{}.go'.format(source[0])
pkg = '{}{}'.format(os.path.dirname(src), env['LIBSUFFIX'])
return 'go/pkg/{}_{}/'.format(env['ENV']['GOOS'], env['ENV']['GOARCH']) + pkg, 'go/src/' + src
gopkg = Builder(generator = gopkg_generator,
emitter = gopkg_emitter,
source_scanner = go_scanner)
def gobin_generator(target, source, env, for_signature):
t = str(source[0]).replace(os.path.sep, '/')
t = os.path.dirname(re.sub(r'.*/go/src/', r'', t))
return 'go install -a {}'.format(t)
def gobin_emitter(target, source, env):
src = 'dps/{}.go'.format(source[0])
bin = os.path.basename(str(source[0]))
return 'go/bin/' + bin, 'go/src/' + src
gobin = Builder(generator = gobin_generator,
emitter = gobin_emitter,
source_scanner = go_scanner)
if env['go']:
if 'gcc' in env['CC']:
goenv = libenv.Clone()
goenv.AppendENVPath('GOOS', os.popen('go env GOOS').read().strip())
goenv.AppendENVPath('GOARCH', os.popen('go env GOARCH').read().strip())
# Append our GOPATH to the environment seen by the go tools and also remember it for use by the
# scanner to locate imports.
goenv.AppendENVPath('GOPATH', goenv.Dir('go').abspath)
goenv.Append(GOPATH = goenv.Dir('go').abspath)
goenv.Append(LIBS = env['DPS_LIBS'])
cgo_cflags = ' '.join(['-I' + goenv.GetBuildPath(p) for p in goenv['CPPPATH']])
cgo_ldflags = ' '.join(l.abspath for l in lib) + ' ' + ' '.join(['-l' + l for l in goenv['LIBS']])
goenv.AppendENVPath('CGO_CFLAGS', cgo_cflags)
goenv.AppendENVPath('CGO_LDFLAGS', cgo_ldflags)
goenv.Append(BUILDERS = {'GoPkg' : gopkg})
goenv.Append(BUILDERS = {'GoBin' : gobin})
goenv.VariantDir('go/src/dps', 'go')
for p in ['dps',
'examples/keys/keys']:
goenv.GoPkg(p)
for b in ['examples/simple_sub_ks/simple_sub_ks',
'examples/simple_sub/simple_sub',
'examples/simple_pub_ks/simple_pub_ks',
'examples/simple_pub/simple_pub']:
goenv.GoBin(b)
for b in ['test/perf_publisher/perf_publisher',
'test/perf_subscriber/perf_subscriber']:
goenv.GoBin(b)
goenv.Install('#/build/dist', 'go')
else:
print('Go binding only supported with the gcc compiler')
exit()
# Unit tests
testenv = commonenv.Clone()
if env['PLATFORM'] == 'posix' and env['fsan'] == True:
testenv.Append(CPPDEFINES = ['DPS_USE_FUZZ'])
testenv.Append(CPPPATH = ['#/ext/safestring/include', 'src'])
testenv.Append(LIBS = [lib, env['DPS_LIBS']])
if extUV: testenv.Append(CPPPATH = ['#/ext/libuv/include'])
testsrcs = ['test/cbortest.c',
'test/cosetest.c',
'test/countvec.c',
'test/discover.c',
'test/hist_unit.c',
'test/jsontest.c',
'test/link_drop.c',
'test/ll_unit.c',
'test/keystoretest.c',
'test/make_mesh.c',
'test/mesh_stress.c',
'test/packtest.c',
'test/pubsub.c',
'test/rle_compression.c',
'test/topic_match.c',
'test/uuid.c',
'test/version.c']
Depends(testsrcs, ext_objs)
testobjs = testenv.Object(['test/keys.c',
'test/test.c'])
testprogs = []
for test in testsrcs:
testprogs.append(testenv.Program([test, testobjs]))
testsrcs = ['test/link.c',
'test/node.c',
'test/publish.c']
for test in testsrcs:
testprogs.append(testenv.Program([test, testobjs]))
testenv.Install('#/build/test/bin', testprogs)
psrcs = ['test/perf/publisher.c',
'test/perf/subscriber.c']
Depends(psrcs, ext_objs)
pprogs = []
for test in psrcs:
pprogs.append(testenv.Program([test, testobjs]))
testenv.Install('#/build/test/perf/bin', pprogs)
# Fuzz tests
if env['PLATFORM'] == 'posix' and env['fsan'] == True:
fenv = commonenv.Clone()
fenv.VariantDir('test/fuzzer', 'test')
fenv.Append(CPPPATH = ['#/ext/safestring/include'])
if extUV: fenv.Append(CPPPATH = ['#/ext/libuv/include'])
fenv.Append(LINKFLAGS = ['-fsanitize=fuzzer'])
fenv.Append(LIBS = [lib, env['DPS_LIBS']])
fsrcs = ['test/fuzzer/cbor_fuzzer.c']
if env['transport'] == 'dtls':
fsrcs.extend(['test/fuzzer/dtls_fuzzer.c'])
elif env['transport'] == 'fuzzer':
fsrcs.extend(['test/fuzzer/net_receive_fuzzer.c',
'test/fuzzer/multicast_receive_fuzzer.c'])
Depends(fsrcs, ext_objs)
fprogs = []
for f in fsrcs:
fprogs.append(fenv.Program([f, 'test/fuzzer/keys.c']))
fenv.Install('#/build/test/bin', fprogs)
# Examples
exampleenv = commonenv.Clone()
exampleenv.Append(LIBS = [lib, env['DPS_LIBS']])
examplesrcs = ['examples/pub_many.c',
'examples/publisher.c',
'examples/reg_pubs.c',
'examples/reg_subs.c',
'examples/subscriber.c',
'examples/registry.c']
Depends(examplesrcs, ext_objs)
exampleprogs = []
for example in examplesrcs:
exampleprogs.append(exampleenv.Program([example, 'examples/keys.c', 'examples/common.c']))
exampleenv.Install('#/build/dist/bin', exampleprogs)
# Tutorial examples
tutorialenv = commonenv.Clone()
tutorialenv.Append(LIBS = [lib, env['DPS_LIBS']])
tutorialsrcs = ['doc/tutorial/tutorial.c']
Depends(tutorialsrcs, ext_objs)
tutorialprogs = []
for tutorial in tutorialsrcs:
tutorialprogs.append(tutorialenv.Program(tutorial))
tutorialenv.Install('#/build/dist/bin', tutorialprogs)
# Documentation
try:
docs = libenv.Doxygen('doc/Doxyfile')
libenv.Doxygen('doc/Doxyfile_dev')
libenv.SwigDox(swig_docs, docs)
if env['nodejs'] and env['PLATFORM'] == 'posix':
libenv.InstallAs('#/build/dist/js/dps.jsdoc', 'swig/js/dps.jsdoc')
except:
# Doxygen may not be installed
pass
# Return the static DPS library
result = [lib]
Return('result')