mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: improve isolation of shell variables in wmake scripts
- reduces unexpected interactions between various make elements
This commit is contained in:
@ -28,6 +28,11 @@
|
||||
# Functions to check wmake environment and find .dep and .o files
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
# Ensure these variables are always defined
|
||||
MakeDir=Make
|
||||
: ${Script:=wmakeFunctions}
|
||||
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Check environment variables
|
||||
#------------------------------------------------------------------------------
|
||||
@ -52,78 +57,83 @@ checkEnv()
|
||||
# expandPath dirName
|
||||
# expandPath fileName
|
||||
#
|
||||
# Sets:
|
||||
# - exPath
|
||||
# Output:
|
||||
# - the expanded path name
|
||||
expandPath()
|
||||
{
|
||||
if [ -d "$1" ]
|
||||
then
|
||||
exPath=$(cd "$1" && pwd -P)
|
||||
(cd "$1" && pwd -P)
|
||||
elif [ -n "$1" ]
|
||||
then
|
||||
(cd $(dirname "$1") && pwd -P)
|
||||
else
|
||||
exPath=$(cd $(dirname "$1") && pwd -P)
|
||||
pwd -P
|
||||
fi
|
||||
}
|
||||
|
||||
# Find the target directory
|
||||
# Find the target directory, which contains a Make/ directory
|
||||
# search upwards in its parent directories, but stopping
|
||||
# when it hits the project root, home, or the file-system root
|
||||
#
|
||||
# findTarget dirName
|
||||
# findTarget fileName
|
||||
#
|
||||
# Sets:
|
||||
# - dir
|
||||
#
|
||||
# Side-effect variables:
|
||||
# - sets exPath
|
||||
# - sets wmpdir
|
||||
# Output:
|
||||
# - the relative target directory
|
||||
#
|
||||
# Global variables used:
|
||||
# - WM_PROJECT_DIR, HOME
|
||||
findTarget()
|
||||
{
|
||||
expandPath $WM_PROJECT_DIR
|
||||
wmpdir=$exPath
|
||||
expandPath $1
|
||||
local wmpdir=$(expandPath $WM_PROJECT_DIR)
|
||||
local home=$(expandPath $HOME)
|
||||
local reldir="${1:-.}"
|
||||
local absdir=$(expandPath $reldir)
|
||||
|
||||
if [ "$exPath" = "$wmpdir" \
|
||||
-o "$exPath" = "$HOME" \
|
||||
-o "$exPath" = "/" \
|
||||
]
|
||||
then
|
||||
echo "$Script error: could not find Make directory" 1>&2
|
||||
exit 1
|
||||
elif [ -d "$1/Make" ]
|
||||
then
|
||||
dir=$1
|
||||
else
|
||||
findTarget "$1/.."
|
||||
fi
|
||||
while [ -n "$absdir" ]
|
||||
do
|
||||
case "$absdir" in
|
||||
($wmpdir | $home | /)
|
||||
break
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ -d "$reldir/Make" ]
|
||||
then
|
||||
echo "$reldir"
|
||||
return 0
|
||||
else
|
||||
# Check parent directory
|
||||
absdir="${absdir%/*}"
|
||||
reldir="$reldir/.."
|
||||
fi
|
||||
done
|
||||
|
||||
echo "Error: no Make directory for $(expandPath $1)" 1>&2
|
||||
echo 1>&2
|
||||
return 1
|
||||
}
|
||||
|
||||
# Change to 'MakeDir'
|
||||
# - 'MakeDir' for its input
|
||||
|
||||
# Change to 'MakeDir' parent
|
||||
# - uses 'MakeDir' for its input
|
||||
#
|
||||
# Sets:
|
||||
# - dir
|
||||
#
|
||||
# Side-effect variables:
|
||||
# - sets exPath
|
||||
# Side-effects:
|
||||
# - unsets targetType
|
||||
cdSource()
|
||||
{
|
||||
if [ ! -d $MakeDir ]
|
||||
local dir
|
||||
if [ ! -d "$MakeDir" ]
|
||||
then
|
||||
echo "$Script: '$MakeDir' directory does not exist in $PWD" 1>&2
|
||||
echo " Searching up directories tree for Make directory" 1>&2
|
||||
|
||||
dir=$(findTarget .) || exit 1 # Fatal
|
||||
cd $dir 2>/dev/null || {
|
||||
echo "$Script error: could not change to directory '$dir'" 1>&2
|
||||
exit 1
|
||||
}
|
||||
unset targetType
|
||||
|
||||
findTarget .
|
||||
|
||||
if [ "$dir" ]
|
||||
then
|
||||
cd $dir 2>/dev/null || {
|
||||
echo "$Script error: could not change to directory '$dir'" 1>&2
|
||||
exit 1
|
||||
}
|
||||
fi
|
||||
fi
|
||||
|
||||
[ -r $MakeDir/files ] || {
|
||||
@ -137,48 +147,58 @@ cdSource()
|
||||
# findObjectDir dirName
|
||||
# findObjectDir fileName
|
||||
#
|
||||
# Sets:
|
||||
# - dir
|
||||
# - path
|
||||
# - appDir
|
||||
# - objectsDir
|
||||
#
|
||||
# Side-effect variables:
|
||||
# - sets exPath
|
||||
# - sets wmpdir
|
||||
# - set platformPath
|
||||
# Output:
|
||||
# - the objectsDir
|
||||
#
|
||||
# Global variables used:
|
||||
# - WM_PROJECT_DIR, WM_OPTIONS
|
||||
findObjectDir()
|
||||
{
|
||||
expandPath $WM_PROJECT_DIR
|
||||
wmpdir=$exPath
|
||||
expandPath $1
|
||||
local wmpdir=$(expandPath $WM_PROJECT_DIR)
|
||||
local exPath=$(expandPath ${1:-.})
|
||||
local objectsDir
|
||||
|
||||
if echo $exPath | grep "$wmpdir" > /dev/null
|
||||
then
|
||||
platformPath=$WM_PROJECT_DIR/platforms/${WM_OPTIONS}
|
||||
objectsDir=$platformPath$(echo $exPath | sed s%$wmpdir%% )
|
||||
else
|
||||
path=$exPath
|
||||
dir=.
|
||||
if [ ! -d Make ]
|
||||
then
|
||||
findTarget .
|
||||
fi
|
||||
appDir=$dir
|
||||
expandPath $appDir/.
|
||||
case "$exPath" in
|
||||
("$wmpdir"/*)
|
||||
local buildPath=$WM_PROJECT_DIR/platforms/${WM_OPTIONS}
|
||||
objectsDir=$buildPath$(echo $exPath | sed s%$wmpdir%% )
|
||||
;;
|
||||
(*)
|
||||
local path=$exPath
|
||||
local appDir=.
|
||||
[ -d Make ] || appDir=$(findTarget .) || exit 1 # Fatal
|
||||
exPath=$(expandPath $appDir/.)
|
||||
objectsDir=$appDir/Make/${WM_OPTIONS}$(echo $path | sed s%$exPath%% )
|
||||
;;
|
||||
esac
|
||||
|
||||
echo "$objectsDir"
|
||||
}
|
||||
|
||||
|
||||
# Find the object directory and remove it
|
||||
# removeObjectDir dirName
|
||||
# removeObjectDir fileName
|
||||
#
|
||||
# Output:
|
||||
# - NONE
|
||||
#
|
||||
# Global variables used:
|
||||
# - WM_PROJECT_DIR, WM_OPTIONS
|
||||
removeObjectDir()
|
||||
{
|
||||
local objectsDir=$(findObjectDir ${1:-.})
|
||||
if [ -d "$objectsDir" ]
|
||||
then
|
||||
rm -rf "$objectsDir" > /dev/null 2>&1
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
# depToSource
|
||||
# - uses 'depFile' for its input
|
||||
# depToSource depFile
|
||||
#
|
||||
# Sets:
|
||||
# - sourceFile
|
||||
# Output:
|
||||
# - the sourceFile corresponding to depFile
|
||||
#
|
||||
# Global variables used:
|
||||
# - WM_OPTIONS
|
||||
@ -187,20 +207,24 @@ if [ -n "$BASH_VERSION" ]
|
||||
then
|
||||
depToSource()
|
||||
{
|
||||
sourceFile=${depFile%.dep}
|
||||
local sourceFile=${1%.dep}
|
||||
sourceFile="${sourceFile/platforms\/${WM_OPTIONS}\//}"
|
||||
sourceFile="${sourceFile/Make\/${WM_OPTIONS}\//}"
|
||||
sourceFile="${sourceFile/platforms\/${WM_OPTIONS}${WM_MPLIB}\//}"
|
||||
sourceFile="${sourceFile/Make\/${WM_OPTIONS}\//}"
|
||||
sourceFile="${sourceFile/Make\/${WM_OPTIONS}${WM_MPLIB}\//}"
|
||||
|
||||
echo "$sourceFile"
|
||||
}
|
||||
else
|
||||
depToSource()
|
||||
{
|
||||
sourceFile=$(echo ${depFile%.dep} | \
|
||||
local sourceFile=$(echo ${1%.dep} | \
|
||||
sed -e s%platforms/${WM_OPTIONS}/%% \
|
||||
-e s%Make/${WM_OPTIONS}/%% \
|
||||
-e s%platforms/${WM_OPTIONS}${WM_MPLIB}/%% \
|
||||
-e s%Make/${WM_OPTIONS}/%% \
|
||||
-e s%Make/${WM_OPTIONS}${WM_MPLIB}/%% )
|
||||
|
||||
echo "$sourceFile"
|
||||
}
|
||||
fi
|
||||
|
||||
|
||||
Reference in New Issue
Block a user