Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion c2rust-ast-exporter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ pub fn get_untyped_ast(
/// libClangTooling is not thread-safe, so we must not allow concurrent calls to `ast_exporter`.
static CLANG_MUTEX: Mutex<()> = Mutex::new(());

fn clang_build_path(cc_db: &Path) -> &Path {
cc_db
.parent()
.filter(|path| !path.as_os_str().is_empty())
.unwrap_or_else(|| Path::new("."))
}

fn get_ast_cbors(
file_path: &Path,
cc_db: &Path,
Expand All @@ -68,7 +75,7 @@ fn get_ast_cbors(
let mut args_owned = vec![CString::new("ast_exporter").unwrap()];
args_owned.push(CString::new(file_path.to_str().unwrap()).unwrap());
args_owned.push(CString::new("-p").unwrap());
args_owned.push(CString::new(cc_db.to_str().unwrap()).unwrap());
args_owned.push(CString::new(clang_build_path(cc_db).to_str().unwrap()).unwrap());

for &arg in extra_args {
args_owned.push(CString::new(["-extra-arg=", arg].join("")).unwrap())
Expand Down
Loading