@@ -20,26 +20,24 @@ use std::path::{Path, PathBuf};
2020use std:: process:: { Child , Command } ;
2121use std:: time:: Instant ;
2222
23- use dylib_util:: { dylib_path, dylib_path_var, exe} ;
23+ use shared_helpers:: {
24+ dylib_path, dylib_path_var, exe, maybe_dump, parse_rustc_stage, parse_rustc_verbose,
25+ parse_value_from_args,
26+ } ;
2427
25- #[ path = "../utils/bin_helpers.rs" ]
26- mod bin_helpers;
27-
28- #[ path = "../utils/dylib.rs" ]
29- mod dylib_util;
28+ #[ path = "../utils/shared_helpers.rs" ]
29+ mod shared_helpers;
3030
3131fn main ( ) {
3232 let orig_args = env:: args_os ( ) . skip ( 1 ) . collect :: < Vec < _ > > ( ) ;
3333 let mut args = orig_args. clone ( ) ;
34- let arg =
35- |name| orig_args. windows ( 2 ) . find ( |args| args[ 0 ] == name) . and_then ( |args| args[ 1 ] . to_str ( ) ) ;
3634
37- let stage = bin_helpers :: parse_rustc_stage ( ) ;
38- let verbose = bin_helpers :: parse_rustc_verbose ( ) ;
35+ let stage = parse_rustc_stage ( ) ;
36+ let verbose = parse_rustc_verbose ( ) ;
3937
4038 // Detect whether or not we're a build script depending on whether --target
4139 // is passed (a bit janky...)
42- let target = arg ( "--target" ) ;
40+ let target = parse_value_from_args ( & orig_args , "--target" ) ;
4341 let version = args. iter ( ) . find ( |w| & * * w == "-vV" ) ;
4442
4543 // Use a different compiler for build scripts, since there may not yet be a
@@ -102,7 +100,7 @@ fn main() {
102100 cmd. args ( & args) . env ( dylib_path_var ( ) , env:: join_paths ( & dylib_path) . unwrap ( ) ) ;
103101
104102 // Get the name of the crate we're compiling, if any.
105- let crate_name = arg ( "--crate-name" ) ;
103+ let crate_name = parse_value_from_args ( & orig_args , "--crate-name" ) ;
106104
107105 if let Some ( crate_name) = crate_name {
108106 if let Some ( target) = env:: var_os ( "RUSTC_TIME" ) {
@@ -143,10 +141,11 @@ fn main() {
143141 cmd. arg ( "-C" ) . arg ( "panic=abort" ) ;
144142 }
145143
144+ let crate_type = parse_value_from_args ( & orig_args, "--crate-type" ) ;
146145 // `-Ztls-model=initial-exec` must not be applied to proc-macros, see
147146 // issue https://github.com/rust-lang/rust/issues/100530
148147 if env:: var ( "RUSTC_TLS_MODEL_INITIAL_EXEC" ) . is_ok ( )
149- && arg ( "--crate-type" ) != Some ( "proc-macro" )
148+ && crate_type != Some ( "proc-macro" )
150149 && !matches ! ( crate_name, Some ( "proc_macro2" | "quote" | "syn" | "synstructure" ) )
151150 {
152151 cmd. arg ( "-Ztls-model=initial-exec" ) ;
@@ -251,7 +250,7 @@ fn main() {
251250 eprintln ! ( "{prefix} libdir: {libdir:?}" ) ;
252251 }
253252
254- bin_helpers :: maybe_dump ( format ! ( "stage{stage}-rustc" ) , & cmd) ;
253+ maybe_dump ( format ! ( "stage{stage}-rustc" ) , & cmd) ;
255254
256255 let start = Instant :: now ( ) ;
257256 let ( child, status) = {
0 commit comments