@@ -8,7 +8,8 @@ extern crate serde;
8
8
extern crate serde_derive;
9
9
extern crate serde_json;
10
10
11
- use cargo:: core:: { Package , PackageId , PackageSet , Source , SourceId , SourceMap , Workspace } ;
11
+ use cargo:: core:: { Package , PackageId , Source , SourceId , Workspace } ;
12
+ use cargo:: sources:: RegistrySource ;
12
13
use curl:: easy:: Easy ;
13
14
use log:: debug;
14
15
use rand:: Rng ;
@@ -94,7 +95,6 @@ fn run(config: &cargo::Config, matches: &getopts::Matches, explain: bool) -> Res
94
95
// -C "name:version" requires fetching the appropriate package:
95
96
WorkInfo :: remote (
96
97
config,
97
- SourceInfo :: new ( config) ?,
98
98
& PackageNameAndVersion :: parse ( & name_and_version) ?,
99
99
) ?
100
100
} else if let Some ( path) = matches. opt_str ( "c" ) . map ( PathBuf :: from) {
@@ -112,7 +112,7 @@ fn run(config: &cargo::Config, matches: &getopts::Matches, explain: bool) -> Res
112
112
// -S "name:version" requires fetching the appropriate package:
113
113
let info = PackageNameAndVersion :: parse ( & name_and_version) ?;
114
114
let version = info. version . to_owned ( ) ;
115
- let work_info = WorkInfo :: remote ( config, SourceInfo :: new ( config ) ? , & info) ?;
115
+ let work_info = WorkInfo :: remote ( config, & info) ?;
116
116
( work_info, version)
117
117
} else if let Some ( path) = matches. opt_str ( "s" ) {
118
118
// -s "local_path":
@@ -127,7 +127,7 @@ fn run(config: &cargo::Config, matches: &getopts::Matches, explain: bool) -> Res
127
127
name : & name,
128
128
version : & stable_crate. max_version ,
129
129
} ;
130
- let work_info = WorkInfo :: remote ( config, SourceInfo :: new ( config ) ? , & info) ?;
130
+ let work_info = WorkInfo :: remote ( config, & info) ?;
131
131
( work_info, stable_crate. max_version . clone ( ) )
132
132
} ;
133
133
@@ -341,33 +341,6 @@ impl<'a> PackageNameAndVersion<'a> {
341
341
}
342
342
}
343
343
344
- /// A specification of a package source to fetch remote packages from.
345
- pub struct SourceInfo < ' a > {
346
- /// The source id to be used.
347
- id : SourceId ,
348
- /// The source to be used.
349
- source : Box < dyn Source + ' a > ,
350
- }
351
-
352
- impl < ' a > SourceInfo < ' a > {
353
- /// Construct a new source info for `crates.io`.
354
- pub fn new ( config : & ' a cargo:: Config ) -> Result < SourceInfo < ' a > > {
355
- let source_id = SourceId :: crates_io ( config) ?;
356
- let mut source = source_id. load ( config, & HashSet :: new ( ) ) ?;
357
-
358
- debug ! ( "source id loaded: {:?}" , source_id) ;
359
-
360
- // Update the index. Without this we would not be able to fetch recent packages if the
361
- // index is not up-to-date.
362
- source. update ( ) ?;
363
-
364
- Ok ( Self {
365
- id : source_id,
366
- source,
367
- } )
368
- }
369
- }
370
-
371
344
/// A specification of a package and it's workspace.
372
345
pub struct WorkInfo < ' a > {
373
346
/// The package to be compiled.
@@ -388,25 +361,29 @@ impl<'a> WorkInfo<'a> {
388
361
/// specified `PackageNameAndVersion` from the `source`.
389
362
pub fn remote (
390
363
config : & ' a cargo:: Config ,
391
- source : SourceInfo < ' a > ,
392
364
& PackageNameAndVersion { name, version } : & PackageNameAndVersion ,
393
365
) -> Result < WorkInfo < ' a > > {
366
+ let source = {
367
+ let source_id = SourceId :: crates_io ( & config) ?;
368
+ let mut source = RegistrySource :: remote ( source_id, & HashSet :: new ( ) , config) ;
369
+
370
+ debug ! ( "source id loaded: {:?}" , source_id) ;
371
+
372
+ source. update ( ) ?;
373
+
374
+ Box :: new ( source)
375
+ } ;
376
+
394
377
// TODO: fall back to locally cached package instance, or better yet, search for it
395
378
// first.
396
- let package_ids = [ PackageId :: new ( name, version, source. id ) ?] ;
397
- debug ! ( "(remote) package id: {:?}" , package_ids[ 0 ] ) ;
398
- let sources = {
399
- let mut s = SourceMap :: new ( ) ;
400
- s. insert ( source. source ) ;
401
- s
402
- } ;
379
+ let package_id = PackageId :: new ( name, version, source. source_id ( ) ) ?;
380
+ debug ! ( "(remote) package id: {:?}" , package_id) ;
403
381
404
- let package_set = PackageSet :: new ( & package_ids, sources, config) ?;
405
- let package = package_set. get_one ( package_ids[ 0 ] ) ?;
382
+ let package = source. download_now ( package_id, config) ?;
406
383
let workspace = Workspace :: ephemeral ( package. clone ( ) , config, None , false ) ?;
407
384
408
385
Ok ( Self {
409
- package : package. clone ( ) ,
386
+ package : package,
410
387
workspace,
411
388
} )
412
389
}
0 commit comments