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 ebaf058
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 48 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
15 changes: 9 additions & 6 deletions src/source_distribution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ebaf058

Please sign in to comment.