1
Fork 0

auto merge of #19170 : erickt/rust/rustup, r=erickt

This closes #19168.

Please be careful reviewing this since this gets used all over the place. I've tested all the options and everything appears to be working though.
This commit is contained in:
bors 2014-12-04 15:03:39 +00:00
commit 4053e82acb

157
src/etc/rustup.sh Normal file → Executable file
View file

@ -188,7 +188,7 @@ flag() {
fi fi
} }
validate_opt () { validate_opt() {
for arg in $CFG_ARGS for arg in $CFG_ARGS
do do
isArgValid=0 isArgValid=0
@ -230,6 +230,7 @@ validate_opt () {
} }
probe_need CFG_CURL curl probe_need CFG_CURL curl
probe_need CFG_TAR tar
CFG_SRC_DIR="$(cd $(dirname $0) && pwd)/" CFG_SRC_DIR="$(cd $(dirname $0) && pwd)/"
CFG_SELF="$0" CFG_SELF="$0"
@ -388,89 +389,109 @@ esac
msg "host triple: ${HOST_TRIPLE}" msg "host triple: ${HOST_TRIPLE}"
PACKAGE_NAME=rust-nightly CFG_INSTALL_FLAGS=""
PACKAGE_NAME_AND_TRIPLE="${PACKAGE_NAME}-${HOST_TRIPLE}" if [ -n "${CFG_UNINSTALL}" ]
TARBALL_NAME="${PACKAGE_NAME_AND_TRIPLE}.tar.gz" then
REMOTE_TARBALL="https://static.rust-lang.org/dist/${TARBALL_NAME}" CFG_INSTALL_FLAGS="${CFG_INSTALL_FLAGS} --uninstall"
TMP_DIR="./rustup-tmp-install" fi
LOCAL_TARBALL="${TMP_DIR}/${TARBALL_NAME}"
LOCAL_INSTALL_DIR="${TMP_DIR}/${PACKAGE_NAME_AND_TRIPLE}"
LOCAL_INSTALL_SCRIPT="${LOCAL_INSTALL_DIR}/install.sh"
if [ -n "${CFG_PREFIX}" ]
then
CFG_INSTALL_FLAGS="${CFG_INSTALL_FLAGS} --prefix=${CFG_PREFIX}"
fi
CFG_TMP_DIR="./rustup-tmp-install"
RUST_URL="https://static.rust-lang.org/dist"
RUST_PACKAGE_NAME=rust-nightly
RUST_PACKAGE_NAME_AND_TRIPLE="${RUST_PACKAGE_NAME}-${HOST_TRIPLE}"
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=cargo-nightly
CARGO_PACKAGE_NAME_AND_TRIPLE="${CARGO_PACKAGE_NAME}-${HOST_TRIPLE}" CARGO_PACKAGE_NAME_AND_TRIPLE="${CARGO_PACKAGE_NAME}-${HOST_TRIPLE}"
CARGO_TARBALL_NAME="${CARGO_PACKAGE_NAME_AND_TRIPLE}.tar.gz" CARGO_TARBALL_NAME="${CARGO_PACKAGE_NAME_AND_TRIPLE}.tar.gz"
CARGO_REMOTE_TARBALL="https://static.rust-lang.org/cargo-dist/${CARGO_TARBALL_NAME}" CARGO_LOCAL_INSTALL_DIR="${CFG_TMP_DIR}/${CARGO_PACKAGE_NAME_AND_TRIPLE}"
CARGO_LOCAL_TARBALL="${TMP_DIR}/${CARGO_TARBALL_NAME}"
CARGO_LOCAL_INSTALL_DIR="${TMP_DIR}/${CARGO_PACKAGE_NAME_AND_TRIPLE}"
CARGO_LOCAL_INSTALL_SCRIPT="${CARGO_LOCAL_INSTALL_DIR}/install.sh" CARGO_LOCAL_INSTALL_SCRIPT="${CARGO_LOCAL_INSTALL_DIR}/install.sh"
rm -Rf "${TMP_DIR}" # Fetch the package.
need_ok "failed to remove temporary installation directory" download_package() {
remote_tarball="$1"
local_tarball="$2"
mkdir -p "${TMP_DIR}" msg "Downloading ${remote_tarball} to ${local_tarball}"
need_ok "failed to create create temporary installation directory"
msg "downloading rust installer" mkdir -p "${CFG_TMP_DIR}"
"${CFG_CURL}" "${REMOTE_TARBALL}" > "${LOCAL_TARBALL}" need_ok "failed to create create download directory"
if [ $? -ne 0 ]
then "${CFG_CURL}" -f -o "${local_tarball}" "${remote_tarball}"
rm -Rf "${TMP_DIR}" if [ $? -ne 0 ]
then
rm -Rf "${CFG_TMP_DIR}"
err "failed to download installer" err "failed to download installer"
fi
if [ -z "${CFG_DISABLE_CARGO}" ]; then
msg "downloading cargo installer"
"${CFG_CURL}" "${CARGO_REMOTE_TARBALL}" > "${CARGO_LOCAL_TARBALL}"
if [ $? -ne 0 ]
then
rm -Rf "${TMP_DIR}"
err "failed to download cargo installer"
fi fi
fi }
# Wrap all the commands needed to install a package.
install_package() {
tarball_name="$1"
install_script="$2"
(cd "${TMP_DIR}" && tar xzf "${TARBALL_NAME}") msg "Extracting ${tarball_name}"
if [ $? -ne 0 ] (cd "${CFG_TMP_DIR}" && "${CFG_TAR}" -xvf "${tarball_name}")
then if [ $? -ne 0 ]; then
rm -Rf "${TMP_DIR}" rm -Rf "${CFG_TMP_DIR}"
err "failed to unpack installer" err "failed to unpack installer"
fi fi
MAYBE_UNINSTALL= sh "${install_script}" "${CFG_INSTALL_FLAGS}"
if [ -n "${CFG_UNINSTALL}" ] if [ $? -ne 0 ]
then then
MAYBE_UNINSTALL="--uninstall" rm -Rf "${CFG_TMP_DIR}"
fi
MAYBE_PREFIX=
if [ -n "${CFG_PREFIX}" ]
then
MAYBE_PREFIX="--prefix=${CFG_PREFIX}"
fi
sh "${LOCAL_INSTALL_SCRIPT}" "${MAYBE_UNINSTALL}" "${MAYBE_PREFIX}"
if [ $? -ne 0 ]
then
rm -Rf "${TMP_DIR}"
err "failed to install Rust" err "failed to install Rust"
fi fi
}
if [ -z "${CFG_DISABLE_CARGO}" ]; then # It's possible that curl could be interrupted partway though downloading
(cd "${TMP_DIR}" && tar xzf "${CARGO_TARBALL_NAME}") # `rustup.sh`, truncating the file. This could be especially bad if we were in
if [ $? -ne 0 ] # the middle of a line that would run "rm -rf ". To protect against this, we
then # wrap up the `rustup.sh` destructive functionality in this helper function,
rm -Rf "${TMP_DIR}" # which we call as the last thing we do. This means we will not do anything
err "failed to unpack cargo installer" # unless we have the entire file downloaded.
install_packages() {
rm -Rf "${CFG_TMP_DIR}"
need_ok "failed to remove temporary installation directory"
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}"
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 fi
sh "${CARGO_LOCAL_INSTALL_SCRIPT}" "${MAYBE_UNINSTALL}" "${MAYBE_PREFIX}" install_package \
if [ $? -ne 0 ] "${RUST_TARBALL_NAME}" \
then "${RUST_LOCAL_INSTALL_SCRIPT}"
rm -Rf "${TMP_DIR}"
err "failed to install Cargo"
fi
fi
rm -Rf "${TMP_DIR}" if [ -z "${CFG_DISABLE_CARGO}" ]; then
need_ok "couldn't rm temporary installation directory" install_package \
"${CARGO_TARBALL_NAME}" \
"${CARGO_LOCAL_INSTALL_SCRIPT}"
fi
rm -Rf "${CFG_TMP_DIR}"
need_ok "couldn't rm temporary installation directory"
}
install_packages