@@ -955,6 +955,7 @@ if run_vendor == 'apple':
955955 config .target_codesign = make_path (config .swift_utils , "swift-darwin-postprocess.py" )
956956 else :
957957 config .target_codesign = "codesign -f -s -"
958+ config .target_library_path_var = "DYLD_LIBRARY_PATH"
958959 config .target_runtime = "objc"
959960
960961 config .available_features .add ('libdispatch' )
@@ -1453,6 +1454,7 @@ elif (run_os in ['linux-gnu', 'linux-gnueabihf', 'freebsd', 'openbsd', 'windows-
14531454 config .target_shared_library_suffix = ".so"
14541455 config .target_sdk_name = "linux"
14551456 config .target_cc_options = "-fPIE"
1457+ config .target_library_path_var = "LD_LIBRARY_PATH"
14561458 config .target_runtime = "native"
14571459 config .target_swift_autolink_extract = inferSwiftBinary ("swift-autolink-extract" )
14581460
@@ -1579,6 +1581,7 @@ elif run_os == 'linux-androideabi' or run_os == 'linux-android':
15791581 config .target_runtime = "native"
15801582 config .target_swift_autolink_extract = inferSwiftBinary ("swift-autolink-extract" )
15811583 config .target_sdk_name = "android"
1584+ config .target_library_path_var = "LD_LIBRARY_PATH"
15821585 config .target_env_prefix = 'ANDROID_CHILD_'
15831586 config .resource_dir_opt = ("-resource-dir %s" % test_resource_dir )
15841587 # Since NDK r19, the headers and libraries are available in a unified
@@ -1792,24 +1795,51 @@ if run_vendor == 'apple':
17921795 if 'back_deploy_concurrency' in config .available_features :
17931796 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 )
17941797
1795- 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 ():
17961824 if 'remote_run_tmpdir' not in lit_config .params :
17971825 lit_config .fatal ("'remote_run_host' provided, but no "
17981826 "'remote_run_tmpdir'" )
17991827
18001828 remote_run_host = lit_config .params ['remote_run_host' ]
18011829 remote_tmp_dir = lit_config .params ['remote_run_tmpdir' ]
18021830 remote_lib_dir = os .path .join (remote_tmp_dir , 'stdlib' )
1803- remote_run_lib_path = ''
1804- if 'use_os_stdlib' not in lit_config .params :
1805- remote_run_lib_path = remote_lib_dir
1806- else :
1831+ remote_run_lib_path = [remote_lib_dir ]
1832+ if 'use_os_stdlib' in lit_config .params :
18071833 config .available_features .add ('use_os_stdlib' )
1808- os_stdlib_path = ''
1809- if run_vendor == 'apple' :
1810- #If we get swift-in-the-OS for non-Apple platforms, add a condition here
1811- os_stdlib_path = "/usr/lib/swift"
1812- 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 )))
18131843
18141844 remote_run_extra_args_param = lit_config .params .get ('remote_run_extra_args' )
18151845 remote_run_extra_args = shlex .split (remote_run_extra_args_param or '' )
@@ -1858,16 +1888,14 @@ if 'remote_run_host' in lit_config.params:
18581888
18591889 config .target_env_prefix = 'REMOTE_RUN_CHILD_'
18601890 config .target_run = (
1861- "/usr/bin/env "
1862- "REMOTE_RUN_CHILD_DYLD_LIBRARY_PATH='{0}' " # Apple option
1863- "REMOTE_RUN_CHILD_LD_LIBRARY_PATH='{0}' " # Linux option
1864- "'{1}'/remote-run --input-prefix '{2}' --output-prefix %t "
1865- "--remote-dir '{3}'%t {4} {5}" .format (remote_run_lib_path ,
1866- config .swift_utils ,
1867- config .swift_src_root ,
1868- remote_tmp_dir ,
1869- ' ' .join (remote_run_extra_args ),
1870- remote_run_host ))
1891+ "/usr/bin/env " +
1892+ construct_library_path_env (remote_run_lib_path ) +
1893+ "'{0}'/remote-run " .format (config .swift_utils ) +
1894+ "--input-prefix '{0}' " .format (config .src_root ) +
1895+ "--output-prefix %t " +
1896+ "--remote-dir '{0}'%t " .format (remote_tmp_dir ) +
1897+ "{0} " .format (' ' .join (remote_run_extra_args )) +
1898+ "{0}" .format (remote_run_host ))
18711899 config .target_swift_reflection_test = os .path .join (
18721900 remote_tmp_dir , 'bin' , swift_reflection_test_name )
18731901 config .available_features .add ('remote_run' )
@@ -2048,42 +2076,40 @@ if 'concurrency' in config.available_features:
20482076 else :
20492077 config .available_features .add ('concurrency_runtime' )
20502078
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
2079+ # Set up testing with the standard libraries coming from either the OS, the back
2080+ # deployment runtime or the just-built libraries. By default, we run tests with
2081+ # the just-built libraries.
2082+ target_stdlib_path = [platform_dylib_dir ]
2083+ if run_os == 'maccatalyst' :
2084+ # Under macCatalyst we need to have the unzippered twin dylib dir come before
2085+ # the zippered/macosx dylib dir so that unzippered twins are picked upload_dylibs
2086+ # before the macOS variant.
2087+ target_stdlib_path = [platform_module_dir , platform_dylib_dir ]
2088+
2089+ if run_vendor != 'apple' :
2090+ libdispatch_path = getattr (config , 'libdispatch_artifact_dir' , None )
2091+ if libdispatch_path is not None :
2092+ target_stdlib_path .append (libdispatch_path )
2093+
2094+ if 'remote-run-host' in lit_config .params :
2095+ configure_remote_run ()
2096+ elif not kIsWindows :
2097+ if 'use_os_stdlib' in lit_config .params :
2098+ config .available_features .add ('use_os_stdlib' )
2099+
2100+ target_stdlib_path = os_stdlib_paths () + [concurrency_back_deploy_path ] + target_stdlib_path
2101+
2102+ lit_config .note ('Testing with the standard libraries in the OS' )
2103+ elif 'back_deployment_runtime' in lit_config .params :
2104+ lit_config .note ('Testing with back deployment runtime libraries' )
2105+ else :
2106+ lit_config .note ('Testing with the just-built libraries' )
2107+
2108+ lit_config .note ('Library load path: {0}' .format (os .path .pathsep .join (target_stdlib_path )))
2109+ config .target_run = (
2110+ "/usr/bin/env " +
2111+ construct_library_path_env (target_stdlib_path ) +
2112+ config .target_run )
20872113
20882114# When running with the JIT on Darwin, force the usage of the just built stdlib
20892115# when running the frontend. This is because we currently JIT in process
0 commit comments