diff --git a/src/etc/rustup.sh b/src/etc/rustup.sh index 85e15e36327..749d9eaa173 100755 --- a/src/etc/rustup.sh +++ b/src/etc/rustup.sh @@ -230,7 +230,7 @@ validate_opt() { } create_tmp_dir() { - local TMP_DIR=./rustup-tmp-install + local TMP_DIR=`pwd`/rustup-tmp-install rm -Rf "${TMP_DIR}" need_ok "failed to remove temporary installation directory" @@ -245,6 +245,21 @@ probe_need CFG_CURL curl probe_need CFG_TAR tar probe_need CFG_FILE file +probe CFG_SHA256SUM sha256sum +probe CFG_SHASUM shasum + +if [ -z "$CFG_SHA256SUM" -a -z "$CFG_SHASUM" ]; then + err "unable to find either sha256sum or shasum" +fi + +calculate_hash() { + if [ -n "$CFG_SHA256SUM" ]; then + ${CFG_SHA256SUM} $@ + else + ${CFG_SHASUM} -a 256 $@ + fi +} + CFG_SRC_DIR="$(cd $(dirname $0) && pwd)/" CFG_SELF="$0" CFG_ARGS="$@" @@ -269,7 +284,8 @@ VAL_OPTIONS="" flag uninstall "only uninstall from the installation prefix" valopt prefix "" "set installation prefix" -opt cargo 1 "install cargo with rust" +valopt date "" "use the YYYY-MM-DD nightly instead of the current nightly" +flag save "save the downloaded nightlies to ~/.rustup" if [ $HELP -eq 1 ] then @@ -417,6 +433,13 @@ CFG_TMP_DIR=$(mktemp -d 2>/dev/null \ || mktemp -d -t 'rustup-tmp-install' 2>/dev/null \ || create_tmp_dir) +# If we're saving nightlies and we didn't specify which one, grab todays. +# Otherwise we'll use the latest version. +if [ -n "${CFG_SAVE}" -a -z "${CFG_DATE}" ]; +then + CFG_DATE=`date "+%Y-%m-%d"` +fi + RUST_URL="https://static.rust-lang.org/dist" RUST_PACKAGE_NAME=rust-nightly RUST_PACKAGE_NAME_AND_TRIPLE="${RUST_PACKAGE_NAME}-${HOST_TRIPLE}" @@ -424,35 +447,84 @@ RUST_TARBALL_NAME="${RUST_PACKAGE_NAME_AND_TRIPLE}.tar.gz" RUST_LOCAL_INSTALL_DIR="${CFG_TMP_DIR}/${RUST_PACKAGE_NAME_AND_TRIPLE}" RUST_LOCAL_INSTALL_SCRIPT="${RUST_LOCAL_INSTALL_DIR}/install.sh" -CARGO_URL="https://static.rust-lang.org/cargo-dist" -CARGO_PACKAGE_NAME=cargo-nightly -CARGO_PACKAGE_NAME_AND_TRIPLE="${CARGO_PACKAGE_NAME}-${HOST_TRIPLE}" -CARGO_TARBALL_NAME="${CARGO_PACKAGE_NAME_AND_TRIPLE}.tar.gz" -CARGO_LOCAL_INSTALL_DIR="${CFG_TMP_DIR}/${CARGO_PACKAGE_NAME_AND_TRIPLE}" -CARGO_LOCAL_INSTALL_SCRIPT="${CARGO_LOCAL_INSTALL_DIR}/install.sh" +# add a date suffix if we want a particular nighly. +if [ -n "${CFG_DATE}" ]; +then + RUST_URL="${RUST_URL}/${CFG_DATE}" +fi -# Fetch the package. +verify_hash() { + remote_sha256="$1" + local_file="$2" + + msg "Downloading ${remote_sha256}" + remote_sha256=`"${CFG_CURL}" -f "${remote_sha256}"` + if [ "$?" -ne 0 ]; then + rm -Rf "${CFG_TMP_DIR}" + err "Failed to download ${remote_url}" + fi + + msg "Verifying hash" + local_sha256=$(calculate_hash "${local_file}") + if [ "$?" -ne 0 ]; then + rm -Rf "${CFG_TMP_DIR}" + err "Failed to compute hash for ${local_tarball}" + fi + + # We only need the sha, not the filenames + remote_sha256=`echo ${remote_sha256} | cut -f 1 -d ' '` + local_sha256=`echo ${local_sha256} | cut -f 1 -d ' '` + + if [ "${remote_sha256}" != "${local_sha256}" ]; then + rm -Rf "${CFG_TMP_DIR}" + errmsg="invalid sha256.\n" + errmsg="$errmsg ${remote_sha256}\t${remote_tarball}\n" + errmsg="$errmsg ${local_sha256}\t${local_tarball}" + err "$errmsg" + fi +} + +# Fetch the package. Optionally caches the tarballs. download_package() { remote_tarball="$1" local_tarball="$2" + remote_sha256="${remote_tarball}.sha256" - msg "Downloading ${remote_tarball} to ${local_tarball}" + # Check if we've already downloaded this file. + if [ -e "${local_tarball}.tmp" ]; then + msg "Resuming ${remote_tarball} to ${local_tarball}" - "${CFG_CURL}" -f -o "${local_tarball}" "${remote_tarball}" - if [ $? -ne 0 ] - then - rm -Rf "${CFG_TMP_DIR}" - err "failed to download installer" + "${CFG_CURL}" -f -C - -o "${local_tarball}.tmp" "${remote_tarball}" + if [ $? -ne 0 ] + then + rm -Rf "${CFG_TMP_DIR}" + err "failed to download installer" + fi + + mv "${local_tarball}.tmp" "${local_tarball}" + elif [ ! -e "${local_tarball}" ]; then + msg "Downloading ${remote_tarball} to ${local_tarball}" + + "${CFG_CURL}" -f -o "${local_tarball}.tmp" "${remote_tarball}" + if [ $? -ne 0 ] + then + rm -Rf "${CFG_TMP_DIR}" + err "failed to download installer" + fi + + mv "${local_tarball}.tmp" "${local_tarball}" fi + + verify_hash "${remote_sha256}" "${local_tarball}" } # Wrap all the commands needed to install a package. install_package() { - tarball_name="$1" + local_tarball="$1" install_script="$2" - msg "Extracting ${tarball_name}" - (cd "${CFG_TMP_DIR}" && "${CFG_TAR}" -xzf "${tarball_name}") + msg "Extracting ${local_tarball}" + (cd "${CFG_TMP_DIR}" && "${CFG_TAR}" -xzf "${local_tarball}") if [ $? -ne 0 ]; then rm -Rf "${CFG_TMP_DIR}" err "failed to unpack installer" @@ -479,29 +551,27 @@ install_packages() { mkdir -p "${CFG_TMP_DIR}" need_ok "failed to create create temporary installation directory" - RUST_LOCAL_TARBALL="${CFG_TMP_DIR}/${RUST_TARBALL_NAME}" - CARGO_LOCAL_TARBALL="${CFG_TMP_DIR}/${CARGO_TARBALL_NAME}" + # If we're saving our nightlies, put them in $HOME/.rustup. + if [ -n "${CFG_SAVE}" ] + then + RUST_DOWNLOAD_DIR="${HOME}/.rustup/${CFG_DATE}" + else + RUST_DOWNLOAD_DIR="${CFG_TMP_DIR}" + fi + + mkdir -p "${RUST_DOWNLOAD_DIR}" + need_ok "failed to create create download directory" + + RUST_LOCAL_TARBALL="${RUST_DOWNLOAD_DIR}/${RUST_TARBALL_NAME}" download_package \ "${RUST_URL}/${RUST_TARBALL_NAME}" \ "${RUST_LOCAL_TARBALL}" - if [ -z "${CFG_DISABLE_CARGO}" ]; then - download_package \ - "${CARGO_URL}/${CARGO_TARBALL_NAME}" \ - "${CARGO_LOCAL_TARBALL}" - fi - install_package \ - "${RUST_TARBALL_NAME}" \ + "${RUST_LOCAL_TARBALL}" \ "${RUST_LOCAL_INSTALL_SCRIPT}" - if [ -z "${CFG_DISABLE_CARGO}" ]; then - install_package \ - "${CARGO_TARBALL_NAME}" \ - "${CARGO_LOCAL_INSTALL_SCRIPT}" - fi - rm -Rf "${CFG_TMP_DIR}" need_ok "couldn't rm temporary installation directory" } diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 01f66f3bbd0..a33ee44be89 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -989,7 +989,7 @@ impl LitIntType { #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)] pub enum Lit_ { LitStr(InternedString, StrStyle), - LitBinary(Rc >), + LitBinary(Rc>), LitByte(u8), LitChar(char), LitInt(u64, LitIntType),