Skip to content

Commit

Permalink
Auto merge of #9789 - ehuss:fix-value-after-table-profile, r=alexcric…
Browse files Browse the repository at this point in the history
…hton

Fix value-after-table error with profiles.

If the `strip`, `dir-name`, or `inherits` fields were included along with a profile override, then `cargo publish` would fail with a `ValueAfterTable` error because the fields were listed in the wrong order in the struct definition.

Fixes #9787
  • Loading branch information
bors committed Aug 16, 2021
2 parents ddf9adb + f0909c7 commit e8a78cc
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/cargo/util/toml/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
37 changes: 36 additions & 1 deletion tests/testsuite/config.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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);
}

0 comments on commit e8a78cc

Please sign in to comment.