Skip to content

Commit

Permalink
Replace toml_edit with toml crate
Browse files Browse the repository at this point in the history
  • Loading branch information
messense committed Jun 23, 2021
1 parent 3e2b8b0 commit ac3b752
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 49 deletions.
41 changes: 0 additions & 41 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ dirs = { version = "3.0.1", optional = true }
configparser = { version = "2.0.0", optional = true }
fs-err = "2.5.0"
fat-macho = "0.4.3"
toml_edit = "0.2.0"
once_cell = "1.7.2"
scroll = "0.10.2"
target-lexicon = "0.12.0"
Expand Down
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Support Aarch64 on OpenBSD in [#570](https://github.com/PyO3/maturin/pull/570)
* Support Aarch64 on FreeBSD in [#571](https://github.com/PyO3/maturin/pull/571)
* `Cargo.toml`'s `authors` field is now optional per Rust [RFC 3052](https://github.com/rust-lang/rfcs/blob/master/text/3052-optional-authors-field.md) in [#573](https://github.com/PyO3/maturin/pull/573)
* Allow dotted keys in `Cargo.toml` by switch from `toml_edit` to `toml` crate in [#577](https://github.com/PyO3/maturin/pull/577)

## 0.10.6 - 2021-05-21

Expand Down
17 changes: 10 additions & 7 deletions src/source_distribution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const LOCAL_DEPENDENCIES_FOLDER: &str = "local_dependencies";
/// distribution. Since there is no cargo-backed way to replace dependencies
/// (see https://github.com/rust-lang/cargo/issues/9170), we do a simple
/// Cargo.toml rewrite ourselves.
/// A big chunk of that (including toml_edit) comes from cargo edit, and esp.
/// A big chunk of that comes from cargo edit, and esp.
/// https://github.com/killercup/cargo-edit/blob/2a08f0311bcb61690d71d39cb9e55e69b256c8e1/src/manifest.rs
/// This method is rather frail, but unfortunately I don't know a better solution.
fn rewrite_cargo_toml(
Expand All @@ -27,7 +27,7 @@ fn rewrite_cargo_toml(
"Can't read Cargo.toml at {}",
manifest_path.as_ref().display(),
))?;
let mut data = text.parse::<toml_edit::Document>().context(format!(
let mut data = toml::from_str::<toml::value::Table>(&text).context(format!(
"Failed to parse Cargo.toml at {}",
manifest_path.as_ref().display()
))?;
Expand All @@ -37,11 +37,14 @@ fn rewrite_cargo_toml(
// ^^^^^^^^^^^^^^^^^^ table[&dep_name]["path"]
// ^^^^^^^^^^^^^ dep_name
for dep_category in &["dependencies", "dev-dependencies", "build-dependencies"] {
if let Some(table) = data[&dep_category].as_table_mut() {
if let Some(table) = data
.get_mut(&dep_category.to_string())
.and_then(|x| x.as_table_mut())
{
let dep_names: Vec<_> = table.iter().map(|(key, _)| key.to_string()).collect();
for dep_name in dep_names {
// There should either be no value for path, or it should be a string
if table[&dep_name]["path"].is_none() {
if table.get(&dep_name).and_then(|x| x.get("path")).is_none() {
continue;
}
if !table[&dep_name]["path"].is_str() {
Expand All @@ -54,10 +57,10 @@ fn rewrite_cargo_toml(
}
// This is the location of the targeted crate in the source distribution
table[&dep_name]["path"] = if root_crate {
toml_edit::value(format!("{}/{}", LOCAL_DEPENDENCIES_FOLDER, dep_name))
format!("{}/{}", LOCAL_DEPENDENCIES_FOLDER, dep_name).into()
} else {
// Cargo.toml contains relative paths, and we're already in LOCAL_DEPENDENCIES_FOLDER
toml_edit::value(format!("../{}", dep_name))
format!("../{}", dep_name).into()
};
if !known_path_deps.contains_key(&dep_name) {
bail!(
Expand All @@ -71,7 +74,7 @@ fn rewrite_cargo_toml(
}
}
}
Ok(data.to_string_in_original_order())
Ok(toml::to_string(&data)?)
}

/// Copies the files of a crate to a source distribution, recursively adding path dependencies
Expand Down

0 comments on commit ac3b752

Please sign in to comment.