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