1
1
use anyhow:: { anyhow, Context } ;
2
2
use chrono:: { DateTime , Utc } ;
3
3
use collector:: Sha ;
4
- use std:: ffi:: OsStr ;
5
4
use std:: fmt;
6
5
use std:: fs:: { self , File } ;
7
6
use std:: io:: { BufReader , Read } ;
8
- use std:: path:: { Path , PathBuf } ;
7
+ use std:: path:: PathBuf ;
9
8
use tar:: Archive ;
10
9
use xz2:: bufread:: XzDecoder ;
11
10
@@ -42,10 +41,11 @@ impl Sysroot {
42
41
download. get_and_extract ( ModuleVariant :: Rustc ) ?;
43
42
download. get_and_extract ( ModuleVariant :: Std ) ?;
44
43
download. get_and_extract ( ModuleVariant :: Cargo ) ?;
44
+ download. get_and_extract ( ModuleVariant :: RustSrc ) ?;
45
45
46
46
download. into_sysroot ( )
47
+ }
47
48
}
48
- }
49
49
50
50
impl Drop for Sysroot {
51
51
fn drop ( & mut self ) {
@@ -66,14 +66,15 @@ struct SysrootDownload {
66
66
triple : String ,
67
67
}
68
68
69
- const MODULE_URL : & str =
70
- "https://rust-lang-ci2.s3.amazonaws.com/rustc-builds/@SHA@/@MODULE@-nightly-@[email protected] " ;
69
+ const BASE_URL : & str = "https://rust-lang-ci2.s3.amazonaws.com/rustc-builds" ;
71
70
71
+ // FIXME(eddyb) rename to just `Component`.
72
72
#[ derive( Debug , Copy , Clone , PartialEq , Eq ) ]
73
73
enum ModuleVariant {
74
74
Cargo ,
75
75
Rustc ,
76
76
Std ,
77
+ RustSrc ,
77
78
}
78
79
79
80
impl fmt:: Display for ModuleVariant {
@@ -82,47 +83,41 @@ impl fmt::Display for ModuleVariant {
82
83
ModuleVariant :: Cargo => write ! ( f, "cargo" ) ,
83
84
ModuleVariant :: Rustc => write ! ( f, "rustc" ) ,
84
85
ModuleVariant :: Std => write ! ( f, "rust-std" ) ,
86
+ ModuleVariant :: RustSrc => write ! ( f, "rust-src" ) ,
85
87
}
86
88
}
87
89
}
88
90
89
91
impl ModuleVariant {
90
92
fn url ( & self , sysroot : & SysrootDownload , triple : & str ) -> String {
91
- MODULE_URL
92
- . replace ( "@MODULE@" , & self . to_string ( ) )
93
- . replace ( "@SHA@" , & sysroot. rust_sha )
94
- . replace ( "@TRIPLE@" , triple)
93
+ let suffix = if * self == ModuleVariant :: RustSrc {
94
+ String :: new ( )
95
+ } else {
96
+ format ! ( "-{}" , triple)
97
+ } ;
98
+ format ! (
99
+ "{base}/{sha}/{module}-nightly{suffix}.tar.xz" ,
100
+ base = BASE_URL ,
101
+ module = self ,
102
+ sha = sysroot. rust_sha,
103
+ suffix = suffix,
104
+ )
95
105
}
96
106
}
97
107
98
108
impl SysrootDownload {
99
109
fn into_sysroot ( self ) -> anyhow:: Result < Sysroot > {
110
+ let sysroot_dir = self . directory . join ( & self . rust_sha ) ;
111
+ let sysroot_dir = sysroot_dir. canonicalize ( ) . with_context ( || {
112
+ format ! (
113
+ "failed to canonicalize sysroot path for {}: {:?}" ,
114
+ self . rust_sha, sysroot_dir
115
+ )
116
+ } ) ?;
100
117
Ok ( Sysroot {
101
- rustc : self
102
- . directory
103
- . join ( & self . rust_sha )
104
- . join ( "rustc/bin/rustc" )
105
- . canonicalize ( )
106
- . with_context ( || {
107
- format ! ( "failed to canonicalize rustc path for {}" , self . rust_sha)
108
- } ) ?,
109
- rustdoc : self
110
- . directory
111
- . join ( & self . rust_sha )
112
- . join ( "rustc/bin/rustdoc" )
113
- . canonicalize ( )
114
- . with_context ( || {
115
- format ! ( "failed to canonicalize rustdoc path for {}" , self . rust_sha)
116
- } ) ?,
117
- cargo : {
118
- let path = self . directory . join ( & self . rust_sha ) . join ( "cargo/bin/cargo" ) ;
119
- path. canonicalize ( ) . with_context ( || {
120
- format ! (
121
- "failed to canonicalize cargo path for {}: {:?}" ,
122
- self . rust_sha, path
123
- )
124
- } ) ?
125
- } ,
118
+ rustc : sysroot_dir. join ( "bin/rustc" ) ,
119
+ rustdoc : sysroot_dir. join ( "bin/rustdoc" ) ,
120
+ cargo : sysroot_dir. join ( "bin/cargo" ) ,
126
121
sha : self . rust_sha ,
127
122
triple : self . triple ,
128
123
} )
@@ -161,19 +156,21 @@ impl SysrootDownload {
161
156
}
162
157
163
158
return Err ( anyhow ! (
164
- "unable to download sha {} triple {} module {}" ,
159
+ "unable to download sha {} triple {} module {} from {} " ,
165
160
self . rust_sha,
166
161
self . triple,
167
- variant
162
+ variant,
163
+ url
168
164
) ) ;
169
165
}
170
166
171
167
fn extract < T : Read > ( & self , variant : ModuleVariant , reader : T ) -> anyhow:: Result < ( ) > {
172
- let is_std = variant == ModuleVariant :: Std ;
173
168
let mut archive = Archive :: new ( reader) ;
174
- let std_prefix = format ! ( "rust-std-{}/lib/rustlib" , self . triple) ;
175
-
176
- let mut to_link = Vec :: new ( ) ;
169
+ let prefix = if variant == ModuleVariant :: Std {
170
+ format ! ( "rust-std-{}" , self . triple)
171
+ } else {
172
+ variant. to_string ( )
173
+ } ;
177
174
178
175
let unpack_into = self . directory . join ( & self . rust_sha ) ;
179
176
@@ -184,21 +181,11 @@ impl SysrootDownload {
184
181
assert ! ( components. next( ) . is_some( ) , "strip container directory" ) ;
185
182
let path = components. as_path ( ) ;
186
183
187
- let path = if is_std {
188
- if let Ok ( path) = path. strip_prefix ( & std_prefix) {
189
- if path. extension ( ) == Some ( OsStr :: new ( "dylib" ) ) {
190
- to_link. push ( path. to_owned ( ) ) ;
191
- continue ;
192
- } else {
193
- Path :: new ( "rustc/lib/rustlib" ) . join ( path)
194
- }
195
- } else {
196
- continue ;
197
- }
184
+ let path = if let Ok ( path) = path. strip_prefix ( & prefix) {
185
+ unpack_into. join ( path)
198
186
} else {
199
- path . into ( )
187
+ continue ;
200
188
} ;
201
- let path = unpack_into. join ( path) ;
202
189
fs:: create_dir_all ( & path. parent ( ) . unwrap ( ) ) . with_context ( || {
203
190
format ! (
204
191
"could not create intermediate directories for {}" ,
@@ -208,24 +195,6 @@ impl SysrootDownload {
208
195
entry. unpack ( path) ?;
209
196
}
210
197
211
- let link_dst_prefix = unpack_into. join ( format ! ( "rustc/lib/rustlib/{}/lib" , self . triple) ) ;
212
- let link_src_prefix = format ! ( "{}/lib" , self . triple) ;
213
- for path in to_link {
214
- let src = unpack_into. join ( "rustc/lib" ) . join (
215
- path. strip_prefix ( & link_src_prefix)
216
- . with_context ( || format ! ( "stripping prefix from: {:?}" , path) ) ?,
217
- ) ;
218
- let dst = link_dst_prefix. join ( & path) ;
219
- fs:: create_dir_all ( & dst. parent ( ) . unwrap ( ) ) . with_context ( || {
220
- format ! (
221
- "could not create intermediate directories for {}" ,
222
- dst. display( )
223
- )
224
- } ) ?;
225
- log:: trace!( "linking {} to {}" , src. display( ) , dst. display( ) ) ;
226
- fs:: hard_link ( src, dst) ?;
227
- }
228
-
229
198
Ok ( ( ) )
230
199
}
231
200
}
0 commit comments