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

Commit a679a6d

Browse files
authored
Merge pull request #148 from brson/manifix
Copy cargo bins from rust-lang-ci to static-rust-lang-org
2 parents 3b44ca2 + 97b6169 commit a679a6d

File tree

1 file changed

+110
-48
lines changed

1 file changed

+110
-48
lines changed

master/build-rust-manifest.py

Lines changed: 110 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,7 @@ def main():
157157
cargo_branch = 'master'
158158
else:
159159
cargo_branch = 'rust-' + rustc_short_version
160-
if channel == "nightly":
161-
cargo_branch = 'master'
160+
162161
cargo_rev_url = "https://api.github.com/repos/rust-lang/cargo/commits/" + cargo_branch
163162
request = urllib2.Request(cargo_rev_url, headers={"Accept" : "Accept: application/vnd.github.3.sha"})
164163
cargo_rev = urllib2.urlopen(request).read()
@@ -173,6 +172,9 @@ def main():
173172
print "cargo version: " + cargo_version
174173
print "cargo short version: " + cargo_short_version
175174

175+
# Download cargo binaries into the correct location
176+
download_cargos(cargo_rev, cargo_short_version)
177+
176178
# Validate the component artifacts and generate the manifest
177179
generate_manifest(rustc_date, rustc_version, rustc_short_version,
178180
cargo_rev, cargo_version, cargo_short_version)
@@ -190,18 +192,46 @@ def most_recent_build_date(channel, component):
190192
date = response.read().strip();
191193
return date
192194

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+
193224
# Read the v1 manifests to find the installer name, download it
194225
# and extract the version file.
195-
def version_from_channel(channel, component, date):
226+
def version_from_channel(channel, component, date_or_sha):
196227
dist = dist_folder(component)
197228

198229
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"
202232
else:
203233
# 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
205235
print "downloading " + manifest_url
206236
response = urllib2.urlopen(manifest_url)
207237
if response.getcode() != 200:
@@ -217,21 +247,12 @@ def version_from_channel(channel, component, date):
217247
if installer_name == None:
218248
raise Exception("couldn't find installer in manifest for " + component)
219249

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
221252

222253
# 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)
235256

236257
# Unpack the installer
237258
unpack_dir = temp_dir + "/unpack"
@@ -255,21 +276,6 @@ def dist_folder(component):
255276
return "cargo-dist"
256277
return "dist"
257278

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-
273279
def parse_short_version(version):
274280
p = re.compile("^\d*\.\d*\.\d*")
275281
m = p.match(version)
@@ -280,6 +286,29 @@ def parse_short_version(version):
280286
raise Exception("couldn't parse version: " + version)
281287
return v
282288

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+
283312
def generate_manifest(rustc_date, rustc_version, rustc_short_version,
284313
cargo_rev, cargo_version, cargo_short_version):
285314

@@ -314,9 +343,8 @@ def build_manifest(rustc_date, rustc_version, rustc_short_version,
314343
doc_pkg = build_package_def_from_archive("rust-docs", "dist", rustc_date,
315344
rustc_version, rustc_short_version,
316345
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)
320348
mingw_pkg = build_package_def_from_archive("rust-mingw", "dist", rustc_date,
321349
rustc_version, rustc_short_version,
322350
mingw_list)
@@ -412,14 +440,46 @@ def build_manifest(rustc_date, rustc_version, rustc_short_version,
412440
# from the archives.
413441
def build_package_def_from_archive(name, dist_dir, archive_date,
414442
version, short_version, target_list):
443+
assert name != "cargo"
444+
415445
target_pkgs = {}
416446
for target in target_list:
417447
url = live_package_url(name, dist_dir, archive_date, short_version, target)
418448
if url is not None:
449+
hash = hash_from_s3_installer(url)
419450
target_pkgs[target] = {
420451
"available": True,
421452
"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
423483
}
424484
else:
425485
print "error: " + name + " for " + target + " not available"
@@ -441,12 +501,9 @@ def build_package_def_from_archive(name, dist_dir, archive_date,
441501
# "rustc-nightly-$triple.tar.gz" or "rustc-$version-$triple.tar.gz". So
442502
# it will try both.
443503
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"
446505

447-
if name == "cargo":
448-
url1 = cargo_addy + "/" + date + "/cargo-nightly-" + target + ".tar.gz"
449-
elif name == "rust-src":
506+
if name == "rust-src":
450507
# The build system treats source packages as a separate target for `rustc`
451508
# but for rustup we'd like to treat them as a completely separate package.
452509
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):
504561
print "error: rust package missing: " + local_file
505562
return None
506563

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
511566

512567
return {
513568
"url": url,
514569
"hash": hash,
515570
}
516571

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

0 commit comments

Comments
 (0)