diff --git a/xtask/src/builder.rs b/xtask/src/builder.rs index f6d92aa98..d791b4196 100644 --- a/xtask/src/builder.rs +++ b/xtask/src/builder.rs @@ -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::::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()); diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 0e78416f0..8f50fa5a1 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -833,6 +833,14 @@ fn main() -> Result<(), Box> { 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