Skip to content

Commit 48c6c80

Browse files
committed
Merge pull request #20452 from brson/rustup
Move rustup to the combined installer Reviewed-by: brson
2 parents dddc9ec + ebdf331 commit 48c6c80

File tree

2 files changed

+104
-34
lines changed

2 files changed

+104
-34
lines changed

src/etc/rustup.sh

Lines changed: 103 additions & 33 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="$@"
@@ -269,7 +284,8 @@ VAL_OPTIONS=""
269284

270285
flag uninstall "only uninstall from the installation prefix"
271286
valopt prefix "" "set installation prefix"
272-
opt cargo 1 "install cargo with rust"
287+
valopt date "" "use the YYYY-MM-DD nightly instead of the current nightly"
288+
flag save "save the downloaded nightlies to ~/.rustup"
273289

274290
if [ $HELP -eq 1 ]
275291
then
@@ -417,42 +433,98 @@ CFG_TMP_DIR=$(mktemp -d 2>/dev/null \
417433
|| mktemp -d -t 'rustup-tmp-install' 2>/dev/null \
418434
|| create_tmp_dir)
419435

436+
# If we're saving nightlies and we didn't specify which one, grab todays.
437+
# Otherwise we'll use the latest version.
438+
if [ -n "${CFG_SAVE}" -a -z "${CFG_DATE}" ];
439+
then
440+
CFG_DATE=`date "+%Y-%m-%d"`
441+
fi
442+
420443
RUST_URL="https://static.rust-lang.org/dist"
421444
RUST_PACKAGE_NAME=rust-nightly
422445
RUST_PACKAGE_NAME_AND_TRIPLE="${RUST_PACKAGE_NAME}-${HOST_TRIPLE}"
423446
RUST_TARBALL_NAME="${RUST_PACKAGE_NAME_AND_TRIPLE}.tar.gz"
424447
RUST_LOCAL_INSTALL_DIR="${CFG_TMP_DIR}/${RUST_PACKAGE_NAME_AND_TRIPLE}"
425448
RUST_LOCAL_INSTALL_SCRIPT="${RUST_LOCAL_INSTALL_DIR}/install.sh"
426449

427-
CARGO_URL="https://static.rust-lang.org/cargo-dist"
428-
CARGO_PACKAGE_NAME=cargo-nightly
429-
CARGO_PACKAGE_NAME_AND_TRIPLE="${CARGO_PACKAGE_NAME}-${HOST_TRIPLE}"
430-
CARGO_TARBALL_NAME="${CARGO_PACKAGE_NAME_AND_TRIPLE}.tar.gz"
431-
CARGO_LOCAL_INSTALL_DIR="${CFG_TMP_DIR}/${CARGO_PACKAGE_NAME_AND_TRIPLE}"
432-
CARGO_LOCAL_INSTALL_SCRIPT="${CARGO_LOCAL_INSTALL_DIR}/install.sh"
450+
# add a date suffix if we want a particular nighly.
451+
if [ -n "${CFG_DATE}" ];
452+
then
453+
RUST_URL="${RUST_URL}/${CFG_DATE}"
454+
fi
455+
456+
verify_hash() {
457+
remote_sha256="$1"
458+
local_file="$2"
459+
460+
msg "Downloading ${remote_sha256}"
461+
remote_sha256=`"${CFG_CURL}" -f "${remote_sha256}"`
462+
if [ "$?" -ne 0 ]; then
463+
rm -Rf "${CFG_TMP_DIR}"
464+
err "Failed to download ${remote_url}"
465+
fi
466+
467+
msg "Verifying hash"
468+
local_sha256=$(calculate_hash "${local_file}")
469+
if [ "$?" -ne 0 ]; then
470+
rm -Rf "${CFG_TMP_DIR}"
471+
err "Failed to compute hash for ${local_tarball}"
472+
fi
473+
474+
# We only need the sha, not the filenames
475+
remote_sha256=`echo ${remote_sha256} | cut -f 1 -d ' '`
476+
local_sha256=`echo ${local_sha256} | cut -f 1 -d ' '`
477+
478+
if [ "${remote_sha256}" != "${local_sha256}" ]; then
479+
rm -Rf "${CFG_TMP_DIR}"
480+
errmsg="invalid sha256.\n"
481+
errmsg="$errmsg ${remote_sha256}\t${remote_tarball}\n"
482+
errmsg="$errmsg ${local_sha256}\t${local_tarball}"
483+
err "$errmsg"
484+
fi
485+
}
433486

