@@ -170,103 +170,97 @@ fn install_one(
170
170
171
171
let dst = root. join ( "bin" ) . into_path_unlocked ( ) ;
172
172
173
- let dependency = {
174
- if let Some ( krate) = krate {
175
- let vers = if source_id. is_git ( ) || source_id. is_path ( ) {
176
- // We explicitly ignore the version flag for these source types.
177
- None
178
- } else if let Some ( vers_flag) = vers {
179
- Some ( parse_semver_flag ( vers_flag) ?. to_string ( ) )
180
- } else {
181
- if source_id. is_registry ( ) {
182
- // Avoid pre-release versions from crate.io
183
- // unless explicitly asked for
184
- Some ( String :: from ( "*" ) )
173
+ let pkg = {
174
+ let dep = {
175
+ if let Some ( krate) = krate {
176
+ let vers = if let Some ( vers_flag) = vers {
177
+ Some ( parse_semver_flag ( vers_flag) ?. to_string ( ) )
185
178
} else {
186
- None
187
- }
188
- } ;
189
- Some ( Dependency :: parse_no_deprecated (
190
- krate,
191
- vers. as_deref ( ) ,
192
- source_id,
193
- ) ?)
194
- } else {
195
- None
196
- }
197
- } ;
198
-
199
- let pkg = if source_id. is_git ( ) {
200
- let dep_or_list_all_fn = if let Some ( dep) = dependency {
201
- DependencyOrListAllFn :: Dependency ( dep)
202
- } else {
203
- DependencyOrListAllFn :: ListAllFn ( |git : & mut GitSource < ' _ > | git. read_packages ( ) )
179
+ if source_id. is_registry ( ) {
180
+ // Avoid pre-release versions from crate.io
181
+ // unless explicitly asked for
182
+ Some ( String :: from ( "*" ) )
183
+ } else {
184
+ None
185
+ }
186
+ } ;
187
+ Some ( Dependency :: parse_no_deprecated (
188
+ krate,
189
+ vers. as_deref ( ) ,
190
+ source_id,
191
+ ) ?)
192
+ } else {
193
+ None
194
+ }
204
195
} ;
205
- select_pkg (
206
- & mut GitSource :: new ( source_id, config) ?,
207
- dep_or_list_all_fn,
208
- config,
209
- true ,
210
- ) ?
211
- } else if source_id. is_path ( ) {
212
- let mut src = path_source ( source_id, config) ?;
213
- if !src. path ( ) . is_dir ( ) {
214
- bail ! (
215
- "`{}` is not a directory. \
216
- --path must point to a directory containing a Cargo.toml file.",
217
- src. path( ) . display( )
218
- )
219
- }
220
- if !src. path ( ) . join ( "Cargo.toml" ) . exists ( ) {
221
- if from_cwd {
196
+
197
+ if source_id. is_git ( ) {
198
+ let mut source = GitSource :: new ( source_id, config) ?;
199
+ select_pkg (
200
+ & mut source,
201
+ dep,
202
+ |git : & mut GitSource < ' _ > | git. read_packages ( ) ,
203
+ config,
204
+ ) ?
205
+ } else if source_id. is_path ( ) {
206
+ let mut src = path_source ( source_id, config) ?;
207
+ if !src. path ( ) . is_dir ( ) {
222
208
bail ! (
223
- "`{}` is not a crate root; specify a crate to \
209
+ "`{}` is not a directory. \
210
+ --path must point to a directory containing a Cargo.toml file.",
211
+ src. path( ) . display( )
212
+ )
213
+ }
214
+ if !src. path ( ) . join ( "Cargo.toml" ) . exists ( ) {
215
+ if from_cwd {
216
+ bail ! (
217
+ "`{}` is not a crate root; specify a crate to \
224
218
install from crates.io, or use --path or --git to \
225
219
specify an alternate source",
226
- src. path( ) . display( )
227
- ) ;
228
- } else {
229
- bail ! (
230
- "`{}` does not contain a Cargo.toml file. \
220
+ src. path( ) . display( )
221
+ ) ;
222
+ } else {
223
+ bail ! (
224
+ "`{}` does not contain a Cargo.toml file. \
231
225
--path must point to a directory containing a Cargo.toml file.",
232
- src. path( ) . display( )
233
- )
226
+ src. path( ) . display( )
227
+ )
228
+ }
234
229
}
235
- }
236
- src. update ( ) ?;
237
-
238
- let dep_or_list_all_fn = if let Some ( dep) = dependency {
239
- DependencyOrListAllFn :: Dependency ( dep)
230
+ select_pkg (
231
+ & mut src,
232
+ dep,
233
+ |path : & mut PathSource < ' _ > | path. read_packages ( ) ,
234
+ config,
235
+ ) ?
240
236
} else {
241
- DependencyOrListAllFn :: ListAllFn ( |path : & mut PathSource < ' _ > | path. read_packages ( ) )
242
- } ;
243
- select_pkg ( & mut src, dep_or_list_all_fn, config, false ) ?
244
- } else {
245
- if !dependency. is_some ( ) {
246
- bail ! (
247
- "must specify a crate to install from \
237
+ if let Some ( dep) = dep {
238
+ let mut source = map. load ( source_id, & HashSet :: new ( ) ) ?;
239
+ if let Ok ( Some ( pkg) ) = installed_exact_package (
240
+ dep. clone ( ) ,
241
+ & mut source,
242
+ config,
243
+ opts,
244
+ root,
245
+ & dst,
246
+ force,
247
+ ) {
248
+ let msg = format ! (
249
+ "package `{}` is already installed, use --force to override" ,
250
+ pkg
251
+ ) ;
252
+ config. shell ( ) . status ( "Ignored" , & msg) ?;
253
+ return Ok ( true ) ;
254
+ }
255
+ select_dep_pkg ( & mut source, dep, config, needs_update_if_source_is_index) ?
256
+ } else {
257
+ bail ! (
258
+ "must specify a crate to install from \
248
259
crates.io, or use --path or --git to \
249
260
specify alternate source"
250
- )
251
- }
252
- let dep = dependency. unwrap ( ) ; // Verified with is_some/bail above.
253
- let mut source = map. load ( source_id, & HashSet :: new ( ) ) ?;
254
- if let Ok ( Some ( pkg) ) =
255
- installed_exact_package ( dep. clone ( ) , & mut source, config, opts, root, & dst, force)
256
- {
257
- let msg = format ! (
258
- "package `{}` is already installed, use --force to override" ,
259
- pkg
260
- ) ;
261
- config. shell ( ) . status ( "Ignored" , & msg) ?;
262
- return Ok ( true ) ;
261
+ )
262
+ }
263
263
}
264
- select_pkg (
265
- & mut source,
266
- DependencyOrListAllFn :: < fn ( & mut Box < dyn Source > ) -> CargoResult < Vec < Package > > > :: Dependency ( dep) ,
267
- config,
268
- needs_update_if_source_is_index,
269
- ) ?
270
264
} ;
271
265
272
266
let git_package = if source_id. is_git ( ) {
@@ -578,12 +572,7 @@ where
578
572
// expensive network call in the case that the package is already installed.
579
573
// If this fails, the caller will possibly do an index update and try again, this is just a
580
574
// best-effort check to see if we can avoid hitting the network.
581
- if let Ok ( pkg) = select_pkg (
582
- source,
583
- DependencyOrListAllFn :: < fn ( & mut T ) -> CargoResult < Vec < Package > > > :: Dependency ( dep) ,
584
- config,
585
- false ,
586
- ) {
575
+ if let Ok ( pkg) = select_dep_pkg ( source, dep, config, false ) {
587
576
let ( _ws, rustc, target) =
588
577
make_ws_rustc_target ( & config, opts, & source. source_id ( ) , pkg. clone ( ) ) ?;
589
578
if let Ok ( true ) = is_installed ( & pkg, config, opts, & rustc, & target, root, & dst, force) {
@@ -644,6 +633,7 @@ fn parse_semver_flag(v: &str) -> CargoResult<VersionReq> {
644
633
) ,
645
634
}
646
635
} else {
636
+ println ! ( "DWH: Converting..." ) ;
647
637
match v. to_semver ( ) {
648
638
Ok ( v) => Ok ( VersionReq :: exact ( & v) ) ,
649
639
Err ( e) => {
0 commit comments