Skip to content

Commit

Permalink
Auto merge of #5830 - Xanewok:executor-compile-mode, r=matklad
Browse files Browse the repository at this point in the history
Add CompileMode to Executor callbacks

This came up when trying to fix rust-lang/rls#876.

So currently in the RLS we recreate our own dep graph, where we store units with a key `(PackageId, TargetKind)`. This turned out to be not enough since
a) we can have multiple bin target kinds with different names (unrelated to this PR)
b) same package target kind (bin, lib) can be compiled regularly or including the test harness.
With this, we can distinguish these cases and properly rerun both regular compilation check and the one including unit tests.

Without this information we'd need to fall back on guessing whether the rustc invocation has `--test` but having this information makes it accurate and seems useful enough to add it to the callback arguments.

r? @alexcrichton or @matklad
  • Loading branch information
bors committed Jul 29, 2018
2 parents 50032b9 + 90a5ba3 commit 1ec8c70
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/cargo/core/compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,13 @@ pub trait Executor: Send + Sync + 'static {

/// In case of an `Err`, Cargo will not continue with the build process for
/// this package.
fn exec(&self, cmd: ProcessBuilder, _id: &PackageId, _target: &Target) -> CargoResult<()> {
fn exec(
&self,
cmd: ProcessBuilder,
_id: &PackageId,
_target: &Target,
_mode: CompileMode
) -> CargoResult<()> {
cmd.exec()?;
Ok(())
}
Expand All @@ -71,6 +77,7 @@ pub trait Executor: Send + Sync + 'static {
cmd: ProcessBuilder,
_id: &PackageId,
_target: &Target,
_mode: CompileMode,
handle_stdout: &mut FnMut(&str) -> CargoResult<()>,
handle_stderr: &mut FnMut(&str) -> CargoResult<()>,
) -> CargoResult<()> {
Expand Down Expand Up @@ -194,6 +201,7 @@ fn rustc<'a, 'cfg>(
let json_messages = cx.bcx.build_config.json_messages();
let package_id = unit.pkg.package_id().clone();
let target = unit.target.clone();
let mode = unit.mode;

exec.init(cx, unit);
let exec = exec.clone();
Expand Down Expand Up @@ -246,6 +254,7 @@ fn rustc<'a, 'cfg>(
rustc,
&package_id,
&target,
mode,
&mut |line| {
if !line.is_empty() {
Err(internal(&format!(
Expand Down Expand Up @@ -279,7 +288,7 @@ fn rustc<'a, 'cfg>(
} else if build_plan {
state.build_plan(buildkey, rustc.clone(), outputs.clone());
} else {
exec.exec(rustc, &package_id, &target)
exec.exec(rustc, &package_id, &target, mode)
.map_err(Internal::new)
.chain_err(|| format!("Could not compile `{}`.", name))?;
}
Expand Down

0 comments on commit 1ec8c70

Please sign in to comment.