Skip to content

Commit

Permalink
Separate updating toolchain from adding essential files so they can h…
Browse files Browse the repository at this point in the history
…ave different retries
  • Loading branch information
Nemo157 committed Sep 22, 2023
1 parent 4635eb7 commit 2b075c3
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 35 deletions.
8 changes: 8 additions & 0 deletions src/bin/cratesfyi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,14 @@ impl BuildSubcommand {
rustwide_builder()?
.update_toolchain()
.context("failed to update toolchain")?;

rustwide_builder()?
.purge_caches()
.context("failed to purge caches")?;

rustwide_builder()?
.add_essential_files()
.context("failed to add essential files")?;
}

Self::AddEssentialFiles => {
Expand Down
65 changes: 36 additions & 29 deletions src/build_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,35 @@ impl BuildQueue {
Ok(())
}

fn update_toolchain(&self, builder: &mut RustwideBuilder) -> Result<()> {
let updated = retry(
|| {
builder
.update_toolchain()
.context("downloading new toolchain failed")
},
3,
)?;

if updated {
// toolchain has changed, purge caches
retry(
|| {
builder
.purge_caches()
.context("purging rustwide caches failed")
},
3,
)?;

builder
.add_essential_files()
.context("adding essential files failed")?;
}

Ok(())
}

/// Builds the top package from the queue. Returns whether there was a package in the queue.
///
/// Note that this will return `Ok(true)` even if the package failed to build.
Expand All @@ -442,35 +471,13 @@ impl BuildQueue {
.map(|r| PackageKind::Registry(r.as_str()))
.unwrap_or(PackageKind::CratesIo);

match retry(
|| {
builder
.update_toolchain()
.context("Updating toolchain failed, locking queue")
},
3,
) {
Err(err) => {
report_error(&err);
self.lock()?;
return Err(err);
}
Ok(true) => {
// toolchain has changed, purge caches
if let Err(err) = retry(
|| {
builder
.purge_caches()
.context("purging rustwide caches failed, locking queue")
},
3,
) {
report_error(&err);
self.lock()?;
return Err(err);
}
}
Ok(false) => {}
if let Err(err) = self
.update_toolchain(&mut *builder)
.context("Updating toolchain failed, locking queue")
{
report_error(&err);
self.lock()?;
return Err(err);
}

builder.build_package(&krate.name, &krate.version, kind)?;
Expand Down
6 changes: 0 additions & 6 deletions src/docbuilder/rustwide_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,6 @@ impl RustwideBuilder {
self.rustc_version = self.detect_rustc_version()?;

let has_changed = old_version.as_deref() != Some(&self.rustc_version);
if has_changed {
self.add_essential_files()?;
}
Ok(has_changed)
}

Expand Down Expand Up @@ -312,7 +309,6 @@ impl RustwideBuilder {
}

pub fn build_local_package(&mut self, path: &Path) -> Result<bool> {
self.update_toolchain()?;
let metadata = CargoMetadata::load_from_rustwide(&self.workspace, &self.toolchain, path)
.map_err(|err| {
err.context(format!("failed to load local package {}", path.display()))
Expand All @@ -333,8 +329,6 @@ impl RustwideBuilder {
return Ok(false);
}

self.update_toolchain()?;

info!("building package {} {}", name, version);

if is_blacklisted(&mut conn, name)? {
Expand Down

0 comments on commit 2b075c3

Please sign in to comment.