Skip to content

Commit 10ddaa8

Browse files
committed
Add a new "fix" mode
This introduces a new "fix" mode to run `cargo fix`. This is primarily intended to support edition migration testing. This includes two related changes: - Adds the ability to change the CapLints behavior because setting CapLints interferes with how `cargo fix` works. - Sets the mount mode of the source directory to read-write because `cargo fix` inherently needs to be able to write to the source directory. It probably needs more work for general purpose `cargo fix` testing (non-edition) because otherwise it would need to rebuild the source directory between toolchains. I don't need that right now, so deferred that till later.
1 parent 2eb688f commit 10ddaa8

File tree

8 files changed

+76
-9
lines changed

8 files changed

+76
-9
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
@@ -52,7 +52,7 @@ remove_dir_all = "0.7"
5252
reqwest = { version = "0.11", features = ["blocking", "json"] }
5353
rusqlite = { version = "0.32.1", features = ["chrono", "functions", "bundled"] }
5454
rust_team_data = { git = "https://github.com/rust-lang/team" }
55-
rustwide = { version = "0.19.1", features = [
55+
rustwide = { version = "0.19.3", features = [
5656
"unstable",
5757
"unstable-toolchain-ci",
5858
] }

docs/bot-usage.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ The following experiment modes are currently available:
8585
* `check-only`: run `cargo check` on every crate (faster)
8686
* `clippy`: run `cargo clippy` on every crate
8787
* `rustdoc`: run `cargo doc --no-deps` on every crate
88+
* `fix`: run `cargo fix` on every crate (intended for edition migration testing)
8889

8990
The mode you should use depends on what your experiment is testing:
9091

src/experiments.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ string_enum!(pub enum Mode {
3030
Clippy => "clippy",
3131
Rustdoc => "rustdoc",
3232
UnstableFeatures => "unstable-features",
33+
Fix => "fix",
3334
});
3435

3536
string_enum!(pub enum CapLints {

src/runner/tasks.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ pub(super) enum TaskStep {
4848
Clippy { tc: Toolchain, quiet: bool },
4949
Rustdoc { tc: Toolchain, quiet: bool },
5050
UnstableFeatures { tc: Toolchain },
51+
Fix { tc: Toolchain, quiet: bool },
5152
}
5253

5354
impl fmt::Debug for TaskStep {
@@ -59,6 +60,7 @@ impl fmt::Debug for TaskStep {
5960
TaskStep::Clippy { ref tc, quiet } => ("clippy", quiet, Some(tc)),
6061
TaskStep::Rustdoc { ref tc, quiet } => ("doc", quiet, Some(tc)),
6162
TaskStep::UnstableFeatures { ref tc } => ("find unstable features on", false, Some(tc)),
63+
TaskStep::Fix { ref tc, quiet } => ("fix", quiet, Some(tc)),
6264
};
6365

6466
write!(f, "{name}")?;
@@ -124,6 +126,7 @@ impl Task {
124126
tc,
125127
false,
126128
),
129+
TaskStep::Fix { ref tc, quiet } => (&build_dir[tc], "fixing", test::fix, tc, quiet),
127130
};
128131

129132
let ctx = TaskCtx::new(build_dir, config, ex, toolchain, &self.krate, quiet);

src/runner/test.rs

Lines changed: 60 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::crates::Crate;
2+
use crate::experiments::CapLints;
23
use crate::prelude::*;
34
use crate::results::DiagnosticCode;
45
use crate::results::{BrokenReason, FailureReason, TestResult};
@@ -9,7 +10,7 @@ use cargo_metadata::diagnostic::DiagnosticLevel;
910
use cargo_metadata::{Message, Metadata, Package, Target};
1011
use docsrs_metadata::Metadata as DocsrsMetadata;
1112
use remove_dir_all::remove_dir_all;
12-
use rustwide::cmd::{CommandError, ProcessLinesActions, SandboxBuilder};
13+
use rustwide::cmd::{CommandError, MountKind, ProcessLinesActions, SandboxBuilder};
1314
use rustwide::logging::LogStorage;
1415
use rustwide::{Build, PrepareError};
1516
use std::collections::{BTreeSet, HashMap, HashSet};
@@ -89,6 +90,8 @@ fn run_cargo(
8990
check_errors: bool,
9091
local_packages: &[Package],
9192
env: HashMap<&'static str, String>,
93+
mount_kind: MountKind,
94+
cap_lints: Option<CapLints>,
9295
) -> Fallible<()> {
9396
let local_packages_id: HashSet<_> = local_packages.iter().map(|p| &p.id).collect();
9497

@@ -100,13 +103,17 @@ fn run_cargo(
100103
args.extend(tc_cargoflags.split(' '));
101104
}
102105

103-
let mut rustflags = format!("--cap-lints={}", ctx.experiment.cap_lints.to_str());
106+
let mut rustflags = cap_lints
107+
.map(|cap| format!("--cap-lints={cap}"))
108+
.unwrap_or_default();
104109
if let Some(ref tc_rustflags) = ctx.toolchain.rustflags {
105110
rustflags.push(' ');
106111
rustflags.push_str(tc_rustflags);
107112
}
108113

109-
let mut rustdocflags = format!("--cap-lints={}", ctx.experiment.cap_lints.to_str());
114+
let mut rustdocflags = cap_lints
115+
.map(|cap| format!("--cap-lints={cap}"))
116+
.unwrap_or_default();
110117
if let Some(ref tc_rustdocflags) = ctx.toolchain.rustdocflags {
111118
rustdocflags.push(' ');
112119
rustdocflags.push_str(tc_rustdocflags);
@@ -187,6 +194,7 @@ fn run_cargo(
187194
let mut command = build_env
188195
.cargo()
189196
.args(&args)
197+
.source_dir_mount_kind(mount_kind)
190198
.env("CARGO_INCREMENTAL", "0")
191199
.env("RUST_BACKTRACE", "full")
192200
.env("RUSTFLAGS", rustflags)
@@ -266,6 +274,8 @@ fn build(ctx: &TaskCtx, build_env: &Build, local_packages: &[Package]) -> Fallib
266274
true,
267275
local_packages,
268276
HashMap::default(),
277+
MountKind::ReadOnly,
278+
Some(ctx.experiment.cap_lints),
269279
)?;
270280
run_cargo(
271281
ctx,
@@ -274,6 +284,8 @@ fn build(ctx: &TaskCtx, build_env: &Build, local_packages: &[Package]) -> Fallib
274284
true,
275285
local_packages,
276286
HashMap::default(),
287+
MountKind::ReadOnly,
288+
Some(ctx.experiment.cap_lints),
277289
)?;
278290
Ok(())
279291
}
@@ -286,6 +298,8 @@ fn test(ctx: &TaskCtx, build_env: &Build) -> Fallible<()> {
286298
false,
287299
&[],
288300
HashMap::default(),
301+
MountKind::ReadOnly,
302+
Some(ctx.experiment.cap_lints),
289303
)
290304
}
291305

@@ -339,6 +353,8 @@ pub(super) fn test_check_only(
339353
true,
340354
local_packages_id,
341355
HashMap::default(),
356+
MountKind::ReadOnly,
357+
Some(ctx.experiment.cap_lints),
342358
) {
343359
Ok(TestResult::BuildFail(failure_reason(&err)))
344360
} else {
@@ -364,6 +380,8 @@ pub(super) fn test_clippy_only(
364380
true,
365381
local_packages,
366382
HashMap::default(),
383+
MountKind::ReadOnly,
384+
Some(ctx.experiment.cap_lints),
367385
) {
368386
Ok(TestResult::BuildFail(failure_reason(&err)))
369387
} else {
@@ -377,7 +395,16 @@ pub(super) fn test_rustdoc(
377395
local_packages: &[Package],
378396
) -> Fallible<TestResult> {
379397
let run = |cargo_args, env| {
380-
let res = run_cargo(ctx, build_env, cargo_args, true, local_packages, env);
398+
let res = run_cargo(
399+
ctx,
400+
build_env,
401+
cargo_args,
402+
true,
403+
local_packages,
404+
env,
405+
MountKind::ReadOnly,
406+
Some(ctx.experiment.cap_lints),
407+
);
381408

382409
// Make sure to remove the built documentation
383410
// There is no point in storing it after the build is done
@@ -436,6 +463,35 @@ fn is_library(target: &Target) -> bool {
436463
.all(|k| !["example", "test", "bench"].contains(&k.as_str()))
437464
}
438465

466+
pub(crate) fn fix(
467+
ctx: &TaskCtx,
468+
build_env: &Build,
469+
local_packages_id: &[Package],
470+
) -> Fallible<TestResult> {
471+
if let Err(err) = run_cargo(
472+
ctx,
473+
build_env,
474+
&[
475+
"fix",
476+
"--allow-no-vcs",
477+
"--allow-dirty",
478+
"--frozen",
479+
"--all",
480+
"--all-targets",
481+
"--message-format=json",
482+
],
483+
true,
484+
local_packages_id,
485+
HashMap::default(),
486+
MountKind::ReadWrite,
487+
None,
488+
) {
489+
Ok(TestResult::BuildFail(failure_reason(&err)))
490+
} else {
491+
Ok(TestResult::TestPass)
492+
}
493+
}
494+
439495
#[test]
440496
fn test_failure_reason() {
441497
let error: anyhow::Error = anyhow!(CommandError::IO(std::io::Error::other("Test")));

src/runner/worker.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ impl<'a> Worker<'a> {
123123
| TaskStep::CheckOnly { tc, .. }
124124
| TaskStep::Clippy { tc, .. }
125125
| TaskStep::Rustdoc { tc, .. }
126-
| TaskStep::UnstableFeatures { tc } => Some(tc),
126+
| TaskStep::UnstableFeatures { tc }
127+
| TaskStep::Fix { tc, .. } => Some(tc),
127128
};
128129
if let Some(toolchain) = toolchain {
129130
if toolchain == self.ex.toolchains.last().unwrap() {
@@ -302,6 +303,10 @@ impl<'a> Worker<'a> {
302303
quiet,
303304
},
304305
Mode::UnstableFeatures => TaskStep::UnstableFeatures { tc: tc.clone() },
306+
Mode::Fix => TaskStep::Fix {
307+
tc: tc.clone(),
308+
quiet,
309+
},
305310
},
306311
};
307312

src/server/routes/ui/experiments.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ impl ExperimentData {
4141
Mode::Clippy => "cargo clippy",
4242
Mode::Rustdoc => "cargo doc",
4343
Mode::UnstableFeatures => "unstable features",
44+
Mode::Fix => "cargo fix",
4445
},
4546
assigned_to: experiment.assigned_to.as_ref().map(|a| a.to_string()),
4647
priority: experiment.priority,

0 commit comments

Comments
 (0)