6
6
use std:: path:: { Path , PathBuf } ;
7
7
use std:: env;
8
8
9
- use cargo:: core:: { SourceId , Dependency , Registry , Source , Package } ;
9
+ use cargo:: core:: { SourceId , Dependency , Registry , Source , Package , Workspace } ;
10
10
use cargo:: util:: { CargoResult , Config , human, Filesystem } ;
11
- use cargo:: sources:: RegistrySource ;
12
- use cargo:: { ops, ChainError } ;
11
+ use cargo:: sources:: SourceConfigMap ;
12
+ use cargo:: ops;
13
13
14
14
15
15
/// Builds documentation of a crate and version.
@@ -22,9 +22,10 @@ use cargo::{ops, ChainError};
22
22
// instead of doing it manually like in the previous version of cratesfyi
23
23
pub fn build_doc ( name : & str , vers : Option < & str > , target : Option < & str > ) -> CargoResult < Package > {
24
24
let config = try!( Config :: default ( ) ) ;
25
- let source_id = try!( SourceId :: for_central ( & config) ) ;
25
+ let source_id = try!( SourceId :: crates_io ( & config) ) ;
26
26
27
- let mut source = RegistrySource :: new ( & source_id, & config) ;
27
+ let source_map = try!( SourceConfigMap :: new ( & config) ) ;
28
+ let mut source = try!( source_map. load ( & source_id) ) ;
28
29
29
30
// update crates.io-index registry
30
31
try!( source. update ( ) ) ;
@@ -38,10 +39,8 @@ pub fn build_doc(name: &str, vers: Option<&str>, target: Option<&str>) -> CargoR
38
39
. unwrap_or ( Err ( human ( "PKG download error" ) ) ) ) ;
39
40
40
41
let current_dir = try!( env:: current_dir ( ) ) ;
41
- let target_dir = PathBuf :: from ( current_dir) . join (
42
- format ! ( "{}-{}" , pkg. manifest( ) . name( ) , pkg. manifest( ) . version( ) ) ) ;
43
-
44
- config. set_target_dir ( Filesystem :: new ( target_dir. clone ( ) ) ) ;
42
+ let target_dir = PathBuf :: from ( current_dir)
43
+ . join ( format ! ( "{}-{}" , pkg. manifest( ) . name( ) , pkg. manifest( ) . version( ) ) ) ;
45
44
46
45
let opts = ops:: CompileOptions {
47
46
config : & config,
@@ -58,12 +57,11 @@ pub fn build_doc(name: &str, vers: Option<&str>, target: Option<&str>) -> CargoR
58
57
target_rustdoc_args : None ,
59
58
} ;
60
59
61
- try!( ops:: compile_pkg ( & pkg, Some ( Box :: new ( source) ) , & opts) . chain_error ( || {
62
- human ( format ! ( "failed to compile `{}`, intermediate artifacts can be \
63
- found at `{}`", pkg, target_dir. display( ) ) )
64
- } ) ) ;
60
+ let ws = try!( Workspace :: one ( pkg, & config, Some ( Filesystem :: new ( target_dir) ) ) ) ;
65
61
66
- Ok ( pkg)
62
+ try!( ops:: compile_ws ( & ws, Some ( source) , & opts) ) ;
63
+
64
+ Ok ( try!( ws. current ( ) ) . clone ( ) )
67
65
}
68
66
69
67
@@ -72,9 +70,10 @@ pub fn build_doc(name: &str, vers: Option<&str>, target: Option<&str>) -> CargoR
72
70
pub fn get_package ( name : & str , vers : Option < & str > ) -> CargoResult < Package > {
73
71
debug ! ( "Getting package with cargo" ) ;
74
72
let config = try!( Config :: default ( ) ) ;
75
- let source_id = try!( SourceId :: for_central ( & config) ) ;
73
+ let source_id = try!( SourceId :: crates_io ( & config) ) ;
76
74
77
- let mut source = RegistrySource :: new ( & source_id, & config) ;
75
+ let source_map = try!( SourceConfigMap :: new ( & config) ) ;
76
+ let mut source = try!( source_map. load ( & source_id) ) ;
78
77
79
78
let dep = try!( Dependency :: parse ( name, vers, & source_id) ) ;
80
79
let deps = try!( source. query ( & dep) ) ;
@@ -91,9 +90,10 @@ pub fn get_package(name: &str, vers: Option<&str>) -> CargoResult<Package> {
91
90
/// Updates central crates-io.index repository
92
91
pub fn update_sources ( ) -> CargoResult < ( ) > {
93
92
let config = try!( Config :: default ( ) ) ;
94
- let source_id = try!( SourceId :: for_central ( & config) ) ;
93
+ let source_id = try!( SourceId :: crates_io ( & config) ) ;
95
94
96
- let mut source = RegistrySource :: new ( & source_id, & config) ;
95
+ let source_map = try!( SourceConfigMap :: new ( & config) ) ;
96
+ let mut source = try!( source_map. load ( & source_id) ) ;
97
97
98
98
source. update ( )
99
99
}
0 commit comments