@@ -2744,9 +2744,12 @@ def test_rpath_args_script(self):
2744
2744
def test_toolchain_prepare_rpath (self ):
2745
2745
"""Test toolchain.prepare under --rpath"""
2746
2746
2747
+ # Code for a bash script that prints each passed argument on a new line
2748
+ BASH_SCRIPT_PRINT_ARGS = '#!/bin/bash\n for arg in "$@"; do echo "$arg"; done'
2749
+
2747
2750
# put fake 'g++' command in place that just echos its arguments
2748
2751
fake_gxx = os .path .join (self .test_prefix , 'fake' , 'g++' )
2749
- write_file (fake_gxx , '#!/bin/bash \n echo "$@"' )
2752
+ write_file (fake_gxx , BASH_SCRIPT_PRINT_ARGS )
2750
2753
adjust_permissions (fake_gxx , stat .S_IXUSR )
2751
2754
os .environ ['PATH' ] = '%s:%s' % (os .path .join (self .test_prefix , 'fake' ), os .getenv ('PATH' , '' ))
2752
2755
@@ -2789,7 +2792,7 @@ def test_toolchain_prepare_rpath(self):
2789
2792
# Check that we can create a wrapper for a toolchain for which self.compilers() returns 'None' for the Fortran
2790
2793
# compilers (i.e. Clang)
2791
2794
fake_clang = os .path .join (self .test_prefix , 'fake' , 'clang' )
2792
- write_file (fake_clang , '#!/bin/bash \n echo "$@"' )
2795
+ write_file (fake_clang , BASH_SCRIPT_PRINT_ARGS )
2793
2796
adjust_permissions (fake_clang , stat .S_IXUSR )
2794
2797
tc_clang = Clang (name = 'Clang' , version = '1' )
2795
2798
tc_clang .prepare_rpath_wrappers ()
@@ -2852,18 +2855,25 @@ def test_toolchain_prepare_rpath(self):
2852
2855
'-L%s/foo' % self .test_prefix ,
2853
2856
'-L/bar' ,
2854
2857
"'$FOO'" ,
2855
- '-DX="\\ "\\ ""' ,
2858
+ # C/C++ preprocessor value including a quotes
2859
+ r'-DX1="\"\""' ,
2860
+ r'-DX2="\"I\""' ,
2861
+ r"-DY1=\'\'" ,
2862
+ r"-DY2=\'J\'" ,
2856
2863
])
2857
2864
out , ec = run_cmd (cmd )
2858
2865
self .assertEqual (ec , 0 )
2859
- expected = ' ' .join ([
2866
+ expected = '\n ' .join ([
2860
2867
'-Wl,--disable-new-dtags' ,
2861
2868
'-Wl,-rpath=%s/foo' % self .test_prefix ,
2862
2869
'%(user)s.c' ,
2863
2870
'-L%s/foo' % self .test_prefix ,
2864
2871
'-L/bar' ,
2865
2872
'$FOO' ,
2866
- '-DX=""' ,
2873
+ '-DX1=""' ,
2874
+ '-DX2="I"' ,
2875
+ "-DY1=''" ,
2876
+ "-DY2='J'" ,
2867
2877
])
2868
2878
self .assertEqual (out .strip (), expected % {'user' : os .getenv ('USER' )})
2869
2879
@@ -2888,35 +2898,43 @@ def test_toolchain_prepare_rpath(self):
2888
2898
for path in paths :
2889
2899
mkdir (path , parents = True )
2890
2900
args = ['-L%s' % x for x in paths ]
2901
+ path_with_spaces = os .path .join (self .test_prefix , 'prefix/with spaces' )
2902
+ mkdir (path_with_spaces )
2903
+ args .append ('-L"%s"' % path_with_spaces )
2891
2904
2892
2905
cmd = "g++ ${USER}.c %s" % ' ' .join (args )
2893
2906
out , ec = run_cmd (cmd , simple = False )
2894
2907
self .assertEqual (ec , 0 )
2895
2908
2896
- expected = ' ' .join ([
2909
+ expected = '\n ' .join ([
2897
2910
'-Wl,--disable-new-dtags' ,
2898
- '-Wl,-rpath=%s/tmp/foo/' % self .test_prefix ,
2899
- '-Wl,-rpath=%s/prefix/software/stubs/1.2.3/lib' % self .test_prefix ,
2900
- '-Wl,-rpath=%s/prefix/software/foobar/4.5/notreallystubs' % self .test_prefix ,
2901
- '-Wl,-rpath=%s/prefix/software/zlib/1.2.11/lib' % self .test_prefix ,
2902
- '-Wl,-rpath=%s/prefix/software/foobar/4.5/stubsbutnotreally' % self .test_prefix ,
2911
+ '-Wl,-rpath=%(libdir)s/tmp/foo/' ,
2912
+ '-Wl,-rpath=%(libdir)s/prefix/software/stubs/1.2.3/lib' ,
2913
+ '-Wl,-rpath=%(libdir)s/prefix/software/foobar/4.5/notreallystubs' ,
2914
+ '-Wl,-rpath=%(libdir)s/prefix/software/zlib/1.2.11/lib' ,
2915
+ '-Wl,-rpath=%(libdir)s/prefix/software/foobar/4.5/stubsbutnotreally' ,
2916
+ '-Wl,-rpath=%(path_with_spaces)s' ,
2903
2917
'%(user)s.c' ,
2904
- '-L%s/prefix/software/CUDA/1.2.3/lib/stubs/' % self .test_prefix ,
2905
- '-L%s/prefix/software/CUDA/1.2.3/stubs/lib/' % self .test_prefix ,
2906
- '-L%s/tmp/foo/' % self .test_prefix ,
2907
- '-L%s/prefix/software/stubs/1.2.3/lib' % self .test_prefix ,
2908
- '-L%s/prefix/software/CUDA/1.2.3/lib/stubs' % self .test_prefix ,
2909
- '-L%s/prefix/software/CUDA/1.2.3/stubs/lib' % self .test_prefix ,
2910
- '-L%s/prefix/software/CUDA/1.2.3/lib64/stubs/' % self .test_prefix ,
2911
- '-L%s/prefix/software/CUDA/1.2.3/stubs/lib64/' % self .test_prefix ,
2912
- '-L%s/prefix/software/foobar/4.5/notreallystubs' % self .test_prefix ,
2913
- '-L%s/prefix/software/CUDA/1.2.3/lib64/stubs' % self .test_prefix ,
2914
- '-L%s/prefix/software/CUDA/1.2.3/stubs/lib64' % self .test_prefix ,
2915
- '-L%s/prefix/software/zlib/1.2.11/lib' % self .test_prefix ,
2916
- '-L%s/prefix/software/bleh/0/lib/stubs' % self .test_prefix ,
2917
- '-L%s/prefix/software/foobar/4.5/stubsbutnotreally' % self .test_prefix ,
2918
+ '-L%(libdir)s/prefix/software/CUDA/1.2.3/lib/stubs/' ,
2919
+ '-L%(libdir)s/prefix/software/CUDA/1.2.3/stubs/lib/' ,
2920
+ '-L%(libdir)s/tmp/foo/' ,
2921
+ '-L%(libdir)s/prefix/software/stubs/1.2.3/lib' ,
2922
+ '-L%(libdir)s/prefix/software/CUDA/1.2.3/lib/stubs' ,
2923
+ '-L%(libdir)s/prefix/software/CUDA/1.2.3/stubs/lib' ,
2924
+ '-L%(libdir)s/prefix/software/CUDA/1.2.3/lib64/stubs/' ,
2925
+ '-L%(libdir)s/prefix/software/CUDA/1.2.3/stubs/lib64/' ,
2926
+ '-L%(libdir)s/prefix/software/foobar/4.5/notreallystubs' ,
2927
+ '-L%(libdir)s/prefix/software/CUDA/1.2.3/lib64/stubs' ,
2928
+ '-L%(libdir)s/prefix/software/CUDA/1.2.3/stubs/lib64' ,
2929
+ '-L%(libdir)s/prefix/software/zlib/1.2.11/lib' ,
2930
+ '-L%(libdir)s/prefix/software/bleh/0/lib/stubs' ,
2931
+ '-L%(libdir)s/prefix/software/foobar/4.5/stubsbutnotreally' ,
2932
+ '-L%(path_with_spaces)s' ,
2918
2933
])
2919
- self .assertEqual (out .strip (), expected % {'user' : os .getenv ('USER' )})
2934
+ self .assertEqual (out .strip (), expected % {'libdir' : self .test_prefix ,
2935
+ 'user' : os .getenv ('USER' ),
2936
+ 'path_with_spaces' : path_with_spaces ,
2937
+ })
2920
2938
2921
2939
# calling prepare() again should *not* result in wrapping the existing RPATH wrappers
2922
2940
# this can happen when building extensions
0 commit comments