From 7b081569edeb88ffdeecb2855c8eea5954917c66 Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Sun, 18 Nov 2018 17:59:05 +0000 Subject: [PATCH 1/3] Distinguish custom build invocations Distinguish building a build script from running it, in build plan invocations. --- src/cargo/core/compiler/build_config.rs | 2 +- src/cargo/core/compiler/build_plan.rs | 4 +++- tests/testsuite/build_plan.rs | 18 ++++++++++++------ 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/cargo/core/compiler/build_config.rs b/src/cargo/core/compiler/build_config.rs index 1add81d0e58..bb25de07e84 100644 --- a/src/cargo/core/compiler/build_config.rs +++ b/src/cargo/core/compiler/build_config.rs @@ -111,7 +111,7 @@ pub enum MessageFormat { /// `compile_ws` to tell it the general execution strategy. This influences /// the default targets selected. The other use is in the `Unit` struct /// to indicate what is being done with a specific target. -#[derive(Clone, Copy, PartialEq, Debug, Eq, Hash, PartialOrd, Ord)] +#[derive(Clone, Copy, PartialEq, Debug, Eq, Hash, PartialOrd, Ord, Serialize)] pub enum CompileMode { /// A target being built for a test. Test, diff --git a/src/cargo/core/compiler/build_plan.rs b/src/cargo/core/compiler/build_plan.rs index 5813e29906b..28625c7de9e 100644 --- a/src/cargo/core/compiler/build_plan.rs +++ b/src/cargo/core/compiler/build_plan.rs @@ -9,7 +9,7 @@ use std::collections::BTreeMap; use core::TargetKind; -use super::{Context, Kind, Unit}; +use super::{CompileMode, Context, Kind, Unit}; use super::context::OutputFile; use util::{internal, CargoResult, ProcessBuilder}; use std::path::PathBuf; @@ -22,6 +22,7 @@ struct Invocation { package_version: semver::Version, target_kind: TargetKind, kind: Kind, + compile_mode: CompileMode, deps: Vec, outputs: Vec, links: BTreeMap, @@ -51,6 +52,7 @@ impl Invocation { package_version: id.version().clone(), kind: unit.kind, target_kind: unit.target.kind().clone(), + compile_mode: unit.mode, deps, outputs: Vec::new(), links: BTreeMap::new(), diff --git a/tests/testsuite/build_plan.rs b/tests/testsuite/build_plan.rs index fa17a79067d..c4ed1e09874 100644 --- a/tests/testsuite/build_plan.rs +++ b/tests/testsuite/build_plan.rs @@ -28,7 +28,8 @@ fn cargo_build_plan_simple() { "package_name": "foo", "package_version": "0.5.0", "program": "rustc", - "target_kind": ["bin"] + "target_kind": ["bin"], + "compile_mode": "Build" } ] } @@ -86,7 +87,8 @@ fn cargo_build_plan_single_dep() { "package_name": "bar", "package_version": "0.0.1", "program": "rustc", - "target_kind": ["lib"] + "target_kind": ["lib"], + "compile_mode": "Build" }, { "args": "{...}", @@ -101,7 +103,8 @@ fn cargo_build_plan_single_dep() { "package_name": "foo", "package_version": "0.5.0", "program": "rustc", - "target_kind": ["lib"] + "target_kind": ["lib"], + "compile_mode": "Build" } ] } @@ -148,7 +151,8 @@ fn cargo_build_plan_build_script() { "package_name": "foo", "package_version": "0.5.0", "program": "rustc", - "target_kind": ["custom-build"] + "target_kind": ["custom-build"], + "compile_mode": "Build" }, { "args": "{...}", @@ -161,7 +165,8 @@ fn cargo_build_plan_build_script() { "package_name": "foo", "package_version": "0.5.0", "program": "[..]/build-script-build", - "target_kind": ["custom-build"] + "target_kind": ["custom-build"], + "compile_mode": "RunCustomBuild" }, { "args": "{...}", @@ -174,7 +179,8 @@ fn cargo_build_plan_build_script() { "package_name": "foo", "package_version": "0.5.0", "program": "rustc", - "target_kind": ["bin"] + "target_kind": ["bin"], + "compile_mode": "Build" } ] } From 27424e2dbaf5ff4ee53da92713d2b4ea04804df6 Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Sun, 18 Nov 2018 18:32:54 +0000 Subject: [PATCH 2/3] Use kebab-case for CompileMode, & discard some info --- src/cargo/core/compiler/build_config.rs | 22 +++++++++++++++++++++- tests/testsuite/build_plan.rs | 12 ++++++------ 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/cargo/core/compiler/build_config.rs b/src/cargo/core/compiler/build_config.rs index bb25de07e84..2de8fb575d9 100644 --- a/src/cargo/core/compiler/build_config.rs +++ b/src/cargo/core/compiler/build_config.rs @@ -1,6 +1,8 @@ use std::path::Path; use std::cell::RefCell; +use serde::ser; + use util::{CargoResult, CargoResultExt, Config, RustfixDiagnosticServer}; /// Configuration information for a rustc build. @@ -111,7 +113,7 @@ pub enum MessageFormat { /// `compile_ws` to tell it the general execution strategy. This influences /// the default targets selected. The other use is in the `Unit` struct /// to indicate what is being done with a specific target. -#[derive(Clone, Copy, PartialEq, Debug, Eq, Hash, PartialOrd, Ord, Serialize)] +#[derive(Clone, Copy, PartialEq, Debug, Eq, Hash, PartialOrd, Ord)] pub enum CompileMode { /// A target being built for a test. Test, @@ -136,6 +138,24 @@ pub enum CompileMode { RunCustomBuild, } +impl ser::Serialize for CompileMode { + fn serialize(&self, s: S) -> Result + where + S: ser::Serializer, + { + use self::CompileMode::*; + match *self { + Test => "test".serialize(s), + Build => "build".serialize(s), + Check { .. } => "check".serialize(s), + Bench => "bench".serialize(s), + Doc { .. } => "doc".serialize(s), + Doctest => "doctest".serialize(s), + RunCustomBuild => "run-custom-build".serialize(s), + } + } +} + impl CompileMode { /// Returns true if the unit is being checked. pub fn is_check(self) -> bool { diff --git a/tests/testsuite/build_plan.rs b/tests/testsuite/build_plan.rs index c4ed1e09874..7b520cfd699 100644 --- a/tests/testsuite/build_plan.rs +++ b/tests/testsuite/build_plan.rs @@ -29,7 +29,7 @@ fn cargo_build_plan_simple() { "package_version": "0.5.0", "program": "rustc", "target_kind": ["bin"], - "compile_mode": "Build" + "compile_mode": "build" } ] } @@ -88,7 +88,7 @@ fn cargo_build_plan_single_dep() { "package_version": "0.0.1", "program": "rustc", "target_kind": ["lib"], - "compile_mode": "Build" + "compile_mode": "build" }, { "args": "{...}", @@ -104,7 +104,7 @@ fn cargo_build_plan_single_dep() { "package_version": "0.5.0", "program": "rustc", "target_kind": ["lib"], - "compile_mode": "Build" + "compile_mode": "build" } ] } @@ -152,7 +152,7 @@ fn cargo_build_plan_build_script() { "package_version": "0.5.0", "program": "rustc", "target_kind": ["custom-build"], - "compile_mode": "Build" + "compile_mode": "build" }, { "args": "{...}", @@ -166,7 +166,7 @@ fn cargo_build_plan_build_script() { "package_version": "0.5.0", "program": "[..]/build-script-build", "target_kind": ["custom-build"], - "compile_mode": "RunCustomBuild" + "compile_mode": "run-custom-build" }, { "args": "{...}", @@ -180,7 +180,7 @@ fn cargo_build_plan_build_script() { "package_version": "0.5.0", "program": "rustc", "target_kind": ["bin"], - "compile_mode": "Build" + "compile_mode": "build" } ] } From e8c1811f83a71deecdc44788645855b2b08b9057 Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Sun, 18 Nov 2018 18:39:08 +0000 Subject: [PATCH 3/3] Fix metabuild::metabuild_build_plan --- tests/testsuite/metabuild.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/testsuite/metabuild.rs b/tests/testsuite/metabuild.rs index c96f0c4b6b6..7837042b1d1 100644 --- a/tests/testsuite/metabuild.rs +++ b/tests/testsuite/metabuild.rs @@ -433,6 +433,7 @@ fn metabuild_build_plan() { "package_name": "mb", "package_version": "0.5.0", "target_kind": ["lib"], + "compile_mode": "build", "kind": "Host", "deps": [], "outputs": ["[..]/target/debug/deps/libmb-[..].rlib"], @@ -446,6 +447,7 @@ fn metabuild_build_plan() { "package_name": "mb-other", "package_version": "0.0.1", "target_kind": ["lib"], + "compile_mode": "build", "kind": "Host", "deps": [], "outputs": ["[..]/target/debug/deps/libmb_other-[..].rlib"], @@ -459,6 +461,7 @@ fn metabuild_build_plan() { "package_name": "foo", "package_version": "0.0.1", "target_kind": ["custom-build"], + "compile_mode": "build", "kind": "Host", "deps": [0, 1], "outputs": ["[..]/target/debug/build/foo-[..]/metabuild_foo-[..][EXE]"], @@ -472,6 +475,7 @@ fn metabuild_build_plan() { "package_name": "foo", "package_version": "0.0.1", "target_kind": ["custom-build"], + "compile_mode": "run-custom-build", "kind": "Host", "deps": [2], "outputs": [], @@ -485,6 +489,7 @@ fn metabuild_build_plan() { "package_name": "foo", "package_version": "0.0.1", "target_kind": ["lib"], + "compile_mode": "build", "kind": "Host", "deps": [3], "outputs": ["[..]/foo/target/debug/deps/libfoo-[..].rlib"],