use cargo::CargoResult;
use cargo::core::PackageId;
use cargo::util::command_prelude::CompileMode;
use crate::cli::cmd::Cmd;
use crate::config::Config;
use crate::proc::cargo_proxy_cmd;
use crate::proc::read_cargo_json;
use self::format::TargetKind;
#[deprecated = "corrupts cargo build cache"]
pub fn build_plan(cfg: &Config) -> CargoResult<format::BuildPlan> {
let mut cargo = cargo_proxy_cmd(cfg, &Cmd::Build)?;
if !cfg.compile_options.build_config.build_plan {
cargo.args(["--build-plan", "-Zunstable-options"]);
}
read_cargo_json(cfg, cargo)
}
impl format::BuildPlan {
#[deprecated]
pub fn build_package_invocations<'plan: 'i, 'p: 'i, 'i>(
&'plan self,
package: &'p PackageId)
-> impl Iterator<Item = &'plan format::Invocation> + 'i {
self.invocations
.iter()
.filter(move |item| {
item.package_name == package.name().as_str() && package.version() == &item.package_version
})
.filter(|item| item.compile_mode == CompileMode::Build)
}
}
#[derive(Debug, Clone, Copy)]
pub enum TargetKindWild {
Lib,
Bin,
Test,
Bench,
ExampleLib,
ExampleBin,
CustomBuild,
}
impl PartialEq<TargetKind> for TargetKindWild {
fn eq(&self, other: &TargetKind) -> bool {
match self {
TargetKindWild::Lib => matches!(other, TargetKind::Lib(_)),
TargetKindWild::Bin => matches!(other, TargetKind::Bin),
TargetKindWild::Test => matches!(other, TargetKind::Test),
TargetKindWild::Bench => matches!(other, TargetKind::Bench),
TargetKindWild::ExampleLib => matches!(other, TargetKind::Example),
TargetKindWild::ExampleBin => matches!(other, TargetKind::Example),
TargetKindWild::CustomBuild => matches!(other, TargetKind::CustomBuild),
}
}
}
pub mod format {
use std::collections::BTreeMap;
use std::path::PathBuf;
use cargo::util::command_prelude::CompileMode;
use cargo::core::compiler::CompileKind;
use serde::{Serialize, Deserialize};
pub use super::super::format::*;
#[derive(Debug, Serialize, Deserialize)]
#[deprecated = "Do not use, corrupts cargo build cache"]
pub struct BuildPlan {
pub invocations: Vec<Invocation>,
pub inputs: Vec<PathBuf>,
}
#[deprecated = "Do not use, corrupts cargo build cache"]
#[derive(Debug, Serialize, Deserialize, PartialEq)]
pub struct Invocation {
pub package_name: String,
pub package_version: semver::Version,
pub target_kind: TargetKind,
#[serde(serialize_with = "CompileKind::serialize")]
#[serde(deserialize_with = "de_compile_kind")]
pub kind: CompileKind,
#[serde(serialize_with = "CompileMode::serialize")]
#[serde(deserialize_with = "CompileModeProxy::deserialize")]
pub compile_mode: CompileMode,
pub deps: Vec<usize>,
pub outputs: Vec<PathBuf>,
pub links: BTreeMap<PathBuf, PathBuf>,
pub program: String,
pub args: Vec<String>,
pub env: BTreeMap<String, String>,
pub cwd: Option<PathBuf>,
}
}