Update Snapshot(2018-12-12)
[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                     }
388     extra_option_str = "resource -c"
389     call_scons(build_options, extra_option_str)
390
391     build_options = {
392                         'LOGGING':'false',
393                         'RELEASE':'false',
394                     }
395     extra_option_str = "resource"
396     call_scons(build_options, extra_option_str)
397
398     build_options = {
399                         'TEST':1,
400                         'RELEASE':'false',
401                     }
402     call_scons(build_options, extra_option_str)
403     build_options = {
404                         'TEST':1,
405                         'SECURED':1,
406                         'RELEASE':'false',
407                     }
408     call_scons(build_options, extra_option_str)
409
410     print ("*********** Unit test Stop *************")
411
412 # Main module starts here
413 if os.getenv("SCONSFLAGS", "") == "":
414     os.environ["SCONSFLAGS"] = "-Q -j " + str(multiprocessing.cpu_count())
415
416 arg_num     = len(sys.argv)
417 script_name = sys.argv[0]
418
419 # May be overridden in user's shell
420 VERBOSE = os.getenv("VERBOSE", "1")
421
422 if arg_num == 1:
423     build_all("true", "")
424     build_all("false", "")
425     unit_tests()
426
427 elif arg_num == 2:
428     if str(sys.argv[1]) == '-c':
429         build_all("true", "-c")
430         build_all("false", "-c")
431
432     elif str(sys.argv[1]) == "all":
433         build_all("true", "")
434         build_all("false", "")
435         unit_tests()
436
437     elif str(sys.argv[1]) == "linux":
438         build_linux("true", "")
439         build_linux("false", "")
440
441     elif str(sys.argv[1]) == "linux_unsecured":
442         build_linux_unsecured("true", "")
443         build_linux_unsecured("false", "")
444         build_linux_unsecured_with_rm("true", "")
445         build_linux_unsecured_with_rm("false", "")
446
447     elif str(sys.argv[1]) == "linux_secured":
448         build_linux_secured("true", "")
449         build_linux_secured("false", "")
450
451     elif str(sys.argv[1]) == "linux_unsecured_with_ra":
452         build_linux_unsecured_with_ra("true", "")
453         build_linux_unsecured_with_ra("false", "")
454
455     elif str(sys.argv[1]) == "linux_secured_with_ra":
456         build_linux_secured_with_ra("true", "")
457         build_linux_secured_with_ra("false", "")
458
459     elif str(sys.argv[1]) == "linux_unsecured_with_rd":
460         build_linux_unsecured_with_rd("true", "")
461         build_linux_unsecured_with_rd("false", "")
462
463     elif str(sys.argv[1]) == "linux_secured_with_rd":
464         build_linux_secured_with_rd("true", "")
465         build_linux_secured_with_rd("false", "")
466
467     elif str(sys.argv[1]) == "linux_unsecured_with_mq":
468         build_linux_unsecured_with_mq("true", "")
469         build_linux_unsecured_with_mq("false", "")
470
471     elif str(sys.argv[1]) == "linux_unsecured_with_tcp":
472         build_linux_unsecured_with_tcp("true", "")
473         build_linux_unsecured_with_tcp("false", "")
474
475     elif str(sys.argv[1]) == "linux_secured_with_tcp":
476         build_linux_secured_with_tcp("false", "")
477         build_linux_secured_with_tcp("true", "")
478
479     elif str(sys.argv[1]) == "android":
480         build_android("true", "")
481         build_android("false", "")
482
483     elif str(sys.argv[1]) == "android_x86":
484         build_android_x86("true", "")
485         build_android_x86("false", "")
486         build_android_x86_with_rm("true", "")
487         build_android_x86_with_rm("false", "")
488
489     elif str(sys.argv[1]) == "android_armeabi":
490         build_android_armeabi("true", "")
491         build_android_armeabi("false", "")
492         build_android_armeabi_with_rm("true", "")
493         build_android_armeabi_with_rm("false", "")
494
495     elif str(sys.argv[1]) == "arduino":
496         build_arduino("true", "")
497         build_arduino("false", "")
498
499     elif str(sys.argv[1]) == "windows":
500         build_windows("true", "")
501         build_windows("false", "")
502
503     elif str(sys.argv[1]) == "msys":
504         build_msys("true", "")
505         build_msys("false", "")
506
507     elif str(sys.argv[1]) == "tizen":
508         build_tizen("true", "")
509         build_tizen("false", "")
510
511     elif str(sys.argv[1]) == "simulator":
512         build_simulator("true", "")
513         build_simulator("false", "")
514
515     elif str(sys.argv[1]) == "darwin":
516         build_darwin("true", "")
517         build_darwin("false", "")
518
519     elif str(sys.argv[1]) == "unit_tests":
520         unit_tests()
521
522     else:
523         helpmsg(script_name)
524 else:
525         helpmsg(script_name)
526
527 print ("===================== done =====================")