Skip to content

Commit

Permalink
refactor: Defer calculating the toolchain flag
Browse files Browse the repository at this point in the history
In addition to decoupling concerns (expansion of a range into discrete
versions), this will make it easier to do contains checks and insertions
on the discrete versions.
  • Loading branch information
epage authored and taiki-e committed Sep 7, 2023
1 parent a70540a commit 2f7dee8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub(crate) struct Context {
pub(crate) cargo_version: u32,
pub(crate) restore: restore::Manager,
pub(crate) current_dir: PathBuf,
pub(crate) version_range: Option<Vec<(u32, String)>>,
pub(crate) version_range: Option<Vec<u32>>,
pub(crate) use_github_action_grouping: bool,
}

Expand Down
11 changes: 6 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ fn try_main() -> Result<()> {
if let Some(range) = &cx.version_range {
let total = progress.total;
progress.total = 0;
for (cargo_version, _) in range {
for cargo_version in range {
if cx.target.is_empty() || *cargo_version >= 64 {
progress.total += total;
} else {
Expand All @@ -79,11 +79,12 @@ fn try_main() -> Result<()> {
// Workaround for spurious "failed to select a version" error.
// (This does not work around the underlying cargo bug: https://github.com/rust-lang/cargo/issues/10623)
let mut regenerate_lockfile_on_51_or_up = false;
for (cargo_version, toolchain) in range {
rustup::install_toolchain(toolchain, &cx.target, true)?;
for cargo_version in range {
let toolchain = format!("+1.{cargo_version}");
rustup::install_toolchain(&toolchain, &cx.target, true)?;
if generate_lockfile || regenerate_lockfile_on_51_or_up && *cargo_version >= 51 {
let mut line = line.clone();
line.leading_arg(toolchain);
line.leading_arg(&toolchain);
line.arg("generate-lockfile");
if let Some(pid) = cx.current_package() {
let package = cx.packages(pid);
Expand All @@ -110,7 +111,7 @@ fn try_main() -> Result<()> {
}

let mut line = line.clone();
line.leading_arg(toolchain);
line.leading_arg(&toolchain);
line.apply_context(cx);
exec_on_packages(
cx,
Expand Down
8 changes: 3 additions & 5 deletions src/rustup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl Rustup {
}
}

pub(crate) fn version_range(range: VersionRange, cx: &Context) -> Result<Vec<(u32, String)>> {
pub(crate) fn version_range(range: VersionRange, cx: &Context) -> Result<Vec<u32>> {
let check = |version: &Version| {
if version.major != 1 {
bail!("major version must be 1");
Expand Down Expand Up @@ -98,10 +98,8 @@ pub(crate) fn version_range(range: VersionRange, cx: &Context) -> Result<Vec<(u3
MaybeVersion::Stable => get_stable_version()?,
};

let versions: Vec<_> = (start_inclusive.minor..=end_inclusive.minor)
.step_by(cx.version_step as _)
.map(|minor| (minor, format!("+1.{minor}")))
.collect();
let versions: Vec<_> =
(start_inclusive.minor..=end_inclusive.minor).step_by(cx.version_step as _).collect();
if versions.is_empty() {
bail!("specified version range `{range}` is empty");
}
Expand Down

0 comments on commit 2f7dee8

Please sign in to comment.