mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
- 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.
387 lines
11 KiB
Bash
Executable File
387 lines
11 KiB
Bash
Executable File
#!/bin/sh
|
|
#------------------------------------------------------------------------------
|
|
# ========= |
|
|
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
|
# \\ / O peration |
|
|
# \\ / A nd | Copyright (C) 2017-2018 OpenCFD Ltd.
|
|
# \\/ M anipulation | Copyright (C) 2016-2017 CINECA
|
|
#------------------------------------------------------------------------------
|
|
# 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
|
|
# foamCreateModuleInclude
|
|
#
|
|
# Description
|
|
# Script to create module settings.
|
|
# This is still incomplete, but can be a useful basis when using a module
|
|
# system.
|
|
#------------------------------------------------------------------------------
|
|
usage() {
|
|
exec 1>&2
|
|
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
|
|
cat<<USAGE
|
|
|
|
usage: ${0##*/} [OPTION] projectDir
|
|
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
|
|
|
|
Create module settings for inclusion in a top-level openfoam module.
|
|
|
|
USAGE
|
|
exit 1
|
|
}
|
|
|
|
# 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
|
|
}
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
unset optBackend optDebug preload projectDir
|
|
unset moduleOutput moduleTmpDir
|
|
|
|
# Parse some options
|
|
while [ "$#" -gt 0 ]
|
|
do
|
|
case "$1" in
|
|
'')
|
|
# Ignore empty args
|
|
;;
|
|
-h | -help*)
|
|
usage
|
|
;;
|
|
-debug)
|
|
optDebug=true
|
|
;;
|
|
-preload=*)
|
|
preload="$preload${preload:+ }${1#*=}"
|
|
;;
|
|
--recursive-backend--)
|
|
optBackend=true
|
|
;;
|
|
--output=*)
|
|
moduleOutput="${1#*=}"
|
|
;;
|
|
--tmpdir=*)
|
|
moduleTmpDir="${1#*=}"
|
|
;;
|
|
-*)
|
|
die "unknown option: $1"
|
|
;;
|
|
*)
|
|
break
|
|
;;
|
|
esac
|
|
shift
|
|
done
|
|
|
|
[ "$#" -eq 1 ] || die "missing projectDir, or too many arguments"
|
|
projectDir="${1%/}"
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
# Filter accepts system paths only
|
|
syspath() {
|
|
local path
|
|
|
|
set -- $(echo "${1}" | tr ':' '\n' )
|
|
for i in $@
|
|
do
|
|
case $i in
|
|
/bin | /usr/bin | /usr/lib*)
|
|
path="${path}${path:+:}$i";;
|
|
esac
|
|
done
|
|
echo "$path"
|
|
}
|
|
|
|
|
|
# Frontend: do all basic sanity checks in the front-end only
|
|
if [ -z "$optBackend" ]
|
|
then
|
|
# Check that it appears to be an OpenFOAM installation
|
|
[ -d "$projectDir" -a -f "$projectDir/etc/bashrc" ] || \
|
|
die "Incorrect projectDir? $projectDir"
|
|
|
|
# Check preloads
|
|
for file in $preloads
|
|
do
|
|
[ -f "$file" ] || echo "No such file to preload: $file" 1>&2
|
|
done
|
|
|
|
# Call itself with clean environment.
|
|
# 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-- \
|
|
"${optDebug:+-debug}" \
|
|
"${output:+-output=$moduleOutput}" \
|
|
"${preloads:+-preload=$preloads}" \
|
|
"${moduleTmpDir:+-tmpdir=$moduleTmpDir}" \
|
|
$projectDir
|
|
|
|
exitCode=$? # exec failed?
|
|
|
|
echo "exec somehow failed?" 1>&2
|
|
exit $exitCode
|
|
fi
|
|
|
|
#------------------------------------------------------------------------------
|
|
# Backend
|
|
|
|
: ${moduleOutput:=ModuleInclude.tcl}
|
|
: ${moduleTmpDir:=${TMPDIR:-/tmp}}
|
|
|
|
# Preload any/all modules
|
|
for file in $preloads
|
|
do
|
|
[ -f "$file" ] && . "$file" ''
|
|
done
|
|
|
|
# Temporary files
|
|
tmpFiles="$moduleTmpDir/modules-$USER.$$"
|
|
if [ -n "$optDebug" ]
|
|
then
|
|
echo "Preserving intermediate files: $tmpFiles.*" 1>&2
|
|
else
|
|
trap 'rm -f $tmpFiles.* 2>/dev/null; exit 0' EXIT TERM INT
|
|
fi
|
|
|
|
|
|
# Snapshot of aliases - sorted
|
|
printAlias()
|
|
{
|
|
alias | sort -f
|
|
}
|
|
|
|
|
|
# Snapshot of environment - without functions
|
|
# Sorted as non-OpenFOAM, WM_*, FOAM_*
|
|
printEnv()
|
|
{
|
|
# Non FOAM_*, WM_* settings
|
|
echo "# non-OpenFOAM"
|
|
env | sed -n -e '\@^FOAM_@d' -e '\@^WM_@d' -e '\@^[^ {}]@p' \
|
|
| sort -f
|
|
|
|
# WM_* settings
|
|
echo "# OpenFOAM"
|
|
env | sed -n -e '\@^WM_@p' \
|
|
| sort -f
|
|
|
|
# FOAM_* settings
|
|
echo "# OpenFOAM"
|
|
env | sed -n -e '\@^FOAM_@p' \
|
|
| sort -f
|
|
}
|
|
|
|
#
|
|
# Initial snapshot of the environment (without functions)
|
|
#
|
|
printEnv > $tmpFiles.env.pre.log
|
|
printAlias > $tmpFiles.alias.pre.log
|
|
|
|
# OpenFOAM settings
|
|
. $projectDir/etc/bashrc ''
|
|
|
|
echo "Using openfoam: $WM_PROJECT_DIR" 1>&2
|
|
echo "==> $moduleOutput" 1>&2
|
|
|
|
# Remove some cruft
|
|
unset FOAM_JOB_DIR FOAM_RUN FOAM_SETTINGS FOAM_INST_DIR WM_PROJECT_INST_DIR
|
|
unset WM_PROJECT_USER_DIR WM_THIRD_PARTY_DIR
|
|
unset SCOTCH_VERSION
|
|
|
|
|
|
# Also remove user directories as being unreliable
|
|
|
|
foamOldDirs="$CEI_HOME $BOOST_ARCH_PATH $CGAL_ARCH_PATH $FFTW_ARCH_PATH $MPI_ARCH_PATH $SCOTCH_ARCH_PATH \
|
|
$FOAM_SITE_APPBIN $FOAM_SITE_LIBBIN $WM_PROJECT_SITE \
|
|
$FOAM_USER_APPBIN $FOAM_USER_LIBBIN"
|
|
foamClean=$WM_PROJECT_DIR/bin/foamCleanPath
|
|
|
|
if [ -x "$foamClean" ]
|
|
then
|
|
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
|
|
eval $($foamClean -sh-env=LD_LIBRARY_PATH "$FOAM_EXT_LIBBIN")
|
|
unset FOAM_EXT_LIBBIN
|
|
fi
|
|
fi
|
|
unset CEI_HOME
|
|
unset ENSIGHT9_INPUT ENSIGHT9_READER
|
|
unset ENSIGHT10_INPUT ENSIGHT10_READER
|
|
|
|
# Always consider site to be bogus. If needed, should be done elsewhere.
|
|
unset FOAM_SITE_APPBIN FOAM_SITE_LIBBIN WM_PROJECT_SITE
|
|
|
|
# Remove non-essential aliases
|
|
unalias wmDP 2>/dev/null
|
|
unalias wmInt32 2>/dev/null
|
|
unalias wmInt64 2>/dev/null
|
|
unalias wmSP 2>/dev/null
|
|
unalias wmSchedOff 2>/dev/null
|
|
unalias wmSchedOn 2>/dev/null
|
|
unalias wmSet 2>/dev/null
|
|
unalias wmUnset 2>/dev/null
|
|
unalias app 2>/dev/null
|
|
unalias foamSite 2>/dev/null
|
|
unalias lib 2>/dev/null
|
|
unalias run 2>/dev/null
|
|
unalias sol 2>/dev/null
|
|
unalias src 2>/dev/null
|
|
unalias tut 2>/dev/null
|
|
unalias util 2>/dev/null
|
|
|
|
#------------------------------------------------
|
|
|
|
# Generalize environment.
|
|
# This needs rethinking since it largely duplicates logic from the etc/config.sh/settings
|
|
rewriteEnv()
|
|
{
|
|
sed \
|
|
-e 's@^\(FOAM_USER_APPBIN=\).*@\1$env(HOME)/OpenFOAM/$env(USER)-$env(WM_PROJECT_VERSION)/platforms/$env(WM_OPTIONS)/bin@' \
|
|
-e 's@^\(FOAM_USER_LIBBIN=\).*@\1$env(HOME)/OpenFOAM/$env(USER)-$env(WM_PROJECT_VERSION)/platforms/$env(WM_OPTIONS)/lib@' \
|
|
;
|
|
}
|
|
|
|
#
|
|
# Updated snapshot of the environment (without functions)
|
|
#
|
|
printEnv | rewriteEnv > $tmpFiles.env.post.log
|
|
printAlias > $tmpFiles.alias.post.log
|
|
|
|
|
|
# Create a diff of the environment and aliases
|
|
diff $tmpFiles.env.pre.log $tmpFiles.env.post.log > $tmpFiles.env.diff.log
|
|
diff $tmpFiles.alias.pre.log $tmpFiles.alias.post.log > $tmpFiles.alias.diff.log
|
|
|
|
echo "# -------------------" > $moduleOutput
|
|
|
|
# --------------------------------------------------
|
|
# 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
|
|
|
|
|
|
# --------------------------------------------------
|
|
# Changes in PATH - without junk and system directories
|
|
echo "# PATH" >> $moduleOutput
|
|
|
|
sed -ne 's/^< *PATH=//p' $tmpFiles.env.diff.log | tr ':' '\n' > $tmpFiles.path.pre.log
|
|
sed -ne 's/^> *PATH=//p' $tmpFiles.env.diff.log | tr ':' '\n' > $tmpFiles.path.post.log
|
|
|
|
grep -vxFf $tmpFiles.path.pre.log $tmpFiles.path.post.log | \
|
|
sed \
|
|
-e '\@^/bin$@d' \
|
|
-e '\@^/usr/bin$@d' \
|
|
-e '\@^/usr/local/bin$@d' \
|
|
-e '\@^[.]$@d' \
|
|
-e '\@^$@d' \
|
|
> $tmpFiles.path.diff.log
|
|
|
|
sed \
|
|
-e 's/^/append-path PATH "/' \
|
|
-e 's/$/\"/' \
|
|
$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
|
|
|
|
sed -ne 's/^< *LD_LIBRARY_PATH=//p' $tmpFiles.env.diff.log | tr ':' '\n' > $tmpFiles.ldpath.pre.log
|
|
sed -ne 's/^> *LD_LIBRARY_PATH=//p' $tmpFiles.env.diff.log | tr ':' '\n' > $tmpFiles.ldpath.post.log
|
|
|
|
grep -vxFf $tmpFiles.ldpath.pre.log $tmpFiles.ldpath.post.log | \
|
|
sed \
|
|
-e '\@^/lib.*$@d' \
|
|
-e '\@^/usr/lib.*$@d' \
|
|
-e '\@^/usr/local/lib.*$@d' \
|
|
-e '\@^[.]$@d' \
|
|
-e '\@^$@d' \
|
|
> $tmpFiles.ldpath.diff.log
|
|
|
|
sed \
|
|
-e 's/^/append-path LD_LIBRARY_PATH "/' \
|
|
-e 's/$/\"/' \
|
|
$tmpFiles.ldpath.diff.log >> $moduleOutput
|
|
|
|
|
|
# -------------------
|
|
# aliases
|
|
# Some diff give "> alias". Others give ">", needed extended regular expressions '-r'
|
|
|
|
echo "# aliases" >> $moduleOutput
|
|
cat $tmpFiles.alias.diff.log | \
|
|
sed -r -n -e 's/^> (alias)?/set-alias /p' | \
|
|
sed -e "s/='/ \"/" -e "s/'/\"/g" >> $moduleOutput
|
|
|
|
echo "# -------------------" >> $moduleOutput
|
|
|
|
# -----------------------------------------------------------------------------
|