From 8b77e2692cd97552b1b8d66eb51cec69695b3a5b Mon Sep 17 00:00:00 2001 From: Jade Date: Sun, 13 Jun 2021 21:41:46 -0700 Subject: Implement a config override for the default #[cfg(test)] in cargo crates Fixes crates which vanish when the 'test' cfg atom is set. Fix #7243. Fix #9203. Fix #7225. --- crates/project_model/src/cargo_workspace.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'crates/project_model/src/cargo_workspace.rs') diff --git a/crates/project_model/src/cargo_workspace.rs b/crates/project_model/src/cargo_workspace.rs index ac079f83e..0935ea967 100644 --- a/crates/project_model/src/cargo_workspace.rs +++ b/crates/project_model/src/cargo_workspace.rs @@ -1,5 +1,6 @@ //! See [`CargoWorkspace`]. +use std::iter; use std::path::PathBuf; use std::{convert::TryInto, ops, process::Command, sync::Arc}; @@ -12,6 +13,7 @@ use rustc_hash::FxHashMap; use serde::Deserialize; use serde_json::from_value; +use crate::CfgOverrides; use crate::{build_data::BuildDataConfig, utf8_stdout}; /// [`CargoWorkspace`] represents the logical structure of, well, a Cargo @@ -76,6 +78,21 @@ pub struct CargoConfig { /// rustc private crate source pub rustc_source: Option, + + /// crates to disable `#[cfg(test)]` on + pub unset_test_crates: Vec, +} + +impl CargoConfig { + pub fn cfg_overrides(&self) -> CfgOverrides { + self.unset_test_crates + .iter() + .cloned() + .zip(iter::repeat_with(|| { + cfg::CfgDiff::new(Vec::new(), vec![cfg::CfgAtom::Flag("test".into())]).unwrap() + })) + .collect() + } } pub type Package = Idx; -- cgit v1.2.3