@@ -14,6 +14,7 @@ use crate::opt::ConnectOpts;
14
14
15
15
pub struct PrepareCtx {
16
16
pub workspace : bool ,
17
+ pub all : bool ,
17
18
pub cargo : OsString ,
18
19
pub cargo_args : Vec < String > ,
19
20
pub metadata : Metadata ,
@@ -33,6 +34,7 @@ impl PrepareCtx {
33
34
34
35
pub async fn run (
35
36
check : bool ,
37
+ all : bool ,
36
38
workspace : bool ,
37
39
connect_opts : ConnectOpts ,
38
40
cargo_args : Vec < String > ,
@@ -49,6 +51,7 @@ hint: This command only works in the manifest directory of a Cargo package or wo
49
51
let metadata: Metadata = Metadata :: from_current_directory ( & cargo) ?;
50
52
let ctx = PrepareCtx {
51
53
workspace,
54
+ all,
52
55
cargo,
53
56
cargo_args,
54
57
metadata,
@@ -166,7 +169,7 @@ fn run_prepare_step(ctx: &PrepareCtx, cache_dir: &Path) -> anyhow::Result<()> {
166
169
167
170
// Try only triggering a recompile on crates that use `sqlx-macros` falling back to a full
168
171
// clean on error
169
- setup_minimal_project_recompile ( & ctx. cargo , & ctx. metadata , ctx. workspace ) ?;
172
+ setup_minimal_project_recompile ( & ctx. cargo , & ctx. metadata , ctx. all , ctx . workspace ) ?;
170
173
171
174
// Compile the queries.
172
175
let check_status = {
@@ -216,10 +219,11 @@ struct ProjectRecompileAction {
216
219
fn setup_minimal_project_recompile (
217
220
cargo : impl AsRef < OsStr > ,
218
221
metadata : & Metadata ,
222
+ all : bool ,
219
223
workspace : bool ,
220
224
) -> anyhow:: Result < ( ) > {
221
225
let recompile_action: ProjectRecompileAction = if workspace {
222
- minimal_project_recompile_action ( metadata)
226
+ minimal_project_recompile_action ( metadata, all )
223
227
} else {
224
228
// Only touch the current crate.
225
229
ProjectRecompileAction {
@@ -275,7 +279,7 @@ fn minimal_project_clean(
275
279
Ok ( ( ) )
276
280
}
277
281
278
- fn minimal_project_recompile_action ( metadata : & Metadata ) -> ProjectRecompileAction {
282
+ fn minimal_project_recompile_action ( metadata : & Metadata , all : bool ) -> ProjectRecompileAction {
279
283
// Get all the packages that depend on `sqlx-macros`
280
284
let mut sqlx_macros_dependents = BTreeSet :: new ( ) ;
281
285
let sqlx_macros_ids: BTreeSet < _ > = metadata
@@ -300,8 +304,7 @@ fn minimal_project_recompile_action(metadata: &Metadata) -> ProjectRecompileActi
300
304
}
301
305
}
302
306
303
- // In-workspace dependents have their source file's mtime updated. Out-of-workspace get
304
- // `cargo clean -p <PKGID>`ed
307
+ // In-workspace dependents have their source file's mtime updated.
305
308
let files_to_touch: Vec < _ > = in_workspace_dependents
306
309
. iter ( )
307
310
. filter_map ( |id| {
@@ -311,14 +314,22 @@ fn minimal_project_recompile_action(metadata: &Metadata) -> ProjectRecompileActi
311
314
} )
312
315
. flatten ( )
313
316
. collect ( ) ;
314
- let packages_to_clean: Vec < _ > = out_of_workspace_dependents
315
- . iter ( )
316
- . filter_map ( |id| {
317
- metadata
318
- . package ( id)
319
- . map ( |package| package. name ( ) . to_owned ( ) )
320
- } )
321
- . collect ( ) ;
317
+
318
+ // Out-of-workspace get `cargo clean -p <PKGID>`ed, only if --all is set.
319
+ let packages_to_clean: Vec < _ > = if all {
320
+ out_of_workspace_dependents
321
+ . iter ( )
322
+ . filter_map ( |id| {
323
+ metadata
324
+ . package ( id)
325
+ . map ( |package| package. name ( ) . to_owned ( ) )
326
+ } )
327
+ // Do not clean sqlx, it depends on sqlx-macros but has no queries to prepare itself.
328
+ . filter ( |name| name != "sqlx" )
329
+ . collect ( )
330
+ } else {
331
+ Vec :: new ( )
332
+ } ;
322
333
323
334
ProjectRecompileAction {
324
335
clean_packages : packages_to_clean,
@@ -366,11 +377,11 @@ mod tests {
366
377
let sample_metadata = std:: fs:: read_to_string ( sample_metadata_path) ?;
367
378
let metadata: Metadata = sample_metadata. parse ( ) ?;
368
379
369
- let action = minimal_project_recompile_action ( & metadata) ;
380
+ let action = minimal_project_recompile_action ( & metadata, false ) ;
370
381
assert_eq ! (
371
382
action,
372
383
ProjectRecompileAction {
373
- clean_packages: vec![ "sqlx" . into ( ) ] ,
384
+ clean_packages: vec![ ] ,
374
385
touch_paths: vec![
375
386
"/home/user/problematic/workspace/b_in_workspace_lib/src/lib.rs" . into( ) ,
376
387
"/home/user/problematic/workspace/c_in_workspace_bin/src/main.rs" . into( ) ,
0 commit comments