Skip to content

Commit 4f4e9c0

Browse files
authored
transpile: Run c2rust-refactor transforms as separate invocations (#1612)
2 parents e400ede + 70148e3 commit 4f4e9c0

File tree

1 file changed

+22
-23
lines changed

1 file changed

+22
-23
lines changed

c2rust-transpile/src/lib.rs

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

536535
fn reorganize_definitions(

0 commit comments

Comments
 (0)