rust/src/etc/get-snapshot.py

79 lines
2.3 KiB
Python
Raw Normal View History

#!/usr/bin/env python
#
# Copyright 2011-2014 The Rust Project Developers. See the COPYRIGHT
2014-02-02 04:47:02 -06:00
# file at the top-level directory of this distribution and at
# http://rust-lang.org/COPYRIGHT.
#
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
# option. This file may not be copied, modified, or distributed
# except according to those terms.
2015-01-27 02:22:24 -06:00
import os
import tarfile
import shutil
import sys
from snapshot import *
2015-01-27 02:22:24 -06:00
def unpack_snapshot(triple, dl_path):
2015-01-27 02:09:13 -06:00
print("opening snapshot " + dl_path)
tar = tarfile.open(dl_path)
kernel = get_kernel(triple)
2015-01-27 02:09:13 -06:00
stagep = os.path.join(triple, "stage0")
2015-01-27 02:09:13 -06:00
# 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))
2015-01-27 02:09:13 -06:00
for p in tar.getnames():
2015-01-27 02:22:24 -06:00
name = p.replace("rust-stage0/", "", 1)
2015-01-27 02:09:13 -06:00
fp = os.path.join(stagep, name)
print("extracting " + p)
tar.extract(p, download_unpack_base)
tp = os.path.join(download_unpack_base, p)
if os.path.isdir(tp) and os.path.exists(fp):
2015-01-27 02:22:24 -06:00
continue
2015-01-27 02:09:13 -06:00
shutil.move(tp, fp)
tar.close()
shutil.rmtree(download_unpack_base)
# Main
# 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.
2015-01-27 02:10:27 -06:00
def main(argv):
triple = argv[1]
if len(argv) == 3:
dl_path = 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
2015-01-27 02:10:27 -06:00
if (not os.path.exists(dl)):
get_url_to_file(url, dl)
2011-05-03 01:37:52 -05:00
2015-01-27 02:10:27 -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)
2015-01-27 02:10:27 -06:00
unpack_snapshot(triple, dl_path)
2015-01-27 02:10:27 -06:00
if __name__ == '__main__':
main(sys.argv)