From b56788c373e81d3d785e9ce761abf38274f7f453 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emil=20Gardstr=C3=B6m?= Date: Fri, 29 Apr 2022 18:18:16 +0200 Subject: [PATCH] add feature parsing also some small improvements --- src/cargo.rs | 3 +++ src/cli.rs | 12 ++++++++++++ src/main.rs | 6 +++--- src/tests.rs | 1 - 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/cargo.rs b/src/cargo.rs index 8589d380a..e7a960f43 100644 --- a/src/cargo.rs +++ b/src/cargo.rs @@ -115,6 +115,9 @@ pub fn cargo_metadata_with_args( if let Some(target) = args.and_then(|a| a.target.as_ref()) { command.args(["--filter-platform", target.triple()]); } + if let Some(features) = args.map(|a| &a.features) { + command.args([String::from("--features"), features.join(",")]); + } let output = command.output()?; let manifest: Option = serde_json::from_slice(&output.stdout).wrap_err_with(|| { diff --git a/src/cli.rs b/src/cli.rs index 736f7b5c4..94b506a23 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -12,6 +12,7 @@ pub struct Args { pub subcommand: Option, pub channel: Option, pub target: Option, + pub features: Vec, pub target_dir: Option, pub docker_in_docker: bool, pub manifest_path: Option, @@ -29,6 +30,7 @@ fn absolute_path(path: PathBuf) -> Result { pub fn parse(target_list: &TargetList) -> Result { let mut channel = None; let mut target = None; + let mut features = Vec::new(); let mut manifest_path: Option = None; let mut target_dir = None; let mut sc = None; @@ -67,6 +69,15 @@ pub fn parse(target_list: &TargetList) -> Result { .split_once('=') .map(|(_, t)| Target::from(t, target_list)); all.push(arg); + } else if arg == "--features" { + all.push(arg); + if let Some(t) = args.next() { + features.push(t.clone()); + all.push(t); + } + } else if arg.starts_with("--features=") { + features.extend(arg.split_once('=').map(|(_, t)| t.to_owned())); + all.push(arg); } else if arg == "--target-dir" { all.push(arg); if let Some(td) = args.next() { @@ -97,6 +108,7 @@ pub fn parse(target_list: &TargetList) -> Result { subcommand: sc, channel, target, + features, target_dir, docker_in_docker, manifest_path, diff --git a/src/main.rs b/src/main.rs index db37f0b9d..ebfa40ca1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -463,10 +463,10 @@ pub(crate) fn warn_host_version_mismatch( /// Parses the `Cross.toml` at the root of the Cargo project or from the /// `CROSS_CONFIG` environment variable (if any exist in either location). -fn toml(root: &CargoMetadata) -> Result> { +fn toml(metadata: &CargoMetadata) -> Result> { let path = match env::var("CROSS_CONFIG") { Ok(var) => PathBuf::from(var), - Err(_) => root.workspace_root.join("Cross.toml"), + Err(_) => metadata.workspace_root.join("Cross.toml"), }; if path.exists() { @@ -479,7 +479,7 @@ fn toml(root: &CargoMetadata) -> Result> { Ok(Some(config)) } else { // Checks if there is a lowercase version of this file - if root.workspace_root.join("cross.toml").exists() { + if metadata.workspace_root.join("cross.toml").exists() { eprintln!("There's a file named cross.toml, instead of Cross.toml. You may want to rename it, or it won't be considered."); } Ok(None) diff --git a/src/tests.rs b/src/tests.rs index 4554db9f9..c6f9bf0e1 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -7,7 +7,6 @@ use std::{ use once_cell::sync::OnceCell; use rustc_version::VersionMeta; -use serde::Deserialize; static WORKSPACE: OnceCell = OnceCell::new();