Skip to content

Commit 4291376

Browse files
committed
Merge pull request #161 from brson/multirust-env
Rename MULTIRUST_ env vars to RUSTUP_. Leave compatibility code.
2 parents 306297f + d04ec91 commit 4291376

File tree

15 files changed

+75
-41
lines changed

15 files changed

+75
-41
lines changed

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ If the date is omitted, the toolchain will track the most recent version.
114114
The following environment variables can be used to customize the behaviour of
115115
multirust-rs:
116116

117+
- `MULTIRUST_HOME` (default: `~/.multirust` or `%LOCALAPPDATA%/.multirust`)
118+
Sets the root multirust folder, used for storing installed toolchains and configuration
119+
options.
120+
117121
- `MULTIRUST_TOOLCHAIN` (default: none)
118122
If set, will override the toolchain used for all rust tool invocations. A toolchain
119123
with this name should be installed, or invocations will fail.
@@ -122,9 +126,8 @@ multirust-rs:
122126
Sets the root URL for downloading packages. You can change this to instead use
123127
a local mirror, or to test the binaries from the staging directory.
124128

125-
- `MULTIRUST_HOME` (default: `~/.multirust` or `%LOCALAPPDATA%/.multirust`)
126-
Sets the root multirust folder, used for storing installed toolchains and configuration
127-
options.
129+
- `MULTIRUST_UPDATE_ROOT` (default `https://static.rust-lang.org/rustup/dist`)
130+
Sets the root URL for downloading self-updates.
128131

129132
- `MULTIRUST_GPG_KEY` (default: none)
130133
Sets the GPG key used to verify the signatures of downloaded files.

src/multirust-cli/main.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ extern crate openssl;
1313
extern crate itertools;
1414
extern crate time;
1515
extern crate rand;
16-
#[macro_use]
1716
extern crate scopeguard;
1817
extern crate tempdir;
1918

@@ -60,6 +59,10 @@ fn run_multirust() -> Result<()> {
6059
return Err(Error::InfiniteRecursion);
6160
}
6261

62+
// Map MULTIRUST_ env vars to RUSTUP_
63+
// FIXME: Remove this soon to get it out of the proxy path
64+
make_environment_compatible();
65+
6366
// The name of arg0 determines how the program is going to behave
6467
let arg0 = env::args().next().map(|a| PathBuf::from(a));
6568
let name = arg0.as_ref()
@@ -108,3 +111,21 @@ fn run_multirust() -> Result<()> {
108111
}
109112
}
110113

114+
// Convert any MULTIRUST_ env vars to RUSTUP_ and warn about them
115+
fn make_environment_compatible() {
116+
let ref vars = ["HOME", "TOOLCHAIN", "DIST_ROOT", "UPDATE_ROOT", "GPG_KEY"];
117+
for var in vars {
118+
let ref mvar = format!("MULTIRUST_{}", var);
119+
let ref rvar = format!("RUSTUP_{}", var);
120+
let mval = env::var_os(mvar);
121+
let rval = env::var_os(rvar);
122+
123+
match (mval, rval) {
124+
(Some(mval), None) => {
125+
env::set_var(rvar, mval);
126+
warn!("environment variable {} is deprecated. Use {}.", mvar, rvar);
127+
}
128+
_ => ()
129+
}
130+
}
131+
}

src/multirust-cli/self_update.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
//!
2424
//! During uninstall (`multirust self uninstall`):
2525
//!
26-
//! * Delete `$MULTIRUST_HOME`.
26+
//! * Delete `$RUSTUP_HOME`.
2727
//! * Delete everything in `$CARGO_HOME`, including
2828
//! the multirust binary and its hardlinks
2929
//!
@@ -43,6 +43,7 @@ use std::path::{Path, PathBuf};
4343
use std::process::{self, Command};
4444
use std::fs;
4545
use tempdir::TempDir;
46+
use scopeguard;
4647

4748
// The big installation messages. These are macros because the first
4849
// argument of format! needs to be a literal.
@@ -233,7 +234,7 @@ fn pre_install_msg() -> Result<String> {
233234
}
234235

235236
// Before multirust-rs installed bins to $CARGO_HOME/bin it installed
236-
// them to $MULTIRUST_HOME/bin. If those bins continue to exist after
237+
// them to $RUSTUP_HOME/bin. If those bins continue to exist after
237238
// upgrade and are on the $PATH, it would cause major confusion. This
238239
// method silently deletes them.
239240
fn cleanup_legacy() -> Result<()> {
@@ -323,7 +324,7 @@ pub fn uninstall(no_prompt: bool) -> Result<()> {
323324

324325
info!("removing multirust home");
325326

326-
// Delete MULTIRUST_HOME
327+
// Delete RUSTUP_HOME
327328
let ref multirust_dir = try!(utils::multirust_home());
328329
if multirust_dir.exists() {
329330
try!(utils::remove_dir("multirust_home", multirust_dir, ntfy!(&NotifyHandler::none())));
@@ -475,7 +476,7 @@ fn delete_multirust_and_cargo_home() -> Result<()> {
475476
return Err(Error::WindowsUninstallMadness(err));
476477
}
477478

478-
defer!{{ let _ = CloseHandle(gc_handle); }}
479+
let _g = scopeguard::guard(gc_handle, |h| { let _ = CloseHandle(*h); });
479480

480481
try!(Command::new(gc_exe).spawn()
481482
.map_err(|e| Error::WindowsUninstallMadness(e)));
@@ -537,7 +538,7 @@ fn wait_for_parent() -> Result<()> {
537538
return Err(Error::WindowsUninstallMadness(err));
538539
}
539540

540-
defer! {{ let _ = CloseHandle(snapshot); }}
541+
let _g = scopeguard::guard(snapshot, |h| { let _ = CloseHandle(*h); });
541542

542543
let mut entry: PROCESSENTRY32 = mem::zeroed();
543544
entry.dwSize = mem::size_of::<PROCESSENTRY32>() as DWORD;
@@ -570,7 +571,7 @@ fn wait_for_parent() -> Result<()> {
570571
return Ok(());
571572
}
572573

573-
defer! {{ let _ = CloseHandle(parent); }}
574+
let _g = scopeguard::guard(parent, |h| { let _ = CloseHandle(*h); });
574575

575576
// Wait for our parent to exit
576577
let res = WaitForSingleObject(parent, INFINITE);
@@ -816,7 +817,7 @@ pub fn prepare_update() -> Result<Option<PathBuf>> {
816817
// Get host triple
817818
let triple = dist::get_host_triple();
818819

819-
let update_root = env::var("MULTIRUST_UPDATE_ROOT")
820+
let update_root = env::var("RUSTUP_UPDATE_ROOT")
820821
.unwrap_or(String::from(UPDATE_ROOT));
821822

822823
let tempdir = try!(TempDir::new("multirust-update")

src/multirust-mock/src/clitools.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@ use dist::{MockDistServer, MockChannel, MockPackage,
1414
MockTargettedPackage, MockComponent, change_channel_date,
1515
ManifestVersion};
1616
use hyper::Url;
17+
use scopeguard;
1718

1819
/// The configuration used by the tests in this module
1920
pub struct Config {
2021
/// Where we put the multirust / rustc / cargo bins
2122
pub exedir: PathBuf,
2223
/// The distribution server
2324
pub distdir: PathBuf,
24-
/// MULTIRUST_HOME
25+
/// RUSTUP_HOME
2526
pub rustupdir: PathBuf,
2627
/// Custom toolchains
2728
pub customdir: PathBuf,
@@ -56,7 +57,7 @@ pub static MULTI_ARCH1: &'static str = "i686-unknown-linux-gnu";
5657
/// a mock dist server.
5758
pub fn setup(s: Scenario, f: &Fn(&Config)) {
5859
// Unset env variables that will break our testing
59-
env::remove_var("MULTIRUST_TOOLCHAIN");
60+
env::remove_var("RUSTUP_TOOLCHAIN");
6061

6162
let exedir = TempDir::new("rustup-exe").unwrap();
6263
let distdir = TempDir::new("rustup-dist").unwrap();
@@ -206,8 +207,8 @@ pub fn cmd(config: &Config, name: &str, args: &[&str]) -> Command {
206207
}
207208

208209
pub fn env(config: &Config, cmd: &mut Command) {
209-
cmd.env("MULTIRUST_HOME", config.rustupdir.to_string_lossy().to_string());
210-
cmd.env("MULTIRUST_DIST_ROOT", format!("file://{}", config.distdir.join("dist").to_string_lossy()));
210+
cmd.env("RUSTUP_HOME", config.rustupdir.to_string_lossy().to_string());
211+
cmd.env("RUSTUP_DIST_ROOT", format!("file://{}", config.distdir.join("dist").to_string_lossy()));
211212
cmd.env("CARGO_HOME", config.cargodir.to_string_lossy().to_string());
212213

213214
// This is only used for some installation tests on unix where CARGO_HOME
@@ -232,9 +233,7 @@ pub fn run(config: &Config, name: &str, args: &[&str], env: &[(&str, &str)]) ->
232233
pub fn change_dir(path: &Path, f: &Fn()) {
233234
let cwd = env::current_dir().unwrap();
234235
env::set_current_dir(path).unwrap();
235-
defer! {
236-
env::set_current_dir(&cwd).unwrap()
237-
}
236+
let _g = scopeguard::guard(cwd, |d| env::set_current_dir(d).unwrap());
238237
f();
239238
}
240239

src/multirust-mock/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
extern crate hyper;
44
#[macro_use]
55
extern crate lazy_static;
6-
#[macro_use]
76
extern crate scopeguard;
87
extern crate walkdir;
98
extern crate flate2;

src/multirust-utils/src/errors.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ impl error::Error for Error {
195195
OpeningBrowser { error: None } => "could not open browser: no browser installed",
196196
SettingPermissions {..} => "failed to set permissions",
197197
CargoHome => "couldn't find value of CARGO_HOME",
198-
MultirustHome => "couldn't find value of MULTIRUST_HOME",
198+
MultirustHome => "couldn't find value of RUSTUP_HOME",
199199
}
200200
}
201201

@@ -365,7 +365,7 @@ impl Display for Error {
365365
error)
366366
},
367367
CargoHome => write!(f, "couldn't find value of CARGO_HOME"),
368-
MultirustHome => write!(f, "couldn't find value of MULTIRUST_HOME"),
368+
MultirustHome => write!(f, "couldn't find value of RUSTUP_HOME"),
369369
}
370370
}
371371
}

src/multirust-utils/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
extern crate hyper;
55
extern crate openssl;
66
extern crate rand;
7-
#[macro_use]
87
extern crate scopeguard;
98

109
#[cfg(windows)]

src/multirust-utils/src/utils.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use errors::{Error, Notification, NotifyHandler};
1212
use raw;
1313
#[cfg(windows)]
1414
use winapi::DWORD;
15+
use scopeguard;
1516

1617
pub use raw::{is_directory, is_file, path_exists, if_not_empty, random_string, prefix_arg,
1718
has_cmd, find_cmd};
@@ -333,7 +334,7 @@ pub fn home_dir() -> Option<PathBuf> {
333334
if OpenProcessToken(me, TOKEN_READ, &mut token) == 0 {
334335
return None
335336
}
336-
defer! {{ let _ = CloseHandle(token); }}
337+
let _g = scopeguard::guard(token, |h| { let _ = CloseHandle(*h); });
337338
fill_utf16_buf(|buf, mut sz| {
338339
match GetUserProfileDirectoryW(token, buf, &mut sz) {
339340
0 if GetLastError() != ERROR_INSUFFICIENT_BUFFER => 0,
@@ -436,7 +437,7 @@ pub fn cargo_home() -> Result<PathBuf> {
436437

437438
pub fn multirust_home() -> Result<PathBuf> {
438439
let cwd = try!(env::current_dir().map_err(|_| Error::MultirustHome));
439-
let multirust_home = env::var_os("MULTIRUST_HOME").map(|home| {
440+
let multirust_home = env::var_os("RUSTUP_HOME").map(|home| {
440441
cwd.join(home)
441442
});
442443
let user_home = home_dir().map(|p| p.join(".multirust"));

src/multirust/config.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub enum OverrideReason {
2525
impl Display for OverrideReason {
2626
fn fmt(&self, f: &mut fmt::Formatter) -> ::std::result::Result<(), fmt::Error> {
2727
match *self {
28-
OverrideReason::Environment => write!(f, "environment override by MULTIRUST_TOOLCHAIN"),
28+
OverrideReason::Environment => write!(f, "environment override by RUSTUP_TOOLCHAIN"),
2929
OverrideReason::OverrideDB(ref path) => {
3030
write!(f, "directory override for '{}'", path.display())
3131
}
@@ -69,19 +69,19 @@ impl Cfg {
6969
}));
7070

7171
// GPG key
72-
let gpg_key = if let Some(path) = env::var_os("MULTIRUST_GPG_KEY")
72+
let gpg_key = if let Some(path) = env::var_os("RUSTUP_GPG_KEY")
7373
.and_then(utils::if_not_empty) {
7474
Cow::Owned(try!(utils::read_file("public key", Path::new(&path))))
7575
} else {
7676
Cow::Borrowed(include_str!("rust-key.gpg.ascii"))
7777
};
7878

7979
// Environment override
80-
let env_override = env::var("MULTIRUST_TOOLCHAIN")
80+
let env_override = env::var("RUSTUP_TOOLCHAIN")
8181
.ok()
8282
.and_then(utils::if_not_empty);
8383

84-
let dist_root_url = env::var("MULTIRUST_DIST_ROOT")
84+
let dist_root_url = env::var("RUSTUP_DIST_ROOT")
8585
.ok()
8686
.and_then(utils::if_not_empty)
8787
.map_or(Cow::Borrowed(dist::DEFAULT_DIST_ROOT), Cow::Owned);

src/multirust/toolchain.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ impl<'a> Toolchain<'a> {
240240
pub fn create_fallback_command<T: AsRef<OsStr>>(&self, binary: T,
241241
primary_toolchain: &Toolchain) -> Result<Command> {
242242
let mut cmd = try!(self.create_command(binary));
243-
cmd.env("MULTIRUST_TOOLCHAIN", &primary_toolchain.name);
243+
cmd.env("RUSTUP_TOOLCHAIN", &primary_toolchain.name);
244244
Ok(cmd)
245245
}
246246

@@ -257,8 +257,8 @@ impl<'a> Toolchain<'a> {
257257

258258
env_var::inc("RUST_RECURSION_COUNT", cmd);
259259

260-
cmd.env("MULTIRUST_TOOLCHAIN", &self.name);
261-
cmd.env("MULTIRUST_HOME", &self.cfg.multirust_dir);
260+
cmd.env("RUSTUP_TOOLCHAIN", &self.name);
261+
cmd.env("RUSTUP_HOME", &self.cfg.multirust_dir);
262262
}
263263

264264
pub fn set_ldpath(&self, cmd: &mut Command) {

tests/cli-misc.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ fn no_colors_in_piped_error_output() {
3333
#[test]
3434
fn rustc_with_bad_multirust_toolchain_env_var() {
3535
setup(&|config| {
36-
let out = run(config, "rustc", &[], &[("MULTIRUST_TOOLCHAIN", "bogus")]);
36+
let out = run(config, "rustc", &[], &[("RUSTUP_TOOLCHAIN", "bogus")]);
3737
assert!(!out.ok);
3838
assert!(out.stderr.contains("toolchain 'bogus' is not installed"));
3939
});
@@ -722,3 +722,15 @@ fn custom_toolchain_cargo_fallback_run() {
722722
});
723723
}
724724

725+
fn multirust_env_compat() {
726+
setup(&|config| {
727+
let mut cmd = clitools::cmd(config, "rustup", &["update", "nightly"]);
728+
clitools::env(config, &mut cmd);
729+
cmd.env_remove("RUSTUP_HOME");
730+
cmd.env("MULTIRUST_HOME", &config.rustupdir);
731+
let out = cmd.output().unwrap();
732+
assert!(out.status.success());
733+
let stderr = String::from_utf8(out.stderr).unwrap();
734+
assert!(stderr.contains("environment variable MULTIRUST_HOME is deprecated. Use RUSTUP_HOME"));
735+
});
736+
}

tests/cli-rustup.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,11 +278,11 @@ fn show_toolchain_env() {
278278
expect_ok(config, &["rustup", "default", "nightly"]);
279279
let mut cmd = clitools::cmd(config, "rustup", &["show"]);
280280
clitools::env(config, &mut cmd);
281-
cmd.env("MULTIRUST_TOOLCHAIN", "nightly");
281+
cmd.env("RUSTUP_TOOLCHAIN", "nightly");
282282
let out = cmd.output().unwrap();
283283
assert!(out.status.success());
284284
let stdout = String::from_utf8(out.stdout).unwrap();
285-
assert!(stdout == "nightly (environment override by MULTIRUST_TOOLCHAIN)\n");
285+
assert!(stdout == "nightly (environment override by RUSTUP_TOOLCHAIN)\n");
286286
});
287287
}
288288

@@ -291,7 +291,7 @@ fn show_toolchain_env_not_installed() {
291291
setup(&|config| {
292292
let mut cmd = clitools::cmd(config, "rustup", &["show"]);
293293
clitools::env(config, &mut cmd);
294-
cmd.env("MULTIRUST_TOOLCHAIN", "nightly");
294+
cmd.env("RUSTUP_TOOLCHAIN", "nightly");
295295
let out = cmd.output().unwrap();
296296
// I'm not sure this should really be erroring when the toolchain
297297
// is not installed; just capturing the behavior.

tests/cli-self-update.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ extern crate multirust_utils;
55
#[macro_use]
66
extern crate lazy_static;
77
extern crate tempdir;
8-
#[macro_use]
98
extern crate scopeguard;
109

1110
#[cfg(windows)]
@@ -38,8 +37,8 @@ pub fn setup(f: &Fn(&Config)) {
3837

3938
// An windows these tests mess with the user's PATH. Save
4039
// and restore them here to keep from trashing things.
41-
let ref saved_path = get_path();
42-
defer! { restore_path(saved_path) }
40+
let saved_path = get_path();
41+
let _g = scopeguard::guard(saved_path, |p| restore_path(p));
4342

4443
f(config);
4544
});
@@ -65,7 +64,7 @@ pub fn update_setup(f: &Fn(&Config, &Path)) {
6564
create_hash(dist_exe, dist_hash);
6665

6766
let ref root_url = format!("file://{}", self_dist.display());
68-
env::set_var("MULTIRUST_UPDATE_ROOT", root_url);
67+
env::set_var("RUSTUP_UPDATE_ROOT", root_url);
6968

7069
f(config, self_dist);
7170
});

tests/cli-v1.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ fn show_override_from_multirust_toolchain_env_var() {
332332
expect_ok(config, &["multirust", "override", "nightly"]);
333333
// change_dir has a lock so it's ok to futz the environment
334334
let out = run(config, "multirust", &["show-override"],
335-
&[("MULTIRUST_TOOLCHAIN", "beta")]);
335+
&[("RUSTUP_TOOLCHAIN", "beta")]);
336336
assert!(out.ok);
337337
assert!(out.stdout.contains("override toolchain: beta"));
338338
assert!(out.stdout.contains("override reason: environment override"));

tests/cli-v2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ fn show_override_from_multirust_toolchain_env_var() {
335335
expect_ok(config, &["multirust", "override", "nightly"]);
336336
// change_dir has a lock so it's ok to futz the environment
337337
let out = run(config, "multirust", &["show-override"],
338-
&[("MULTIRUST_TOOLCHAIN", "beta")]);
338+
&[("RUSTUP_TOOLCHAIN", "beta")]);
339339
assert!(out.ok);
340340
assert!(out.stdout.contains("override toolchain: beta"));
341341
assert!(out.stdout.contains("override reason: environment override"));

0 commit comments

Comments
 (0)