From e291c2bb719867a08ebed7ebce1d1523f1d4b18b Mon Sep 17 00:00:00 2001 From: Rohit Goswami Date: Thu, 19 Nov 2026 07:28:41 -0600 Subject: [PATCH] fix: clear configured target override variables Sites can rename the variables that carry a target's CPU and accelerator values with cpu_override_var and accel_override_var. A value the calling shell left in such a custom variable survived into commands of the European Environment for Scientific Software Installations, so a target without cpu_target skipped hardware detection. Every command started by the pipeline, including audit and watch probes, now clears the custom names along with EESSI_SOFTWARE_SUBDIR_OVERRIDE and EESSI_ACCELERATOR_TARGET_OVERRIDE, which the init scripts always read. The regression exports both kinds of name from the parent shell and asserts that neither reaches the build stub. --- ...+eessi-custom-override-isolation.bugfix.md | 2 + docs/orgmode/reference/environment.org | 3 +- docs/orgmode/reference/site-file.org | 2 +- src/audit.rs | 14 ++++- src/resolve.rs | 23 ++++++- src/run.rs | 62 ++++++++++++------- src/watch.rs | 8 +-- tests/run_stubs.rs | 29 +++++++++ 8 files changed, 112 insertions(+), 31 deletions(-) create mode 100644 changelog.d/+eessi-custom-override-isolation.bugfix.md diff --git a/changelog.d/+eessi-custom-override-isolation.bugfix.md b/changelog.d/+eessi-custom-override-isolation.bugfix.md new file mode 100644 index 00000000..088b28a4 --- /dev/null +++ b/changelog.d/+eessi-custom-override-isolation.bugfix.md @@ -0,0 +1,2 @@ +Clear the default and the configured target override variables of the European +Environment for Scientific Software Installations before starting a command. diff --git a/docs/orgmode/reference/environment.org b/docs/orgmode/reference/environment.org index 4b825322..8bb4cc42 100644 --- a/docs/orgmode/reference/environment.org +++ b/docs/orgmode/reference/environment.org @@ -126,7 +126,8 @@ The keys of =[scheduler.env]= come first, and a variable of the table below with For an EESSI command, =eb-pipeline= removes inherited EESSI installation-mode variables and target overrides before setting the values in this table. An unset =cpu_target= or =accel_target= therefore uses EESSI detection instead -of a value left by the calling shell. +of a value left by the calling shell. This clears the default EESSI override +names and a custom =cpu_override_var= or =accel_override_var=. =[licences]= is on when its =enabled= and =enforce= are not =false=. =EESSI= stands for the European Environment for Scientific Software Installations. diff --git a/docs/orgmode/reference/site-file.org b/docs/orgmode/reference/site-file.org index 20a891d5..c064e235 100644 --- a/docs/orgmode/reference/site-file.org +++ b/docs/orgmode/reference/site-file.org @@ -454,7 +454,7 @@ The module wrapper starts when =init= is not empty, =unuse_path= is =true= or =s | =cpu_override_var= | string | =EESSI_SOFTWARE_SUBDIR_OVERRIDE= | The variable that carries the target's =cpu_target=. | | =accel_override_var= | string | =EESSI_ACCELERATOR_TARGET_OVERRIDE= | The variable that carries the target's =accel_target=. | -With the table on, every command also gets =EESSI_SITE_SOFTWARE_PREFIX=, the target's install prefix, and =check= checks the form of each target's =cpu_target= and =accel_target=. Before it starts an EESSI command, =eb-pipeline= removes inherited EESSI target overrides, so an unset target value leaves detection to EESSI. +With the table on, every command also gets =EESSI_SITE_SOFTWARE_PREFIX=, the target's install prefix, and =check= checks the form of each target's =cpu_target= and =accel_target=. Before it starts an EESSI command, =eb-pipeline= removes inherited default and configured =cpu_override_var= and =accel_override_var= names, so an unset target value leaves detection to EESSI. ** =[caches]= diff --git a/src/audit.rs b/src/audit.rs index 21269cab..997965b7 100644 --- a/src/audit.rs +++ b/src/audit.rs @@ -183,7 +183,12 @@ fn probe_target_env( .collect(); let cmd = planner.plan_role_cmd(PHASE, inner)?; let log_path = work.join("probe.log"); - let code = exec_logged(&cmd, &planner.scope.env(), &log_path)?; + let code = exec_logged( + &cmd, + &planner.scope.env(), + &planner.scope.eessi_unset_env(), + &log_path, + )?; let bytes = std::fs::read(&out).unwrap_or_default(); let _ = std::fs::remove_file(&out); if code != 0 || bytes.is_empty() { @@ -245,7 +250,12 @@ fn run_eb_stack(planner: &Planner<'_>, tail: &[String], log_path: &Path) -> Resu let mut argv = vec![Tool::EbStack.bin(planner.scope.site)]; argv.extend(tail.iter().cloned()); let cmd = planner.plan_role_cmd(PHASE, argv)?; - let code = exec_logged(&cmd, &planner.scope.env(), log_path)?; + let code = exec_logged( + &cmd, + &planner.scope.env(), + &planner.scope.eessi_unset_env(), + log_path, + )?; if code != 0 { let exit_code = match code { exit::USAGE => exit::USAGE, diff --git a/src/resolve.rs b/src/resolve.rs index 5b90b5e2..243f262a 100644 --- a/src/resolve.rs +++ b/src/resolve.rs @@ -4,7 +4,7 @@ use crate::exit::Fail; use crate::schema::*; use crate::util::{package_of, split_args}; use serde_json::{json, Value}; -use std::collections::BTreeMap; +use std::collections::{BTreeMap, BTreeSet}; /// A phase role: which launch arguments a command takes from /// `[phase_defaults]` or the target's `phases`. @@ -502,6 +502,27 @@ impl<'a> Scope<'a> { e } + /// EESSI variables removed from a child before its configured environment + /// is applied. + pub fn eessi_unset_env(&self) -> BTreeSet { + let Some(es) = self.site.eessi_on() else { + return BTreeSet::new(); + }; + [ + "EESSI_CVMFS_INSTALL".to_string(), + "EESSI_SITE_INSTALL".to_string(), + "EESSI_PROJECT_INSTALL".to_string(), + "EESSI_USER_INSTALL".to_string(), + "EESSI_ACCELERATOR_INSTALL".to_string(), + "EESSI_SOFTWARE_SUBDIR_OVERRIDE".to_string(), + "EESSI_ACCELERATOR_TARGET_OVERRIDE".to_string(), + es.cpu_override_var.clone(), + es.accel_override_var.clone(), + ] + .into_iter() + .collect() + } + /// Environment added for one build list line. pub fn line_env(&self, easyconfig: &str) -> BTreeMap { let (name, version) = package_of(easyconfig); diff --git a/src/run.rs b/src/run.rs index c9c149fd..c838c461 100644 --- a/src/run.rs +++ b/src/run.rs @@ -228,7 +228,12 @@ struct Exec { /// Run one command to completion with output in a log file. A signal that /// arrives is forwarded to the child once. -fn exec(cmd: &Cmd, base_env: &BTreeMap, log: &Path) -> Result { +fn exec( + cmd: &Cmd, + base_env: &BTreeMap, + unset_env: &BTreeSet, + log: &Path, +) -> Result { if let Some(dir) = log.parent() { std::fs::create_dir_all(dir).map_err(|e| { Fail::new( @@ -247,18 +252,8 @@ fn exec(cmd: &Cmd, base_env: &BTreeMap, log: &Path) -> Result, log: &Path) -> Result, + unset_env: &BTreeSet, log: &Path, ) -> Result { - exec(cmd, base_env, log).map(|e| e.code) + exec(cmd, base_env, unset_env, log).map(|e| e.code) } fn last_json_line(path: &Path) -> Option { @@ -671,9 +667,10 @@ impl State { phase: &str, cmd: &Cmd, env: &BTreeMap, + unset_env: &BTreeSet, log: &Path, ) -> Result { - let ex = exec(cmd, env, log)?; + let ex = exec(cmd, env, unset_env, log)?; *self.spent.entry(phase.to_string()).or_default() += ex.elapsed; Ok(ex) } @@ -687,6 +684,7 @@ pub fn run(planner: &Planner, lines: &[ListLine], opts: &Options<'_>) -> RunResu let site = p.scope.site; let target = p.scope.target.name.clone(); let env = p.scope.env(); + let unset_env = p.scope.eessi_unset_env(); let log_dir = PathBuf::from(p.scope.log_dir()); let mut st = State { res: RunResult { @@ -1000,7 +998,8 @@ pub fn run(planner: &Planner, lines: &[ListLine], opts: &Options<'_>) -> RunResu } Ok(cmd) => { let hashes = resume::hashes_path(&p.scope.log_dir()); - let ex = match st.exec("shard", &cmd, &env, &log_dir.join("order.log")) { + let ex = match st.exec("shard", &cmd, &env, &unset_env, &log_dir.join("order.log")) + { Ok(e) => e, Err(f) => { st.res.message = Some(f.msg); @@ -1104,7 +1103,8 @@ pub fn run(planner: &Planner, lines: &[ListLine], opts: &Options<'_>) -> RunResu &target, &format!("planning {} shards", sh.count), ); - let ex = match st.exec("shard", &cmd, &env, &log_dir.join("shard.log")) { + let ex = match st.exec("shard", &cmd, &env, &unset_env, &log_dir.join("shard.log")) + { Ok(e) => e, Err(f) => { st.res.message = Some(f.msg); @@ -1191,7 +1191,8 @@ pub fn run(planner: &Planner, lines: &[ListLine], opts: &Options<'_>) -> RunResu &target, &format!("planning {count} shards"), ); - let ex = match st.exec("shard", &cmd, &env, &log_dir.join("shard.log")) { + let ex = match st.exec("shard", &cmd, &env, &unset_env, &log_dir.join("shard.log")) + { Ok(e) => e, Err(f) => { st.res.message = Some(f.msg); @@ -1341,6 +1342,7 @@ pub fn run(planner: &Planner, lines: &[ListLine], opts: &Options<'_>) -> RunResu "sources", cmd, &env, + &unset_env, &log_dir.join(format!("offline-planner-{:02}.log", i + 1)), ) { Ok(ex) => ex, @@ -1389,6 +1391,7 @@ pub fn run(planner: &Planner, lines: &[ListLine], opts: &Options<'_>) -> RunResu "sources", &cmd, &env, + &unset_env, &log_dir.join(format!("{s}.fetch.log")), ) { Ok(e) => e, @@ -1545,6 +1548,7 @@ pub fn run(planner: &Planner, lines: &[ListLine], opts: &Options<'_>) -> RunResu "admission", &cmd, &env, + &unset_env, &log_dir.join(format!("admission-{}.{attempt}.log", u.name)), ) { Ok(e) => e, @@ -1672,7 +1676,7 @@ pub fn run(planner: &Planner, lines: &[ListLine], opts: &Options<'_>) -> RunResu log("WARN", "build", &target, &format!("{s}: {w}")); } log("INFO", "build", &target, &format!("{s}: start")); - let ex = match st.exec("build", &cmd, &env, Path::new(&p.log_stdout(s))) { + let ex = match st.exec("build", &cmd, &env, &unset_env, Path::new(&p.log_stdout(s))) { Ok(e) => e, Err(f) => { st.res.message = Some(f.msg); @@ -1740,6 +1744,7 @@ pub fn run(planner: &Planner, lines: &[ListLine], opts: &Options<'_>) -> RunResu "logs", &kc, &env, + &unset_env, &log_dir.join(format!("{s}.keep-logs.log")), ); match kx { @@ -1801,7 +1806,13 @@ pub fn run(planner: &Planner, lines: &[ListLine], opts: &Options<'_>) -> RunResu Ok(Some(cmd)) => { if !st.failed && !st.refused && !st.pending { log("INFO", "checks", &target, "start"); - match st.exec("checks", &cmd, &env, &log_dir.join("checks.log")) { + match st.exec( + "checks", + &cmd, + &env, + &unset_env, + &log_dir.join("checks.log"), + ) { Ok(ex) => { if ex.code == 0 { st.phase("checks", "ok", Some(0), None); @@ -1851,6 +1862,7 @@ pub fn run(planner: &Planner, lines: &[ListLine], opts: &Options<'_>) -> RunResu "verification", cmd, &env, + &unset_env, &log_dir.join(format!("verification-{}.log", index + 1)), ) { Ok(ex) if ex.code == 0 => { @@ -1901,7 +1913,13 @@ pub fn run(planner: &Planner, lines: &[ListLine], opts: &Options<'_>) -> RunResu match p.cache_cmd() { Ok(Some(cmd)) => { log("INFO", "caches", &target, "start"); - match st.exec("caches", &cmd, &env, &log_dir.join("caches.log")) { + match st.exec( + "caches", + &cmd, + &env, + &unset_env, + &log_dir.join("caches.log"), + ) { Ok(ex) => { if ex.code == 0 { st.phase("caches", "ok", Some(0), None); @@ -1975,7 +1993,7 @@ pub fn run(planner: &Planner, lines: &[ListLine], opts: &Options<'_>) -> RunResu p.rotate_cmd(false).ok().flatten().unwrap_or(cmd) } }; - match st.exec("logs", &cmd, &env, &log_dir.join("rotate.log")) { + match st.exec("logs", &cmd, &env, &unset_env, &log_dir.join("rotate.log")) { Ok(ex) => match map_rotate(ex.code) { RotateOutcome::Ok => st.phase("logs", "ok", Some(0), note), RotateOutcome::Locked => { diff --git a/src/watch.rs b/src/watch.rs index e3b52891..57ccaa32 100644 --- a/src/watch.rs +++ b/src/watch.rs @@ -232,7 +232,7 @@ pub fn probe(p: &Planner, work: &Path) -> Result<(Probe, BTreeMap Result