File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -45,7 +45,7 @@ impl Rustflags {
45
45
pub fn for_xargo ( & self , home : & Home ) -> String {
46
46
let mut flags = self . flags . clone ( ) ;
47
47
flags. push ( "--sysroot" . to_owned ( ) ) ;
48
- flags. push ( home. display ( ) . to_string ( ) ) ;
48
+ flags. push ( util :: escape_argument_spaces ( format ! ( "{}" , home. display( ) ) ) ) ;
49
49
flags. join ( " " )
50
50
}
51
51
}
Original file line number Diff line number Diff line change @@ -100,3 +100,24 @@ pub fn write(path: &Path, contents: &str) -> Result<()> {
100
100
. write_all ( contents. as_bytes ( ) )
101
101
. chain_err ( || format ! ( "couldn't write to {}" , p) )
102
102
}
103
+
104
+ /// Escapes spaces (` `) in the given input with `%20` or does nothing. Then
105
+ /// it returns the processed string.
106
+ /// ### Windows Only
107
+ /// Doesn't do anything on non-windows systems because escaped output
108
+ /// (containing `\ `) is still treated as two arguments because of the
109
+ /// remaining space character.
110
+ pub fn escape_argument_spaces < S : Into < String > > ( arg : S ) -> String {
111
+ #[ cfg( target_os = "windows" ) ]
112
+ let escaped = arg. into ( ) . replace ( " " , "%20" ) ;
113
+
114
+ #[ cfg( not( target_os = "windows" ) ) ]
115
+ let escaped = arg. into ( ) ;
116
+ // Doesn't work because there's still a space character in the string
117
+ // and it's still interpreted as a separation between two arguments.
118
+ /*
119
+ let escaped = arg.into().replace(" ", "\\ ");
120
+ */
121
+
122
+ escaped
123
+ }
You can’t perform that action at this time.
0 commit comments