Skip to content

Commit 90a5ba3

Browse files
committed
Add CompileMode to Executor callbacks
This helps distinguish whether a given rustc invocation corresponds to a regular compilation or is it compiled as a test harness. The difference is important for tools like RLS, since checking test code is different than checking what is it regularly compiled as.
1 parent 50032b9 commit 90a5ba3

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/cargo/core/compiler/mod.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,13 @@ pub trait Executor: Send + Sync + 'static {
6161

6262
/// In case of an `Err`, Cargo will not continue with the build process for
6363
/// this package.
64-
fn exec(&self, cmd: ProcessBuilder, _id: &PackageId, _target: &Target) -> CargoResult<()> {
64+
fn exec(
65+
&self,
66+
cmd: ProcessBuilder,
67+
_id: &PackageId,
68+
_target: &Target,
69+
_mode: CompileMode
70+
) -> CargoResult<()> {
6571
cmd.exec()?;
6672
Ok(())
6773
}
@@ -71,6 +77,7 @@ pub trait Executor: Send + Sync + 'static {
7177
cmd: ProcessBuilder,
7278
_id: &PackageId,
7379
_target: &Target,
80+
_mode: CompileMode,
7481
handle_stdout: &mut FnMut(&str) -> CargoResult<()>,
7582
handle_stderr: &mut FnMut(&str) -> CargoResult<()>,
7683
) -> CargoResult<()> {
@@ -194,6 +201,7 @@ fn rustc<'a, 'cfg>(
194201
let json_messages = cx.bcx.build_config.json_messages();
195202
let package_id = unit.pkg.package_id().clone();
196203
let target = unit.target.clone();
204+
let mode = unit.mode;
197205

198206
exec.init(cx, unit);
199207
let exec = exec.clone();
@@ -246,6 +254,7 @@ fn rustc<'a, 'cfg>(
246254
rustc,
247255
&package_id,
248256
&target,
257+
mode,
249258
&mut |line| {
250259
if !line.is_empty() {
251260
Err(internal(&format!(
@@ -279,7 +288,7 @@ fn rustc<'a, 'cfg>(
279288
} else if build_plan {
280289
state.build_plan(buildkey, rustc.clone(), outputs.clone());
281290
} else {
282-
exec.exec(rustc, &package_id, &target)
291+
exec.exec(rustc, &package_id, &target, mode)
283292
.map_err(Internal::new)
284293
.chain_err(|| format!("Could not compile `{}`.", name))?;
285294
}

0 commit comments

Comments
 (0)