Skip to content

Commit f8b3e7c

Browse files
authored
Rollup merge of rust-lang#46031 - Keruspe:cargofmt, r=Mark-Simulacrum
rustbuild: distribute cargo-fmt alongside rustfmt Not sure whether we want that nor if it's the right way to do so, but it feels quite weird to have rustfmt without cargo-fmt. Or are there other plans wrt that? What do you think @nrc ?
2 parents c0c3cc4 + b29a61e commit f8b3e7c

File tree

2 files changed

+57
-135
lines changed

2 files changed

+57
-135
lines changed

src/bootstrap/dist.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1168,7 +1168,12 @@ impl Step for Rustfmt {
11681168
compiler: builder.compiler(stage, build.build),
11691169
target
11701170
}).expect("Rustfmt to build: toolstate is testing");
1171+
let cargofmt = builder.ensure(tool::Cargofmt {
1172+
compiler: builder.compiler(stage, build.build),
1173+
target
1174+
}).expect("Cargofmt to build: toolstate is testing");
11711175
install(&rustfmt, &image.join("bin"), 0o755);
1176+
install(&cargofmt, &image.join("bin"), 0o755);
11721177
let doc = image.join("share/doc/rustfmt");
11731178
install(&src.join("README.md"), &doc, 0o644);
11741179
install(&src.join("LICENSE-MIT"), &doc, 0o644);

src/bootstrap/tool.rs

+52-135
Original file line numberDiff line numberDiff line change
@@ -403,71 +403,66 @@ impl Step for Cargo {
403403
}
404404
}
405405

