Skip to content

Commit e17cbec

Browse files
committed
Revert "break c2rust dependency on c2rust-refactor"
This reverts commit 2bd339d.
1 parent 5acd0c8 commit e17cbec

File tree

6 files changed

+50
-5
lines changed

6 files changed

+50
-5
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

c2rust-transpile/src/lib.rs

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -460,8 +460,43 @@ fn get_extra_args_macos() -> Vec<String> {
460460
args
461461
}
462462

463-
fn invoke_refactor(_build_dir: &Path) -> Result<(), Error> {
464-
Ok(())
463+
fn invoke_refactor(build_dir: &Path) -> Result<(), Error> {
464+
// Make sure the crate builds cleanly
465+
let status = process::Command::new("cargo")
466+
.args(&["check"])
467+
.env("RUSTFLAGS", "-Awarnings")
468+
.current_dir(build_dir)
469+
.status()?;
470+
if !status.success() {
471+
return Err(failure::format_err!("Crate does not compile."));
472+
}
473+
474+
// Assumes the subcommand executable is in the same directory as this program.
475+
let cmd_path = std::env::current_exe().expect("Cannot get current executable path");
476+
let mut cmd_path = cmd_path.as_path().canonicalize().unwrap();
477+
cmd_path.pop(); // remove current executable
478+
cmd_path.push(format!("c2rust-refactor"));
479+
assert!(cmd_path.exists(), "{:?} is missing", cmd_path);
480+
let args = [
481+
"--cargo",
482+
"--rewrite-mode",
483+
"inplace",
484+
"rename_unnamed",
485+
";",
486+
"reorganize_definitions",
487+
];
488+
let status = process::Command::new(cmd_path.into_os_string())
489+
.args(&args)
490+
.current_dir(build_dir)
491+
.status()?;
492+
if status.success() {
493+
Ok(())
494+
} else {
495+
Err(failure::format_err!(
496+
"Refactoring failed. Please fix errors above and re-run:\n c2rust refactor {}",
497+
args.join(" "),
498+
))
499+
}
465500
}
466501

467502
fn reorganize_definitions(

c2rust/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@ log = "0.4"
2121
regex = "1.3"
2222
shlex = "1.3"
2323
c2rust-transpile = { version = "0.21.0", path = "../c2rust-transpile" }
24+
c2rust-refactor = { version = "0.21.0", path = "../c2rust-refactor" }
2425

2526
[build-dependencies]
2627
c2rust-build-paths = { path = "../c2rust-build-paths", version = "0.21.0" }
2728

2829
[features]
2930
# Force static linking of LLVM
3031
llvm-static = ["c2rust-transpile/llvm-static"]
32+
profile = ["c2rust-refactor/profile"]

c2rust-refactor/src/bin/c2rust-refactor.rs renamed to c2rust/src/bin/c2rust-refactor.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
1-
use clap::{load_yaml, App, ArgMatches};
2-
use log::info;
1+
extern crate env_logger;
2+
#[macro_use]
3+
extern crate log;
4+
#[macro_use]
5+
extern crate clap;
6+
extern crate c2rust_refactor;
7+
extern crate shlex;
8+
9+
use clap::{App, ArgMatches};
310
use std::fs::File;
411
use std::io::Read;
512
use std::process;

c2rust/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ impl SubCommand {
6060
/// Get all known [`SubCommand`]s. These have no [`SubCommand::path`].
6161
/// Even if the subcommand executables aren't there, we can still suggest them.
6262
pub fn known() -> impl Iterator<Item = Self> {
63-
["transpile", "instrument", "pdg", "analyze"]
63+
["transpile", "refactor", "instrument", "pdg", "analyze"]
6464
.into_iter()
6565
.map(|name| Self {
6666
path: None,
File renamed without changes.

0 commit comments

Comments
 (0)