Skip to content

Commit b32e009

Browse files
committed
Merge remote-tracking branch 'erickt/rustup'
2 parents 4b40bc8 + 6465cb8 commit b32e009

File tree

2 files changed

+124
-16
lines changed

2 files changed

+124
-16
lines changed

src/etc/rustup.sh

Lines changed: 123 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ validate_opt() {
230230
}
231231

232232
create_tmp_dir() {
233-
local TMP_DIR=./rustup-tmp-install
233+
local TMP_DIR=`pwd`/rustup-tmp-install
234234

235235
rm -Rf "${TMP_DIR}"
236236
need_ok "failed to remove temporary installation directory"
@@ -245,6 +245,21 @@ probe_need CFG_CURL curl
245245
probe_need CFG_TAR tar
246246
probe_need CFG_FILE file
247247

248+
probe CFG_SHA256SUM sha256sum
249+
probe CFG_SHASUM shasum
250+
251+
if [ -z "$CFG_SHA256SUM" -a -z "$CFG_SHASUM" ]; then
252+
err "unable to find either sha256sum or shasum"
253+
fi
254+
255+
calculate_hash() {
256+
if [ -n "$CFG_SHA256SUM" ]; then
257+
${CFG_SHA256SUM} $@
258+
else
259+
${CFG_SHASUM} -a 256 $@
260+
fi
261+
}
262+
248263
CFG_SRC_DIR="$(cd $(dirname $0) && pwd)/"
249264
CFG_SELF="$0"
250265
CFG_ARGS="$@"
@@ -270,6 +285,10 @@ VAL_OPTIONS=""
270285
flag uninstall "only uninstall from the installation prefix"
271286
valopt prefix "" "set installation prefix"
272287
opt cargo 1 "install cargo with rust"
288+
valopt date "" "use the YYYY-MM-DD nightly instead of the current nightly"
289+
valopt rust-date "" "use the YYYY-MM-DD rust nightly instead of the current nightly"
290+
valopt cargo-date "" "use the YYYY-MM-DD cargo nightly instead of the current nightly"
291+
flag save "save the downloaded nightlies to ~/.rustup"
273292

274293
if [ $HELP -eq 1 ]
275294
then
@@ -417,6 +436,21 @@ CFG_TMP_DIR=$(mktemp -d 2>/dev/null \
417436
|| mktemp -d -t 'rustup-tmp-install' 2>/dev/null \
418437
|| create_tmp_dir)
419438

439+
# If we're saving nightlies and we didn't specify which one, grab todays.
440+
# Otherwise we'll use the latest version.
441+
if [ -n "${CFG_SAVE}" -a -z "${CFG_DATE}" ];
442+
then
443+
CFG_DATE=`date "+%Y-%m-%d"`
444+
fi
445+
446+
if [ -z "${CFG_RUST_DATE}" ]; then
447+
CFG_RUST_DATE="${CFG_DATE}"
448+
fi
449+
450+
if [ -z "${CFG_CARGO_DATE}" ]; then
451+
CFG_CARGO_DATE="${CFG_DATE}"
452+
fi
453+
420454
RUST_URL="https://static.rust-lang.org/dist"
421455
RUST_PACKAGE_NAME=rust-nightly
422456
RUST_PACKAGE_NAME_AND_TRIPLE="${RUST_PACKAGE_NAME}-${HOST_TRIPLE}"
@@ -431,28 +465,86 @@ CARGO_TARBALL_NAME="${CARGO_PACKAGE_NAME_AND_TRIPLE}.tar.gz"
431465
CARGO_LOCAL_INSTALL_DIR="${CFG_TMP_DIR}/${CARGO_PACKAGE_NAME_AND_TRIPLE}"
432466
CARGO_LOCAL_INSTALL_SCRIPT="${CARGO_LOCAL_INSTALL_DIR}/install.sh"
433467

434-
# Fetch the package.
468+
# add a date suffix if we want a particular nighly.
469+
if [ -n "${CFG_RUST_DATE}" ];
470+
then
471+
RUST_URL="${RUST_URL}/${CFG_RUST_DATE}"
472+
fi
473+
474+
if [ -n "${CFG_CARGO_DATE}" ];
475+
then
476+
CARGO_URL="${CARGO_URL}/${CFG_CARGO_DATE}"
477+
fi
478+
479+
verify_hash() {
480+
remote_sha256="$1"
481+
local_file="$2"
482+
483+
msg "Downloading ${remote_sha256}"
484+
remote_sha256=`"${CFG_CURL}" -f "${remote_sha256}"`
485+
if [ "$?" -ne 0 ]; then
486+
rm -Rf "${CFG_TMP_DIR}"
487+
err "Failed to download ${remote_url}"
488+
fi
489+
490+
msg "Verifying hash"
491+
local_sha256=$(calculate_hash "${local_file}")
492+
if [ "$?" -ne 0 ]; then
493+
rm -Rf "${CFG_TMP_DIR}"
494+
err "Failed to compute hash for ${local_tarball}"
495+
fi
496+
497+
# We only need the sha, not the filenames
498+
remote_sha256=`echo ${remote_sha256} | cut -f 1 -d ' '`
499+
local_sha256=`echo ${local_sha256} | cut -f 1 -d ' '`
500+
501+
if [ "${remote_sha256}" != "${local_sha256}" ]; then
502+
rm -Rf "${CFG_TMP_DIR}"
503+
err "invalid sha256.\n ${remote_sha256}\t${remote_tarball}\n ${local_sha256}\t${local_tarball}"
504+
fi
505+
}
506+
507+
# Fetch the package. Optionally caches the tarballs.
435508
download_package() {
436509
remote_tarball="$1"
437510
local_tarball="$2"
511+
remote_sha256="${remote_tarball}.sha256"
438512

439-
msg "Downloading ${remote_tarball} to ${local_tarball}"
513+
# Check if we've already downloaded this file.
514+
if [ -e "${local_tarball}.tmp" ]; then
515+
msg "Resuming ${remote_tarball} to ${local_tarball}"
440516

441-
"${CFG_CURL}" -f -o "${local_tarball}" "${remote_tarball}"
442-
if [ $? -ne 0 ]
443-
then
444-
rm -Rf "${CFG_TMP_DIR}"
445-
err "failed to download installer"
517+
"${CFG_CURL}" -f -C - -o "${local_tarball}.tmp" "${remote_tarball}"
518+
if [ $? -ne 0 ]
519+
then
520+
rm -Rf "${CFG_TMP_DIR}"
521+
err "failed to download installer"
522+
fi
523+
524+
mv "${local_tarball}.tmp" "${local_tarball}"
525+
elif [ ! -e "${local_tarball}" ]; then
526+
msg "Downloading ${remote_tarball} to ${local_tarball}"
527+
528+
"${CFG_CURL}" -f -o "${local_tarball}.tmp" "${remote_tarball}"
529+
if [ $? -ne 0 ]
530+
then
531+
rm -Rf "${CFG_TMP_DIR}"
532+
err "failed to download installer"
533+
fi
534+
535+
mv "${local_tarball}.tmp" "${local_tarball}"
446536
fi
537+
538+
verify_hash "${remote_sha256}" "${local_tarball}"
447539
}
448540

449541
# Wrap all the commands needed to install a package.
450542
install_package() {
451-
tarball_name="$1"
543+
local_tarball="$1"
452544
install_script="$2"
453545

454-
msg "Extracting ${tarball_name}"
455-
(cd "${CFG_TMP_DIR}" && "${CFG_TAR}" -xzf "${tarball_name}")
546+
msg "Extracting ${local_tarball}"
547+
(cd "${CFG_TMP_DIR}" && "${CFG_TAR}" -xvf "${local_tarball}")
456548
if [ $? -ne 0 ]; then
457549
rm -Rf "${CFG_TMP_DIR}"
458550
err "failed to unpack installer"
@@ -479,8 +571,24 @@ install_packages() {
479571
mkdir -p "${CFG_TMP_DIR}"
480572
need_ok "failed to create create temporary installation directory"
481573

482-
RUST_LOCAL_TARBALL="${CFG_TMP_DIR}/${RUST_TARBALL_NAME}"
483-
CARGO_LOCAL_TARBALL="${CFG_TMP_DIR}/${CARGO_TARBALL_NAME}"
574+
# If we're saving our nightlies, put them in $HOME/.rustup.
575+
if [ -n "${CFG_SAVE}" ]
576+
then
577+
RUST_DOWNLOAD_DIR="${HOME}/.rustup/${CFG_RUST_DATE}"
578+
CARGO_DOWNLOAD_DIR="${HOME}/.rustup/${CFG_CARGO_DATE}"
579+
else
580+
RUST_DOWNLOAD_DIR="${CFG_TMP_DIR}"
581+
CARGO_DOWNLOAD_DIR="${CFG_TMP_DIR}"
582+
fi
583+
584+
mkdir -p "${RUST_DOWNLOAD_DIR}"
585+
need_ok "failed to create create download directory"
586+
587+
mkdir -p "${CARGO_DOWNLOAD_DIR}"
588+
need_ok "failed to create create download directory"
589+
590+
RUST_LOCAL_TARBALL="${RUST_DOWNLOAD_DIR}/${RUST_TARBALL_NAME}"
591+
CARGO_LOCAL_TARBALL="${CARGO_DOWNLOAD_DIR}/${CARGO_TARBALL_NAME}"
484592

485593
download_package \
486594
"${RUST_URL}/${RUST_TARBALL_NAME}" \
@@ -493,12 +601,12 @@ install_packages() {
493601
fi
494602

495603
install_package \
496-
"${RUST_TARBALL_NAME}" \
604+
"${RUST_LOCAL_TARBALL}" \
497605
"${RUST_LOCAL_INSTALL_SCRIPT}"
498606

499607
if [ -z "${CFG_DISABLE_CARGO}" ]; then
500608
install_package \
501-
"${CARGO_TARBALL_NAME}" \
609+
"${CARGO_LOCAL_TARBALL}" \
502610
"${CARGO_LOCAL_INSTALL_SCRIPT}"
503611
fi
504612

src/libsyntax/ast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -989,7 +989,7 @@ impl LitIntType {
989989
#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
990990
pub enum Lit_ {
991991
LitStr(InternedString, StrStyle),
992-
LitBinary(Rc<Vec<u8> >),
992+
LitBinary(Rc<Vec<u8>>),
993993
LitByte(u8),
994994
LitChar(char),
995995
LitInt(u64, LitIntType),

0 commit comments

Comments
 (0)