Skip to content

Commit 9caf0ba

Browse files
committed
Auto merge of #6331 - dwijnand:distinguish-custom-build-invocations, r=alexcrichton
Distinguish custom build invocations Distinguish building a build script from running it, in build plan invocations. Fixes #5719
2 parents 85060d8 + e8c1811 commit 9caf0ba

File tree

4 files changed

+40
-7
lines changed

4 files changed

+40
-7
lines changed

src/cargo/core/compiler/build_config.rs

+20
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use std::path::Path;
22
use std::cell::RefCell;
33

4+
use serde::ser;
5+
46
use util::{CargoResult, CargoResultExt, Config, RustfixDiagnosticServer};
57

68
/// Configuration information for a rustc build.
@@ -136,6 +138,24 @@ pub enum CompileMode {
136138
RunCustomBuild,
137139
}
138140

141+
impl ser::Serialize for CompileMode {
142+
fn serialize<S>(&self, s: S) -> Result<S::Ok, S::Error>
143+
where
144+
S: ser::Serializer,
145+
{
146+
use self::CompileMode::*;
147+
match *self {
148+
Test => "test".serialize(s),
149+
Build => "build".serialize(s),
150+
Check { .. } => "check".serialize(s),
151+
Bench => "bench".serialize(s),
152+
Doc { .. } => "doc".serialize(s),
153+
Doctest => "doctest".serialize(s),
154+
RunCustomBuild => "run-custom-build".serialize(s),
155+
}
156+
}
157+
}
158+
139159
impl CompileMode {
140160
/// Returns true if the unit is being checked.
141161
pub fn is_check(self) -> bool {

src/cargo/core/compiler/build_plan.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use std::collections::BTreeMap;
1010

1111
use core::TargetKind;
12-
use super::{Context, Kind, Unit};
12+
use super::{CompileMode, Context, Kind, Unit};
1313
use super::context::OutputFile;
1414
use util::{internal, CargoResult, ProcessBuilder};
1515
use std::path::PathBuf;
@@ -22,6 +22,7 @@ struct Invocation {
2222
package_version: semver::Version,
2323
target_kind: TargetKind,
2424
kind: Kind,
25+
compile_mode: CompileMode,
2526
deps: Vec<usize>,
2627
outputs: Vec<PathBuf>,
2728
links: BTreeMap<PathBuf, PathBuf>,
@@ -51,6 +52,7 @@ impl Invocation {
5152
package_version: id.version().clone(),
5253
kind: unit.kind,
5354
target_kind: unit.target.kind().clone(),
55+
compile_mode: unit.mode,
5456
deps,
5557
outputs: Vec::new(),
5658
links: BTreeMap::new(),

tests/testsuite/build_plan.rs

+12-6
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ fn cargo_build_plan_simple() {
2828
"package_name": "foo",
2929
"package_version": "0.5.0",
3030
"program": "rustc",
31-
"target_kind": ["bin"]
31+
"target_kind": ["bin"],
32+
"compile_mode": "build"
3233
}
3334
]
3435
}
@@ -86,7 +87,8 @@ fn cargo_build_plan_single_dep() {
8687
"package_name": "bar",
8788
"package_version": "0.0.1",
8889
"program": "rustc",
89-
"target_kind": ["lib"]
90+
"target_kind": ["lib"],
91+
"compile_mode": "build"
9092
},
9193
{
9294
"args": "{...}",
@@ -101,7 +103,8 @@ fn cargo_build_plan_single_dep() {
101103
"package_name": "foo",
102104
"package_version": "0.5.0",
103105
"program": "rustc",
104-
"target_kind": ["lib"]
106+
"target_kind": ["lib"],
107+
"compile_mode": "build"
105108
}
106109
]
107110
}
@@ -148,7 +151,8 @@ fn cargo_build_plan_build_script() {
148151
"package_name": "foo",
149152
"package_version": "0.5.0",
150153
"program": "rustc",
151-
"target_kind": ["custom-build"]
154+
"target_kind": ["custom-build"],
155+
"compile_mode": "build"
152156
},
153157
{
154158
"args": "{...}",
@@ -161,7 +165,8 @@ fn cargo_build_plan_build_script() {
161165
"package_name": "foo",
162166
"package_version": "0.5.0",
163167
"program": "[..]/build-script-build",
164-
"target_kind": ["custom-build"]
168+
"target_kind": ["custom-build"],
169+
"compile_mode": "run-custom-build"
165170
},
166171
{
167172
"args": "{...}",
@@ -174,7 +179,8 @@ fn cargo_build_plan_build_script() {
174179
"package_name": "foo",
175180
"package_version": "0.5.0",
176181
"program": "rustc",
177-
"target_kind": ["bin"]
182+
"target_kind": ["bin"],
183+
"compile_mode": "build"
178184
}
179185
]
180186
}

tests/testsuite/metabuild.rs

+5
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,7 @@ fn metabuild_build_plan() {
433433
"package_name": "mb",
434434
"package_version": "0.5.0",
435435
"target_kind": ["lib"],
436+
"compile_mode": "build",
436437
"kind": "Host",
437438
"deps": [],
438439
"outputs": ["[..]/target/debug/deps/libmb-[..].rlib"],
@@ -446,6 +447,7 @@ fn metabuild_build_plan() {
446447
"package_name": "mb-other",
447448
"package_version": "0.0.1",
448449
"target_kind": ["lib"],
450+
"compile_mode": "build",
449451
"kind": "Host",
450452
"deps": [],
451453
"outputs": ["[..]/target/debug/deps/libmb_other-[..].rlib"],
@@ -459,6 +461,7 @@ fn metabuild_build_plan() {
459461
"package_name": "foo",
460462
"package_version": "0.0.1",
461463
"target_kind": ["custom-build"],
464+
"compile_mode": "build",
462465
"kind": "Host",
463466
"deps": [0, 1],
464467
"outputs": ["[..]/target/debug/build/foo-[..]/metabuild_foo-[..][EXE]"],
@@ -472,6 +475,7 @@ fn metabuild_build_plan() {
472475
"package_name": "foo",
473476
"package_version": "0.0.1",
474477
"target_kind": ["custom-build"],
478+
"compile_mode": "run-custom-build",
475479
"kind": "Host",
476480
"deps": [2],
477481
"outputs": [],
@@ -485,6 +489,7 @@ fn metabuild_build_plan() {
485489
"package_name": "foo",
486490
"package_version": "0.0.1",
487491
"target_kind": ["lib"],
492+
"compile_mode": "build",
488493
"kind": "Host",
489494
"deps": [3],
490495
"outputs": ["[..]/foo/target/debug/deps/libfoo-[..].rlib"],

0 commit comments

Comments
 (0)