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