Return L4Re TargetOptions as a Result type instead of panic

If the environment variable L4RE_LIBDIR ist not set an Error will be
returned wrapped in a result type instead of a panic.
This commit is contained in:
Tobias Schaffner 2017-08-22 11:11:30 +02:00
parent beedf4e7d8
commit c60fc4bd58
2 changed files with 6 additions and 6 deletions

View File

@ -26,9 +26,9 @@ fn get_path_or(filename: &str) -> String {
.expect("Couldn't read path from GCC").trim().into()
}
pub fn opts() -> TargetOptions {
let l4re_lib_path = env::var_os("L4RE_LIBDIR").expect("Unable to find L4Re \
library directory: L4RE_LIBDIR not set.").into_string().unwrap();
pub fn opts() -> Result<TargetOptions, String> {
let l4re_lib_path = env::var_os("L4RE_LIBDIR").ok_or("Unable to find L4Re \
library directory: L4RE_LIBDIR not set.")?.into_string().unwrap();
let mut pre_link_args = LinkArgs::new();
pre_link_args.insert(LinkerFlavor::Ld, vec![
format!("-T{}/main_stat.ld", l4re_lib_path),
@ -68,7 +68,7 @@ pub fn opts() -> TargetOptions {
format!("{}/crtn.o", l4re_lib_path),
]);
TargetOptions {
Ok(TargetOptions {
executables: true,
has_elf_tls: false,
exe_allocation_crate: None,
@ -78,5 +78,5 @@ pub fn opts() -> TargetOptions {
post_link_args,
target_family: Some("unix".to_string()),
.. Default::default()
}
})
}

View File

@ -12,7 +12,7 @@ use LinkerFlavor;
use target::{Target, TargetResult};
pub fn target() -> TargetResult {
let mut base = super::l4re_base::opts();
let mut base = super::l4re_base::opts()?;
base.cpu = "x86-64".to_string();
base.max_atomic_width = Some(64);