File tree Expand file tree Collapse file tree 1 file changed +14
-20
lines changed Expand file tree Collapse file tree 1 file changed +14
-20
lines changed Original file line number Diff line number Diff line change 1- use std:: env;
2- use std:: path:: PathBuf ;
1+ use std:: process:: { Command , ExitStatus , Stdio } ;
32
43#[ cfg( not( windows) ) ]
5- const CARGO_EXPAND_BIN : & str = "cargo-expand" ;
4+ const CARGO_EXPAND : & str = "cargo-expand" ;
65
76#[ cfg( windows) ]
8- const CARGO_EXPAND_BIN : & str = "cargo-expand.exe" ;
7+ const CARGO_EXPAND : & str = "cargo-expand.exe" ;
98
10- /// Scans paths in PATH env variable for a presence of `CARGO_EXPAND_BIN` file.
11- fn is_cargo_expand_present ( ) -> bool {
12- if let Ok ( var) = env:: var ( "PATH" ) {
13- for path in var. split ( ":" ) . map ( PathBuf :: from) {
14- let cargo_expand_path = path. join ( CARGO_EXPAND_BIN ) ;
15- if cargo_expand_path. exists ( ) {
16- return true ;
17- }
18- }
19- }
20-
21- false
22- }
23-
24- pub fn main ( ) {
25- if is_cargo_expand_present ( ) {
9+ fn main ( ) {
10+ if Command :: new ( CARGO_EXPAND )
11+ . arg ( "--version" )
12+ . stdin ( Stdio :: null ( ) )
13+ . stdout ( Stdio :: null ( ) )
14+ . stderr ( Stdio :: null ( ) )
15+ . status ( )
16+ . as_ref ( )
17+ . map ( ExitStatus :: success)
18+ . unwrap_or ( false )
19+ {
2620 println ! ( "cargo:rustc-cfg=cargo_expand" ) ;
2721 }
2822}
You can’t perform that action at this time.
0 commit comments