init: Turn default dependencies into regular dependencies at load time

This commit is contained in:
bjorn3
2026-04-05 14:30:07 +02:00
parent 6056059e49
commit 57d74e8e17
2 changed files with 32 additions and 12 deletions
+21 -1
View File
@@ -10,6 +10,7 @@ use crate::service::Service;
pub struct UnitStore {
pub config_dirs: Vec<PathBuf>,
units: BTreeMap<UnitId, Unit>,
runtime_target: Option<UnitId>,
}
impl UnitStore {
@@ -17,9 +18,16 @@ impl UnitStore {
UnitStore {
config_dirs: vec![],
units: BTreeMap::new(),
runtime_target: None,
}
}
pub fn set_runtime_target(&mut self, unit_id: UnitId) {
assert!(self.runtime_target.is_none());
assert!(self.units.contains_key(&unit_id));
self.runtime_target = Some(unit_id);
}
fn load_single_unit(&mut self, unit_id: UnitId, errors: &mut Vec<String>) -> Option<UnitId> {
let (filename, instance) = if let Some((base_service, rest)) = unit_id.0.split_once('@') {
let Some((instance, ext)) = rest.rsplit_once('.') else {
@@ -42,13 +50,25 @@ impl UnitStore {
return None;
};
let unit = match Unit::from_file(unit_id.clone(), &path, instance, errors) {
let mut unit = match Unit::from_file(unit_id.clone(), &path, instance, errors) {
Ok(unit) => unit,
Err(err) => {
errors.push(format!("{}: {err}", path.display()));
return None;
}
};
if unit.info.default_dependencies {
if let Some(runtime_target) = self.runtime_target.clone() {
unit.info.requires_weak.push(runtime_target);
} else {
errors.push(format!(
"{}: dependency of the runtime target must have default dependencies disabled",
path.display(),
));
}
}
self.units.insert(unit_id.clone(), unit);
Some(unit_id)