/// directly, we'll use an Executor, giving clients an opportunity to intercept
/// the build calls.
pub trait Executor: Send + Sync + 'static {
- fn init(&self, _cx: &Context) {}
-
- /// If execution succeeds, the ContinueBuild value indicates whether Cargo
- /// should continue with the build process for this package.
- fn exec(&self, cmd: ProcessBuilder, _id: &PackageId) -> CargoResult<()> {
+ /// Called after a rustc process invocation is prepared up-front for a given
+ /// unit of work (may still be modified for runtime-known dependencies, when
+ /// the work is actually executed).
+ fn init(&self, _cx: &Context, _unit: &Unit) {}
+
+ /// 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<()> {
cmd.exec()?;
Ok(())
}
fn exec_json(&self,
cmd: ProcessBuilder,
_id: &PackageId,
+ _target: &Target,
handle_stdout: &mut FnMut(&str) -> CargoResult<()>,
handle_stderr: &mut FnMut(&str) -> CargoResult<()>)
-> CargoResult<()> {
let package_id = unit.pkg.package_id().clone();
let target = unit.target.clone();
- exec.init(cx);
+ exec.init(cx, &unit);
let exec = exec.clone();
let root_output = cx.target_root().to_path_buf();
state.running(&rustc);
if json_messages {
- exec.exec_json(rustc, &package_id,
+ exec.exec_json(rustc, &package_id, &target,
&mut |line| if !line.is_empty() {
Err(internal(&format!("compiler stdout is not empty: `{}`", line)))
} else {
format!("Could not compile `{}`.", name)
})?;
} else {
- exec.exec(rustc, &package_id).map_err(|e| e.into_internal()).chain_err(|| {
+ exec.exec(rustc, &package_id, &target).map_err(|e| e.into_internal()).chain_err(|| {
format!("Could not compile `{}`.", name)
})?;
}