mirror of
https://gitlab.com/gabmus/envision.git
synced 2025-07-31 13:18:46 +00:00
feat: refactor depcheck; depcheck for includes
This commit is contained in:
parent
29b21562fe
commit
86ab0cdf31
1 changed files with 26 additions and 31 deletions
|
@ -1,13 +1,15 @@
|
||||||
use std::{env, path::Path};
|
use std::{env, path::Path};
|
||||||
|
|
||||||
pub enum DepType {
|
pub enum DepType {
|
||||||
SharedObject(String),
|
SharedObject,
|
||||||
Executable(String),
|
Executable,
|
||||||
|
Include,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Dependency {
|
pub struct Dependency {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub dep_type: DepType,
|
pub dep_type: DepType,
|
||||||
|
pub filename: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn shared_obj_paths() -> Vec<String> {
|
fn shared_obj_paths() -> Vec<String> {
|
||||||
|
@ -23,37 +25,27 @@ fn shared_obj_paths() -> Vec<String> {
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! executable_paths {
|
fn include_paths() -> Vec<String> {
|
||||||
() => {
|
vec!["/usr/include".to_string()]
|
||||||
env::var("PATH")
|
|
||||||
.expect("PATH environment variable not defined")
|
|
||||||
.split(':')
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn check_dependency(dep: Dependency) -> bool {
|
pub fn check_dependency(dep: Dependency) -> bool {
|
||||||
match dep.dep_type {
|
for dir in match dep.dep_type {
|
||||||
DepType::SharedObject(filename) => {
|
DepType::SharedObject => shared_obj_paths(),
|
||||||
for lib_path in shared_obj_paths() {
|
DepType::Executable => env::var("PATH")
|
||||||
let path_s = &format!("{lp}/{fn}", lp=lib_path, fn=filename);
|
.expect("PATH environment variable not defined")
|
||||||
let path = Path::new(&path_s);
|
.split(':')
|
||||||
if path.is_file() {
|
.map(str::to_string)
|
||||||
return true;
|
.collect(),
|
||||||
}
|
DepType::Include => include_paths(),
|
||||||
}
|
} {
|
||||||
return false;
|
let path_s = &format!("{dir}/{fname}", dir = dir, fname = dep.filename);
|
||||||
|
let path = Path::new(&path_s);
|
||||||
|
if path.is_file() {
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
DepType::Executable(exec) => {
|
|
||||||
for path in executable_paths!() {
|
|
||||||
let path_s = &format!("{p}/{ex}", p=path, ex=exec);
|
|
||||||
let path = Path::new(path_s);
|
|
||||||
if path.is_file() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -64,7 +56,8 @@ mod tests {
|
||||||
fn can_find_libc() {
|
fn can_find_libc() {
|
||||||
let libc_dep = Dependency {
|
let libc_dep = Dependency {
|
||||||
name: "libc".into(),
|
name: "libc".into(),
|
||||||
dep_type: DepType::SharedObject("libc.so".into()),
|
dep_type: DepType::SharedObject,
|
||||||
|
filename: "libc.so".into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
assert!(check_dependency(libc_dep));
|
assert!(check_dependency(libc_dep));
|
||||||
|
@ -74,7 +67,8 @@ mod tests {
|
||||||
fn can_find_ls() {
|
fn can_find_ls() {
|
||||||
let libc_dep = Dependency {
|
let libc_dep = Dependency {
|
||||||
name: "ls".into(),
|
name: "ls".into(),
|
||||||
dep_type: DepType::Executable("ls".into()),
|
dep_type: DepType::Executable,
|
||||||
|
filename: ("ls".into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
assert!(check_dependency(libc_dep));
|
assert!(check_dependency(libc_dep));
|
||||||
|
@ -84,7 +78,8 @@ mod tests {
|
||||||
fn cannot_find_fake_lib() {
|
fn cannot_find_fake_lib() {
|
||||||
let fake_dep = Dependency {
|
let fake_dep = Dependency {
|
||||||
name: "fakedep".into(),
|
name: "fakedep".into(),
|
||||||
dep_type: DepType::SharedObject("fakedep.so".into()),
|
dep_type: DepType::SharedObject,
|
||||||
|
filename: "fakedep.so".into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
assert!(!check_dependency(fake_dep));
|
assert!(!check_dependency(fake_dep));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue