Skip to content

Commit 12307fc

Browse files
committed
Introduce CompileFilter::from_raw_arguments
... in order to give CompileFilter::new as a better API.
1 parent 7d53e48 commit 12307fc

File tree

4 files changed

+27
-14
lines changed

4 files changed

+27
-14
lines changed

src/bin/cargo/commands/run.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
4949
.filter_map(|pkg| pkg.manifest().default_run())
5050
.collect();
5151
if default_runs.len() == 1 {
52-
compile_opts.filter = CompileFilter::new(
52+
compile_opts.filter = CompileFilter::from_raw_arguments(
5353
false,
5454
vec![default_runs[0].to_owned()],
5555
false,

src/bin/cargo/commands/test.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use cargo::ops::{self, CompileFilter};
1+
use cargo::ops::{self, CompileFilter, FilterRule};
22

33
use crate::command_prelude::*;
44

@@ -112,15 +112,10 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
112112
compile_opts.build_config.mode = CompileMode::Doctest;
113113
compile_opts.filter = ops::CompileFilter::new(
114114
true,
115-
Vec::new(),
116-
false,
117-
Vec::new(),
118-
false,
119-
Vec::new(),
120-
false,
121-
Vec::new(),
122-
false,
123-
false,
115+
FilterRule::none(),
116+
FilterRule::none(),
117+
FilterRule::none(),
118+
FilterRule::none(),
124119
);
125120
}
126121

src/cargo/ops/cargo_compile.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,10 @@ impl FilterRule {
349349
}
350350
}
351351

352+
pub fn none() -> FilterRule {
353+
FilterRule::Just(Vec::new())
354+
}
355+
352356
fn matches(&self, target: &Target) -> bool {
353357
match *self {
354358
FilterRule::All => true,
@@ -372,7 +376,8 @@ impl FilterRule {
372376
}
373377

374378
impl CompileFilter {
375-
pub fn new(
379+
/// Construct a CompileFilter from raw command line arguments.
380+
pub fn from_raw_arguments(
376381
lib_only: bool,
377382
bins: Vec<String>,
378383
all_bins: bool,
@@ -398,7 +403,20 @@ impl CompileFilter {
398403
benches: FilterRule::All,
399404
tests: FilterRule::All,
400405
}
401-
} else if lib_only
406+
} else {
407+
CompileFilter::new(lib_only, rule_bins, rule_tsts, rule_exms, rule_bens)
408+
}
409+
}
410+
411+
/// Construct a CompileFilter from underlying primitives.
412+
pub fn new(
413+
lib_only: bool,
414+
rule_bins: FilterRule,
415+
rule_tsts: FilterRule,
416+
rule_exms: FilterRule,
417+
rule_bens: FilterRule,
418+
) -> CompileFilter {
419+
if lib_only
402420
|| rule_bins.is_specific()
403421
|| rule_tsts.is_specific()
404422
|| rule_exms.is_specific()

src/cargo/util/command_prelude.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ pub trait ArgMatchesExt {
328328
all_features: self._is_present("all-features"),
329329
no_default_features: self._is_present("no-default-features"),
330330
spec,
331-
filter: CompileFilter::new(
331+
filter: CompileFilter::from_raw_arguments(
332332
self._is_present("lib"),
333333
self._values_of("bin"),
334334
self._is_present("bins"),

0 commit comments

Comments
 (0)