@@ -75,6 +75,22 @@ impl RustfmtRunner {
75
75
. args ( args)
76
76
. output ( )
77
77
}
78
+
79
+ fn get_binary_version ( & self ) -> Result < String , CheckDiffError > {
80
+ let Ok ( command) = Command :: new ( & self . binary_path )
81
+ . env ( "LD_LIB_PATH" , & self . ld_library_path )
82
+ . args ( [ "--version" ] )
83
+ . output ( )
84
+ else {
85
+ return Err ( CheckDiffError :: FailedBinaryVersioning (
86
+ self . binary_path . to_path_buf ( ) ,
87
+ ) ) ;
88
+ } ;
89
+
90
+ let binding = String :: from_utf8 ( command. stdout ) ?;
91
+ let binary_version = binding. trim ( ) ;
92
+ return Ok ( binary_version. to_string ( ) ) ;
93
+ }
78
94
}
79
95
80
96
/// Clone a git repository
@@ -198,23 +214,9 @@ pub fn get_cargo_version() -> Result<String, CheckDiffError> {
198
214
return Ok ( cargo_version) ;
199
215
}
200
216
201
- pub fn get_binary_version ( binary : & Path , ld_lib_path : & String ) -> Result < String , CheckDiffError > {
202
- let Ok ( command) = Command :: new ( binary)
203
- . env ( "LD_LIB_PATH" , ld_lib_path)
204
- . args ( [ "--version" ] )
205
- . output ( )
206
- else {
207
- return Err ( CheckDiffError :: FailedBinaryVersioning ( binary. to_path_buf ( ) ) ) ;
208
- } ;
209
-
210
- let binary_version = String :: from_utf8 ( command. stdout ) ?;
211
-
212
- return Ok ( binary_version) ;
213
- }
214
-
215
217
/// Obtains the ld_lib path and then builds rustfmt from source
216
218
/// If that operation succeeds, the source is then copied to the output path specified
217
- pub fn build_rustfmt_from_src ( binary_path : & Path ) -> Result < RustfmtRunner , CheckDiffError > {
219
+ pub fn build_rustfmt_from_src ( binary_path : PathBuf ) -> Result < RustfmtRunner , CheckDiffError > {
218
220
//Because we're building standalone binaries we need to set `LD_LIBRARY_PATH` so each
219
221
// binary can find it's runtime dependencies.
220
222
// See https://github.com/rust-lang/rustfmt/issues/5675
@@ -235,7 +237,7 @@ pub fn build_rustfmt_from_src(binary_path: &Path) -> Result<RustfmtRunner, Check
235
237
236
238
return Ok ( RustfmtRunner {
237
239
ld_library_path : ld_lib_path,
238
- binary_path : binary_path . into ( ) ,
240
+ binary_path,
239
241
} ) ;
240
242
}
241
243
@@ -252,33 +254,31 @@ pub fn compile_rustfmt(
252
254
const RUSTFMT_REPO : & str = "https://github.com/rust-lang/rustfmt.git" ;
253
255
254
256
clone_git_repo ( RUSTFMT_REPO , dest) ?;
257
+ change_directory_to_path ( dest) ?;
255
258
git_remote_add ( remote_repo_url. as_str ( ) ) ?;
256
259
git_fetch ( feature_branch. as_str ( ) ) ?;
257
260
258
261
let cargo_version = get_cargo_version ( ) ?;
259
262
info ! ( "Compiling with {}" , cargo_version) ;
260
- let rustfmt_binary = dest. join ( "/rustfmt" ) ;
261
- let src_runner = build_rustfmt_from_src ( & rustfmt_binary) ?;
263
+ let src_runner = build_rustfmt_from_src ( dest. join ( "/rustfmt" ) ) ?;
262
264
263
265
let should_detach = commit_hash. is_some ( ) ;
264
266
git_switch (
265
267
commit_hash. unwrap_or ( feature_branch) . as_str ( ) ,
266
268
should_detach,
267
269
) ?;
268
- let feature_binary = dest. join ( "/feature_rustfmt" ) ;
269
270
270
- let feature_runner = build_rustfmt_from_src ( & feature_binary ) ?;
271
+ let feature_runner = build_rustfmt_from_src ( dest . join ( "/feature_rustfmt" ) ) ?;
271
272
272
273
info ! (
273
274
"\n Runtime dependencies for rustfmt -- LD_LIBRARY_PATH: {}" ,
274
275
& feature_runner. ld_library_path
275
276
) ;
276
277
277
- let rustfmt_version = get_binary_version ( & rustfmt_binary , & feature_runner . ld_library_path ) ?;
278
+ let rustfmt_version = src_runner . get_binary_version ( ) ?;
278
279
info ! ( "\n RUSFMT_BIN {}\n " , rustfmt_version) ;
279
280
280
- let feature_binary_version =
281
- get_binary_version ( & feature_binary, & ( feature_runner. ld_library_path ) ) ?;
281
+ let feature_binary_version = feature_runner. get_binary_version ( ) ?;
282
282
info ! ( "FEATURE_BIN {}\n " , feature_binary_version) ;
283
283
284
284
return Ok ( CheckDiffRunners {
0 commit comments