@@ -71,6 +71,14 @@ impl<'a> Toolchain<'a> {
71
71
} )
72
72
}
73
73
74
+ pub fn as_installed_common ( & ' a self ) -> Result < InstalledCommonToolchain < ' a > > {
75
+ if !self . exists ( ) {
76
+ // Should be verify perhaps?
77
+ return Err ( ErrorKind :: ToolchainNotInstalled ( self . name . to_owned ( ) ) . into ( ) ) ;
78
+ }
79
+ Ok ( InstalledCommonToolchain ( self ) )
80
+ }
81
+
74
82
fn as_installed ( & ' a self ) -> Result < Box < dyn InstalledToolchain < ' a > + ' a > > {
75
83
if self . is_custom ( ) {
76
84
let toolchain = CustomToolchain :: new ( self ) ?;
@@ -150,48 +158,6 @@ impl<'a> Toolchain<'a> {
150
158
== Some ( true )
151
159
}
152
160
153
- // Both Distributable and Custom; Installed only.
154
- pub fn create_command < T : AsRef < OsStr > > ( & self , binary : T ) -> Result < Command > {
155
- if !self . exists ( ) {
156
- return Err ( ErrorKind :: ToolchainNotInstalled ( self . name . to_owned ( ) ) . into ( ) ) ;
157
- }
158
-
159
- // Create the path to this binary within the current toolchain sysroot
160
- let binary = if let Some ( binary_str) = binary. as_ref ( ) . to_str ( ) {
161
- if binary_str. to_lowercase ( ) . ends_with ( EXE_SUFFIX ) {
162
- binary. as_ref ( ) . to_owned ( )
163
- } else {
164
- OsString :: from ( format ! ( "{}{}" , binary_str, EXE_SUFFIX ) )
165
- }
166
- } else {
167
- // Very weird case. Non-unicode command.
168
- binary. as_ref ( ) . to_owned ( )
169
- } ;
170
-
171
- let bin_path = self . path . join ( "bin" ) . join ( & binary) ;
172
- let path = if utils:: is_file ( & bin_path) {
173
- & bin_path
174
- } else {
175
- let recursion_count = env:: var ( "RUST_RECURSION_COUNT" )
176
- . ok ( )
177
- . and_then ( |s| s. parse ( ) . ok ( ) )
178
- . unwrap_or ( 0 ) ;
179
- if recursion_count > env_var:: RUST_RECURSION_COUNT_MAX - 1 {
180
- let defaults = self . cfg . get_default ( ) ?;
181
- return Err ( ErrorKind :: BinaryNotFound (
182
- binary. to_string_lossy ( ) . into ( ) ,
183
- self . name . clone ( ) ,
184
- Some ( & self . name ) == defaults. as_ref ( ) ,
185
- )
186
- . into ( ) ) ;
187
- }
188
- Path :: new ( & binary)
189
- } ;
190
- let mut cmd = Command :: new ( & path) ;
191
- self . set_env ( & mut cmd) ;
192
- Ok ( cmd)
193
- }
194
-
195
161
// Custom and Distributable. Installed only.
196
162
fn set_env ( & self , cmd : & mut Command ) {
197
163
self . set_ldpath ( cmd) ;
@@ -355,6 +321,48 @@ impl<'a> Toolchain<'a> {
355
321
}
356
322
}
357
323
324
+ /// Newtype hosting functions that apply to both custom and distributable toolchains that are installed.
325
+ pub struct InstalledCommonToolchain < ' a > ( & ' a Toolchain < ' a > ) ;
326
+
327
+ impl < ' a > InstalledCommonToolchain < ' a > {
328
+ pub fn create_command < T : AsRef < OsStr > > ( & self , binary : T ) -> Result < Command > {
329
+ // Create the path to this binary within the current toolchain sysroot
330
+ let binary = if let Some ( binary_str) = binary. as_ref ( ) . to_str ( ) {
331
+ if binary_str. to_lowercase ( ) . ends_with ( EXE_SUFFIX ) {
332
+ binary. as_ref ( ) . to_owned ( )
333
+ } else {
334
+ OsString :: from ( format ! ( "{}{}" , binary_str, EXE_SUFFIX ) )
335
+ }
336
+ } else {
337
+ // Very weird case. Non-unicode command.
338
+ binary. as_ref ( ) . to_owned ( )
339
+ } ;
340
+
341
+ let bin_path = self . 0 . path . join ( "bin" ) . join ( & binary) ;
342
+ let path = if utils:: is_file ( & bin_path) {
343
+ & bin_path
344
+ } else {
345
+ let recursion_count = env:: var ( "RUST_RECURSION_COUNT" )
346
+ . ok ( )
347
+ . and_then ( |s| s. parse ( ) . ok ( ) )
348
+ . unwrap_or ( 0 ) ;
349
+ if recursion_count > env_var:: RUST_RECURSION_COUNT_MAX - 1 {
350
+ let defaults = self . 0 . cfg . get_default ( ) ?;
351
+ return Err ( ErrorKind :: BinaryNotFound (
352
+ binary. to_string_lossy ( ) . into ( ) ,
353
+ self . 0 . name . clone ( ) ,
354
+ Some ( & self . 0 . name ) == defaults. as_ref ( ) ,
355
+ )
356
+ . into ( ) ) ;
357
+ }
358
+ Path :: new ( & binary)
359
+ } ;
360
+ let mut cmd = Command :: new ( & path) ;
361
+ self . 0 . set_env ( & mut cmd) ;
362
+ Ok ( cmd)
363
+ }
364
+ }
365
+
358
366
/// Newtype to facilitate splitting out custom-toolchain specific code.
359
367
pub struct CustomToolchain < ' a > ( & ' a Toolchain < ' a > ) ;
360
368
0 commit comments