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