mirror of
https://gitlab.com/gabmus/envision.git
synced 2025-08-03 06:38:52 +00:00
fix: take into account the possibility of library path being lib64 for active runtime
This commit is contained in:
parent
6a231f8c09
commit
e956e3c499
1 changed files with 66 additions and 21 deletions
|
@ -104,23 +104,58 @@ pub fn set_current_active_runtime_to_steam() -> Result<(), ()> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build_profile_active_runtime(profile: &Profile) -> ActiveRuntime {
|
pub fn build_profile_active_runtime(profile: &Profile) -> ActiveRuntime {
|
||||||
|
let build_oxr_so_path = |lib64: bool| {
|
||||||
|
format!(
|
||||||
|
"{prefix}/{libdir}/libopenxr_{xrservice}.so",
|
||||||
|
prefix = profile.prefix,
|
||||||
|
xrservice = match profile.xrservice_type {
|
||||||
|
XRServiceType::Monado => "monado",
|
||||||
|
XRServiceType::Wivrn => "wivrn",
|
||||||
|
},
|
||||||
|
libdir = match lib64 {
|
||||||
|
true => "lib64",
|
||||||
|
false => "lib",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut oxr_so = build_oxr_so_path(false);
|
||||||
|
|
||||||
|
if !Path::new(&oxr_so).is_file() {
|
||||||
|
let alt = build_oxr_so_path(true);
|
||||||
|
if Path::new(&alt).is_file() {
|
||||||
|
oxr_so = alt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ActiveRuntime {
|
ActiveRuntime {
|
||||||
file_format_version: "1.0.0".into(),
|
file_format_version: "1.0.0".into(),
|
||||||
runtime: ActiveRuntimeInnerRuntime {
|
runtime: ActiveRuntimeInnerRuntime {
|
||||||
name: None,
|
name: None,
|
||||||
valve_runtime_is_steamvr: None,
|
valve_runtime_is_steamvr: None,
|
||||||
library_path: format!(
|
library_path: oxr_so,
|
||||||
"{prefix}/lib/libopenxr_{xrservice}.so",
|
|
||||||
prefix = profile.prefix,
|
|
||||||
xrservice = match profile.xrservice_type {
|
|
||||||
XRServiceType::Monado => "monado",
|
|
||||||
XRServiceType::Wivrn => "wivrn",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// for system installs
|
||||||
|
fn relativize_active_runtime_lib_path(ar: &ActiveRuntime, dest: &str) -> ActiveRuntime {
|
||||||
|
let mut res = ar.clone();
|
||||||
|
let path = Path::new(dest);
|
||||||
|
let mut rel_chain = path
|
||||||
|
.components()
|
||||||
|
.map(|_| String::from(".."))
|
||||||
|
.collect::<Vec<String>>();
|
||||||
|
rel_chain.pop();
|
||||||
|
rel_chain.pop();
|
||||||
|
res.runtime.library_path = format!(
|
||||||
|
"{rels}{fullpath}",
|
||||||
|
rels = rel_chain.join("/"),
|
||||||
|
fullpath = ar.runtime.library_path
|
||||||
|
);
|
||||||
|
res
|
||||||
|
}
|
||||||
|
|
||||||
pub fn set_current_active_runtime_to_profile(profile: &Profile) -> Result<(), ()> {
|
pub fn set_current_active_runtime_to_profile(profile: &Profile) -> Result<(), ()> {
|
||||||
let dest = get_active_runtime_json_path();
|
let dest = get_active_runtime_json_path();
|
||||||
checkerr!(set_file_readonly(&dest, false));
|
checkerr!(set_file_readonly(&dest, false));
|
||||||
|
@ -129,17 +164,7 @@ pub fn set_current_active_runtime_to_profile(profile: &Profile) -> Result<(), ()
|
||||||
let mut ar = build_profile_active_runtime(profile);
|
let mut ar = build_profile_active_runtime(profile);
|
||||||
// hack: relativize libopenxr_monado.so path for system installs
|
// hack: relativize libopenxr_monado.so path for system installs
|
||||||
if pfx == SYSTEM_PREFIX {
|
if pfx == SYSTEM_PREFIX {
|
||||||
let path = Path::new(&dest);
|
ar = relativize_active_runtime_lib_path(&ar, &dest);
|
||||||
let mut rel_chain = path
|
|
||||||
.components()
|
|
||||||
.map(|_| String::from(".."))
|
|
||||||
.collect::<Vec<String>>();
|
|
||||||
rel_chain.pop();
|
|
||||||
rel_chain.pop();
|
|
||||||
ar.runtime.library_path = format!(
|
|
||||||
"{rels}/usr/lib/libopenxr_monado.so",
|
|
||||||
rels = rel_chain.join("/")
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
checkerr!(dump_current_active_runtime(&ar));
|
checkerr!(dump_current_active_runtime(&ar));
|
||||||
checkerr!(set_file_readonly(&dest, true));
|
checkerr!(set_file_readonly(&dest, true));
|
||||||
|
@ -149,8 +174,8 @@ pub fn set_current_active_runtime_to_profile(profile: &Profile) -> Result<(), ()
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::{
|
use super::{
|
||||||
dump_active_runtime_to_path, get_active_runtime_from_path, ActiveRuntime,
|
dump_active_runtime_to_path, get_active_runtime_from_path,
|
||||||
ActiveRuntimeInnerRuntime,
|
relativize_active_runtime_lib_path, ActiveRuntime, ActiveRuntimeInnerRuntime,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -181,4 +206,24 @@ mod tests {
|
||||||
dump_active_runtime_to_path(&ar, &"./target/testout/active_runtime.json.steamvr".into())
|
dump_active_runtime_to_path(&ar, &"./target/testout/active_runtime.json.steamvr".into())
|
||||||
.expect("could not dump active runtime to path");
|
.expect("could not dump active runtime to path");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn can_relativize_path() {
|
||||||
|
let ar = ActiveRuntime {
|
||||||
|
file_format_version: "1.0.0".into(),
|
||||||
|
runtime: ActiveRuntimeInnerRuntime {
|
||||||
|
valve_runtime_is_steamvr: None,
|
||||||
|
library_path: "/usr/lib64/libopenxr_monado.so".into(),
|
||||||
|
name: None,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
let relativized = relativize_active_runtime_lib_path(
|
||||||
|
&ar,
|
||||||
|
"/home/user/.config/openxr/1/active_runtime.json",
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
relativized.runtime.library_path,
|
||||||
|
"../../../../../usr/lib64/libopenxr_monado.so"
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue