Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelog.d/+env-scrub-policy.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
The Bash program clears install-location variables from `scrub_names`,
the same list as `share/env-scrub.json` and the Zig program's
`install_vars`.
24 changes: 24 additions & 0 deletions docs/orgmode/reference/env-scrub.org
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#+title: Install variables cleared for a child

=share/env-scrub.json= is a JSON array of the install-location names a child command must not inherit.
The Bash program keeps that array as =scrub_names=, in the same order.
=clear_install_environment= unsets every name in it before a build.
=eb-local env= prints the same names, in four =unset= lines, in that order.
The Zig program names the same list as =install_vars=.

| Name |
|-------------------------------------|
| =EESSI_CVMFS_INSTALL= |
| =EESSI_SITE_INSTALL= |
| =EESSI_USER_INSTALL= |
| =EESSI_PROJECT_INSTALL= |
| =EESSI_SITE_SOFTWARE_PREFIX= |
| =EESSI_SOFTWARE_SUBDIR_OVERRIDE= |
| =EESSI_ACCELERATOR_TARGET_OVERRIDE= |
| =EESSI_OVERRIDE_GPU_CHECK= |
| =EASYBUILD_INSTALLPATH= |
| =EASYBUILD_INSTALLPATH_SOFTWARE= |
| =EASYBUILD_INSTALLPATH_MODULES= |
| =EASYBUILD_PREFIX= |

[[file:environment.org][Environment variables]] says what each name selects.
1 change: 1 addition & 0 deletions docs/orgmode/reference/index.org
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ configuration
recipe-overlay
readiness
environment
env-scrub
refusals
api
```
Expand Down
26 changes: 26 additions & 0 deletions docs/reference/env-scrub.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!-- Generated from docs/orgmode/reference/env-scrub.org by docs/export.el; edit that file. -->

# Install variables cleared for a child

`share/env-scrub.json` is a JSON array of the install-location names a child command must not inherit.
The Bash program keeps that array as `scrub_names`, in the same order.
`clear_install_environment` unsets every name in it before a build.
`eb-local env` prints the same names, in four `unset` lines, in that order.
The Zig program names the same list as `install_vars`.

| Name |
|---|
| `EESSI_CVMFS_INSTALL` |
| `EESSI_SITE_INSTALL` |
| `EESSI_USER_INSTALL` |
| `EESSI_PROJECT_INSTALL` |
| `EESSI_SITE_SOFTWARE_PREFIX` |
| `EESSI_SOFTWARE_SUBDIR_OVERRIDE` |
| `EESSI_ACCELERATOR_TARGET_OVERRIDE` |
| `EESSI_OVERRIDE_GPU_CHECK` |
| `EASYBUILD_INSTALLPATH` |
| `EASYBUILD_INSTALLPATH_SOFTWARE` |
| `EASYBUILD_INSTALLPATH_MODULES` |
| `EASYBUILD_PREFIX` |

[Environment variables](environment.md) says what each name selects.
1 change: 1 addition & 0 deletions docs/reference/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ configuration
recipe-overlay
readiness
environment
env-scrub
refusals
api
```
33 changes: 24 additions & 9 deletions eb-local
Original file line number Diff line number Diff line change
Expand Up @@ -302,22 +302,37 @@ case "${EB_LOCAL_TRASH:-}" in
*) die "EB_LOCAL_TRASH is auto, rtrash or none" ;;
esac

# The install-location names a child must not inherit. The same names, in
# this order, are share/env-scrub.json and the Zig program's install_vars.
scrub_names=(
EESSI_CVMFS_INSTALL
EESSI_SITE_INSTALL
EESSI_USER_INSTALL
EESSI_PROJECT_INSTALL
EESSI_SITE_SOFTWARE_PREFIX
EESSI_SOFTWARE_SUBDIR_OVERRIDE
EESSI_ACCELERATOR_TARGET_OVERRIDE
EESSI_OVERRIDE_GPU_CHECK
EASYBUILD_INSTALLPATH
EASYBUILD_INSTALLPATH_SOFTWARE
EASYBUILD_INSTALLPATH_MODULES
EASYBUILD_PREFIX
)

clear_install_environment() {
unset EESSI_CVMFS_INSTALL EESSI_SITE_INSTALL EESSI_USER_INSTALL EESSI_PROJECT_INSTALL
unset EESSI_SITE_SOFTWARE_PREFIX
unset EESSI_SOFTWARE_SUBDIR_OVERRIDE EESSI_ACCELERATOR_TARGET_OVERRIDE EESSI_OVERRIDE_GPU_CHECK
unset EASYBUILD_INSTALLPATH EASYBUILD_INSTALLPATH_SOFTWARE EASYBUILD_INSTALLPATH_MODULES EASYBUILD_PREFIX
[ "${#scrub_names[@]}" -eq 12 ] || die "the install-location list has ${#scrub_names[@]} names"
unset "${scrub_names[@]}"
}

