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
2 changes: 2 additions & 0 deletions changelog.d/+env-scrub-policy.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
`env_scrub.childClearNames` returns the install-location names in
`src/env-scrub.json`, in the order `eb-local env` prints them.
27 changes: 27 additions & 0 deletions docs/orgmode/reference/env-scrub.org
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#+TITLE: Variables cleared for a child
#+OPTIONS: toc:nil todo:nil num:nil author:nil title:nil
#+STARTUP: content

* Variables cleared for a child

=src/env-scrub.json= is a JSON array of environment names.
[[zig:zig_common.env_scrub.childClearNames]] returns them in the order the file has them, which is the order =eb-local env= prints its =unset= lines.
A child command clears each name, so an install location inherited from the parent shell does not decide where the child writes.

| 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= |

eb-staged-rebuild also clears =EASYBUILD_REMOVE_GHOST_INSTALL_DIRS=, and =EASYBUILD_BUILDPATH= when the build path is private.
Those two are that tool's own.
1 change: 1 addition & 0 deletions docs/orgmode/reference/index.org
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ Each page states facts in the order the thing itself has them.
cli-conventions
compatibility
api
env-scrub
#+end_export
14 changes: 14 additions & 0 deletions src/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"
]
83 changes: 83 additions & 0 deletions src/env_scrub.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
//! Install-location names a child command clears before it runs.
//!
//! `env-scrub.json` is the list. The names are the ones `eb-local env`
//! prints, in that order: the European Environment for Scientific Software
//! Installations (EESSI) install locations, the overrides that move a stack,
//! and EasyBuild's install paths. eb-staged-rebuild also clears
//! `EASYBUILD_REMOVE_GHOST_INSTALL_DIRS`, and `EASYBUILD_BUILDPATH` when the
//! build path is private. Those two stay with that tool.
const std = @import("std");
const env = @import("env.zig");

const source = @embedFile("env-scrub.json");

fn countQuoted(comptime text: []const u8) usize {
@setEvalBranchQuota(100_000);
var n: usize = 0;
var i: usize = 0;
while (i < text.len) : (i += 1) {
if (text[i] != '"') continue;
n += 1;
i += 1;
while (i < text.len and text[i] != '"') : (i += 1) {}
}
return n;
}

fn quoted(comptime text: []const u8) [countQuoted(text)][]const u8 {
@setEvalBranchQuota(100_000);
var out: [countQuoted(text)][]const u8 = undefined;
var n: usize = 0;
var i: usize = 0;
while (i < text.len) : (i += 1) {
if (text[i] != '"') continue;
const start = i + 1;
i += 1;
while (i < text.len and text[i] != '"') : (i += 1) {}
out[n] = text[start..i];
n += 1;
}
return out;
}

const names = quoted(source);

comptime {
@setEvalBranchQuota(100_000);
if (names.len == 0) @compileError("env-scrub.json has no names");
for (names, 0..) |name, i| {
if (std.mem.indexOfScalar(u8, name, '\\') != null) @compileError("env-scrub.json: " ++ name);
if (!env.validName(name)) @compileError("env-scrub.json: " ++ name);
for (names[i + 1 ..]) |later| {
if (std.mem.eql(u8, name, later)) @compileError("env-scrub.json repeats " ++ name);
}
}
}

/// The names in `env-scrub.json`, in file order.
pub const child_clear: []const []const u8 = &names;

/// The names in `env-scrub.json`, in file order.
pub fn childClearNames() []const []const u8 {
return child_clear;
}

test "childClearNames is the install-location list, in env's print order" {
const expect = [_][]const u8{
"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",
};
const got = childClearNames();
try std.testing.expectEqual(expect.len, got.len);
for (expect, got) |want, have| try std.testing.expectEqualStrings(want, have);
}
2 changes: 2 additions & 0 deletions src/root.zig
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ pub const logs = @import("logs.zig");
pub const cli = @import("cli.zig");
/// The environment as the C library sees it.
pub const env = @import("env.zig");
/// Install-location names a child command clears.
pub const env_scrub = @import("env_scrub.zig");
/// Private state files in a directory other users may write.
pub const state = @import("state.zig");
/// JSON as the Python tools these programs replace read and wrote it.
Expand Down
Loading