@@ -18,10 +18,12 @@ const CHECK_EXTENSIONS: &[Option<&str>] = &[Some("rlib"), Some("a"), Some("exe")
18
18
19
19
const USAGE : & str = "Usage:
20
20
21
- symbol-check build-and-check CARGO_ARGS ...
21
+ symbol-check build-and-check [TARGET] -- CARGO_ARGS ...
22
22
23
- Cargo will get invoked with `CARGO_ARGS` and all output
23
+ Cargo will get invoked with `CARGO_ARGS` and the specified target. All output
24
24
`compiler_builtins*.rlib` files will be checked.
25
+
26
+ If TARGET is not specified, the host target is used.
25
27
" ;
26
28
27
29
fn main ( ) {
@@ -30,11 +32,13 @@ fn main() {
30
32
let args_ref = args. iter ( ) . map ( String :: as_str) . collect :: < Vec < _ > > ( ) ;
31
33
32
34
match & args_ref[ 1 ..] {
33
- [ "build-and-check" , "--target" , target, args @ ..] if !args. is_empty ( ) => {
34
- run_build_and_check ( Some ( target) , args) ;
35
+ [ "build-and-check" , target, "--" , args @ ..] if !args. is_empty ( ) => {
36
+ check_cargo_args ( args) ;
37
+ run_build_and_check ( target, args) ;
35
38
}
36
- [ "build-and-check" , args @ ..] if !args. is_empty ( ) => {
37
- run_build_and_check ( None , args) ;
39
+ [ "build-and-check" , "--" , args @ ..] if !args. is_empty ( ) => {
40
+ check_cargo_args ( args) ;
41
+ run_build_and_check ( & host_target ( ) , args) ;
38
42
}
39
43
_ => {
40
44
println ! ( "{USAGE}" ) ;
@@ -43,14 +47,14 @@ fn main() {
43
47
}
44
48
}
45
49
46
- fn run_build_and_check ( target : Option < & str > , args : & [ & str ] ) {
47
- let paths = exec_cargo_with_args ( target , args ) ;
48
- for path in paths {
49
- println ! ( "Checking {}" , path . display ( ) ) ;
50
- let archive = Archive :: from_path ( & path ) ;
51
-
52
- verify_no_duplicates ( & archive ) ;
53
- verify_core_symbols ( & archive ) ;
50
+ /// Make sure `-- target` isn't passed to avoid confusion (since it should be proivded only once,
51
+ /// positionally).
52
+ fn check_cargo_args ( args : & [ & str ] ) {
53
+ for arg in args {
54
+ assert ! (
55
+ !arg . contains ( "--target" ) ,
56
+ "target must be passed positionally. {USAGE}"
57
+ ) ;
54
58
}
55
59
}
56
60
@@ -68,15 +72,20 @@ fn host_target() -> String {
68
72
. to_owned ( )
69
73
}
70
74
75
+ fn run_build_and_check ( target : & str , args : & [ & str ] ) {
76
+ let paths = exec_cargo_with_args ( target, args) ;
77
+ for path in paths {
78
+ println ! ( "Checking {}" , path. display( ) ) ;
79
+ let archive = Archive :: from_path ( & path) ;
80
+
81
+ verify_no_duplicates ( & archive) ;
82
+ verify_core_symbols ( & archive) ;
83
+ }
84
+ }
85
+
71
86
/// Run `cargo build` with the provided additional arguments, collecting the list of created
72
87
/// libraries.
73
- fn exec_cargo_with_args ( target : Option < & str > , args : & [ & str ] ) -> Vec < PathBuf > {
74
- let mut host = String :: new ( ) ;
75
- let target = target. unwrap_or_else ( || {
76
- host = host_target ( ) ;
77
- host. as_str ( )
78
- } ) ;
79
-
88
+ fn exec_cargo_with_args ( target : & str , args : & [ & str ] ) -> Vec < PathBuf > {
80
89
let mut cmd = Command :: new ( "cargo" ) ;
81
90
cmd. args ( [ "build" , "--target" , target, "--message-format=json" ] )
82
91
. args ( args)
0 commit comments