Skip to content

Commit

Permalink
Remove old multirust & compat code
Browse files Browse the repository at this point in the history
  • Loading branch information
dwijnand committed Mar 16, 2019
1 parent 819ddda commit 91af98b
Show file tree
Hide file tree
Showing 10 changed files with 11 additions and 951 deletions.
11 changes: 1 addition & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,31 +1,22 @@
[package]

name = "rustup"
version = "1.17.0"
edition = "2018"
authors = [ "Diggory Blake <diggsey@googlemail.com>" ]
description = "Manage multiple rust installations with ease"

documentation = "http://rust-lang.github.io/rustup.rs/rustup/index.html"
documentation = "https://rust-lang.github.io/rustup.rs/rustup/index.html"
homepage = "https://github.com/rust-lang/rustup.rs"
repository = "https://github.com/rust-lang/rustup.rs"

readme = "README.md"

keywords = ["rustup", "multirust", "install", "proxy"]

license = "MIT OR Apache-2.0"

build = "build.rs"

[features]

default = ["curl-backend", "reqwest-backend"]

curl-backend = ["download/curl-backend"]
reqwest-backend = ["download/reqwest-backend"]
vendored-openssl = ['openssl/vendored']

# Include in the default set to disable self-update and uninstall.
no-self-update = []

Expand Down
95 changes: 1 addition & 94 deletions src/cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ mod setup_mode;
mod term2;

