Tweak main build_common scripts
authorMats Wichmann <mats@linux.com>
Fri, 7 Jul 2017 18:15:37 +0000 (12:15 -0600)
committerPhil Coval <philippe.coval@osg.samsung.com>
Mon, 24 Jul 2017 08:12:43 +0000 (08:12 +0000)
build_common/SConscript:
  * list of supported target-os not general enough for helpmsg, updated
  * send error msg to stderr by passing it to Exit instead of doing print
  * Use simpler python slicing in Yocto tool setup
  * pull most Add(somekind of construction variable) into one big call
    to AddVariables; name some more arguments for better clarity
  Removed temporarily while chasing Jenkins fails:
  * turn all variables which behave like booleans actually into BoolVariable
build_common/external_libs.scons:
  * a bad combination of options used to "raise" an error, but there is
    no need for a stack bracktrace here, want just a simple msg+exit
  * send error msg to stderr by passing it to Exit instead of doing print
build_common/external_libs.scons
  * send error msg to stderr by passing it to Exit instead of doing print
build_common/linux/SConscript
build_common/windows/SConscript
  * reduce repeated calls to env.get for same key
  * windows: update style to like in linux script

Bug: https://jira.iotivity.org/browse/IOT-1745
Change-Id: I928199f005af805cad0b0657ca62411caf7a2500
Signed-off-by: Mats Wichmann <mats@linux.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/21311
Reviewed-by: Ibrahim Esmat <iesmat@microsoft.com>
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: George Nash <george.nash@intel.com>
Reviewed-by: Phil Coval <philippe.coval@osg.samsung.com>
build_common/SConscript
build_common/external_builders.scons
build_common/external_libs.scons
build_common/linux/SConscript
build_common/windows/SConscript

index 4c74ac4..107974b 100755 (executable)
@@ -8,7 +8,7 @@ import platform
 
 project_version = '1.3.0'
 
