2
2
// License, v. 2.0. If a copy of the MPL was not distributed with this
3
3
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4
4
5
- use std:: process:: { Command , Stdio } ;
6
-
7
- use anyhow:: { bail, Result } ;
5
+ use anyhow:: Result ;
8
6
use clap:: { Parser , Subcommand } ;
9
- use serde_json:: { Map , Value } ;
7
+
8
+ mod task_clippy;
9
+ mod task_license;
10
+ mod util;
10
11
11
12
#[ derive( Parser ) ]
12
13
#[ command( name = "cargo xtask" , about = "Builder tasks for Propolis" ) ]
@@ -23,67 +24,13 @@ enum Cmds {
23
24
#[ arg( short, long) ]
24
25
strict : bool ,
25
26
} ,
26
- }
27
-
28
- fn workspace_root ( ) -> Result < String > {
29
- let mut cmd = Command :: new ( "cargo" ) ;
30
- cmd. args ( [ "metadata" , "--format-version=1" ] )
31
- . stdin ( Stdio :: null ( ) )
32
- . stderr ( Stdio :: inherit ( ) ) ;
33
-
34
- let output = cmd. output ( ) ?;
35
- if !output. status . success ( ) {
36
- bail ! ( "failed to query cargo metadata" ) ;
37
- }
38
- let metadata: Map < String , Value > = serde_json:: from_slice ( & output. stdout ) ?;
39
-
40
- if let Some ( Value :: String ( root) ) = metadata. get ( "workspace_root" ) {
41
- Ok ( root. clone ( ) )
42
- } else {
43
- bail ! ( "could not location workspace root" )
44
- }
45
- }
46
-
47
- fn cmd_clippy ( strict : bool ) -> Result < ( ) > {
48
- let wroot = workspace_root ( ) ?;
49
-
50
- let run_clippy = |args : & [ & str ] | -> Result < bool > {
51
- let mut cmd = Command :: new ( "cargo" ) ;
52
- cmd. arg ( "clippy" ) . arg ( "--no-deps" ) . args ( args) . current_dir ( & wroot) ;
53
-
54
- if strict {
55
- cmd. args ( [ "--" , "-Dwarnings" ] ) ;
56
- }
57
-
58
- let status = cmd. spawn ( ) ?. wait ( ) ?;
59
- Ok ( !status. success ( ) )
60
- } ;
61
-
62
- let mut failed = false ;
63
-
64
- // Everything in the workspace (including tests, etc)
65
- failed |= run_clippy ( & [ "--workspace" , "--all-targets" ] ) ?;
66
-
67
- // Check the server as it is built for production
68
- failed |=
69
- run_clippy ( & [ "-p" , "propolis-server" , "--features" , "omicron-build" ] ) ?;
70
-
71
- // Check the Falcon bits
72
- failed |= run_clippy ( & [ "-p" , "propolis-server" , "--features" , "falcon" ] ) ?;
73
-
74
- // Check the mock server
75
- failed |=
76
- run_clippy ( & [ "-p" , "propolis-server" , "--features" , "mock-only" ] ) ?;
77
-
78
- if failed {
79
- bail ! ( "Clippy failures detected" )
80
- }
81
-
82
- Ok ( ( ) )
27
+ /// (Crudely) Check for appropriate license headers
28
+ License ,
83
29
}
84
30
85
31
fn main ( ) -> Result < ( ) > {
86
32
match Args :: parse ( ) . cmd {
87
- Cmds :: Clippy { strict } => cmd_clippy ( strict) ,
33
+ Cmds :: Clippy { strict } => task_clippy:: cmd_clippy ( strict) ,
34
+ Cmds :: License => task_license:: cmd_license ( ) ,
88
35
}
89
36
}
0 commit comments