406-
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
407-
pub struct Clippy {
408-
pub compiler: Compiler,
409-
pub target: Interned<String>,
410-
}
406+
macro_rules! tool_extended {
407+
(($sel:ident, $builder:ident),
408+
$($name:ident,
409+
$toolstate:ident,
410+
$path:expr,
411+
$tool_name:expr,
412+
$extra_deps:block;)+) => {
413+
$(
414+
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
415+
pub struct $name {
416+
pub compiler: Compiler,
417+
pub target: Interned<String>,
418+
}
411419

412-
impl Step for Clippy {
413-
type Output = Option<PathBuf>;
414-
const DEFAULT: bool = true;
415-
const ONLY_HOSTS: bool = true;
420+
impl Step for $name {
421+
type Output = Option<PathBuf>;
422+
const DEFAULT: bool = true;
423+
const ONLY_HOSTS: bool = true;
416424

417-
fn should_run(run: ShouldRun) -> ShouldRun {
418-
let builder = run.builder;
419-
run.path("src/tools/clippy").default_condition(builder.build.config.extended)
420-
}
425+
fn should_run(run: ShouldRun) -> ShouldRun {
426+
let builder = run.builder;
427+
run.path($path).default_condition(builder.build.config.extended)
428+
}
421429

422-
fn make_run(run: RunConfig) {
423-
run.builder.ensure(Clippy {
424-
compiler: run.builder.compiler(run.builder.top_stage, run.builder.build.build),
425-
target: run.target,
426-
});
430+
fn make_run(run: RunConfig) {
431+
run.builder.ensure($name {
432+
compiler: run.builder.compiler(run.builder.top_stage, run.builder.build.build),
433+
target: run.target,
434+
});
435+
}
436+
437+
fn run($sel, $builder: &Builder) -> Option<PathBuf> {
438+
$extra_deps
439+
let toolstate = $builder.build.config.toolstate.$toolstate;
440+
$builder.ensure(ToolBuild {
441+
compiler: $sel.compiler,
442+
target: $sel.target,
443+
tool: $tool_name,
444+
mode: Mode::Librustc,
445+
path: $path,
446+
expectation: toolstate.passes(ToolState::Compiling),
447+
})
448+
}
449+
}
450+
)+
427451
}
452+
}
428453

429-
fn run(self, builder: &Builder) -> Option<PathBuf> {
454+
tool_extended!((self, builder),
455+
Cargofmt, rustfmt, "src/tools/rustfmt", "cargo-fmt", {};
456+
Clippy, clippy, "src/tools/clippy", "clippy-driver", {
430457
// Clippy depends on procedural macros (serde), which requires a full host
431458
// compiler to be available, so we need to depend on that.
432459
builder.ensure(compile::Rustc {
433460
compiler: self.compiler,
434461
target: builder.build.build,
435462
});
436-
builder.ensure(ToolBuild {
437-
compiler: self.compiler,
438-
target: self.target,
439-
tool: "clippy-driver",
440-
mode: Mode::Librustc,
441-
path: "src/tools/clippy",
442-
expectation: builder.build.config.toolstate.clippy.passes(ToolState::Compiling),
443-
})
444-
}
445-
}
446-
447-
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
448-
pub struct Rls {
449-
pub compiler: Compiler,
450-
pub target: Interned<String>,
451-
}
452-
453-
impl Step for Rls {
454-
type Output = Option<PathBuf>;
455-
const DEFAULT: bool = true;
456-
const ONLY_HOSTS: bool = true;
457-
458-
fn should_run(run: ShouldRun) -> ShouldRun {
459-
let builder = run.builder;
460-
run.path("src/tools/rls").default_condition(builder.build.config.extended)
461-
}
462-
463-
fn make_run(run: RunConfig) {
464-
run.builder.ensure(Rls {
465-
compiler: run.builder.compiler(run.builder.top_stage, run.builder.build.build),
466-
target: run.target,
467-
});
468-
}
469-
470-
fn run(self, builder: &Builder) -> Option<PathBuf> {
463+
};
464+
Miri, miri, "src/tools/miri", "miri", {};
465+
Rls, rls, "src/tools/rls", "rls", {
471466
builder.ensure(native::Openssl {
472467
target: self.target,
473468
});
@@ -477,87 +472,9 @@ impl Step for Rls {
477472
compiler: self.compiler,
478473
target: builder.build.build,
479474
});
480-
builder.ensure(ToolBuild {
481-
compiler: self.compiler,
482-
target: self.target,
483-
tool: "rls",
484-
mode: Mode::Librustc,
485-
path: "src/tools/rls",
486-
expectation: builder.build.config.toolstate.rls.passes(ToolState::Compiling),
487-
})
488-
}
489-
}
490-
491-
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
492-
pub struct Rustfmt {
493-
pub compiler: Compiler,
494-
pub target: Interned<String>,
495-
}
496-
497-
impl Step for Rustfmt {
498-
type Output = Option<PathBuf>;
499-
const DEFAULT: bool = true;
500-
const ONLY_HOSTS: bool = true;
501-
502-
fn should_run(run: ShouldRun) -> ShouldRun {
503-
let builder = run.builder;
504-
run.path("src/tools/rustfmt").default_condition(builder.build.config.extended)
505-
}
506-
507-
fn make_run(run: RunConfig) {
508-
run.builder.ensure(Rustfmt {
509-
compiler: run.builder.compiler(run.builder.top_stage, run.builder.build.build),
510-
target: run.target,
511-
});
512-
}
513-
514-
fn run(self, builder: &Builder) -> Option<PathBuf> {
515-
builder.ensure(ToolBuild {
516-
compiler: self.compiler,
517-
target: self.target,
518-
tool: "rustfmt",
519-
mode: Mode::Librustc,
520-
path: "src/tools/rustfmt",
521-
expectation: builder.build.config.toolstate.rustfmt.passes(ToolState::Compiling),
522-
})
523-
}
524-
}
525-
526-
527-
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
528-
pub struct Miri {
529-
pub compiler: Compiler,
530-
pub target: Interned<String>,
531-
}
532-
533-
impl Step for Miri {
534-
type Output = Option<PathBuf>;
535-
const DEFAULT: bool = true;
536-
const ONLY_HOSTS: bool = true;
537-
538-
fn should_run(run: ShouldRun) -> ShouldRun {
539-
let build_miri = run.builder.build.config.test_miri;
540-
run.path("src/tools/miri").default_condition(build_miri)
541-
}
542-
543-
fn make_run(run: RunConfig) {
544-
run.builder.ensure(Miri {
545-
compiler: run.builder.compiler(run.builder.top_stage, run.builder.build.build),
546-
target: run.target,
547-
});
548-
}
549-
550-
fn run(self, builder: &Builder) -> Option<PathBuf> {
551-
builder.ensure(ToolBuild {
552-
compiler: self.compiler,
553-
target: self.target,
554-
tool: "miri",
555-
mode: Mode::Librustc,
556-
path: "src/tools/miri",
557-
expectation: builder.build.config.toolstate.miri.passes(ToolState::Compiling),
558-
})
559-
}
560-
}
475+
};
476+
Rustfmt, rustfmt, "src/tools/rustfmt", "rustfmt", {};
477+
);
561478

562479
impl<'a> Builder<'a> {
563480
/// Get a `Command` which is ready to run `tool` in `stage` built for

0 commit comments

Comments
 (0)