-# Map of host os and allowed target os (host: allowed target os)
+# Map of build host to possible target os
 host_target_map = {
     'linux': ['linux', 'android', 'arduino', 'yocto', 'tizen'],
     'windows': ['windows', 'android', 'arduino'],
@@ -16,7 +16,7 @@ host_target_map = {
     'msys_nt': ['msys_nt'],
 }
 
-# Map of os and allowed archs (os: allowed archs)
+# Map of target os to possible target architecture
 os_arch_map = {
     'linux': [
         'x86', 'x86_64', 'arm', 'arm-v7a', 'armeabi-v7a', 'arm64', 'mips',
@@ -38,26 +38,28 @@ os_arch_map = {
     ],
 }
 
+# Fetch host from Python platform information and smash case
 host = platform.system().lower()
 
-# the host string contains internal version of Windows: 6.3, 6.4, 10.0
-# which are externally known as 8.0, 8.1, and 10 respectively.
-# Canonicalize the msys_nt-XX.X system name by stripping version off.
+# In case of msys_nt, the host string contains an internal Windows version
+# which is not interesting for lookups in the maps.
+# Canonicalize the msys_nt-XX.X system name to msys-nt
 if 'msys_nt' in host:
     host = 'msys_nt'
 
 if host not in host_target_map:
-    print "\nError: building on '%s' is not currently supported.\n" % host
-    Exit(1)
+    msg = "\nError: building on host os '%s' is not currently supported.\n" % host
+    Exit(msg)
 
 ######################################################################
-# Get build options (the optins from command line)
+# Get build options from command line
 ######################################################################
-target_os = ARGUMENTS.get('TARGET_OS', host).lower()  # target os
+target_os = ARGUMENTS.get('TARGET_OS', host).lower()
 
 if target_os not in host_target_map[host]:
-    print "\nError: Unsupported target os: %s (available: %s)\n" % (target_os, host_target_map[host])
-    Exit(1)
+    msg = "\nError: host '%s' cannot currently build target '%s'" % (host, target_os)
+    msg += "\n\tchoices: %s\n" % host_target_map[host]
+    Exit(msg)
 
 if target_os == 'android':
     default_arch = 'x86'
@@ -85,207 +87,185 @@ else:
             'y', 'yes', 'true', 't', '1', 'on', 'all', True
     ]:
         release_mode = True
-    logging_default = (release_mode == False)
+    logging_default = (release_mode is False)
 
 # targets that do not support the DTLS build (SECURED=1 build option)
 targets_without_dtls_support = ['arduino']
 if ARGUMENTS.get('SECURED') == '1' and target_os in targets_without_dtls_support:
-    print "\nError: DTLS not supported on target %s, MUST build with SECURED=0\n" % (target_os)
-    Exit(1)
+    msg = "\nError: DTLS not supported on target '%s', MUST build with SECURED=0\n" % (target_os)
+    Exit(msg)
 
-######################################################################
-# Common build options (release, target os, target arch)
-######################################################################
+# targets that do not support multiple values for TARGET_TRANSPORT
 targets_disallow_multitransport = ['arduino']
 
-help_vars = Variables()
+# generate a list of unique targets: convert to set() for uniqueness,
+# then convert back to a list
+targetlist = list(set(x for l in host_target_map.values() for x in l))
 
-help_vars.Add('PROJECT_VERSION',
-              'The version of IoTivity',
-              project_version)
+######################################################################
+# Common build options
+######################################################################
 
-help_vars.Add(
+help_vars = Variables()
+help_vars.AddVariables(
+    ('PROJECT_VERSION',
+                 'The version of IoTivity',
+                 project_version),
     BoolVariable('VERBOSE',
                  'Show compilation',
-                 False))
-help_vars.Add(
+                 default=False),
     BoolVariable('RELEASE',
                  'Build for release?',
-                 True))  # set to 'no', 'false' or 0 for debug
-help_vars.Add(
+                 default=True),
     EnumVariable('TARGET_OS',
                  'Target platform',
-                 host,
-                 allowed_values=host_target_map[host]))
-
-help_vars.Add(
+                 default=host,
+                 allowed_values=targetlist),
     BoolVariable('WITH_RA',
                  'Build with Remote Access module',
-                 False))
-help_vars.Add(
+                 default=False),
     BoolVariable('WITH_TCP',
                  'Build with TCP adapter',
-                 False))
-help_vars.Add(
+                 default=False),
     BoolVariable('WITH_PROXY',
                  'Build with CoAP-HTTP Proxy',
-                 True))
-help_vars.Add(
+                 default=True),
     ListVariable('WITH_MQ',
                  'Build with MQ publisher/broker',
-                 'OFF',
-                 ['OFF', 'SUB', 'PUB', 'BROKER']))
-help_vars.Add(
+                 default='OFF',
+                 names=('OFF', 'SUB', 'PUB', 'BROKER')),
     BoolVariable('WITH_CLOUD',
                  'Build including AccountManager class and Cloud Client sample',
-                 False))
-help_vars.Add(
+                 default=False),
     ListVariable('RD_MODE',
                  'Resource Directory build mode',
-                 'CLIENT',
-                 ['CLIENT', 'SERVER']))
-help_vars.Add(
+                 default='CLIENT',
+                 names=('CLIENT', 'SERVER')),
     BoolVariable('SIMULATOR',
                  'Build with simulator module',
-                 False))
-help_vars.Add(
+                 default=False),
     BoolVariable('WITH_RA_IBB',
                  'Build with Remote Access module(workssys)',
-                 False))
-
-if target_os in targets_disallow_multitransport:
-    help_vars.Add(
-        ListVariable('TARGET_TRANSPORT',
-                     'Target transport',
-                     'IP',
-                     ['BT', 'BLE', 'IP', 'NFC']))
-else:
-    help_vars.Add(
-        ListVariable('TARGET_TRANSPORT',
-                     'Target transport',
-                     'ALL',
-                     ['ALL', 'BT', 'BLE', 'IP', 'NFC']))
-
-help_vars.Add(
+                 default=False),
     EnumVariable('TARGET_ARCH',
                  'Target architecture',
-                 default_arch,
-                 allowed_values=os_arch_map[target_os]))
-
-if target_os in targets_without_dtls_support:
-    help_vars.Add(
-        EnumVariable('SECURED',
-                     'Build with DTLS',
-                     '0',
-                     allowed_values=('0', '1')))
-else:
-
-    help_vars.Add(
-        EnumVariable('SECURED',
-                     'Build with DTLS',
-                     '1',
-                     allowed_values=('0', '1')))
-help_vars.Add(
+                 default=default_arch,
+                 allowed_values=os_arch_map[target_os]),
     EnumVariable('MULTIPLE_OWNER',
                  'Enable multiple owner',
-                 '1',
-                 allowed_values=('0', '1')))
-help_vars.Add(
+                 default='1',
+                 allowed_values=('0', '1')),
     EnumVariable('EXC_PROV_SUPPORT',
                  'Except OCPMAPI library(libocpmapi.so)',
-                 '0',
-                 allowed_values=('0', '1')))
-help_vars.Add(
+                 default='0',
+                 allowed_values=('0', '1')),
     EnumVariable('TEST',
                  'Run unit tests',
-                 '0',
-                 allowed_values=('0', '1')))
-help_vars.Add(
+                 default='0',
+                 allowed_values=('0', '1')),
     BoolVariable('LOGGING',
                  'Enable stack logging',
-                 logging_default))
-help_vars.Add(
+                 default=logging_default),
     EnumVariable('LOG_LEVEL',
                  'Enable stack logging level',
-                 'DEBUG',
-                 allowed_values=('DEBUG', 'INFO', 'ERROR', 'WARNING', 'FATAL')))
-help_vars.Add(
+                 default='DEBUG',
+                 allowed_values=('DEBUG', 'INFO', 'ERROR', 'WARNING', 'FATAL')),
     BoolVariable('UPLOAD',
-                 'Upload binary ? (For Arduino)',
-                 require_upload))
-help_vars.Add(
+                 'Upload binary? (For Arduino)',
+                 default=require_upload),
     EnumVariable('ROUTING',
                  'Enable routing',
-                 'EP',
-                 allowed_values=('GW', 'EP')))
-help_vars.Add(
+                 default='EP',
+                 allowed_values=('GW', 'EP')),
     EnumVariable('BUILD_SAMPLE',
                  'Build with sample',
-                 'ON',
-                 allowed_values=('ON', 'OFF')))
-help_vars.AddVariables(('DEVICE_NAME',
-                        'Network display name for device (For Arduino)',
-                        device_name,
-                        None,
-                        None), )
-help_vars.Add(
+                 default='ON',
+                 allowed_values=('ON', 'OFF')),
+    ('DEVICE_NAME',
+                 'Network display name for device (For Arduino)',
+                 device_name),
     PathVariable('ANDROID_NDK',
                  'Android NDK path',
-                 None,
-                 PathVariable.PathAccept))
-help_vars.Add(
+                 default=None,
+                 validator=PathVariable.PathAccept),
     PathVariable('ANDROID_HOME',
                  'Android SDK path',
-                 None,
-                 PathVariable.PathAccept))
-help_vars.Add(
+                 default=None,
+                 validator=PathVariable.PathAccept),
     PathVariable('ANDROID_GRADLE',
-                 'Gradle binary file',
-                 None,
-                 PathVariable.PathIsFile))
-help_vars.Add(
+                 'Gradle executable location',
+                 default=None,
+                 validator=PathVariable.PathIsFile),
     EnumVariable('WITH_UPSTREAM_LIBCOAP',
                  'Use latest stable version of LibCoAP downloaded from github',
-                 default_with_upstream_libcoap,
-                 allowed_values=('0', '1')))
-help_vars.Add(
+                 default=default_with_upstream_libcoap,
+                 allowed_values=('0', '1')),
     BoolVariable('WITH_ENV',
                  'Use compiler options from environment',
-                 False))
-help_vars.Add(
+                 default=False),
     BoolVariable('AUTOMATIC_UPDATE',
                  'Makes libcoap update automatically to the required versions if needed.',
-                 False))
+                 default=False),
+    BoolVariable('BUILD_JAVA',
+                 'Build Java bindings',
+                 default=False),
+    PathVariable('JAVA_HOME',
+                 'JDK directory',
+                 default=os.environ.get('JAVA_HOME'),
+                 validator=PathVariable.PathAccept),
+    EnumVariable('OIC_SUPPORT_TIZEN_TRACE',
+                 'Tizen Trace(T-trace) api availability',
+                 default='False',
+                 allowed_values=('True', 'False')),
+)
+
+######################################################################
+# Platform (build target) specific options
+######################################################################
+if target_os in targets_disallow_multitransport:
+    help_vars.Add(
+        EnumVariable('TARGET_TRANSPORT',
+                     'Target transport',
+                     default='IP',
+                     allowed_values=('BT', 'BLE', 'IP', 'NFC')))
+else:
+    help_vars.Add(
+        ListVariable('TARGET_TRANSPORT',
+                     'Target transport',
+                     default='ALL',
+                     names=('ALL', 'BT', 'BLE', 'IP', 'NFC')))
+
+if target_os in targets_without_dtls_support:
+    help_vars.Add(
+        EnumVariable('SECURED',
+                     'Build with DTLS',
+                     default='0',
+                     allowed_values=('0',)))
+else:
+    help_vars.Add(
+        EnumVariable('SECURED',
+                     'Build with DTLS',
+                     default='1',
+                     allowed_values=('0', '1')))
 
 if target_os == 'windows':
