@@ -20,7 +20,8 @@ pub enum Packages {
20
20
/// Opt in all packages.
21
21
///
22
22
/// As of the time of this writing, it only works on opting in all workspace members.
23
- All ,
23
+ /// Keeps the packages passed in to verify that they exist in the workspace.
24
+ All ( Vec < String > ) ,
24
25
/// Opt out of packages passed in.
25
26
///
26
27
/// As of the time of this writing, it only works on opting out workspace members.
@@ -36,19 +37,21 @@ impl Packages {
36
37
( false , 0 , 0 ) => Packages :: Default ,
37
38
( false , 0 , _) => Packages :: Packages ( package) ,
38
39
( false , _, _) => anyhow:: bail!( "--exclude can only be used together with --workspace" ) ,
39
- ( true , 0 , _) => Packages :: All ,
40
+ ( true , 0 , _) => Packages :: All ( package ) ,
40
41
( true , _, _) => Packages :: OptOut ( exclude) ,
41
42
} )
42
43
}
43
44
44
45
/// Converts selected packages to [`PackageIdSpec`]s.
45
46
pub fn to_package_id_specs ( & self , ws : & Workspace < ' _ > ) -> CargoResult < Vec < PackageIdSpec > > {
46
47
let specs = match self {
47
- Packages :: All => ws
48
- . members ( )
49
- . map ( Package :: package_id)
50
- . map ( |id| id. to_spec ( ) )
51
- . collect ( ) ,
48
+ Packages :: All ( packages) => {
49
+ emit_packages_not_found_within_workspace ( ws, packages) ?;
50
+ ws. members ( )
51
+ . map ( Package :: package_id)
52
+ . map ( |id| id. to_spec ( ) )
53
+ . collect ( )
54
+ }
52
55
Packages :: OptOut ( opt_out) => {
53
56
let ( mut patterns, mut ids) = opt_patterns_and_ids ( opt_out) ?;
54
57
let specs = ws
@@ -111,7 +114,10 @@ impl Packages {
111
114
pub fn get_packages < ' ws > ( & self , ws : & ' ws Workspace < ' _ > ) -> CargoResult < Vec < & ' ws Package > > {
112
115
let packages: Vec < _ > = match self {
113
116
Packages :: Default => ws. default_members ( ) . collect ( ) ,
114
- Packages :: All => ws. members ( ) . collect ( ) ,
117
+ Packages :: All ( packages) => {
118
+ emit_packages_not_found_within_workspace ( ws, packages) ?;
119
+ ws. members ( ) . collect ( )
120
+ }
115
121
Packages :: OptOut ( opt_out) => {
116
122
let ( mut patterns, mut ids) = opt_patterns_and_ids ( opt_out) ?;
117
123
let packages = ws
@@ -161,7 +167,7 @@ impl Packages {
161
167
pub fn needs_spec_flag ( & self , ws : & Workspace < ' _ > ) -> bool {
162
168
match self {
163
169
Packages :: Default => ws. default_members ( ) . count ( ) > 1 ,
164
- Packages :: All => ws. members ( ) . count ( ) > 1 ,
170
+ Packages :: All ( _ ) => ws. members ( ) . count ( ) > 1 ,
165
171
Packages :: Packages ( _) => true ,
166
172
Packages :: OptOut ( _) => true ,
167
173
}
@@ -207,6 +213,32 @@ fn emit_pattern_not_found(
207
213
Ok ( ( ) )
208
214
}
209
215
216
+ fn emit_packages_not_found_within_workspace (
217
+ ws : & Workspace < ' _ > ,
218
+ packages : & [ String ] ,
219
+ ) -> CargoResult < ( ) > {
220
+ let ( mut patterns, mut ids) = opt_patterns_and_ids ( packages) ?;
221
+ let _: Vec < _ > = ws
222
+ . members ( )
223
+ . filter ( |pkg| {
224
+ let id = ids. iter ( ) . find ( |id| id. matches ( pkg. package_id ( ) ) ) . cloned ( ) ;
225
+ if let Some ( id) = & id {
226
+ ids. remove ( id) ;
227
+ }
228
+ !id. is_some ( ) && !match_patterns ( pkg, & mut patterns)
229
+ } )
230
+ . map ( Package :: package_id)
231
+ . map ( |id| id. to_spec ( ) )
232
+ . collect ( ) ;
233
+ let names = ids
234
+ . into_iter ( )
235
+ . map ( |id| id. to_string ( ) )
236
+ . collect :: < BTreeSet < _ > > ( ) ;
237
+ emit_package_not_found ( ws, names, false ) ?;
238
+ emit_pattern_not_found ( ws, patterns, false ) ?;
239
+ Ok ( ( ) )
240
+ }
241
+
210
242
/// Given a list opt-in or opt-out package selection strings, generates two
211
243
/// collections that represent glob patterns and package id specs respectively.
212
244
fn opt_patterns_and_ids (
0 commit comments