Skip to content

Commit 59a740f

Browse files
pietroalbiniJoshua Nelson
authored and
Joshua Nelson
committed
remove unused targets when updating rust
1 parent 15a5371 commit 59a740f

File tree

3 files changed

+39
-6
lines changed

3 files changed

+39
-6
lines changed

Cargo.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ tokio = "0.1"
3838
systemstat = "0.1.4"
3939
prometheus = { version = "0.7.0", default-features = false }
4040
lazy_static = "1.0.0"
41-
rustwide = "0.4.0"
41+
rustwide = "0.5.0"
4242
tempdir = "0.3"
4343

4444
# iron dependencies

src/docbuilder/rustwide_builder.rs

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ use postgres::Connection;
1010
use rustc_serialize::json::ToJson;
1111
use rustwide::cmd::{Command, SandboxBuilder};
1212
use rustwide::logging::{self, LogStorage};
13+
use rustwide::toolchain::ToolchainError;
1314
use rustwide::{Build, Crate, Toolchain, Workspace, WorkspaceBuilder};
1415
use std::borrow::Cow;
16+
use std::collections::HashSet;
1517
use std::path::Path;
1618
use utils::{copy_doc_dir, parse_rustc_version, CargoMetadata};
1719
use Metadata;
@@ -95,12 +97,43 @@ impl RustwideBuilder {
9597
// Ignore errors if detection fails.
9698
let old_version = self.detect_rustc_version().ok();
9799

100+
let mut targets_to_install = TARGETS
101+
.iter()
102+
.map(|t| t.to_string())
103+
.collect::<HashSet<_>>();
104+
let installed_targets = match self.toolchain.installed_targets(&self.workspace) {
105+
Ok(targets) => targets,
106+
Err(err) => {
107+
if let Some(&ToolchainError::NotInstalled) = err.downcast_ref::<ToolchainError>() {
108+
Vec::new()
109+
} else {
110+
return Err(err);
111+
}
112+
}
113+
};
114+
115+
// The extra targets are intentionally removed *before* trying to update.
116+
//
117+
// If a target is installed locally and it goes missing the next update, rustup will block
118+
// the update to avoid leaving the system in a broken state. This is not a behavior we want
119+
// though when we also remove the target from the list managed by docs.rs: we want that
120+
// target gone, and we don't care if it's missing in the next update.
121+
//
122+
// Removing it beforehand works fine, and prevents rustup from blocking the update later in
123+
// the method.
124+
for target in installed_targets {
125+
if !targets_to_install.remove(&target) {
126+
self.toolchain.remove_target(&self.workspace, &target)?;
127+
}
128+
}
129+
98130
self.toolchain.install(&self.workspace)?;
99-
for target in TARGETS {
131+
132+
for target in &targets_to_install {
100133
self.toolchain.add_target(&self.workspace, target)?;
101134
}
102-
self.rustc_version = self.detect_rustc_version()?;
103135

136+
self.rustc_version = self.detect_rustc_version()?;
104137
if old_version.as_ref().map(|s| s.as_str()) != Some(&self.rustc_version) {
105138
self.add_essential_files()?;
106139
}

0 commit comments

Comments
 (0)