Skip to content

Preserve genuine path duplicates in source-sh/sh-to-mod output#652

Merged
xdelaruelle merged 5 commits into
envmodules:mainfrom
xdelaruelle:sh-to-mod-duplicates
Jul 24, 2026
Merged

Preserve genuine path duplicates in source-sh/sh-to-mod output#652
xdelaruelle merged 5 commits into
envmodules:mainfrom
xdelaruelle:sh-to-mod-duplicates

Conversation

@xdelaruelle

Copy link
Copy Markdown
Collaborator

Summary

  • Fix source-sh/sh-to-mod to produce a setenv command instead of a mismatched prepend-path/append-path pair when a path-like variable change needs both a prepend and an append expressed with different delimiter characters.
  • No longer de-duplicate a directory found several times in the entries sh-to-mod prepends or appends, and set --duplicates on the generated prepend-path/append-path command whenever an added entry is already in the prior value, repeated within its own list, or present in both lists — so it isn't silently absorbed by these commands' default de-duplication, nor relocated by path_entry_reorder.
  • Simplify the diff-to-modulefile-commands loop in sh-to-mod (no behavior change).

Test plan

  • 70-maint/310-sh-to-mod.exp, 70-maint/311-eval-sh-to-mod.exp, 50-cmds/400-source-sh.exp pass, stable across repeated runs
  • Full make test suite: no regressions (same pre-existing/unrelated failures as before)
  • make testlint clean

When a path-like environment variable change requires both a prepended
and an appended part expressed with a different delimiter character,
describing it as a prepend-path and an append-path command does not
produce a consistent value: each command independently splits and
de-duplicates the full variable value using its own delimiter. A
setenv command directly setting the resulting value is generated
instead in this situation.

Signed-off-by: Xavier Delaruelle <xavier.delaruelle@cea.fr>
Wrap the test bodies of 310-sh-to-mod.exp, 311-eval-sh-to-mod.exp and
400-source-sh.exp in a loop over path_entry_reorder 0 and 1, so both
configurations get full coverage instead of only the default one.

Each loop iteration resets the environment and loaded module state
accumulated by the previous iteration, so both runs start from the
same clean baseline. A few path-like values used to test literal
curly brace handling needed extra backslash escaping so the whole
test body can be parsed as a single Tcl script argument by foreach.

Signed-off-by: Xavier Delaruelle <xavier.delaruelle@cea.fr>
A path entry added by a prepend-path or append-path command generated
by source-sh/sh-to-mod could be silently absorbed or relocated by
these commands' default de-duplication behavior, or by the
path_entry_reorder configuration option, when this entry was already
part of the variable value prior script evaluation, appeared several
times in the entries being prepended or appended, or appeared in both
the prepended and appended entries. Such an entry is genuinely meant
to end up at this specific position in the resulting value, so it is
no longer de-duplicated away, and the --duplicates option is now added
to the corresponding command in these situations.

Signed-off-by: Xavier Delaruelle <xavier.delaruelle@cea.fr>
The prepend and append branches of the environment variable diff loop
in the sh-to-mod procedure had grown into near-duplicate blocks of
code for splitting the directory list to add and deciding whether the
--duplicates option is needed on the resulting command. Factor this
logic out into two helper procedures, shared by both branches: one
building the directory list to add, the other assembling the
resulting prepend-path or append-path command.

No behavior change.

Signed-off-by: Xavier Delaruelle <xavier.delaruelle@cea.fr>
Merge the two prepend/append branches of the environment variable diff
loop in the sh-to-mod procedure into a single flow: both branches now
share one directory list, seeded with the de-duplicated prior value
then extended with the raw (non-de-duplicated) entries to prepend and
to append, and one pass decides whether --duplicates is needed on the
resulting commands. This relies on a new helper procedure checking
whether a list holds a repeated element.

Seeding with the de-duplicated prior value, rather than merging it in
afterwards, avoids a repeated entry already found in the prior value
on its own from masking a genuine new duplicate.

No behavior change.

Signed-off-by: Xavier Delaruelle <xavier.delaruelle@cea.fr>
@xdelaruelle
xdelaruelle merged commit f83b0d2 into envmodules:main Jul 24, 2026
19 checks passed
@xdelaruelle
xdelaruelle deleted the sh-to-mod-duplicates branch July 24, 2026 17:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant