Skip to content

Commit eea2f55

Browse files
authored
Rollup merge of rust-lang#44533 - nrc:rustfmt-submod, r=alexcrichton
Add Rustfmt r? @alexcrichton
2 parents 39710f8 + 368cab3 commit eea2f55

File tree

9 files changed

+93
-5
lines changed

9 files changed

+93
-5
lines changed

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,6 @@
3636
[submodule "src/tools/clippy"]
3737
path = src/tools/clippy
3838
url = https://github.com/rust-lang-nursery/rust-clippy.git
39+
[submodule "src/tools/rustfmt"]
40+
path = src/tools/rustfmt
41+
url = https://github.com/rust-lang-nursery/rustfmt.git

src/Cargo.lock

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

src/Cargo.toml

+9
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ members = [
1818
"tools/cargo",
1919
"tools/rustdoc",
2020
"tools/rls",
21+
"tools/rustfmt",
2122
# FIXME(https://github.com/rust-lang/cargo/issues/4089): move these to exclude
2223
"tools/rls/test_data/borrow_error",
2324
"tools/rls/test_data/completion",
@@ -58,3 +59,11 @@ debug-assertions = false
5859

5960
[patch."https://github.com/rust-lang/cargo"]
6061
cargo = { path = "tools/cargo" }
62+
63+
# Override rustfmt dependencies both on the repo and the crate (the RLS
64+
# sometimes uses either).
65+
# FIXME should only need the crates.io patch, long term.
66+
[patch.'https://github.com/rust-lang-nursery/rustfmt']
67+
rustfmt-nightly = { path = "tools/rustfmt" }
68+
[patch.crates-io]
69+
rustfmt-nightly = { path = "tools/rustfmt" }

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/mk/Makefile.in

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ check-aux:
5555
src/tools/cargotest \
5656
src/tools/cargo \
5757
src/tools/rls \
58+
src/tools/rustfmt \
5859
src/test/pretty \
5960
src/test/run-pass/pretty \
6061
src/test/run-fail/pretty \

src/bootstrap/tool.rs

+34
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,40 @@ impl Step for Rls {
445445
}
446446
}
447447

448+
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
449+
pub struct Rustfmt {
450+
pub compiler: Compiler,
451+
pub target: Interned<String>,
452+
}
453+
454+
impl Step for Rustfmt {
455+
type Output = PathBuf;
456+
const DEFAULT: bool = true;
457+
const ONLY_HOSTS: bool = true;
458+
459+
fn should_run(run: ShouldRun) -> ShouldRun {
460+
let builder = run.builder;
461+
run.path("src/tools/rustfmt").default_condition(builder.build.config.extended)
462+
}
463+
464+
fn make_run(run: RunConfig) {
465+
run.builder.ensure(Rustfmt {
466+
compiler: run.builder.compiler(run.builder.top_stage, run.builder.build.build),
467+
target: run.target,
468+
});
469+
}
470+
471+
fn run(self, builder: &Builder) -> PathBuf {
472+
builder.ensure(ToolBuild {
473+
compiler: self.compiler,
474+
target: self.target,
475+
tool: "rustfmt",
476+
mode: Mode::Librustc,
477+
path: "src/tools/rustfmt",
478+
})
479+
}
480+
}
481+
448482
impl<'a> Builder<'a> {
449483
/// Get a `Command` which is ready to run `tool` in `stage` built for
450484
/// `host`.

src/tools/rustfmt

Submodule rustfmt added at a1fd68d

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)