Look for native programs in same directory as the current executable

This commit is contained in:
Michael Vines 2018-10-09 14:52:38 -07:00
parent 9931ac9780
commit 02225aa95c
1 changed files with 12 additions and 22 deletions

View File

@ -1,6 +1,7 @@
extern crate elf;
extern crate rbpf;
use std::env;
use std::io::prelude::*;
use std::mem;
use std::path::PathBuf;
@ -46,28 +47,17 @@ pub enum ProgramPath {
impl ProgramPath {
/// Creates a platform-specific file path
pub fn create(&self, name: &str) -> PathBuf {
let mut path = PathBuf::from(env!("OUT_DIR"));
match self {
ProgramPath::Bpf => {
//println!("Bpf");
path.pop();
path.pop();
path.pop();
path.push(PLATFORM_FILE_PREFIX_BPF.to_string() + name);
path.set_extension(PLATFORM_FILE_EXTENSION_BPF);
}
ProgramPath::Native => {
//println!("Native");
path.pop();
path.pop();
path.pop();
path.push("deps");
path.push(PLATFORM_FILE_PREFIX_NATIVE.to_string() + name);
path.set_extension(PLATFORM_FILE_EXTENSION_NATIVE);
}
}
//println!("Path: {:?}", path);
path
let pathbuf = {
let current_exe = env::current_exe().unwrap();
PathBuf::from(current_exe.parent().unwrap())
};
pathbuf.join(match self {
ProgramPath::Bpf => PathBuf::from(PLATFORM_FILE_PREFIX_BPF.to_string() + name)
.with_extension(PLATFORM_FILE_EXTENSION_BPF),
ProgramPath::Native => PathBuf::from(PLATFORM_FILE_PREFIX_NATIVE.to_string() + name)
.with_extension(PLATFORM_FILE_EXTENSION_NATIVE),
})
}
}