Commit aa2f932b authored by Mark Olesen's avatar Mark Olesen
Browse files

CONFIG: additional packaging helpers, tutorial test helper

- bin/tools/create-mpi-config to query/write values for system openmpi.
  In some cases this can be used to avoid an mpicc requirement at runtime.

- adjust openfoam session to include -test-tutorial forwarding to the
  tutorials/AutoTest. This helps with writing installation tests.

- adjust foamConfigurePaths to latest version

- removal of gperftools default config, as per develop
parent 6691e656
......@@ -86,8 +86,8 @@ echo " ${WM_PROJECT_DIR##*/}"
echo " $WM_COMPILER ${WM_COMPILER_TYPE:-system} compiler"
echo " ${WM_OPTIONS}, with ${WM_MPLIB} ${FOAM_MPI}"
echo
echo " api = $(foamEtcFile -show-api 2>/dev/null)"
echo " patch = $(foamEtcFile -show-patch 2>/dev/null)"
echo " api = $(etc/openfoam -show-api 2>/dev/null)"
echo " patch = $(etc/openfoam -show-patch 2>/dev/null)"
echo " bin = $(_foamCountDirEntries $FOAM_APPBIN) entries"
echo " lib = $(_foamCountDirEntries $FOAM_LIBBIN) entries"
echo
......
api=1912
patch=200403
patch=200417
......@@ -7,14 +7,13 @@
# \\/ M anipulation |
#------------------------------------------------------------------------------
# Copyright (C) 2011-2016 OpenFOAM Foundation
# Copyright (C) 2017-2018 OpenCFD Ltd.
# Copyright (C) 2017-2020 OpenCFD Ltd.
#------------------------------------------------------------------------------
# License
# This file is part of OpenFOAM, licensed under GNU General Public License
# <http://www.gnu.org/licenses/>.
# This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
#
# Script
# foamEtcFile
# bin/foamEtcFile
#
# Description
# Locate user/group/other file as per '#includeEtc'.
......@@ -67,8 +66,8 @@ options:
-config Add config directory prefix for shell type:
with -csh* for a config.csh/ prefix
with -sh* for a config.sh/ prefix
-show-api Print api value from wmake/rules, or meta-info and exit
-show-patch Print patch value from meta-info and exit
-show-api Print META-INFO api value and exit
-show-patch Print META-INFO patch value and exit
-with-api=NUM Specify alternative api value to search with
-quiet (-q) Suppress all normal output
-silent (-s) Suppress stderr, except -csh-verbose, -sh-verbose output
......@@ -129,54 +128,17 @@ fi
#-------------------------------------------------------------------------------
# The API locations. See wmake/wmakeBuildInfo
rulesFile="$projectDir/wmake/rules/General/general"
metaInfoDir="$projectDir/META-INFO"
# Get api from rules/General/general
#
# Failure modes:
# - No api information (can't find file etc).
# -> Fatal for building, but could be OK for a stripped down version
#
# Fallback. Get from api-info
#
getApi()
# Get a value from META-INFO/api-info
# $1 : keyword
getApiInfo()
{
local value
value="$(sed -ne '/^ *#/!{ /WM_VERSION.*OPENFOAM=/{ s@^.*OPENFOAM= *\([0-9][0-9]*\).*@\1@p; q }}' $rulesFile 2>/dev/null)"
if [ -z "$value" ] && [ -f "$metaInfoDir/api-info" ]
then
# Fallback. Get from api-info
value="$(sed -ne 's@^ *api *= *\([0-9][0-9]*\).*@\1@p' $metaInfoDir/api-info 2>/dev/null)"
fi
if [ -n "$value" ]
then
echo "$value"
else
return 1
fi
}
# Get patch from meta-info / api-info
#
# Failure modes:
# - No patch information (can't find file etc).
#
getPatchLevel()
{
local value
# Fallback. Get from api-info
value="$(sed -ne 's@^ *patch *= *\([0-9][0-9]*\).*@\1@p' $metaInfoDir/api-info 2>/dev/null)"
value="$(sed -ne 's@^'"$1"' *= *\([0-9][0-9]*\).*@\1@p' "$projectDir"/META-INFO/api-info 2>/dev/null)"
if [ -n "$value" ]
then
echo "$value"
else
echo "Could not determine OPENFOAM '$1' value" 1>&2
return 1
fi
}
......@@ -193,14 +155,12 @@ do
-h | -help*)
printHelp
;;
-show-api)
# Show API and exit
getApi
-show-api) # Show API and exit
getApiInfo api
exit $?
;;
-show-patch)
# Show patch level and exit
getPatchLevel
-show-patch) # Show patch level and exit
getApiInfo patch
exit $?
;;
-with-api=*)
......@@ -276,7 +236,7 @@ done
#-------------------------------------------------------------------------------
# Establish the API value
[ -n "$projectApi" ] || projectApi=$(getApi)
[ -n "$projectApi" ] || projectApi=$(getApiInfo api)
# Split arguments into filename (for searching) and trailing bits for shell eval
# Silently remove leading ~OpenFOAM/ (as per Foam::findEtcFile)
......
#!/bin/sh
#------------------------------------------------------------------------------
# ========= |
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
# \\ / O peration |
# \\ / A nd | www.openfoam.com
# \\/ M anipulation |
#------------------------------------------------------------------------------
# Copyright (C) 2020 OpenCFD Ltd.
#------------------------------------------------------------------------------
# License
# This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
#
# Script
# bin/tools/create-mpi-config
#
# Description
# Define hard-coded packaging settings for MPI flavours,
# primarily for system openmpi.
# This eliminates a runtime dependency on mpicc, for example.
#
# Instead of querying/parsing 'mpicc --showme:link' each time,
# it is done once during packaging.
#
# Environment
# FOAM_MPI, MPI_ARCH_PATH, DEB_TARGET_MULTIARCH
#
# Possible Dependencies
# - dpkg-architecture
# - mpicc
#
# Notes
# Run from top-level directory when creating config files
#
#------------------------------------------------------------------------------
printHelp() {
exec 1>&2
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
cat<<USAGE
usage: ${0##*/} options
options:
-dry-run Report but do not write config files
-no-mpicc Bypass any use of mpicc
-query-openmpi Report installation directory for system openmpi
-write-openmpi Query system openmpi and write config files
-write Write config files using FOAM_MPI, MPI_ARCH_PATH
Define hard-coded packaging settings for MPI flavours.
Equivalent options:
-write-system-openmpi | -write-openmpi
-query-system-openmpi | -query-openmpi
USAGE
exit 0 # A clean exit
}
# Report error and exit
die()
{
exec 1>&2
echo
echo "Error encountered:"
while [ "$#" -ge 1 ]; do echo " $1"; shift; done
echo
echo "See '${0##*/} -help' for usage"
echo
exit 1
}
#------------------------------------------------------------------------------
# Options
unset optDryRun
useMpicc=true
# Get installation directory for system openmpi
# - from "mpicc --showme:link"
# - manual fallback
#
# The mpicc content looks like this:
# ----
# -pthread -L/usr/lib64/mpi/gcc/openmpi/lib64 -lmpi
# ----
query_system_openmpi()
{
unset arch_path
if [ "$useMpicc" = true ]
then
arch_path=$(mpicc --showme:link 2>/dev/null | sed -e 's#^.*-L\([^ ]*\).*#\1#')
arch_path="${arch_path%/*}"
if [ -n "$arch_path" ]
then
echo "$arch_path"
return 0 # Clean exit
fi
echo "No mpicc found. Attempt manually" 1>&2
fi
# Manual discovery
if [ -z "$DEB_TARGET_MULTIARCH" ]
then
DEB_TARGET_MULTIARCH=$(dpkg-architecture -qDEB_TARGET_MULTIARCH 2>/dev/null || true)
fi
# Include is under /usr/lib... (eg, debian, openSUSE)
for testdir in \
/usr/lib/"${DEB_TARGET_MULTIARCH:+${DEB_TARGET_MULTIARCH}/}"openmpi/include \
/usr/lib64/mpi/gcc/openmpi/include \
;
do
if [ -e "$testdir/mpi.h" ]
then
echo "${testdir%/*}"
return 0 # Clean exit
fi
done
# Include is under /usr/include (eg, RedHat)
for testdir in \
/usr/include/openmpi-"$(uname -m)" \
/usr/include/openmpi \
;
do
if [ -e "$testdir/mpi.h" ]
then
echo "/usr"
return 0 # Clean exit
fi
done
# Failed (should not happen)
# - report '/usr', but with error code 2
echo "/usr"
return 2
}
# Generate etc/config.{csh,sh}/MPI-TYPE files
# based on the values for FOAM_MPI and MPI_ARCH_PATH
create_files()
{
[ -n "$FOAM_MPI" ] || die "FOAM_MPI not set"
if [ -d "$MPI_ARCH_PATH" ]
then
echo "Define $FOAM_MPI with $MPI_ARCH_PATH" 1>&2
case "$FOAM_MPI" in
(openmpi-system)
configDir="etc/config.sh"
if [ "$optDryRun" = true ]
then
cat << CONTENT 1>&2
dry-run: $configDir/$FOAM_MPI
#
# Packaging configured value for $FOAM_MPI
export MPI_ARCH_PATH="$MPI_ARCH_PATH"
CONTENT
elif [ -d "$configDir" ]
then
echo "Write $configDir/$FOAM_MPI" 1>&2
cat << CONTENT > "$configDir/$FOAM_MPI"
# $configDir/$FOAM_MPI
#
# Packaging configured value for $FOAM_MPI
export MPI_ARCH_PATH="$MPI_ARCH_PATH"
#----
CONTENT
else
echo "Cannot write $configDir/$FOAM_MPI - no directory" 1>&2
fi
configDir="etc/config.csh"
if [ "$optDryRun" = true ]
then
cat << CONTENT 1>&2
dry-run: $configDir/$FOAM_MPI
#
# Packaging configured value for $FOAM_MPI
setenv MPI_ARCH_PATH "$MPI_ARCH_PATH"
CONTENT
elif [ -d "$configDir" ]
then
echo "Write $configDir/$FOAM_MPI" 1>&2
cat << CONTENT > "$configDir/$FOAM_MPI"
# $configDir/$FOAM_MPI
#
# Packaging configured value for $FOAM_MPI
setenv MPI_ARCH_PATH "$MPI_ARCH_PATH"
#----
CONTENT
else
echo "Cannot write $configDir/$FOAM_MPI - no directory" 1>&2
fi
;;
esac
else
echo "Warning: $FOAM_MPI with bad MPI_ARCH_PATH: $MPI_ARCH_PATH" 1>&2
# TBD - remove old/bad entries?
#
# for file in "etc/config.sh/$FOAM_MPI" "etc/config.csh/$FOAM_MPI"
# do
# [ -f "$file" ] && rm -f "$file"
# done
fi
}
#------------------------------------------------------------------------------
# Parse options
while [ "$#" -gt 0 ]
do
case "$1" in
-h | -help* | --help*)
printHelp
;;
'')
# Discard empty arguments
;;
-dry-run)
optDryRun=true
;;
-no-mpicc)
unset useMpicc
;;
-query-openmpi | -query-system-openmpi)
query_system_openmpi
exit $?
;;
-write-openmpi | -write-system-openmpi)
if MPI_ARCH_PATH=$(query_system_openmpi)
then
FOAM_MPI="openmpi-system"
create_files
else
die "Failed query for system openmpi"
fi
;;
-write)
create_files
;;
*)
echo "Ignore unknown option/argument: '$1'" 1>&2
;;
esac
shift
done
exit 0 # A clean exit, if we get this far
# -----------------------------------------------------------------------------
......@@ -29,18 +29,49 @@
#
#------------------------------------------------------------------------------
printHelp() {
cat<<USAGE
case "$1" in
(*compat*)
cat<<HELP_COMPAT
Obsolete options:
-foamInstall DIR [obsolete]
-projectName NAME [obsolete]
-sigfpe|-no-sigfpe [obsolete - now under etc/controlDict]
-archOption 32|64 [obsolete setting of 'WM_ARCH_OPTION' - edit manually]
Equivalent options:
-version -foamVersion --projectVersion
-archOption --archOption
-third -ThirdParty
-paraview --paraviewVersion | -paraviewVersion
-paraview-path --paraviewInstall | -paraviewInstall
-scotch --scotchVersion | -scotchVersion
-scotch-path --scotchArchPath | -scotchArchPath
-system-compiler -system
-third-compiler -third
HELP_COMPAT
exit 0 # A clean exit
;;
esac
cat<<HELP_HEAD
usage: $0 options
Options
-h | -help Display short help and exit
-help-compat Display compatibility options and exit
-help-full Display full help and exit
Basic
-etc=DIR set FOAM_CONFIG_ETC for alternative project files
-project-path DIR specify 'WM_PROJECT_DIR' (eg, /opt/openfoam1806-patch1)
-version VER specify project version (eg, v1806)
-sp | -SP | -float32 single precision (WM_PRECISION_OPTION)
-dp | -DP | -float64 double precision (WM_PRECISION_OPTION)
-spdp | -SPDP mixed single/double precision
-int32 | -int64 the 'WM_LABEL_SIZE'
-spdp | -SPDP mixed precision (WM_PRECISION_OPTION)
-int32 | -int64 label-size (WM_LABEL_SIZE)
Compiler
-system-compiler NAME The 'system' compiler to use (eg, Gcc, Clang, Icc,...)
......@@ -57,16 +88,21 @@ MPI
-openmpi-system use system openmpi
-openmpi-third use ThirdParty openmpi (using default version)
ThirdParty versions
Components versions (ThirdParty)
-adios VER specify 'adios2_version'
-boost VER specify 'boost_version'
-cgal ver specify 'cgal_version'
-cgal VER specify 'cgal_version'
-cmake VER specify 'cmake_version'
-fftw VER specify 'fffw_version'
-kahip VER specify 'KAHIP_VERSION'
-metis ver specify 'METIS_VERSION'
-metis VER specify 'METIS_VERSION'
-scotch VER specify 'SCOTCH_VERSION' (eg, scotch_6.0.4)
HELP_HEAD
case "$1" in
(*full*)
cat<<HELP_FULL
Components specified by absolute path
-adios-path DIR Path for 'ADIOS2_ARCH_PATH' (overrides -adios)
-boost-path DIR Path for 'BOOST_ARCH_PATH' (overrides -boost)
......@@ -80,32 +116,24 @@ Graphics
-paraview VER specify 'ParaView_VERSION' (eg, 5.4.1 or system)
-paraview-qt VER specify 'ParaView_QT' (eg, qt-system)
-paraview-path DIR specify 'ParaView_DIR' (eg, /opt/ParaView-5.4.1)
-vtk VER specify 'vtk_version' (eg, VTK-7.1.0)
-llvm VER specify 'mesa_llvm'
-mesa VER specify 'mesa_version' (eg, mesa-13.0.1)
-vtk VER specify 'vtk_version' (eg, VTK-7.1.0)
-llvm-path DIR Path for 'LLVM_ARCH_PATH' (overrides -llvm)
-mesa-path DIR Path for 'MESA_ARCH_PATH' (overrides -mesa)
-vtk-path DIR Path for 'VTK_DIR' (overrides -vtk)
Misc
-foamInstall DIR [obsolete]
-projectName NAME [obsolete]
-sigfpe|-no-sigfpe [obsolete - now under etc/controlDict]
-archOption 32|64 [obsolete setting of 'WM_ARCH_OPTION' - edit manually]
HELP_FULL
;;
esac
Adjusts hardcoded versions and installation paths (POSIX and C-shell).
cat<<HELP_TAIL_COMMON
Adjusts hardcoded versions and installation paths (POSIX and C-shell)
for OpenFOAM.
HELP_TAIL_COMMON
Equivalent options:
-version -foamVersion --projectVersion
-archOption --archOption
-third -ThirdParty
-paraview --paraviewVersion | -paraviewVersion
-paraview-path --paraviewInstall | -paraviewInstall
-scotch --scotchVersion | -scotchVersion
-scotch-path --scotchArchPath | -scotchArchPath
-system-compiler -system
-third-compiler -third
USAGE
exit 0 # clean exit
exit 0 # A clean exit
}
......@@ -123,11 +151,12 @@ die()
}
# -----------------------------------------------------------------------------
projectDir="$(\pwd -L)" # Project dir
# Check that it appears to be an OpenFOAM installation
if [ -f etc/bashrc ] && [ -d "META-INFO" ]
then
echo "Configuring OpenFOAM" 1>&2
echo "Configuring OpenFOAM ($projectDir)" 1>&2
else
die "Please run from the OpenFOAM top-level installation directory" \
"No etc/bashrc or META-INFO/ found"
......@@ -172,18 +201,22 @@ _inlineSed()
local replacement="$3"
local msg="$4"
local cmd='/^[^#]/s@'"$regexp"'@'"$replacement"'@'
local localFile
[ -f "$file" ] || {
echo "Missing file: $file"
exit 2 # Fatal
}
# Local filename (for reporting)
localFile="$(echo "$file" | sed -e "s#^$projectDir/##")"
grep -q "$regexp" "$file" && sed -i -e "$cmd" "$file" || { \
echo "Failed: ${msg:-replacement} in $file"
echo "Failed: ${msg:-replacement} in $localFile"
return 1
}
[ -n "$msg" ] && echo " $msg ($file)"
[ -n "$msg" ] && echo " $msg ($localFile)"
return 0
}
......@@ -209,7 +242,7 @@ replace()
"$file" \
"$key=.*" \
"$key=$val" \
"Replaced $key setting by '$val'"
"Replaced $key by '$val'"
done
}
......@@ -232,9 +265,9 @@ replaceCsh()
_inlineSed \
"$file" \
"setenv *$key [^ #]*" \
"setenv [ ]*$key [^ #]*" \
"setenv $key $val" \
"Replaced $key setenv by '$val'"
"Replaced $key by '$val'"
done
}
......@@ -323,7 +356,13 @@ unset adjusted optMpi
while [ "$#" -gt 0 ]
do
case "$1" in
-h | -help* | --help*)
-help-c*) # Compat help
printHelp -compat
;;
-help-f*) # Full help
printHelp -full
;;
-h | -help*) # Short help
printHelp
;;
'')
......@@ -516,12 +555,12 @@ CONFIG_CSH
_inlineSed $(_foamEtc config.sh/mpi) \
"FOAM_MPI=$expected" \
"FOAM_MPI=$optMpi" \
"Replaced 'FOAM_MPI=$expected' setting by 'FOAM_MPI=$optMpi'"
"Replaced 'FOAM_MPI=$expected' by 'FOAM_MPI=$optMpi'"
_inlineSed $(_foamEtc config.csh/mpi) \
"FOAM_MPI $expected" \
"FOAM_MPI $optMpi" \
"Replaced 'FOAM_MPI $expected' setting by 'FOAM_MPI $optMpi'"
"Replaced 'FOAM_MPI $expected' by 'FOAM_MPI $optMpi'"
replaceEtc bashrc WM_MPLIB OPENMPI
replaceEtcCsh cshrc WM_MPLIB OPENMPI
......@@ -711,11 +750,11 @@ CONFIG_CSH
shift
;;
-vtk)
# Replace vtk_version=...
-llvm)
# Replace mesa_llvm=...
optionValue=$(getOptionValue "$@")
replaceEtc config.sh/vtk vtk_version "$optionValue"
replaceEtc config.csh/vtk vtk_version "$optionValue"
replaceEtc config.sh/vtk mesa_llvm "$optionValue"
replaceEtc config.csh/vtk mesa_llvm "$optionValue"
adjusted=true
shift
;;
......@@ -729,6 +768,42 @@ CONFIG_CSH
shift
;;
-vtk)
# Replace vtk_version=...
optionValue=$(getOptionValue "$@")
replaceEtc config.sh/vtk vtk_version "$optionValue"
replaceEtc config.csh/vtk vtk_version "$optionValue"
adjusted=true
shift
;;
-llvm-path)
# Replace LLVM_ARCH_PATH=...