1
1
//! FIXME: write short doc here
2
2
3
+ mod cmd;
3
4
pub mod codegen;
4
5
pub mod install;
5
6
pub mod pre_commit;
6
7
mod ast_src;
7
8
8
9
use anyhow:: Context ;
9
- pub use anyhow:: Result ;
10
10
use std:: {
11
11
env,
12
12
path:: { Path , PathBuf } ,
13
- process:: { Command , Output , Stdio } ,
13
+ process:: { Command , Stdio } ,
14
14
} ;
15
15
16
16
use crate :: codegen:: Mode ;
17
17
18
+ pub use anyhow:: Result ;
19
+ pub use cmd:: { run, run_with_output, Cmd } ;
20
+
18
21
const TOOLCHAIN : & str = "stable" ;
19
22
20
23
pub fn project_root ( ) -> PathBuf {
@@ -27,40 +30,6 @@ pub fn project_root() -> PathBuf {
27
30
. to_path_buf ( )
28
31
}
29
32
30
- pub struct Cmd < ' a > {
31
- pub unix : & ' a str ,
32
- pub windows : & ' a str ,
33
- pub work_dir : & ' a str ,
34
- }
35
-
36
- impl Cmd < ' _ > {
37
- pub fn run ( self ) -> Result < ( ) > {
38
- if cfg ! ( windows) {
39
- run ( self . windows , self . work_dir )
40
- } else {
41
- run ( self . unix , self . work_dir )
42
- }
43
- }
44
- pub fn run_with_output ( self ) -> Result < Output > {
45
- if cfg ! ( windows) {
46
- run_with_output ( self . windows , self . work_dir )
47
- } else {
48
- run_with_output ( self . unix , self . work_dir )
49
- }
50
- }
51
- }
52
-
53
- pub fn run ( cmdline : & str , dir : & str ) -> Result < ( ) > {
54
- do_run ( cmdline, dir, |c| {
55
- c. stdout ( Stdio :: inherit ( ) ) ;
56
- } )
57
- . map ( |_| ( ) )
58
- }
59
-
60
- pub fn run_with_output ( cmdline : & str , dir : & str ) -> Result < Output > {
61
- do_run ( cmdline, dir, |_| { } )
62
- }
63
-
64
33
pub fn run_rustfmt ( mode : Mode ) -> Result < ( ) > {
65
34
match Command :: new ( "rustup" )
66
35
. args ( & [ "run" , TOOLCHAIN , "--" , "cargo" , "fmt" , "--version" ] )
@@ -132,20 +101,3 @@ pub fn run_fuzzer() -> Result<()> {
132
101
133
102
run ( "rustup run nightly -- cargo fuzz run parser" , "./crates/ra_syntax" )
134
103
}
135
-
136
- fn do_run < F > ( cmdline : & str , dir : & str , mut f : F ) -> Result < Output >
137
- where
138
- F : FnMut ( & mut Command ) ,
139
- {
140
- eprintln ! ( "\n will run: {}" , cmdline) ;
141
- let proj_dir = project_root ( ) . join ( dir) ;
142
- let mut args = cmdline. split_whitespace ( ) ;
143
- let exec = args. next ( ) . unwrap ( ) ;
144
- let mut cmd = Command :: new ( exec) ;
145
- f ( cmd. args ( args) . current_dir ( proj_dir) . stderr ( Stdio :: inherit ( ) ) ) ;
146
- let output = cmd. output ( ) . with_context ( || format ! ( "running `{}`" , cmdline) ) ?;
147
- if !output. status . success ( ) {
148
- anyhow:: bail!( "`{}` exited with {}" , cmdline, output. status) ;
149
- }
150
- Ok ( output)
151
- }
0 commit comments