Skip to content

Commit 70148e3

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

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
@@ -506,30 +506,29 @@ 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+
// see https://github.com/immunant/c2rust/issues/1605.
513+
for transform in ["rename_unnamed", "reorganize_definitions"] {
514+
let args = ["--cargo", "--rewrite-mode", "inplace", transform];
515+
let status = Command::new(&refactor)
516+
.args(args)
517+
.current_dir(build_dir)
518+
.status()
519+
.map_err(|e| {
520+
let refactor = refactor.display();
521+
failure::format_err!("unable to run {refactor}: {e}\nNote that c2rust-refactor must be installed separately from c2rust and c2rust-transpile.")
522+
})?;
523+
if !status.success() {
524+
return Err(failure::format_err!(
525+
"Refactoring failed. Please fix errors above and re-run:\n c2rust refactor {}",
526+
args.join(" "),
527+
));
528+
}
532529
}
530+
531+
Ok(())
533532
}
534533

535534
fn reorganize_definitions(

0 commit comments

Comments
 (0)