@@ -47,8 +47,8 @@ pub struct CompileOptions<'a> {
47
47
pub all_features : bool ,
48
48
/// Flag if the default feature should be built for the root package
49
49
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 > ,
52
52
/// Filter to apply to the root package to select which targets will be
53
53
/// built.
54
54
pub filter : CompileFilter < ' a > ,
@@ -79,6 +79,12 @@ pub enum MessageFormat {
79
79
Json
80
80
}
81
81
82
+ #[ derive( Clone , Copy , PartialEq , Eq ) ]
83
+ pub enum Packages < ' a > {
84
+ All ,
85
+ Packages ( & ' a [ String ] ) ,
86
+ }
87
+
82
88
pub enum CompileFilter < ' a > {
83
89
Everything ,
84
90
Only {
@@ -92,8 +98,10 @@ pub enum CompileFilter<'a> {
92
98
93
99
pub fn compile < ' a > ( ws : & Workspace < ' a > , options : & CompileOptions < ' a > )
94
100
-> 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
+ }
97
105
}
98
106
compile_ws ( ws, None , options)
99
107
}
@@ -103,17 +111,18 @@ pub fn resolve_dependencies<'a>(ws: &Workspace<'a>,
103
111
features : & [ String ] ,
104
112
all_features : bool ,
105
113
no_default_features : bool ,
106
- specs : & [ PackageIdSpec ] )
107
- -> CargoResult < ( PackageSet < ' a > , Resolve ) > {
114
+ specs : & Packages < ' a > )
115
+ -> CargoResult < ( Vec < PackageIdSpec > , PackageSet < ' a > , Resolve ) > {
108
116
let features = features. iter ( ) . flat_map ( |s| {
109
117
s. split_whitespace ( )
110
118
} ) . map ( |s| s. to_string ( ) ) . collect :: < Vec < String > > ( ) ;
111
119
112
120
let mut registry = PackageRegistry :: new ( ws. config ( ) ) ?;
113
121
114
122
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
+ }
117
126
}
118
127
119
128
// First, resolve the root_package's *listed* dependencies, as well as
@@ -137,22 +146,33 @@ pub fn resolve_dependencies<'a>(ws: &Workspace<'a>,
137
146
}
138
147
} ;
139
148
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
+
140
161
let resolved_with_overrides =
141
162
ops:: resolve_with_previous ( & mut registry, ws,
142
163
method, Some ( & resolve) , None ,
143
- specs) ?;
164
+ & specs) ?;
144
165
145
166
let packages = ops:: get_resolved_packages ( & resolved_with_overrides,
146
167
registry) ;
147
168
148
- Ok ( ( packages, resolved_with_overrides) )
169
+ Ok ( ( specs , packages, resolved_with_overrides) )
149
170
}
150
171
151
172
pub fn compile_ws < ' a > ( ws : & Workspace < ' a > ,
152
173
source : Option < Box < Source + ' a > > ,
153
174
options : & CompileOptions < ' a > )
154
175
-> CargoResult < ops:: Compilation < ' a > > {
155
- let root_package = ws. current ( ) ?;
156
176
let CompileOptions { config, jobs, target, spec, features,
157
177
all_features, no_default_features,
158
178
release, mode, message_format,
@@ -167,27 +187,23 @@ pub fn compile_ws<'a>(ws: &Workspace<'a>,
167
187
}
168
188
169
189
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 < _ > > > ( ) ?;
176
190
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 ;
184
198
185
199
let mut pkgids = Vec :: new ( ) ;
186
200
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 ( ) ) ?) ;
189
203
}
190
204
} else {
205
+ let root_package = ws. current ( ) ?;
206
+ generate_targets ( root_package, profiles, mode, filter, release) ?;
191
207
pkgids. push ( root_package. package_id ( ) ) ;
192
208
} ;
193
209
0 commit comments