pub struct CompileCommand {
pub file: PathBuf,
pub directory: Option<PathBuf>,
pub arguments: Vec<String>,
}Expand description
One entry of a compile_commands.json.
The format every C++ build system can emit, and the only reliable way to learn how a project is meant to be compiled. Guessing include paths from a directory listing is what produces an analysis that works on the author’s machine and fails everywhere else.
Fields§
§file: PathBufThe file this command compiles.
directory: Option<PathBuf>The directory the command runs in.
arguments: Vec<String>The command, split into arguments.
Implementations§
Source§impl CompileCommand
impl CompileCommand
Sourcepub fn to_config(&self) -> CompilerConfig
pub fn to_config(&self) -> CompilerConfig
Read the compiler configuration out of this command’s arguments.
Only the flags that change what the code means are read: include paths, defines, the standard,
the target, and the -o/-c/input/output plumbing that is skipped. A flag this does not know is
ignored rather than guessed at, because a wrong -D is worse than a missing one.
Sourcepub fn to_config_with(
&self,
read: &mut dyn FnMut(&Path) -> Option<String>,
) -> CompilerConfig
pub fn to_config_with( &self, read: &mut dyn FnMut(&Path) -> Option<String>, ) -> CompilerConfig
The same, with the command’s response files read — which is what a build system’s own command line means, and what CMake’s database needs.
CMake does not write its include paths into the arguments: it writes
@CMakeFiles/<target>.dir/includes_CXX.rsp and puts the -I flags in that file, for the Makefile and Ninja
generators alike. Measured on a real CMake project: every entry of its compile_commands.json was of that
shape, so a reader that does not follow the indirection sees a project with no include paths at all — its own
headers stop resolving, and the file list stops being the build’s.
read is the caller’s, because this crate reads through a provider rather than the filesystem: the server has
to answer for a buffer nobody has saved, and a test has to be able to say what a file holds.
Trait Implementations§
Source§impl Clone for CompileCommand
impl Clone for CompileCommand
Source§fn clone(&self) -> CompileCommand
fn clone(&self) -> CompileCommand
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for CompileCommand
impl Debug for CompileCommand
impl Eq for CompileCommand
Source§impl PartialEq for CompileCommand
impl PartialEq for CompileCommand
impl StructuralPartialEq for CompileCommand
Auto Trait Implementations§
impl Forget for CompileCommand
impl Freeze for CompileCommand
impl Move for CompileCommand
impl RefUnwindSafe for CompileCommand
impl Send for CompileCommand
impl Sync for CompileCommand
impl Unpin for CompileCommand
impl UnsafeUnpin for CompileCommand
impl UnwindSafe for CompileCommand
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more