Skip to content

Commit 93a5569

Browse files
committed
Add rustfmt to the tools list
1 parent ab75525 commit 93a5569

File tree

5 files changed

+76
-17
lines changed

5 files changed

+76
-17
lines changed

Cargo.lock

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

src/rustup-cli/self_update.rs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,14 +184,19 @@ Studio 2013 and during install select the "C++ tools":
184184
185185
_Install the C++ build tools before proceeding_.
186186
187-
If you will be targetting the GNU ABI or otherwise know what you are
187+
If you will be targeting the GNU ABI or otherwise know what you are
188188
doing then it is fine to continue installation without the build
189189
tools, but otherwise, install the C++ build tools before proceeding.
190190
"#;
191191

192192
static TOOLS: &'static [&'static str]
193193
= &["rustc", "rustdoc", "cargo", "rust-lldb", "rust-gdb", "rls"];
194194

195+
// Tools which are commonly installed by Cargo as well as rustup. We take a bit
196+
// more care with these to ensure we don't overwrite the user's previous
197+
// installation.
198+
static DUP_TOOLS: &'static [&'static str] = &["rustfmt", "cargo-fmt"];
199+
195200
static UPDATE_ROOT: &'static str
196201
= "https://static.rust-lang.org/rustup";
197202

@@ -646,13 +651,31 @@ fn install_bins() -> Result<()> {
646651
try!(utils::copy_file(this_exe_path, rustup_path));
647652
try!(utils::make_executable(rustup_path));
648653

654+
// Record the size of the known links, then when we get files which may or
655+
// may not be links, we compare their size. Same size means probably a link.
656+
let mut file_size = 0;
657+
649658
// Try to hardlink all the Rust exes to the rustup exe. Some systems,
650659
// like Android, does not support hardlinks, so we fallback to symlinks.
651660
for tool in TOOLS {
652661
let ref tool_path = bin_path.join(&format!("{}{}", tool, EXE_SUFFIX));
662+
if tool_path.exists() {
663+
file_size = utils::file_size(tool_path)?;
664+
}
653665
try!(utils::hard_or_symlink_file(rustup_path, tool_path));
654666
}
655667

668+
for tool in DUP_TOOLS {
669+
let ref tool_path = bin_path.join(&format!("{}{}", tool, EXE_SUFFIX));
670+
if tool_path.exists() && (file_size == 0 || utils::file_size(tool_path)? != file_size) {
671+
warn!("tool `{}` is already installed, remove it from `{}`, then run `rustup update` \
672+
to have rustup manage this tool.",
673+
tool, bin_path.to_string_lossy());
674+
} else {
675+
try!(utils::hard_or_symlink_file(rustup_path, tool_path));
676+
}
677+
}
678+
656679
Ok(())
657680
}
658681

@@ -752,7 +775,7 @@ pub fn uninstall(no_prompt: bool) -> Result<()> {
752775

753776
// Then everything in bin except rustup and tools. These can't be unlinked
754777
// until this process exits (on windows).
755-
let tools = TOOLS.iter().map(|t| format!("{}{}", t, EXE_SUFFIX));
778+
let tools = TOOLS.iter().chain(DUP_TOOLS.iter()).map(|t| format!("{}{}", t, EXE_SUFFIX));
756779
let tools: Vec<_> = tools.chain(vec![format!("rustup{}", EXE_SUFFIX)]).collect();
757780
for dirent in try!(fs::read_dir(&cargo_home.join("bin")).chain_err(|| read_dir_err)) {
758781
let dirent = try!(dirent.chain_err(|| read_dir_err));

src/rustup-utils/src/utils.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,16 @@ pub fn set_permissions(path: &Path, perms: fs::Permissions) -> Result<()> {
383383
})
384384
}
385385

