From 4ab214c28625dba946b8a1dc2507850d458e6b3b Mon Sep 17 00:00:00 2001 From: Stuart Pernsteiner Date: Fri, 15 Mar 2024 16:31:30 -0700 Subject: [PATCH] analyze: accept multiple --rewrite-paths args --- c2rust-analyze/src/analyze.rs | 3 +++ c2rust-analyze/src/main.rs | 11 ++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/c2rust-analyze/src/analyze.rs b/c2rust-analyze/src/analyze.rs index acdb225bf5..84f589b65a 100644 --- a/c2rust-analyze/src/analyze.rs +++ b/c2rust-analyze/src/analyze.rs @@ -460,6 +460,9 @@ fn check_rewrite_path_prefixes(tcx: TyCtxt, fixed_defs: &mut HashSet, pre let hir = tcx.hir(); let prefixes: HashSet> = 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::>()) .collect(); let sym_impl = Symbol::intern("{impl}"); diff --git a/c2rust-analyze/src/main.rs b/c2rust-analyze/src/main.rs index ae8f0ff745..420495d463 100644 --- a/c2rust-analyze/src/main.rs +++ b/c2rust-analyze/src/main.rs @@ -37,7 +37,7 @@ use analyze::AnalysisCallbacks; use anyhow::anyhow; use anyhow::ensure; use anyhow::Context; -use clap::Parser; +use clap::{Parser, ArgAction}; use rustc_driver::RunCompiler; use rustc_driver::TimePassesCallbacks; use rustc_session::config::CrateType; @@ -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, + #[clap(long, action(ArgAction::Append))] + rewrite_paths: Vec, /// 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)] @@ -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, + fixed_defs_list: Option, /// `cargo` args. cargo_args: Vec, @@ -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); }