feat: split cmake var into name and value when it contains =
Some checks failed
/ cargo-fmtcheck (push) Has been cancelled
/ cargo-clippy (push) Has been cancelled
/ cargo-test (push) Has been cancelled
/ appimage (push) Has been cancelled

This commit is contained in:
Gabriele Musco 2024-11-18 13:39:11 +01:00
commit af5c57f0f8
No known key found for this signature in database
GPG key ID: 1068D795C80E51DE

View file

@ -48,6 +48,21 @@ pub struct ProfileEditorInit {
pub profile: Profile,
}
/// This parses a var (either env var or cmake var) and if it contains
/// a '=' char, it assumes it's key and value, otherwise it's just going to
/// be the key and the value is gonna be an empty string
fn parse_var(input: &str) -> (String, String) {
if input.contains('=') {
let mut sp = input.split('=');
(
sp.next().unwrap().to_string(),
sp.next().unwrap().to_string(),
)
} else {
(input.to_string(), "".to_string())
}
}
#[relm4::component(pub)]
impl SimpleComponent for ProfileEditor {
type Init = ProfileEditorInit;
@ -428,33 +443,23 @@ impl SimpleComponent for ProfileEditor {
}
Self::Input::AddEnvVar(var) => {
let mut prof = self.profile.borrow_mut();
if !prof.environment.contains_key(&var) {
let (name, value) = if var.contains('=') {
let mut sp = var.split('=');
(
sp.next().unwrap().to_string(),
sp.next().unwrap().to_string(),
)
} else {
(var, "".to_string())
};
let (name, value) = parse_var(&var);
if !prof.environment.contains_key(&name) {
prof.environment.insert(name.clone(), value.clone());
self.env_rows
.guard()
.push_back(EnvVarModelInit { name, value });
}
}
Self::Input::AddXrServiceCmakeFlag(name) => {
Self::Input::AddXrServiceCmakeFlag(var) => {
let mut prof = self.profile.borrow_mut();
let (name, value) = parse_var(&var);
if !prof.xrservice_cmake_flags.contains_key(&name) {
prof.xrservice_cmake_flags
.insert(name.clone(), "".to_string());
.insert(name.clone(), value.clone());
self.xrservice_cmake_flags_rows
.guard()
.push_back(EnvVarModelInit {
name,
value: "".to_string(),
});
.push_back(EnvVarModelInit { name, value });
}
}
}