Skip to content

Commit 481c6d7

Browse files
fw-immunantkkysen
authored andcommitted
Revert "break c2rust dependency on c2rust-refactor"
This reverts commit 2bd339d.
1 parent 584b50b commit 481c6d7

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
@@ -464,8 +464,43 @@ fn get_extra_args_macos() -> Vec<String> {
464464
args
465465
}
466466

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

471506
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)