Skip to content

Commit 77d366d

Browse files
committed
Move install_from_dir to CustomToolchain
1 parent dc44f64 commit 77d366d

File tree

3 files changed

+33
-28
lines changed

3 files changed

+33
-28
lines changed

src/cli/errors.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ error_chain! {
2626
}
2727

2828
errors {
29+
InvalidCustomToolchainName(t: String) {
30+
display("invalid custom toolchain name: '{}'", t)
31+
}
2932
PermissionDenied {
3033
description("permission denied")
3134
}

src/cli/rustup_mode.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ use crate::self_update;
55
use crate::term2;
66
use crate::term2::Terminal;
77
use crate::topical_doc;
8+
89
use clap::{App, AppSettings, Arg, ArgGroup, ArgMatches, Shell, SubCommand};
910
use rustup::dist::dist::{PartialTargetTriple, PartialToolchainDesc, Profile, TargetTriple};
1011
use rustup::dist::manifest::Component;
11-
use rustup::toolchain::DistributableToolchain;
12+
use rustup::toolchain::{CustomToolchain, DistributableToolchain};
1213
use rustup::utils::utils::{self, ExitCode};
1314
use rustup::Notification;
1415
use rustup::{command, Cfg, ComponentStatus, Toolchain};
@@ -1233,9 +1234,13 @@ fn toolchain_link(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> {
12331234
let path = m.value_of("path").unwrap();
12341235
let toolchain = cfg.get_toolchain(toolchain, true)?;
12351236

1236-
toolchain
1237-
.install_from_dir(Path::new(path), true)
1238-
.map_err(Into::into)
1237+
if let Ok(custom) = CustomToolchain::new(&toolchain) {
1238+
custom
1239+
.install_from_dir(Path::new(path), true)
1240+
.map_err(Into::into)
1241+
} else {
1242+
Err(ErrorKind::InvalidCustomToolchainName(toolchain.name().to_string()).into())
1243+
}
12391244
}
12401245

12411246
fn toolchain_remove(cfg: &mut Cfg, m: &ArgMatches<'_>) -> Result<()> {

src/toolchain.rs

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -221,30 +221,6 @@ impl<'a> Toolchain<'a> {
221221
Ok(())
222222
}
223223

224-
// Custom only. Not installed only.
225-
pub fn install_from_dir(&self, src: &Path, link: bool) -> Result<()> {
226-
self.ensure_custom()?;
227-
let custom = CustomToolchain::new(&self)?;
228-
229-
let mut pathbuf = PathBuf::from(src);
230-
231-
pathbuf.push("lib");
232-
utils::assert_is_directory(&pathbuf)?;
233-
pathbuf.pop();
234-
pathbuf.push("bin");
235-
utils::assert_is_directory(&pathbuf)?;
236-
pathbuf.push(format!("rustc{}", EXE_SUFFIX));
237-
utils::assert_is_file(&pathbuf)?;
238-
239-
if link {
240-
InstallMethod::Link(&utils::to_absolute(src)?, &custom).install(&self)?;
241-
} else {
242-
InstallMethod::Copy(src, &custom).install(&self)?;
243-
}
244-
245-
Ok(())
246-
}
247-
248224
// Both Distributable and Custom; Installed only.
249225
pub fn create_command<T: AsRef<OsStr>>(&self, binary: T) -> Result<Command> {
250226
if !self.exists() {
@@ -514,6 +490,27 @@ impl<'a> CustomToolchain<'a> {
514490
Err(format!("{} is not a custom toolchain", toolchain.name()).into())
515491
}
516492
}
493+
494+
// Not installed only.
495+
pub fn install_from_dir(&self, src: &Path, link: bool) -> Result<()> {
496+
let mut pathbuf = PathBuf::from(src);
497+
498+
pathbuf.push("lib");
499+
utils::assert_is_directory(&pathbuf)?;
500+
pathbuf.pop();
501+
pathbuf.push("bin");
502+
utils::assert_is_directory(&pathbuf)?;
503+
pathbuf.push(format!("rustc{}", EXE_SUFFIX));
504+
utils::assert_is_file(&pathbuf)?;
505+
506+
if link {
507+
InstallMethod::Link(&utils::to_absolute(src)?, self).install(&self.0)?;
508+
} else {
509+
InstallMethod::Copy(src, self).install(&self.0)?;
510+
}
511+
512+
Ok(())
513+
}
517514
}
518515

519516
impl<'a> InstalledToolchain<'a> for CustomToolchain<'a> {

0 commit comments

Comments
 (0)