@@ -47,8 +47,8 @@ pub struct CompileOptions<'a> {
4747 pub all_features : bool ,
4848 /// Flag if the default feature should be built for the root package
4949 pub no_default_features : bool ,
50- /// Root package to build (if None it's the current one)
51- pub spec : & ' a [ String ] ,
50+ /// Root package to build (if empty it's the current one)
51+ pub spec : Packages < ' a > ,
5252 /// Filter to apply to the root package to select which targets will be
5353 /// built.
5454 pub filter : CompileFilter < ' a > ,
@@ -79,6 +79,12 @@ pub enum MessageFormat {
7979 Json
8080}
8181
82+ #[ derive( Clone , Copy , PartialEq , Eq ) ]
83+ pub enum Packages < ' a > {
84+ All ,
85+ Packages ( & ' a [ String ] ) ,
86+ }
87+
8288pub enum CompileFilter < ' a > {
8389 Everything ,
8490 Only {
@@ -92,8 +98,10 @@ pub enum CompileFilter<'a> {
9298
9399pub fn compile < ' a > ( ws : & Workspace < ' a > , options : & CompileOptions < ' a > )
94100 -> CargoResult < ops:: Compilation < ' a > > {
95- for key in ws. current ( ) ?. manifest ( ) . warnings ( ) . iter ( ) {
96- options. config . shell ( ) . warn ( key) ?
101+ for member in ws. members ( ) {
102+ for key in member. manifest ( ) . warnings ( ) . iter ( ) {
103+ options. config . shell ( ) . warn ( key) ?
104+ }
97105 }
98106 compile_ws ( ws, None , options)
99107}
@@ -103,17 +111,18 @@ pub fn resolve_dependencies<'a>(ws: &Workspace<'a>,
103111 features : & [ String ] ,
104112 all_features : bool ,
105113 no_default_features : bool ,
106- specs : & [ PackageIdSpec ] )
107- -> CargoResult < ( PackageSet < ' a > , Resolve ) > {
114+ specs : & Packages < ' a > )
115+ -> CargoResult < ( Vec < PackageIdSpec > , PackageSet < ' a > , Resolve ) > {
108116 let features = features. iter ( ) . flat_map ( |s| {
109117 s. split_whitespace ( )
110118 } ) . map ( |s| s. to_string ( ) ) . collect :: < Vec < String > > ( ) ;
111119
112120 let mut registry = PackageRegistry :: new ( ws. config ( ) ) ?;
113121
114122 if let Some ( source) = source {
115- registry. add_preloaded ( ws. current ( ) ?. package_id ( ) . source_id ( ) ,
116- source) ;
123+ if let Some ( root_package) = ws. current_opt ( ) {
124+ registry. add_preloaded ( root_package. package_id ( ) . source_id ( ) , source) ;
125+ }
117126 }
118127
119128 // First, resolve the root_package's *listed* dependencies, as well as
@@ -137,22 +146,33 @@ pub fn resolve_dependencies<'a>(ws: &Workspace<'a>,
137146 }
138147 } ;
139148
149+ let specs = match * specs {
150+ Packages :: All => {
151+ ws. members ( )
152+ . map ( Package :: package_id)
153+ . map ( PackageIdSpec :: from_package_id)
154+ . collect ( )
155+ }
156+ Packages :: Packages ( packages) => {
157+ packages. iter ( ) . map ( |p| PackageIdSpec :: parse ( & p) ) . collect :: < CargoResult < Vec < _ > > > ( ) ?
158+ }
159+ } ;
160+
140161 let resolved_with_overrides =
141162 ops:: resolve_with_previous ( & mut registry, ws,
142163 method, Some ( & resolve) , None ,
143- specs) ?;
164+ & specs) ?;
144165
145166 let packages = ops:: get_resolved_packages ( & resolved_with_overrides,
146167 registry) ;
147168
148- Ok ( ( packages, resolved_with_overrides) )
169+ Ok ( ( specs , packages, resolved_with_overrides) )
149170}
150171
151172pub fn compile_ws < ' a > ( ws : & Workspace < ' a > ,
152173 source : Option < Box < Source + ' a > > ,
153174 options : & CompileOptions < ' a > )
154175 -> CargoResult < ops:: Compilation < ' a > > {
155- let root_package = ws. current ( ) ?;
156176 let CompileOptions { config, jobs, target, spec, features,
157177 all_features, no_default_features,
158178 release, mode, message_format,
@@ -167,27 +187,23 @@ pub fn compile_ws<'a>(ws: &Workspace<'a>,
167187 }
168188
169189 let profiles = ws. profiles ( ) ;
170- if spec. len ( ) == 0 {
171- generate_targets ( root_package, profiles, mode, filter, release) ?;
172- }
173-
174- let specs = spec. iter ( ) . map ( |p| PackageIdSpec :: parse ( p) )
175- . collect :: < CargoResult < Vec < _ > > > ( ) ?;
176190
177- let pair = resolve_dependencies ( ws,
178- source,
179- features,
180- all_features,
181- no_default_features,
182- & specs ) ?;
183- let ( packages, resolve_with_overrides) = pair ;
191+ let resolve = resolve_dependencies ( ws,
192+ source,
193+ features,
194+ all_features,
195+ no_default_features,
196+ & spec ) ?;
197+ let ( spec , packages, resolve_with_overrides) = resolve ;
184198
185199 let mut pkgids = Vec :: new ( ) ;
186200 if spec. len ( ) > 0 {
187- for p in spec {
188- pkgids. push ( resolve_with_overrides . query ( & p ) ?) ;
201+ for p in spec. iter ( ) {
202+ pkgids. push ( p . query ( resolve_with_overrides . iter ( ) ) ?) ;
189203 }
190204 } else {
205+ let root_package = ws. current ( ) ?;
206+ generate_targets ( root_package, profiles, mode, filter, release) ?;
191207 pkgids. push ( root_package. package_id ( ) ) ;
192208 } ;
193209
0 commit comments