Preserve genuine path duplicates in source-sh/sh-to-mod output#652
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
source-sh/sh-to-modto produce asetenvcommand instead of a mismatchedprepend-path/append-pathpair when a path-like variable change needs both a prepend and an append expressed with different delimiter characters.sh-to-modprepends or appends, and set--duplicateson the generatedprepend-path/append-pathcommand 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 bypath_entry_reorder.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.exppass, stable across repeated runsmake testsuite: no regressions (same pre-existing/unrelated failures as before)make testlintclean