Skip to content

Commit 8cd5735

Browse files
committed
rustbuild: use a macro to define "extended" tools
Signed-off-by: Marc-Antoine Perennou <[email protected]>
1 parent 1410d56 commit 8cd5735

File tree

1 file changed

+50
-135
lines changed

1 file changed

+50
-135
lines changed

src/bootstrap/tool.rs

Lines changed: 50 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -403,71 +403,64 @@ 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+
$builder.ensure(ToolBuild {
440+
compiler: $sel.compiler,
441+
target: $sel.target,
442+
tool: $tool_name,
443+
mode: Mode::Librustc,
444+
path: $path,
445+
expectation: $builder.build.config.toolstate.$toolstate.passes(ToolState::Compiling),
446+
})
447+
}
448+
}
449+
)+
427450
}
451+
}
428452

429-
fn run(self, builder: &Builder) -> Option<PathBuf> {
453+
tool_extended!((self, builder),
454+
Clippy, clippy, "src/tools/clippy", "clippy-driver", {
430455
// Clippy depends on procedural macros (serde), which requires a full host
431456
// compiler to be available, so we need to depend on that.
432457
builder.ensure(compile::Rustc {
433458
compiler: self.compiler,
434459
target: builder.build.build,
435460
});
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> {
461+
};
462+
Miri, miri, "src/tools/miri", "miri", {};
463+
Rls, rls, "src/tools/rls", "rls", {
471464
builder.ensure(native::Openssl {
472465
target: self.target,
473466
});
@@ -477,87 +470,9 @@ impl Step for Rls {
477470
compiler: self.compiler,
478471
target: builder.build.build,
479472
});
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-
}
473+
};
474+
Rustfmt, rustfmt, "src/tools/rustfmt", "rustfmt", {};
475+
);
561476

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

0 commit comments

Comments
 (0)