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

Replace toml_edit with toml crate #577

Merged
merged 2 commits into from
Jul 1, 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
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)
* Fix source distribution with local path dependencies on Windows in [#580](https://github.com/PyO3/maturin/pull/580)

## 0.10.6 - 2021-05-21
Expand Down
20 changes: 13 additions & 7 deletions src/source_distribution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,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 @@ -26,21 +26,22 @@ 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()
))?;
let mut rewritten = false;
// ˇˇˇˇˇˇˇˇˇˇˇˇ dep_category
// [dependencies]
// some_path_dep = { path = "../some_path_dep" }
// ^^^^^^^^^^^^^^^^^^ 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).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 @@ -53,11 +54,12 @@ 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()
};
rewritten = true;
if !known_path_deps.contains_key(&dep_name) {
bail!(
"cargo metadata does not know about the path for {}.{} present in {}, \
Expand All @@ -70,7 +72,11 @@ fn rewrite_cargo_toml(
}
}
}
Ok(data.to_string_in_original_order())
if rewritten {
Ok(toml::to_string(&data)?)
} else {
Ok(text)
}
}

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