Skip to content

Commit 7e7eb08

Browse files
authored
Merge pull request #2162 from kinnison/demote-deprecation
Demote deprecation
2 parents 7ebe42b + 4560e85 commit 7e7eb08

File tree

5 files changed

+81
-20
lines changed

5 files changed

+81
-20
lines changed

src/cli/rustup_mode.rs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use clap::{App, AppSettings, Arg, ArgGroup, ArgMatches, Shell, SubCommand};
99
use rustup::dist::dist::{PartialTargetTriple, PartialToolchainDesc, Profile, TargetTriple};
1010
use rustup::dist::manifest::Component;
1111
use rustup::utils::utils::{self, ExitCode};
12+
use rustup::Notification;
1213
use rustup::{command, Cfg, Toolchain};
1314
use std::error::Error;
1415
use std::fmt;
@@ -27,12 +28,23 @@ fn handle_epipe(res: Result<()>) -> Result<()> {
2728
}
2829
}
2930

30-
fn deprecated<F, A, B>(instead: &str, cfg: A, matches: B, callee: F) -> Result<()>
31+
fn deprecated<F, B>(instead: &str, cfg: &mut Cfg, matches: B, callee: F) -> Result<()>
3132
where
32-
F: FnOnce(A, B) -> Result<()>,
33+
F: FnOnce(&mut Cfg, B) -> Result<()>,
3334
{
34-
warn!("Use of deprecated command line interface.");
35-
warn!(" Please use `rustup {}` instead", instead);
35+
(cfg.notify_handler)(Notification::PlainVerboseMessage(
36+
"Use of (currently) unmaintained command line interface.",
37+
));
38+
(cfg.notify_handler)(Notification::PlainVerboseMessage(
39+
"The exact API of this command may change without warning",
40+
));
41+
(cfg.notify_handler)(Notification::PlainVerboseMessage(
42+
"Eventually this command will be a true alias. Until then:",
43+
));
44+
(cfg.notify_handler)(Notification::PlainVerboseMessage(&format!(
45+
" Please use `rustup {}` instead",
46+
instead
47+
)));
3648
callee(cfg, matches)
3749
}
3850

