]> git.proxmox.com Git - cargo.git/commitdiff
Fix value-after-table error with profiles.
authorEric Huss <eric@huss.org>
Sat, 14 Aug 2021 21:45:25 +0000 (14:45 -0700)
committerEric Huss <eric@huss.org>
Sat, 14 Aug 2021 21:45:25 +0000 (14:45 -0700)
src/cargo/util/toml/mod.rs
tests/testsuite/config.rs

index ee5abeebac38f12a6bd044b931c6459e9c63e8f3..e1919c946035db81ffbcd67e461b182b0b9bea18 100644 (file)
@@ -442,11 +442,13 @@ pub struct TomlProfile {
     pub panic: Option<String>,
     pub overflow_checks: Option<bool>,
     pub incremental: Option<bool>,
-    pub package: Option<BTreeMap<ProfilePackageSpec, TomlProfile>>,
-    pub build_override: Option<Box<TomlProfile>>,
     pub dir_name: Option<InternedString>,
     pub inherits: Option<InternedString>,
     pub strip: Option<StringOrBool>,
+    // These two fields must be last because they are sub-tables, and TOML
+    // requires all non-tables to be listed first.
+    pub package: Option<BTreeMap<ProfilePackageSpec, TomlProfile>>,
+    pub build_override: Option<Box<TomlProfile>>,
 }
 
 #[derive(Clone, Debug, PartialEq, Eq, Ord, PartialOrd, Hash)]
index 77fac2c54629b9e2830ce7c1218c4a705950ddda..176fdd88321e8bca082b15c1713030c571c91cbf 100644 (file)
@@ -1,6 +1,6 @@
 //! Tests for config settings.
 
-use cargo::core::Shell;
+use cargo::core::{PackageIdSpec, Shell};
 use cargo::util::config::{self, Config, SslVersionConfig, StringList};
 use cargo::util::interning::InternedString;
 use cargo::util::toml::{self, VecStringOrBool as VSOB};
@@ -1461,3 +1461,38 @@ fn cargo_target_empty_env() {
         .with_status(101)
         .run()
 }
+
+#[cargo_test]
+fn all_profile_options() {
+    // Check that all profile options can be serialized/deserialized.
+    let base_settings = toml::TomlProfile {
+        opt_level: Some(toml::TomlOptLevel("0".to_string())),
+        lto: Some(toml::StringOrBool::String("thin".to_string())),
+        codegen_backend: Some(InternedString::new("example")),
+        codegen_units: Some(123),
+        debug: Some(toml::U32OrBool::U32(1)),
+        split_debuginfo: Some("packed".to_string()),
+        debug_assertions: Some(true),
+        rpath: Some(true),
+        panic: Some("abort".to_string()),
+        overflow_checks: Some(true),
+        incremental: Some(true),
+        dir_name: Some(InternedString::new("dir_name")),
+        inherits: Some(InternedString::new("debug")),
+        strip: Some(toml::StringOrBool::String("symbols".to_string())),
+        package: None,
+        build_override: None,
+    };
+    let mut overrides = BTreeMap::new();
+    let key = toml::ProfilePackageSpec::Spec(PackageIdSpec::parse("foo").unwrap());
+    overrides.insert(key, base_settings.clone());
+    let profile = toml::TomlProfile {
+        build_override: Some(Box::new(base_settings.clone())),
+        package: Some(overrides),
+        ..base_settings.clone()
+    };
+    let profile_toml = ::toml::to_string(&profile).unwrap();
+    let roundtrip: toml::TomlProfile = ::toml::from_str(&profile_toml).unwrap();
+    let roundtrip_toml = ::toml::to_string(&roundtrip).unwrap();
+    compare::assert_match_exact(&profile_toml, &roundtrip_toml);
+}