1
+ //! Filters and their rules to select which Cargo targets will be built.
2
+
1
3
use crate :: core:: compiler:: CompileMode ;
2
4
use crate :: core:: { Target , TargetKind } ;
3
5
use crate :: util:: restricted_names:: is_glob_pattern;
@@ -27,7 +29,10 @@ pub enum FilterRule {
27
29
///
28
30
/// The actual filter process happens inside [`generate_targets`].
29
31
///
32
+ /// Not to be confused with [`Packages`], which opts in packages to be built.
33
+ ///
30
34
/// [`generate_targets`]: super::generate_targets
35
+ /// [`Packages`]: crate::ops::Packages
31
36
#[ derive( Debug ) ]
32
37
pub enum CompileFilter {
33
38
/// The default set of Cargo targets.
@@ -56,17 +61,25 @@ impl FilterRule {
56
61
}
57
62
}
58
63
64
+ /// Creates a filter with no rule.
65
+ ///
66
+ /// In the current Cargo implementation, filter without a rule implies
67
+ /// Cargo will follows the default behaviour to filter targets.
59
68
pub fn none ( ) -> FilterRule {
60
69
FilterRule :: Just ( Vec :: new ( ) )
61
70
}
62
71
72
+ /// Checks if a target definition matches this filter rule.
63
73
fn matches ( & self , target : & Target ) -> bool {
64
74
match * self {
65
75
FilterRule :: All => true ,
66
76
FilterRule :: Just ( ref targets) => targets. iter ( ) . any ( |x| * x == target. name ( ) ) ,
67
77
}
68
78
}
69
79
80
+ /// Check if a filter is specific.
81
+ ///
82
+ /// Only filters without rules are considered as not specific.
70
83
fn is_specific ( & self ) -> bool {
71
84
match * self {
72
85
FilterRule :: All => true ,
@@ -81,6 +94,7 @@ impl FilterRule {
81
94
}
82
95
}
83
96
97
+ /// Checks if any specified target name contains glob patterns.
84
98
pub ( crate ) fn contains_glob_patterns ( & self ) -> bool {
85
99
match self {
86
100
FilterRule :: All => false ,
@@ -274,6 +288,7 @@ impl CompileFilter {
274
288
)
275
289
}
276
290
291
+ /// Checks if any specified target name contains glob patterns.
277
292
pub ( crate ) fn contains_glob_patterns ( & self ) -> bool {
278
293
match self {
279
294
CompileFilter :: Default { .. } => false ,
0 commit comments