]> git.lizzy.rs Git - rust.git/blob - src/etc/get-snapshot.py
Rollup merge of #31295 - steveklabnik:gh31266, r=alexcrichton
[rust.git] / src / etc / get-snapshot.py
1 #!/usr/bin/env python
2 #
3 # Copyright 2011-2014 The Rust Project Developers. See the COPYRIGHT
4 # file at the top-level directory of this distribution and at
5 # http://rust-lang.org/COPYRIGHT.
6 #
7 # Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
8 # http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
9 # <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
10 # option. This file may not be copied, modified, or distributed
11 # except according to those terms.
12
13 import os
14 import tarfile
15 import shutil
16 import sys
17 from snapshot import *
18
19
20 def unpack_snapshot(triple, dl_path):
21     print("opening snapshot " + dl_path)
22     tar = tarfile.open(dl_path)
23     kernel = get_kernel(triple)
24
25     stagep = os.path.join(triple, "stage0")
26
27     # Remove files from prior unpackings, since snapshot rustc may not
28     # be able to disambiguate between multiple candidate libraries.
29     # (Leave dirs in place since extracting step still needs them.)
30     for root, _, files in os.walk(stagep):
31         for f in files:
32             print("removing " + os.path.join(root, f))
33             os.unlink(os.path.join(root, f))
34
35     for p in tar.getnames():
36         name = p.replace("rust-stage0/", "", 1)
37
38         fp = os.path.join(stagep, name)
39         print("extracting " + p)
40         tar.extract(p, download_unpack_base)
41         tp = os.path.join(download_unpack_base, p)
42         if os.path.isdir(tp) and os.path.exists(fp):
43             continue
44         shutil.move(tp, fp)
45     tar.close()
46     shutil.rmtree(download_unpack_base)
47
48
49 # Main
50
51 # this gets called with one or two arguments:
52 # The first is the O/S triple.
53 # The second is an optional path to the snapshot to use.
54
55 def main(argv):
56     triple = argv[1]
57     if len(argv) == 3:
58         dl_path = argv[2]
59     else:
60         snap = determine_curr_snapshot(triple)
61         dl = os.path.join(download_dir_base, snap)
62         url = download_url_base + "/" + snap
63         print("determined most recent snapshot: " + snap)
64
65         if (not os.path.exists(dl)):
66             get_url_to_file(url, dl)
67
68         if (snap_filename_hash_part(snap) == hash_file(dl)):
69             print("got download with ok hash")
70         else:
71             raise Exception("bad hash on download")
72
73         dl_path = os.path.join(download_dir_base, snap)
74
75     unpack_snapshot(triple, dl_path)
76
77 if __name__ == '__main__':
78     main(sys.argv)