use crate::errors::*;
use rustup::dist::dist::TargetTriple;
use rustup::env_var::RUST_RECURSION_COUNT_MAX;
use std::alloc::System;
use std::env;
Expand All @@ -51,9 +50,6 @@ fn run_rustup() -> Result<()> {
// bugs in rustup.
do_recursion_guard()?;

// Do various hacks to clean up past messes
do_compatibility_hacks();

// The name of arg0 determines how the program is going to behave
let arg0 = env::args().next().map(PathBuf::from);
let name = arg0
Expand All @@ -63,11 +59,7 @@ fn run_rustup() -> Result<()> {

match name {
Some("rustup") => rustup_mode::main(),
Some(n)
if n.starts_with("multirust-setup")
|| n.starts_with("rustup-setup")
|| n.starts_with("rustup-init") =>
{
Some(n) if n.starts_with("rustup-setup") || n.starts_with("rustup-init") => {
// NB: The above check is only for the prefix of the file
// name. Browsers rename duplicates to
// e.g. rustup-setup(2), and this allows all variations
Expand All @@ -79,24 +71,6 @@ fn run_rustup() -> Result<()> {
// rustup deletes its own exe
self_update::complete_windows_uninstall()
}
Some(n) if n.starts_with("multirust-") => {
// This is for compatibility with previous revisions of
// multirust-rs self-update, which expect multirust-rs to
// be available on the server, downloads it to
// ~/.multirust/tmp/multirust-$random, and execute it with
// `self install` as the arguments. FIXME: Verify this
// works.
let opts = self_update::InstallOpts {
default_host_triple: TargetTriple::from_host_or_build().to_string(),
default_toolchain: "stable".to_string(),
no_modify_path: false,
};
if cfg!(windows) {
self_update::install(false, false, opts)
} else {
self_update::install(true, false, opts)
}
}
Some(_) => proxy_mode::main(),
None => {
// Weird case. No arg0, or it's unparsable.
Expand All @@ -116,70 +90,3 @@ fn do_recursion_guard() -> Result<()> {

Ok(())
}

fn do_compatibility_hacks() {
make_environment_compatible();
fix_windows_reg_key();
delete_multirust_bin();
}

// Convert any MULTIRUST_ env vars to RUSTUP_ and warn about them
fn make_environment_compatible() {
let ref vars = ["HOME", "TOOLCHAIN", "DIST_ROOT", "UPDATE_ROOT", "GPG_KEY"];
for var in vars {
let ref mvar = format!("MULTIRUST_{}", var);
let ref rvar = format!("RUSTUP_{}", var);
let mval = env::var_os(mvar);
let rval = env::var_os(rvar);

match (mval, rval) {
(Some(mval), None) => {
env::set_var(rvar, mval);
warn!("environment variable {} is deprecated. Use {}.", mvar, rvar);
}
_ => (),
}
}
}

// #261 We previously incorrectly set HKCU/Environment/PATH to a
// REG_SZ type, when it should be REG_EXPAND_SZ. Silently fix it.
#[cfg(windows)]
fn fix_windows_reg_key() {
use winreg::enums::{RegType, HKEY_CURRENT_USER, KEY_READ, KEY_WRITE};
use winreg::RegKey;

let root = RegKey::predef(HKEY_CURRENT_USER);
let env = root.open_subkey_with_flags("Environment", KEY_READ | KEY_WRITE);

let env = if let Ok(e) = env { e } else { return };

let path = env.get_raw_value("PATH");

let mut path = if let Ok(p) = path { p } else { return };

if path.vtype == RegType::REG_EXPAND_SZ {
return;
}

path.vtype = RegType::REG_EXPAND_SZ;

let _ = env.set_raw_value("PATH", &path);
}

#[cfg(not(windows))]
fn fix_windows_reg_key() {}

// rustup used to be called 'multirust'. This deletes the old bin.
fn delete_multirust_bin() {
use rustup::utils::utils;
use std::env::consts::EXE_SUFFIX;
use std::fs;

if let Ok(home) = utils::cargo_home() {
let legacy_bin = home.join(format!("bin/multirust{}", EXE_SUFFIX));
if legacy_bin.exists() {
let _ = fs::remove_file(legacy_bin);
}
}
}
95 changes: 0 additions & 95 deletions src/cli/self_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,14 +262,10 @@ pub fn install(no_prompt: bool, verbose: bool, mut opts: InstallOpts) -> Result<
}

let install_res: Result<()> = (|| {
cleanup_legacy()?;
install_bins()?;
if !opts.no_modify_path {
do_add_to_path(&get_add_path_methods())?;
}
// Create ~/.rustup and a compatibility ~/.multirust symlink.
// FIXME: Someday we can stop setting up the symlink, and when
// we do that we can stop creating ~/.rustup as well.
utils::create_rustup_home()?;
maybe_install_rust(&opts.default_toolchain, &opts.default_host_triple, verbose)?;

Expand Down Expand Up @@ -340,9 +336,6 @@ fn rustc_or_cargo_exists_in_path() -> Result<()> {
!path
.components()
.any(|c| c == Component::Normal(".cargo".as_ref()))
&& !path
.components()
.any(|c| c == Component::Normal(".multirust".as_ref()))
}

if let Some(paths) = env::var_os("PATH") {
Expand Down Expand Up @@ -381,62 +374,13 @@ fn check_existence_of_rustc_or_cargo_in_path(no_prompt: bool) -> Result<()> {
}

fn do_pre_install_sanity_checks() -> Result<()> {
let multirust_manifest_path = PathBuf::from("/usr/local/lib/rustlib/manifest-multirust");
let rustc_manifest_path = PathBuf::from("/usr/local/lib/rustlib/manifest-rustc");
let uninstaller_path = PathBuf::from("/usr/local/lib/rustlib/uninstall.sh");
let multirust_meta_path = utils::home_dir().map(|d| d.join(".multirust"));
let multirust_version_path = multirust_meta_path.as_ref().map(|p| p.join("version"));
let rustup_sh_path = utils::home_dir().map(|d| d.join(".rustup"));
let rustup_sh_version_path = rustup_sh_path.as_ref().map(|p| p.join("rustup-version"));

let multirust_exists = multirust_manifest_path.exists() && uninstaller_path.exists();
let rustc_exists = rustc_manifest_path.exists() && uninstaller_path.exists();
let rustup_sh_exists = rustup_sh_version_path.map(|p| p.exists()) == Some(true);
let old_multirust_meta_exists = if let Some(ref multirust_version_path) = multirust_version_path
{
multirust_version_path.exists() && {
let version = utils::read_file("old-multirust", multirust_version_path);
let version = version.unwrap_or(String::new());
let version = version.parse().unwrap_or(0);
let cutoff_version = 12; // First rustup version

version < cutoff_version
}
} else {
false
};

match (multirust_exists, old_multirust_meta_exists) {
(true, false) => {
warn!("it looks like you have an existing installation of multirust");
warn!("rustup cannot be installed alongside multirust");
warn!(
"run `{}` as root to uninstall multirust before installing rustup",
uninstaller_path.display()
);
return Err("cannot install while multirust is installed".into());
}
(false, true) => {
warn!("it looks like you have existing multirust metadata");
warn!("rustup cannot be installed alongside multirust");
warn!(
"delete `{}` before installing rustup",
multirust_meta_path.expect("").display()
);
return Err("cannot install while multirust is installed".into());
}
(true, true) => {
warn!("it looks like you have an existing installation of multirust");
warn!("rustup cannot be installed alongside multirust");
warn!(
"run `{}` as root and delete `{}` before installing rustup",
uninstaller_path.display(),
multirust_meta_path.expect("").display()
);
return Err("cannot install while multirust is installed".into());
}
(false, false) => (),
}

if rustc_exists {
warn!("it looks like you have an existing installation of Rust");
Expand Down Expand Up @@ -666,36 +610,6 @@ fn customize_install(mut opts: InstallOpts) -> Result<InstallOpts> {
Ok(opts)
}

// Before rustup-rs installed bins to $CARGO_HOME/bin it installed
// them to $RUSTUP_HOME/bin. If those bins continue to exist after
// upgrade and are on the $PATH, it would cause major confusion. This
// method silently deletes them.
fn cleanup_legacy() -> Result<()> {
let legacy_bin_dir = legacy_multirust_home_dir()?.join("bin");

for tool in TOOLS.iter().cloned().chain(vec!["multirust", "rustup"]) {
let ref file = legacy_bin_dir.join(&format!("{}{}", tool, EXE_SUFFIX));
if file.exists() {
utils::remove_file("legacy-bin", file)?;
}
}

return Ok(());

#[cfg(unix)]
fn legacy_multirust_home_dir() -> Result<PathBuf> {
Ok(utils::legacy_multirust_home()?)
}

#[cfg(windows)]
fn legacy_multirust_home_dir() -> Result<PathBuf> {
use rustup::utils::raw::windows::{get_special_folder, FOLDERID_LocalAppData};

// FIXME: This looks bogus. Where is the .multirust dir?
Ok(get_special_folder(&FOLDERID_LocalAppData).unwrap_or(PathBuf::from(".")))
}
}

fn install_bins() -> Result<()> {
let ref bin_path = utils::cargo_home()?.join("bin");
let ref this_exe_path = utils::current_exe()?;
Expand Down Expand Up @@ -845,8 +759,6 @@ pub fn uninstall(no_prompt: bool) -> Result<()> {

info!("removing rustup home");

utils::delete_legacy_multirust_symlink()?;

// Delete RUSTUP_HOME
let ref rustup_dir = utils::rustup_home()?;
if rustup_dir.exists() {
Expand Down Expand Up @@ -1631,12 +1543,5 @@ pub fn cleanup_self_updater() -> Result<()> {
utils::remove_file("setup", setup)?;
}

// Transitional
let ref old_setup = cargo_home.join(&format!("bin/multirust-setup{}", EXE_SUFFIX));

if old_setup.exists() {
utils::remove_file("setup", old_setup)?;
}

Ok(())
}
2 changes: 0 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ impl Cfg {
utils::ensure_dir_exists("home", &rustup_dir, &|n| notify_handler(n.into()))?;

let settings_file = SettingsFile::new(rustup_dir.join("settings.toml"));
// Convert from old settings format if necessary
settings_file.maybe_upgrade_from_legacy(&rustup_dir)?;

let toolchains_dir = rustup_dir.join("toolchains");
let update_hash_dir = rustup_dir.join("update-hashes");
Expand Down
47 changes: 0 additions & 47 deletions src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use crate::utils::utils;
use std::cell::RefCell;
use std::collections::BTreeMap;
use std::path::{Path, PathBuf};
use std::str::FromStr;

pub const SUPPORTED_METADATA_VERSIONS: [&'static str; 2] = ["2", "12"];
pub const DEFAULT_METADATA_VERSION: &'static str = "12";
Expand Down Expand Up @@ -61,52 +60,6 @@ impl SettingsFile {
self.write_settings()?;
Ok(result)
}
pub fn maybe_upgrade_from_legacy(&self, multirust_dir: &Path) -> Result<()> {
// Data locations
let legacy_version_file = multirust_dir.join("version");
if utils::is_file(&legacy_version_file) {
fn split_override<T: FromStr>(s: &str, separator: char) -> Option<(T, T)> {
s.find(separator).and_then(|index| {
match (T::from_str(&s[..index]), T::from_str(&s[index + 1..])) {
(Ok(l), Ok(r)) => Some((l, r)),
_ => None,
}
})
}

let override_db = multirust_dir.join("overrides");
let default_file = multirust_dir.join("default");
// Legacy upgrade
self.with_mut(|s| {
s.version = utils::read_file("version", &legacy_version_file)?
.trim()
.to_owned();

if utils::is_file(&default_file) {
s.default_toolchain = Some(
utils::read_file("default", &default_file)?
.trim()
.to_owned(),
);
}
if utils::is_file(&override_db) {
let overrides = utils::read_file("overrides", &override_db)?;
for o in overrides.lines() {
if let Some((k, v)) = split_override(o, ';') {
s.overrides.insert(k, v);
}
}
}
Ok(())
})?;

// Failure to delete these is not a fatal error
let _ = utils::remove_file("version", &legacy_version_file);
let _ = utils::remove_file("default", &default_file);
let _ = utils::remove_file("overrides", &override_db);
}
Ok(())
}
}

#[derive(Clone, Debug, PartialEq)]
Expand Down
Loading

0 comments on commit 91af98b

Please sign in to comment.