Fix build error with scons-4.4.0 version which is based on python3
[platform/upstream/iotivity.git] / build_common / external_libs.scons
index f1e8295..b9c6947 100644 (file)
 #
 ##
 import os, subprocess
-import urllib2, urlparse
+import urllib.request, urllib.error, urllib.parse, urllib.parse
 import SCons.Errors
 
 Import('env')
 
 target_os = env.get('TARGET_OS')
 target_arch = env.get('TARGET_ARCH')
+rd_mode = env.get('RD_MODE')
 
 # for android, doesn't distinguish 'armeabi-v7a-hard' and 'armeabi-v7a' library
 if target_os == 'android':
@@ -78,21 +79,21 @@ def __prepare_lib(ienv, libname, lib = None, path = None, script = None):
                        SConscript(st)
                else:
                        if target_os in ['linux', 'darwin', 'tizen']:
-                               print 'Don\'t find library(%s), please intall it, exit ...' % libname
+                               print(('Don\'t find library(%s), please intall it, exit ...' % libname))
                        else:
-                               print 'Don\'t find library(%s) and don\'t find the process script (%s), exit ...' % (libname, st)
+                               print(('Don\'t find library(%s) and don\'t find the process script (%s), exit ...' % (libname, st)))
                        Exit(1)
 
        conf.Finish()
 
 # Run configure command (usually it's done before build a library)
 def __configure(env, cwd, cmd) :
-       print "Configuring using [%s/%s] ..." % (cwd, cmd)
+       print(("Configuring using [%s/%s] ..." % (cwd, cmd)))
        # build it now (we need the shell, because some programs need it)
        devnull = open(os.devnull, "wb")
        handle  = subprocess.Popen(cmd, shell=True, cwd=cwd, stdout=devnull)
 
-       if handle.wait() <> 0 :
+       if handle.wait() != 0 :
                raise SCons.Errors.BuildError( "Run configuring script [%s]" % (cmd) )
 
 # Download from URL 'url', will save as 'target'
@@ -101,15 +102,15 @@ def __download(ienv, target, url) :
                return target
 
        try :
-               print "Download %s from %s" % (target, url)
-               print "Downloading ..."
-               stream = urllib2.urlopen(url)
+               print(("Download %s from %s" % (target, url)))
+               print("Downloading ...")
+               stream = urllib.request.urlopen(url)
                file = open(target, 'wb')
                file.write(stream.read())
                file.close()
-               print "Download %s from %s complete" % (target, url)
+               print(("Download %s from %s complete" % (target, url)))
                return target
-       except Exception, e :
+       except Exception as e :
                raise SCons.Errors.StopError( '%s [%s]' % (e, url) )
 
 # Install header file(s) to <src_dir>/deps/<target_os>/include
@@ -140,5 +141,6 @@ env.AddMethod(__download, "Download")
 env.AddMethod(__install_head_file, "InstallHeadFile")
 env.AddMethod(__install_lib, "InstallLib")
 
-if env.get('SECURED') == '1':
-       SConscript(os.path.join(env.get('SRC_DIR'), 'extlibs', 'sqlite3', 'SConscript'))
+if env.get('SECURED') == '1' or 'SERVER' in rd_mode:
+       if target_os not in ['linux', 'tizen']:
+               SConscript('#extlibs/sqlite3/SConscript')