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

View File

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