From 50ccb197dc7d3ca22ac79e6771ebacb33e62abb5 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Wed, 21 Nov 2018 11:02:58 +0100 Subject: [PATCH] BUG: fix bad environment parsing in foamCreateModuleInclude - The changes in foamCleanPath introduced for issues (#1007, #1008) include quoted output of the cleaned environment variable. When used in foamCreateModuleInclude, the quotes make their way into the final environment. Avoid this by using the -sh-env eval format instead. - add environment extraction of MANPATH changes --- bin/tools/foamCreateModuleInclude | 42 +++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/bin/tools/foamCreateModuleInclude b/bin/tools/foamCreateModuleInclude index 994b36e818..f8e8775ed3 100755 --- a/bin/tools/foamCreateModuleInclude +++ b/bin/tools/foamCreateModuleInclude @@ -3,7 +3,7 @@ # ========= | # \\ / F ield | OpenFOAM: The Open Source CFD Toolbox # \\ / O peration | -# \\ / A nd | Copyright (C) 2017 OpenCFD Ltd. +# \\ / A nd | Copyright (C) 2017-2018 OpenCFD Ltd. # \\/ M anipulation | Copyright (C) 2016-2017 CINECA #------------------------------------------------------------------------------ # License @@ -40,7 +40,7 @@ options: -output=file The output name (default: ModuleInclude.tcl) -preload=file Specify (module) file to preload. Can use multiple times -tmpdir=file The tmp directory to use. - -help print the usage + -help Print the usage Create module settings for inclusion in a top-level openfoam module. @@ -136,11 +136,12 @@ then done # Call itself with clean environment. - # Tag the start/end of the original PATH, LD_LIBRARY_PATH + # Tag the start/end of the original PATH, MANPATH, LD_LIBRARY_PATH exec env -i \ HOME=$HOME \ USER=$USER \ PATH=":MOD_PREPEND:$(syspath $PATH):MOD_APPEND:" \ + MANPATH=":MOD_PREPEND:$(syspath $MANPATH):MOD_APPEND:" \ LD_LIBRARY_PATH=":MOD_PREPEND:$(syspath $LD_LIBRARY_PATH):MOD_APPEND:" \ $0 \ --recursive-backend-- \ @@ -232,16 +233,14 @@ foamClean=$WM_PROJECT_DIR/bin/foamCleanPath if [ -x "$foamClean" ] then - cleaned=$($foamClean "$PATH" "$foamOldDirs") && PATH="$cleaned" - cleaned=$($foamClean "$LD_LIBRARY_PATH" "$foamOldDirs") \ - && LD_LIBRARY_PATH="$cleaned" + eval $($foamClean -sh-env=PATH "$foamOldDirs") + eval $($foamClean -sh-env=MANPATH "$foamOldDirs") + eval $($foamClean -sh-env=LD_LIBRARY_PATH "$foamOldDirs") # May not have/need any third party at all if [ -n "$FOAM_EXT_LIBBIN" -a ! -d "$FOAM_EXT_LIBBIN" ] then - cleaned=$($foamClean "$LD_LIBRARY_PATH" "$FOAM_EXT_LIBBIN") \ - && LD_LIBRARY_PATH="$cleaned" - + eval $($foamClean -sh-env=LD_LIBRARY_PATH "$FOAM_EXT_LIBBIN") unset FOAM_EXT_LIBBIN fi fi @@ -296,11 +295,12 @@ diff $tmpFiles.alias.pre.log $tmpFiles.alias.post.log > $tmpFiles.alias.diff.lo echo "# -------------------" > $moduleOutput # -------------------------------------------------- -# Environment other than PATH, LD_LIBRARY_PATH +# Environment other than PATH, MANPATH, LD_LIBRARY_PATH echo "# Environment" >> $moduleOutput grep '> ' $tmpFiles.env.diff.log | \ sed \ -e '/^> *PATH=/d' \ + -e '/^> *MANPATH=/d' \ -e '/^> *LD_LIBRARY_PATH=/d' \ -e 's/^>/setenv /' \ -e 's/=/ "/' -e 's/$/\"/' >> $moduleOutput @@ -328,6 +328,28 @@ sed \ $tmpFiles.path.diff.log >> $moduleOutput # -------------------------------------------------- +# -------------------------------------------------- +# Changes in MANPATH - without junk and system directories +echo "# MANPATH" >> $moduleOutput + +sed -ne 's/^< *MANPATH=//p' $tmpFiles.env.diff.log | tr ':' '\n' > $tmpFiles.manpath.pre.log +sed -ne 's/^> *MANPATH=//p' $tmpFiles.env.diff.log | tr ':' '\n' > $tmpFiles.manpath.post.log + +grep -vxFf $tmpFiles.manpath.pre.log $tmpFiles.manpath.post.log | \ +sed \ + -e '\@^/usr/share/@d' \ + -e '\@^/usr/local/@d' \ + -e '\@^/usr/lib@d' \ + -e '\@^[.]$@d' \ + -e '\@^$@d' \ + > $tmpFiles.manpath.diff.log + +sed \ + -e 's/^/append-path MANPATH "/' \ + -e 's/$/\"/' \ + $tmpFiles.manpath.diff.log >> $moduleOutput +# -------------------------------------------------- + # -------------------------------------------------- # Changes in LD_LIBRARY_PATH - without junk and system directories echo "# LD_LIBRARY_PATH" >> $moduleOutput