@@ -940,6 +940,7 @@ config.target_cxx_lib = '-lc++'
940940config .target_msvc_runtime_opt = ''
941941config .target_static_library_prefix = 'lib'
942942config .target_static_library_suffix = '.a'
943+ config .target_env_prefix = ''
943944
944945if run_vendor == 'apple' :
945946 target_specific_module_triple = '{}-apple-{}' .format (
@@ -954,6 +955,7 @@ if run_vendor == 'apple':
954955 config .target_codesign = make_path (config .swift_utils , "swift-darwin-postprocess.py" )
955956 else :
956957 config .target_codesign = "codesign -f -s -"
958+ config .target_library_path_var = "DYLD_LIBRARY_PATH"
957959 config .target_runtime = "objc"
958960
959961 config .available_features .add ('libdispatch' )
@@ -1080,6 +1082,8 @@ if run_vendor == 'apple':
10801082 xcrun_sdk_name = "watchos"
10811083 target_future_version = "9.99.0"
10821084
1085+ config .target_env_prefix = 'IOS_CHILD_'
1086+
10831087 config .target_cc_options = (
10841088 "-target %s %s" %
10851089 (config .variant_triple , clang_mcp_opt ))
@@ -1122,6 +1126,8 @@ if run_vendor == 'apple':
11221126
11231127 target_specific_module_triple += "-simulator"
11241128
1129+ config .target_env_prefix = 'SIMCTL_CHILD_'
1130+
11251131 config .target_cc_options = (
11261132 "-target %s %s" %
11271133 (config .variant_triple , clang_mcp_opt ))
@@ -1330,6 +1336,7 @@ elif run_os in ['windows-msvc']:
13301336 config .target_msvc_runtime_opt = '-%s -D_MT' % config .swift_stdlib_msvc_runtime
13311337 if 'D' in config .swift_stdlib_msvc_runtime :
13321338 config .target_msvc_runtime_opt += ' -D_DLL'
1339+ config .target_env_prefix = ''
13331340
13341341 config .target_build_swift = \
13351342 ('%r -target %s %s %s %s %s -libc %s' % \
@@ -1439,13 +1446,15 @@ elif (run_os in ['linux-gnu', 'linux-gnueabihf', 'freebsd', 'openbsd', 'windows-
14391446 config .target_shared_library_suffix = ".so"
14401447 config .target_sdk_name = "android"
14411448 config .target_cc_options = "-fPIE"
1449+ config .target_env_prefix = 'ANDROID_CHILD_'
14421450 else :
14431451 lit_config .note ("Testing Linux " + config .variant_triple )
14441452 config .target_object_format = "elf"
14451453 config .target_shared_library_prefix = 'lib'
14461454 config .target_shared_library_suffix = ".so"
14471455 config .target_sdk_name = "linux"
14481456 config .target_cc_options = "-fPIE"
1457+ config .target_library_path_var = "LD_LIBRARY_PATH"
14491458 config .target_runtime = "native"
14501459 config .target_swift_autolink_extract = inferSwiftBinary ("swift-autolink-extract" )
14511460
@@ -1572,6 +1581,8 @@ elif run_os == 'linux-androideabi' or run_os == 'linux-android':
15721581 config .target_runtime = "native"
15731582 config .target_swift_autolink_extract = inferSwiftBinary ("swift-autolink-extract" )
15741583 config .target_sdk_name = "android"
1584+ config .target_library_path_var = "LD_LIBRARY_PATH"
1585+ config .target_env_prefix = 'ANDROID_CHILD_'
15751586 config .resource_dir_opt = ("-resource-dir %s" % test_resource_dir )
15761587 # Since NDK r19, the headers and libraries are available in a unified
15771588 # sysroot at $NDK_PATH/toolchains/llvm/prebuilt/$prebuilt_directory/sysroot,
@@ -1775,19 +1786,6 @@ config.substitutions.append(('%string_processing_module', string_processing_modu
17751786config .substitutions .append (('%/string_processing_module' ,
17761787 '/' .join (os .path .normpath (string_processing_module ).split (os .sep ))))
17771788
1778- # Different OS's require different prefixes for the environment variables to be
1779- # propagated to the calling contexts.
1780- # In order to make tests OS-agnostic, names of environment variables should be
1781- # prefixed with `%env-`, which is then expanded to the appropriate prefix.
1782- SIMULATOR_ENV_PREFIX = 'SIMCTL_CHILD_'
1783- ENV_VAR_PREFIXES = {
1784- 'iphonesimulator' : SIMULATOR_ENV_PREFIX ,
1785- 'watchsimulator' : SIMULATOR_ENV_PREFIX ,
1786- 'appletvsimulator' : SIMULATOR_ENV_PREFIX ,
1787- 'android' : 'ANDROID_CHILD_'
1788- }
1789- TARGET_ENV_PREFIX = ENV_VAR_PREFIXES .get (config .target_sdk_name , "" ) if not kIsAndroid else ""
1790-
17911789back_deployment_runtime = lit_config .params .get ('back_deployment_runtime' , None )
17921790if back_deployment_runtime is not None :
17931791 config .available_features .add ('back_deployment_runtime' )
@@ -1797,24 +1795,51 @@ if run_vendor == 'apple':
17971795 if 'back_deploy_concurrency' in config .available_features :
17981796 concurrency_back_deploy_path = os .path .join (os .path .dirname (swift_obj_root ), os .path .basename (swift_obj_root ).replace ("swift-" , "backdeployconcurrency-" ), 'lib' , 'swift-5.5' , run_os )
17991797
1800- if 'remote_run_host' in lit_config .params :
1798+ def os_stdlib_paths ():
1799+ if run_vendor == 'apple' :
1800+ if run_os == 'maccatalyst' :
1801+ return ["/System/iOSSupport/usr/lib/swift" , "/usr/lib/swift" ]
1802+ else :
1803+ return ["/usr/lib/swift" ]
1804+ else :
1805+ lit_config .fatal ("Unsupported platform for os_stdlib_paths" )
1806+
1807+ # This returns a shell variable assignment of the form <LIBRARY_PATH>=<VALUE>
1808+ # where <LIBRARY_PATH> is whatever environment variable we need to set to
1809+ # override dynamic library locations. (Usually DYLD_LIBRARY_PATH or
1810+ # LD_LIBRARY_PATH, sometimes prefixed by a special annotation to tunnel the
1811+ # setting through a helper tool.)
1812+ #
1813+ # The return value is designed to be passed to `/usr/bin/env` when executing a
1814+ # binary on the test target.
1815+ #
1816+ # The single parameter is an array of directory paths that hold the libraries.
1817+ def construct_library_path_env (dirs ):
1818+ return "{0}{1}='{2}' " .format (
1819+ config .target_env_prefix ,
1820+ config .target_library_path_var ,
1821+ os .path .pathsep .join (dirs ))
1822+
1823+ def configure_remote_run ():
18011824 if 'remote_run_tmpdir' not in lit_config .params :
18021825 lit_config .fatal ("'remote_run_host' provided, but no "
18031826 "'remote_run_tmpdir'" )
18041827
18051828 remote_run_host = lit_config .params ['remote_run_host' ]
18061829 remote_tmp_dir = lit_config .params ['remote_run_tmpdir' ]
18071830 remote_lib_dir = os .path .join (remote_tmp_dir , 'stdlib' )
1808- remote_run_lib_path = ''
1809- if 'use_os_stdlib' not in lit_config .params :
1810- remote_run_lib_path = remote_lib_dir
1811- else :
1831+ remote_run_lib_path = [remote_lib_dir ]
1832+ if 'use_os_stdlib' in lit_config .params :
18121833 config .available_features .add ('use_os_stdlib' )
1813- os_stdlib_path = ''
1814- if run_vendor == 'apple' :
1815- #If we get swift-in-the-OS for non-Apple platforms, add a condition here
1816- os_stdlib_path = "/usr/lib/swift"
1817- remote_run_lib_path = os .path .pathsep .join ((os_stdlib_path , remote_lib_dir ))
1834+ remote_run_lib_path = os_stdlib_paths () + [remote_lib_dir ]
1835+ lit_config .note ('Remote testing with the standard libraries in the OS' )
1836+ elif 'back_deployment_runtime' in lit_config .params :
1837+ lit_config .note ('Remote testing with back deployment libraries' )
1838+ else :
1839+ lit_config .note ('Remote testing with the just-built libraries' )
1840+
1841+ lit_config .note (
1842+ 'Remote library load path: {0}' .format (os .path .pathsep .join (remote_run_lib_path )))
18181843
18191844 remote_run_extra_args_param = lit_config .params .get ('remote_run_extra_args' )
18201845 remote_run_extra_args = shlex .split (remote_run_extra_args_param or '' )
@@ -1861,23 +1886,38 @@ if 'remote_run_host' in lit_config.params:
18611886 os .path .dirname (local_swift_reflection_test ),
18621887 'bin/' )
18631888
1889+ print ("Contents of {0} on {1} after upload:" .format (
1890+ remote_lib_dir , remote_run_host ))
1891+ subprocess .check_call (
1892+ [
1893+ os .path .join (config .swift_utils , 'remote-run' ),
1894+ '--remote-dir' , remote_tmp_dir ,
1895+ ] + remote_run_extra_args + [
1896+ remote_run_host ,
1897+ '--' ,
1898+ 'ls' , '-l' , remote_lib_dir
1899+ ])
1900+
1901+ config .target_env_prefix = 'REMOTE_RUN_CHILD_'
18641902 config .target_run = (
1865- "/usr/bin/env "
1866- "REMOTE_RUN_CHILD_DYLD_LIBRARY_PATH='{0}' " # Apple option
1867- "REMOTE_RUN_CHILD_LD_LIBRARY_PATH='{0}' " # Linux option
1868- "'{1}'/remote-run --input-prefix '{2}' --output-prefix %t "
1869- "--remote-dir '{3}'%t {4} {5}" .format (remote_run_lib_path ,
1870- config .swift_utils ,
1871- config .swift_src_root ,
1872- remote_tmp_dir ,
1873- ' ' .join (remote_run_extra_args ),
1874- remote_run_host ))
1903+ "/usr/bin/env " +
1904+ construct_library_path_env (remote_run_lib_path ) +
1905+ "'{0}'/remote-run " .format (config .swift_utils ) +
1906+ "--input-prefix '{0}' " .format (config .src_root ) +
1907+ "--output-prefix %t " +
1908+ "--remote-dir '{0}'%t " .format (remote_tmp_dir ) +
1909+ "{0} " .format (' ' .join (remote_run_extra_args )) +
1910+ "{0}" .format (remote_run_host ))
18751911 config .target_swift_reflection_test = os .path .join (
18761912 remote_tmp_dir , 'bin' , swift_reflection_test_name )
1877- TARGET_ENV_PREFIX = 'REMOTE_RUN_CHILD_'
18781913 config .available_features .add ('remote_run' )
18791914
1880- config .substitutions .append (('%env-' , TARGET_ENV_PREFIX ))
1915+ # Different OS's require different prefixes for the environment variables to be
1916+ # propagated to the calling contexts.
1917+ # In order to make tests OS-agnostic, names of environment variables should be
1918+ # prefixed with `%env-`, which is then expanded to the appropriate prefix.
1919+ config .substitutions .append (('%env-' , config .target_env_prefix ))
1920+
18811921config .substitutions .append (("%target-sdk-name" , config .target_sdk_name ))
18821922
18831923simulator_sdks = [
@@ -2048,42 +2088,40 @@ if 'concurrency' in config.available_features:
20482088 else :
20492089 config .available_features .add ('concurrency_runtime' )
20502090
2051- # Set up testing with the standard libraries coming from the OS / just-built libraries
2052- # default Swift tests to use the just-built libraries
2053- target_stdlib_path = platform_dylib_dir
2054- if not kIsWindows :
2055- libdispatch_path = getattr (config , 'libdispatch_artifact_dir' , '' )
2056- if 'use_os_stdlib' not in lit_config .params :
2057- if run_os == 'maccatalyst' :
2058- # Under macCatalyst we need to have the unzippered twin dylib dir come before
2059- # the zippered/macosx dylib dir so that unzippered twins are picked upload_dylibs
2060- # before the macOS variant.
2061- target_stdlib_path = "{0}:{1}" .format (platform_module_dir , target_stdlib_path )
2062- lit_config .note ('Testing with the just-built libraries at ' + target_stdlib_path )
2063- config .target_run = (
2064- "/usr/bin/env "
2065- "DYLD_LIBRARY_PATH='{0}' " # Apple option
2066- "LD_LIBRARY_PATH='{0}:{1}' " # Linux option
2067- "SIMCTL_CHILD_DYLD_LIBRARY_PATH='{0}' " # Simulator option
2068- .format (target_stdlib_path , libdispatch_path )) + config .target_run
2069- else :
2070- config .available_features .add ('use_os_stdlib' )
2071- os_stdlib_path = ''
2072- if run_vendor == 'apple' :
2073- #If we get swift-in-the-OS for non-Apple platforms, add a condition here
2074- os_stdlib_path = "/usr/lib/swift"
2075- if run_os == 'maccatalyst' :
2076- os_stdlib_path = "/System/iOSSupport/usr/lib/swift:/usr/lib/swift"
2077-
2078- all_stdlib_path = os .path .pathsep .join ((os_stdlib_path , concurrency_back_deploy_path , target_stdlib_path ))
2079-
2080- lit_config .note ('Testing with the standard libraries coming from the OS ' + all_stdlib_path )
2081- config .target_run = (
2082- "/usr/bin/env "
2083- "DYLD_LIBRARY_PATH='{0}' " # Apple option
2084- "LD_LIBRARY_PATH='{0}:{1}' " # Linux option
2085- "SIMCTL_CHILD_DYLD_LIBRARY_PATH='{0}' " # Simulator option
2086- .format (all_stdlib_path , libdispatch_path )) + config .target_run
2091+ # Set up testing with the standard libraries coming from either the OS, the back
2092+ # deployment runtime or the just-built libraries. By default, we run tests with
2093+ # the just-built libraries.
2094+ target_stdlib_path = [platform_dylib_dir ]
2095+ if run_os == 'maccatalyst' :
2096+ # Under macCatalyst we need to have the unzippered twin dylib dir come before
2097+ # the zippered/macosx dylib dir so that unzippered twins are picked upload_dylibs
2098+ # before the macOS variant.
2099+ target_stdlib_path = [platform_module_dir , platform_dylib_dir ]
2100+
2101+ if run_vendor != 'apple' :
2102+ libdispatch_path = getattr (config , 'libdispatch_artifact_dir' , None )
2103+ if libdispatch_path is not None :
2104+ target_stdlib_path .append (libdispatch_path )
2105+
2106+ if 'remote-run-host' in lit_config .params :
2107+ configure_remote_run ()
2108+ elif not kIsWindows :
2109+ if 'use_os_stdlib' in lit_config .params :
2110+ config .available_features .add ('use_os_stdlib' )
2111+
2112+ target_stdlib_path = os_stdlib_paths () + [concurrency_back_deploy_path ] + target_stdlib_path
2113+
2114+ lit_config .note ('Testing with the standard libraries in the OS' )
2115+ elif 'back_deployment_runtime' in lit_config .params :
2116+ lit_config .note ('Testing with back deployment runtime libraries' )
2117+ else :
2118+ lit_config .note ('Testing with the just-built libraries' )
2119+
2120+ lit_config .note ('Library load path: {0}' .format (os .path .pathsep .join (target_stdlib_path )))
2121+ config .target_run = (
2122+ "/usr/bin/env " +
2123+ construct_library_path_env (target_stdlib_path ) +
2124+ config .target_run )
20872125
20882126# When running with the JIT on Darwin, force the usage of the just built stdlib
20892127# when running the frontend. This is because we currently JIT in process
@@ -2410,7 +2448,7 @@ config.substitutions.append(('%import-static-libdispatch', getattr(config, 'impo
24102448config .environment ['SWIFT_DEBUG_ENABLE_COW_CHECKS' ] = 'false'
24112449
24122450# Add this to the command which runs an executable to enable COW checks in the swift runtime.
2413- config .substitutions .append (('%enable-cow-checking' , TARGET_ENV_PREFIX + 'SWIFT_DEBUG_ENABLE_COW_CHECKS=true;' ))
2451+ config .substitutions .append (('%enable-cow-checking' , config . target_env_prefix + 'SWIFT_DEBUG_ENABLE_COW_CHECKS=true;' ))
24142452
24152453# We add an expansion to ensure that migrator tests can search for the api diff
24162454# data dir from the host compiler toolchain instead of the resource dir of the
@@ -2445,10 +2483,10 @@ if config.lldb_build_root != "":
24452483# Disable randomized hash seeding by default. Tests need to manually opt in to
24462484# random seeds by unsetting the SWIFT_DETERMINISTIC_HASHING environment
24472485# variable.
2448- config .environment [TARGET_ENV_PREFIX + 'SWIFT_DETERMINISTIC_HASHING' ] = '1'
2486+ config .environment [config . target_env_prefix + 'SWIFT_DETERMINISTIC_HASHING' ] = '1'
24492487
24502488# Enable malloc scribble during tests by default.
2451- config .environment [TARGET_ENV_PREFIX + 'SWIFT_DEBUG_ENABLE_MALLOC_SCRIBBLE' ] = 'YES'
2489+ config .environment [config . target_env_prefix + 'SWIFT_DEBUG_ENABLE_MALLOC_SCRIBBLE' ] = 'YES'
24522490
24532491# Run lsb_release on the target to be tested and return the results.
24542492def linux_get_lsb_release ():
0 commit comments