@@ -20,7 +20,8 @@ pub enum Packages {
2020 /// Opt in all packages.
2121 ///
2222 /// 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 > ) ,
2425 /// Opt out of packages passed in.
2526 ///
2627 /// As of the time of this writing, it only works on opting out workspace members.
@@ -36,19 +37,21 @@ impl Packages {
3637 ( false , 0 , 0 ) => Packages :: Default ,
3738 ( false , 0 , _) => Packages :: Packages ( package) ,
3839 ( false , _, _) => anyhow:: bail!( "--exclude can only be used together with --workspace" ) ,
39- ( true , 0 , _) => Packages :: All ,
40+ ( true , 0 , _) => Packages :: All ( package ) ,
4041 ( true , _, _) => Packages :: OptOut ( exclude) ,
4142 } )
4243 }
4344
4445 /// Converts selected packages to [`PackageIdSpec`]s.
4546 pub fn to_package_id_specs ( & self , ws : & Workspace < ' _ > ) -> CargoResult < Vec < PackageIdSpec > > {
4647 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+ }
5255 Packages :: OptOut ( opt_out) => {
5356 let ( mut patterns, mut ids) = opt_patterns_and_ids ( opt_out) ?;
5457 let specs = ws
@@ -111,7 +114,10 @@ impl Packages {
111114 pub fn get_packages < ' ws > ( & self , ws : & ' ws Workspace < ' _ > ) -> CargoResult < Vec < & ' ws Package > > {
112115 let packages: Vec < _ > = match self {
113116 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+ }
115121 Packages :: OptOut ( opt_out) => {
116122 let ( mut patterns, mut ids) = opt_patterns_and_ids ( opt_out) ?;
117123 let packages = ws
@@ -161,7 +167,7 @@ impl Packages {
161167 pub fn needs_spec_flag ( & self , ws : & Workspace < ' _ > ) -> bool {
162168 match self {
163169 Packages :: Default => ws. default_members ( ) . count ( ) > 1 ,
164- Packages :: All => ws. members ( ) . count ( ) > 1 ,
170+ Packages :: All ( _ ) => ws. members ( ) . count ( ) > 1 ,
165171 Packages :: Packages ( _) => true ,
166172 Packages :: OptOut ( _) => true ,
167173 }
@@ -207,6 +213,32 @@ fn emit_pattern_not_found(
207213 Ok ( ( ) )
208214}
209215
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+
210242/// Given a list opt-in or opt-out package selection strings, generates two
211243/// collections that represent glob patterns and package id specs respectively.
212244fn opt_patterns_and_ids (
0 commit comments