From 5c47771c883daa1801feb40e70eaa7ef374e6f17 Mon Sep 17 00:00:00 2001 From: Waylon Jepsen Date: Thu, 14 Sep 2023 12:19:32 +0200 Subject: [PATCH 1/3] Update bind.rs --- bin/bind.rs | 60 ++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 55 insertions(+), 5 deletions(-) diff --git a/bin/bind.rs b/bin/bind.rs index 15cff2fa..03fa51d3 100644 --- a/bin/bind.rs +++ b/bin/bind.rs @@ -1,5 +1,5 @@ #![warn(missing_docs)] -use std::process::Command; +use std::{env, fs, io, path::Path, process::Command}; /// Runs the `forge` command-line tool to generate bindings. /// @@ -17,6 +17,7 @@ use std::process::Command; /// tool is not installed. pub(crate) fn forge_bind() -> std::io::Result<()> { + println!("Generating bindings for project contracts..."); let output = Command::new("forge") .arg("bind") .arg("--revert-strings") @@ -30,14 +31,63 @@ pub(crate) fn forge_bind() -> std::io::Result<()> { if output.status.success() { let output_str = String::from_utf8_lossy(&output.stdout); println!("Command output: {}", output_str); - println!("Note: revert strings are on"); - Ok(()) + println!("Revert strings are on"); } else { let err_str = String::from_utf8_lossy(&output.stderr); println!("Command failed, error: {}, is forge installed?", err_str); - Err(std::io::Error::new( + return Err(std::io::Error::new( std::io::ErrorKind::Other, "Command failed", - )) + )); } + + // Define path to `lib` directory + let lib_dir = Path::new("lib"); + bindings_for_submodules(lib_dir)?; + + Ok(()) +} + +fn bindings_for_submodules(dir: &Path) -> io::Result<()> { + if dir.is_dir() { + // Iterate through entries in the directory + for entry in fs::read_dir(dir)? { + let entry = entry?; + let path = entry.path(); + + // If the entry is a directory, run command inside it + if path.is_dir() && path.file_name().unwrap_or_default() != "forge-std" { + println!("Generating bindings for submodule: {:?}...", path); + + env::set_current_dir(&path)?; + + let submodule_name = path.file_name().unwrap().to_str().unwrap(); // Assuming file_name() is not None and is valid UTF-8 + let output_path = format!("../../src/{}_bindings/", submodule_name); + + let output = Command::new("forge") + .arg("bind") + .arg("--revert-strings") + .arg("debug") + .arg("-b") + .arg(&output_path) // Use the dynamically generated path + .arg("--module") + .arg("--overwrite") + .output()?; + + if output.status.success() { + let output_str = String::from_utf8_lossy(&output.stdout); + println!("Command output: {}", output_str); + println!("Revert strings are on"); + } else { + let err_str = String::from_utf8_lossy(&output.stderr); + println!("Command failed, error: {}", err_str); + return Err(std::io::Error::new( + std::io::ErrorKind::Other, + "Command failed", + )); + } + } + } + } + Ok(()) } From da23639507017186ffca19076f1d424dff383c53 Mon Sep 17 00:00:00 2001 From: Waylon Jepsen Date: Thu, 14 Sep 2023 12:28:42 +0200 Subject: [PATCH 2/3] =?UTF-8?q?arbiter=20bind=20bug=20is=20fixed=20?= =?UTF-8?q?=F0=9F=90=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/bind.rs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/bin/bind.rs b/bin/bind.rs index 03fa51d3..a878fd0b 100644 --- a/bin/bind.rs +++ b/bin/bind.rs @@ -74,18 +74,18 @@ fn bindings_for_submodules(dir: &Path) -> io::Result<()> { .arg("--overwrite") .output()?; - if output.status.success() { - let output_str = String::from_utf8_lossy(&output.stdout); - println!("Command output: {}", output_str); - println!("Revert strings are on"); - } else { - let err_str = String::from_utf8_lossy(&output.stderr); - println!("Command failed, error: {}", err_str); - return Err(std::io::Error::new( - std::io::ErrorKind::Other, - "Command failed", - )); - } + if output.status.success() { + let output_str = String::from_utf8_lossy(&output.stdout); + println!("Command output: {}", output_str); + println!("Revert strings are on"); + } else { + let err_str = String::from_utf8_lossy(&output.stderr); + println!("Command failed, error: {}", err_str); + return Err(std::io::Error::new( + std::io::ErrorKind::Other, + "Command failed", + )); + } } } } From 361295c7733635db3439f1a07ea372207fd94f01 Mon Sep 17 00:00:00 2001 From: Waylon Jepsen Date: Thu, 14 Sep 2023 12:30:04 +0200 Subject: [PATCH 3/3] patch version --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 7313e130..785ee466 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ exclude = ["benches"] # Package configuration [package] name = "arbiter" -version = "0.3.1" +version = "0.3.2" edition = "2021" authors = ["Colin Roberts", "Waylon Jepsen"]