Skip to content

Commit 954fe6e

Browse files
committed
Remove telemetry
1 parent b697df1 commit 954fe6e

File tree

20 files changed

+10
-970
lines changed

20 files changed

+10
-970
lines changed

Cargo.lock

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ serde_derive = "1.0"
5151
serde_json = "1.0"
5252
sha2 = "0.7.0"
5353
tempdir = "0.3.4"
54-
tempfile = "3.0.2"
5554
term = "0.5.1"
5655
time = "0.1.34"
5756
toml = "0.4"

src/rustup-cli/common.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
use crate::errors::*;
44
use crate::self_update;
55
use crate::term2;
6-
use rustup::telemetry_analysis::TelemetryAnalysis;
76
use rustup::{self, Cfg, Notification, Toolchain, UpdateStatus};
87
use rustup_utils::notify::NotificationLevel;
98
use rustup_utils::utils;
@@ -434,11 +433,3 @@ pub fn report_error(e: &Error) {
434433
false
435434
}
436435
}
437-
438-
pub fn show_telemetry(analysis: TelemetryAnalysis) -> Result<()> {
439-
println!("Telemetry Analysis");
440-
441-
println!("{}", analysis);
442-
443-
Ok(())
444-
}

src/rustup-cli/proxy_mode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,5 @@ fn direct_proxy(
5757
None => cfg.create_command_for_dir(&utils::current_dir()?, arg0)?,
5858
Some(tc) => cfg.create_command_for_toolchain(tc, false, arg0)?,
5959
};
60-
Ok(run_command_for_dir(cmd, arg0, args, &cfg)?)
60+
Ok(run_command_for_dir(cmd, arg0, args)?)
6161
}

src/rustup-cli/rustup_mode.rs

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use crate::help::*;
44
use crate::self_update;
55
use crate::term2;
66
use clap::{App, AppSettings, Arg, ArgGroup, ArgMatches, Shell, SubCommand};
7-
use rustup::settings::TelemetryMode;
87
use rustup::{command, Cfg, Toolchain};
98
use rustup_dist::dist::{PartialTargetTriple, PartialToolchainDesc, TargetTriple};
109
use rustup_dist::manifest::Component;
@@ -71,12 +70,6 @@ pub fn main() -> Result<()> {
7170
("uninstall", Some(m)) => self_uninstall(m)?,
7271
(_, _) => unreachable!(),
7372
},
74-
("telemetry", Some(c)) => match c.subcommand() {
75-
("enable", Some(_)) => set_telemetry(&cfg, TelemetryMode::On)?,
76-
("disable", Some(_)) => set_telemetry(&cfg, TelemetryMode::Off)?,
77-
("analyze", Some(_)) => analyze_telemetry(&cfg)?,
78-
(_, _) => unreachable!(),
79-
},
8073
("set", Some(c)) => match c.subcommand() {
8174
("default-host", Some(m)) => set_default_host_triple(&cfg, m)?,
8275
(_, _) => unreachable!(),
@@ -453,17 +446,6 @@ pub fn cli() -> App<'static, 'static> {
453446
SubCommand::with_name("upgrade-data").about("Upgrade the internal data format."),
454447
),
455448
)
456-
.subcommand(
457-
SubCommand::with_name("telemetry")
458-
.about("rustup telemetry commands")
459-
.setting(AppSettings::Hidden)
460-
.setting(AppSettings::VersionlessSubcommands)
461-
.setting(AppSettings::DeriveDisplayOrder)
462-
.setting(AppSettings::SubcommandRequiredElseHelp)
463-
.subcommand(SubCommand::with_name("enable").about("Enable rustup telemetry"))
464-
.subcommand(SubCommand::with_name("disable").about("Disable rustup telemetry"))
465-
.subcommand(SubCommand::with_name("analyze").about("Analyze stored telemetry")),
466-
)
467449
.subcommand(
468450
SubCommand::with_name("set")
469451
.about("Alter rustup settings")
@@ -630,7 +612,7 @@ fn run(cfg: &Cfg, m: &ArgMatches) -> Result<()> {
630612
let args: Vec<_> = args.collect();
631613
let cmd = cfg.create_command_for_toolchain(toolchain, m.is_present("install"), args[0])?;
632614

633-
let ExitCode(c) = command::run_command_for_dir(cmd, args[0], &args[1..], &cfg)?;
615+
let ExitCode(c) = command::run_command_for_dir(cmd, args[0], &args[1..])?;
634616

635617
process::exit(c)
636618
}
@@ -1030,18 +1012,6 @@ fn self_uninstall(m: &ArgMatches) -> Result<()> {
10301012
self_update::uninstall(no_prompt)
10311013
}
10321014

1033-
fn set_telemetry(cfg: &Cfg, t: TelemetryMode) -> Result<()> {
1034-
match t {
1035-
TelemetryMode::On => Ok(cfg.set_telemetry(true)?),
1036-
TelemetryMode::Off => Ok(cfg.set_telemetry(false)?),
1037-
}
1038-
}
1039-
1040-
fn analyze_telemetry(cfg: &Cfg) -> Result<()> {
1041-
let analysis = cfg.analyze_telemetry()?;
1042-
common::show_telemetry(analysis)
1043-
}
1044-
10451015
fn set_default_host_triple(cfg: &Cfg, m: &ArgMatches) -> Result<()> {
10461016
cfg.set_default_host_triple(m.value_of("host_triple").expect(""))?;
10471017
Ok(())

src/rustup-mock/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ tempdir = "0.3.4"
2020
tar = "0.4.0"
2121
toml = "0.4"
2222
sha2 = "0.7.0"
23-
wait-timeout = "0.1.3"
2423

2524
[target."cfg(windows)".dependencies]
2625
winapi = "0.3"

src/rustup-mock/src/clitools.rs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ use std::sync::Arc;
2020
use std::time::Duration;
2121
use tempdir::TempDir;
2222
use url::Url;
23-
use wait_timeout::ChildExt;
2423

2524
/// The configuration used by the tests in this module
2625
pub struct Config {
@@ -252,25 +251,6 @@ pub fn expect_ok_contains(config: &Config, args: &[&str], stdout: &str, stderr:
252251
}
253252
}
254253

255-
pub fn expect_timeout_ok(config: &Config, timeout: Duration, args: &[&str]) {
256-
let mut child = cmd(config, args[0], &args[1..])
257-
.stdout(Stdio::null())
258-
.stderr(Stdio::null())
259-
.spawn()
260-
.unwrap();
261-
262-
match child.wait_timeout(timeout).unwrap() {
263-
Some(status) => {
264-
assert!(status.success(), "not ok {:?}", args);
265-
}
266-
None => {
267-
// child hasn't exited yet
268-
child.kill().unwrap();
269-
panic!("command timed out: {:?}", args);
270-
}
271-
}
272-
}
273-
274254
fn print_command(args: &[&str], out: &SanitizedOutput) {
275255
print!("\n>");
276256
for arg in args {

src/rustup-mock/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ extern crate tar;
88
extern crate tempdir;
99
extern crate toml;
1010
extern crate url;
11-
extern crate wait_timeout;
1211
extern crate walkdir;
1312
extern crate xz2;
1413

src/rustup-utils/src/toml_utils.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,6 @@ pub fn get_bool(table: &mut toml::value::Table, key: &str, path: &str) -> Result
4343
})
4444
}
4545

46-
pub fn get_opt_bool(table: &mut toml::value::Table, key: &str, path: &str) -> Result<Option<bool>> {
47-
if let Ok(v) = get_value(table, key, path) {
48-
if let toml::Value::Boolean(b) = v {
49-
Ok(Some(b))
50-
} else {
51-
Err(ErrorKind::ExpectedType("bool", path.to_owned() + key).into())
52-
}
53-
} else {
54-
Ok(None)
55-
}
56-
}
57-
5846
pub fn get_table(
5947
table: &mut toml::value::Table,
6048
key: &str,

src/rustup/command.rs

Lines changed: 2 additions & 169 deletions
Original file line numberDiff line numberDiff line change
@@ -1,155 +1,11 @@
1-
use regex::Regex;
21
use std::ffi::OsStr;
3-
use std::fs::File;
4-
use std::io::{self, BufRead, BufReader, Seek, SeekFrom, Write};
5-
use std::process::{self, Command, Stdio};
6-
use std::time::Instant;
7-
use tempfile::tempfile;
2+
use std::io;
3+
use std::process::{self, Command};
84

95
use crate::errors::*;
10-
use crate::notifications::*;
11-
use crate::telemetry::{Telemetry, TelemetryEvent};
12-
use crate::Cfg;
136
use rustup_utils::{self, utils::ExitCode};
147

158
pub fn run_command_for_dir<S: AsRef<OsStr>>(
16-
cmd: Command,
17-
arg0: &str,
18-
args: &[S],
19-
cfg: &Cfg,
20-
) -> Result<ExitCode> {
21-
if (arg0 == "rustc" || arg0 == "rustc.exe") && cfg.telemetry_enabled()? {
22-
return telemetry_rustc(cmd, arg0, args, cfg);
23-
}
24-
25-
exec_command_for_dir_without_telemetry(cmd, arg0, args)
26-
}
27-
28-
fn telemetry_rustc<S: AsRef<OsStr>>(
29-
mut cmd: Command,
30-
arg0: &str,
31-
args: &[S],
32-
cfg: &Cfg,
33-
) -> Result<ExitCode> {
34-
#[cfg(unix)]
35-
fn file_as_stdio(file: &File) -> Stdio {
36-
use std::os::unix::io::{AsRawFd, FromRawFd};
37-
unsafe { Stdio::from_raw_fd(file.as_raw_fd()) }
38-
}
39-
40-
#[cfg(windows)]
41-
fn file_as_stdio(file: &File) -> Stdio {
42-
use std::os::windows::io::{AsRawHandle, FromRawHandle};
43-
unsafe { Stdio::from_raw_handle(file.as_raw_handle()) }
44-
}
45-
46-
let now = Instant::now();
47-
48-
cmd.args(args);
49-
50-
let has_color_args = args.iter().any(|e| {
51-
let e = e.as_ref().to_str().unwrap_or("");
52-
e.starts_with("--color")
53-
});
54-
55-
if stderr_isatty() && !has_color_args {
56-
cmd.arg("--color");
57-
cmd.arg("always");
58-
}
59-
60-
let mut cmd_err_file = tempfile().unwrap();
61-
let cmd_err_stdio = file_as_stdio(&cmd_err_file);
62-
63-
// FIXME rust-lang/rust#32254. It's not clear to me
64-
// when and why this is needed.
65-
let mut cmd = cmd
66-
.stdin(Stdio::inherit())
67-
.stdout(Stdio::inherit())
68-
.stderr(cmd_err_stdio)
69-
.spawn()
70-
.unwrap();
71-
72-
let status = cmd.wait();
73-
74-
let duration = now.elapsed();
75-
76-
let ms = (duration.as_secs() as u64 * 1000) + (duration.subsec_nanos() as u64 / 1000 / 1000);
77-
78-
let t = Telemetry::new(cfg.rustup_dir.join("telemetry"));
79-
80-
match status {
81-
Ok(status) => {
82-
let exit_code = status.code().unwrap_or(1);
83-
84-
let re = Regex::new(r"\[(?P<error>E.{4})\]").unwrap();
85-
86-
let mut buffer = String::new();
87-
// Chose a HashSet instead of a Vec to avoid calls to sort() and dedup().
88-
// The HashSet should be faster if there are a lot of errors, too.
89-
let mut errors: Vec<String> = Vec::new();
90-
91-
let stderr = io::stderr();
92-
let mut handle = stderr.lock();
93-
94-
cmd_err_file.seek(SeekFrom::Start(0)).unwrap();
95-
96-
let mut buffered_stderr = BufReader::new(cmd_err_file);
97-
98-
while buffered_stderr.read_line(&mut buffer).unwrap() > 0 {
99-
let b = buffer.to_owned();
100-
buffer.clear();
101-
let _ = handle.write(b.as_bytes());
102-
103-
if let Some(caps) = re.captures(&b) {
104-
if caps.len() > 0 {
105-
errors.push(
106-
caps.name("error")
107-
.map(|m| m.as_str())
108-
.unwrap_or("")
109-
.to_owned(),
110-
);
111-
}
112-
};
113-
}
114-
115-
let e = if errors.is_empty() {
116-
None
117-
} else {
118-
Some(errors)
119-
};
120-
121-
let te = TelemetryEvent::RustcRun {
122-
duration_ms: ms,
123-
exit_code: exit_code,
124-
errors: e,
125-
};
126-
127-
let _ = t.log_telemetry(te).map_err(|xe| {
128-
(cfg.notify_handler)(Notification::TelemetryCleanupError(&xe));
129-
});
130-
131-
Ok(ExitCode(exit_code))
132-
}
133-
Err(e) => {
134-
let exit_code = e.raw_os_error().unwrap_or(1);
135-
let te = TelemetryEvent::RustcRun {
136-
duration_ms: ms,
137-
exit_code: exit_code,
138-
errors: None,
139-
};
140-
141-
let _ = t.log_telemetry(te).map_err(|xe| {
142-
(cfg.notify_handler)(Notification::TelemetryCleanupError(&xe));
143-
});
144-
145-
Err(e).chain_err(|| rustup_utils::ErrorKind::RunningCommand {
146-
name: OsStr::new(arg0).to_owned(),
147-
})
148-
}
149-
}
150-
}
151-
152-
fn exec_command_for_dir_without_telemetry<S: AsRef<OsStr>>(
1539
mut cmd: Command,
15410
arg0: &str,
15511
args: &[S],
@@ -176,26 +32,3 @@ fn exec_command_for_dir_without_telemetry<S: AsRef<OsStr>>(
17632
Ok(ExitCode(status.code().unwrap()))
17733
}
17834
}
179-
180-
#[cfg(unix)]
181-
fn stderr_isatty() -> bool {
182-
use libc;
183-
unsafe { libc::isatty(libc::STDERR_FILENO) != 0 }
184-
}
185-
186-
#[cfg(windows)]
187-
fn stderr_isatty() -> bool {
188-
type DWORD = u32;
189-
type BOOL = i32;
190-
type HANDLE = *mut u8;
191-
const STD_ERROR_HANDLE: DWORD = -12i32 as DWORD;
192-
extern "system" {
193-
fn GetStdHandle(which: DWORD) -> HANDLE;
194-
fn GetConsoleMode(hConsoleHandle: HANDLE, lpMode: *mut DWORD) -> BOOL;
195-
}
196-
unsafe {
197-
let handle = GetStdHandle(STD_ERROR_HANDLE);
198-
let mut out = 0;
199-
GetConsoleMode(handle, &mut out) != 0
200-
}
201-
}

0 commit comments

Comments
 (0)