diff --git a/build/util/src/lib.rs b/build/util/src/lib.rs index ec795e59c..a1bad19d4 100644 --- a/build/util/src/lib.rs +++ b/build/util/src/lib.rs @@ -198,20 +198,31 @@ pub fn task_extern_regions() -> Result> Ok(t) } +/// Pulls the entire config for all tasks +pub fn all_tasks_full_config() +-> Result>> { + toml_from_env::>>( + "HUBRIS_ALL_TASK_CONFIGS", + )? + .ok_or_else(|| anyhow!("HUBRIS_ALL_TASK_CONFIGS is not defined")) +} + /// Pulls the full task configuration block of a different task pub fn other_task_full_config( name: &str, ) -> Result> { - let mut t = toml_from_env::>>( - "HUBRIS_ALL_TASK_CONFIGS", - )? - .ok_or_else(|| anyhow!("HUBRIS_ALL_TASK_CONFIGS is not defined"))?; + let mut t = all_tasks_full_config::()?; let out = t .remove(name) .ok_or_else(|| anyhow!("Could not find {name} in tasks"))?; Ok(out) } +pub fn all_tasks_full_config_toml() +-> Result>> { + all_tasks_full_config() +} + pub fn other_task_full_config_toml( name: &str, ) -> Result> { @@ -325,11 +336,15 @@ pub fn build_notifications() -> Result<()> { write_task_notifications(&mut out, &full_task_config.notifications)?; - for task in env_var("HUBRIS_TASKS") - .expect("missing HUBRIS_TASKS") - .split(',') - { - let full_task_config = other_task_full_config_toml(task)?; + // Rather than re-parse the toml on every task iter, we just get the full + // task toml, and pluck out each task as we need it. + let all_task_configs = all_tasks_full_config_toml()?; + let all_tasks = env_var("HUBRIS_TASKS").expect("missing HUBRIS_TASKS"); + + for task in all_tasks.split(',') { + let full_task_config = all_task_configs + .get(task) + .ok_or_else(|| anyhow!("Could not find {task} in tasks"))?; writeln!(&mut out, "pub mod {task} {{")?; write_task_notifications(&mut out, &full_task_config.notifications)?; writeln!(&mut out, "}}")?;