From be9914625b0cbf5f305c5af3adbc6bc337ae760e Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Thu, 9 Feb 2012 17:58:09 -0800 Subject: [PATCH] allow snapshot to be specified in make command line --- mk/stage0.mk | 4 +++- src/etc/get-snapshot.py | 36 ++++++++++++++++++++++-------------- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/mk/stage0.mk b/mk/stage0.mk index 66dafc92be7..b790c2f9f2d 100644 --- a/mk/stage0.mk +++ b/mk/stage0.mk @@ -4,7 +4,9 @@ $(HBIN0_H_$(CFG_HOST_TRIPLE))/rustc$(X): \ $(S)src/snapshots.txt \ $(S)src/etc/get-snapshot.py $(MKFILE_DEPS) @$(call E, fetch: $@) - $(Q)$(S)src/etc/get-snapshot.py $(CFG_HOST_TRIPLE) +# Note: the variable "SNAPSHOT_FILE" is generally not set, and so +# we generally only pass one argument to this script. + $(Q)$(S)src/etc/get-snapshot.py $(CFG_HOST_TRIPLE) $(SNAPSHOT_FILE) $(Q)touch $@ # Host libs will be extracted by the above rule diff --git a/src/etc/get-snapshot.py b/src/etc/get-snapshot.py index 8c85e5b8e39..643cd0fcdd6 100755 --- a/src/etc/get-snapshot.py +++ b/src/etc/get-snapshot.py @@ -3,8 +3,7 @@ import os, tarfile, hashlib, re, shutil, sys from snapshot import * -def unpack_snapshot(triple, snap): - dl_path = os.path.join(download_dir_base, snap) +def unpack_snapshot(triple, dl_path): print("opening snapshot " + dl_path) tar = tarfile.open(dl_path) kernel = get_kernel(triple) @@ -60,18 +59,27 @@ def determine_curr_snapshot(triple): # 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. + triple = sys.argv[1] -snap = determine_curr_snapshot(triple) -dl = os.path.join(download_dir_base, snap) -url = download_url_base + "/" + snap -print("determined most recent snapshot: " + snap) - -if (not os.path.exists(dl)): - get_url_to_file(url, dl) - -if (snap_filename_hash_part(snap) == hash_file(dl)): - print("got download with ok hash") +if len(sys.argv) == 3: + dl_path = sys.argv[2] else: - raise Exception("bad hash on download") + snap = determine_curr_snapshot(triple) + dl = os.path.join(download_dir_base, snap) + url = download_url_base + "/" + snap + print("determined most recent snapshot: " + snap) -unpack_snapshot(triple, snap) + if (not os.path.exists(dl)): + get_url_to_file(url, dl) + + 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) + +unpack_snapshot(triple, dl_path)