4 import os, tarfile, re, shutil, sys
7 def unpack_snapshot(triple, dl_path):
8 print("opening snapshot " + dl_path)
9 tar = tarfile.open(dl_path)
10 kernel = get_kernel(triple)
12 stagep = os.path.join(triple, "stage0")
14 # Remove files from prior unpackings, since snapshot rustc may not
15 # be able to disambiguate between multiple candidate libraries.
16 # (Leave dirs in place since extracting step still needs them.)
17 for root, _, files in os.walk(stagep):
19 print("removing " + os.path.join(root, f))
20 os.unlink(os.path.join(root, f))
22 for p in tar.getnames():
23 name = p.replace("rust-stage0/", "", 1);
25 fp = os.path.join(stagep, name)
26 print("extracting " + p)
27 tar.extract(p, download_unpack_base)
28 tp = os.path.join(download_unpack_base, p)
29 if os.path.isdir(tp) and os.path.exists(fp):
33 shutil.rmtree(download_unpack_base)
38 # this gets called with one or two arguments:
39 # The first is the O/S triple.
40 # The second is an optional path to the snapshot to use.
43 if len(sys.argv) == 3:
46 snap = determine_curr_snapshot(triple)
47 dl = os.path.join(download_dir_base, snap)
48 url = download_url_base + "/" + snap
49 print("determined most recent snapshot: " + snap)
51 if (not os.path.exists(dl)):
52 get_url_to_file(url, dl)
54 if (snap_filename_hash_part(snap) == hash_file(dl)):
55 print("got download with ok hash")
57 raise Exception("bad hash on download")
59 dl_path = os.path.join(download_dir_base, snap)
61 unpack_snapshot(triple, dl_path)