Skip to content

Commit c44e884

Browse files
authored
Merge pull request #2586 from kinnison/profile-in-rust-toolchain
Profile in rust toolchain
2 parents fbfc454 + 5f4ca98 commit c44e884

File tree

6 files changed

+59
-8
lines changed

6 files changed

+59
-8
lines changed

doc/src/overrides.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ called `rust-toolchain`, the content of which is either the name of a single
8282
channel = "nightly-2020-07-10"
8383
components = [ "rustfmt", "rustc-dev" ]
8484
targets = [ "wasm32-unknown-unknown", "thumbv2-none-eabi" ]
85+
profile = "minimal"
8586
```
8687

8788
If the TOML format is used, the `[toolchain]` section is mandatory, and at

src/cli/rustup_mode.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -949,6 +949,7 @@ fn update(cfg: &mut Cfg, m: &ArgMatches<'_>) -> Result<utils::ExitCode> {
949949
m.is_present("allow-downgrade"),
950950
&components,
951951
&targets,
952+
None,
952953
)?)
953954
} else if !toolchain.exists() {
954955
return Err(ErrorKind::InvalidToolchainName(toolchain.name().to_string()).into());

src/cli/self_update.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,7 @@ fn maybe_install_rust(
738738
warn!("Updating existing toolchain, profile choice will be ignored");
739739
}
740740
let distributable = DistributableToolchain::new(&toolchain)?;
741-
let status = distributable.install_from_dist(true, false, components, targets)?;
741+
let status = distributable.install_from_dist(true, false, components, targets, None)?;
742742
let toolchain_str = toolchain.name().to_owned();
743743
toolchain.cfg().set_default(&toolchain_str)?;
744744
writeln!(process().stdout())?;

src/config.rs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ struct ToolchainSection {
3535
channel: Option<String>,
3636
components: Option<Vec<String>>,
3737
targets: Option<Vec<String>>,
38+
profile: Option<String>,
3839
}
3940

4041
impl ToolchainSection {
@@ -78,6 +79,7 @@ struct OverrideCfg<'a> {
7879
toolchain: Option<Toolchain<'a>>,
7980
components: Vec<String>,
8081
targets: Vec<String>,
82+
profile: Option<dist::Profile>,
8183
}
8284

8385
impl<'a> OverrideCfg<'a> {
@@ -89,6 +91,12 @@ impl<'a> OverrideCfg<'a> {
8991
},
9092
components: file.toolchain.components.unwrap_or_default(),
9193
targets: file.toolchain.targets.unwrap_or_default(),
94+
profile: file
95+
.toolchain
96+
.profile
97+
.as_deref()
98+
.map(dist::Profile::from_str)
99+
.transpose()?,
92100
})
93101
}
94102
}
@@ -660,13 +668,14 @@ impl Cfg {
660668
}
661669
}
662670

663-
if let Some((toolchain, components, targets, reason)) =
671+
if let Some((toolchain, components, targets, reason, profile)) =
664672
match self.find_override_config(path)? {
665673
Some((
666674
OverrideCfg {
667675
toolchain,
668676
components,
669677
targets,
678+
profile,
670679
},
671680
reason,
672681
)) => {
@@ -678,11 +687,11 @@ impl Cfg {
678687

679688
toolchain
680689
.or(default)
681-
.map(|toolchain| (toolchain, components, targets, Some(reason)))
690+
.map(|toolchain| (toolchain, components, targets, Some(reason), profile))
682691
}
683692
None => self
684693
.find_default()?
685-
.map(|toolchain| (toolchain, vec![], vec![], None)),
694+
.map(|toolchain| (toolchain, vec![], vec![], None, None)),
686695
}
687696
{
688697
if toolchain.is_custom() {
@@ -698,7 +707,7 @@ impl Cfg {
698707
let distributable = DistributableToolchain::new(&toolchain)?;
699708
if !toolchain.exists() || !components_exist(&distributable, &components, &targets)?
700709
{
701-
distributable.install_from_dist(true, false, &components, &targets)?;
710+
distributable.install_from_dist(true, false, &components, &targets, profile)?;
702711
}
703712
}
704713

@@ -760,7 +769,7 @@ impl Cfg {
760769
let channels = channels.map(|(n, t)| {
761770
let st = t.and_then(|t| {
762771
let distributable = DistributableToolchain::new(&t)?;
763-
let st = distributable.install_from_dist(force_update, false, &[], &[]);
772+
let st = distributable.install_from_dist(force_update, false, &[], &[], None);
764773
if let Err(ref e) = st {
765774
(self.notify_handler)(Notification::NonFatalError(e));
766775
}
@@ -815,7 +824,7 @@ impl Cfg {
815824
let toolchain = self.get_toolchain(toolchain, false)?;
816825
if install_if_missing && !toolchain.exists() {
817826
let distributable = DistributableToolchain::new(&toolchain)?;
818-
distributable.install_from_dist(true, false, &[], &[])?;
827+
distributable.install_from_dist(true, false, &[], &[], None)?;
819828
}
820829

821830
if let Some(cmd) = self.maybe_do_cargo_fallback(&toolchain, binary)? {
@@ -911,6 +920,7 @@ mod tests {
911920
channel: Some(contents.into()),
912921
components: None,
913922
targets: None,
923+
profile: None,
914924
}
915925
}
916926
);
@@ -922,6 +932,7 @@ mod tests {
922932
channel = "nightly-2020-07-10"
923933
components = [ "rustfmt", "rustc-dev" ]
924934
targets = [ "wasm32-unknown-unknown", "thumbv2-none-eabi" ]
935+
profile = "default"
925936
"#;
926937

927938
let result = Cfg::parse_override_file(contents);
@@ -935,6 +946,7 @@ targets = [ "wasm32-unknown-unknown", "thumbv2-none-eabi" ]
935946
"wasm32-unknown-unknown".into(),
936947
"thumbv2-none-eabi".into()
937948
]),
949+
profile: Some("default".into()),
938950
}
939951
}
940952
);
@@ -954,6 +966,7 @@ channel = "nightly-2020-07-10"
954966
channel: Some("nightly-2020-07-10".into()),
955967
components: None,
956968
targets: None,
969+
profile: None,
957970
}
958971
}
959972
);
@@ -974,6 +987,7 @@ components = []
974987
channel: Some("nightly-2020-07-10".into()),
975988
components: Some(vec![]),
976989
targets: None,
990+
profile: None,
977991
}
978992
}
979993
);
@@ -994,6 +1008,7 @@ targets = []
9941008
channel: Some("nightly-2020-07-10".into()),
9951009
components: None,
9961010
targets: Some(vec![]),
1011+
profile: None,
9971012
}
9981013
}
9991014
);
@@ -1013,6 +1028,7 @@ components = [ "rustfmt" ]
10131028
channel: None,
10141029
components: Some(vec!["rustfmt".into()]),
10151030
targets: None,
1031+
profile: None,
10161032
}
10171033
}
10181034
);

src/toolchain.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use wait_timeout::ChildExt;
1212

1313
use crate::component_for_bin;
1414
use crate::config::Cfg;
15+
use crate::dist::dist::Profile;
1516
use crate::dist::dist::TargetTriple;
1617
use crate::dist::dist::ToolchainDesc;
1718
use crate::dist::download::DownloadCfg;
@@ -685,12 +686,15 @@ impl<'a> DistributableToolchain<'a> {
685686
allow_downgrade: bool,
686687
components: &[&str],
687688
targets: &[&str],
689+
profile: Option<Profile>,
688690
) -> Result<UpdateStatus> {
689691
let update_hash = self.update_hash()?;
690692
let old_date = self.get_manifest().ok().and_then(|m| m.map(|m| m.date));
691693
InstallMethod::Dist {
692694
desc: &self.desc()?,
693-
profile: self.0.cfg.get_profile()?,
695+
profile: profile
696+
.map(Ok)
697+
.unwrap_or_else(|| self.0.cfg.get_profile())?,
694698
update_hash: Some(&update_hash),
695699
dl_cfg: self.download_cfg(),
696700
force_update,

tests/cli-rustup.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1548,6 +1548,35 @@ components = [ "rust-bongo" ]
15481548
});
15491549
}
15501550

1551+
#[test]
1552+
fn file_override_toml_format_specify_profile() {
1553+
setup(&|config| {
1554+
expect_ok(config, &["rustup", "set", "profile", "default"]);
1555+
expect_stderr_ok(
1556+
config,
1557+
&["rustup", "default", "stable"],
1558+
"downloading component 'rust-docs'",
1559+
);
1560+
1561+
let cwd = config.current_dir();
1562+
let toolchain_file = cwd.join("rust-toolchain");
1563+
raw::write_file(
1564+
&toolchain_file,
1565+
r#"
1566+
[toolchain]
1567+
profile = "minimal"
1568+
channel = "nightly"
1569+
"#,
1570+
)
1571+
.unwrap();
1572+
expect_not_stdout_ok(
1573+
config,
1574+
&["rustup", "component", "list"],
1575+
for_host!("rust-docs-{} (installed)"),
1576+
);
1577+
});
1578+
}
1579+
15511580
#[test]
15521581
fn directory_override_beats_file_override() {
15531582
setup(&|config| {

0 commit comments

Comments
 (0)