Skip to content

Commit d0070e8

Browse files
committed
Build and test Rustfmt
1 parent c4508e1 commit d0070e8

File tree

5 files changed

+79
-5
lines changed

5 files changed

+79
-5
lines changed

src/Cargo.lock

+1-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/bootstrap/builder.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -249,11 +249,11 @@ impl<'a> Builder<'a> {
249249
tool::UnstableBookGen, tool::Tidy, tool::Linkchecker, tool::CargoTest,
250250
tool::Compiletest, tool::RemoteTestServer, tool::RemoteTestClient,
251251
tool::RustInstaller, tool::Cargo, tool::Rls, tool::Rustdoc, tool::Clippy,
252-
native::Llvm),
252+
native::Llvm, tool::Rustfmt),
253253
Kind::Test => describe!(check::Tidy, check::Bootstrap, check::DefaultCompiletest,
254254
check::HostCompiletest, check::Crate, check::CrateLibrustc, check::Rustdoc,
255255
check::Linkcheck, check::Cargotest, check::Cargo, check::Rls, check::Docs,
256-
check::ErrorIndex, check::Distcheck),
256+
check::ErrorIndex, check::Distcheck, check::Rustfmt),
257257
Kind::Bench => describe!(check::Crate, check::CrateLibrustc),
258258
Kind::Doc => describe!(doc::UnstableBook, doc::UnstableBookGen, doc::TheBook,
259259
doc::Standalone, doc::Std, doc::Test, doc::Rustc, doc::ErrorIndex, doc::Nomicon,

src/bootstrap/check.rs

+41
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,47 @@ impl Step for Rls {
253253
}
254254
}
255255

256+
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
257+
pub struct Rustfmt {
258+
stage: u32,
259+
host: Interned<String>,
260+
}
261+
262+
impl Step for Rustfmt {
263+
type Output = ();
264+
const ONLY_HOSTS: bool = true;
265+
266+
fn should_run(run: ShouldRun) -> ShouldRun {
267+
run.path("src/tools/rustfmt")
268+
}
269+
270+
fn make_run(run: RunConfig) {
271+
run.builder.ensure(Rustfmt {
272+
stage: run.builder.top_stage,
273+
host: run.target,
274+
});
275+
}
276+
277+
/// Runs `cargo test` for rustfmt.
278+
fn run(self, builder: &Builder) {
279+
let build = builder.build;
280+
let stage = self.stage;
281+
let host = self.host;
282+
let compiler = builder.compiler(stage, host);
283+
284+
builder.ensure(tool::Rustfmt { compiler, target: self.host });
285+
let mut cargo = builder.cargo(compiler, Mode::Tool, host, "test");
286+
cargo.arg("--manifest-path").arg(build.src.join("src/tools/rustfmt/Cargo.toml"));
287+
288+
// Don't build tests dynamically, just a pain to work with
289+
cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
290+
291+
builder.add_rustc_lib_path(compiler, &mut cargo);
292+
293+
try_run(build, &mut cargo);
294+
}
295+
}
296+
256297
fn path_for_cargo(builder: &Builder, compiler: Compiler) -> OsString {
257298
// Configure PATH to find the right rustc. NB. we have to use PATH
258299
// and not RUSTC because the Cargo test suite has tests that will

src/bootstrap/tool.rs

+34
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,40 @@ impl Step for Rls {
431431
}
432432
}
433433

434+
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
435+
pub struct Rustfmt {
436+
pub compiler: Compiler,
437+
pub target: Interned<String>,
438+
}
439+
440+
impl Step for Rustfmt {
441+
type Output = PathBuf;
442+
const DEFAULT: bool = true;
443+
const ONLY_HOSTS: bool = true;
444+
445+
fn should_run(run: ShouldRun) -> ShouldRun {
446+
let builder = run.builder;
447+
run.path("src/tools/rustfmt").default_condition(builder.build.config.extended)
448+
}
449+
450+
fn make_run(run: RunConfig) {
451+
run.builder.ensure(Rustfmt {
452+
compiler: run.builder.compiler(run.builder.top_stage, run.builder.build.build),
453+
target: run.target,
454+
});
455+
}
456+
457+
fn run(self, builder: &Builder) -> PathBuf {
458+
builder.ensure(ToolBuild {
459+
compiler: self.compiler,
460+
target: self.target,
461+
tool: "rustfmt",
462+
mode: Mode::Librustc,
463+
path: "src/tools/rustfmt",
464+
})
465+
}
466+
}
467+
434468
impl<'a> Builder<'a> {
435469
/// Get a `Command` which is ready to run `tool` in `stage` built for
436470
/// `host`.

src/tools/tidy/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ fn filter_dirs(path: &Path) -> bool {
6464
"src/tools/rls",
6565
"src/tools/clippy",
6666
"src/tools/rust-installer",
67+
"src/tools/rustfmt",
6768
];
6869
skip.iter().any(|p| path.ends_with(p))
6970
}

0 commit comments

Comments
 (0)