Skip to content

Commit 7234b71

Browse files
committed
transpile: Run c2rust-refactor transforms as separate invocations
1 parent d016d67 commit 7234b71

File tree

1 file changed

+21
-23
lines changed

1 file changed

+21
-23
lines changed

c2rust-transpile/src/lib.rs

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -506,30 +506,28 @@ fn invoke_refactor(build_dir: &Path) -> Result<(), Error> {
506506
let refactor = env::current_exe()
507507
.expect("Cannot get current executable path")
508508
.with_file_name("c2rust-refactor");
509-
let args = [
510-
"--cargo",
511-
"--rewrite-mode",
512-
"inplace",
513-
"rename_unnamed",
514-
";",
515-
"reorganize_definitions",
516-
];
517-
let status = Command::new(&refactor)
518-
.args(args)
519-
.current_dir(build_dir)
520-
.status()
521-
.map_err(|e| {
522-
let refactor = refactor.display();
523-
failure::format_err!("unable to run {refactor}: {e}\nNote that c2rust-refactor must be installed separately from c2rust and c2rust-transpile.")
524-
})?;
525-
if status.success() {
526-
Ok(())
527-
} else {
528-
Err(failure::format_err!(
529-
"Refactoring failed. Please fix errors above and re-run:\n c2rust refactor {}",
530-
args.join(" "),
531-
))
509+
510+
// TODO: we could use `commit` to invoke the refactorer only once
511+
// with all transforms, but that command is currently broken
512+
for transform in ["rename_unnamed", "reorganize_definitions"] {
513+
let args = ["--cargo", "--rewrite-mode", "inplace", transform];
514+
let status = Command::new(&refactor)
515+
.args(args)
516+
.current_dir(build_dir)
517+
.status()
518+
.map_err(|e| {
519+
let refactor = refactor.display();
520+
failure::format_err!("unable to run {refactor}: {e}\nNote that c2rust-refactor must be installed separately from c2rust and c2rust-transpile.")
521+
})?;
522+
if !status.success() {
523+
return Err(failure::format_err!(
524+
"Refactoring failed. Please fix errors above and re-run:\n c2rust refactor {}",
525+
args.join(" "),
526+
));
527+
}
532528
}
529+
530+
Ok(())
533531
}
534532

535533
fn reorganize_definitions(

0 commit comments

Comments
 (0)