From 1d82d2b38c6f0d1d7c28b229376da3f3a9271b3f Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Mon, 5 Feb 2018 10:23:07 -0500 Subject: [PATCH] Add epoch key to [package] --- src/cargo/core/features.rs | 21 +++++++++++++++++++++ src/cargo/core/manifest.rs | 5 ++++- src/cargo/core/mod.rs | 2 +- src/cargo/util/toml/mod.rs | 14 +++++++++++++- 4 files changed, 39 insertions(+), 3 deletions(-) diff --git a/src/cargo/core/features.rs b/src/cargo/core/features.rs index 414e6a4a8..30c2b433f 100644 --- a/src/cargo/core/features.rs +++ b/src/cargo/core/features.rs @@ -40,9 +40,30 @@ //! we'll be sure to update this documentation! use std::env; +use std::str::FromStr; use util::errors::CargoResult; +/// The epoch of the compiler (RFC 2052) +#[derive(Clone, Copy, Debug, Hash, PartialOrd, Ord, Eq, PartialEq)] +pub enum Epoch { + /// The 2015 epoch + Epoch2015, + /// The 2018 epoch + Epoch2018, +} + +impl FromStr for Epoch { + type Err = (); + fn from_str(s: &str) -> Result { + match s { + "2015" => Ok(Epoch::Epoch2015), + "2018" => Ok(Epoch::Epoch2018), + _ => Err(()) + } + } +} + enum Status { Stable, Unstable, diff --git a/src/cargo/core/manifest.rs b/src/cargo/core/manifest.rs index 5ba9419e4..98d87abd0 100644 --- a/src/cargo/core/manifest.rs +++ b/src/cargo/core/manifest.rs @@ -9,7 +9,7 @@ use serde::ser; use url::Url; use core::{Dependency, PackageId, Summary, SourceId, PackageIdSpec}; -use core::{WorkspaceConfig, Features, Feature}; +use core::{WorkspaceConfig, Epoch, Features, Feature}; use util::Config; use util::toml::TomlManifest; use util::errors::*; @@ -36,6 +36,7 @@ pub struct Manifest { workspace: WorkspaceConfig, original: Rc, features: Features, + epoch: Epoch, im_a_teapot: Option, } @@ -269,6 +270,7 @@ impl Manifest { patch: HashMap>, workspace: WorkspaceConfig, features: Features, + epoch: Epoch, im_a_teapot: Option, original: Rc) -> Manifest { Manifest { @@ -285,6 +287,7 @@ impl Manifest { patch: patch, workspace: workspace, features: features, + epoch: epoch, original: original, im_a_teapot: im_a_teapot, } diff --git a/src/cargo/core/mod.rs b/src/cargo/core/mod.rs index 6b4e3906f..df1eff072 100644 --- a/src/cargo/core/mod.rs +++ b/src/cargo/core/mod.rs @@ -1,5 +1,5 @@ pub use self::dependency::Dependency; -pub use self::features::{Features, Feature, CliUnstable}; +pub use self::features::{Epoch, Features, Feature, CliUnstable}; pub use self::manifest::{EitherManifest, VirtualManifest}; pub use self::manifest::{Manifest, Target, TargetKind, Profile, LibKind, Profiles}; pub use self::package::{Package, PackageSet}; diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index a088598e9..d2e47a692 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -14,7 +14,7 @@ use url::Url; use core::{SourceId, Profiles, PackageIdSpec, GitReference, WorkspaceConfig, WorkspaceRootConfig}; use core::{Summary, Manifest, Target, Dependency, PackageId}; -use core::{EitherManifest, VirtualManifest, Features, Feature}; +use core::{EitherManifest, Epoch, VirtualManifest, Features, Feature}; use core::dependency::{Kind, Platform}; use core::manifest::{LibKind, Profile, ManifestMetadata, Lto}; use sources::CRATES_IO; @@ -441,6 +441,7 @@ pub struct TomlProject { license_file: Option, repository: Option, metadata: Option, + epoch: Option, } #[derive(Debug, Deserialize, Serialize)] @@ -715,6 +716,16 @@ impl TomlManifest { Some(VecStringOrBool::Bool(false)) => Some(vec![]), None | Some(VecStringOrBool::Bool(true)) => None, }; + + let epoch = if let Some(ref epoch) = project.epoch { + if let Ok(epoch) = epoch.parse() { + epoch + } else { + bail!("the `epoch` key must be one of: `2015`, `2018`") + } + } else { + Epoch::Epoch2015 + }; let mut manifest = Manifest::new(summary, targets, exclude, @@ -727,6 +738,7 @@ impl TomlManifest { patch, workspace_config, features, + epoch, project.im_a_teapot, Rc::clone(me)); if project.license_file.is_some() && project.license.is_some() { -- 2.30.2