@@ -66,7 +78,7 @@ pub fn main() -> Result<()> {
6678
("install", Some(m)) => deprecated("toolchain install", cfg, m, update)?,
6779
("update", Some(m)) => update(cfg, m)?,
6880
("check", Some(_)) => check_updates(cfg)?,
69-
("uninstall", Some(m)) => deprecated("toolchain uninstall", &*cfg, m, toolchain_remove)?,
81+
("uninstall", Some(m)) => deprecated("toolchain uninstall", cfg, m, toolchain_remove)?,
7082
("default", Some(m)) => default_(cfg, m)?,
7183
("toolchain", Some(c)) => match c.subcommand() {
7284
("install", Some(m)) => update(cfg, m)?,
@@ -1200,7 +1212,7 @@ fn toolchain_link(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> {
12001212
.map_err(Into::into)
12011213
}
12021214

1203-
fn toolchain_remove(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> {
1215+
fn toolchain_remove(cfg: &mut Cfg, m: &ArgMatches<'_>) -> Result<()> {
12041216
for toolchain in m.values_of("toolchain").unwrap() {
12051217
let toolchain = cfg.get_toolchain(toolchain, false)?;
12061218
toolchain.remove()?;

src/notifications.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ pub enum Notification<'a> {
3232
NonFatalError(&'a Error),
3333
UpgradeRemovesToolchains,
3434
MissingFileDuringSelfUninstall(PathBuf),
35+
PlainVerboseMessage(&'a str),
3536
}
3637

3738
impl<'a> From<crate::dist::Notification<'a>> for Notification<'a> {
@@ -64,6 +65,7 @@ impl<'a> Notification<'a> {
6465
| UpdatingToolchain(_)
6566
| ReadMetadataVersion(_)
6667
| InstalledToolchain(_)
68+
| PlainVerboseMessage(_)
6769
| UpdateHashMatches => NotificationLevel::Verbose,
6870
SetDefaultToolchain(_)
6971
| SetOverrideToolchain(_, _)
@@ -127,6 +129,7 @@ impl<'a> Display for Notification<'a> {
127129
"expected file does not exist to uninstall: {}",
128130
p.display()
129131
),
132+
PlainVerboseMessage(r) => write!(f, "{}", r),
130133
}
131134
}
132135
}

tests/cli-misc.rs

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
pub mod mock;
55

66
use crate::mock::clitools::{
7-
self, expect_component_executable, expect_component_not_executable, expect_err, expect_ok,
8-
expect_ok_contains, expect_ok_eq, expect_ok_ex, expect_stderr_ok, expect_stdout_ok, run,
9-
set_current_dist_date, this_host_triple, Config, Scenario,
7+
self, expect_component_executable, expect_component_not_executable, expect_err,
8+
expect_not_stderr_ok, expect_ok, expect_ok_contains, expect_ok_eq, expect_ok_ex,
9+
expect_stderr_ok, expect_stdout_ok, run, set_current_dist_date, this_host_triple, Config,
10+
Scenario,
1011
};
1112
use rustup::utils::{raw, utils};
1213

@@ -998,17 +999,35 @@ fn toolchain_link_then_list_verbose() {
998999
#[test]
9991000
fn deprecated_interfaces() {
10001001
setup(&|config| {
1002+
// In verbose mode we want the deprecated interfaces to complain
10011003
expect_ok_contains(
10021004
config,
1003-
&["rustup", "install", "nightly", "--no-self-update"],
1005+
&[
1006+
"rustup",
1007+
"--verbose",
1008+
"install",
1009+
"nightly",
1010+
"--no-self-update",
1011+
],
10041012
"",
10051013
"Please use `rustup toolchain install` instead",
10061014
);
10071015
expect_ok_contains(
10081016
config,
1009-
&["rustup", "uninstall", "nightly"],
1017+
&["rustup", "--verbose", "uninstall", "nightly"],
10101018
"",
10111019
"Please use `rustup toolchain uninstall` instead",
10121020
);
1021+
// But if not verbose then they should *NOT* complain
1022+
expect_not_stderr_ok(
1023+
config,
1024+
&["rustup", "install", "nightly", "--no-self-update"],
1025+
"Please use `rustup toolchain install` instead",
1026+
);
1027+
expect_not_stderr_ok(
1028+
config,
1029+
&["rustup", "uninstall", "nightly"],
1030+
"Please use `rustup toolchain uninstall` instead",
1031+
);
10131032
})
10141033
}

tests/cli-v2.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pub mod mock;
55

66
use crate::mock::clitools::{
77
self, expect_component_executable, expect_component_not_executable, expect_err,
8-
expect_not_stderr_ok, expect_not_stdout_ok, expect_ok, expect_ok_ex, expect_stderr_ok,
8+
expect_not_stderr_err, expect_not_stdout_ok, expect_ok, expect_ok_ex, expect_stderr_ok,
99
expect_stdout_ok, set_current_dist_date, this_host_triple, Config, Scenario,
1010
};
1111
use std::fs;
@@ -1124,7 +1124,7 @@ fn add_component_suggest_best_match() {
11241124
&["rustup", "component", "add", "rustd"],
11251125
"did you mean 'rustc'?",
11261126
);
1127-
expect_not_stderr_ok(
1127+
expect_not_stderr_err(
11281128
config,
11291129
&["rustup", "component", "add", "potato"],
11301130
"did you mean",
@@ -1136,7 +1136,7 @@ fn add_component_suggest_best_match() {
11361136
fn remove_component_suggest_best_match() {
11371137
setup(&|config| {
11381138
expect_ok(config, &["rustup", "default", "nightly"]);
1139-
expect_not_stderr_ok(
1139+
expect_not_stderr_err(
11401140
config,
11411141
&["rustup", "component", "remove", "rsl"],
11421142
"did you mean 'rls'?",
@@ -1175,7 +1175,7 @@ fn add_target_suggest_best_match() {
11751175
],
11761176
&format!("did you mean '{}'", clitools::CROSS_ARCH1),
11771177
);
1178-
expect_not_stderr_ok(
1178+
expect_not_stderr_err(
11791179
config,
11801180
&["rustup", "target", "add", "potato"],
11811181
"did you mean",
@@ -1187,7 +1187,7 @@ fn add_target_suggest_best_match() {
11871187
fn remove_target_suggest_best_match() {
11881188
setup(&|config| {
11891189
expect_ok(config, &["rustup", "default", "nightly"]);
1190-
expect_not_stderr_ok(
1190+
expect_not_stderr_err(
11911191
config,
11921192
&[
11931193
"rustup",

tests/mock/clitools.rs

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,16 @@ pub fn expect_not_stdout_ok(config: &Config, args: &[&str], expected: &str) {
229229
}
230230

231231
pub fn expect_not_stderr_ok(config: &Config, args: &[&str], expected: &str) {
232+
let out = run(config, args[0], &args[1..], &[]);
233+
if !out.ok || out.stderr.contains(expected) {
234+
print_command(args, &out);
235+
println!("expected.ok: false");
236+
print_indented("expected.stderr.does_not_contain", expected);
237+
panic!();
238+
}
239+
}
240+
241+
pub fn expect_not_stderr_err(config: &Config, args: &[&str], expected: &str) {
232242
let out = run(config, args[0], &args[1..], &[]);
233243
if out.ok || out.stderr.contains(expected) {
234244
print_command(args, &out);
@@ -427,10 +437,27 @@ where
427437
}
428438

429439
println!("running {:?}", cmd);
430-
let lock = cmd_lock().read().unwrap();
431-
let out = cmd.output();
432-
drop(lock);
433-
let out = out.expect("failed to run test command");
440+
let mut retries = 8;
441+
let out = loop {
442+
let lock = cmd_lock().read().unwrap();
443+
let out = cmd.output();
444+
drop(lock);
445+
match out {
446+
Ok(out) => break out,
447+
Err(e) => {
448+
retries -= 1;
449+
if retries > 0
450+
&& e.kind() == std::io::ErrorKind::Other
451+
&& format!("{}", e).contains("os error 26")
452+
{
453+
// This is a ETXTBSY situation
454+
std::thread::sleep(std::time::Duration::from_millis(250));
455+
} else {
456+
panic!("Unable to run test command: {:?}", e);
457+
}
458+
}
459+
}
460+
};
434461

435462
let output = SanitizedOutput {
436463
ok: out.status.success(),

0 commit comments

Comments
 (0)