# The lines env and dev print. Every value is quoted with %q, and module names
# are checked above, so the output means the same whatever the input.
print_environment() {
printf 'module unload %q >/dev/null 2>&1 || true\n' "$extend_module"
printf '%s\n' \
'unset EESSI_CVMFS_INSTALL EESSI_SITE_INSTALL EESSI_USER_INSTALL EESSI_PROJECT_INSTALL' \
'unset EESSI_SITE_SOFTWARE_PREFIX' \
'unset EESSI_SOFTWARE_SUBDIR_OVERRIDE EESSI_ACCELERATOR_TARGET_OVERRIDE EESSI_OVERRIDE_GPU_CHECK' \
'unset EASYBUILD_INSTALLPATH EASYBUILD_INSTALLPATH_SOFTWARE EASYBUILD_INSTALLPATH_MODULES EASYBUILD_PREFIX'
[ "${#scrub_names[@]}" -eq 12 ] || die "the install-location list has ${#scrub_names[@]} names"
printf 'unset %s %s %s %s\n' "${scrub_names[@]:0:4}"
printf 'unset %s\n' "${scrub_names[4]}"
printf 'unset %s %s %s\n' "${scrub_names[@]:5:3}"
printf 'unset %s %s %s %s\n' "${scrub_names[@]:8:4}"
if [ "$mode" = project ]; then
printf 'export EESSI_PROJECT_INSTALL=%q\n' "$prefix"
else
Expand Down
14 changes: 14 additions & 0 deletions share/env-scrub.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[
"EESSI_CVMFS_INSTALL",
"EESSI_SITE_INSTALL",
"EESSI_USER_INSTALL",
"EESSI_PROJECT_INSTALL",
"EESSI_SITE_SOFTWARE_PREFIX",
"EESSI_SOFTWARE_SUBDIR_OVERRIDE",
"EESSI_ACCELERATOR_TARGET_OVERRIDE",
"EESSI_OVERRIDE_GPU_CHECK",
"EASYBUILD_INSTALLPATH",
"EASYBUILD_INSTALLPATH_SOFTWARE",
"EASYBUILD_INSTALLPATH_MODULES",
"EASYBUILD_PREFIX"
]
60 changes: 60 additions & 0 deletions tests/test_env_scrub_parity.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/usr/bin/env python3
"""The shared install-location list is one list in three places.

share/env-scrub.json is the copy of zig-common's src/env-scrub.json.
The Bash program's scrub_names and the Zig program's install_vars name
the same names in the same order. The sha256 is the file's own: a copy
that drifts from zig-common fails here.
"""
from pathlib import Path
import hashlib
import json
import re
import unittest

ROOT = Path(__file__).resolve().parents[1]
# zig-common src/env-scrub.json, the list childClearNames reads.
POLICY_SHA256 = "07ff930b0a4064619dc9ee7b982aa27f33593566bced1c856a5ad376d6ef4d20"


def script_names(text):
body = re.search(r"^scrub_names=\((.*?)\n\)", text, re.S | re.M)
if body is None:
raise AssertionError("eb-local has no scrub_names array")
return re.findall(r"[A-Z][A-Z0-9_]*", body.group(1))


def zig_names(text):
body = re.search(r"const install_vars = \[_\]\[\]const u8\{(.*?)\};", text, re.S)
if body is None:
raise AssertionError("src/main.zig has no install_vars")
return re.findall(r'"([A-Z0-9_]+)"', body.group(1))


class EnvScrubParity(unittest.TestCase):
def test_the_shell_the_zig_program_and_the_file_name_one_list(self):
raw = (ROOT / "share" / "env-scrub.json").read_bytes()
self.assertEqual(hashlib.sha256(raw).hexdigest(), POLICY_SHA256)
policy = json.loads(raw)
self.assertIsInstance(policy, list)
script = (ROOT / "eb-local").read_text()
self.assertEqual(script_names(script), policy)
self.assertEqual(zig_names((ROOT / "src" / "main.zig").read_text()), policy)
# The four unset lines eb-local env has always printed, built from
# the one array: four names, one name, three names, four names.
self.assertIn("printf 'unset %s %s %s %s\\n' \"${scrub_names[@]:0:4}\"", script)
self.assertIn("printf 'unset %s\\n' \"${scrub_names[4]}\"", script)
self.assertIn("printf 'unset %s %s %s\\n' \"${scrub_names[@]:5:3}\"", script)
self.assertIn("printf 'unset %s %s %s %s\\n' \"${scrub_names[@]:8:4}\"", script)
lines = [
"unset " + " ".join(policy[0:4]),
"unset " + policy[4],
"unset " + " ".join(policy[5:8]),
"unset " + " ".join(policy[8:12]),
]
self.assertEqual(lines, [
"unset EESSI_CVMFS_INSTALL EESSI_SITE_INSTALL EESSI_USER_INSTALL EESSI_PROJECT_INSTALL",
"unset EESSI_SITE_SOFTWARE_PREFIX",
"unset EESSI_SOFTWARE_SUBDIR_OVERRIDE EESSI_ACCELERATOR_TARGET_OVERRIDE EESSI_OVERRIDE_GPU_CHECK",
"unset EASYBUILD_INSTALLPATH EASYBUILD_INSTALLPATH_SOFTWARE EASYBUILD_INSTALLPATH_MODULES EASYBUILD_PREFIX",
])
Loading