@@ -37,13 +37,16 @@ import site
3737site .addsitedir (os .path .dirname (__file__ ))
3838import swift_test
3939
40+ def make_path (* args ):
41+ return os .path .normpath (os .path .join (* args ))
42+
4043#
4144# Helper functions.
4245#
4346
4447def darwin_get_sdk_version (sdk_path ):
45- system_version_plist_path = os . path . join (
46- sdk_path , "System" , "Library" , "CoreServices" , "SystemVersion.plist" )
48+ system_version_plist_path = make_path ( sdk_path , "System" , "Library" ,
49+ "CoreServices" , "SystemVersion.plist" )
4750 name = subprocess .check_output (
4851 ["defaults" , "read" , system_version_plist_path ,
4952 "ProductName" ]).rstrip ()
@@ -194,7 +197,7 @@ if swift_obj_root is not None:
194197 append_to_env_path (llvm_tools_dir )
195198
196199 build_mode = lit_config .params .get ('build_mode' , '' )
197- append_to_env_path (os . path . join (swift_obj_root , build_mode , 'bin' ))
200+ append_to_env_path (make_path (swift_obj_root , build_mode , 'bin' ))
198201
199202native_llvm_tools_path = lit_config .params .get ('native_llvm_tools_path' )
200203if native_llvm_tools_path is not None :
@@ -269,21 +272,21 @@ config.complete_test = inferSwiftBinary('complete-test')
269272config .swift_api_digester = inferSwiftBinary ('swift-api-digester' )
270273config .swift_refactor = inferSwiftBinary ('swift-refactor' )
271274
272- config .swift_utils = os . path . join (config .swift_src_root , 'utils' )
273- config .line_directive = os . path . join (config .swift_utils , 'line-directive' )
274- config .gyb = os . path . join (config .swift_utils , 'gyb' )
275- config .rth = os . path . join (config .swift_utils , 'rth' ) # Resilience test helper
276- config .scale_test = os . path . join (config .swift_utils , 'scale-test' )
277- config .PathSanitizingFileCheck = os . path . join (config .swift_utils , 'PathSanitizingFileCheck' )
278- config .swift_lib_dir = os . path . join ( os . path . dirname ( os . path . dirname ( config . swift )) , 'lib' )
279- config .round_trip_syntax_test = os . path . join (config .swift_utils , 'round-trip-syntax-test' )
275+ config .swift_utils = make_path (config .swift_src_root , 'utils' )
276+ config .line_directive = make_path (config .swift_utils , 'line-directive' )
277+ config .gyb = make_path (config .swift_utils , 'gyb' )
278+ config .rth = make_path (config .swift_utils , 'rth' ) # Resilience test helper
279+ config .scale_test = make_path (config .swift_utils , 'scale-test' )
280+ config .PathSanitizingFileCheck = make_path (config .swift_utils , 'PathSanitizingFileCheck' )
281+ config .swift_lib_dir = make_path ( config . swift , '..' , '..' , 'lib' )
282+ config .round_trip_syntax_test = make_path (config .swift_utils , 'round-trip-syntax-test' )
280283
281284# Find the resource directory. Assume it's near the swift compiler if not set.
282285test_resource_dir = lit_config .params .get ('test_resource_dir' )
283286if test_resource_dir :
284287 resource_dir_opt = ("-resource-dir %s" % test_resource_dir )
285288else :
286- test_resource_dir = os . path . join (config .swift_lib_dir , 'swift' )
289+ test_resource_dir = make_path (config .swift_lib_dir , 'swift' )
287290 resource_dir_opt = ""
288291stdlib_resource_dir_opt = resource_dir_opt
289292sourcekitd_framework_dir = config .swift_lib_dir
@@ -300,8 +303,8 @@ test_sdk_overlay_dir = lit_config.params.get('test_sdk_overlay_dir', None)
300303if test_sdk_overlay_dir is not None :
301304 config .available_features .add ('sdk_overlay' )
302305
303- sdk_overlay_dir_opt = ("-I %s" % os . path . join (test_sdk_overlay_dir , run_cpu ))
304- sdk_overlay_link_path_dir = os . path . join (test_sdk_overlay_dir , run_cpu )
306+ sdk_overlay_dir_opt = ("-I %s" % make_path (test_sdk_overlay_dir , run_cpu ))
307+ sdk_overlay_link_path_dir = make_path (test_sdk_overlay_dir , run_cpu )
305308 sdk_overlay_link_path = ("-L %s" % sdk_overlay_link_path_dir )
306309 sdk_overlay_linker_opt = (
307310 "-L %s -Xlinker -rpath -Xlinker %s" %
@@ -326,14 +329,14 @@ config.swift_frontend_test_options = os.environ.get('SWIFT_FRONTEND_TEST_OPTIONS
326329config .swift_driver_test_options = os .environ .get ('SWIFT_DRIVER_TEST_OPTIONS' , '' )
327330config .sil_test_options = os .environ .get ('SIL_TEST_OPTIONS' , '' )
328331
329- clang_module_cache_path = os . path . join (config .swift_test_results_dir , "clang-module-cache" )
332+ clang_module_cache_path = make_path (config .swift_test_results_dir , "clang-module-cache" )
330333shutil .rmtree (clang_module_cache_path , ignore_errors = True )
331334mcp_opt = "-module-cache-path %r" % clang_module_cache_path
332335clang_mcp_opt = "-fmodules-cache-path=%r" % clang_module_cache_path
333336lit_config .note ("Using Clang module cache: " + clang_module_cache_path )
334337lit_config .note ("Using test results dir: " + config .swift_test_results_dir )
335338
336- completion_cache_path = os . path . join (config .swift_test_results_dir , "completion-cache" )
339+ completion_cache_path = make_path (config .swift_test_results_dir , "completion-cache" )
337340shutil .rmtree (completion_cache_path , ignore_errors = True )
338341ccp_opt = "-completion-cache-path %r" % completion_cache_path
339342lit_config .note ("Using code completion cache: " + completion_cache_path )
@@ -367,8 +370,7 @@ config.substitutions.append(
367370 "%r -frontend %s -disable-objc-attr-requires-foundation-module %s %s"
368371 % (config .swift , mcp_opt , config .swift_test_options , config .swift_frontend_test_options )) )
369372
370- config .clang_include_dir = \
371- os .path .join (os .path .dirname (os .path .dirname (config .swift )), 'include' )
373+ config .clang_include_dir = make_path (config .swift , '..' , '..' , 'include' )
372374config .substitutions .append ( ('%clang-include-dir' , config .clang_include_dir ) )
373375
374376# Use this to build the basic set of Objective-C overlays.
@@ -380,15 +382,15 @@ config.substitutions.append(
380382
381383# FIXME: BEGIN -enable-source-import hackaround
382384config .substitutions .append (('%clang-importer-sdk-path' ,
383- '%r' % (os . path . join (config .test_source_root , 'Inputs' , 'clang-importer-sdk' ))))
385+ '%r' % (make_path (config .test_source_root , 'Inputs' , 'clang-importer-sdk' ))))
384386
385387config .substitutions .append (('%clang-importer-sdk-nosource' ,
386- '-sdk %r' % (os . path . join (config .test_source_root , 'Inputs' , 'clang-importer-sdk' ))))
388+ '-sdk %r' % (make_path (config .test_source_root , 'Inputs' , 'clang-importer-sdk' ))))
387389# FIXME: END -enable-source-import hackaround
388390
389391config .substitutions .append (('%clang-importer-sdk' ,
390- '-enable-source-import -sdk %r -I %r ' % (os . path . join (config .test_source_root , 'Inputs' , 'clang-importer-sdk' ),
391- os . path . join (config .test_source_root , 'Inputs' , 'clang-importer-sdk' , 'swift-modules' ))))
392+ '-enable-source-import -sdk %r -I %r ' % (make_path (config .test_source_root , 'Inputs' , 'clang-importer-sdk' ),
393+ make_path (config .test_source_root , 'Inputs' , 'clang-importer-sdk' , 'swift-modules' ))))
392394
393395config .substitutions .append ( ('%clang_apinotes' ,
394396 "%r -cc1apinotes" %
@@ -567,8 +569,8 @@ if run_vendor == 'apple':
567569 xcrun_prefix = (
568570 "xcrun --toolchain %s --sdk %s" %
569571 (config .darwin_xcrun_toolchain , config .variant_sdk ))
570- extra_frameworks_dir = os . path . join (config .variant_sdk ,
571- ".." , ".." , ".." , "Developer" , "Library" , "Frameworks" )
572+ extra_frameworks_dir = make_path (config .variant_sdk , ".." , ".." , ".." ,
573+ "Developer" , "Library" , "Frameworks" )
572574 target_options = (
573575 "-target %s %s %s" %
574576 (config .variant_triple , resource_dir_opt , mcp_opt ))
@@ -711,9 +713,7 @@ if run_vendor == 'apple':
711713 (sw_vers_name , sw_vers_vers , sw_vers_build ))
712714
713715 config .target_sdk_name = xcrun_sdk_name
714- config .target_ld = (
715- "%s ld -L%s" %
716- (xcrun_prefix , os .path .join (test_resource_dir , config .target_sdk_name )))
716+ config .target_ld = "%s ld -L%r" % (xcrun_prefix , make_path (test_resource_dir , config .target_sdk_name ))
717717 config .target_swift_frontend = (
718718 "%s -frontend %s -sdk %s %s %s" %
719719 (config .swiftc , target_options , config .variant_sdk ,
@@ -826,9 +826,7 @@ elif run_os in ['linux-gnu', 'linux-gnueabihf', 'freebsd', 'windows-cygnus', 'wi
826826 config .target_clang = (
827827 "clang++ -target %s %s" %
828828 (config .variant_triple , clang_mcp_opt ))
829- config .target_ld = (
830- "ld -L%s" %
831- (os .path .join (test_resource_dir , config .target_sdk_name )))
829+ config .target_ld = "ld -L%r" % (make_path (test_resource_dir , config .target_sdk_name ))
832830elif run_os == 'linux-androideabi' :
833831 lit_config .note ("Testing Android " + config .variant_triple )
834832 config .target_object_format = "elf"
@@ -837,16 +835,15 @@ elif run_os == 'linux-androideabi':
837835 config .target_swift_autolink_extract = inferSwiftBinary ("swift-autolink-extract" )
838836 config .target_sdk_name = "android"
839837 android_linker_opt = "-L {libcxx} -L {libgcc}" .format (
840- libcxx = os .path .join (config .android_ndk_path ,
841- "sources" , "cxx-stl" , "llvm-libc++" , "libs" ,
842- "armeabi-v7a" ),
843- libgcc = os .path .join (config .android_ndk_path ,
844- "toolchains" ,
845- "arm-linux-androideabi-{}" .format (
846- config .android_ndk_gcc_version ),
847- "prebuilt" , "linux-x86_64" , "lib" , "gcc" ,
848- "arm-linux-androideabi" ,
849- "{}.x" .format (config .android_ndk_gcc_version )))
838+ libcxx = make_path (config .android_ndk_path ,
839+ "sources" , "cxx-stl" , "llvm-libc++" , "libs" ,
840+ "armeabi-v7a" ),
841+ libgcc = make_path (config .android_ndk_path ,
842+ "toolchains" ,
843+ "arm-linux-androideabi-{}" .format (config .android_ndk_gcc_version ),
844+ "prebuilt" , "linux-x86_64" , "lib" , "gcc" ,
845+ "arm-linux-androideabi" ,
846+ "{}.x" .format (config .android_ndk_gcc_version )))
850847 config .target_build_swift = (
851848 '%s -target %s -sdk %s %s -Xlinker -pie %s %s %s %s %s'
852849 % (config .swiftc , config .variant_triple , config .variant_sdk ,
@@ -864,8 +861,7 @@ elif run_os == 'linux-androideabi':
864861 config .swift_frontend_test_options ))
865862 subst_target_swift_frontend_mock_sdk = config .target_swift_frontend
866863 subst_target_swift_frontend_mock_sdk_after = ""
867- config .target_run = os .path .join (
868- config .swift_src_root , 'utils' , 'android' , 'adb_test_runner.py' )
864+ config .target_run = make_path (config .swift_src_root , 'utils' , 'android' , 'adb_test_runner.py' )
869865 # FIXME: Include -sdk in this invocation.
870866 config .target_sil_opt = (
871867 '%s -target %s %s %s %s' %
@@ -887,15 +883,10 @@ elif run_os == 'linux-androideabi':
887883 "clang++ -target %s %s" %
888884 (config .variant_triple , clang_mcp_opt ))
889885 config .target_ld = "{} -L{}" .format (
890- os .path .join (
891- config .android_ndk_path ,
892- 'toolchains' ,
893- 'arm-linux-androideabi-{}' .format (config .android_ndk_gcc_version ),
894- 'prebuilt' ,
895- 'linux-x86_64' ,
896- 'arm-linux-androideabi' ,
897- 'bin' ),
898- os .path .join (test_resource_dir , config .target_sdk_name ))
886+ make_path (config .android_ndk_path , 'toolchains' ,
887+ 'arm-linux-androideabi-{}' .format (config .android_ndk_gcc_version ),
888+ 'prebuilt' , 'linux-x86_64' , 'arm-linux-androideabi' , 'bin' ),
889+ make_path (test_resource_dir , config .target_sdk_name ))
899890 # The Swift interpreter is not available when targeting Android.
900891 config .available_features .remove ('swift_interpreter' )
901892
@@ -936,7 +927,7 @@ def source_compiler_rt_libs(path):
936927 if lib .startswith ('libclang_rt.' )
937928 and config .compiler_rt_platform in lib ])
938929
939- source_compiler_rt_libs (os . path . join (test_resource_dir , 'clang' , 'lib' ,
930+ source_compiler_rt_libs (make_path (test_resource_dir , 'clang' , 'lib' ,
940931 platform .system ().lower ()))
941932
942933def check_runtime_libs (features_to_check ):
@@ -1089,10 +1080,10 @@ if hasattr(config, 'target_swift_autolink_extract'):
10891080config .substitutions .append (('%target-swift-modulewrap' ,
10901081 config .target_swift_modulewrap ))
10911082
1092- platform_module_dir = os . path . join (test_resource_dir , '%target-sdk-name' , run_cpu )
1083+ platform_module_dir = make_path (test_resource_dir , '%target-sdk-name' , run_cpu )
10931084lit_config .note ('Using platform module dir: ' + platform_module_dir )
10941085if test_sdk_overlay_dir is not None :
1095- platform_sdk_overlay_dir = os . path . join (test_sdk_overlay_dir , run_cpu )
1086+ platform_sdk_overlay_dir = make_path (test_sdk_overlay_dir , run_cpu )
10961087else :
10971088 platform_sdk_overlay_dir = platform_module_dir
10981089
@@ -1121,8 +1112,8 @@ config.substitutions.append(
11211112config .substitutions .append (('%raw-FileCheck' , pipes .quote (config .filecheck )))
11221113
11231114# If static stdlib is present, enable static stdlib tests
1124- static_stdlib_path = os . path . join ( os . path . join ( config .swift_lib_dir ,"swift_static" ) , config .target_sdk_name )
1125- libswiftCore_path = os . path . join (static_stdlib_path ,"libswiftCore.a" )
1115+ static_stdlib_path = make_path ( config .swift_lib_dir , "swift_static" , config .target_sdk_name )
1116+ libswiftCore_path = make_path (static_stdlib_path , "libswiftCore.a" )
11261117if os .path .exists (libswiftCore_path ):
11271118 config .available_features .add ("static_stdlib" )
11281119 config .substitutions .append (('%target-static-stdlib-path' , static_stdlib_path ))
0 commit comments