scripts: remove . from $PATH 1.7
authorJohannes Stezenbach <js@sig21.net>
Thu Jul 29 19:30:37 2010 +0200 (2010-07-29)
branch1.7
changeset 2047ace1d90c9b15
parent 2046 471acb219d77
child 2048 2d3a2b3f4a0c
scripts: remove . from $PATH

Add CT_SanitizePath function which removes entries referring to ., /tmp
and non-existing directories from $PATH, and call it early in the
build script.

If . is in PATH, gcc-4.4.4 build breaks:

[ALL ] checking what assembler to use...
/tmp/build/targets/arm-unknown-linux-uclibcgnueabi/build/gcc-core-static/arm-unknown-linux-uclibcgnueabi/bin/as
...
[ALL ] config.status: creating as

i.e. "as" is supposed to be the arm-unknown-linux-uclibcgnueabi cross assembler,
but config.status creates a local "as" script which is calling the
host assembler.

Signed-off-by: Johannes Stezenbach <js@sig21.net>
[Yann E. MORIN: style fixes + explanations]
Signed-off-by: "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
(transplanted from 20dd8cef1c8adff0aa3e78ae6d7acfbc45ed5a83)
scripts/crosstool-NG.sh.in
scripts/functions
     1.1 --- a/scripts/crosstool-NG.sh.in	Mon Jul 19 23:16:02 2010 +0200
     1.2 +++ b/scripts/crosstool-NG.sh.in	Thu Jul 29 19:30:37 2010 +0200
     1.3 @@ -28,6 +28,9 @@
     1.4  # Overide the locale early, in case we ever translate crosstool-NG messages
     1.5  [ -z "${CT_NO_OVERIDE_LC_MESSAGES}" ] && export LC_ALL=C
     1.6  
     1.7 +# remove . from PATH since it can cause gcc build failures
     1.8 +CT_SanitizePath
     1.9 +
    1.10  # Some sanity checks in the environment and needed tools
    1.11  CT_DoLog INFO "Performing some trivial sanity checks"
    1.12  CT_TestAndAbort "Don't set LD_LIBRARY_PATH. It screws up the build." -n "${LD_LIBRARY_PATH}"
     2.1 --- a/scripts/functions	Mon Jul 19 23:16:02 2010 +0200
     2.2 +++ b/scripts/functions	Thu Jul 29 19:30:37 2010 +0200
     2.3 @@ -137,6 +137,24 @@
     2.4      CT_DoLog ${level:-INFO} "(elapsed: ${elapsed_min}:${elapsed_sec}.${elapsed_csec})"
     2.5  }
     2.6  
     2.7 +# Remove entries referring to ., /tmp and non-existing directories from $PATH
     2.8 +# Usage: CT_SanitizePath
     2.9 +CT_SanitizePath() {
    2.10 +    local new
    2.11 +    local tmp
    2.12 +    local IFS=:
    2.13 +    for p in $PATH; do
    2.14 +        # Replace any occurence of . with $(pwd -P)
    2.15 +        # Use /tmp as a default if the directory is non-existent
    2.16 +        # Do not add /tmp in the PATH
    2.17 +        tmp="$( cd /tmp; cd "${p}" 2>/dev/null || true; pwd -P )"
    2.18 +        if [ "${tmp}" != "/tmp" ]; then
    2.19 +            new="${new}${new:+:}${p}"
    2.20 +        fi
    2.21 +    done
    2.22 +    PATH="${new}"
    2.23 +}
    2.24 +
    2.25  # Abort the execution with an error message
    2.26  # Usage: CT_Abort <message>
    2.27  CT_Abort() {