From ebaf058006ee4e1fb2475c1c20de2cbb200bec31 Mon Sep 17 00:00:00 2001 From: messense Date: Wed, 23 Jun 2021 12:03:23 +0800 Subject: [PATCH] Replace `toml_edit` with `toml` crate --- Cargo.lock | 41 -------------------------------------- Cargo.toml | 1 - src/source_distribution.rs | 15 ++++++++------ 3 files changed, 9 insertions(+), 48 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 44c7d89ae..e0f36b71f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -267,19 +267,6 @@ dependencies = [ "encoding_rs", ] -[[package]] -name = "chrono" -version = "0.4.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73" -dependencies = [ - "libc", - "num-integer", - "num-traits", - "time", - "winapi", -] - [[package]] name = "cipher" version = "0.2.5" @@ -304,16 +291,6 @@ dependencies = [ "vec_map", ] -[[package]] -name = "combine" -version = "4.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2d47c1b11006b87e492b53b313bb699ce60e16613c4dddaa91f8f7c220ab2fa" -dependencies = [ - "bytes", - "memchr", -] - [[package]] name = "configparser" version = "2.1.0" @@ -846,12 +823,6 @@ version = "0.2.97" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "12b8adadd720df158f4d70dfe7ccc6adb0472d7c55ca83445f6a5ab3e36f8fb6" -[[package]] -name = "linked-hash-map" -version = "0.5.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fb9b38af92608140b86b693604b9ffcc5824240a484d1ecd4795bacb2fe88f3" - [[package]] name = "llvm-bitcode" version = "0.1.2" @@ -925,7 +896,6 @@ dependencies = [ "tempfile", "thiserror", "toml", - "toml_edit", "walkdir", "zip", ] @@ -1878,17 +1848,6 @@ dependencies = [ "serde", ] -[[package]] -name = "toml_edit" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbbdcf4f749dd33b1f1ea19b547bf789d87442ec40767d6015e5e2d39158d69a" -dependencies = [ - "chrono", - "combine", - "linked-hash-map", -] - [[package]] name = "tower-service" version = "0.3.1" diff --git a/Cargo.toml b/Cargo.toml index 8e3abf888..e8b182dd7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/src/source_distribution.rs b/src/source_distribution.rs index b2b3d8e5d..2cbba6ee8 100644 --- a/src/source_distribution.rs +++ b/src/source_distribution.rs @@ -27,7 +27,7 @@ fn rewrite_cargo_toml( "Can't read Cargo.toml at {}", manifest_path.as_ref().display(), ))?; - let mut data = text.parse::().context(format!( + let mut data = toml::from_str::(&text).context(format!( "Failed to parse Cargo.toml at {}", manifest_path.as_ref().display() ))?; @@ -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() { @@ -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!( @@ -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