386+
pub fn file_size(path: &Path) -> Result<u64> {
387+
let metadata = fs::metadata(path).chain_err(|| {
388+
ErrorKind::ReadingFile {
389+
name: "metadata for",
390+
path: PathBuf::from(path),
391+
}
392+
})?;
393+
Ok(metadata.len())
394+
}
395+
386396
pub fn make_executable(path: &Path) -> Result<()> {
387397
#[cfg(windows)]
388398
fn inner(_: &Path) -> Result<()> {

src/rustup-win-installer/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub const LOGMSG_STANDARD: i32 = 2;
1616

1717
// TODO: share this with self_update.rs
1818
static TOOLS: &'static [&'static str]
19-
= &["rustc", "rustdoc", "cargo", "rust-lldb", "rust-gdb", "rls"];
19+
= &["rustc", "rustdoc", "cargo", "rust-lldb", "rust-gdb", "rls", "rustfmt", "cargo-fmt"];
2020

2121
#[no_mangle]
2222
/// This is be run as a `deferred` action after `InstallFiles` on install and upgrade

tests/cli-self-upd.rs

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,13 @@ use std::process::Command;
2727
use remove_dir_all::remove_dir_all;
2828
use rustup_mock::clitools::{self, Config, Scenario,
2929
expect_ok, expect_ok_ex,
30-
expect_stdout_ok,
30+
expect_stdout_ok, expect_stderr_ok,
3131
expect_err, expect_err_ex,
3232
this_host_triple};
3333
use rustup_mock::dist::{calc_hash};
3434
use rustup_mock::{get_path, restore_path};
3535
use rustup_utils::{utils, raw};
3636

37-
#[cfg(windows)]
38-
use rustup_mock::clitools::expect_stderr_ok;
39-
4037
macro_rules! for_host { ($s: expr) => (&format!($s, this_host_triple())) }
4138

4239
const TEST_VERSION: &'static str = "1.1.1";
@@ -49,7 +46,7 @@ pub fn setup(f: &Fn(&Config)) {
4946
}
5047
let _g = LOCK.lock();
5148

52-
// An windows these tests mess with the user's PATH. Save
49+
// On windows these tests mess with the user's PATH. Save
5350
// and restore them here to keep from trashing things.
5451
let saved_path = get_path();
5552
let _g = scopeguard::guard(saved_path, |p| restore_path(p));
@@ -1249,3 +1246,32 @@ fn rls_proxy_set_up_after_update() {
12491246
assert!(rls_path.exists());
12501247
});
12511248
}
1249+
1250+
1251+
#[test]
1252+
fn update_does_not_overwrite_rustfmt() {
1253+
update_setup(&|config, _| {
1254+
expect_ok(config, &["rustup-init", "-y"]);
1255+
let ref rustfmt_path = config.cargodir.join(format!("bin/rustfmt{}", EXE_SUFFIX));
1256+
raw::write_file(rustfmt_path, "").unwrap();
1257+
assert_eq!(utils::file_size(rustfmt_path).unwrap(), 0);
1258+
1259+
expect_stderr_ok(config, &["rustup", "self", "update"],
1260+
"`rustfmt` is already installed");
1261+
expect_ok(config, &["rustup", "self", "update"]);
1262+
assert!(rustfmt_path.exists());
1263+
assert_eq!(utils::file_size(rustfmt_path).unwrap(), 0);
1264+
1265+
1266+
// We run the test twice because the first time around none of the shims
1267+
// exist, and we want to check that out check for rustfmt works if there
1268+
// are shims or not.
1269+
let ref rustdoc_path = config.cargodir.join(format!("bin/rustdoc{}", EXE_SUFFIX));
1270+
assert!(rustdoc_path.exists());
1271+
1272+
expect_stderr_ok(config, &["rustup", "self", "update"],
1273+
"`rustfmt` is already installed");
1274+
assert!(rustfmt_path.exists());
1275+
assert_eq!(utils::file_size(rustfmt_path).unwrap(), 0);
1276+
});
1277+
}

0 commit comments

Comments
 (0)