2011-05-02 20:56:13 -05:00
|
|
|
#!/usr/bin/env python
|
2013-01-18 01:28:42 -06:00
|
|
|
# xfail-license
|
2011-05-02 20:56:13 -05:00
|
|
|
|
2012-03-28 04:25:54 -05:00
|
|
|
import os, tarfile, re, shutil, sys
|
2011-05-02 20:56:13 -05:00
|
|
|
from snapshot import *
|
|
|
|
|
2012-02-09 19:58:09 -06:00
|
|
|
def unpack_snapshot(triple, dl_path):
|
2011-05-03 01:37:52 -05:00
|
|
|
print("opening snapshot " + dl_path)
|
2011-05-02 20:56:13 -05:00
|
|
|
tar = tarfile.open(dl_path)
|
2011-11-28 14:13:42 -06:00
|
|
|
kernel = get_kernel(triple)
|
2013-07-08 11:35:47 -05:00
|
|
|
|
|
|
|
stagep = os.path.join(triple, "stage0")
|
|
|
|
|
|
|
|
# Remove files from prior unpackings, since snapshot rustc may not
|
|
|
|
# be able to disambiguate between multiple candidate libraries.
|
|
|
|
# (Leave dirs in place since extracting step still needs them.)
|
|
|
|
for root, _, files in os.walk(stagep):
|
|
|
|
for f in files:
|
|
|
|
print("removing " + os.path.join(root, f))
|
|
|
|
os.unlink(os.path.join(root, f))
|
|
|
|
|
2011-12-13 12:54:48 -06:00
|
|
|
for p in tar.getnames():
|
2012-06-21 18:44:10 -05:00
|
|
|
name = p.replace("rust-stage0/", "", 1);
|
2013-07-08 11:35:47 -05:00
|
|
|
|
2011-11-21 15:11:40 -06:00
|
|
|
fp = os.path.join(stagep, name)
|
2011-12-13 12:54:48 -06:00
|
|
|
print("extracting " + p)
|
2011-05-02 20:56:13 -05:00
|
|
|
tar.extract(p, download_unpack_base)
|
|
|
|
tp = os.path.join(download_unpack_base, p)
|
2013-10-04 23:16:54 -05:00
|
|
|
if os.path.isdir(tp) and os.path.exists(fp):
|
|
|
|
continue
|
2011-05-02 20:56:13 -05:00
|
|
|
shutil.move(tp, fp)
|
|
|
|
tar.close()
|
|
|
|
shutil.rmtree(download_unpack_base)
|
|
|
|
|
|
|
|
|
|
|
|
# Main
|
|
|
|
|
2012-02-09 19:58:09 -06:00
|
|
|
# this gets called with one or two arguments:
|
|
|
|
# The first is the O/S triple.
|
|
|
|
# The second is an optional path to the snapshot to use.
|
|
|
|
|
2011-11-21 15:11:40 -06:00
|
|
|
triple = sys.argv[1]
|
2012-02-09 19:58:09 -06:00
|
|
|
if len(sys.argv) == 3:
|
|
|
|
dl_path = sys.argv[2]
|
|
|
|
else:
|
|
|
|
snap = determine_curr_snapshot(triple)
|
|
|
|
dl = os.path.join(download_dir_base, snap)
|
|
|
|
url = download_url_base + "/" + snap
|
|
|
|
print("determined most recent snapshot: " + snap)
|
2011-05-03 01:37:52 -05:00
|
|
|
|
2012-02-09 19:58:09 -06:00
|
|
|
if (not os.path.exists(dl)):
|
|
|
|
get_url_to_file(url, dl)
|
2011-05-03 01:37:52 -05:00
|
|
|
|
2012-02-09 19:58:09 -06:00
|
|
|
if (snap_filename_hash_part(snap) == hash_file(dl)):
|
|
|
|
print("got download with ok hash")
|
|
|
|
else:
|
|
|
|
raise Exception("bad hash on download")
|
|
|
|
|
|
|
|
dl_path = os.path.join(download_dir_base, snap)
|
2011-05-02 20:56:13 -05:00
|
|
|
|
2012-02-09 19:58:09 -06:00
|
|
|
unpack_snapshot(triple, dl_path)
|