|
7 | 7 | //LICENSE All rights reserved. |
8 | 8 | //LICENSE |
9 | 9 | //LICENSE Use of this source code is governed by the MIT license that can be found in the LICENSE file. |
10 | | -use crate::profile::CargoProfile; |
11 | 10 | use std::collections::BTreeMap; |
12 | 11 | use std::path::PathBuf; |
13 | 12 | use std::{env, process}; |
@@ -213,3 +212,52 @@ pub(crate) fn initialize() { |
213 | 212 | (_, Err(_)) => {} |
214 | 213 | } |
215 | 214 | } |
| 215 | + |
| 216 | +#[derive(Debug, Default, Clone, PartialEq, Eq)] |
| 217 | +pub enum CargoProfile { |
| 218 | + /// The default non-release profile, `[profile.dev]` |
| 219 | + #[default] |
| 220 | + Dev, |
| 221 | + /// The default release profile, `[profile.release]` |
| 222 | + Release, |
| 223 | + /// Some other profile, specified by name. |
| 224 | + Profile(String), |
| 225 | +} |
| 226 | + |
| 227 | +impl CargoProfile { |
| 228 | + pub fn from_flags(profile: Option<&str>, default: CargoProfile) -> eyre::Result<Self> { |
| 229 | + match profile { |
| 230 | + // Cargo treats `--profile release` the same as `--release`. |
| 231 | + Some("release") => Ok(Self::Release), |
| 232 | + // Cargo has two names for the debug profile, due to legacy |
| 233 | + // reasons... |
| 234 | + Some("debug") | Some("dev") => Ok(Self::Dev), |
| 235 | + Some(profile) => Ok(Self::Profile(profile.into())), |
| 236 | + None => Ok(default), |
| 237 | + } |
| 238 | + } |
| 239 | + |
| 240 | + pub fn cargo_args(&self) -> Vec<String> { |
| 241 | + match self { |
| 242 | + Self::Dev => vec![], |
| 243 | + Self::Release => vec!["--release".into()], |
| 244 | + Self::Profile(p) => vec!["--profile".into(), p.into()], |
| 245 | + } |
| 246 | + } |
| 247 | + |
| 248 | + pub fn name(&self) -> &str { |
| 249 | + match self { |
| 250 | + Self::Dev => "dev", |
| 251 | + Self::Release => "release", |
| 252 | + Self::Profile(p) => p, |
| 253 | + } |
| 254 | + } |
| 255 | + |
| 256 | + pub fn target_subdir(&self) -> &str { |
| 257 | + match self { |
| 258 | + Self::Dev => "debug", |
| 259 | + Self::Release => "release", |
| 260 | + Self::Profile(p) => p, |
| 261 | + } |
| 262 | + } |
| 263 | +} |
0 commit comments