Do not hardcode path separators in build paths.
authorOssama Othman <ossama.othman@intel.com>
Mon, 9 Mar 2015 23:35:07 +0000 (16:35 -0700)
committerPatrick Lankswert <patrick.lankswert@intel.com>
Tue, 10 Mar 2015 22:12:46 +0000 (22:12 +0000)
It is conceivable that iotivity may be built on platforms where '/'
is not a suitable directory separator.  When constructing paths use
Python's os.path.join() function instead of constructing paths by
concatenating strings with '/' in them.

Change-Id: I7c435bd454339f4df9a8e41250e705aa98a6d09f
Signed-off-by: Ossama Othman <ossama.othman@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/456
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Erich Keane <erich.keane@intel.com>
Reviewed-by: Patrick Lankswert <patrick.lankswert@intel.com>
SConstruct
build_common/SConscript
build_common/external_libs.scons
extlibs/boost/SConscript
extlibs/cereal/SConscript

index 0a82963..aeaaf8e 100644 (file)
@@ -3,6 +3,8 @@
 #
 ##
 
+import os
+
 # Load common build config
 SConscript('build_common/SConscript')
 
@@ -15,8 +17,8 @@ else:
        # Prepare libraries
        env.PrepareLib('cereal')
        env.PrepareLib('expat')
-       env.PrepareLib('boost', 'boost_thread', env.get('SRC_DIR') + '/extlibs/boost/')
-       env.PrepareLib('boost', 'boost_system', env.get('SRC_DIR') + '/extlibs/boost/')
+       env.PrepareLib('boost', 'boost_thread', os.path.join(env.get('SRC_DIR'), 'extlibs', 'boost'))
+       env.PrepareLib('boost', 'boost_system', os.path.join(env.get('SRC_DIR'), 'extlibs', 'boost'))
 
 # By default, src_dir is current dir, the build_dir is:
 #     ./out/<target_os>/<target_arch>/<release or debug>/
@@ -30,10 +32,10 @@ else:
 build_dir = env.get('BUILD_DIR')
 
 # Build 'resource' sub-project
-SConscript(build_dir + 'resource/SConscript')
+SConscript(os.path.join(build_dir, 'resource', 'SConscript'))
 
 # Build 'service' sub-project
-SConscript(build_dir + 'service/SConscript')
+SConscript(os.path.join(build_dir, 'service', 'SConscript'))
 
 # Append targets information to the help information, to see help info, execute command line:
 #     $ scon [options] -h
index 2670070..d2b3859 100644 (file)
@@ -96,7 +96,7 @@ if target_os in targets_support_cc:
 
        if tc_path:
                env.PrependENVPath('PATH', tc_path)
-               sys_root = os.path.abspath(tc_path + '/../')
+               sys_root = os.path.abspath(os.path.join(tc_path, '..'))
                env.AppendUnique(CCFLAGS = ['--sysroot=' + sys_root])
                env.AppendUnique(LINKFLAGS = ['--sysroot=' + sys_root])
 
@@ -115,7 +115,7 @@ env.SConscriptChdir(1)
 #   env.get('BUILD_DIR')
 
 def __set_dir(env, dir):
-       if not os.path.exists(dir + '/SConstruct'):
+       if not os.path.exists(os.path.join(dir, 'SConstruct')):
                print '''
 *************************************** Error *********************************
 * The directory(%s) seems isn't a source code directory, no SConstruct file is
@@ -124,10 +124,11 @@ def __set_dir(env, dir):
 ''' % dir
                Exit(1)
 
+        build_dir = os.path.join(dir, 'out', target_os, target_arch)
        if env.get('RELEASE'):
-               build_dir = dir + '/out/' + target_os + '/' + target_arch + '/release/'
+               build_dir = os.path.join(build_dir, 'release')
        else:
-               build_dir = dir + '/out/' + target_os + '/' + target_arch + '/debug/'
+               build_dir = os.path.join(build_dir, 'debug')
        env.VariantDir(build_dir, dir, duplicate=0)
 
        env.Replace(BUILD_DIR = build_dir)
index 44994d5..322767b 100644 (file)
@@ -40,8 +40,8 @@ if target_os == 'darwin':
 
 # External library include files are in <src_dir>/deps/<target_os>/include
 # the library binaries are in <src_dir>/deps/<target_os>/lib/<arch>
-env.AppendUnique(CPPPATH = [env.get('SRC_DIR') + '/deps/' + target_os + '/include'])
-env.AppendUnique(LIBPATH = [env.get('SRC_DIR') + '/deps/' + target_os + '/lib/' + target_arch])
+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)])
 
 # Check whether a library exists, if not, notify user to install it or try to
 # download the source code and build it
@@ -65,13 +65,13 @@ def __prepare_lib(ienv, libname, lib = None, path = None, script = None):
                if path:
                        dir = path
                else:
-                       dir = env.get('SRC_DIR') + '/extlibs/' + libname
+                       dir = os.path.join(env.get('SRC_DIR'), 'extlibs', libname)
 
                # Execute the script to download(if required) and build source code
                if script:
-                       st = dir + '/' + script
+                       st = os.path.join(dir, script)
                else:
-                       st = dir + '/SConscript'
+                       st = os.path.join(dir, 'SConscript')
 
                if os.path.exists(st):
                        SConscript(st)
@@ -113,11 +113,11 @@ def __download(ienv, target, url) :
 
 # Install header file(s) to <src_dir>/deps/<target_os>/include
 def __install_head_file(ienv, file):
-               return ienv.Install(env.get('SRC_DIR') + '/deps/' + target_os + '/include', file)
+               return ienv.Install(os.path.join(env.get('SRC_DIR'), 'deps', target_os, 'include'), file)
 
 # Install library binaries to <src_dir>/deps/<target_os>/lib/<arch>
 def __install_lib(ienv, lib):
-               return ienv.Install(env.get('SRC_DIR') + '/deps/' + target_os + '/lib/' + target_arch, lib)
+               return ienv.Install(os.path.join(env.get('SRC_DIR'), 'deps', target_os, 'lib', target_arch), lib)
 
 SConscript('tools/UnpackAll.py')
 
index e9ad92c..751cbb6 100644 (file)
@@ -73,7 +73,7 @@ except ValueError:
        pass
 
 # Write a user-config for this variant
-user_config_name = cwd+os.sep+'tools'+os.sep+'build'+os.sep+'src'+os.sep+'user-config.jam'
+user_config_name = os.path.join(cwd, 'tools', 'build', 'src', 'user-config.jam')
 user_config_file = open(user_config_name, 'w')
 user_config_file.write('import os ;\n')
 user_config_file.write('using gcc :')
@@ -99,9 +99,9 @@ user_config_file.close();
 
 # Ensure that the toolchain is in the PATH
 penv = os.environ.copy()
-penv["PATH"] = tool_path+":" + penv["PATH"]
+penv["PATH"] = tool_path + ":" + penv["PATH"]
 
-build_path = 'build' + os.sep + target_os + os.sep + target_arch
+build_path = os.path.join('build', target_os, target_arch)
 
 cmd.append('-q')
 cmd.append('target-os=linux')
@@ -125,8 +125,9 @@ if handle.wait() <> 0 :
        raise SCons.Errors.BuildError( "Building boost [%s] on the source [%s]" % (cmd, boost_b2_name) )
 
 # Use Copy instead of InstallXXX to make sure boost is installed immediately
-Execute(Copy(env.get('SRC_DIR') + '/deps/' + target_os + '/include',
-       boost_base_name + os.sep + build_path + os.sep + 'install_tmp' + os.sep + 'include'))
+Execute(Copy(os.path.join(env.get('SRC_DIR'), 'deps', target_os, 'include'),
+       os.path.join(boost_base_name, build_path, 'install_tmp', 'include')))
+
+Execute(Copy(os.path.join(env.get('SRC_DIR'), 'deps', target_os, 'lib', target_arch),
+       os.path.join(boost_base_name, build_path, 'install_tmp', 'lib')))
 
-Execute(Copy(env.get('SRC_DIR') + '/deps/' + target_os + '/lib/' + target_arch,
-       boost_base_name + os.sep + build_path + os.sep + 'install_tmp' + os.sep + 'lib'))
index 6945131..946a483 100644 (file)
@@ -13,8 +13,8 @@ src_dir = env.get('SRC_DIR')
 # library management rule, cereal should be put in extlibs/cereal/cereal.
 # jenkins of gerrit server, still follow the old, to avoid jenkins fail
 # both places are handled.
-old = src_dir + '/extlibs/cereal/include'
-cur = src_dir + '/extlibs/cereal/cereal/include'
+old = os.path.join(src_dir, 'extlibs', 'cereal', 'include')
+cur = os.path.join(src_dir, 'extlibs', 'cereal', 'cereal', 'include')
 
 # check 'cereal' library, if it doesn't exits, ask user to download it
 if not os.path.exists(old) and not os.path.exists(cur):