Skip to content

Commit 352b144

Browse files
authored
Merge branch 'main' into force-skip-std
2 parents 0eb6b73 + 323bf9f commit 352b144

File tree

9 files changed

+196
-268
lines changed

9 files changed

+196
-268
lines changed

src/cli/common.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ use tracing_subscriber::{EnvFilter, Registry, reload::Handle};
1616

1717
use crate::{
1818
config::Cfg,
19-
dist::{TargetTriple, ToolchainDesc},
19+
dist::{DistOptions, TargetTriple, ToolchainDesc},
2020
errors::RustupError,
21-
install::UpdateStatus,
21+
install::{InstallMethod, UpdateStatus},
2222
process::Process,
2323
toolchain::{LocalToolchainName, Toolchain, ToolchainName},
2424
utils,
@@ -215,7 +215,20 @@ pub(crate) async fn update_all_channels(
215215
cfg: &Cfg<'_>,
216216
force_update: bool,
217217
) -> Result<utils::ExitCode> {
218-
let toolchains = cfg.update_all_channels(force_update).await?;
218+
let profile = cfg.get_profile()?;
219+
let mut toolchains = Vec::new();
220+
for (desc, distributable) in cfg.list_channels()? {
221+
let options = DistOptions::new(&[], &[], &desc, profile, force_update, cfg)?
222+
.for_update(&distributable, false);
223+
let result = InstallMethod::Dist(options).install().await;
224+
225+
if let Err(e) = &result {
226+
error!("{e}");
227+
}
228+
229+
toolchains.push((desc, result));
230+
}
231+
219232
let has_update_error = toolchains.iter().any(|(_, r)| r.is_err());
220233
let exit_code = utils::ExitCode(if has_update_error { 1 } else { 0 });
221234

src/cli/rustup_mode.rs

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ use crate::{
4141
command, component_for_bin,
4242
config::{ActiveSource, Cfg},
4343
dist::{
44-
AutoInstallMode, PartialToolchainDesc, Profile, TargetTriple,
44+
AutoInstallMode, DistOptions, PartialToolchainDesc, Profile, TargetTriple,
4545
download::DownloadCfg,
4646
manifest::{Component, ComponentStatus},
4747
},
@@ -960,27 +960,23 @@ async fn update(
960960

961961
let components = opts.component.iter().map(|s| &**s).collect::<Vec<_>>();
962962
let targets = opts.target.iter().map(|s| &**s).collect::<Vec<_>>();
963+
let dist_opts = DistOptions::new(
964+
&components,
965+
&targets,
966+
&desc,
967+
cfg.get_profile()?,
968+
opts.force,
969+
cfg,
970+
)?;
963971

964-
let force = opts.force;
965-
let allow_downgrade = opts.allow_downgrade;
966-
let profile = cfg.get_profile()?;
967972
let status = match DistributableToolchain::new(cfg, desc.clone()) {
968-
Ok(mut d) => {
969-
d.update_extra(&components, &targets, profile, force, allow_downgrade)
973+
Ok(d) => {
974+
InstallMethod::Dist(dist_opts.for_update(&d, opts.allow_downgrade))
975+
.install()
970976
.await?
971977
}
972978
Err(RustupError::ToolchainNotInstalled { .. }) => {
973-
DistributableToolchain::install(
974-
cfg,
975-
&desc,
976-
&components,
977-
&targets,
978-
profile,
979-
force,
980-
false,
981-
)
982-
.await?
983-
.0
979+
DistributableToolchain::install(dist_opts).await?.0
984980
}
985981
Err(e) => Err(e)?,
986982
};
@@ -1520,17 +1516,8 @@ async fn override_add(
15201516
Err(e @ RustupError::ToolchainNotInstalled { .. }) => match &toolchain_name {
15211517
ToolchainName::Custom(_) => Err(e)?,
15221518
ToolchainName::Official(desc) => {
1523-
let status = DistributableToolchain::install(
1524-
cfg,
1525-
desc,
1526-
&[],
1527-
&[],
1528-
cfg.get_profile()?,
1529-
false,
1530-
false,
1531-
)
1532-
.await?
1533-
.0;
1519+
let options = DistOptions::new(&[], &[], desc, cfg.get_profile()?, false, cfg)?;
1520+
let status = DistributableToolchain::install(options).await?.0;
15341521
writeln!(cfg.process.stdout().lock())?;
15351522
common::show_channel_update(
15361523
cfg,

src/cli/self_update.rs

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,13 @@ use crate::{
5959
markdown::md,
6060
},
6161
config::Cfg,
62-
dist::{PartialToolchainDesc, Profile, TargetTriple, ToolchainDesc, download::DownloadCfg},
62+
dist::{
63+
DistOptions, PartialToolchainDesc, Profile, TargetTriple, ToolchainDesc,
64+
download::DownloadCfg,
65+
},
6366
download::download_file,
6467
errors::RustupError,
65-
install::UpdateStatus,
68+
install::{InstallMethod, UpdateStatus},
6669
process::Process,
6770
toolchain::{
6871
DistributableToolchain, MaybeOfficialToolchainName, ResolvableToolchainName, Toolchain,
@@ -996,29 +999,20 @@ async fn maybe_install_rust(opts: InstallOpts<'_>, cfg: &mut Cfg<'_>) -> Result<
996999
let (components, targets) = (opts.components, opts.targets);
9971000
let toolchain = opts.install(cfg)?;
9981001
if let Some(desc) = &toolchain {
1002+
let options = DistOptions::new(components, targets, desc, cfg.get_profile()?, true, cfg)?;
9991003
let status = if Toolchain::exists(cfg, &desc.into())? {
10001004
warn!("Updating existing toolchain, profile choice will be ignored");
10011005
// If we have a partial install we might not be able to read content here. We could:
10021006
// - fail and folk have to delete the partially present toolchain to recover
10031007
// - silently ignore it (and provide inconsistent metadata for reporting the install/update change)
10041008
// - delete the partial install and start over
10051009
// For now, we error.
1006-
let mut toolchain = DistributableToolchain::new(cfg, desc.clone())?;
1007-
toolchain
1008-
.update(components, targets, cfg.get_profile()?)
1010+
let toolchain = DistributableToolchain::new(cfg, desc.clone())?;
1011+
InstallMethod::Dist(options.for_update(&toolchain, false))
1012+
.install()
10091013
.await?
10101014
} else {
1011-
DistributableToolchain::install(
1012-
cfg,
1013-
desc,
1014-
components,
1015-
targets,
1016-
cfg.get_profile()?,
1017-
true,
1018-
false,
1019-
)
1020-
.await?
1021-
.0
1015+
DistributableToolchain::install(options).await?.0
10221016
};
10231017

10241018
check_proxy_sanity(cfg.process, components, desc)?;

src/config.rs

Lines changed: 24 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,17 @@ use std::str::FromStr;
66
use anyhow::{Context, Result, anyhow, bail};
77
use serde::Deserialize;
88
use thiserror::Error as ThisError;
9-
use tokio_stream::StreamExt;
109
use tracing::{debug, error, info, trace, warn};
1110

12-
use crate::dist::AutoInstallMode;
1311
use crate::{
1412
cli::{common, self_update::SelfUpdateMode},
15-
dist::{self, PartialToolchainDesc, Profile, TargetTriple, ToolchainDesc, temp},
13+
dist::{
14+
self, AutoInstallMode, DistOptions, PartialToolchainDesc, Profile, TargetTriple,
15+
ToolchainDesc, temp,
16+
},
1617
errors::RustupError,
1718
fallback_settings::FallbackSettings,
18-
install::UpdateStatus,
19+
install::{InstallMethod, UpdateStatus},
1920
process::Process,
2021
settings::{MetadataVersion, Settings, SettingsFile},
2122
toolchain::{
@@ -797,29 +798,31 @@ impl<'a> Cfg<'a> {
797798
}
798799
let components: Vec<_> = components.iter().map(AsRef::as_ref).collect();
799800
let targets: Vec<_> = targets.iter().map(AsRef::as_ref).collect();
800-
let profile = match profile {
801-
Some(profile) => profile,
802-
None => self.get_profile()?,
803-
};
801+
let mut options = DistOptions::new(
802+
&components,
803+
&targets,
804+
toolchain,
805+
match profile {
806+
Some(p) => p,
807+
None => self.get_profile()?,
808+
},
809+
false,
810+
self,
811+
)?;
812+
804813
let (status, toolchain) = match DistributableToolchain::new(self, toolchain.clone()) {
805814
Err(RustupError::ToolchainNotInstalled { .. }) => {
806-
DistributableToolchain::install(
807-
self,
808-
toolchain,
809-
&components,
810-
&targets,
811-
profile,
812-
false,
813-
skip_std,
814-
)
815-
.await?
815+
DistributableToolchain::install(options).await?
816816
}
817-
Ok(mut distributable) => {
817+
Ok(distributable) => {
818818
if verbose {
819819
info!("using existing install for {toolchain}");
820820
}
821821
let status = if !distributable.components_exist(&components, &targets)? {
822-
distributable.update(&components, &targets, profile).await?
822+
options.force = true;
823+
InstallMethod::Dist(options.for_update(&distributable, false))
824+
.install()
825+
.await?
823826
} else {
824827
UpdateStatus::Unchanged
825828
};
@@ -903,28 +906,6 @@ impl<'a> Cfg<'a> {
903906
})
904907
}
905908

906-
pub(crate) async fn update_all_channels(
907-
&self,
908-
force_update: bool,
909-
) -> Result<Vec<(ToolchainDesc, Result<UpdateStatus>)>> {
910-
let channels = self.list_channels()?;
911-
let channels = channels.into_iter();
912-
let profile = self.get_profile()?;
913-
914-
// Update toolchains and collect the results
915-
let channels = tokio_stream::iter(channels).then(|(desc, mut distributable)| async move {
916-
let st = distributable
917-
.update_extra(&[], &[], profile, force_update, false)
918-
.await;
919-
if let Err(e) = &st {
920-
error!("{e}");
921-
}
922-
(desc, st)
923-
});
924-
925-
Ok(channels.collect().await)
926-
}
927-
928909
pub(crate) fn set_default_host_triple(&self, host_triple: String) -> Result<()> {
929910
// Ensure that the provided host_triple is capable of resolving
930911
// against the 'stable' toolchain. This provides early errors
@@ -954,7 +935,7 @@ impl<'a> Cfg<'a> {
954935

955936
/// The root path of the release server, without the `/dist` suffix.
956937
/// By default, it points to [`dist::DEFAULT_DIST_SERVER`].
957-
pub(crate) fn dist_root_server(process: &Process) -> Result<String> {
938+
fn dist_root_server(process: &Process) -> Result<String> {
958939
if let Some(s) = process.var_opt("RUSTUP_DIST_SERVER")? {
959940
trace!("`RUSTUP_DIST_SERVER` has been set to `{s}`");
960941
return Ok(s);

src/dist/manifestation.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ impl Manifestation {
361361
pub(crate) async fn update_v1(
362362
&self,
363363
new_manifest: &[String],
364-
update_hash: Option<&Path>,
364+
update_hash: &Path,
365365
dl_cfg: &DownloadCfg<'_>,
366366
) -> Result<Option<String>> {
367367
// If there's already a v2 installation then something has gone wrong
@@ -387,7 +387,7 @@ impl Manifestation {
387387

388388
let status = dl_cfg.status_for("rust");
389389
let dl = dl_cfg
390-
.download_and_check(&url, update_hash, Some(&status), ".tar.gz")
390+
.download_and_check(&url, Some(update_hash), Some(&status), ".tar.gz")
391391
.await?;
392392
if dl.is_none() {
393393
return Ok(None);

0 commit comments

Comments
 (0)