@@ -157,8 +157,7 @@ def main():
157
157
cargo_branch = 'master'
158
158
else :
159
159
cargo_branch = 'rust-' + rustc_short_version
160
- if channel == "nightly" :
161
- cargo_branch = 'master'
160
+
162
161
cargo_rev_url = "https://api.github.com/repos/rust-lang/cargo/commits/" + cargo_branch
163
162
request = urllib2 .Request (cargo_rev_url , headers = {"Accept" : "Accept: application/vnd.github.3.sha" })
164
163
cargo_rev = urllib2 .urlopen (request ).read ()
@@ -173,6 +172,9 @@ def main():
173
172
print "cargo version: " + cargo_version
174
173
print "cargo short version: " + cargo_short_version
175
174
175
+ # Download cargo binaries into the correct location
176
+ download_cargos (cargo_rev , cargo_short_version )
177
+
176
178
# Validate the component artifacts and generate the manifest
177
179
generate_manifest (rustc_date , rustc_version , rustc_short_version ,
178
180
cargo_rev , cargo_version , cargo_short_version )
@@ -190,18 +192,46 @@ def most_recent_build_date(channel, component):
190
192
date = response .read ().strip ();
191
193
return date
192
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
+
193
224
# Read the v1 manifests to find the installer name, download it
194
225
# and extract the version file.
195
- def version_from_channel (channel , component , date ):
226
+ def version_from_channel (channel , component , date_or_sha ):
196
227
dist = dist_folder (component )
197
228
198
229
if component == "cargo" :
199
- target = "x86_64-unknown-linux-gnu"
200
- installer_name = "cargo-nightly-" + target + ".tar.gz"
201
- installer_url = cargo_addy + "/" + date + "/" + installer_name
230
+ installer_url = cargo_ci_url (date_or_sha , "x86_64-unknown-linux-gnu" )
231
+ local_name = "cargo.tar.gz"
202
232
else :
203
233
# Load the manifest
204
- manifest_url = s3_addy + "/" + dist + "/" + date + "/channel-" + component + "-" + channel
234
+ manifest_url = s3_addy + "/" + dist + "/" + date_or_sha + "/channel-" + component + "-" + channel
205
235
print "downloading " + manifest_url
206
236
response = urllib2 .urlopen (manifest_url )
207
237
if response .getcode () != 200 :
@@ -217,21 +247,12 @@ def version_from_channel(channel, component, date):
217
247
if installer_name == None :
218
248
raise Exception ("couldn't find installer in manifest for " + component )
219
249
220
- installer_url = s3_addy + "/" + dist + "/" + date + "/" + installer_name
250
+ installer_url = s3_addy + "/" + dist + "/" + date_or_sha + "/" + installer_name
251
+ local_name = installer_name
221
252
222
253
# Download the installer
223
- print "downloading " + installer_url
224
- response = urllib2 .urlopen (installer_url )
225
- if response .getcode () != 200 :
226
- raise Exception ("couldn't download " + installer_url )
227
-
228
- installer_file = temp_dir + "/" + installer_name
229
- f = open (installer_file , "w" )
230
- while True :
231
- buf = response .read (4096 )
232
- if not buf : break
233
- f .write (buf )
234
- f .close ()
254
+ installer_file = temp_dir + "/" + local_name
255
+ download_file (installer_url , installer_file )
235
256
236
257
# Unpack the installer
237
258
unpack_dir = temp_dir + "/unpack"
@@ -255,21 +276,6 @@ def dist_folder(component):
255
276
return "cargo-dist"
256
277
return "dist"
257
278
258
- def cargo_rev_from_packaging (rustc_version ):
259
- print "downloading " + cargo_revs
260
- response = urllib2 .urlopen (cargo_revs )
261
- if response .getcode () != 200 :
262
- raise Exception ("couldn't download " + cargo_revs )
263
- revs = response .read ().strip ()
264
- for line in revs .split ("\n " ):
265
- values = line .split (":" )
266
- version = values [0 ].strip ()
267
- date = values [1 ].strip ()
268
- if version == rustc_version :
269
- return date
270
- raise Exception ("couldn't find cargo rev for " + rustc_version )
271
-
272
-
273
279
def parse_short_version (version ):
274
280
p = re .compile ("^\d*\.\d*\.\d*" )
275
281
m = p .match (version )
@@ -280,6 +286,29 @@ def parse_short_version(version):
280
286
raise Exception ("couldn't parse version: " + version )
281
287
return v
282
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
+
283
312
def generate_manifest (rustc_date , rustc_version , rustc_short_version ,
284
313
cargo_rev , cargo_version , cargo_short_version ):
285
314
@@ -314,9 +343,8 @@ def build_manifest(rustc_date, rustc_version, rustc_short_version,
314
343
doc_pkg = build_package_def_from_archive ("rust-docs" , "dist" , rustc_date ,
315
344
rustc_version , rustc_short_version ,
316
345
host_list )
317
- cargo_pkg = build_package_def_from_archive ("cargo" , "cargo-dist" , cargo_rev ,
318
- cargo_version , cargo_short_version ,
319
- host_list )
346
+ cargo_pkg = build_package_def_for_cargo (cargo_version , cargo_short_version ,
347
+ host_list )
320
348
mingw_pkg = build_package_def_from_archive ("rust-mingw" , "dist" , rustc_date ,
321
349
rustc_version , rustc_short_version ,
322
350
mingw_list )
@@ -412,14 +440,46 @@ def build_manifest(rustc_date, rustc_version, rustc_short_version,
412
440
# from the archives.
413
441
def build_package_def_from_archive (name , dist_dir , archive_date ,
414
442
version , short_version , target_list ):
443
+ assert name != "cargo"
444
+
415
445
target_pkgs = {}
416
446
for target in target_list :
417
447
url = live_package_url (name , dist_dir , archive_date , short_version , target )
418
448
if url is not None :
449
+ hash = hash_from_s3_installer (url )
419
450
target_pkgs [target ] = {
420
451
"available" : True ,
421
452
"url" : url .replace (s3_addy , public_addy ),
422
- "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
423
483
}
424
484
else :
425
485
print "error: " + name + " for " + target + " not available"
@@ -441,12 +501,9 @@ def build_package_def_from_archive(name, dist_dir, archive_date,
441
501
# "rustc-nightly-$triple.tar.gz" or "rustc-$version-$triple.tar.gz". So
442
502
# it will try both.
443
503
def live_package_url (name , dist_dir , date , version , target ):
444
- # Cargo builds are always named 'nightly'
445
- maybe_channel = channel
504
+ assert name != "cargo"
446
505
447
- if name == "cargo" :
448
- url1 = cargo_addy + "/" + date + "/cargo-nightly-" + target + ".tar.gz"
449
- elif name == "rust-src" :
506
+ if name == "rust-src" :
450
507
# The build system treats source packages as a separate target for `rustc`
451
508
# but for rustup we'd like to treat them as a completely separate package.
452
509
url1 = s3_addy + "/" + dist_dir + "/" + date + "/rust-src-" + version + ".tar.gz"
@@ -504,16 +561,21 @@ def url_and_hash_of_rust_package(target, rustc_short_version):
504
561
print "error: rust package missing: " + local_file
505
562
return None
506
563
507
- hash = None
508
- with open (local_file , 'rb' ) as f :
509
- buf = f .read ()
510
- hash = hashlib .sha256 (buf ).hexdigest ()
564
+ hash = file_hash (local_file )
565
+ assert hash != None
511
566
512
567
return {
513
568
"url" : url ,
514
569
"hash" : hash ,
515
570
}
516
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
+
517
579
def write_manifest (manifest , file_path ):
518
580
def quote (value ):
519
581
return '"' + str (value ).replace ('"' , r'\"' ) + '"'
0 commit comments