Unit test development.
[platform/upstream/iotivity.git] / auto_build.py
1 #!/usr/bin/python
2
3 import os
4 import sys
5 import platform
6 import subprocess
7 import multiprocessing
8
9 # help message
10 def helpmsg(script):
11     helpstr = '''
12 Usage:
13     build:
14         python %s <targetbuild>
15         Allowed values for <target_build>: all, linux_unsecured, linux_secured, linux_unsecured_with_ra, linux_secured_with_ra, linux_unsecured_with_rd, linux_secured_with_rd, android, arduino, tizen, simulator, darwin, windows, msys
16         Note: \"linux\" will build \"linux_unsecured\", \"linux_secured\", \"linux_unsecured_with_ra\", \"linux_secured_with_ra\", \"linux_secured_with_rd\", \"linux_unsecured_with_mq\", \"linux_unsecured_with_tcp\" & \"linux_unsecured_with_rd\".
17         Any selection will build both debug and release versions of all available targets in the scope you've selected.
18         To choose any specific command, please use the SCons commandline directly. Please refer to [IOTIVITY_REPO]/Readme.scons.txt.
19     clean:
20         python %s -c
21     '''
22     print (helpstr % (script, script))
23     sys.exit()
24
25 def call_scons(build_options, extra_option_str):
26     """
27     This function formats and runs a scons command
28     Arguments:
29     build_options    -- {Dictionary} build flags (keys) associated with values;
30     extra_option_str -- {String} extra options to append to scons command
31     """
32     cmd_line = "scons VERBOSE=" + VERBOSE
33     for key in build_options:
34         cmd_line += " " + key + "=" + str(build_options[key])
35
36     cmd_line += " " + str(extra_option_str)
37
38     print ("Running : " + cmd_line)
39     exit_code = subprocess.Popen([cmd_line], shell=True).wait()
40     if exit_code != 0:
41         exit(exit_code)
42
43 def build_all(flag, extra_option_str):
44     if platform.system() == "Linux":
45         build_linux_unsecured(flag, extra_option_str)
46         build_linux_secured(flag, extra_option_str)
47         build_linux_unsecured_with_ra(flag, extra_option_str)
48         build_linux_secured_with_ra(flag, extra_option_str)
49         build_linux_unsecured_with_rm(flag, extra_option_str)
50         build_linux_unsecured_with_rd(flag, extra_option_str)
51         build_linux_secured_with_rd(flag, extra_option_str)
52         build_linux_unsecured_with_mq(flag, extra_option_str)
53         build_linux_unsecured_with_tcp(flag, extra_option_str)
54         build_simulator(flag, extra_option_str)
55
56     build_android(flag, extra_option_str)
57     build_arduino(flag, extra_option_str)
58     build_tizen(flag, extra_option_str)
59
60     if platform.system() == "Windows":
61         build_windows(flag, extra_option_str)
62
63     if platform.system() == "Darwin":
64         build_darwin(flag, extra_option_str)
65
66 def build_linux(flag, extra_option_str):
67     build_linux_unsecured(flag, extra_option_str)
68     build_linux_secured(flag, extra_option_str)
69
70 def build_linux_unsecured(flag, extra_option_str):
71     print ("*********** Build for linux ************")
72     build_options = {
73                         'RELEASE':flag,
74                     }
75     call_scons(build_options, extra_option_str)
76
77 def build_linux_unsecured_with_tcp(flag, extra_option_str):
78     print ("*********** Build for linux with TCP ************")
79     build_options = {
80                         'RELEASE':flag,
81                         'WITH_TCP': 1,
82                         'TARGET_TRANSPORT': 'IP',
83                     }
84     call_scons(build_options, extra_option_str)
85
86 def build_linux_unsecured_with_rm(flag, extra_option_str):
87     print ("*********** Build for linux with RoutingManager************")
88     build_options = {
89                         'ROUTING':'GW',
90                         'RELEASE':flag,
91                     }
92     call_scons(build_options, extra_option_str)
93
94 def build_linux_secured(flag, extra_option_str):
95     print ("*********** Build for linux with Security *************")
96     build_options = {
97                         'RELEASE':flag,
98                         'SECURED':1,
99                     }
100     call_scons(build_options, extra_option_str)
101
102 def build_linux_unsecured_with_ra(flag, extra_option_str):
103     print ("*********** Build for linux With Remote Access *************")
104     build_options = {
105                         'RELEASE':flag,
106                         'WITH_RA':1,
107                         'WITH_RA_IBB':1,
108                     }
109     call_scons(build_options, extra_option_str)
110
111 def build_linux_secured_with_ra(flag, extra_option_str):
112     print ("*********** Build for linux With Remote Access & Security ************")
113     build_options = {
114                         'RELEASE':flag,
115                         'WITH_RA':1,
116                         'WITH_RA_IBB':1,
117                         'SECURED':1,
118                     }
119     call_scons(build_options, extra_option_str)
120
121 def build_linux_unsecured_with_rd(flag, extra_option_str):
122     print ("*********** Build for linux With Resource Directory *************")
123     build_options = {
124                         'RELEASE':flag,
125                         'WITH_RD':1,
126                     }
127     call_scons(build_options, extra_option_str)
128
129 def build_linux_secured_with_rd(flag, extra_option_str):
130     print ("*********** Build for linux With Resource Directory & Security ************")
131     build_options = {
132                         'RELEASE':flag,
133                         'WITH_RD':1,
134                         'SECURED':1,
135                     }
136     call_scons(build_options, extra_option_str)
137
138 def build_linux_unsecured_with_mq(flag, extra_option_str):
139     print ("*********** Build for linux With Message Queue ************")
140     build_options = {
141                         'RELEASE':flag,
142                         'WITH_MQ':'PUB,SUB,BROKER',
143                     }
144     call_scons(build_options, extra_option_str)
145
146 def build_linux_unsecured_with_tcp(flag, extra_option_str):
147     print ("*********** Build for linux With tcp ************")
148     build_options = {
149                         'RELEASE':flag,
150                         'WITH_TCP':'1',
151                     }
152     call_scons(build_options, extra_option_str)
153
154 def build_android(flag, extra_option_str):
155     # Note: for android, as oic-resource uses C++11 feature stoi and to_string,
156     # it requires gcc-4.9, currently only android-ndk-r10(for linux)
157     # and windows android-ndk-r10(64bit target version) support these features.
158
159     build_android_x86(flag, extra_option_str)
160     build_android_x86_with_rm(flag, extra_option_str)
161     build_android_armeabi(flag, extra_option_str)
162     build_android_armeabi_with_rm(flag, extra_option_str)
163
164 def build_android_x86(flag, extra_option_str):
165     print ("*********** Build for android x86 *************")
166     build_options = {
167                         'TARGET_OS':'android',
168                         'TARGET_ARCH':'x86',
169                         'RELEASE':flag,
170                         'TARGET_TRANSPORT':'IP',
171                     }
172     call_scons(build_options, extra_option_str)
173
174     build_options['TARGET_TRANSPORT'] = 'BT'
175     call_scons(build_options, extra_option_str)
176
177     build_options['TARGET_TRANSPORT'] = 'BLE'
178     call_scons(build_options, extra_option_str)
179
180 def build_android_x86_with_rm(flag, extra_option_str):
181     print ("*********** Build for android x86 with Routing Manager *************")
182     build_options = {
183                         'TARGET_OS':'android',
184                         'TARGET_ARCH':'x86',
185                         'ROUTING':'GW',
186                         'RELEASE':flag,
187                         'TARGET_TRANSPORT':'IP',
188                     }
189     call_scons(build_options, extra_option_str)
190
191     build_options['TARGET_TRANSPORT'] = 'BT'
192     call_scons(build_options, extra_option_str)
193
194     build_options['TARGET_TRANSPORT'] = 'BLE'
195     call_scons(build_options, extra_option_str)
196
197 def build_android_armeabi(flag, extra_option_str):
198     print ("*********** Build for android armeabi *************")
199     build_options = {
200                         'TARGET_OS':'android',
201                         'TARGET_ARCH':'armeabi',
202                         'RELEASE':flag,
203                         'TARGET_TRANSPORT':'IP',
204                     }
205     call_scons(build_options, extra_option_str)
206
207     build_options['TARGET_TRANSPORT'] = 'BT'
208     call_scons(build_options, extra_option_str)
209
210     build_options['TARGET_TRANSPORT'] = 'BLE'
211     call_scons(build_options, extra_option_str)
212
213 def build_android_armeabi_with_rm(flag, extra_option_str):
214     print ("*********** Build for android armeabi with Routing Manager*************")
215     build_options = {
216                         'TARGET_OS':'android',
217                         'TARGET_ARCH':'armeabi',
218                         'ROUTING':'GW',
219                         'RELEASE':flag,
220                         'TARGET_TRANSPORT':'IP',
221                     }
222     call_scons(build_options, extra_option_str)
223
224     build_options['TARGET_TRANSPORT'] = 'BT'
225     call_scons(build_options, extra_option_str)
226
227     build_options['TARGET_TRANSPORT'] = 'BLE'
228     call_scons(build_options, extra_option_str)
229
230 def build_arduino(flag, extra_option_str):
231     print ("*********** Build for arduino avr *************")
232     extra_option_str = "resource " + extra_option_str
233     build_options = {
234                         'TARGET_OS':'arduino',
235                         'UPLOAD':'false',
236                         'BOARD':'mega',
237                         'TARGET_ARCH':'avr',
238                         'TARGET_TRANSPORT':'IP',
239                         'SHIELD':'ETH',
240                         'RELEASE':flag,
241                     }
242     call_scons(build_options, extra_option_str)
243
244     build_options['SHIELD'] = 'WIFI'
245     call_scons(build_options, extra_option_str)
246
247     build_options['TARGET_TRANSPORT'] = 'BLE'
248     build_options['SHIELD']           = 'RBL_NRF8001'
249     call_scons(build_options, extra_option_str)
250
251     print ("*********** Build for arduino arm *************")
252     build_options['BOARD']            = 'arduino_due_x'
253     build_options['TARGET_ARCH']      = 'arm'
254     build_options['TARGET_TRANSPORT'] = 'IP'
255     build_options['SHIELD']           = 'ETH'
256     call_scons(build_options, extra_option_str)
257
258     build_options['SHIELD'] = 'WIFI'
259     call_scons(build_options, extra_option_str)
260
261     # BLE support for the Arduino Due is currently unavailable.
262
263 def build_tizen(flag, extra_option_str):
264     print ("*********** Build for Tizen *************")
265     cmd_line = "/bin/sh " + os.getcwd() + "/gbsbuild.sh"
266     print ("Running : " + cmd_line)
267     subprocess.Popen([cmd_line], shell=True).wait()
268
269     print ("*********** Build for Tizen octbstack lib and sample *************")
270     extra_option_str = "-f resource/csdk/stack/samples/tizen/build/SConscript " + extra_option_str
271     build_options = {
272                         'TARGET_OS':'tizen',
273                         'TARGET_TRANSPORT':'IP',
274                         'LOGGING':'true',
275                         'RELEASE':flag,
276                     }
277     call_scons(build_options, extra_option_str)
278
279     print ("*********** Build for Tizen octbstack lib and sample with Security*************")
280     build_options['SECURED'] = 1
281     call_scons(build_options, extra_option_str)
282
283     print ("*********** Build for Tizen octbstack lib and sample with Routing Manager*************")
284     del build_options['SECURED']
285     build_options['ROUTING'] = 'GW'
286     call_scons(build_options, extra_option_str)
287
288 # Mac OS and iOS
289 def build_darwin(flag, extra_option_str):
290     print ("*********** Build for OSX *************")
291     build_options = {
292                         'TARGET_OS':'darwin',
293                         'SYS_VERSION':'10.9',
294                         'RELEASE':flag,
295                     }
296     call_scons(build_options, extra_option_str)
297
298     print ("*********** Build for IOS i386 *************")
299     build_options = {
300                         'TARGET_OS':'ios',
301                         'TARGET_ARCH':'i386',
302                         'SYS_VERSION':'7.0',
303                         'RELEASE':flag,
304                     }
305     call_scons(build_options, extra_option_str)
306
307     print ("*********** Build for IOS x86_64 *************")
308     build_options['TARGET_ARCH'] = 'x86_64'
309     call_scons(build_options, extra_option_str)
310
311     print ("*********** Build for IOS armv7 *************")
312     build_options['TARGET_ARCH'] = 'armv7'
313     call_scons(build_options, extra_option_str)
314
315     print ("*********** Build for IOS armv7s *************")
316     build_options['TARGET_ARCH'] = 'armv7s'
317     call_scons(build_options, extra_option_str)
318
319     print ("*********** Build for IOS arm64 *************")
320     build_options['TARGET_ARCH'] = 'arm64'
321     call_scons(build_options, extra_option_str)
322
323 # Windows
324 def build_windows(flag, extra_option_str):
325     print ("*********** Build for Windows *************")
326     os.environ["SCONSFLAGS"] = ""
327     build_options = {
328                         'TARGET_OS':'windows',
329                         'TARGET_ARCH':'amd64',
330                         'RELEASE':flag,
331                         'WITH_RA':0,
332                         'TARGET_TRANSPORT':'IP',
333                         'SECURED':1,
334                         'WITH_TCP':0,
335                         'BUILD_SAMPLE':'ON',
336                         'LOGGING':'off',
337                         'TEST':1,
338                         'WITH_RD':1,
339                     }
340     call_scons(build_options, extra_option_str)
341
342 # Windows msys
343 def build_msys(flag, extra_option_str):
344     print ("*********** Build for msys_nt *************")
345     os.environ["SCONSFLAGS"] = ""
346     build_options = {
347                         'TARGET_OS':'msys_nt',
348                         'TARGET_ARCH':'x86_64',
349                         'RELEASE':flag,
350                         'WITH_RA':0,
351                         'TARGET_TRANSPORT':'IP',
352                         'SECURED':1,
353                         'WITH_TCP':0,
354                         'BUILD_SAMPLE':'ON',
355                         'LOGGING':'off',
356                         'TEST':1,
357                         'WITH_RD':1,
358                     }
359     call_scons(build_options, extra_option_str)
360
361 def build_simulator(flag, extra_option_str):
362     print ("*********** Build for simulator plugin *************")
363     build_options = {
364                         'SIMULATOR':1,
365                         'RELEASE':flag,
366                     }
367     call_scons(build_options, extra_option_str)
368
369 def unit_tests():
370     print ("*********** Unit test Start *************")
371     build_options = {
372                         'RELEASE':'false',
373                     }
374     extra_option_str = "resource -c"
375     call_scons(build_options, extra_option_str)
376
377     build_options = {
378                         'LOGGING':'false',
379                         'RELEASE':'false',
380                     }
381     extra_option_str = "resource"
382     call_scons(build_options, extra_option_str)
383
384     build_options = {
385                         'TEST':1,
386                         'RELEASE':'false',
387                     }
388     extra_option_str = "resource"
389     call_scons(build_options, extra_option_str)
390
391     print ("*********** Unit test Stop *************")
392
393 # Main module starts here
394 if os.getenv("SCONSFLAGS", "") == "":
395     os.environ["SCONSFLAGS"] = "-Q -j " + str(multiprocessing.cpu_count())
396
397 arg_num     = len(sys.argv)
398 script_name = sys.argv[0]
399
400 # May be overridden in user's shell
401 VERBOSE = os.getenv("VERBOSE", "1")
402
403 if arg_num == 1:
404     build_all("true", "")
405     build_all("false", "")
406     unit_tests()
407
408 elif arg_num == 2:
409     if str(sys.argv[1]) == '-c':
410         build_all("true", "-c")
411         build_all("false", "-c")
412
413     elif str(sys.argv[1]) == "all":
414         build_all("true", "")
415         build_all("false", "")
416         unit_tests()
417
418     elif str(sys.argv[1]) == "linux":
419         build_linux("true", "")
420         build_linux("false", "")
421
422     elif str(sys.argv[1]) == "linux_unsecured":
423         build_linux_unsecured("true", "")
424         build_linux_unsecured("false", "")
425         build_linux_unsecured_with_rm("true", "")
426         build_linux_unsecured_with_rm("false", "")
427
428     elif str(sys.argv[1]) == "linux_secured":
429         build_linux_secured("true", "")
430         build_linux_secured("false", "")
431
432     elif str(sys.argv[1]) == "linux_unsecured_with_ra":
433         build_linux_unsecured_with_ra("true", "")
434         build_linux_unsecured_with_ra("false", "")
435
436     elif str(sys.argv[1]) == "linux_secured_with_ra":
437         build_linux_secured_with_ra("true", "")
438         build_linux_secured_with_ra("false", "")
439
440     elif str(sys.argv[1]) == "linux_unsecured_with_rd":
441         build_linux_unsecured_with_rd("true", "")
442         build_linux_unsecured_with_rd("false", "")
443
444     elif str(sys.argv[1]) == "linux_secured_with_rd":
445         build_linux_secured_with_rd("true", "")
446         build_linux_secured_with_rd("false", "")
447
448     elif str(sys.argv[1]) == "linux_unsecured_with_mq":
449         build_linux_unsecured_with_mq("true", "")
450         build_linux_unsecured_with_mq("false", "")
451
452     elif str(sys.argv[1]) == "linux_unsecured_with_tcp":
453         build_linux_unsecured_with_tcp("true", "")
454         build_linux_unsecured_with_tcp("false", "")
455
456     elif str(sys.argv[1]) == "android":
457         build_android("true", "")
458         build_android("false", "")
459
460     elif str(sys.argv[1]) == "android_x86":
461         build_android_x86("true", "")
462         build_android_x86("false", "")
463         build_android_x86_with_rm("true", "")
464         build_android_x86_with_rm("false", "")
465
466     elif str(sys.argv[1]) == "android_armeabi":
467         build_android_armeabi("true", "")
468         build_android_armeabi("false", "")
469         build_android_armeabi_with_rm("true", "")
470         build_android_armeabi_with_rm("false", "")
471
472     elif str(sys.argv[1]) == "arduino":
473         build_arduino("true", "")
474         build_arduino("false", "")
475
476     elif str(sys.argv[1]) == "windows":
477         build_windows("true", "")
478         build_windows("false", "")
479
480     elif str(sys.argv[1]) == "msys":
481         build_msys("true", "")
482         build_msys("false", "")
483
484     elif str(sys.argv[1]) == "tizen":
485         build_tizen("true", "")
486         build_tizen("false", "")
487
488     elif str(sys.argv[1]) == "simulator":
489         build_simulator("true", "")
490         build_simulator("false", "")
491
492     elif str(sys.argv[1]) == "darwin":
493         build_darwin("true", "")
494         build_darwin("false", "")
495
496     elif str(sys.argv[1]) == "unit_tests":
497         unit_tests()
498
499     else:
500         helpmsg(script_name)
501 else:
502         helpmsg(script_name)
503
504 print ("===================== done =====================")