434-
# Fetch the package.
487+
# Fetch the package. Optionally caches the tarballs.
435488
download_package() {
436489
remote_tarball="$1"
437490
local_tarball="$2"
491+
remote_sha256="${remote_tarball}.sha256"
438492

439-
msg "Downloading ${remote_tarball} to ${local_tarball}"
493+
# Check if we've already downloaded this file.
494+
if [ -e "${local_tarball}.tmp" ]; then
495+
msg "Resuming ${remote_tarball} to ${local_tarball}"
440496

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"
497+
"${CFG_CURL}" -f -C - -o "${local_tarball}.tmp" "${remote_tarball}"
498+
if [ $? -ne 0 ]
499+
then
500+
rm -Rf "${CFG_TMP_DIR}"
501+
err "failed to download installer"
502+
fi
503+
504+
mv "${local_tarball}.tmp" "${local_tarball}"
505+
elif [ ! -e "${local_tarball}" ]; then
506+
msg "Downloading ${remote_tarball} to ${local_tarball}"
507+
508+
"${CFG_CURL}" -f -o "${local_tarball}.tmp" "${remote_tarball}"
509+
if [ $? -ne 0 ]
510+
then
511+
rm -Rf "${CFG_TMP_DIR}"
512+
err "failed to download installer"
513+
fi
514+
515+
mv "${local_tarball}.tmp" "${local_tarball}"
446516
fi
517+
518+
verify_hash "${remote_sha256}" "${local_tarball}"
447519
}
448520

449521
# Wrap all the commands needed to install a package.
450522
install_package() {
451-
tarball_name="$1"
523+
local_tarball="$1"
452524
install_script="$2"
453525

454-
msg "Extracting ${tarball_name}"
455-
(cd "${CFG_TMP_DIR}" && "${CFG_TAR}" -xzf "${tarball_name}")
526+
msg "Extracting ${local_tarball}"
527+
(cd "${CFG_TMP_DIR}" && "${CFG_TAR}" -xzf "${local_tarball}")
456528
if [ $? -ne 0 ]; then
457529
rm -Rf "${CFG_TMP_DIR}"
458530
err "failed to unpack installer"
@@ -479,29 +551,27 @@ install_packages() {
479551
mkdir -p "${CFG_TMP_DIR}"
480552
need_ok "failed to create create temporary installation directory"
481553

482-
RUST_LOCAL_TARBALL="${CFG_TMP_DIR}/${RUST_TARBALL_NAME}"
483-
CARGO_LOCAL_TARBALL="${CFG_TMP_DIR}/${CARGO_TARBALL_NAME}"
554+
# If we're saving our nightlies, put them in $HOME/.rustup.
555+
if [ -n "${CFG_SAVE}" ]
556+
then
557+
RUST_DOWNLOAD_DIR="${HOME}/.rustup/${CFG_DATE}"
558+
else
559+
RUST_DOWNLOAD_DIR="${CFG_TMP_DIR}"
560+
fi
561+
562+
mkdir -p "${RUST_DOWNLOAD_DIR}"
563+
need_ok "failed to create create download directory"
564+
565+
RUST_LOCAL_TARBALL="${RUST_DOWNLOAD_DIR}/${RUST_TARBALL_NAME}"
484566

485567
download_package \
486568
"${RUST_URL}/${RUST_TARBALL_NAME}" \
487569
"${RUST_LOCAL_TARBALL}"
488570

489-
if [ -z "${CFG_DISABLE_CARGO}" ]; then
490-
download_package \
491-
"${CARGO_URL}/${CARGO_TARBALL_NAME}" \
492-
"${CARGO_LOCAL_TARBALL}"
493-
fi
494-
495571
install_package \
496-
"${RUST_TARBALL_NAME}" \
572+
"${RUST_LOCAL_TARBALL}" \
497573
"${RUST_LOCAL_INSTALL_SCRIPT}"
498574

499-
if [ -z "${CFG_DISABLE_CARGO}" ]; then
500-
install_package \
501-
"${CARGO_TARBALL_NAME}" \
502-
"${CARGO_LOCAL_INSTALL_SCRIPT}"
503-
fi
504-
505575
rm -Rf "${CFG_TMP_DIR}"
506576
need_ok "couldn't rm temporary installation directory"
507577
}

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
#[derive(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)