1
1
use std:: fs:: File ;
2
- use std:: io:: { BufRead , BufReader , BufWriter , Write } ;
2
+ use std:: io:: { BufRead , BufReader , BufWriter , Cursor , Write } ;
3
3
use std:: process:: { Command , Stdio } ;
4
4
5
5
use anyhow:: { Context , Result } ;
@@ -12,23 +12,25 @@ const VENDORPATH: &str = "target/vendor.tar.zstd";
12
12
13
13
fn main ( ) {
14
14
if let Err ( e) = try_main ( ) {
15
- eprintln ! ( "{e:?}" ) ;
15
+ eprintln ! ( "error: {e:?}" ) ;
16
16
std:: process:: exit ( 1 ) ;
17
17
}
18
18
}
19
19
20
- const TASKS : & [ ( & ' static str , fn ( & Shell ) -> Result < ( ) > ) ] = & [
20
+ #[ allow( clippy:: type_complexity) ]
21
+ const TASKS : & [ ( & str , fn ( & Shell ) -> Result < ( ) > ) ] = & [
21
22
( "vendor" , vendor) ,
22
23
( "package" , package) ,
23
24
( "package-srpm" , package_srpm) ,
25
+ ( "custom-lints" , custom_lints) ,
24
26
] ;
25
27
26
28
fn try_main ( ) -> Result < ( ) > {
27
29
let task = std:: env:: args ( ) . nth ( 1 ) ;
28
30
let sh = xshell:: Shell :: new ( ) ?;
29
31
if let Some ( cmd) = task. as_deref ( ) {
30
32
let f = TASKS
31
- . into_iter ( )
33
+ . iter ( )
32
34
. find_map ( |( k, f) | ( * k == cmd) . then_some ( * f) )
33
35
. unwrap_or ( print_help) ;
34
36
f ( & sh) ?;
@@ -170,6 +172,18 @@ fn package_srpm(sh: &Shell) -> Result<()> {
170
172
Ok ( ( ) )
171
173
}
172
174
175
+ fn custom_lints ( sh : & Shell ) -> Result < ( ) > {
176
+ // Verify there are no invocations of the dbg macro.
177
+ let o = cmd ! ( sh, "git grep dbg\x21 *.rs" ) . ignore_status ( ) . read ( ) ?;
178
+ if !o. is_empty ( ) {
179
+ let mut stderr = std:: io:: stderr ( ) . lock ( ) ;
180
+ std:: io:: copy ( & mut Cursor :: new ( o. as_bytes ( ) ) , & mut stderr) ?;
181
+ eprintln ! ( ) ;
182
+ anyhow:: bail!( "Found dbg\x21 macro" ) ;
183
+ }
184
+ Ok ( ( ) )
185
+ }
186
+
173
187
fn print_help ( _sh : & Shell ) -> Result < ( ) > {
174
188
println ! ( "Tasks:" ) ;
175
189
for ( name, _) in TASKS {
0 commit comments