Skip to content

Commit a6b847b

Browse files
Merge pull request #777 from ehuss/cargo-fix
Add a new "fix" mode
2 parents 5b5f77f + 6a446f1 commit a6b847b

File tree

8 files changed

+74
-7
lines changed

8 files changed

+74
-7
lines changed

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/report/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ fn write_logs<DB: ReadResults, W: ReportWriter>(
300300
}
301301

302302
for (i, krate) in crates.iter().enumerate() {
303-
if i % progress_every == 0 {
303+
if i.is_multiple_of(progress_every) {
304304
info!("wrote logs for {i}/{num_crates} crates")
305305
}
306306

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)
@@ -263,6 +271,8 @@ fn build(ctx: &TaskCtx, build_env: &Build, local_packages: &[Package]) -> Fallib
263271
true,
264272
local_packages,
265273
HashMap::default(),
274+
MountKind::ReadOnly,
275+
Some(ctx.experiment.cap_lints),
266276
)?;
267277
run_cargo(
268278
ctx,
@@ -271,6 +281,8 @@ fn build(ctx: &TaskCtx, build_env: &Build, local_packages: &[Package]) -> Fallib
271281
true,
272282
local_packages,
273283
HashMap::default(),
284+
MountKind::ReadOnly,
285+
Some(ctx.experiment.cap_lints),
274286
)?;
275287
Ok(())
276288
}
@@ -283,6 +295,8 @@ fn test(ctx: &TaskCtx, build_env: &Build) -> Fallible<()> {
283295
false,
284296
&[],
285297
HashMap::default(),
298+
MountKind::ReadOnly,
299+
Some(ctx.experiment.cap_lints),
286300
)
287301
}
288302

@@ -336,6 +350,8 @@ pub(super) fn test_check_only(
336350
true,
337351
local_packages_id,
338352
HashMap::default(),
353+
MountKind::ReadOnly,
354+
Some(ctx.experiment.cap_lints),
339355
) {
340356
Ok(TestResult::BuildFail(failure_reason(&err)))
341357
} else {
@@ -361,6 +377,8 @@ pub(super) fn test_clippy_only(
361377
true,
362378
local_packages,
363379
HashMap::default(),
380+
MountKind::ReadOnly,
381+
Some(ctx.experiment.cap_lints),
364382
) {
365383
Ok(TestResult::BuildFail(failure_reason(&err)))
366384
} else {
@@ -374,7 +392,16 @@ pub(super) fn test_rustdoc(
374392
local_packages: &[Package],
375393
) -> Fallible<TestResult> {
376394
let run = |cargo_args, env| {
377-
let res = run_cargo(ctx, build_env, cargo_args, true, local_packages, env);
395+
let res = run_cargo(
396+
ctx,
397+
build_env,
398+
cargo_args,
399+
true,
400+
local_packages,
401+
env,
402+
MountKind::ReadOnly,
403+
Some(ctx.experiment.cap_lints),
404+
);
378405

379406
// Make sure to remove the built documentation
380407
// There is no point in storing it after the build is done
@@ -433,6 +460,35 @@ fn is_library(target: &Target) -> bool {
433460
.all(|k| !["example", "test", "bench"].contains(&k.as_str()))
434461
}
435462

463+
pub(crate) fn fix(
464+
ctx: &TaskCtx,
465+
build_env: &Build,
466+
local_packages_id: &[Package],
467+
) -> Fallible<TestResult> {
468+
if let Err(err) = run_cargo(
469+
ctx,
470+
build_env,
471+
&[
472+
"fix",
473+
"--allow-no-vcs",
474+
"--allow-dirty",
475+
"--frozen",
476+
"--all",
477+
"--all-targets",
478+
"--message-format=json",
479+
],
480+
true,
481+
local_packages_id,
482+
HashMap::default(),
483+
MountKind::ReadWrite,
484+
None,
485+
) {
486+
Ok(TestResult::BuildFail(failure_reason(&err)))
487+
} else {
488+
Ok(TestResult::TestPass)
489+
}
490+
}
491+
436492
#[test]
437493
fn test_failure_reason() {
438494
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() {
@@ -301,6 +302,10 @@ impl<'a> Worker<'a> {
301302
quiet,
302303
},
303304
Mode::UnstableFeatures => TaskStep::UnstableFeatures { tc: tc.clone() },
305+
Mode::Fix => TaskStep::Fix {
306+
tc: tc.clone(),
307+
quiet,
308+
},
304309
},
305310
};
306311

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)