Skip to content

Commit

Permalink
analyze: accept multiple --rewrite-paths args
Browse files Browse the repository at this point in the history
  • Loading branch information
spernsteiner committed Mar 15, 2024
1 parent f7a8f63 commit faa795d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
3 changes: 3 additions & 0 deletions c2rust-analyze/src/analyze.rs
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,9 @@ fn check_rewrite_path_prefixes(tcx: TyCtxt, fixed_defs: &mut HashSet<DefId>, pre
let hir = tcx.hir();
let prefixes: HashSet<Vec<Symbol>> = prefixes
.split(',')
// Exclude empty paths. This allows for leading/trailing commas or double commas within
// the list, which may result when building the list programmatically.
.filter(|prefix| prefix.len() > 0)
.map(|prefix| prefix.split("::").map(Symbol::intern).collect::<Vec<_>>())
.collect();
let sym_impl = Symbol::intern("{impl}");
Expand Down
11 changes: 6 additions & 5 deletions c2rust-analyze/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use analyze::AnalysisCallbacks;
use anyhow::anyhow;
use anyhow::ensure;
use anyhow::Context;
use clap::Parser;
use clap::{ArgAction, Parser};
use rustc_driver::RunCompiler;
use rustc_driver::TimePassesCallbacks;
use rustc_session::config::CrateType;
Expand Down Expand Up @@ -75,8 +75,8 @@ struct Args {

/// Comma-separated list of paths to rewrite. Any item whose path does not start with a prefix
/// from this list will be marked non-rewritable (`FIXED`).
#[clap(long)]
rewrite_paths: Option<OsString>,
#[clap(long, action(ArgAction::Append))]
rewrite_paths: Vec<OsString>,
/// Rewrite source files on disk. The default is to print the rewritten source code to stdout
/// as part of the tool's debug output.
#[clap(long)]
Expand All @@ -95,7 +95,7 @@ struct Args {
/// in the crate being analyzed; the file passed to this option should list a subset of those
/// defs.
#[clap(long)]
fixed_defs_list: Option<OsString>,
fixed_defs_list: Option<PathBuf>,

/// `cargo` args.
cargo_args: Vec<OsString>,
Expand Down Expand Up @@ -395,7 +395,8 @@ fn cargo_wrapper(rustc_wrapper: &Path) -> anyhow::Result<()> {
cmd.env("C2RUST_ANALYZE_FIXED_DEFS_LIST", fixed_defs_list);
}

if let Some(ref rewrite_paths) = rewrite_paths {
if rewrite_paths.len() > 0 {
let rewrite_paths = rewrite_paths.join(OsStr::new(","));
cmd.env("C2RUST_ANALYZE_REWRITE_PATHS", rewrite_paths);
}

Expand Down

0 comments on commit faa795d

Please sign in to comment.