From 8cd573550353427a8a66b6ddd676cb5731d4620e Mon Sep 17 00:00:00 2001 From: Marc-Antoine Perennou Date: Wed, 15 Nov 2017 11:17:39 +0100 Subject: [PATCH 1/4] rustbuild: use a macro to define "extended" tools Signed-off-by: Marc-Antoine Perennou --- src/bootstrap/tool.rs | 185 ++++++++++++------------------------------ 1 file changed, 50 insertions(+), 135 deletions(-) diff --git a/src/bootstrap/tool.rs b/src/bootstrap/tool.rs index 7175fed5410ba..eb403f88cb05f 100644 --- a/src/bootstrap/tool.rs +++ b/src/bootstrap/tool.rs @@ -403,71 +403,64 @@ impl Step for Cargo { } } -#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] -pub struct Clippy { - pub compiler: Compiler, - pub target: Interned, -} +macro_rules! tool_extended { + (($sel:ident, $builder:ident), + $($name:ident, + $toolstate:ident, + $path:expr, + $tool_name:expr, + $extra_deps:block;)+) => { + $( + #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] + pub struct $name { + pub compiler: Compiler, + pub target: Interned, + } -impl Step for Clippy { - type Output = Option; - const DEFAULT: bool = true; - const ONLY_HOSTS: bool = true; + impl Step for $name { + type Output = Option; + const DEFAULT: bool = true; + const ONLY_HOSTS: bool = true; - fn should_run(run: ShouldRun) -> ShouldRun { - let builder = run.builder; - run.path("src/tools/clippy").default_condition(builder.build.config.extended) - } + fn should_run(run: ShouldRun) -> ShouldRun { + let builder = run.builder; + run.path($path).default_condition(builder.build.config.extended) + } - fn make_run(run: RunConfig) { - run.builder.ensure(Clippy { - compiler: run.builder.compiler(run.builder.top_stage, run.builder.build.build), - target: run.target, - }); + fn make_run(run: RunConfig) { + run.builder.ensure($name { + compiler: run.builder.compiler(run.builder.top_stage, run.builder.build.build), + target: run.target, + }); + } + + fn run($sel, $builder: &Builder) -> Option { + $extra_deps + $builder.ensure(ToolBuild { + compiler: $sel.compiler, + target: $sel.target, + tool: $tool_name, + mode: Mode::Librustc, + path: $path, + expectation: $builder.build.config.toolstate.$toolstate.passes(ToolState::Compiling), + }) + } + } + )+ } +} - fn run(self, builder: &Builder) -> Option { +tool_extended!((self, builder), + Clippy, clippy, "src/tools/clippy", "clippy-driver", { // Clippy depends on procedural macros (serde), which requires a full host // compiler to be available, so we need to depend on that. builder.ensure(compile::Rustc { compiler: self.compiler, target: builder.build.build, }); - builder.ensure(ToolBuild { - compiler: self.compiler, - target: self.target, - tool: "clippy-driver", - mode: Mode::Librustc, - path: "src/tools/clippy", - expectation: builder.build.config.toolstate.clippy.passes(ToolState::Compiling), - }) - } -} - -#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] -pub struct Rls { - pub compiler: Compiler, - pub target: Interned, -} - -impl Step for Rls { - type Output = Option; - const DEFAULT: bool = true; - const ONLY_HOSTS: bool = true; - - fn should_run(run: ShouldRun) -> ShouldRun { - let builder = run.builder; - run.path("src/tools/rls").default_condition(builder.build.config.extended) - } - - fn make_run(run: RunConfig) { - run.builder.ensure(Rls { - compiler: run.builder.compiler(run.builder.top_stage, run.builder.build.build), - target: run.target, - }); - } - - fn run(self, builder: &Builder) -> Option { + }; + Miri, miri, "src/tools/miri", "miri", {}; + Rls, rls, "src/tools/rls", "rls", { builder.ensure(native::Openssl { target: self.target, }); @@ -477,87 +470,9 @@ impl Step for Rls { compiler: self.compiler, target: builder.build.build, }); - builder.ensure(ToolBuild { - compiler: self.compiler, - target: self.target, - tool: "rls", - mode: Mode::Librustc, - path: "src/tools/rls", - expectation: builder.build.config.toolstate.rls.passes(ToolState::Compiling), - }) - } -} - -#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] -pub struct Rustfmt { - pub compiler: Compiler, - pub target: Interned, -} - -impl Step for Rustfmt { - type Output = Option; - const DEFAULT: bool = true; - const ONLY_HOSTS: bool = true; - - fn should_run(run: ShouldRun) -> ShouldRun { - let builder = run.builder; - run.path("src/tools/rustfmt").default_condition(builder.build.config.extended) - } - - fn make_run(run: RunConfig) { - run.builder.ensure(Rustfmt { - compiler: run.builder.compiler(run.builder.top_stage, run.builder.build.build), - target: run.target, - }); - } - - fn run(self, builder: &Builder) -> Option { - builder.ensure(ToolBuild { - compiler: self.compiler, - target: self.target, - tool: "rustfmt", - mode: Mode::Librustc, - path: "src/tools/rustfmt", - expectation: builder.build.config.toolstate.rustfmt.passes(ToolState::Compiling), - }) - } -} - - -#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] -pub struct Miri { - pub compiler: Compiler, - pub target: Interned, -} - -impl Step for Miri { - type Output = Option; - const DEFAULT: bool = true; - const ONLY_HOSTS: bool = true; - - fn should_run(run: ShouldRun) -> ShouldRun { - let build_miri = run.builder.build.config.test_miri; - run.path("src/tools/miri").default_condition(build_miri) - } - - fn make_run(run: RunConfig) { - run.builder.ensure(Miri { - compiler: run.builder.compiler(run.builder.top_stage, run.builder.build.build), - target: run.target, - }); - } - - fn run(self, builder: &Builder) -> Option { - builder.ensure(ToolBuild { - compiler: self.compiler, - target: self.target, - tool: "miri", - mode: Mode::Librustc, - path: "src/tools/miri", - expectation: builder.build.config.toolstate.miri.passes(ToolState::Compiling), - }) - } -} + }; + Rustfmt, rustfmt, "src/tools/rustfmt", "rustfmt", {}; +); impl<'a> Builder<'a> { /// Get a `Command` which is ready to run `tool` in `stage` built for From 8f91a45e484796998942cfe2d7ae1c9aa24ccee2 Mon Sep 17 00:00:00 2001 From: Marc-Antoine Perennou Date: Wed, 15 Nov 2017 11:21:21 +0100 Subject: [PATCH 2/4] rustbuild: dist cargo-fmt as part of rustfmt Signed-off-by: Marc-Antoine Perennou --- src/bootstrap/dist.rs | 5 +++++ src/bootstrap/tool.rs | 1 + 2 files changed, 6 insertions(+) diff --git a/src/bootstrap/dist.rs b/src/bootstrap/dist.rs index 7bf385301fab5..9009be247a651 100644 --- a/src/bootstrap/dist.rs +++ b/src/bootstrap/dist.rs @@ -1163,7 +1163,12 @@ impl Step for Rustfmt { compiler: builder.compiler(stage, build.build), target }).expect("Rustfmt to build: toolstate is testing"); + let cargofmt = builder.ensure(tool::Cargofmt { + compiler: builder.compiler(stage, build.build), + target + }).expect("Rustfmt to build: toolstate is testing"); install(&rustfmt, &image.join("bin"), 0o755); + install(&cargofmt, &image.join("bin"), 0o755); let doc = image.join("share/doc/rustfmt"); install(&src.join("README.md"), &doc, 0o644); install(&src.join("LICENSE-MIT"), &doc, 0o644); diff --git a/src/bootstrap/tool.rs b/src/bootstrap/tool.rs index eb403f88cb05f..bc7ec93ca8af0 100644 --- a/src/bootstrap/tool.rs +++ b/src/bootstrap/tool.rs @@ -451,6 +451,7 @@ macro_rules! tool_extended { } tool_extended!((self, builder), + Cargofmt, rustfmt, "src/tools/rustfmt", "cargo-fmt", {}; Clippy, clippy, "src/tools/clippy", "clippy-driver", { // Clippy depends on procedural macros (serde), which requires a full host // compiler to be available, so we need to depend on that. From 98175892b0fcbbb001235d3fe86cb9a5469ff171 Mon Sep 17 00:00:00 2001 From: Marc-Antoine Perennou Date: Thu, 16 Nov 2017 11:26:45 +0100 Subject: [PATCH 3/4] rustbuild: make tidy happy Signed-off-by: Marc-Antoine Perennou --- src/bootstrap/tool.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/bootstrap/tool.rs b/src/bootstrap/tool.rs index bc7ec93ca8af0..9b16ca0980acb 100644 --- a/src/bootstrap/tool.rs +++ b/src/bootstrap/tool.rs @@ -436,13 +436,14 @@ macro_rules! tool_extended { fn run($sel, $builder: &Builder) -> Option { $extra_deps + let toolstate = $builder.build.config.toolstate.$toolstate; $builder.ensure(ToolBuild { compiler: $sel.compiler, target: $sel.target, tool: $tool_name, mode: Mode::Librustc, path: $path, - expectation: $builder.build.config.toolstate.$toolstate.passes(ToolState::Compiling), + expectation: toolstate.passes(ToolState::Compiling), }) } } From b29a61e51b14276edf0d2110901129ab4e92fc5e Mon Sep 17 00:00:00 2001 From: Marc-Antoine Perennou Date: Mon, 20 Nov 2017 10:02:08 +0100 Subject: [PATCH 4/4] rustbuild: fix expectation message Signed-off-by: Marc-Antoine Perennou --- src/bootstrap/dist.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bootstrap/dist.rs b/src/bootstrap/dist.rs index 9009be247a651..81b3b04411965 100644 --- a/src/bootstrap/dist.rs +++ b/src/bootstrap/dist.rs @@ -1166,7 +1166,7 @@ impl Step for Rustfmt { let cargofmt = builder.ensure(tool::Cargofmt { compiler: builder.compiler(stage, build.build), target - }).expect("Rustfmt to build: toolstate is testing"); + }).expect("Cargofmt to build: toolstate is testing"); install(&rustfmt, &image.join("bin"), 0o755); install(&cargofmt, &image.join("bin"), 0o755); let doc = image.join("share/doc/rustfmt");