]> git.lizzy.rs Git - rust.git/blob - src/etc/get-snapshot.py
auto merge of #11347 : alexcrichton/rust/issue-11346, r=brson
[rust.git] / src / etc / get-snapshot.py
1 #!/usr/bin/env python
2 # xfail-license
3
4 import os, tarfile, re, shutil, sys
5 from snapshot import *
6
7 def unpack_snapshot(triple, dl_path):
8   print("opening snapshot " + dl_path)
9   tar = tarfile.open(dl_path)
10   kernel = get_kernel(triple)
11
12   stagep = os.path.join(triple, "stage0")
13
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):
18     for f in files:
19       print("removing " + os.path.join(root, f))
20       os.unlink(os.path.join(root, f))
21
22   for p in tar.getnames():
23     name = p.replace("rust-stage0/", "", 1);
24
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):
30         continue
31     shutil.move(tp, fp)
32   tar.close()
33   shutil.rmtree(download_unpack_base)
34
35
36 # Main
37
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.
41
42 triple = sys.argv[1]
43 if len(sys.argv) == 3:
44   dl_path = sys.argv[2]
45 else:
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)
50
51   if (not os.path.exists(dl)):
52     get_url_to_file(url, dl)
53
54   if (snap_filename_hash_part(snap) == hash_file(dl)):
55     print("got download with ok hash")
56   else:
57     raise Exception("bad hash on download")
58
59   dl_path = os.path.join(download_dir_base, snap)
60
61 unpack_snapshot(triple, dl_path)