Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix value-after-table error with profiles. #9789

Merged
merged 1 commit into from
Aug 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}