1
1
use std:: { env, path:: PathBuf } ;
2
2
3
- use anyhow:: Error ;
3
+ use anyhow:: { Context , Error } ;
4
4
use structopt:: StructOpt ;
5
5
6
6
mod util;
@@ -14,33 +14,23 @@ mod visit;
14
14
struct Opt {
15
15
/// Repository root of `rust-lang/rust`.
16
16
#[ structopt( long, parse( from_os_str) ) ]
17
- repo_root : PathBuf ,
17
+ repo_root : Option < PathBuf > ,
18
18
#[ structopt( long) ]
19
19
feature : String ,
20
20
}
21
21
22
22
fn main ( ) -> Result < ( ) , Error > {
23
23
let opt = Opt :: from_iter ( env:: args ( ) . filter ( |arg| arg != "unstable-api" ) ) ;
24
24
25
+ let repo_root = match opt. repo_root {
26
+ Some ( p) => p,
27
+ None => find_repo_root ( ) ?,
28
+ } ;
29
+
25
30
let libs = vec ! [
26
- {
27
- let mut lib_core = opt. repo_root. clone( ) ;
28
- lib_core. push( "library" ) ;
29
- lib_core. push( "core" ) ;
30
- lib_core
31
- } ,
32
- {
33
- let mut lib_alloc = opt. repo_root. clone( ) ;
34
- lib_alloc. push( "library" ) ;
35
- lib_alloc. push( "alloc" ) ;
36
- lib_alloc
37
- } ,
38
- {
39
- let mut lib_std = opt. repo_root. clone( ) ;
40
- lib_std. push( "library" ) ;
41
- lib_std. push( "std" ) ;
42
- lib_std
43
- } ,
31
+ repo_root. clone( ) . join( "library/core" ) ,
32
+ repo_root. clone( ) . join( "library/alloc" ) ,
33
+ repo_root. clone( ) . join( "library/std" ) ,
44
34
] ;
45
35
46
36
for crate_root in libs {
@@ -49,3 +39,16 @@ fn main() -> Result<(), Error> {
49
39
50
40
Ok ( ( ) )
51
41
}
42
+
43
+ fn find_repo_root ( ) -> Result < PathBuf , Error > {
44
+ let path = std:: process:: Command :: new ( "cargo" )
45
+ . arg ( "locate-project" )
46
+ . arg ( "--workspace" )
47
+ . arg ( "--message-format=plain" )
48
+ . output ( )
49
+ . context ( "unable to find repository root" ) ?
50
+ . stdout ;
51
+ let mut path = PathBuf :: from ( String :: from_utf8 ( path) ?) ;
52
+ path. pop ( ) ;
53
+ Ok ( path)
54
+ }
0 commit comments