openfoam/bin/foamInstallationTest
Mark Olesen 6c68c34e1a ENH: update handling of versioning and make control (issue #1010)
- Use the OPENFOAM define (eg, 1806, 1812), which normally corresponds
  to a major release, to define an API level. This remains consistent
  within a release cycle and means that it is possible to manage
  several sub-versions and continue to have a consistent lookup.

  The current API value is updated automatically during the build
  and cached as meta data for later use, even when the wmake/ directory
  is missing or OpenFOAM has not yet be initialized.

  The version information reported on program start or with -help
  usage adjusted to reflect this. The build tag from git now also
  carries the date as being more meaningful to trace than a hash
  value.

- Update etc/bashrc and etc/cshrc to obtain the project directory
  directly instead of via its prefix directory. The value obtained
  corresponds to an absolute path, from which the prefix directory
  can be obtained.

  The combination of these changes removes the reliance on any
  particular directory naming convention.
  For example,

     With an 1812 version (API level):

     WM_PROJECT_VERSION=myVersion

     installed as /some/path/somewhere/openfoam-mySandbox

  This makes the -prefix, -foamInstall, -projectVersion, -version
  values of foamEtcFiles, and similar entries for foamConfigurePaths
  superfluous.

  WM_PROJECT_INST_DIR is no longer required or used

ENH: improve handling and discovery of ThirdParty

- improve the flexibility and reusability of ThirdParty packs to cover
  various standard use cases:

    1. Unpacking initial release tar files with two parallel directories
       - OpenFOAM-v1812/
       - ThirdParty-v1812/

    2. With an adjusted OpenFOAM directory name, for whatever reason
       - OpenFOAM-v1812-myCustom/
       - openfoam-1812-other-info/

    3. Operating with/without ThirdParty directory

  To handle these use cases, the following discovery is used.

  Note PROJECT = the OpenFOAM directory `$WM_PROJECT_DIR`
       PREFIX = the parent directory
       VERSION = `$WM_PROJECT_VERSION`
       API = `$WM_PROJECT_API`, as per `foamEtcFiles -show-api`

   0. PROJECT/ThirdParty
      - for single-directory installations

   1. PREFIX/ThirdParty-VERSION
      - this corresponds to the traditional approach

   2. PREFIX/ThirdParty-vAPI
      - allows for an updated value of VERSION (eg, v1812-myCustom)
        without requiring a renamed ThirdParty. The API value
        would still be '1812' and the original ThirdParty-v1812/
        would be found.

   3. PREFIX/ThirdParty-API
      - this is the same as the previous example, but using an unadorned
        API value. This also makes sense if the chosen version name also
        uses the unadorned API value in its naming
        (eg, 1812-patch190131, 1812.19W03)

   4. PREFIX/ThirdParty-common
      - permits maximum reuse for various versions, but only for
        experienced user who are aware of potential version
        incompatibilities

   Directory existence is checked as is the presence of an Allwmake file
   or a platforms/ directory. This reduces the potential of false positive
   matches and limits the selection to directories that are either
   with sources (has the Allwmake file), or pre-compiled binaries (has
   the platforms/ directory).

   If none of the explored directories are found to be suitable,
   it reverts to using a PROJECT/ThirdParty dummy location since
   this is within the project source tree and can be trusted to
   have no negative side-effects.

ENH: add csh support to foamConfigurePaths

- this removes the previously experienced inconsistence in config file
  contents.

REMOVED: foamExec

- was previously used when switching versions and before the
  bashrc/cshrc discovery logic was added. It is now obsolete.
2018-12-02 18:25:57 +01:00

468 lines
12 KiB
Bash
Executable File

#!/bin/sh
#------------------------------------------------------------------------------
# ========= |
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
# \\ / O peration |
# \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
# \\/ M anipulation |
#-------------------------------------------------------------------------------
# License
# This file is part of OpenFOAM.
#
# OpenFOAM is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public License
# along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
#
# Script
# foamInstallationTest
#
# Description
# Check the machine system, the installation of OpenFOAM, and the user's
# personal configuration for running OpenFOAM.
#
#------------------------------------------------------------------------------
# Base settings
MIN_VERSION_GCC=4.8.0
# General
WIDTH=20
# System variables
HOST=$(uname -n)
OSTYPE=$(uname -s)
# OpenFOAM application to test for the Version
foamTestApp=icoFoam
# Global variables
unset fatalError criticalError
#==============================================================================
# HELPER FUNCTIONS
#==============================================================================
hline()
{
echo "-------------------------------------------------------------------------------"
}
heading()
{
echo
echo
echo "$1"
}
fixlen()
{
WORD=$1
LDIFF=$(expr ${#WORD} - ${2:-4})
if [ $LDIFF -le 1 ]
then
while [ $LDIFF -lt 0 ]
do
WORD="$WORD "
LDIFF=$(expr $LDIFF + 1)
done
echo "$WORD"
else
LDIFF=$(expr $LDIFF + 4)
WORD=$(echo "$WORD" | cut -c${LDIFF}-)
echo "...${WORD}"
fi
}
reportEnv()
{
eval EXP_ENV="$1"
eval EXP_PATH="$2"
CRIT="$3"
EXISTS=" no "
ON_PATH=""
if [ -n "$EXP_ENV" ]
then
if test -e "$EXP_ENV"
then
EXISTS=" yes "
if [ "$2" != noPath ]
then
ON_PATH=" no "
oldIFS=$IFS
IFS=':'
for e in $EXP_PATH
do
case "$e" in
"$EXP_ENV" | "$EXP_ENV/bin" | "$EXP_ENV/lib")
ON_PATH="yes "
break
;;
esac
done
IFS=$oldIFS
else
CRIT=" $3"
fi
else
ON_PATH=" "
fi
echo "$(fixlen "$1" 21) $(fixlen "$EXP_ENV" 40) $EXISTS $ON_PATH $CRIT"
else
echo "$(fixlen "$1" 21) --------- env variable not set --------- $3"
fi
ERROR=false
if [ "$EXISTS" = no ] || [ "$ON_PATH" = no ]
then
ERROR=true
fi
if [ "$3" = yes ] && [ "$ERROR" = true ]
then
criticalError="x${criticalError}"
echo "WARNING: CRITICAL ERROR"
echo
fi
}
findExec()
{
oldIFS=$IFS
IFS=':'
for d in $1
do
if test ! -d "$d/$2" -a -x "$d/$2"
then
IFS=$oldIFS
echo "$d/$2"
return 0
fi
done
IFS=$oldIFS
return 1
}
# compare (required-version, version)
# Major.minor.patch <= Major.minor.patch
#
vercmp_3()
{
local arg1="$1"
local arg2="$2"
oldIFS=$IFS
IFS='.'
set -- $arg1
local arg1Major=$1 arg1Minor=$2 arg1Patch="${3:-0}"
set -- $arg2
local arg2Major=$1 arg2Minor=$2 arg2Patch="${3:-0}"
IFS=$oldIFS
#debug> echo "check $arg1 vs $arg2"
#debug> echo "arg1maj=$arg1Major arg1min=$arg1Minor arg1patch=$arg1Patch"
#debug> echo "arg2maj=$arg2Major arg2min=$arg2Minor arg2patch=$arg2Patch"
# Major version
if [ $arg1Major -lt $arg2Major ]
then
return 0
elif [ $arg1Major -gt $arg2Major ]
then
return 1
fi
# Minor version
if [ $arg1Minor -lt $arg2Minor ]
then
return 0
elif [ $arg1Minor -gt $arg2Minor ]
then
return 2
fi
# Patch
if [ -n "$arg1Patch" -a -n "$arg2Patch" ]
then
if [ "$arg1Patch" -gt "$arg2Patch" ]
then
return 3
fi
fi
return 0
}
reportExecutable()
{
APP_NAME="$1"
APP_SPEC="$2"
APP_PATH="$(findExec $PATH $1)"
if [ -z "$APP_PATH" ]
then
echo "$(fixlen "$1" 9)" "*** not installed ***"
VERSION=""
case "$1" in
gcc* | $foamTestApp)
echo " CRITICAL ERROR"
criticalError="x${criticalError}"
;;
esac
echo
return 1
fi
case "$APP_NAME" in
$foamTestApp)
VERSION=$($APP_NAME -case /dev/null 2>&1 \
| sed -ne 's/^.*Version: *\([^ ][^ ]*\).*/\1/p')
;;
flex)
VERSION=$($APP_NAME --version /dev/null 2>&1 \
| sed -ne 's/flex \([0-9][0-9.]*\).*/\1/p')
;;
gcc* | g++*)
VERSION=$($APP_NAME -v 2>&1 \
| sed -ne 's/^gcc version \([0-9][0-9.]*\).*/\1/p')
if ! vercmp_3 "$MIN_VERSION_GCC" "$VERSION"
then
case "$APP_NAME" in
gcc*)
SHORT_NAME=gcc
;;
g++*)
SHORT_NAME=g++
;;
esac
echo "ERROR: $SHORT_NAME version is too old for this release of OpenFOAM"
echo " User version : $VERSION"
echo " Minimum required: $MIN_VERSION_GCC"
echo ""
fatalError="x${fatalError}"
fi
;;
gtar)
VERSION=$($APP_PATH --version | head -1)
;;
tar)
VERSION=$($APP_PATH --version | head -1 | cut -d" " -f4)
;;
gzip)
case "$OSTYPE" in
SunOS)
VERSION=$($APP_NAME --version 2>&1 | grep gzip | cut -d" " -f2)
;;
*)
VERSION=$($APP_NAME --version | head -1 | cut -d" " -f2)
;;
esac
;;
esac
if [ "$APP_PATH" = "$APP_SPEC" ] || [ -z "$APP_SPEC" ]
then
echo "$(fixlen "$APP_NAME" 9) $(fixlen "$VERSION" 10) $(fixlen "$APP_PATH" 58)"
else
echo "$(fixlen "$APP_NAME" 9) $(fixlen "$VERSION" 10)"
echo "WARNING: Conflicting installations:"
echo " OpenFOAM settings : $APP_SPEC"
echo " current path : $APP_PATH"
case "$APP_NAME" in
gcc | $foamTestApp)
echo " CRITICAL ERROR"
criticalError="x${criticalError}"
;;
esac
echo ""
fi
}
checkOpenFOAMEnvironment()
{
[ -d "$WM_PROJECT_DIR" ] && [ -d "$WM_THIRD_PARTY_DIR" ] || {
echo ""
echo "FATAL ERROR: OpenFOAM environment not configured."
echo ""
echo " Please follow the download and installation link in README.html:"
echo " <OpenFOAM installation dir>/OpenFOAM-${WM_PROJECT_VERSION}/README.html"
echo " for information on setting-up the OpenFOAM environment."
echo ""
exit 1
}
echo "$(fixlen OpenFOAM: $WIDTH) ${WM_PROJECT_DIR##*/}"
echo "$(fixlen ThirdParty: $WIDTH) ${WM_THIRD_PARTY_DIR##*/}"
}
checkUserShell()
{
echo "$(fixlen Shell: $WIDTH) ${SHELL##*/}"
case $SHELL in
*/csh | */tcsh | */bash | */ksh)
;;
*)
echo "FATAL ERROR: Cannot identify the shell you are running."
echo " OpenFOAM ${WM_PROJECT_VERSION} is compatible with "
echo " csh, tcsh, ksh and bash."
echo
fatalError="x${fatalError}"
;;
esac
}
checkHostName()
{
echo "$(fixlen Host: $WIDTH) $HOST"
if [ -z "$HOST" ]
then
echo "FATAL ERROR: Cannot stat hostname."
echo " Contact your system administrator, "
echo " OpenFOAM ${WM_PROJECT_VERSION} needs a valid "
echo " hostname to function."
echo
fatalError="x${fatalError}"
fi
}
checkOS()
{
case "$OSTYPE" in
Linux | LinuxAMD64 | SunOS )
echo "$(fixlen OS: $WIDTH) $OSTYPE version $(uname -r)"
;;
*)
echo "FATAL ERROR: Incompatible operating system \"$OSTYPE\"."
echo " OpenFOAM ${FWM_PROJECT_VERSION} is currently "
echo " available for Linux and SunOS only."
echo
fatalError="x${fatalError}"
;;
esac
}
#==============================================================================
# MAIN SCRIPT
#==============================================================================
#
echo "Executing $0:"
#------------------------------------------------------------------------------
heading "Basic setup :"
hline
checkOpenFOAMEnvironment
checkUserShell
checkHostName
checkOS
hline
#------------------------------------------------------------------------------
heading "Main OpenFOAM env variables :"
COL1=$(fixlen EnvironmentVariable 21)
COL2=$(fixlen FileOrDirectory 40)
COL3="Valid"
COL4="Path"
COL5="Crit"
hline
echo "$COL1 $COL2 $COL3 $COL5"
hline
reportEnv '$WM_PROJECT_USER_DIR' noPath no
reportEnv '$WM_THIRD_PARTY_DIR' noPath yes
hline
#------------------------------------------------------------------------------
heading "OpenFOAM env variables in PATH :"
hline
echo "$COL1 $COL2 $COL3 $COL4 $COL5"
hline
reportEnv '$WM_PROJECT_DIR' '$PATH' yes
echo ""
reportEnv '$FOAM_APPBIN' '$PATH' yes
reportEnv '$FOAM_SITE_APPBIN' '$PATH' no
reportEnv '$FOAM_USER_APPBIN' '$PATH' no
reportEnv '$WM_DIR' '$PATH' often
hline
#------------------------------------------------------------------------------
heading "OpenFOAM env variables in LD_LIBRARY_PATH :"
hline
echo "$COL1 $COL2 $COL3 $COL4 $COL5"
hline
reportEnv '$FOAM_LIBBIN' '$LD_LIBRARY_PATH' yes
reportEnv '$FOAM_SITE_LIBBIN' '$LD_LIBRARY_PATH' no
reportEnv '$FOAM_USER_LIBBIN' '$LD_LIBRARY_PATH' no
reportEnv '$FOAM_EXT_LIBBIN' '$LD_LIBRARY_PATH' maybe
reportEnv '$MPI_ARCH_PATH' '$LD_LIBRARY_PATH' yes
hline
#------------------------------------------------------------------------------
heading "Software Components"
hline
echo "$(fixlen Software 9) $(fixlen Version 10) $(fixlen Location 10)"
hline
reportExecutable flex
reportExecutable "$WM_CC"
reportExecutable "$WM_CXX"
reportExecutable gzip
if [ "$OSTYPE" = Linux ]
then
reportExecutable tar
else
reportExecutable gtar
fi
reportExecutable $foamTestApp "$FOAM_APPBIN/$foamTestApp"
hline
#------------------------------------------------------------------------------
heading "Summary"
hline
if [ "${#fatalError}" -gt 0 ]
then
echo "The system test evoked ${#fatalError} fatal error(s)."
else
echo "Base configuration ok."
fi
if [ "${#criticalError}" -gt 0 ]
then
echo "The foam installation contains ${#criticalError} critical error(s)."
else
echo "Critical systems ok."
fi
if [ "${#criticalError}" -gt 0 ] || [ "${#fatalError}" -gt 0 ]
then
echo
echo "Review the output for warning messages and consult"
echo "the installation guide for troubleshooting."
fi
echo
echo Done
echo
exit 0
#------------------------------------------------------------------------------