Skip to content
This repository was archived by the owner on Nov 21, 2018. It is now read-only.

Commit 97b6169

Browse files
author
Someone on the Dev Buildmaster
committed
Download cargo installers to the right location during manifest building
1 parent 9440b8a commit 97b6169

File tree

1 file changed

+106
-28
lines changed

1 file changed

+106
-28
lines changed

master/build-rust-manifest.py

Lines changed: 106 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@ def main():
172172
print "cargo version: " + cargo_version
173173
print "cargo short version: " + cargo_short_version
174174

175+
# Download cargo binaries into the correct location
176+
download_cargos(cargo_rev, cargo_short_version)
177+
175178
# Validate the component artifacts and generate the manifest
176179
generate_manifest(rustc_date, rustc_version, rustc_short_version,
177180
cargo_rev, cargo_version, cargo_short_version)
@@ -189,15 +192,43 @@ def most_recent_build_date(channel, component):
189192
date = response.read().strip();
190193
return date
191194

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+
192224
# Read the v1 manifests to find the installer name, download it
193225
# and extract the version file.
194226
def version_from_channel(channel, component, date_or_sha):
195227
dist = dist_folder(component)
196228

197229
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"
201232
else:
202233
# Load the manifest
203234
manifest_url = s3_addy + "/" + dist + "/" + date_or_sha + "/channel-" + component + "-" + channel
@@ -217,20 +248,11 @@ def version_from_channel(channel, component, date_or_sha):
217248
raise Exception("couldn't find installer in manifest for " + component)
218249

219250
installer_url = s3_addy + "/" + dist + "/" + date_or_sha + "/" + installer_name
251+
local_name = installer_name
220252

221253
# 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)
234256

235257
# Unpack the installer
236258
unpack_dir = temp_dir + "/unpack"
@@ -264,6 +286,29 @@ def parse_short_version(version):
264286
raise Exception("couldn't parse version: " + version)
265287
return v
266288

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+
267312
def generate_manifest(rustc_date, rustc_version, rustc_short_version,
268313
cargo_rev, cargo_version, cargo_short_version):
269314

@@ -298,9 +343,8 @@ def build_manifest(rustc_date, rustc_version, rustc_short_version,
298343
doc_pkg = build_package_def_from_archive("rust-docs", "dist", rustc_date,
299344
rustc_version, rustc_short_version,
300345
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)
304348
mingw_pkg = build_package_def_from_archive("rust-mingw", "dist", rustc_date,
305349
rustc_version, rustc_short_version,
306350
mingw_list)
@@ -396,14 +440,46 @@ def build_manifest(rustc_date, rustc_version, rustc_short_version,
396440
# from the archives.
397441
def build_package_def_from_archive(name, dist_dir, archive_date,
398442
version, short_version, target_list):
443+
assert name != "cargo"
444+
399445
target_pkgs = {}
400446
for target in target_list:
401447
url = live_package_url(name, dist_dir, archive_date, short_version, target)
402448
if url is not None:
449+
hash = hash_from_s3_installer(url)
403450
target_pkgs[target] = {
404451
"available": True,
405452
"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
407483
}
408484
else:
409485
print "error: " + name + " for " + target + " not available"
@@ -425,12 +501,9 @@ def build_package_def_from_archive(name, dist_dir, archive_date,
425501
# "rustc-nightly-$triple.tar.gz" or "rustc-$version-$triple.tar.gz". So
426502
# it will try both.
427503
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"
430505

431-
if name == "cargo":
432-
url1 = cargo_addy + "/" + date + "/cargo-nightly-" + target + ".tar.gz"
433-
elif name == "rust-src":
506+
if name == "rust-src":
434507
# The build system treats source packages as a separate target for `rustc`
435508
# but for rustup we'd like to treat them as a completely separate package.
436509
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):
488561
print "error: rust package missing: " + local_file
489562
return None
490563

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
495566

496567
return {
497568
"url": url,
498569
"hash": hash,
499570
}
500571

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+
501579
def write_manifest(manifest, file_path):
502580
def quote(value):
503581
return '"' + str(value).replace('"', r'\"') + '"'

0 commit comments

Comments
 (0)