Skip to content

Commit ac7576d

Browse files
committed
Merge branch 'main' into feat/new-exec-merge-1.3
2 parents ad5e7c2 + bee97a7 commit ac7576d

File tree

1 file changed

+28
-15
lines changed

1 file changed

+28
-15
lines changed

crates/cli/tests/app_e2e.rs

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1-
use std::{env, fs::OpenOptions, io::Write, path::Path, process::Command, sync::OnceLock};
1+
use std::{
2+
env,
3+
fs::{self, read_to_string},
4+
path::Path,
5+
process::Command,
6+
sync::OnceLock,
7+
};
28

39
use eyre::Result;
10+
use itertools::Itertools;
411
use tempfile::tempdir;
512

613
fn install_cli() {
@@ -134,6 +141,7 @@ fn test_cli_init_build() -> Result<()> {
134141
let manifest_path = temp_path.join("Cargo.toml");
135142
install_cli();
136143

144+
// Cargo will not respect patches if run within a workspace
137145
run_cmd(
138146
"cargo",
139147
&[
@@ -145,7 +153,7 @@ fn test_cli_init_build() -> Result<()> {
145153
],
146154
)?;
147155
if matches!(env::var("USE_LOCAL_OPENVM"), Ok(x) if x == "1") {
148-
append_patch_to_cargo_toml(&manifest_path)?;
156+
replace_with_local_openvm(&manifest_path)?;
149157
}
150158

151159
run_cmd(
@@ -185,25 +193,30 @@ fn run_cmd(program: &str, args: &[&str]) -> Result<()> {
185193
Ok(())
186194
}
187195

188-
fn append_patch_to_cargo_toml(file_path: impl AsRef<Path>) -> Result<()> {
196+
fn replace_with_local_openvm(file_path: impl AsRef<Path>) -> Result<()> {
189197
const MANIFEST_DIR: &str = env!("CARGO_MANIFEST_DIR");
190198
let openvm_path = Path::new(MANIFEST_DIR)
191199
.parent()
192200
.unwrap()
193201
.join("toolchain")
194202
.join("openvm");
195-
let mut file = OpenOptions::new()
196-
.create(false)
197-
.append(true)
198-
.open(file_path)?;
199-
200-
// Add a newline first to ensure proper formatting
201-
writeln!(file)?;
202-
writeln!(
203-
file,
204-
r#"[patch."https://github.com/openvm-org/openvm.git"]"#
205-
)?;
206-
writeln!(file, r#"openvm = {{ path = "{}" }}"#, openvm_path.display())?;
203+
let content = read_to_string(&file_path)?;
204+
let lines = content.lines().collect::<Vec<_>>();
205+
let new_content = lines
206+
.iter()
207+
.map(|line| {
208+
if line.starts_with("openvm = { git = \"https://github.com/openvm-org/openvm.git\"") {
209+
format!(
210+
r#"openvm = {{ path = "{}", features = ["std"] }}"#,
211+
openvm_path.display()
212+
)
213+
} else {
214+
line.to_string()
215+
}
216+
})
217+
.join("\n");
218+
219+
fs::write(file_path, new_content)?;
207220

208221
Ok(())
209222
}

0 commit comments

Comments
 (0)