Add epoch key to [package]
authorManish Goregaokar <manishsmail@gmail.com>
Mon, 5 Feb 2018 15:23:07 +0000 (10:23 -0500)
committerManish Goregaokar <manishsmail@gmail.com>
Tue, 6 Feb 2018 03:02:25 +0000 (22:02 -0500)
src/cargo/core/features.rs
src/cargo/core/manifest.rs
src/cargo/core/mod.rs
src/cargo/util/toml/mod.rs

index 414e6a4a8b6947aa7b967023c326d512c8103016..30c2b433ffc1e99e4d2063392f3d1d34f0a4a840 100644 (file)
 //! 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<Self, ()> {
+        match s {
+            "2015" => Ok(Epoch::Epoch2015),
+            "2018" => Ok(Epoch::Epoch2018),
+            _ => Err(())
+        }
+    }
+}
+
 enum Status {
     Stable,
     Unstable,
index 5ba9419e4678d2ef61410dc4f1ac86357d827eab..98d87abd0b41dc1eae768abbd081cfcd05f8ccdf 100644 (file)
@@ -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<TomlManifest>,
     features: Features,
+    epoch: Epoch,
     im_a_teapot: Option<bool>,
 }
 
@@ -269,6 +270,7 @@ impl Manifest {
                patch: HashMap<Url, Vec<Dependency>>,
                workspace: WorkspaceConfig,
                features: Features,
+               epoch: Epoch,
                im_a_teapot: Option<bool>,
                original: Rc<TomlManifest>) -> Manifest {
         Manifest {
@@ -285,6 +287,7 @@ impl Manifest {
             patch: patch,
             workspace: workspace,
             features: features,
+            epoch: epoch,
             original: original,
             im_a_teapot: im_a_teapot,
         }
index 6b4e3906f8edd0cb1d41fddcd330fa7d325497f1..df1eff0725e5b1a9945cedfff36d7c7670634104 100644 (file)
@@ -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};
index a088598e9ba43b8cf8e3c5e1e6bf9f94bd20b635..d2e47a692c4a55bfc660d2d79eb86d4d98a54b1c 100644 (file)
@@ -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<String>,
     repository: Option<String>,
     metadata: Option<toml::Value>,
+    epoch: Option<String>,
 }
 
 #[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() {