mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-26 11:59:49 +00:00
Simplify feature representation in CargoConfig
This commit is contained in:
parent
39eaf7864c
commit
d9f5709609
5 changed files with 109 additions and 90 deletions
|
@ -15,7 +15,7 @@ use rustc_hash::FxHashMap;
|
|||
use semver::Version;
|
||||
use serde::Deserialize;
|
||||
|
||||
use crate::{cfg_flag::CfgFlag, CargoConfig, CargoWorkspace, Package};
|
||||
use crate::{cfg_flag::CfgFlag, CargoConfig, CargoFeatures, CargoWorkspace, Package};
|
||||
|
||||
#[derive(Debug, Default, Clone, PartialEq, Eq)]
|
||||
pub struct WorkspaceBuildScripts {
|
||||
|
@ -49,7 +49,6 @@ impl WorkspaceBuildScripts {
|
|||
|
||||
let mut cmd = Command::new(toolchain::cargo());
|
||||
cmd.envs(&config.extra_env);
|
||||
|
||||
cmd.args(&["check", "--quiet", "--workspace", "--message-format=json"]);
|
||||
|
||||
// --all-targets includes tests, benches and examples in addition to the
|
||||
|
@ -61,15 +60,18 @@ impl WorkspaceBuildScripts {
|
|||
cmd.args(&["--target", target]);
|
||||
}
|
||||
|
||||
if config.all_features {
|
||||
cmd.arg("--all-features");
|
||||
} else {
|
||||
if config.no_default_features {
|
||||
cmd.arg("--no-default-features");
|
||||
match &config.features {
|
||||
CargoFeatures::All => {
|
||||
cmd.arg("--all-features");
|
||||
}
|
||||
if !config.features.is_empty() {
|
||||
cmd.arg("--features");
|
||||
cmd.arg(config.features.join(" "));
|
||||
CargoFeatures::Selected { features, no_default_features } => {
|
||||
if *no_default_features {
|
||||
cmd.arg("--no-default-features");
|
||||
}
|
||||
if !features.is_empty() {
|
||||
cmd.arg("--features");
|
||||
cmd.arg(features.join(" "));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -71,35 +71,41 @@ impl Default for UnsetTestCrates {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub enum CargoFeatures {
|
||||
All,
|
||||
Selected {
|
||||
/// List of features to activate.
|
||||
features: Vec<String>,
|
||||
/// Do not activate the `default` feature.
|
||||
no_default_features: bool,
|
||||
},
|
||||
}
|
||||
|
||||
impl Default for CargoFeatures {
|
||||
fn default() -> Self {
|
||||
CargoFeatures::Selected { features: vec![], no_default_features: false }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default, Clone, Debug, PartialEq, Eq)]
|
||||
pub struct CargoConfig {
|
||||
/// Do not activate the `default` feature.
|
||||
pub no_default_features: bool,
|
||||
|
||||
/// Activate all available features
|
||||
pub all_features: bool,
|
||||
|
||||
/// List of features to activate.
|
||||
/// This will be ignored if `cargo_all_features` is true.
|
||||
pub features: Vec<String>,
|
||||
|
||||
pub features: CargoFeatures,
|
||||
/// rustc target
|
||||
pub target: Option<String>,
|
||||
|
||||
/// Don't load sysroot crates (`std`, `core` & friends). Might be useful
|
||||
/// when debugging isolated issues.
|
||||
pub no_sysroot: bool,
|
||||
|
||||
/// rustc private crate source
|
||||
pub rustc_source: Option<RustcSource>,
|
||||
|
||||
/// crates to disable `#[cfg(test)]` on
|
||||
pub unset_test_crates: UnsetTestCrates,
|
||||
|
||||
/// Invoke `cargo check` through the RUSTC_WRAPPER.
|
||||
pub wrap_rustc_in_build_scripts: bool,
|
||||
|
||||
/// The command to run instead of `cargo check` for building build scripts.
|
||||
pub run_build_script_command: Option<Vec<String>>,
|
||||
|
||||
/// Extra env vars to set when invoking the cargo command
|
||||
pub extra_env: FxHashMap<String, String>,
|
||||
}
|
||||
|
||||
|
@ -143,7 +149,7 @@ pub struct PackageData {
|
|||
pub targets: Vec<Target>,
|
||||
/// Does this package come from the local filesystem (and is editable)?
|
||||
pub is_local: bool,
|
||||
// Whether this package is a member of the workspace
|
||||
/// Whether this package is a member of the workspace
|
||||
pub is_member: bool,
|
||||
/// List of packages this package depends on
|
||||
pub dependencies: Vec<PackageDependency>,
|
||||
|
@ -249,8 +255,8 @@ impl TargetKind {
|
|||
}
|
||||
}
|
||||
|
||||
// Deserialize helper for the cargo metadata
|
||||
#[derive(Deserialize, Default)]
|
||||
// Deserialise helper for the cargo metadata
|
||||
struct PackageMetadata {
|
||||
#[serde(rename = "rust-analyzer")]
|
||||
rust_analyzer: Option<RustAnalyzerPackageMetaData>,
|
||||
|
@ -272,16 +278,19 @@ impl CargoWorkspace {
|
|||
let mut meta = MetadataCommand::new();
|
||||
meta.cargo_path(toolchain::cargo());
|
||||
meta.manifest_path(cargo_toml.to_path_buf());
|
||||
if config.all_features {
|
||||
meta.features(CargoOpt::AllFeatures);
|
||||
} else {
|
||||
if config.no_default_features {
|
||||
// FIXME: `NoDefaultFeatures` is mutual exclusive with `SomeFeatures`
|
||||
// https://github.com/oli-obk/cargo_metadata/issues/79
|
||||
meta.features(CargoOpt::NoDefaultFeatures);
|
||||
match &config.features {
|
||||
CargoFeatures::All => {
|
||||
meta.features(CargoOpt::AllFeatures);
|
||||
}
|
||||
if !config.features.is_empty() {
|
||||
meta.features(CargoOpt::SomeFeatures(config.features.clone()));
|
||||
CargoFeatures::Selected { features, no_default_features } => {
|
||||
if *no_default_features {
|
||||
// FIXME: `NoDefaultFeatures` is mutual exclusive with `SomeFeatures`
|
||||
// https://github.com/oli-obk/cargo_metadata/issues/79
|
||||
meta.features(CargoOpt::NoDefaultFeatures);
|
||||
}
|
||||
if !features.is_empty() {
|
||||
meta.features(CargoOpt::SomeFeatures(features.clone()));
|
||||
}
|
||||
}
|
||||
}
|
||||
meta.current_dir(current_dir.as_os_str());
|
||||
|
|
|
@ -42,8 +42,8 @@ use rustc_hash::FxHashSet;
|
|||
pub use crate::{
|
||||
build_scripts::WorkspaceBuildScripts,
|
||||
cargo_workspace::{
|
||||
CargoConfig, CargoWorkspace, Package, PackageData, PackageDependency, RustcSource, Target,
|
||||
TargetData, TargetKind, UnsetTestCrates,
|
||||
CargoConfig, CargoFeatures, CargoWorkspace, Package, PackageData, PackageDependency,
|
||||
RustcSource, Target, TargetData, TargetKind, UnsetTestCrates,
|
||||
},
|
||||
manifest_path::ManifestPath,
|
||||
project_json::{ProjectJson, ProjectJsonData},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue