@@ -172,6 +172,9 @@ def main():
172
172
print "cargo version: " + cargo_version
173
173
print "cargo short version: " + cargo_short_version
174
174
175
+ # Download cargo binaries into the correct location
176
+ download_cargos (cargo_rev , cargo_short_version )
177
+
175
178
# Validate the component artifacts and generate the manifest
176
179
generate_manifest (rustc_date , rustc_version , rustc_short_version ,
177
180
cargo_rev , cargo_version , cargo_short_version )
@@ -189,15 +192,43 @@ def most_recent_build_date(channel, component):
189
192
date = response .read ().strip ();
190
193
return date
191
194
195
+ def cargo_ci_url (cargo_rev , target ):
196
+ installer_name = "cargo-nightly-" + target + ".tar.gz"
197
+ installer_url = cargo_addy + "/" + cargo_rev + "/" + installer_name
198
+ return installer_url
199
+
200
+ # The name of the cargo installer in it's final location on s.rlo
201
+ # Unlike the files produced by cargo CI that are all called "-nightly", the
202
+ # live installers mirror the rust naming scheme for the beta/stable channels
203
+ # using either "-beta" or the cargo version number in the file name.
204
+ # This is to avoid naming conflicts in the s.rlo dist archives.
205
+ def cargo_live_name (short_version , target ):
206
+ # This mirrors the logic in url_and_hash_of_rust_package
207
+ version = channel
208
+ if channel == "stable" : version = short_version
209
+ return "cargo-" + version + "-" + target + ".tar.gz"
210
+
211
+ def cargo_live_url (short_version , target ):
212
+ file_name = cargo_live_name (short_version , target )
213
+ url = public_addy + "/dist/" + today + "/" + file_name
214
+ return url
215
+
216
+ # This is the path where we are putting the cargo binaries,
217
+ # downloaded from rust-lang-ci, to upload to static.rlo.
218
+ # This path corresponds to the dist/ directory, and buildbot
219
+ # will upload it to both dist/ and the archives.
220
+ def cargo_local_path (short_version , target ):
221
+ file_name = cargo_live_name (short_version , target )
222
+ return rust_package_dir + "/" + file_name
223
+
192
224
# Read the v1 manifests to find the installer name, download it
193
225
# and extract the version file.
194
226
def version_from_channel (channel , component , date_or_sha ):
195
227
dist = dist_folder (component )
196
228
197
229
if component == "cargo" :
198
- target = "x86_64-unknown-linux-gnu"
199
- installer_name = "cargo-nightly-" + target + ".tar.gz"
200
- installer_url = cargo_addy + "/" + date_or_sha + "/" + installer_name
230
+ installer_url = cargo_ci_url (date_or_sha , "x86_64-unknown-linux-gnu" )
231
+ local_name = "cargo.tar.gz"
201
232
else :
202
233
# Load the manifest
203
234
manifest_url = s3_addy + "/" + dist + "/" + date_or_sha + "/channel-" + component + "-" + channel
@@ -217,20 +248,11 @@ def version_from_channel(channel, component, date_or_sha):
217
248
raise Exception ("couldn't find installer in manifest for " + component )
218
249
219
250
installer_url = s3_addy + "/" + dist + "/" + date_or_sha + "/" + installer_name
251
+ local_name = installer_name
220
252
221
253
# Download the installer
222
- print "downloading " + installer_url
223
- response = urllib2 .urlopen (installer_url )
224
- if response .getcode () != 200 :
225
- raise Exception ("couldn't download " + installer_url )
226
-
227
- installer_file = temp_dir + "/" + installer_name
228
- f = open (installer_file , "w" )
229
- while True :
230
- buf = response .read (4096 )
231
- if not buf : break
232
- f .write (buf )
233
- f .close ()
254
+ installer_file = temp_dir + "/" + local_name
255
+ download_file (installer_url , installer_file )
234
256
235
257
# Unpack the installer
236
258
unpack_dir = temp_dir + "/unpack"
@@ -264,6 +286,29 @@ def parse_short_version(version):
264
286
raise Exception ("couldn't parse version: " + version )
265
287
return v
266
288
289
+ def download_cargos (cargo_rev , short_version ):
290
+ for host in host_list :
291
+ download_cargo (cargo_rev , short_version , host )
292
+
293
+ def download_cargo (cargo_rev , short_version , host ):
294
+ ci_url = cargo_ci_url (cargo_rev , host )
295
+ local_path = cargo_local_path (short_version , host )
296
+ download_file (ci_url , local_path )
297
+
298
+ def download_file (url , path ):
299
+ print "downloading " + url + " to " + path
300
+ response = urllib2 .urlopen (url )
301
+ if response .getcode () != 200 :
302
+ raise Exception ("couldn't download " + url )
303
+
304
+ f = open (path , "w" )
305
+ while True :
306
+ buf = response .read (4096 )
307
+ if not buf : break
308
+ f .write (buf )
309
+ f .close ()
310
+ response .close ()
311
+
267
312
def generate_manifest (rustc_date , rustc_version , rustc_short_version ,
268
313
cargo_rev , cargo_version , cargo_short_version ):
269
314
@@ -298,9 +343,8 @@ def build_manifest(rustc_date, rustc_version, rustc_short_version,
298
343
doc_pkg = build_package_def_from_archive ("rust-docs" , "dist" , rustc_date ,
299
344
rustc_version , rustc_short_version ,
300
345
host_list )
301
- cargo_pkg = build_package_def_from_archive ("cargo" , "cargo-dist" , cargo_rev ,
302
- cargo_version , cargo_short_version ,
303
- host_list )
346
+ cargo_pkg = build_package_def_for_cargo (cargo_version , cargo_short_version ,
347
+ host_list )
304
348
mingw_pkg = build_package_def_from_archive ("rust-mingw" , "dist" , rustc_date ,
305
349
rustc_version , rustc_short_version ,
306
350
mingw_list )
@@ -396,14 +440,46 @@ def build_manifest(rustc_date, rustc_version, rustc_short_version,
396
440
# from the archives.
397
441
def build_package_def_from_archive (name , dist_dir , archive_date ,
398
442
version , short_version , target_list ):
443
+ assert name != "cargo"
444
+
399
445
target_pkgs = {}
400
446
for target in target_list :
401
447
url = live_package_url (name , dist_dir , archive_date , short_version , target )
402
448
if url is not None :
449
+ hash = hash_from_s3_installer (url )
403
450
target_pkgs [target ] = {
404
451
"available" : True ,
405
452
"url" : url .replace (s3_addy , public_addy ),
406
- "hash" : hash_from_s3_installer (url ),
453
+ "hash" : hash
454
+ }
455
+ else :
456
+ print "error: " + name + " for " + target + " not available"
457
+ target_pkgs [target ] = {
458
+ "available" : False ,
459
+ "url" : "" ,
460
+ "hash" : ""
461
+ }
462
+
463
+ return {
464
+ "version" : version ,
465
+ "target" : target_pkgs
466
+ }
467
+
468
+ # The cargo packages are not uploaded to their final location yet. They
469
+ # are still only on the local disk, after being downloaded from cargo CI
470
+ def build_package_def_for_cargo (version , short_version , target_list ):
471
+ target_pkgs = {}
472
+ for target in target_list :
473
+ url = cargo_live_url (short_version , target )
474
+ path = cargo_local_path (short_version , target )
475
+
476
+ if os .path .exists (path ):
477
+ hash = file_hash (path )
478
+ assert hash != None
479
+ target_pkgs [target ] = {
480
+ "available" : True ,
481
+ "url" : url ,
482
+ "hash" : hash
407
483
}
408
484
else :
409
485
print "error: " + name + " for " + target + " not available"
@@ -425,12 +501,9 @@ def build_package_def_from_archive(name, dist_dir, archive_date,
425
501
# "rustc-nightly-$triple.tar.gz" or "rustc-$version-$triple.tar.gz". So
426
502
# it will try both.
427
503
def live_package_url (name , dist_dir , date , version , target ):
428
- # Cargo builds are always named 'nightly'
429
- maybe_channel = channel
504
+ assert name != "cargo"
430
505
431
- if name == "cargo" :
432
- url1 = cargo_addy + "/" + date + "/cargo-nightly-" + target + ".tar.gz"
433
- elif name == "rust-src" :
506
+ if name == "rust-src" :
434
507
# The build system treats source packages as a separate target for `rustc`
435
508
# but for rustup we'd like to treat them as a completely separate package.
436
509
url1 = s3_addy + "/" + dist_dir + "/" + date + "/rust-src-" + version + ".tar.gz"
@@ -488,16 +561,21 @@ def url_and_hash_of_rust_package(target, rustc_short_version):
488
561
print "error: rust package missing: " + local_file
489
562
return None
490
563
491
- hash = None
492
- with open (local_file , 'rb' ) as f :
493
- buf = f .read ()
494
- hash = hashlib .sha256 (buf ).hexdigest ()
564
+ hash = file_hash (local_file )
565
+ assert hash != None
495
566
496
567
return {
497
568
"url" : url ,
498
569
"hash" : hash ,
499
570
}
500
571
572
+ def file_hash (path ):
573
+ hash = None
574
+ with open (path , 'rb' ) as f :
575
+ buf = f .read ()
576
+ hash = hashlib .sha256 (buf ).hexdigest ()
577
+ return hash
578
+
501
579
def write_manifest (manifest , file_path ):
502
580
def quote (value ):
503
581
return '"' + str (value ).replace ('"' , r'\"' ) + '"'
0 commit comments