Skip to content

Commit

Permalink
[move] Update versions of toml and toml_edit crates
Browse files Browse the repository at this point in the history
  • Loading branch information
tzakian committed Dec 18, 2024
1 parent a8d8af5 commit cd16088
Show file tree
Hide file tree
Showing 13 changed files with 92 additions and 63 deletions.
61 changes: 38 additions & 23 deletions external-crates/move/Cargo.lock

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

4 changes: 2 additions & 2 deletions external-crates/move/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ tera = "1.16.0"
thiserror = "1.0.24"
tiny-keccak = { version = "2.0.2", features = ["sha3"] }
tokio = { version = "1.18.2", features = ["full"] }
toml = "0.5.8"
toml_edit = { version = "0.14.3", features = ["easy"] }
toml = "0.8.19"
toml_edit = { version = "0.22.22", features = ["serde"] }
tracing = "0.1.26"
tracing-subscriber = { version = "0.3.15", features = ["env-filter"] }
treeline = "0.1.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use std::{
io::Write,
path::{Path, PathBuf},
};
use toml_edit::{value, Document};
use toml_edit::{value, DocumentMut};
use vfs::VfsPath;

use super::{
Expand Down Expand Up @@ -273,7 +273,7 @@ impl BuildPlan {
pub fn record_package_edition(&self, edition: Edition) -> anyhow::Result<()> {
let move_toml_path = resolve_move_manifest_path(&self.root_package_path());
let mut toml = std::fs::read_to_string(move_toml_path.clone())?
.parse::<Document>()
.parse::<DocumentMut>()
.expect("Failed to read TOML file to update edition");
toml[PACKAGE_NAME][EDITION_NAME] = value(edition.to_string());
std::fs::write(move_toml_path, toml.to_string())?;
Expand Down
12 changes: 6 additions & 6 deletions external-crates/move/crates/move-package/src/lock_file/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ pub fn update_dependency_graph(
use toml_edit::value;
let mut toml_string = String::new();
file.read_to_string(&mut toml_string)?;
let mut toml = toml_string.parse::<toml_edit::Document>()?;
let mut toml = toml_string.parse::<toml_edit::DocumentMut>()?;
let move_table = toml
.entry("move")
.or_insert(Item::Table(toml_edit::Table::new()))
Expand Down Expand Up @@ -297,7 +297,7 @@ pub fn update_compiler_toolchain(
) -> Result<()> {
let mut toml_string = String::new();
file.read_to_string(&mut toml_string)?;
let mut toml = toml_string.parse::<toml_edit::Document>()?;
let mut toml = toml_string.parse::<toml_edit::DocumentMut>()?;
let move_table = toml["move"].as_table_mut().ok_or(std::fmt::Error)?;
let toolchain_version = toml::Value::try_from(ToolchainVersion {
compiler_version,
Expand Down Expand Up @@ -355,10 +355,10 @@ pub enum ManagedAddressUpdate {
/// for preparing package publishing and package upgrades. Invariant: callers maintain a valid
/// hex `id`.
pub fn set_original_id(file: &mut LockFile, environment: &str, id: &str) -> Result<()> {
use toml_edit::{value, Document};
use toml_edit::{value, DocumentMut};
let mut toml_string = String::new();
file.read_to_string(&mut toml_string)?;
let mut toml = toml_string.parse::<Document>()?;
let mut toml = toml_string.parse::<DocumentMut>()?;
let env_table = toml
.get_mut(ENV_TABLE_NAME)
.and_then(|item| item.as_table_mut())
Expand All @@ -382,11 +382,11 @@ pub fn update_managed_address(
environment: &str,
managed_address_update: ManagedAddressUpdate,
) -> Result<()> {
use toml_edit::{value, Document, Table};
use toml_edit::{value, DocumentMut, Table};

let mut toml_string = String::new();
file.read_to_string(&mut toml_string)?;
let mut toml = toml_string.parse::<Document>()?;
let mut toml = toml_string.parse::<DocumentMut>()?;

let env_table = toml
.entry(ENV_TABLE_NAME)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1246,10 +1246,10 @@ impl DependencyGraph {
for (id, pkg) in &self.package_table {
writeln!(writer, "\n[[move.package]]")?;

writeln!(writer, "id = {}", str_escape(id.as_str())?)?;
writeln!(writer, "id = {}", str_escape(id.as_str()))?;
writeln!(writer, "source = {}", PackageTOML(pkg))?;
if let Some(version) = &pkg.version {
writeln!(writer, "version = {}", str_escape(version.as_str())?)?;
writeln!(writer, "version = {}", str_escape(version.as_str()))?;
}

self.write_dependencies_to_lock(*id, &mut writer)?;
Expand All @@ -1259,7 +1259,7 @@ impl DependencyGraph {
let mut dev_dependencies = None;
let mut packages = None;
if !writer.is_empty() {
let toml = writer.parse::<toml_edit::Document>()?;
let toml = writer.parse::<toml_edit::DocumentMut>()?;
if let Some(value) = toml.get("dependencies").and_then(|v| v.as_value()) {
dependencies = Some(value.clone());
}
Expand Down Expand Up @@ -1572,18 +1572,18 @@ impl fmt::Display for Package {
subdir,
}) => {
write!(f, "git = ")?;
f.write_str(&str_escape(git_url.as_str())?)?;
f.write_str(&str_escape(git_url.as_str()))?;

write!(f, ", rev = ")?;
f.write_str(&str_escape(git_rev.as_str())?)?;
f.write_str(&str_escape(git_rev.as_str()))?;

write!(f, ", subdir = ")?;
f.write_str(&path_escape(subdir)?)?;
}

PM::DependencyKind::OnChain(PM::OnChainInfo { id }) => {
write!(f, "id = ")?;
f.write_str(&str_escape(id.as_str())?)?;
f.write_str(&str_escape(id.as_str()))?;
}
}

Expand Down Expand Up @@ -1628,14 +1628,14 @@ impl<'a> fmt::Display for DependencyTOML<'a> {
f.write_str("{ ")?;

write!(f, "id = ")?;
f.write_str(&str_escape(id.as_str())?)?;
f.write_str(&str_escape(id.as_str()))?;

write!(f, ", name = ")?;
f.write_str(&str_escape(dep_name.as_str())?)?;
f.write_str(&str_escape(dep_name.as_str()))?;

if let Some(digest) = digest {
write!(f, ", digest = ")?;
f.write_str(&str_escape(digest.as_str())?)?;
f.write_str(&str_escape(digest.as_str()))?;
}

if let Some(subst) = subst {
Expand All @@ -1655,18 +1655,18 @@ impl<'a> fmt::Display for SubstTOML<'a> {
addr: &PM::NamedAddress,
subst: &PM::SubstOrRename,
) -> fmt::Result {
f.write_str(&str_escape(addr.as_str())?)?;
f.write_str(&str_escape(addr.as_str()))?;
write!(f, " = ")?;

match subst {
PM::SubstOrRename::RenameFrom(named) => {
f.write_str(&str_escape(named.as_str())?)?;
f.write_str(&str_escape(named.as_str()))?;
}

PM::SubstOrRename::Assign(account) => {
f.write_str(&str_escape(
&account.to_canonical_string(/* with_prefix */ false),
)?)?;
))?;
}
}

Expand Down Expand Up @@ -1694,13 +1694,13 @@ impl<'a> fmt::Display for SubstTOML<'a> {
}

/// Escape a string to output in a TOML file.
fn str_escape(s: &str) -> Result<String, fmt::Error> {
toml::to_string(s).map_err(|_| fmt::Error)
fn str_escape(s: &str) -> String {
format!("\"{}\"", s)
}

/// Escape a path to output in a TOML file.
fn path_escape(p: &Path) -> Result<String, fmt::Error> {
str_escape(p.to_str().ok_or(fmt::Error)?)
Ok(str_escape(p.to_str().ok_or(fmt::Error)?))
}

fn format_deps(
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
Unable to parse Move package manifest: duplicate key: `OtherDep` for key `dependencies` at line 4 column 1
Unable to parse Move package manifest: TOML parse error at line 6, column 1
|
6 | OtherDep = { local = "./deps_only/different_dep" }
| ^
duplicate key `OtherDep` in table `dependencies`

Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
Failed to resolve dependencies for package 'Root': Parsing response from '../resolvers/broken.sh' for dependency 'A' of package 'Root': Deserializing packages: expected an equals, found an identifier at line 1 column 8
Failed to resolve dependencies for package 'Root': Parsing response from '../resolvers/broken.sh' for dependency 'A' of package 'Root': Deserializing packages: TOML parse error at line 1, column 8
|
1 | Broken response (not a lock file) from resolver for dependencies of A.
| ^
expected `.`, `=`

Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
Error parsing '[dependencies]' section of manifest: Malformed external resolver declaration for dependency r.baz = "quz"
foo = "bar"

Error parsing '[dependencies]' section of manifest: Malformed external resolver declaration for dependency r.{ baz = "quz", foo = "bar" }
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
Error parsing '[dependencies]' section of manifest: Malformed external resolver declaration for dependency r.[foo]
bar = "baz"

Error parsing '[dependencies]' section of manifest: Malformed external resolver declaration for dependency r.{ foo = { bar = "baz" } }
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
Unable to parse Move package manifest: duplicate key: `a` for key `addresses` at line 4 column 1
Unable to parse Move package manifest: TOML parse error at line 6, column 1
|
6 | a = "0x2"
| ^
duplicate key `a` in table `addresses`

Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
Unable to parse Move package manifest: redefinition of table `package` for key `package` at line 4 column 1
Unable to parse Move package manifest: TOML parse error at line 4, column 1
|
4 | [package]
| ^
invalid table header
duplicate key `package` in document root

Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
Error parsing '[addresses]' section of manifest: Invalid address name b = "0x1"
encountered. Expected a string but found a table
Error parsing '[addresses]' section of manifest: Invalid address name { b = "0x1" } encountered. Expected a string but found a table
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
Error parsing '[dependencies]' section of manifest: Malformed dependency substitution B = "0x1"
R = "0x2"
. Expected a string, but encountered a table
Error parsing '[dependencies]' section of manifest: Malformed dependency substitution { B = "0x1", R = "0x2" }. Expected a string, but encountered a table

0 comments on commit cd16088

Please sign in to comment.