Skip to content

Commit

Permalink
Merge pull request #499 from primitivefinance/arbiter_bind
Browse files Browse the repository at this point in the history
Arbiter bind
  • Loading branch information
Autoparallel authored Sep 14, 2023
2 parents a63d62d + 361295c commit 211f034
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down
60 changes: 55 additions & 5 deletions bin/bind.rs
Original file line number Diff line number Diff line change
@@ -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.
///
Expand All @@ -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")
Expand All @@ -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(())
}

0 comments on commit 211f034

Please sign in to comment.