mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-08-23 20:04:21 +00:00
internal: a bit more of cwd safety for flycheck
This commit is contained in:
parent
8df38aa797
commit
8d8c26e6f5
16 changed files with 72 additions and 52 deletions
|
@ -1,6 +1,7 @@
|
|||
//! Handles dynamic library loading for proc macro
|
||||
|
||||
use std::{
|
||||
convert::TryInto,
|
||||
fmt,
|
||||
fs::File,
|
||||
io,
|
||||
|
@ -10,6 +11,7 @@ use std::{
|
|||
use libloading::Library;
|
||||
use memmap2::Mmap;
|
||||
use object::Object;
|
||||
use paths::AbsPath;
|
||||
use proc_macro_api::{read_dylib_info, ProcMacroKind};
|
||||
|
||||
use super::abis::Abi;
|
||||
|
@ -116,7 +118,10 @@ impl ProcMacroLibraryLibloading {
|
|||
invalid_data_err(format!("Cannot find registrar symbol in file {}", file.display()))
|
||||
})?;
|
||||
|
||||
let version_info = read_dylib_info(file)?;
|
||||
let abs_file: &AbsPath = file.try_into().map_err(|_| {
|
||||
invalid_data_err(format!("expected an absolute path, got {}", file.display()))
|
||||
})?;
|
||||
let version_info = read_dylib_info(&abs_file)?;
|
||||
|
||||
let lib = load_library(file).map_err(invalid_data_err)?;
|
||||
let abi = Abi::from_lib(&lib, symbol_name, version_info)?;
|
||||
|
@ -136,7 +141,7 @@ impl Expander {
|
|||
|
||||
let lib = ensure_file_with_lock_free_access(&lib)?;
|
||||
|
||||
let library = ProcMacroLibraryLibloading::open(&lib)?;
|
||||
let library = ProcMacroLibraryLibloading::open(lib.as_ref())?;
|
||||
|
||||
Ok(Expander { inner: library })
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ pub(crate) struct ProcMacroSrv {
|
|||
|
||||
impl ProcMacroSrv {
|
||||
pub fn expand(&mut self, task: &ExpansionTask) -> Result<ExpansionResult, String> {
|
||||
let expander = self.expander(&task.lib)?;
|
||||
let expander = self.expander(task.lib.as_ref())?;
|
||||
|
||||
let mut prev_env = HashMap::new();
|
||||
for (k, v) in &task.env {
|
||||
|
@ -54,7 +54,7 @@ impl ProcMacroSrv {
|
|||
}
|
||||
|
||||
pub fn list_macros(&mut self, task: &ListMacrosTask) -> Result<ListMacrosResult, String> {
|
||||
let expander = self.expander(&task.lib)?;
|
||||
let expander = self.expander(task.lib.as_ref())?;
|
||||
Ok(ListMacrosResult { macros: expander.list_macros() })
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#[macro_use]
|
||||
mod utils;
|
||||
use expect_test::expect;
|
||||
use paths::AbsPathBuf;
|
||||
use utils::*;
|
||||
|
||||
#[test]
|
||||
|
@ -95,7 +96,7 @@ fn list_test_macros() {
|
|||
|
||||
#[test]
|
||||
fn test_version_check() {
|
||||
let path = fixtures::proc_macro_test_dylib_path();
|
||||
let path = AbsPathBuf::assert(fixtures::proc_macro_test_dylib_path());
|
||||
let info = proc_macro_api::read_dylib_info(&path).unwrap();
|
||||
assert!(info.version.1 >= 50);
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
use crate::dylib;
|
||||
use crate::ProcMacroSrv;
|
||||
use expect_test::Expect;
|
||||
use paths::AbsPathBuf;
|
||||
use proc_macro_api::ListMacrosTask;
|
||||
use std::str::FromStr;
|
||||
|
||||
|
@ -41,7 +42,7 @@ fn assert_expand_impl(macro_name: &str, input: &str, attr: Option<&str>, expect:
|
|||
}
|
||||
|
||||
pub fn list() -> Vec<String> {
|
||||
let path = fixtures::proc_macro_test_dylib_path();
|
||||
let path = AbsPathBuf::assert(fixtures::proc_macro_test_dylib_path());
|
||||
let task = ListMacrosTask { lib: path };
|
||||
let mut srv = ProcMacroSrv::default();
|
||||
let res = srv.list_macros(&task).unwrap();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue