Skip to content

Commit

Permalink
Use serde for deserializing strip option
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielMajeri committed May 19, 2020
1 parent e768b17 commit 5353f81
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 16 deletions.
11 changes: 4 additions & 7 deletions src/cargo/core/profiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -566,12 +566,7 @@ fn merge_profile(profile: &mut Profile, toml: &TomlProfile) {
profile.incremental = incremental;
}
if let Some(strip) = toml.strip {
profile.strip = match strip.as_str() {
"debuginfo" => Strip::DebugInfo,
"none" => Strip::None,
"symbols" => Strip::Symbols,
_ => panic!("Unexpected strip option `{}`", strip),
};
profile.strip = strip;
}
}

Expand Down Expand Up @@ -790,7 +785,9 @@ impl fmt::Display for PanicStrategy {
}

/// The setting for choosing which symbols to strip
#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash, PartialOrd, Ord, serde::Serialize)]
#[derive(
Clone, Copy, PartialEq, Eq, Debug, Hash, PartialOrd, Ord, serde::Serialize, serde::Deserialize,
)]
#[serde(rename_all = "lowercase")]
pub enum Strip {
/// Only strip debugging symbols
Expand Down
12 changes: 3 additions & 9 deletions src/cargo/util/toml/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use url::Url;

use crate::core::dependency::DepKind;
use crate::core::manifest::{ManifestMetadata, TargetSourcePath, Warnings};
use crate::core::profiles::Strip;
use crate::core::resolver::ResolveBehavior;
use crate::core::{Dependency, InternedString, Manifest, PackageId, Summary, Target};
use crate::core::{Edition, EitherManifest, Feature, Features, VirtualManifest, Workspace};
Expand Down Expand Up @@ -407,7 +408,7 @@ pub struct TomlProfile {
pub build_override: Option<Box<TomlProfile>>,
pub dir_name: Option<InternedString>,
pub inherits: Option<InternedString>,
pub strip: Option<InternedString>,
pub strip: Option<Strip>,
}

#[derive(Clone, Debug, PartialEq, Eq, Ord, PartialOrd, Hash)]
Expand Down Expand Up @@ -524,15 +525,8 @@ impl TomlProfile {
}
}

if let Some(strip) = &self.strip {
if self.strip.is_some() {
features.require(Feature::strip())?;
if strip != "debuginfo" && strip != "none" && strip != "symbols" {
bail!(
"`strip` setting of `{}` is not a valid setting,\
must be `debuginfo`, `none` or `symbols`",
strip
);
}
}
Ok(())
}
Expand Down

0 comments on commit 5353f81

Please sign in to comment.