Bug 2842 - Generated bakeSetEnv.sh needs empty path detection
Generated bakeSetEnv.sh needs empty path detection
Status: RESOLVED FIXED
Product: bake
Classification: Unclassified
Component: bake
unspecified
All All
: P3 normal
Assigned To: Daniel Camara
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2018-01-03 15:07 UTC by Peter Barnes
Modified: 2018-01-04 17:16 UTC (History)
2 users (show)

See Also:


Attachments
Suggested patch (1.34 KB, patch)
2018-01-03 15:39 UTC, Peter Barnes
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Peter Barnes 2018-01-03 15:07:37 UTC
The generated bakeSetEnv.sh doesn't check if path variables are empty before appending.  This causes a bash error when sourcing the file, and the variables aren't set.

For example, on my Mac, LD_LIBRARY_PATH doesn't normally exist.  After sourcing bakeSetEvn.sh, it still doesn't exist...

Suggested fix could look like:

if [ -z "${LD_LIBRARY_PATH:-}" ]; then
    export LD_LIBRARY_PATH=...
else
    export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:..."
fi

A little more cryptic, this also works:

export LD_LIBRARY_PATH="${LD_LIBRARY_PATH:+${LD_LIBRARY_PATH}:}..."

The fix should be made to each variable in the script.

The actual export statements are generated by ModuleEnvironment.py, in the add_onPath function around line 414.

[Note:  encapsulating the rhs of shell variable assignment in double quotes is preferred, in case it contains ' ' spaces...]
Comment 1 Peter Barnes 2018-01-03 15:10:48 UTC
Clarify:  error is caused by expansion of an unset environment variable
Comment 2 Peter Barnes 2018-01-03 15:39:17 UTC
Created attachment 2987 [details]
Suggested patch

Suggested patch.

This patch also detects if the file is being sourced correctly, and if not prints the error message and exits.
Comment 3 Tom Henderson 2018-01-04 17:16:13 UTC
fixed in changeset 385:d64a4a547639, thanks!