@@ -11,21 +11,26 @@ use std::{
11
11
ffi:: { OsStr , OsString } ,
12
12
fs:: create_dir_all,
13
13
io,
14
- path:: { Path , PathBuf } ,
14
+ path:: Path ,
15
15
process:: exit,
16
16
} ;
17
17
18
18
use cli:: get_clap_config;
19
19
use config:: Config ;
20
20
use driver:: { get_driver_path, run_driver} ;
21
- use lints:: build_local_lint_crate ;
21
+ use lints:: LintCrateSpec ;
22
22
use once_cell:: sync:: Lazy ;
23
23
24
24
use crate :: driver:: print_driver_version;
25
25
26
26
const CARGO_ARGS_SEPARATOR : & str = "--" ;
27
27
const VERSION : & str = concat ! ( "cargo-marker " , env!( "CARGO_PKG_VERSION" ) ) ;
28
28
const LINT_KRATES_BASE_DIR : & str = "./target/marker" ;
29
+ const NO_LINTS_ERROR : & str = concat ! (
30
+ "Please provide at least one valid lint crate, " ,
31
+ "with the `--lints` argument, " ,
32
+ "or `[workspace.metadata.marker.lints]` in `Cargo.toml`"
33
+ ) ;
29
34
static MARKER_LINT_DIR : Lazy < String > = Lazy :: new ( || prepare_lint_build_dir ( "marker" , "marker" ) ) ;
30
35
31
36
#[ derive( Debug ) ]
@@ -79,28 +84,21 @@ fn prepare_lint_build_dir(dir_name: &str, info_name: &str) -> String {
79
84
. to_string ( )
80
85
}
81
86
82
- fn choose_lint_crates (
83
- args : & clap:: ArgMatches ,
84
- config : Option < Config > ,
85
- ) -> Result < Vec < ( Option < String > , OsString ) > , ExitStatus > {
86
- let lint_crates : Vec < ( Option < String > , OsString ) > = match args. get_many :: < OsString > ( "lints" ) {
87
- Some ( v) => v . cloned ( ) . map ( |v| ( None , v) ) . collect ( ) ,
87
+ fn choose_lint_crates < ' a > (
88
+ args : & ' a clap:: ArgMatches ,
89
+ config : Option < & ' a Config > ,
90
+ ) -> Result < Vec < LintCrateSpec < ' a > > , ExitStatus > {
91
+ match args. get_many :: < OsString > ( "lints" ) {
92
+ Some ( v) => Ok ( v . map ( |v| LintCrateSpec :: new ( None , v. as_ref ( ) ) ) . collect ( ) ) ,
88
93
None => {
89
94
if let Some ( config) = config {
90
- config
91
- . collect_crates ( ) ?
92
- . into_iter ( )
93
- . map ( |( name, path) | ( Some ( name) , path. into ( ) ) )
94
- . collect ( )
95
+ config. collect_crates ( )
95
96
} else {
96
- eprintln ! (
97
- "Please provide at least one valid lint crate, with the `--lints` argument, or `[workspace.metadata.marker.lints]` in `Cargo.toml`"
98
- ) ;
99
- return Err ( ExitStatus :: NoLints ) ;
97
+ eprintln ! ( "{NO_LINTS_ERROR}" ) ;
98
+ Err ( ExitStatus :: NoLints )
100
99
}
101
100
} ,
102
- } ;
103
- Ok ( lint_crates)
101
+ }
104
102
}
105
103
106
104
fn main ( ) -> Result < ( ) , ExitStatus > {
@@ -130,14 +128,24 @@ fn main() -> Result<(), ExitStatus> {
130
128
131
129
match matches. subcommand ( ) {
132
130
Some ( ( "setup" , _args) ) => driver:: install_driver ( verbose, dev_build) ,
133
- Some ( ( "check" , args) ) => run_check ( & choose_lint_crates ( args, config) ?, verbose, dev_build, test_build) ,
134
- None => run_check ( & choose_lint_crates ( & matches, config) ?, verbose, dev_build, test_build) ,
131
+ Some ( ( "check" , args) ) => run_check (
132
+ & choose_lint_crates ( args, config. as_ref ( ) ) ?,
133
+ verbose,
134
+ dev_build,
135
+ test_build,
136
+ ) ,
137
+ None => run_check (
138
+ & choose_lint_crates ( & matches, config. as_ref ( ) ) ?,
139
+ verbose,
140
+ dev_build,
141
+ test_build,
142
+ ) ,
135
143
_ => unreachable ! ( ) ,
136
144
}
137
145
}
138
146
139
147
fn run_check (
140
- crate_entries : & [ ( Option < String > , OsString ) ] ,
148
+ crate_entries : & [ LintCrateSpec ] ,
141
149
verbose : bool ,
142
150
dev_build : bool ,
143
151
test_build : bool ,
@@ -148,16 +156,11 @@ fn run_check(
148
156
}
149
157
150
158
if crate_entries. is_empty ( ) {
151
- eprintln ! (
152
- "Please provide at least one valid lint crate, with the `--lints` argument, or `[workspace.metadata.marker.lints]` in `Cargo.toml`"
153
- ) ;
159
+ eprintln ! ( "{NO_LINTS_ERROR}" ) ;
154
160
return Err ( ExitStatus :: NoLints ) ;
155
161
}
156
162
157
- if crate_entries
158
- . iter ( )
159
- . any ( |( _name, path) | path. to_string_lossy ( ) . contains ( ';' ) )
160
- {
163
+ if crate_entries. iter ( ) . any ( LintCrateSpec :: validate) {
161
164
eprintln ! ( "The absolute paths of lint crates are not allowed to contain a `;`" ) ;
162
165
return Err ( ExitStatus :: InvalidValue ) ;
163
166
}
@@ -167,14 +170,8 @@ fn run_check(
167
170
println ! ( ) ;
168
171
println ! ( "Compiling Lints:" ) ;
169
172
let target_dir = Path :: new ( & * MARKER_LINT_DIR ) ;
170
- for ( name, path) in crate_entries {
171
- let src_dir = PathBuf :: from ( path) ;
172
- let crate_file = build_local_lint_crate (
173
- name. as_ref ( ) . map ( String :: as_str) ,
174
- src_dir. as_path ( ) ,
175
- target_dir,
176
- verbose,
177
- ) ?;
173
+ for krate in crate_entries {
174
+ let crate_file = krate. build_self ( target_dir, verbose) ?;
178
175
lint_crates. push ( crate_file. as_os_str ( ) . to_os_string ( ) ) ;
179
176
}
180
177
0 commit comments