Skip to content

Commit 4558445

Browse files
committed
openvino-finder: add logging, OPENVINO_BUILD_DIR
1 parent cd9f495 commit 4558445

File tree

3 files changed

+82
-15
lines changed

3 files changed

+82
-15
lines changed

Cargo.lock

Lines changed: 44 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/openvino-finder/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,7 @@ documentation = "https://docs.rs/openvino-finder"
1010
edition = "2018"
1111

1212
[dependencies]
13+
log = "0.4"
14+
15+
[dev-dependencies]
16+
pretty_env_logger = "0.4"

crates/openvino-finder/src/lib.rs

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,36 @@ pub fn find(library_name: &str) -> Option<PathBuf> {
1313
library_name,
1414
env::consts::DLL_SUFFIX
1515
);
16+
log::info!("Attempting to find library: {}", file);
17+
18+
// We search for the library in various different places and early-return if we find it.
19+
macro_rules! check_and_return {
20+
($path: expr) => {
21+
log::debug!("Searching in: {}", $path.display());
22+
if $path.is_file() {
23+
log::info!("Found library at path: {}", $path.display());
24+
return Some($path);
25+
}
26+
};
27+
}
1628

1729
// Search using the `OPENVINO_INSTALL_DIR` environment variable; this may be set by users of the
1830
// openvino-rs library.
1931
if let Some(install_dir) = env::var_os(ENV_OPENVINO_INSTALL_DIR) {
2032
let install_dir = PathBuf::from(install_dir);
2133
for lib_dir in KNOWN_INSTALLATION_SUBDIRECTORIES {
2234
let search_path = install_dir.join(lib_dir).join(&file);
23-
if search_path.is_file() {
24-
return Some(search_path);
25-
}
35+
check_and_return!(search_path);
36+
}
37+
}
38+
39+
// Search using the `OPENVINO_BUILD_DIR` environment variable; this may be set by users of the
40+
// openvino-rs library.
41+
if let Some(build_dir) = env::var_os(ENV_OPENVINO_BUILD_DIR) {
42+
let install_dir = PathBuf::from(build_dir);
43+
for lib_dir in KNOWN_BUILD_SUBDIRECTORIES {
44+
let search_path = install_dir.join(lib_dir).join(&file);
45+
check_and_return!(search_path);
2646
}
2747
}
2848

@@ -32,9 +52,7 @@ pub fn find(library_name: &str) -> Option<PathBuf> {
3252
let install_dir = PathBuf::from(install_dir);
3353
for lib_dir in KNOWN_INSTALLATION_SUBDIRECTORIES {
3454
let search_path = install_dir.join(lib_dir).join(&file);
35-
if search_path.is_file() {
36-
return Some(search_path);
37-
}
55+
check_and_return!(search_path);
3856
}
3957
}
4058

@@ -44,9 +62,7 @@ pub fn find(library_name: &str) -> Option<PathBuf> {
4462
if let Some(path) = env::var_os(ENV_LIBRARY_PATH) {
4563
for lib_dir in env::split_paths(&path) {
4664
let search_path = lib_dir.join(&file);
47-
if search_path.is_file() {
48-
return Some(search_path);
49-
}
65+
check_and_return!(search_path);
5066
}
5167
}
5268

@@ -58,17 +74,15 @@ pub fn find(library_name: &str) -> Option<PathBuf> {
5874
{
5975
for lib_dir in KNOWN_INSTALLATION_SUBDIRECTORIES {
6076
let search_path = default_dir.join(lib_dir).join(&file);
61-
if search_path.is_file() {
62-
return Some(search_path);
63-
}
77+
check_and_return!(search_path);
6478
}
6579
}
6680

6781
None
6882
}
6983

7084
const ENV_OPENVINO_INSTALL_DIR: &'static str = "OPENVINO_INSTALL_DIR";
71-
85+
const ENV_OPENVINO_BUILD_DIR: &'static str = "OPENVINO_BUILD_DIR";
7286
const ENV_INTEL_OPENVINO_DIR: &'static str = "INTEL_OPENVINO_DIR";
7387

7488
#[cfg(target_os = "linux")]
@@ -95,6 +109,12 @@ const KNOWN_INSTALLATION_SUBDIRECTORIES: &'static [&'static str] = &[
95109
"deployment_tools/inference_engine/external/tbb/lib",
96110
];
97111

112+
const KNOWN_BUILD_SUBDIRECTORIES: &'static [&'static str] = &[
113+
"bin/intel64/Debug/lib",
114+
"bin/intel64/Release/lib",
115+
"inference-engine/temp/tbb/lib",
116+
];
117+
98118
#[cfg(test)]
99119
mod test {
100120
use super::*;
@@ -103,6 +123,7 @@ mod test {
103123
/// system.
104124
#[test]
105125
fn find_inference_engine_c_api_locally() {
126+
pretty_env_logger::init();
106127
assert!(find("inference_engine_c_api").is_some());
107128
}
108129
}

0 commit comments

Comments
 (0)