Skip to content

Commit ada73c1

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 1a8ed56 commit ada73c1

File tree

6 files changed

+74
-5
lines changed

6 files changed

+74
-5
lines changed

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: 5 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,9 @@ impl Task {
124126
tc,
125127
false,
126128
),
129+
TaskStep::Fix { ref tc, quiet } => {
130+
(&build_dir[tc], "fixing", test::fix, tc, quiet)
131+
}
127132
};
128133

129134
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};
@@ -111,6 +112,8 @@ fn run_cargo(
111112
check_errors: bool,
112113
local_packages: &[Package],
113114
env: HashMap<&'static str, String>,
115+
mount_kind: MountKind,
116+
cap_lints: Option<CapLints>,
114117
) -> Fallible<()> {
115118
let local_packages_id: HashSet<_> = local_packages.iter().map(|p| &p.id).collect();
116119

@@ -122,13 +125,17 @@ fn run_cargo(
122125
args.extend(tc_cargoflags.split(' '));
123126
}
124127

125-
let mut rustflags = format!("--cap-lints={}", ctx.experiment.cap_lints.to_str());
128+
let mut rustflags = cap_lints
129+
.map(|cap| format!("--cap-lints={cap}"))
130+
.unwrap_or_default();
126131
if let Some(ref tc_rustflags) = ctx.toolchain.rustflags {
127132
rustflags.push(' ');
128133
rustflags.push_str(tc_rustflags);
129134
}
130135

131-
let mut rustdocflags = format!("--cap-lints={}", ctx.experiment.cap_lints.to_str());
136+
let mut rustdocflags = cap_lints
137+
.map(|cap| format!("--cap-lints={cap}"))
138+
.unwrap_or_default();
132139
if let Some(ref tc_rustdocflags) = ctx.toolchain.rustdocflags {
133140
rustdocflags.push(' ');
134141
rustdocflags.push_str(tc_rustdocflags);
@@ -209,6 +216,7 @@ fn run_cargo(
209216
let mut command = build_env
210217
.cargo()
211218
.args(&args)
219+
.source_dir_mount_kind(mount_kind)
212220
.env("CARGO_INCREMENTAL", "0")
213221
.env("RUST_BACKTRACE", "full")
214222
.env("RUSTFLAGS", rustflags)
@@ -288,6 +296,8 @@ fn build(ctx: &TaskCtx, build_env: &Build, local_packages: &[Package]) -> Fallib
288296
true,
289297
local_packages,
290298
HashMap::default(),
299+
MountKind::ReadOnly,
300+
Some(ctx.experiment.cap_lints),
291301
)?;
292302
run_cargo(
293303
ctx,
@@ -296,6 +306,8 @@ fn build(ctx: &TaskCtx, build_env: &Build, local_packages: &[Package]) -> Fallib
296306
true,
297307
local_packages,
298308
HashMap::default(),
309+
MountKind::ReadOnly,
310+
Some(ctx.experiment.cap_lints),
299311
)?;
300312
Ok(())
301313
}
@@ -308,6 +320,8 @@ fn test(ctx: &TaskCtx, build_env: &Build) -> Fallible<()> {
308320
false,
309321
&[],
310322
HashMap::default(),
323+
MountKind::ReadOnly,
324+
Some(ctx.experiment.cap_lints),
311325
)
312326
}
313327

@@ -361,6 +375,8 @@ pub(super) fn test_check_only(
361375
true,
362376
local_packages_id,
363377
HashMap::default(),
378+
MountKind::ReadOnly,
379+
Some(ctx.experiment.cap_lints),
364380
) {
365381
Ok(TestResult::BuildFail(failure_reason(&err)))
366382
} else {
@@ -386,6 +402,8 @@ pub(super) fn test_clippy_only(
386402
true,
387403
local_packages,
388404
HashMap::default(),
405+
MountKind::ReadOnly,
406+
Some(ctx.experiment.cap_lints),
389407
) {
390408
Ok(TestResult::BuildFail(failure_reason(&err)))
391409
} else {
@@ -399,7 +417,16 @@ pub(super) fn test_rustdoc(
399417
local_packages: &[Package],
400418
) -> Fallible<TestResult> {
401419
let run = |cargo_args, env| {
402-
let res = run_cargo(ctx, build_env, cargo_args, true, local_packages, env);
420+
let res = run_cargo(
421+
ctx,
422+
build_env,
423+
cargo_args,
424+
true,
425+
local_packages,
426+
env,
427+
MountKind::ReadOnly,
428+
Some(ctx.experiment.cap_lints),
429+
);
403430

404431
// Make sure to remove the built documentation
405432
// There is no point in storing it after the build is done
@@ -458,6 +485,35 @@ fn is_library(target: &Target) -> bool {
458485
.all(|k| !["example", "test", "bench"].contains(&k.as_str()))
459486
}
460487

488+
pub(crate) fn fix(
489+
ctx: &TaskCtx,
490+
build_env: &Build,
491+
local_packages_id: &[Package],
492+
) -> Fallible<TestResult> {
493+
if let Err(err) = run_cargo(
494+
ctx,
495+
build_env,
496+
&[
497+
"fix",
498+
"--allow-no-vcs",
499+
"--allow-dirty",
500+
"--frozen",
501+
"--all",
502+
"--all-targets",
503+
"--message-format=json",
504+
],
505+
true,
506+
local_packages_id,
507+
HashMap::default(),
508+
MountKind::ReadWrite,
509+
None,
510+
) {
511+
Ok(TestResult::BuildFail(failure_reason(&err)))
512+
} else {
513+
Ok(TestResult::TestPass)
514+
}
515+
}
516+
461517
#[test]
462518
fn test_failure_reason() {
463519
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)