mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-15 08:30:02 +00:00
add app deduplication code
this ensures that a given app is not included more than once significantly, this allows for an app to be in the default list and also selectable from the menu and you don't end up with two copies of it in the binary.
This commit is contained in:
parent
dd144b9446
commit
0bcd861d9c
2 changed files with 38 additions and 0 deletions
|
|
@ -461,6 +461,36 @@ impl Builder {
|
|||
self
|
||||
}
|
||||
|
||||
/// Searches through the services and apps name spaces and removes duplicates
|
||||
pub fn deduplicate_processes(&mut self) {
|
||||
let mut pid_names = Vec::<String>::new();
|
||||
let mut dup_indices = Vec::<(usize, usize)>::new();
|
||||
{
|
||||
// ensure the borrows that compose name_spaces go out of scope after searching for duplicates
|
||||
let name_spaces = [&self.services, &self.apps];
|
||||
for (ns, name_space) in name_spaces.iter().enumerate() {
|
||||
for (i, service) in name_space.iter().enumerate() {
|
||||
if let Some(name) = &service.name() {
|
||||
if pid_names.contains(&name) {
|
||||
dup_indices.push((ns, i));
|
||||
} else {
|
||||
pid_names.push(name.to_owned());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if dup_indices.len() > 0 {
|
||||
println!("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
|
||||
for (dupe_ns, dupe_i) in dup_indices {
|
||||
let removed =
|
||||
if dupe_ns == 0 { self.services.remove(dupe_i) } else { self.apps.remove(dupe_i) };
|
||||
println!("WARNING: Found duplicate package name, removing later instances of {:?}", removed);
|
||||
}
|
||||
println!("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
|
||||
}
|
||||
}
|
||||
|
||||
/// add a feature to be passed on to services
|
||||
pub fn add_feature(&mut self, feature: &str) -> &mut Builder {
|
||||
self.features.push(feature.into());
|
||||
|
|
|
|||
|
|
@ -833,6 +833,14 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
// clean up any duplicates - this is an artifact of wanting to include dabao-console
|
||||
// as a "default app" to make behavior more intuitive for beginners trying out dabao,
|
||||
// but also wanting to list it in the UI as an app so that developers are /aware/ of
|
||||
// dabao-console as an app they can modify. Simply hiding it by sticking it in the services
|
||||
// directory makes in hard to discover. Maybe this will be changed to handle it entirely
|
||||
// at the UI layer but anyways - this avoids accidental duplicate processes which is a good thing
|
||||
// in general.
|
||||
builder.deduplicate_processes();
|
||||
builder.build()?;
|
||||
|
||||
// the intent of this call is to check that crates we are sourcing from crates.io
|
||||
|
|
|
|||
Loading…
Reference in a new issue