-    # For VS2013, MSVC_VERSION is '12.0'. For VS2015, MSVC_VERSION is '14.0'.
-    # Default value is None, meaning that SCons has to choose automatically a VS version.
+    # Builds differ based on Visual Studio version
+    #   For VS2013, MSVC_VERSION is '12.0'.
+    #   For VS2015, MSVC_VERSION is '14.0'.
+    #   For VS2017, MSVC_VERSION is '15.0'.
+    # Default value is None, which means SCons will pick
     help_vars.Add(
         EnumVariable('MSVC_VERSION',
                      'MSVC compiler version - Windows',
-                     None,
+                     default=None,
                      allowed_values=('12.0', '14.0')))
-    help_vars.Add(EnumVariable(
-                     'UWP_APP',
-                     'Build for a Universal Windows Platform (UWP) Application',
-                     '0',
+                     #TODO allowed_values=('12.0', '14.0', '15.0')))
+    help_vars.Add(
+        EnumVariable('UWP_APP',
+                     'Build a Universal Windows Platform (UWP) Application',
+                     default='0',
                      allowed_values=('0', '1')))
 
-help_vars.Add(
-    BoolVariable('BUILD_JAVA',
-                 'Build Java bindings',
-                 False))
-help_vars.Add(
-    PathVariable('JAVA_HOME',
-                 'JDK directory',
-                 os.environ.get('JAVA_HOME'),
-                 PathVariable.PathAccept))
-help_vars.Add(
-    EnumVariable('OIC_SUPPORT_TIZEN_TRACE',
-                 'Tizen Trace(T-trace) api availability',
-                 'False',
-                 allowed_values=('True', 'False')))
-
 AddOption(
     '--prefix',
     dest='prefix',
@@ -296,21 +276,24 @@ AddOption(
     help='installation prefix')
 
 ######################################################################
-# Platform(build target) specific options: SDK/NDK & toolchain
+# Platform (build target) specific options: SDK/NDK & toolchain
 ######################################################################
 targets_support_cc = ['linux', 'arduino', 'tizen']
 
 if target_os in targets_support_cc:
     # Set cross compile toolchain
     help_vars.Add('TC_PREFIX',
-                  "Toolchain prefix (Generally only be required for cross-compiling)",
-                  os.environ.get('TC_PREFIX'))
+                  "Toolchain prefix (Generally only required for cross-compiling)",
+                  default=None)
     help_vars.Add(
         PathVariable('TC_PATH',
-                     'Toolchain path (Generally only be required for cross-compiling)',
-                     os.environ.get('TC_PATH')))
+                     'Toolchain path (Generally only required for cross-compiling)',
+                     default=None,
+                     validator=PathVariable.PathAccept))
 
+######################################################################
 # this is where the setup of the construction envionment begins
+######################################################################
 if target_os in ['android', 'arduino']:
     # Android/Arduino always uses GNU compiler regardless of the host
     env = Environment(
@@ -353,7 +336,7 @@ if env.get('WITH_ENV'):
         print "using LDFLAGS/LINKFLAGS from environment: %s" % env['LINKFLAGS']
 
 # set quieter build messages unless verbose mode was requested
-if env.get('VERBOSE') == False:
+if not env.get('VERBOSE'):
     env['CCCOMSTR'] = "Compiling $TARGET"
     env['SHCCCOMSTR'] = "Compiling $TARGET"
     env['CXXCOMSTR'] = "Compiling $TARGET"
@@ -396,7 +379,7 @@ if target_os in ['yocto']:
 else:
     env['CONFIG_ENVIRONMENT_IMPORT'] = False
 
-if env['CONFIG_ENVIRONMENT_IMPORT'] == True:
+if env['CONFIG_ENVIRONMENT_IMPORT']:
     print "warning: importing some environment variables for OS: %s" % target_os
     for ev in [
         'PATH',
@@ -404,7 +387,7 @@ if env['CONFIG_ENVIRONMENT_IMPORT'] == True:
         'PKG_CONFIG_PATH',
         'PKG_CONFIG_SYSROOT_DIR'
     ]:
-        if os.environ.get(ev) != None:
+        if os.environ.get(ev) is not None:
             env['ENV'][ev] = os.environ.get(ev)
     if os.environ['LDFLAGS'] != None:
         env.AppendUnique(LINKFLAGS=Split(os.environ['LDFLAGS']))
@@ -435,13 +418,13 @@ def __set_dir(env, dir):
     #   env.get('BUILD_DIR')
     #
     if not os.path.exists(dir + '/SConstruct'):
-        print '''
+        msg = '''
 *************************************** Error *********************************
 * The directory (%s) seems not to be a buildable directory,
 * no SConstruct file found.
 *******************************************************************************
 ''' % dir
-        Exit(1)
+        Exit(msg)
 
     build_dir = dir + '/out/' + target_os + '/'
 
@@ -559,6 +542,7 @@ env.AddMethod(__installpcfile, 'UserInstallTargetPCFile')
 env.SetDir(env.GetLaunchDir())
 env['ROOT_DIR'] = env.GetLaunchDir() + '/..'
 
+# make 'env' available to all other build scripts to Import()
 Export('env')
 
 ####################################################################i#
@@ -678,8 +662,8 @@ if 'ALL' in target_transport:
 else:
     if ('BT' in target_transport):
         if (target_os == 'linux'):
-            print "CA Transport BT is not supported "
-            Exit(1)
+            msg = "CA Transport BT is not supported "
+            Exit(msg)
         else:
             env.AppendUnique(CPPDEFINES=['EDR_ADAPTER'])
     else:
@@ -701,8 +685,8 @@ else:
         ]):
             env.AppendUnique(CPPDEFINES=['TCP_ADAPTER', 'WITH_TCP'])
         else:
-            print "CA Transport TCP is not supported "
-            Exit(1)
+            msg = "CA Transport TCP is not supported "
+            Exit(msg)
     else:
         env.AppendUnique(CPPDEFINES=['NO_TCP_ADAPTER'])
 
@@ -710,8 +694,8 @@ else:
         if (target_os == 'android'):
             env.AppendUnique(CPPDEFINES=['NFC_ADAPTER'])
         else:
-            print "CA Transport NFC is not supported "
-            Exit(1)
+            msg = "CA Transport NFC is not supported "
+            Exit(msg)
     else:
         env.AppendUnique(CPPDEFINES=['NO_NFC_ADAPTER'])
 
@@ -724,7 +708,7 @@ if ('PUB' in with_mq):
 if ('BROKER' in with_mq):
     env.AppendUnique(CPPDEFINES=['MQ_BROKER', 'WITH_MQ'])
 
-env.AppendUnique(CPPDEFINES = {'OC_LOG_LEVEL' : env.get('LOG_LEVEL')})
+env.AppendUnique(CPPDEFINES={'OC_LOG_LEVEL': env.get('LOG_LEVEL')})
 
 if env.get('LOGGING'):
     env.AppendUnique(CPPDEFINES=['TB_LOG'])
@@ -750,15 +734,15 @@ env.SConscript('external_builders.scons')
 ######################################################################
 if target_os == "yocto":
     '''
-    This code injects Yocto cross-compilation tools+flags into scons'
-    build environment in order to invoke the relevant tools while
+    This code injects Yocto cross-compilation tools+flags into the scons
+    construction environment in order to invoke the relevant tools while
     performing a build.
     '''
     import os.path
     try:
         CC = os.environ['CC']
         target_prefix = CC.split()[0]
-        target_prefix = target_prefix[:len(target_prefix) - 3]
+        target_prefix = target_prefix[:-3]
         tools = {
             "CC": target_prefix + "gcc",
             "CXX": target_prefix + "g++",
@@ -781,10 +765,10 @@ if target_os == "yocto":
                     if os.path.isfile(os.path.join(path, tools[tool])):
                         env[tool] = os.path.join(path, os.environ[tool])
                         break
-        env['CROSS_COMPILE'] = target_prefix[:len(target_prefix) - 1]
+        env['CROSS_COMPILE'] = target_prefix[:-1]
     except:
-        print "ERROR in Yocto cross-toolchain environment"
-        Exit(1)
+        msg = "ERROR in Yocto cross-toolchain environment"
+        Exit(msg)
     '''
     Now reset TARGET_OS to linux so that all linux specific build configurations
     hereupon apply for the entirety of the build process.
index eeae541..70e537a 100644 (file)
@@ -2,34 +2,33 @@
 # Add external Pseudo-Builders
 #
 # Some methods are added to manage external packages:
-#    'PrepareLib': Checks the existence of an external library, if it
-# doesn't exist, calls the script user provided to download(if required)
-# and build the source code of the external library or notify user to
-# install the library.
+#   'PrepareLib': Make a library ready to use.
 #   'Download': Download package from specify URL
 #   'UnpackAll': Unpack the package
-#   'Configure': Execute specify script(configure, bootstrap etc)
+#   'Configure': Execute specify script (configure, bootstrap etc)
 #   'InstallHeadFile': Install head files
-#   'InstallLib': Install library binaries(.so, .a etc)
+#   'InstallLib': Install library binaries (.so, .a etc)
 #
 # for more on Pseudo-Builders see scons offical documentation
 # 'Pseudo-Builders: the AddMethod function'
 ##
-import os, subprocess
-import urllib2, urlparse
+import os
+import subprocess
+import urllib2
 import SCons.Errors
 
 Import('env')
+src_dir = env.get('SRC_DIR')
 
-
-# Check whether a library exists, if not, notify user to install it or try to
-# download the source code and build it
+# Prepare a library for use.
+# Check whether it exists
+#  if not try to download the source code and build it
+#  if not possible, give the user a hint about downloading
 # @param libname - the name of the library try to prepare
-# @param lib - the lib(.so, .a etc) to check (a library may include more then
-#      one lib, e.g. boost, includes boost_thread, boost_system ...
-# @param path - the directory of the library building script, if it's not set,
-#            by default, it's <src_dir>/extlibs/<libname>/
-# @param script - the building script, by default, it's 'SConscript'
+# @param lib - the lib (.so, .a etc) to check (a library may include more then
+#      one lib, e.g. boost includes boost_thread, boost_system ...)
+# @param path - path to build script for library. Default is <src_dir>/extlibs/<libname>/
+# @param script - build script for this library. Default is SConscript
 #
 def __prepare_lib(ienv, libname, lib=None, path=None, script=None):
     p_env = ienv.Clone(LIBS=[])
@@ -44,9 +43,9 @@ def __prepare_lib(ienv, libname, lib=None, path=None, script=None):
         if path:
             dir = path
         else:
-            dir = os.path.join(env.get('SRC_DIR'), 'extlibs', libname)
+            dir = os.path.join(src_dir, 'extlibs', libname)
 
-        # Execute the script to download(if required) and build source code
+        # Execute the script to download (if required) and build source code
         if script:
             st = os.path.join(dir, script)
         else:
@@ -56,16 +55,16 @@ 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
+                msg = 'Library (%s) not found, please intall it, exit ...' % libname
             else:
-                print 'Library (%s) not found and cannot find the scons script (%s), exit ...' % (
+                msg = 'Library (%s) not found and cannot find the scons script (%s), exit ...' % (
                     libname, st)
-            Exit(1)
+            Exit(msg)
 
     conf.Finish()
 
 
-# Run configure command (usually it's done before build a library)
+# Run configure command (usually done before building a library)
 def __configure(env, cwd, cmd):
     print "Configuring using [%s/%s] ..." % (cwd, cmd)
     # build it now (we need the shell, because some programs need it)
@@ -98,15 +97,14 @@ def __download(ienv, target, url):
 def __install_head_file(ienv, file):
     return ienv.Install(
         os.path.join(
-            env.get('SRC_DIR'), 'dep', target_os, target_arch, 'usr',
-            'include'), file)
+            src_dir, 'dep', target_os, target_arch, 'usr', 'include'), file)
 
 
 # Install library binaries to <src_dir>/deps/<target_os>/lib/<arch>
 def __install_lib(ienv, lib):
     return ienv.Install(
         os.path.join(
-            env.get('SRC_DIR'), 'dep', target_os, target_arch, 'usr', 'lib'),
+            src_dir, 'dep', target_os, target_arch, 'usr', 'lib'),
         lib)
 
 
index cbf2720..9088e93 100644 (file)
@@ -16,6 +16,8 @@ Import('env')
 target_os = env.get('TARGET_OS')
 target_arch = env.get('TARGET_ARCH')
 rd_mode = env.get('RD_MODE')
+src_dir = env.get('SRC_DIR')
+java_home = env.get('JAVA_HOME')
 
 # for android, doesn't distinguish 'armeabi-v7a-hard' and 'armeabi-v7a' library
 if target_os == 'android':
@@ -27,18 +29,18 @@ if target_os == 'darwin':
     env.AppendUnique(CPPPATH = ['/usr/local/include'])
     env.AppendUnique(LIBPATH = ['/usr/local/lib'])
 
-if env.get('BUILD_JAVA') == True and target_os != 'android':
-    if env.get('JAVA_HOME') != None:
+if env.get('BUILD_JAVA') is True and target_os != 'android':
+    if java_home is not None:
         env.AppendUnique(CPPDEFINES=['__JAVA__'])
         if target_os in ['windows', 'winrt']:
             env.AppendUnique(CPPPATH=[
-            env.get('JAVA_HOME') + '/include',
-            env.get('JAVA_HOME') + '/include/win32'
+            java_home + '/include',
+            java_home + '/include/win32'
             ])
         else:
             env.AppendUnique(CPPPATH=[
-            env.get('JAVA_HOME') + '/include',
-            env.get('JAVA_HOME') + '/include/' + target_os
+            java_home + '/include',
+            java_home + '/include/' + target_os
         ])
     else:
         msg = "Error: BUILD_JAVA requires JAVA_HOME to be set for target '%s'" % target_os
@@ -47,22 +49,22 @@ if env.get('BUILD_JAVA') == True and target_os != 'android':
 # External library include files are in <src_dir>/deps/<target_os>/include
 # the library binaries are in <src_dir>/deps/<target_os>/lib/<arch>
 if target_os not in ['windows']:
-    env.AppendUnique(CPPPATH = [os.path.join(env.get('SRC_DIR'), 'deps', target_os, 'include')])
-    env.AppendUnique(LIBPATH = [os.path.join(env.get('SRC_DIR'), 'deps', target_os, 'lib', target_arch)])
+    env.AppendUnique(CPPPATH = [os.path.join(src_dir, 'deps', target_os, 'include')])
+    env.AppendUnique(LIBPATH = [os.path.join(src_dir, 'deps', target_os, 'lib', target_arch)])
 
 # tinycbor build/fetch
-SConscript(os.path.join(env.get('SRC_DIR'), 'extlibs', 'tinycbor', 'SConscript'))
+SConscript(os.path.join(src_dir, 'extlibs', 'tinycbor', 'SConscript'))
 
 #cJSON lib
-SConscript(os.path.join(env.get('SRC_DIR'), 'extlibs', 'cjson', 'SConscript'))
+SConscript(os.path.join(src_dir, 'extlibs', 'cjson', 'SConscript'))
 
 with_ra = env.get('WITH_RA')
 if with_ra:
-    SConscript(os.path.join(env.get('SRC_DIR'), 'extlibs', 'raxmpp', 'SConscript'))
+    SConscript(os.path.join(src_dir, 'extlibs', 'raxmpp', 'SConscript'))
 
 with_ra_ibb = env.get('WITH_RA_IBB')
 if with_ra_ibb:
-    SConscript(os.path.join(env.get('SRC_DIR'), 'extlibs', 'wksxmppxep', 'SConscript'))
+    SConscript(os.path.join(src_dir, 'extlibs', 'wksxmppxep', 'SConscript'))
 
 if env.get('SECURED') == '1' or 'SERVER' in rd_mode:
     if target_os not in ['linux', 'tizen']:
index 331482a..5632296 100644 (file)
@@ -6,7 +6,7 @@
 import os
 Import('env')
 
-print "Reading linux configuration script"
+src_dir = env.get('SRC_DIR')
 
 help_vars = Variables()
 if env.get('BUILD_JAVA') == True:
@@ -15,8 +15,8 @@ if env.get('BUILD_JAVA') == True:
         help_vars.Add(
             PathVariable('ANDROID_GRADLE',
                          'Android Gradle directory',
-                         os.path.join(
-                             env.get('SRC_DIR'), 'extlibs', 'android',
+                         default=os.path.join(
+                             src_dir, 'extlibs', 'android',
                              'gradle', 'gradle-2.2.1/bin/gradle')))
 
     if env.get('ANDROID_GRADLE'):
@@ -24,14 +24,13 @@ if env.get('BUILD_JAVA') == True:
     else:
         print '''
 *************************************** Info **********************************
-*    Android Gradle path isn't set, the default will be used. You can set     *
-* environment variable ANDROID_GRADLE or add it in command line as:           *
-*      # scons ANDROID_GRADLE=<path to android GRADLE> ...                    *
+* Android Gradle path is not set, the default will be used. You can set
+* environment variable ANDROID_GRADLE or add it on the command line as:
+*      # scons ANDROID_GRADLE=<path to android GRADLE> ...
 *******************************************************************************
 '''
         android_gradle = os.path.join(
-            env.get('SRC_DIR'), 'extlibs', 'android', 'gradle', 'gradle-2.2.1',
-            'bin', 'gradle')
+            src_dir, 'extlibs', 'android', 'gradle', 'gradle-2.2.1', 'bin', 'gradle')
 
 help_vars.Update(env)
 Help(help_vars.GenerateHelpText(env))
index fd167e9..cf47d97 100644 (file)
@@ -6,6 +6,9 @@ import os
 import winreg
 import platform
 
+src_dir = env.get('SRC_DIR')
+build_dir = env.get('BUILD_DIR')
+
 def OpenRegKey(env, key, sub_key, reg_view_64bit=False):
     # Default access
     reg_access_mask = winreg.KEY_READ
@@ -104,7 +107,12 @@ help_vars = Variables()
 if env.get('BUILD_JAVA') == True:
     if not env.get('ANDROID_GRADLE'):
         SConscript('../../extlibs/android/gradle/SConscript')
-        help_vars.Add(PathVariable('ANDROID_GRADLE', 'Android Gradle directory', os.path.join(env.get('SRC_DIR'), 'extlibs', 'android', 'gradle', 'gradle-2.2.1/bin/gradle')))
+        help_vars.Add(
+            PathVariable('ANDROID_GRADLE',
+                         'Android Gradle directory',
+                         default=os.path.join(
+                             src_dir, 'extlibs', 'android',
+                             'gradle', 'gradle-2.2.1/bin/gradle')))
 
     if env.get('ANDROID_GRADLE'):
         android_gradle = env.get('ANDROID_GRADLE')
@@ -112,12 +120,13 @@ if env.get('BUILD_JAVA') == True:
         print(
 '''
 *************************************** Info **********************************
-*    Android Gradle path isn't set, the default will be used. You can set     *
-* environment variable ANDROID_GRADLE or add it in command line as:           *
-*      # scons ANDROID_GRADLE=<path to android GRADLE> ...                    *
+* Android Gradle path is not set, the default will be used. You can set
+* environment variable ANDROID_GRADLE or add it on the command line as:
+*      # scons ANDROID_GRADLE=<path to android GRADLE> ...
 *******************************************************************************
 ''')
-        android_gradle = os.path.join(env.get('SRC_DIR'), 'extlibs', 'android', 'gradle', 'gradle-2.2.1', 'bin', 'gradle')
+        android_gradle = os.path.join(
+            src_dir, 'extlibs', 'android', 'gradle', 'gradle-2.2.1', 'bin', 'gradle')
 
 help_vars.Update(env)
 Help(help_vars.GenerateHelpText(env))
@@ -142,11 +151,12 @@ if env.get('UWP_APP') == '1':
 if env['CC'] == 'cl':
     if env.get('UWP_APP') == '1':
         # Currently only supports VS2015 (14.0)
+        # TODO add VS2017 (15.0)
         supported_uwp_msvc_versions = ['14.0']
         # If MSVC_VERSION is not supported for UWP, exit on error
         if env.get('MSVC_VERSION') not in supported_uwp_msvc_versions:
-            print '\nError: Trying to Build UWP binaries with unsupported Visual Studio version\n'
-            Exit(1)
+            msg = '\nError: Trying to Build UWP binaries with unsupported Visual Studio version\n'
+            Exit(msg)
 
     #  - warning C4133: incompatible type conversion
     env.AppendUnique(CCFLAGS=['/we4133'])
@@ -195,11 +205,13 @@ if env['CC'] == 'cl':
     # InstallTarget() for this static LIB, but didn't finish yet. That behavior results
     # in linker errors. Work around this issue by linking with the source of InstallTarget(),
     # rather than the target.
-    env.PrependUnique(LIBPATH=[os.path.join(env.get('BUILD_DIR'), 'resource', 'src')])
-    env.PrependUnique(LIBPATH=[os.path.join(env.get('BUILD_DIR'), 'resource', 'c_common', 'windows')])
-    env.PrependUnique(LIBPATH=[os.path.join(env.get('BUILD_DIR'), 'resource', 'oc_logger')])
-    env.PrependUnique(LIBPATH=[os.path.join(env.get('BUILD_DIR'), 'resource', 'csdk', 'resource-directory')])
-    env.PrependUnique(LIBPATH=['#extlibs/mbedtls'])
+    env.PrependUnique(LIBPATH=[
+        os.path.join(build_dir, 'resource', 'src'),
+        os.path.join(build_dir, 'resource', 'c_common', 'windows'),
+        os.path.join(build_dir, 'resource', 'oc_logger'),
+        os.path.join(build_dir, 'resource', 'csdk', 'resource-directory'),
+        '#extlibs/mbedtls',
+    ])
 
     env['PDB'] = '${TARGET.base}.pdb'
     env.Append(LINKFLAGS=['/PDB:${TARGET.base}.pdb'])
@@ -231,5 +243,5 @@ if env['CC'] == 'cl':
         env.AppendUnique(LIBS=['WindowsApp', 'bcrypt', 'ws2_32', 'iphlpapi', 'crypt32'])
 
 elif env['CC'] == 'gcc':
-    print "\nError: gcc not supported on Windows.  Use Visual Studio!\n"
-    Exit(1)
+    msg = "\nError: gcc not supported on Windows.  Use Visual Studio!\n"
+    Exit(msg)