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.
This commit is contained in:
Mark Olesen 2018-12-02 18:25:57 +01:00
parent cacbcd98d9
commit 6c68c34e1a
33 changed files with 1428 additions and 714 deletions

5
META-INFO/.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
# Do not track build information
build-info
# Do not track time-stamp
time-stamp

84
META-INFO/README.md Normal file
View File

@ -0,0 +1,84 @@
# META-INFO
Meta-information is for OpenFOAM internal use only.
Do not rely on any files or any file contents in this directory,
or even the existence of this directory.
The format, content and meaning may be changed at anytime without
notice.
The information is provided here for internal documentation purposes.
## api-info
This file and its contents are to be tracked by git.
- File content (api) generated by wmakeBuildInfo from OPENFOAM define
in `wmake/rules/General/general`
- File content (patch) is manually generated content.
## build-info
This file is *never* to be tracked by git, but may be present in shipped
source archives.
- File content (branch, build) generated by wmakeBuildInfo from git
information and cached from previous wmake (api)
## Content types
### api
- 4-digit year-month (YYMM) integer corresponding to the major
release or in unusual cases an intermediate release.
- Format is year-month, as per `date +%y%m`.
Eg, `1712` for the Dec-2017 release.
### patch
- 6-digit year-month-day (YYMMDD) integer corresponding to a patch-level
for the given **released** API.
Development branches have a patch value of `0`.
- Format is year-month-day, as per `date +%y%m%d`.
- The first release is by definition unpatched, and thus carries
a patch value of `0`. If this release were to be patched the following
day, the patch level would jump accordingly.
The patch value is only meaningful together with the api value.
## Flow of information
Changes in the build information must be reflected in information
available in the final binaries. Conversely, it is necessary for later
distributions to have a record of the same information.
| property | source | saved |
|-----------|---------------------------|------------|
| api | wmake/rules | api-info |
| patch | manual (api-info) | build-info |
| branch | git | build-info |
| build | git | build-info |
The command `wmakeBuildInfo -check` is used to determine if
the saved information needs synchronization. The command
`wmakeBuildInfo -update` preforms the synchronitzation.
## Notes
The saved information is split into two separate files. The `api-info`
contains more permanent information, whereas the `build-info` is more
transient in nature.
----
2018-11-29

2
META-INFO/api-info Normal file
View File

@ -0,0 +1,2 @@
api=1811
patch=0

View File

@ -24,21 +24,20 @@
# \endcode # \endcode
# #
# The -mode option can also be used when chaining settings. # The -mode option can also be used when chaining settings.
# For example, in the user ~/.OpenFOAM/<VERSION>/config.sh/compiler # For example, in the user ~/.OpenFOAM/config.sh/compiler
# \code # \code
# eval $(foamEtcFile -sh -mode=go config.sh/compiler) # eval $(foamEtcFile -sh -mode=go config.sh/compiler)
# \endcode # \endcode
# #
# Environment # Environment
# - WM_PROJECT (unset defaults to OpenFOAM) # - WM_PROJECT_SITE (unset defaults to PROJECT/site)
# - WM_PROJECT_VERSION (unset defaults to detect from path)
# - WM_PROJECT_SITE (unset defaults to PREFIX/site)
# #
# Note # Note
# This script must exist in one of these locations: # This script must exist in the project 'bin' directory
# - PREFIX/OpenFOAM-<VERSION>/bin #
# - PREFIX/openfoam-<VERSION>/bin # The '-show-api' and '-show-patch' options implement partial logic
# - PREFIX/openfoam<VERSION>/bin # from wmake/wmakeBuildInfo.
# Make sure that any changes there are also reflected here.
# #
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
printHelp() { printHelp() {
@ -52,8 +51,6 @@ options:
-list (-l) List directories or files to be checked -list (-l) List directories or files to be checked
-list-test List (existing) directories or files to be checked -list-test List (existing) directories or files to be checked
-mode=MODE Any combination of u(user), g(group), o(other) -mode=MODE Any combination of u(user), g(group), o(other)
-prefix=DIR Specify an alternative installation prefix
-version=VER Specify alternative OpenFOAM version (eg, 1712, 1806, ...)
-csh Produce 'source FILE' output for a csh eval -csh Produce 'source FILE' output for a csh eval
-sh Produce '. FILE' output for a sh eval -sh Produce '. FILE' output for a sh eval
-csh-verbose As per -csh, with additional verbosity -csh-verbose As per -csh, with additional verbosity
@ -61,6 +58,9 @@ options:
-config Add config directory prefix for shell type: -config Add config directory prefix for shell type:
with -csh* for a config.csh/ prefix with -csh* for a config.csh/ prefix
with -sh* for a config.sh/ 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
-with-api=NUM Specify alternative api value to search with
-quiet (-q) Suppress all normal output -quiet (-q) Suppress all normal output
-silent (-s) Suppress stderr, except -csh-verbose, -sh-verbose output -silent (-s) Suppress stderr, except -csh-verbose, -sh-verbose output
-help Print the usage -help Print the usage
@ -70,8 +70,8 @@ Locate user/group/other file as per '#includeEtc'
Do not group single character options. Do not group single character options.
Equivalent options: Equivalent options:
| -mode=MODE | -mode MODE | -m MODE | -mode=MODE | -mode MODE | -m MODE
| -prefix=DIR | -prefix DIR | -p DIR | -prefix=DIR | -prefix DIR | -p DIR [obsolete 1812]
| -version=VER | -version VER | -v VER | -version=VER | -version VER | -v VER [obsolete 1812]
Exit status Exit status
0 when the file is found. Print resolved path to stdout. 0 when the file is found. Print resolved path to stdout.
@ -98,80 +98,71 @@ die()
} }
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
binDir="${0%/*}" # The bin dir binDir="${0%/*}" # The bin dir
projectDir="${binDir%/bin}" # The project dir projectDir="$(\cd $(dirname $binDir) && \pwd -L)" # Project dir
prefixDir="${projectDir%/*}" # The prefix dir (same as $WM_PROJECT_INST_DIR)
# Could not resolve projectDir, prefixDir? (eg, called as ./bin/foamEtcFile) userDir="$HOME/.OpenFOAM" # As per foamVersion.H
if [ "$prefixDir" = "$projectDir" ] groupDir="${WM_PROJECT_SITE:-$projectDir/site}" # As per foamVersion.H
then
binDir="$(cd $binDir && pwd -L)"
projectDir="${binDir%/bin}"
prefixDir="${projectDir%/*}"
fi
projectDirName="${projectDir##*/}" # The project directory name
projectVersion="$WM_PROJECT_VERSION" # Empty? - will be treated later
userDir="$HOME/.OpenFOAM" # Hard-coded as per foamVersion.H
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
# Guess project version or simply get the stem part of the projectDirName. # The API locations. See wmake/wmakeBuildInfo
# Handle standard naming conventions: rulesFile="$projectDir/wmake/rules/General/general"
metaInfoDir="$projectDir/META-INFO"
# Get api from rules/General/general
# #
# * OpenFOAM-<version>[-extra...] # Failure modes:
# * openfoam-<version>[-extra...] # - No api information (can't find file etc).
# * openfoam<digits> # -> Fatal for building, but could be OK for a stripped down version
# #
# - projectVersion: update unless already set # Fallback. Get from api-info
# #
# Helper variables: getApi()
# - dirBase (for reassembling name) == projectDirName without the version
unset dirBase
guessVersion()
{ {
local version local value
case "$projectDirName" in value="$(sed -ne '/^ *#/!{ /WM_VERSION.*OPENFOAM=/{ s@^.*OPENFOAM= *\([0-9][0-9]*\).*@\1@p; q }}' $rulesFile 2>/dev/null)"
(OpenFOAM-* | openfoam-*) if [ -z "$value" ] && [ -f "$metaInfoDir/api-info" ]
# Dashed naming: OpenFOAM-<VERSION> or openfoam-<VERSION> then
dirBase="${projectDirName%%-*}-" # Fallback. Get from api-info
version="${projectDirName#*-}" value="$(sed -ne 's@^ *api *= *\([0-9][0-9]*\).*@\1@p' $metaInfoDir/api-info 2>/dev/null)"
version="${version%%*-}" # Extra safety, eg openfoam-version-packager fi
;;
(openfoam[0-9]*) if [ -n "$value" ]
# Debian-style naming: openfoam<VERSION> then
dirBase="openfoam" echo "$value"
version="${projectDirName#openfoam}" else
;; return 1
fi
(*)
die "unknown/unsupported naming convention for '$projectDirName'"
;;
esac
# Set projectVersion if required
: ${projectVersion:=$version}
} }
# Set projectVersion and update versionNum, projectDirName accordingly # Get patch from meta-info / api-info
setVersion() #
# Failure modes:
# - No patch information (can't find file etc).
#
getPatchLevel()
{ {
projectVersion="$1" local value
# Need dirBase when reassembling projectDirName # Fallback. Get from api-info
[ -n "$dirBase" ] || guessVersion value="$(sed -ne 's@^ *patch *= *\([0-9][0-9]*\).*@\1@p' $metaInfoDir/api-info 2>/dev/null)"
projectDirName="$dirBase$projectVersion" if [ -n "$value" ]
then
echo "$value"
else
return 1
fi
} }
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
optMode=ugo # Default mode is always 'ugo' optMode=ugo # Default mode is always 'ugo'
unset shellOutput verboseOutput unset shellOutput verboseOutput
unset optAll optConfig optList optVersion unset optAll optConfig optList projectApi
# Parse options # Parse options
while [ "$#" -gt 0 ] while [ "$#" -gt 0 ]
@ -180,6 +171,19 @@ do
-h | -help*) -h | -help*)
printHelp printHelp
;; ;;
-show-api)
# Show API and exit
getApi
exit $?
;;
-show-patch)
# Show patch level and exit
getPatchLevel
exit $?
;;
-with-api=*)
projectApi="${1#*=}"
;;
-a | -all) -a | -all)
optAll=true optAll=true
unset shellOutput verboseOutput unset shellOutput verboseOutput
@ -204,13 +208,6 @@ do
-mode=[ugo]*) -mode=[ugo]*)
optMode="${1#*=}" optMode="${1#*=}"
;; ;;
-prefix=/*)
prefixDir="${1#*=}"
prefixDir="${prefixDir%/}"
;;
-version=*)
optVersion="${1#*=}"
;;
-m | -mode) -m | -mode)
optMode="$2" optMode="$2"
shift shift
@ -223,22 +220,23 @@ do
;; ;;
esac esac
;; ;;
-p | -prefix)
[ "$#" -ge 2 ] || die "'$1' option requires an argument"
prefixDir="${2%/}"
shift
;;
-q | -quiet) -q | -quiet)
optQuiet=true optQuiet=true
;; ;;
-s | -silent) -s | -silent)
optSilent=true optSilent=true
;; ;;
-v | -version)
-prefix=* | -version=*)
echo "ignored defunct option '${1%%=*}'" 1>&2
;;
-p | -prefix | -v | -version)
# Ignored, but still need to check/discard its argument
[ "$#" -ge 2 ] || die "'$1' option requires an argument" [ "$#" -ge 2 ] || die "'$1' option requires an argument"
optVersion="$2" echo "ignored defunct option '$1'" 1>&2
shift shift
;; ;;
--) --)
shift shift
break break
@ -255,6 +253,10 @@ done
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
# Establish the API value
[ -n "$projectApi" ] || projectApi=$(getApi)
# Split arguments into filename (for searching) and trailing bits for shell eval # Split arguments into filename (for searching) and trailing bits for shell eval
# Silently remove leading ~OpenFOAM/ (as per Foam::findEtcFile) # Silently remove leading ~OpenFOAM/ (as per Foam::findEtcFile)
nArgs=$# nArgs=$#
@ -279,25 +281,9 @@ then
fi fi
# Get version information
if [ -n "$optVersion" ]
then
setVersion $optVersion
elif [ -z "$projectVersion" ]
then
guessVersion
fi
# Updates:
# - projectDir for changes via -prefix or -version
# - groupDir for changes via -prefix
projectDir="$prefixDir/$projectDirName"
groupDir="${WM_PROJECT_SITE:-$prefixDir/site}"
# Debugging: # Debugging:
# echo "Installed locations:" 1>&2 # echo "Installed locations:" 1>&2
# for i in projectDir prefixDir projectDirName projectVersion # for i in projectDir
# do # do
# eval echo "$i=\$$i" 1>&2 # eval echo "$i=\$$i" 1>&2
# done # done
@ -305,12 +291,12 @@ groupDir="${WM_PROJECT_SITE:-$prefixDir/site}"
# Define the various places to be searched: # Define the various places to be searched:
unset dirList unset dirList
case "$optMode" in (*u*) # (U)ser case "$optMode" in (*u*) # (U)ser
dirList="$dirList $userDir/$projectVersion $userDir" dirList="$dirList $userDir/$projectApi $userDir"
;; ;;
esac esac
case "$optMode" in (*g*) # (G)roup == site case "$optMode" in (*g*) # (G)roup == site
dirList="$dirList $groupDir/$projectVersion/etc $groupDir/etc" dirList="$dirList $groupDir/$projectApi/etc $groupDir/etc"
;; ;;
esac esac

View File

@ -1,145 +0,0 @@
#!/bin/bash
#------------------------------------------------------------------------------
# ========= |
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
# \\ / O peration |
# \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
# \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
#-------------------------------------------------------------------------------
# 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
# foamExec
#
# Description
# Usage: foamExec [-version=foamVersion] <foamCommand> ...
#
# Runs the <foamVersion> version of executable <foamCommand>
# with the rest of the arguments.
#
# Can also be used for parallel runs. For example,
# \code
# mpirun -np <nProcs> \
# foamExec -version=VERSION <foamCommand> ... -parallel
# \endcode
#
# Note
# This script must exist in $WM_PROJECT_INST_DIR/OpenFOAM-<VERSION>/bin
# or $WM_PROJECT_INST_DIR/openfoam<VERSION>/bin (debian)
#
# foamEtcFile located in the same directory as this script
#
# See also
# foamEtcFile
#
#------------------------------------------------------------------------------
usage() {
exec 1>&2
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
cat<<USAGE
Usage: ${0##*/} [OPTION] <application> ...
options:
-mode=MODE Any combination of u(user), g(group), o(other)
-prefix=DIR Specify an alternative installation prefix
pass through to foamEtcFile
-version=VER Specify alternative OpenFOAM version (eg, 3.0, 1612, ...)
pass through to foamEtcFile
-help Print the usage
Run a particular OpenFOAM version of <APPLICATION>
USAGE
exit 1
}
#-------------------------------------------------------------------------------
binDir="${0%/*}" # The bin dir
projectDir="${binDir%/bin}" # The project dir
# prefixDir="${projectDir%/*}" # The prefix dir (same as $WM_PROJECT_INST_DIR)
projectVersion="${WM_PROJECT_VERSION:-unknown}"
unset etcOpts
# parse options
while [ "$#" -gt 0 ]
do
case "$1" in
-h | -help*)
usage
;;
-mode=*)
etcOpts="$etcOpts $1" # pass-thru to foamEtcFile
;;
-prefix=/*)
etcOpts="$etcOpts $1" # pass-thru to foamEtcFile
;;
-version=*)
etcOpts="$etcOpts $1" # pass-thru to foamEtcFile
projectVersion="${1#*=}" # for reporting
;;
-m | -mode)
[ "$#" -ge 2 ] || usage "'$1' option requires an argument"
etcOpts="$etcOpts $1 $2" # pass-thru to foamEtcFile
shift
;;
-p | -prefix)
[ "$#" -ge 2 ] || usage "'$1' option requires an argument"
etcOpts="$etcOpts $1 $2" # pass-thru to foamEtcFile
shift
;;
-v | -version)
[ "$#" -ge 2 ] || usage "'$1' option requires an argument"
etcOpts="$etcOpts $1 $2" # pass-thru to foamEtcFile
projectVersion="$2" # for reporting
shift
;;
--)
shift
break
;;
-*)
usage "invalid option '$1'"
;;
*)
break
;;
esac
shift
done
# Find and source the OpenFOAM <etc/bashrc>
# placed in function to preserve command-line arguments
sourceBashrc()
{
rcFile="$($binDir/foamEtcFile $etcOpts bashrc)" || {
echo "Error: bashrc file could not be found for OpenFOAM-$projectVersion" 1>&2
exit 2
}
. $rcFile $FOAM_SETTINGS
}
[ "$#" -ge 1 ] || usage "no application specified"
sourceBashrc
exec "$@"
#------------------------------------------------------------------------------

View File

@ -297,9 +297,7 @@ reportExecutable()
checkOpenFOAMEnvironment() checkOpenFOAMEnvironment()
{ {
[ -d "$WM_PROJECT_INST_DIR" ] && \ [ -d "$WM_PROJECT_DIR" ] && [ -d "$WM_THIRD_PARTY_DIR" ] || {
[ -d "$WM_PROJECT_DIR" ] && \
[ -d "$WM_THIRD_PARTY_DIR" ] || {
echo "" echo ""
echo "FATAL ERROR: OpenFOAM environment not configured." echo "FATAL ERROR: OpenFOAM environment not configured."
echo "" echo ""
@ -389,7 +387,6 @@ COL5="Crit"
hline hline
echo "$COL1 $COL2 $COL3 $COL5" echo "$COL1 $COL2 $COL3 $COL5"
hline hline
reportEnv '$WM_PROJECT_INST_DIR' noPath yes
reportEnv '$WM_PROJECT_USER_DIR' noPath no reportEnv '$WM_PROJECT_USER_DIR' noPath no
reportEnv '$WM_THIRD_PARTY_DIR' noPath yes reportEnv '$WM_THIRD_PARTY_DIR' noPath yes
hline hline
@ -415,11 +412,12 @@ hline
reportEnv '$FOAM_LIBBIN' '$LD_LIBRARY_PATH' yes reportEnv '$FOAM_LIBBIN' '$LD_LIBRARY_PATH' yes
reportEnv '$FOAM_SITE_LIBBIN' '$LD_LIBRARY_PATH' no reportEnv '$FOAM_SITE_LIBBIN' '$LD_LIBRARY_PATH' no
reportEnv '$FOAM_USER_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 reportEnv '$MPI_ARCH_PATH' '$LD_LIBRARY_PATH' yes
hline hline
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
heading "Third-party software" heading "Software Components"
hline hline
echo "$(fixlen Software 9) $(fixlen Version 10) $(fixlen Location 10)" echo "$(fixlen Software 9) $(fixlen Version 10) $(fixlen Location 10)"
hline hline

View File

@ -28,11 +28,16 @@
# Description # Description
# Extract data for each time-step from a log file for graphing. # Extract data for each time-step from a log file for graphing.
# #
# Environment
# WM_PROJECT_API
# WM_PROJECT_DIR
# WM_PROJECT_SITE
#
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
Script=${0##*/} Script="${0##*/}"
toolsDir=${0%/*}/tools toolsDir="${0%/*}/tools"
siteDir="${WM_PROJECT_SITE:-${WM_PROJECT_DIR:-<unknown>}/site}" groupDir="${WM_PROJECT_SITE:-${WM_PROJECT_DIR:-<unknown>}/site}"
userDir=$HOME/.OpenFOAM userDir="$HOME/.OpenFOAM"
usage() { usage() {
exec 1>&2 exec 1>&2
@ -85,11 +90,11 @@ cat <<HELP
The database ($Script.db) will taken from these locations: The database ($Script.db) will taken from these locations:
. .
$userDir/$WM_PROJECT_VERSION $userDir/$WM_PROJECT_API/
$userDir $userDir/
$siteDir/$WM_PROJECT_VERSION $groupDir/$WM_PROJECT_API/etc/
$siteDir $groupDir/etc/
$WM_PROJECT_DIR/etc $WM_PROJECT_DIR/etc/
$toolsDir $toolsDir
option -quiet : suppresses the default information and only prints the option -quiet : suppresses the default information and only prints the

View File

@ -4,7 +4,7 @@
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox # \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
# \\ / O peration | # \\ / O peration |
# \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation # \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
# \\/ M anipulation | # \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
# License # License
# This file is part of OpenFOAM. # This file is part of OpenFOAM.
@ -29,10 +29,15 @@
# Create a new case from a template for particular applications # Create a new case from a template for particular applications
# - requires rsync # - requires rsync
# #
# Environment
# WM_PROJECT_API
# WM_PROJECT_DIR
# WM_PROJECT_SITE
#
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
siteDir="${WM_PROJECT_SITE:-${WM_PROJECT_DIR:-<unknown>}/site}" groupDir="${WM_PROJECT_SITE:-${WM_PROJECT_DIR:-<unknown>}/site}"
userDir="$HOME/.OpenFOAM" userDir="$HOME/.OpenFOAM"
version="${WM_PROJECT_VERSION:-unknown}" projectApi="${WM_PROJECT_API:-unknown}"
templateDir="appTemplates" templateDir="appTemplates"
@ -44,20 +49,22 @@ usage() {
Usage: ${0##*/} [OPTION] Usage: ${0##*/} [OPTION]
options: options:
-app <name> specify the application to use -app NAME specify the application to use
-case <dir> specify alternative case directory, default is the cwd -case DIR specify alternative case directory, default is the cwd
-list list the applications available -list list the applications available
-version <ver> specify an alternative version (default: '$WM_PROJECT_VERSION') -with-api=NUM specify alternative api to use (default: \$WM_PROJECT_API)
-version VER [obsolete]
-help Print the usage
clone initial application settings to the specified case from clone initial application settings to the specified case from
$userDir/$templateDir/{$version,}/<APP> $userDir/$templateDir/{$projectApi,}/APP
$siteDir/$templateDir/{$version,}/<APP> $groupDir/$templateDir/{$projectApi,}/APP
USAGE USAGE
exit 1 exit 1
} }
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
unset appName caseName listOpt unset appName caseName optList
# parse options # parse options
while [ "$#" -gt 0 ] while [ "$#" -gt 0 ]
@ -69,21 +76,23 @@ do
-app) -app)
[ "$#" -ge 2 ] || usage "'$1' option requires an argument" [ "$#" -ge 2 ] || usage "'$1' option requires an argument"
appName="$2" appName="$2"
shift 2 shift
;; ;;
-case) -case)
[ "$#" -ge 2 ] || usage "'$1' option requires an argument" [ "$#" -ge 2 ] || usage "'$1' option requires an argument"
caseName="$2" caseName="$2"
shift 2 shift
;; ;;
-l | -list) -l | -list)
listOpt=true optList=true
shift
;; ;;
-v | -ver | -version) -v | -ver | -version)
[ "$#" -ge 2 ] || usage "'$1' option requires an argument" [ "$#" -ge 2 ] || usage "'$1' option requires an argument"
version="$2" echo "ignored defunct option -version" 1>&2
shift 2 shift
;;
-with-api=*)
projectApi="${1#*=}"
;; ;;
-*) -*)
usage "unknown option: '$*'" usage "unknown option: '$*'"
@ -92,19 +101,16 @@ do
usage "unexpected argument: '$*'" usage "unexpected argument: '$*'"
;; ;;
esac esac
shift
done done
# need rsync, except for when listing # need rsync, except for when listing
type rsync >/dev/null 2>&1 || [ "$listOpt" = true ] || usage "Error: 'rsync' seems to be missing" command -v rsync >/dev/null 2>&1 || \
[ "$optList" = true ] || usage "Error: 'rsync' seems to be missing"
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
[ -n "$version" ] || {
echo "Error: no -version specified and \$WM_PROJECT_VERSION is not set"
exit 1
}
# #
# find apps in current directory # find apps in current directory
# considered an app if it has constant/ and system/ directories # considered an app if it has constant/ and system/ directories
@ -113,18 +119,23 @@ findApps()
{ {
for app in $(/bin/ls -d * 2>/dev/null) for app in $(/bin/ls -d * 2>/dev/null)
do do
[ -d "$app/constant" -a -d "$app/system" ] && echo $app [ -d "$app/constant" -a -d "$app/system" ] && echo "$app"
done done
} }
appList=$( appList=$(
for dir in $userDir/$templateDir $siteDir/$templateDir for dir in "$userDir/$templateDir" "$groupDir/$templateDir"
do do
if cd $dir 2>/dev/null if cd "$dir" 2>/dev/null
then then
findApps ## generic findApps ## generic
cd $version 2>/dev/null && findApps ## version-specific
## version-specific
if [ -n "$projectApi" ]
then
cd "$projectApi" 2>/dev/null && findApps
fi
fi fi
done | sort | uniq done | sort | uniq
) )
@ -142,7 +153,7 @@ listApps()
} }
if [ "$listOpt" = true ] if [ "$optList" = true ]
then then
listApps listApps
exit 0 exit 0
@ -160,11 +171,11 @@ fi
# get the corresponding srcDir name # get the corresponding srcDir name
srcDir=$( srcDir=$(
for dir in $userDir/$templateDir $siteDir/$templateDir for dir in "$userDir/$templateDir" "$groupDir/$templateDir"
do do
if [ -d $dir ] if [ -d $dir ]
then then
for appDir in $dir/$version/$appName $dir/$appName for appDir in "$dir/$projectApi/$appName" "$dir/$appName"
do do
if [ -d $appDir -a -d $appDir/constant -a -d $appDir/system ] if [ -d $appDir -a -d $appDir/constant -a -d $appDir/system ]
then then
@ -211,21 +222,6 @@ echo " syncing ..."
# sync updated files only, itemize changes so we know what is going on # sync updated files only, itemize changes so we know what is going on
rsync -aui $srcDir/ $newDir rsync -aui $srcDir/ $newDir
#
# reuse or create new FOAM_SETTINGS (useful for queuing systems)
#
if [ -e "$newDir/FOAM_SETTINGS" ]
then
echo " retaining FOAM_SETTINGS"
else
echo " creating FOAM_SETTINGS"
cat << SETTINGS > "$newDir/FOAM_SETTINGS"
APPLICATION=$appName
FOAM_VERSION=OpenFOAM-$version
SETTINGS
fi
echo Done echo Done
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------

View File

@ -4,7 +4,7 @@
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox # \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
# \\ / O peration | # \\ / O peration |
# \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation # \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
# \\/ M anipulation | # \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# License # License
# This file is part of OpenFOAM. # This file is part of OpenFOAM.
@ -44,7 +44,7 @@ options:
-help print the usage -help print the usage
Updates the header of application files and removes consecutive blank lines. Updates the header of application files and removes consecutive blank lines.
By default, writes current OpenFOAM version in the header. By default, writes current OpenFOAM API number version in the header.
An alternative version can be specified with the -version option. An alternative version can be specified with the -version option.
USAGE USAGE
@ -74,8 +74,12 @@ do
esac esac
done done
# constant width for version - default to WM_PROJECT_VERSION # Constant width for version - default to WM_PROJECT_API
version=$(printf %-36s ${version:-$WM_PROJECT_VERSION})
: ${version:=$WM_PROJECT_API}
: ${version:=$WM_PROJECT_VERSION}
version=$(printf %-36s ${version:-OPENFOAM})
[ $# -ge 1 ] || usage [ $# -ge 1 ] || usage

View File

@ -2,7 +2,7 @@
# ========= | # ========= |
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox # \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
# \\ / O peration | # \\ / O peration |
# \\ / A nd | Copyright (C) 2017 OpenCFD Ltd. # \\ / A nd | Copyright (C) 2017-2018 OpenCFD Ltd.
# \\/ M anipulation | # \\/ M anipulation |
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# License # License
@ -25,7 +25,7 @@
# . change-sitedir.sh PREFIX [SUFFIX] # . change-sitedir.sh PREFIX [SUFFIX]
# #
# Shortcuts (prefix) # Shortcuts (prefix)
# -prefix "$WM_PROJECT_INST_DIR/site" # -prefix "$WM_PROJECT_DIR/../site"
# -project "$WM_PROJECT_DIR/site" # -project "$WM_PROJECT_DIR/site"
# -none remove from environment # -none remove from environment
# #
@ -46,7 +46,7 @@
# #
# corresponds to the standard site location: # corresponds to the standard site location:
# #
# $WM_PROJECT_DIR/site{/$WM_PROJECT_VERSION/platforms/$WM_OPTIONS} # $WM_PROJECT_DIR/site{/$WM_PROJECT_API/platforms/$WM_OPTIONS}
# #
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
@ -56,7 +56,7 @@ then
suffix="$2" suffix="$2"
foamOldDirs="$FOAM_SITE_APPBIN $FOAM_SITE_LIBBIN \ foamOldDirs="$FOAM_SITE_APPBIN $FOAM_SITE_LIBBIN \
$WM_PROJECT_SITE $WM_PROJECT_INST_DIR/site $WM_PROJECT_DIR/site" $WM_PROJECT_SITE $WM_PROJECT_DIR/site"
foamClean=$WM_PROJECT_DIR/bin/foamCleanPath foamClean=$WM_PROJECT_DIR/bin/foamCleanPath
if [ -x "$foamClean" ] if [ -x "$foamClean" ]
then then
@ -66,12 +66,12 @@ then
fi fi
case "$suffix" in case "$suffix" in
-plat*) suffix="platforms/$WM_OPTIONS" ;; -plat*) suffix="platforms/$WM_OPTIONS" ;;
esac esac
case "$prefix" in case "$prefix" in
-prefix) prefix="$WM_PROJECT_INST_DIR/site" ;; -prefix) prefix="${WM_PROJECT_DIR%/*}/site" ;;
-project) prefix="$WM_PROJECT_DIR/site" ;; -project) prefix="$WM_PROJECT_DIR/site" ;;
-none) unset prefix ;; -none) unset prefix ;;
esac esac
if [ -n "$prefix" ] if [ -n "$prefix" ]

View File

@ -69,8 +69,8 @@ then
-plat*) suffix="platforms/$WM_OPTIONS" ;; -plat*) suffix="platforms/$WM_OPTIONS" ;;
esac esac
case "$prefix" in case "$prefix" in
-home) prefix="$HOME/OpenFOAM/$USER-${WM_PROJECT_VERSION:-unknown}" ;; -home) prefix="$HOME/OpenFOAM/$USER-${WM_PROJECT_VERSION:-unknown}" ;;
-none) unset prefix ;; -none) unset prefix ;;
esac esac
if [ -n "$prefix" ] if [ -n "$prefix" ]

View File

@ -25,9 +25,8 @@ usage() {
usage: ${0##*/} options usage: ${0##*/} options
Basic Basic
-prefix DIR specify installation directory (eg, /opt) -project-path DIR specify 'WM_PROJECT_DIR' (eg, /opt/openfoam1806-patch1)
-version VER specify project version (eg, 1612) -version VER specify project version (eg, v1806)
-projectName NAME specify project directory name (eg, openfoam1612)
-archOption 32|64 specify 'WM_ARCH_OPTION' architecture option -archOption 32|64 specify 'WM_ARCH_OPTION' architecture option
-SP | -float32 specify 'WM_PRECISION_OPTION' for single precision -SP | -float32 specify 'WM_PRECISION_OPTION' for single precision
-DP | -float64 specify 'WM_PRECISION_OPTION' for double precision -DP | -float64 specify 'WM_PRECISION_OPTION' for double precision
@ -61,31 +60,26 @@ Components
-metis ver specify 'METIS_VERSION' -metis ver specify 'METIS_VERSION'
-metis-path DIR specify 'METIS_ARCH_PATH' -metis-path DIR specify 'METIS_ARCH_PATH'
-scotch VER specify 'SCOTCH_VERSION' (eg, scotch_6.0.4) -scotch VER specify 'SCOTCH_VERSION' (eg, scotch_6.0.4)
-scotch-path DIR specify 'SCOTCH_ARCH_PATH' (eg, /opt/OpenFOAM-scotch_6.0.4) -scotch-path DIR specify 'SCOTCH_ARCH_PATH' (eg, /opt/scotch_6.0.4)
Graphics Graphics
-paraview VER specify 'ParaView_VERSION' (eg, 5.4.1) -paraview VER specify 'ParaView_VERSION' (eg, 5.4.1)
-paraview-qt VER specify 'ParaView_QT' (eg, qt-system)
-paraview-path DIR specify 'ParaView_DIR' (eg, /opt/ParaView-5.4.1) -paraview-path DIR specify 'ParaView_DIR' (eg, /opt/ParaView-5.4.1)
-vtk VER specify 'vtk_version' (eg, VTK-7.1.0) -vtk VER specify 'vtk_version' (eg, VTK-7.1.0)
-mesa VER specify 'mesa_version' (eg, mesa-13.0.1) -mesa VER specify 'mesa_version' (eg, mesa-13.0.1)
Misc Misc
-default-third default ThirdParty location: PREFIX/ThirdParty-VERSION -foamInstall DIR [obsolete]
-no-third use PROJECT/ThirdParty for ThirdParty location -projectName NAME [obsolete]
-third-path DIR specify 'WM_THIRD_PARTY_DIR' -sigfpe|-no-sigfpe [obsolete - now under etc/controlDict]
-default-site set PREFIX/site as fallback for WM_PROJECT_SITE
-no-site use PROJECT/site as fallback for WM_PROJECT_SITE
-sigfpe | -no-sigfpe [defunct - now under etc/controlDict]
Adjusts hardcoded versions and installation paths (for bash, POSIX shell). Adjusts hardcoded versions and installation paths (for bash, POSIX shell).
Equivalent options: Equivalent options:
-prefix -foamInstall --foamInstall -version -foamVersion --projectVersion
-version -foamVersion --projectVersion
-projectName --projectName
-archOption --archOption -archOption --archOption
-third -ThirdParty -third -ThirdParty
-paraview --paraviewVersion | -paraviewVersion -paraview --paraviewVersion | -paraviewVersion
@ -186,6 +180,31 @@ replace()
done done
} }
# Standard <key> <val> type of replacements.
# replace <file> <key1> <val1> .. <keyN> <valN>
# looks for "setenv KEYWORD value"
# but avoids "setenv KEYWORD" without a value
replaceCsh()
{
local file="$1"
shift
local key val
while [ "$#" -ge 2 ]
do
key=$1
val=$2
shift 2
_inlineSed \
"$file" \
"setenv *$key [^ #]*" \
"setenv $key $val" \
"Replaced $key setenv by '$val'"
done
}
# Get the option's value (argument). # Get the option's value (argument).
# Die if the argument doesn't exist or is empty # Die if the argument doesn't exist or is empty
# $1 option # $1 option
@ -196,13 +215,14 @@ getOptionValue()
echo "$2" echo "$2"
} }
# Remove BASH_SOURCE and FOAM_INST_DIR=... magic that looks like this:
# Remove BASH_SOURCE and projectDir=... magic that looks like this:
# ---- # ----
# variable=$BASH_SOURCE # projectDir=$BASH_SOURCE
# [ -n "$variable" ] && FOAM_INST_DIR= ... # [ -n "$projectDir" ] && projectDir= ...
# FOAM_INST_DIR=... # projectDir=...
# ---- # ----
removeMagic() removeBashMagic()
{ {
local file="$1" local file="$1"
@ -211,10 +231,33 @@ removeMagic()
exit 2 # Fatal exit 2 # Fatal
} }
echo " Remove default FOAM_INST_DIR setting ($file)" echo " Remove automatic projectDir setting ($file)"
sed -i \ sed -i \
-e '/^ *#/!{/\(BASH_SOURCE\|FOAM_INST_DIR=\)/s/^/##IGNORE## /}' \ -e '/^ *#/!{/\(BASH_SOURCE\|projectDir=\)/s/^/##IGNORE## /}' \
"$file"
}
# Remove set projectName=, set projectDir= magic that looks like this:
# ----
# set projectName="$WM_PROJECT"
# set projectDir=`lsof +p $$ |& \
# sed -n -e 's@^[^/]*@@; s@\(/'"$projectName"'[^/]*\)/etc/cshrc[^/]*@\1@p'`
# ----
removeCshMagic()
{
local file="$1"
[ -f "$file" ] || {
echo "Missing file: $file"
exit 2 # Fatal
}
echo " Remove automatic projectDir setting ($file)"
sed -i \
-e '/^ *#/!{\@\(projectName=\|projectDir=\|/etc/cshrc\)@s/^/##IGNORE## /}' \
"$file" "$file"
} }
@ -235,23 +278,15 @@ do
## Basic ## ## Basic ##
-prefix | -foamInstall | --foamInstall) -project-path)
# Replace WM_PROJECT_INST_DIR, disable FOAM_INST_DIR discovery # Replace WM_PROJECT_DIR=...
optionValue=$(getOptionValue "$@") optionValue=$(getOptionValue "$@")
removeMagic etc/bashrc replace etc/bashrc WM_PROJECT_DIR "\"$optionValue\""
replace etc/bashrc WM_PROJECT_INST_DIR "$optionValue" replaceCsh etc/cshrc WM_PROJECT_DIR "\"$optionValue\""
adjusted=true
shift removeBashMagic etc/bashrc
;; removeCshMagic etc/cshrc
-projectName | --projectName)
# Replace basename part of WM_PROJECT_DIR=...
optionValue=$(getOptionValue "$@")
_inlineSed \
etc/bashrc \
'WM_PROJECT_DIR=.*' \
'WM_PROJECT_DIR=$WM_PROJECT_INST_DIR/'"$optionValue" \
"Replaced WM_PROJECT_DIR basename by $optionValue"
adjusted=true adjusted=true
shift shift
;; ;;
@ -259,7 +294,8 @@ do
-version | -foamVersion | --projectVersion) -version | -foamVersion | --projectVersion)
# Replace WM_PROJECT_VERSION=... # Replace WM_PROJECT_VERSION=...
optionValue=$(getOptionValue "$@") optionValue=$(getOptionValue "$@")
replace etc/bashrc WM_PROJECT_VERSION "$optionValue" replace etc/bashrc WM_PROJECT_VERSION "$optionValue"
replaceCsh etc/cshrc WM_PROJECT_VERSION "$optionValue"
adjusted=true adjusted=true
shift shift
;; ;;
@ -275,7 +311,8 @@ do
echo "WM_ARCH_OPTION already set to $optionValue" echo "WM_ARCH_OPTION already set to $optionValue"
: ${adjusted:=false} : ${adjusted:=false}
else else
replace etc/bashrc WM_ARCH_OPTION "$optionValue" replace etc/bashrc WM_ARCH_OPTION "$optionValue"
replaceCsh etc/cshrc WM_ARCH_OPTION "$optionValue"
adjusted=true adjusted=true
fi fi
shift shift
@ -283,20 +320,23 @@ do
-SP | -float32) -SP | -float32)
# Replace WM_PRECISION_OPTION=... # Replace WM_PRECISION_OPTION=...
replace etc/bashrc WM_PRECISION_OPTION "SP" replace etc/bashrc WM_PRECISION_OPTION "SP"
replaceCsh etc/cshrc WM_PRECISION_OPTION "SP"
adjusted=true adjusted=true
;; ;;
-DP | -float64) -DP | -float64)
# Replace WM_PRECISION_OPTION=... # Replace WM_PRECISION_OPTION=...
replace etc/bashrc WM_PRECISION_OPTION "DP" replace etc/bashrc WM_PRECISION_OPTION "DP"
replaceCsh etc/cshrc WM_PRECISION_OPTION "DP"
adjusted=true adjusted=true
;; ;;
-int32 | -int64) -int32 | -int64)
# Replace WM_LABEL_SIZE=... # Replace WM_LABEL_SIZE=...
optionValue="${1#-int}" optionValue="${1#-int}"
replace etc/bashrc WM_LABEL_SIZE "$optionValue" replace etc/bashrc WM_LABEL_SIZE "$optionValue"
replaceCsh etc/cshrc WM_LABEL_SIZE "$optionValue"
adjusted=true adjusted=true
;; ;;
@ -306,7 +346,8 @@ do
-clang) -clang)
# Replace clang_version=... # Replace clang_version=...
optionValue=$(getOptionValue "$@") optionValue=$(getOptionValue "$@")
replace etc/config.sh/compiler clang_version "$optionValue" replace etc/config.sh/compiler clang_version "$optionValue"
replace etc/config.csh/compiler clang_version "$optionValue"
adjusted=true adjusted=true
shift shift
;; ;;
@ -314,7 +355,8 @@ do
-gcc) -gcc)
# Replace gcc_version=... # Replace gcc_version=...
optionValue=$(getOptionValue "$@") optionValue=$(getOptionValue "$@")
replace etc/config.sh/compiler gcc_version "$optionValue" replace etc/config.sh/compiler gcc_version "$optionValue"
replace etc/config.csh/compiler gcc_version "$optionValue"
adjusted=true adjusted=true
shift shift
;; ;;
@ -325,6 +367,9 @@ do
replace etc/bashrc \ replace etc/bashrc \
WM_COMPILER_TYPE system \ WM_COMPILER_TYPE system \
WM_COMPILER "$optionValue" WM_COMPILER "$optionValue"
replaceCsh etc/cshrc \
WM_COMPILER_TYPE system \
WM_COMPILER "$optionValue"
adjusted=true adjusted=true
shift shift
;; ;;
@ -335,25 +380,31 @@ do
replace etc/bashrc \ replace etc/bashrc \
WM_COMPILER_TYPE ThirdParty \ WM_COMPILER_TYPE ThirdParty \
WM_COMPILER "$optionValue" WM_COMPILER "$optionValue"
replaceCsh etc/cshrc \
WM_COMPILER_TYPE ThirdParty \
WM_COMPILER "$optionValue"
adjusted=true adjusted=true
shift shift
;; ;;
gmp-[4-9]* | gmp-system) gmp-[4-9]* | gmp-system)
# gcc-related package # gcc-related package
replace etc/config.sh/compiler gmp_version "$1" replace etc/config.sh/compiler gmp_version "$1"
replace etc/config.csh/compiler gmp_version "$1"
adjusted=true adjusted=true
;; ;;
mpfr-[2-9]* | mpfr-system) mpfr-[2-9]* | mpfr-system)
# gcc-related package # gcc-related package
replace etc/config.sh/compiler mpfr_version "$1" replace etc/config.sh/compiler mpfr_version "$1"
replace etc/config.csh/compiler mpfr_version "$1"
adjusted=true adjusted=true
;; ;;
mpc-[0-9]* | mpc-system) mpc-[0-9]* | mpc-system)
# gcc-related package # gcc-related package
replace etc/config.sh/compiler mpc_version "$1" replace etc/config.sh/compiler mpc_version "$1"
replace etc/config.csh/compiler mpc_version "$1"
adjusted=true adjusted=true
;; ;;
@ -363,7 +414,8 @@ do
-mpi) -mpi)
# Explicitly set WM_MPLIB=... # Explicitly set WM_MPLIB=...
optionValue=$(getOptionValue "$@") optionValue=$(getOptionValue "$@")
replace etc/bashrc WM_MPLIB "$optionValue" replace etc/bashrc WM_MPLIB "$optionValue"
replaceCsh etc/bashrc WM_MPLIB "$optionValue"
optMpi=system optMpi=system
adjusted=true adjusted=true
shift shift
@ -383,21 +435,29 @@ do
"FOAM_MPI=$optMpi" \ "FOAM_MPI=$optMpi" \
"Replaced 'FOAM_MPI=$expected' setting by 'FOAM_MPI=$optMpi'" "Replaced 'FOAM_MPI=$expected' setting by 'FOAM_MPI=$optMpi'"
replace etc/bashrc WM_MPLIB OPENMPI _inlineSed etc/config.csh/mpi \
"FOAM_MPI $expected" \
"FOAM_MPI $optMpi" \
"Replaced 'FOAM_MPI $expected' setting by 'FOAM_MPI $optMpi'"
replace etc/bashrc WM_MPLIB OPENMPI
replaceCsh etc/cshrc WM_MPLIB OPENMPI
adjusted=true adjusted=true
shift shift
;; ;;
-openmpi-system) -openmpi-system)
# Explicitly set WM_MPLIB=SYSTEMOPENMPI # Explicitly set WM_MPLIB=SYSTEMOPENMPI
replace etc/bashrc WM_MPLIB SYSTEMOPENMPI replace etc/bashrc WM_MPLIB SYSTEMOPENMPI
replaceCsh etc/cshrc WM_MPLIB SYSTEMOPENMPI
optMpi=system optMpi=system
adjusted=true adjusted=true
;; ;;
-openmpi-third) -openmpi-third)
# Explicitly set WM_MPLIB=OPENMPI, using default setting for openmpi # Explicitly set WM_MPLIB=OPENMPI, using default setting for openmpi
replace etc/bashrc WM_MPLIB OPENMPI replace etc/bashrc WM_MPLIB OPENMPI
replaceCsh etc/cshrc WM_MPLIB OPENMPI
optMpi=third optMpi=third
adjusted=true adjusted=true
;; ;;
@ -408,7 +468,8 @@ do
-boost) -boost)
# Replace boost_version=... # Replace boost_version=...
optionValue=$(getOptionValue "$@") optionValue=$(getOptionValue "$@")
replace etc/config.sh/CGAL boost_version "$optionValue" replace etc/config.sh/CGAL boost_version "$optionValue"
replace etc/config.csh/CGAL boost_version "$optionValue"
adjusted=true adjusted=true
shift shift
;; ;;
@ -416,7 +477,8 @@ do
-boost-path) -boost-path)
# Replace BOOST_ARCH_PATH=... # Replace BOOST_ARCH_PATH=...
optionValue=$(getOptionValue "$@") optionValue=$(getOptionValue "$@")
replace etc/config.sh/CGAL BOOST_ARCH_PATH "$optionValue" replace etc/config.sh/CGAL BOOST_ARCH_PATH "\"$optionValue\""
replaceCsh etc/config.csh/CGAL BOOST_ARCH_PATH "\"$optionValue\""
adjusted=true adjusted=true
shift shift
;; ;;
@ -424,7 +486,8 @@ do
-cgal) -cgal)
# Replace cgal_version=... # Replace cgal_version=...
optionValue=$(getOptionValue "$@") optionValue=$(getOptionValue "$@")
replace etc/config.sh/CGAL cgal_version "$optionValue" replace etc/config.sh/CGAL cgal_version "$optionValue"
replace etc/config.csh/CGAL cgal_version "$optionValue"
adjusted=true adjusted=true
shift shift
;; ;;
@ -432,7 +495,8 @@ do
-cgal-path) -cgal-path)
# Replace CGAL_ARCH_PATH=... # Replace CGAL_ARCH_PATH=...
optionValue=$(getOptionValue "$@") optionValue=$(getOptionValue "$@")
replace etc/config.sh/CGAL CGAL_ARCH_PATH "$optionValue" replace etc/config.sh/CGAL CGAL_ARCH_PATH "$optionValue"
replaceCsh etc/config.csh/CGAL CGAL_ARCH_PATH "$optionValue"
adjusted=true adjusted=true
shift shift
;; ;;
@ -440,7 +504,8 @@ do
-fftw) -fftw)
# Replace fftw_version=... # Replace fftw_version=...
optionValue=$(getOptionValue "$@") optionValue=$(getOptionValue "$@")
replace etc/config.sh/FFTW fftw_version "$optionValue" replace etc/config.sh/FFTW fftw_version "$optionValue"
replace etc/config.csh/FFTW fftw_version "$optionValue"
adjusted=true adjusted=true
shift shift
;; ;;
@ -448,7 +513,8 @@ do
-fftw-path) -fftw-path)
# Replace FFTW_ARCH_PATH=... # Replace FFTW_ARCH_PATH=...
optionValue=$(getOptionValue "$@") optionValue=$(getOptionValue "$@")
replace etc/config.sh/FFTW FFTW_ARCH_PATH "$optionValue" replace etc/config.sh/FFTW FFTW_ARCH_PATH "\"$optionValue\""
replaceCsh etc/config.csh/FFTW FFTW_ARCH_PATH "\"$optionValue\""
adjusted=true adjusted=true
shift shift
;; ;;
@ -456,7 +522,8 @@ do
-cmake) -cmake)
# Replace cmake_version=... # Replace cmake_version=...
optionValue=$(getOptionValue "$@") optionValue=$(getOptionValue "$@")
replace etc/config.sh/paraview cmake_version "$optionValue" replace etc/config.sh/paraview cmake_version "$optionValue"
replace etc/config.csh/paraview cmake_version "$optionValue"
adjusted=true adjusted=true
shift shift
;; ;;
@ -472,7 +539,7 @@ do
-kahip-path) -kahip-path)
# Replace KAHIP_ARCH_PATH=... # Replace KAHIP_ARCH_PATH=...
optionValue=$(getOptionValue "$@") optionValue=$(getOptionValue "$@")
replace etc/config.sh/kahip KAHIP_ARCH_PATH "$optionValue" replace etc/config.sh/kahip KAHIP_ARCH_PATH "\"$optionValue\""
adjusted=true adjusted=true
shift shift
;; ;;
@ -488,7 +555,7 @@ do
-metis-path) -metis-path)
# Replace METIS_ARCH_PATH=... # Replace METIS_ARCH_PATH=...
optionValue=$(getOptionValue "$@") optionValue=$(getOptionValue "$@")
replace etc/config.sh/metis METIS_ARCH_PATH "$optionValue" replace etc/config.sh/metis METIS_ARCH_PATH "\"$optionValue\""
adjusted=true adjusted=true
shift shift
;; ;;
@ -504,7 +571,7 @@ do
-scotch-path | -scotchArchPath | --scotchArchPath) -scotch-path | -scotchArchPath | --scotchArchPath)
# Replace SCOTCH_ARCH_PATH=... # Replace SCOTCH_ARCH_PATH=...
optionValue=$(getOptionValue "$@") optionValue=$(getOptionValue "$@")
replace etc/config.sh/scotch SCOTCH_ARCH_PATH "$optionValue" replace etc/config.sh/scotch SCOTCH_ARCH_PATH "\"$optionValue\""
adjusted=true adjusted=true
shift shift
;; ;;
@ -519,7 +586,17 @@ do
_matches "$optionValue" "$expected" || \ _matches "$optionValue" "$expected" || \
die "'$1' has bad value: '$optionValue'" die "'$1' has bad value: '$optionValue'"
replace etc/config.sh/paraview ParaView_VERSION "$optionValue" replace etc/config.sh/paraview ParaView_VERSION "$optionValue"
replaceCsh etc/config.csh/paraview ParaView_VERSION "$optionValue"
adjusted=true
shift
;;
-paraview-qt)
# Replace ParaView_QT=...
optionValue=$(getOptionValue "$@")
replace etc/config.sh/paraview ParaView_QT "$optionValue"
replace etc/config.csh/paraview ParaView_QT "$optionValue"
adjusted=true adjusted=true
shift shift
;; ;;
@ -527,7 +604,8 @@ do
-paraview-path | -paraviewInstall | --paraviewInstall) -paraview-path | -paraviewInstall | --paraviewInstall)
# Replace ParaView_DIR=... # Replace ParaView_DIR=...
optionValue=$(getOptionValue "$@") optionValue=$(getOptionValue "$@")
replace etc/config.sh/paraview ParaView_DIR "$optionValue" replace etc/config.sh/paraview ParaView_DIR \""$optionValue\""
replaceCsh etc/config.csh/paraview ParaView_DIR \""$optionValue\""
adjusted=true adjusted=true
shift shift
;; ;;
@ -535,7 +613,8 @@ do
-vtk) -vtk)
# Replace vtk_version=... # Replace vtk_version=...
optionValue=$(getOptionValue "$@") optionValue=$(getOptionValue "$@")
replace etc/config.sh/vtk vtk_version "$optionValue" replace etc/config.sh/vtk vtk_version "$optionValue"
replace etc/config.csh/vtk vtk_version "$optionValue"
adjusted=true adjusted=true
shift shift
;; ;;
@ -543,7 +622,8 @@ do
-mesa) -mesa)
# Replace mesa_version=... # Replace mesa_version=...
optionValue=$(getOptionValue "$@") optionValue=$(getOptionValue "$@")
replace etc/config.sh/vtk mesa_version "$optionValue" replace etc/config.sh/vtk mesa_version "$optionValue"
replace etc/config.csh/vtk mesa_version "$optionValue"
adjusted=true adjusted=true
shift shift
;; ;;
@ -551,55 +631,17 @@ do
## Misc ## ## Misc ##
-no-third)
# Replace WM_THIRD_PARTY_DIR=... with location within the project dir
replace etc/bashrc WM_THIRD_PARTY_DIR '$WM_PROJECT_DIR/ThirdParty'
adjusted=true
shift
;;
-default-third)
# Replace WM_THIRD_PARTY_DIR=... with default location/naming
replace etc/bashrc WM_THIRD_PARTY_DIR \
'$WM_PROJECT_INST_DIR/ThirdParty-$WM_PROJECT_VERSION'
adjusted=true
shift
;;
-third-path)
# Replace WM_THIRD_PARTY_DIR=...
optionValue=$(getOptionValue "$@")
replace etc/bashrc WM_THIRD_PARTY_DIR "$optionValue"
adjusted=true
shift
;;
-no-site)
# Replace fallback value for site within the project dir
_inlineSed \
etc/config.sh/settings \
'^ *siteDir=.*\/site' \
'siteDir=$WM_PROJECT_DIR/site' \
"Setting fallback site-dir '\$WM_PROJECT_DIR/site'"
adjusted=true
shift
;;
-default-site)
# Replace WM_THIRD_PARTY_DIR=... with standard location
_inlineSed \
etc/config.sh/settings \
'^ *siteDir=.*\/site' \
'siteDir=$WM_PROJECT_INST_DIR/site' \
"Setting fallback site-dir '\$WM_PROJECT_INST_DIR/site'"
adjusted=true
shift
;;
-sigfpe | -no-sigfpe) -sigfpe | -no-sigfpe)
echo "Enable/disable FOAM_SIGFPE now via controlDict" 1>&2 echo "Enable/disable FOAM_SIGFPE now via controlDict" 1>&2
;; ;;
-foamInstall | --foamInstall | -projectName | --projectName)
# Removed for 1812
optionValue=$(getOptionValue "$@")
echo "Ignoring obsolete option $1" 1>&2
shift
;;
*) *)
die "unknown option/argument: '$1'" die "unknown option/argument: '$1'"
;; ;;

View File

@ -219,7 +219,7 @@ echo "Using openfoam: $WM_PROJECT_DIR" 1>&2
echo "==> $moduleOutput" 1>&2 echo "==> $moduleOutput" 1>&2
# Remove some cruft # Remove some cruft
unset FOAM_JOB_DIR FOAM_RUN FOAM_SETTINGS FOAM_INST_DIR 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 WM_PROJECT_USER_DIR WM_THIRD_PARTY_DIR
unset SCOTCH_VERSION unset SCOTCH_VERSION

29
etc/README.md Normal file
View File

@ -0,0 +1,29 @@
OpenFOAM Configuration
----------------------
The main OpenFOAM settings are located in the parent `etc/` directory.
Both POSIX (bash, dash,...) and csh shells are supported.
To configure OpenFOAM, source either the `etc/bashrc` or the
`etc/cshrc` file, as appropriate for your shell.
These source the following files in the `config.sh/` or
`config.csh/` directories:
* `setup` : finalize setup of OpenFOAM environment (called by bashrc,cshrc)
* `settings` : core settings
* `aliases` : aliases for interactive shells
* `unset` : sourced to clear as many OpenFOAM environment settings as possible
* `mpi` : MPI communications library settings
* `ensight` : application settings for EnSight
* `paraview` : application settings for ParaView
* `scotch` : application settings for compiling against scotch
* `metis` : application settings for compiling against metis
The `config.*/example` directories contain additional example configuration
files for the corresponding shell:
* `compiler` : an example of fine tuning ThirdParty compiler settings
* `openmpi` : an example of fine tuning openmpi settings for OpenFOAM
* `paraview` : an example of chaining to the standard config/paraview
with a different ParaView_VERSION
* `prefs`: an example of supplying alternative site-defined settings

View File

@ -1,21 +0,0 @@
* OpenFOAM Configuration
The main OpenFOAM settings are located in the parent etc/ directory. The bash
and csh shells are supported and to configure OpenFOAM source etc/bashrc or
etc/cshrc respectively which source the following files in the config.sh or
config.csh respectively:
+ =settings=: core settings
+ =aliases=: aliases for interactive shells
+ =unset=: sourced to clear as many OpenFOAM environment settings as possible
+ =mpi=: MPI communications library settings
+ =ensight=: application settings for EnSight
+ =paraview=: application settings for ParaView
+ =scotch=: application settings for compiling against scotch
+ =metis=: application settings for compiling against metis 5
The config.*/example directories contains various example configuration files
for the corresponding shell:
+ =compiler=: an example of fine tuning ThirdParty compiler settings
+ =openmpi=: an example of fine tuning openmpi settings for OpenFOAM
+ =paraview=: an example of chaining to the standard config/paraview with a
different ParaView_VERSION
+ =prefs=: an example of supplying alternative site-defined settings

View File

@ -22,9 +22,9 @@
# - $WM_PROJECT_DIR/etc/prefs.sh # - $WM_PROJECT_DIR/etc/prefs.sh
# #
# - User or group values (first file found): # - User or group values (first file found):
# - ~/.OpenFOAM/$WM_PROJECT_VERSION/prefs.sh # - ~/.OpenFOAM/$WM_PROJECT_API/prefs.sh
# - ~/.OpenFOAM/prefs.sh # - ~/.OpenFOAM/prefs.sh
# - $WM_PROJECT_SITE/$WM_PROJECT_VERSION/etc/prefs.sh # - $WM_PROJECT_SITE/$WM_PROJECT_API/etc/prefs.sh
# - $WM_PROJECT_SITE/etc/prefs.sh # - $WM_PROJECT_SITE/etc/prefs.sh
# #
# Environment # Environment
@ -43,21 +43,22 @@
export WM_PROJECT=OpenFOAM export WM_PROJECT=OpenFOAM
export WM_PROJECT_VERSION=plus export WM_PROJECT_VERSION=plus
# [FOAM_INST_DIR] - parent directory containing the OpenFOAM installation. # [projectDir] - directory containing this OpenFOAM version.
# \- When this file is located as $WM_PROJECT_DIR/etc/bashrc, the next lines # \- When this file is located as $WM_PROJECT_DIR/etc/bashrc, the next lines
# should work when sourced by BASH or ZSH shells. If this however fails, # should work when sourced by BASH or ZSH shells. If this however fails,
# set one of the fallback values to an appropriate path. # set one of the fallback values to an appropriate path.
# --
rc="${BASH_SOURCE:-${ZSH_NAME:+$0}}"
[ -n "$rc" ] && FOAM_INST_DIR="$(\cd $(dirname $rc)/../.. && \pwd -L)" || \
FOAM_INST_DIR="$HOME/$WM_PROJECT"
# FOAM_INST_DIR="/opt/$WM_PROJECT"
# FOAM_INST_DIR="/usr/local/$WM_PROJECT"
# #
# This can be removed if an absolute path is provided for WM_PROJECT_DIR
# later on in this file
# --
projectDir="${BASH_SOURCE:-${ZSH_NAME:+$0}}";
[ -n "$projectDir" ] && projectDir="$(\cd $(dirname $projectDir)/.. && \pwd -L)" ||\
projectDir="$HOME/OpenFOAM/OpenFOAM-$WM_PROJECT_VERSION"
# projectDir="/opt/OpenFOAM/OpenFOAM-$WM_PROJECT_VERSION"
# projectDir="/usr/local/OpenFOAM/OpenFOAM-$WM_PROJECT_VERSION"
# END OF (NORMAL) USER EDITABLE PART # END OF (NORMAL) USER EDITABLE PART
################################################################################ ################################################################################
: # Safety statement (if the user removed all fallback values) : # Safety statement (if the user removed all fallback values)
unset rc
# Configuration environment variables. # Configuration environment variables.
# Should override via <prefs.sh> file instead of editing this file. # Should override via <prefs.sh> file instead of editing this file.
@ -127,113 +128,31 @@ foamOldDirs="$WM_PROJECT_DIR $WM_THIRD_PARTY_DIR \
$HOME/$WM_PROJECT/$USER $FOAM_USER_APPBIN $FOAM_USER_LIBBIN \ $HOME/$WM_PROJECT/$USER $FOAM_USER_APPBIN $FOAM_USER_LIBBIN \
$WM_PROJECT_SITE $FOAM_SITE_APPBIN $FOAM_SITE_LIBBIN" $WM_PROJECT_SITE $FOAM_SITE_APPBIN $FOAM_SITE_LIBBIN"
# Location of installation and third-party software # [WM_PROJECT_DIR] - Location of this OpenFOAM version
export WM_PROJECT_INST_DIR=$FOAM_INST_DIR export WM_PROJECT_DIR="$projectDir"
export WM_PROJECT_DIR=$WM_PROJECT_INST_DIR/$WM_PROJECT-$WM_PROJECT_VERSION
export WM_THIRD_PARTY_DIR=$WM_PROJECT_INST_DIR/ThirdParty-$WM_PROJECT_VERSION
# [WM_PROJECT_USER_DIR] - Location of user files # [WM_PROJECT_USER_DIR] - Location of user files
export WM_PROJECT_USER_DIR=$HOME/$WM_PROJECT/$USER-$WM_PROJECT_VERSION export WM_PROJECT_USER_DIR="$HOME/$WM_PROJECT/$USER-$WM_PROJECT_VERSION"
# [WM_PROJECT_SITE] - Location of site-specific (group) files # [WM_PROJECT_SITE] - Location of site-specific (group) files
# Default (unset) implies WM_PROJECT_DIR/site # Default (unset) implies WM_PROJECT_DIR/site
# Normally defined in calling environment # Normally defined in calling environment
if [ -d "$WM_PROJECT_SITE" ]
# Finalize setup of OpenFOAM environment for POSIX shell
if [ -d "$WM_PROJECT_DIR" ]
then then
export WM_PROJECT_SITE if [ -n "$FOAM_VERBOSE" ] && [ -n "$PS1" ]
then
echo "source $WM_PROJECT_DIR/etc/config.sh/setup" 1>&2
fi
. "$WM_PROJECT_DIR/etc/config.sh/setup" "$@"
else else
unset WM_PROJECT_SITE echo "Error: did not locate installation path for $WM_PROJECT-$WM_PROJECT_VERSION" 1>&2
echo "No directory: $WM_PROJECT_DIR" 1>&2
fi fi
# Load shell functions # Cleanup variables (done as final statement for a clean exit code)
unset WM_SHELL_FUNCTIONS unset foamOldDirs projectDir
. $WM_PROJECT_DIR/etc/config.sh/functions
# Overrides via <prefs.sh>
# 1. other (system) values
_foamEtc -mode=o prefs.sh
# 2. user or group values (unless disabled)
[ -z "$FOAM_CONFIG_NOUSER" ] && _foamEtc -mode=ug prefs.sh
# Evaluate command-line parameters and record settings for later.
# These can be used to set/unset values, specify additional files etc.
FOAM_SETTINGS="$@"
if [ -z "$FOAM_SETTINGS" ]
then
unset FOAM_SETTINGS
else
export FOAM_SETTINGS
_foamEval "$@"
fi
# Clean standard environment variables (PATH, MANPATH, LD_LIBRARY_PATH)
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
export PATH MANPATH LD_LIBRARY_PATH
_foamClean PATH "$foamOldDirs"
_foamClean MANPATH "$foamOldDirs"
_foamClean LD_LIBRARY_PATH "$foamOldDirs"
# Setup for OpenFOAM compilation etc
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
_foamEtc -config settings
# Setup for third-party packages
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
_foamEtc -config mpi
_foamEtc -config paraview -- "$@" # Pass through for evaluation
_foamEtc -config vtk
_foamEtc -config ensight
_foamEtc -config gperftools
## _foamEtc -config ADIOS
## _foamEtc -config ADIOS2
_foamEtc -config CGAL
_foamEtc -config scotch
_foamEtc -config FFTW
if [ -d "$WM_PROJECT_DIR/doc/man1" ]
then
_foamAddMan "$WM_PROJECT_DIR/doc"
fi
# Interactive shell
if /usr/bin/tty -s 2>/dev/null
then
_foamEtc -config aliases
[ "${BASH_VERSINFO:-0}" -ge 4 ] && _foamEtc -config bash_completion
fi
# Clean environment paths again. Only remove duplicates
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
export PATH MANPATH LD_LIBRARY_PATH
_foamClean PATH
_foamClean MANPATH
_foamClean LD_LIBRARY_PATH
# Add trailing ':' for system manpages
if [ -n "$MANPATH" ]
then
MANPATH="${MANPATH}:"
fi
if [ -n "$LD_PRELOAD" ]
then
export LD_PRELOAD
_foamClean LD_PRELOAD
fi
# Cleanup temporary information
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Unload shell functions
. $WM_PROJECT_DIR/etc/config.sh/functions
# Variables (done as the last statement for a clean exit code)
unset FOAM_INST_DIR # Old variable name (OpenFOAM-v1606) - now unneeded
unset cleaned foamOldDirs
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------

View File

@ -33,6 +33,13 @@ alias _foamAddLib 'setenv LD_LIBRARY_PATH \!*\:${LD_LIBRARY_PATH}'
# $2 = fallback libname ('lib' or 'lib64') # $2 = fallback libname ('lib' or 'lib64')
alias _foamAddLibAuto 'eval `$WM_PROJECT_DIR/bin/tools/lib-dir -csh \!*`' alias _foamAddLibAuto 'eval `$WM_PROJECT_DIR/bin/tools/lib-dir -csh \!*`'
# Echo values when FOAM_VERBOSE is on, no-op otherwise
if ($?FOAM_VERBOSE && $?prompt) then
alias _foamEcho 'echo \!*'
else
alias _foamEcho 'true'
endif
# Source an etc file, possibly with some verbosity # Source an etc file, possibly with some verbosity
if ($?FOAM_VERBOSE && $?prompt) then if ($?FOAM_VERBOSE && $?prompt) then
if ($?FOAM_CONFIG_NOUSER) then if ($?FOAM_CONFIG_NOUSER) then

View File

@ -147,9 +147,6 @@ setenv WM_OPTIONS "$WM_ARCH$WM_COMPILER$WM_PRECISION_OPTION$WM_LABEL_OPTION$WM_C
setenv FOAM_APPBIN "$WM_PROJECT_DIR/platforms/$WM_OPTIONS/bin" setenv FOAM_APPBIN "$WM_PROJECT_DIR/platforms/$WM_OPTIONS/bin"
setenv FOAM_LIBBIN "$WM_PROJECT_DIR/platforms/$WM_OPTIONS/lib" setenv FOAM_LIBBIN "$WM_PROJECT_DIR/platforms/$WM_OPTIONS/lib"
# External (ThirdParty) libraries
setenv FOAM_EXT_LIBBIN "$WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER$WM_PRECISION_OPTION$WM_LABEL_OPTION/lib"
# Site-specific (group) files # Site-specific (group) files
# Default # Default
@ -173,7 +170,7 @@ setenv FOAM_USER_LIBBIN "$WM_PROJECT_USER_DIR/platforms/$WM_OPTIONS/lib"
# Prepend wmake to the path - not required for runtime-only environment # Prepend wmake to the path - not required for runtime-only environment
set foundDir="${WM_PROJECT_DIR}/wmake" set foundDir="${WM_PROJECT_DIR}/wmake"
if ( $?WM_DIR ) then if ( $?WM_DIR ) then
if ( -d "${WM_DIR}" ) foundDir="${WM_DIR}" if ( -d "${WM_DIR}" ) set foundDir="${WM_DIR}"
endif endif
if ( -d "$foundDir" ) then if ( -d "$foundDir" ) then
setenv PATH "${foundDir}:${PATH}" setenv PATH "${foundDir}:${PATH}"
@ -189,8 +186,8 @@ setenv PATH "${WM_PROJECT_DIR}/bin:${PATH}"
if ( -d "$siteDir/bin" ) then # Generic if ( -d "$siteDir/bin" ) then # Generic
_foamAddPath "$siteDir/bin" _foamAddPath "$siteDir/bin"
endif endif
if ( -d "$siteDir/$WM_PROJECT_VERSION/bin" ) then # Version-specific if ( -d "$siteDir/$WM_PROJECT_API/bin" ) then # API-specific
_foamAddPath "$siteDir/$WM_PROJECT_VERSION/bin" _foamAddPath "$siteDir/$WM_PROJECT_API/bin"
endif endif
# OpenFOAM executables (user, group, standard) # OpenFOAM executables (user, group, standard)
@ -200,8 +197,11 @@ _foamAddPath "${FOAM_USER_APPBIN}:${FOAM_SITE_APPBIN}:${FOAM_APPBIN}"
_foamAddLib "$FOAM_LIBBIN/dummy" _foamAddLib "$FOAM_LIBBIN/dummy"
# External (ThirdParty) libraries. Also allowed to be unset # External (ThirdParty) libraries. Also allowed to be unset
if ( $?FOAM_EXT_LIBBIN ) then if ( -d "$WM_THIRD_PARTY_DIR" ) then
_foamAddLib $FOAM_EXT_LIBBIN setenv FOAM_EXT_LIBBIN "$WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER$WM_PRECISION_OPTION$WM_LABEL_OPTION/lib"
_foamAddLib "$FOAM_EXT_LIBBIN"
else
unsetenv FOAM_EXT_LIBBIN
endif endif
# OpenFOAM libraries (user, group, standard) # OpenFOAM libraries (user, group, standard)

187
etc/config.csh/setup Normal file
View File

@ -0,0 +1,187 @@
#----------------------------------*-sh-*--------------------------------------
# ========= |
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
# \\ / O peration |
# \\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
# \\/ M anipulation |
#------------------------------------------------------------------------------
# License
# This file is part of OpenFOAM, licensed under GNU General Public License
# <http://www.gnu.org/licenses/>.
#
# File
# etc/config.csh/setup
# - sourced by OpenFOAM-*/etc/cshrc
#
# Description
# Finalize setup of OpenFOAM environment for C-shell (csh, tcsh)
#
# Environment
# FOAM_VERBOSE (set/unset)
# - add extra verbosity when sourcing files
# FOAM_CONFIG_NOUSER (set/unset)
# - suppress use of user/group configuration files
#
#------------------------------------------------------------------------------
# [WM_PROJECT_API] - The API level for the project
setenv WM_PROJECT_API `$WM_PROJECT_DIR/bin/foamEtcFile -show-api`
# The installation parent directory
set prefixDir="${WM_PROJECT_DIR:h}"
# Load shell "functions" (actually aliases)
source "$WM_PROJECT_DIR/etc/config.csh/functions"
# [WM_THIRD_PARTY_DIR] - Location of third-party software components
# \- This may be installed in a directory parallel to the OpenFOAM project
# directory, with the same version name or using the API value.
# It may also not be required at all, in which case a dummy "ThirdParty"
# directory inside of the OpenFOAM project directory.
#
# Note: only accept if the directory exists and contains a "Allwmake" file
setenv WM_THIRD_PARTY_DIR
set foundDir=''
_foamEcho "Locating ThirdParty directory"
foreach WM_THIRD_PARTY_DIR (\
"$WM_PROJECT_DIR/ThirdParty" \
"$prefixDir/ThirdParty-$WM_PROJECT_VERSION" \
"$prefixDir/ThirdParty-v$WM_PROJECT_API" \
"$prefixDir/ThirdParty-$WM_PROJECT_API" \
"$prefixDir/ThirdParty-common" \
)
_foamEcho "... $WM_THIRD_PARTY_DIR"
if ( -d "$WM_THIRD_PARTY_DIR" ) then
if ( -f "$WM_THIRD_PARTY_DIR/Allwmake" || -d "$WM_THIRD_PARTY_DIR/platforms" ) then
set foundDir=true
break
endif
endif
end
if ( "${%foundDir}" ) then
_foamEcho "Using $WM_THIRD_PARTY_DIR"
else
# Dummy fallback value
setenv WM_THIRD_PARTY_DIR "$WM_PROJECT_DIR/ThirdParty"
_foamEcho "Dummy $WM_THIRD_PARTY_DIR"
endif
# Done with ThirdParty discovery
# Overrides via <prefs.csh>
# 1. other (system) values
_foamEtc -mode=o prefs.csh
# 2. user or group values (unless disabled)
if (! $?FOAM_CONFIG_NOUSER ) then
_foamEtc -mode=ug prefs.csh
endif
# Capture and evaluate any command-line parameters
# These can be used to set/unset values, specify additional files etc.
setenv FOAM_SETTINGS "${*}"
while ( $#argv > 0 )
switch ($argv[1])
case -*:
# Stray option (not meant for us here) -> get out
break
breaksw
case *=:
# name= -> unsetenv name
_foamEcho "unsetenv $argv[1]:s/=//"
eval "unsetenv $argv[1]:s/=//"
breaksw
case *=*:
# name=value -> setenv name value
_foamEcho "setenv $argv[1]:s/=/ /"
eval "setenv $argv[1]:s/=/ /"
breaksw
default:
# Filename: source it
if ( -f "$argv[1]" ) then
_foamEcho "Using: $argv[1]"
source "$argv[1]"
else
_foamEtc -silent "$argv[1]"
endif
breaksw
endsw
shift
end
# Clean standard environment variables (PATH, MANPATH, LD_LIBRARY_PATH)
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Prevent local variables from shadowing setenv variables
unset PATH MANPATH LD_LIBRARY_PATH LD_PRELOAD
if (! $?LD_LIBRARY_PATH ) setenv LD_LIBRARY_PATH
if (! $?MANPATH ) setenv MANPATH
_foamClean PATH "$foamOldDirs"
_foamClean MANPATH "$foamOldDirs"
_foamClean LD_LIBRARY_PATH "$foamOldDirs"
# Setup for OpenFOAM compilation etc
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
_foamEtc -config settings
# Setup for third-party packages
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
_foamEtc -config mpi
_foamEtc -config paraview -- "$FOAM_SETTINGS" # Pass through for evaluation
_foamEtc -config vtk
_foamEtc -config ensight
## _foamEtc -config ADIOS
## _foamEtc -config ADIOS2
_foamEtc -config CGAL
_foamEtc -config FFTW
if ( -d "$WM_PROJECT_DIR/doc/man1" ) then
_foamAddMan "$WM_PROJECT_DIR/doc"
endif
# Interactive shell
if ($?prompt) then
_foamEtc -config aliases
_foamEtc -config tcsh_completion
endif
# Clean environment paths again. Only remove duplicates
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
_foamClean PATH
_foamClean MANPATH
_foamClean LD_LIBRARY_PATH
# Add trailing ':' for system manpages
if ( $?MANPATH ) then
setenv MANPATH "${MANPATH}:"
endif
if ( $?LD_PRELOAD ) then
_foamClean LD_PRELOAD
endif
# Cleanup temporary information
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Unload shell "functions"
unalias _foamClean
unalias _foamEcho
unalias _foamEtc
unalias _foamAddPath
unalias _foamAddMan
unalias _foamAddLib
unalias _foamAddLibAuto
# Variables (done as final statement for a clean exit code)
unset cleaned foamOldDirs foundDir prefixDir
#------------------------------------------------------------------------------

View File

@ -59,6 +59,7 @@ unsetenv WM_OPTIONS
unsetenv WM_OSTYPE unsetenv WM_OSTYPE
unsetenv WM_PRECISION_OPTION unsetenv WM_PRECISION_OPTION
unsetenv WM_PROJECT unsetenv WM_PROJECT
unsetenv WM_PROJECT_API
unsetenv WM_PROJECT_DIR unsetenv WM_PROJECT_DIR
unsetenv WM_PROJECT_INST_DIR unsetenv WM_PROJECT_INST_DIR
unsetenv WM_PROJECT_SITE unsetenv WM_PROJECT_SITE

View File

@ -40,6 +40,15 @@ then
unset "foamVar_name" unset "foamVar_name"
} }
# Echo values to stderr when FOAM_VERBOSE is on, no-op otherwise
unset -f _foamEcho 2>/dev/null
if [ -n "$FOAM_VERBOSE" ] && [ -n "$PS1" ]
then
_foamEcho() { echo "$@" 1>&2; }
else
_foamEcho() { true; }
fi
# Source an etc file, possibly with some verbosity # Source an etc file, possibly with some verbosity
# - use eval to avoid intermediate variables (ksh doesn't have 'local') # - use eval to avoid intermediate variables (ksh doesn't have 'local')
unset -f _foamEtc 2>/dev/null unset -f _foamEtc 2>/dev/null
@ -216,7 +225,7 @@ else
# Was previously loaded/defined - now unset # Was previously loaded/defined - now unset
unset -f _foamAddPath _foamAddMan _foamAddLib _foamAddLibAuto 2>/dev/null unset -f _foamAddPath _foamAddMan _foamAddLib _foamAddLibAuto 2>/dev/null
unset -f _foamClean _foamEtc _foamEval 2>/dev/null unset -f _foamClean _foamEcho _foamEtc _foamEval 2>/dev/null
unset foamClean unset foamClean
unset WM_SHELL_FUNCTIONS unset WM_SHELL_FUNCTIONS

View File

@ -140,9 +140,6 @@ export WM_OPTIONS="$WM_ARCH$WM_COMPILER$WM_PRECISION_OPTION$WM_LABEL_OPTION$WM_C
export FOAM_APPBIN="$WM_PROJECT_DIR/platforms/$WM_OPTIONS/bin" export FOAM_APPBIN="$WM_PROJECT_DIR/platforms/$WM_OPTIONS/bin"
export FOAM_LIBBIN="$WM_PROJECT_DIR/platforms/$WM_OPTIONS/lib" export FOAM_LIBBIN="$WM_PROJECT_DIR/platforms/$WM_OPTIONS/lib"
# External (ThirdParty) libraries
export FOAM_EXT_LIBBIN="$WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER$WM_PRECISION_OPTION$WM_LABEL_OPTION/lib"
# Site-specific (group) files # Site-specific (group) files
# Default # Default
@ -187,9 +184,9 @@ if [ -d "$siteDir/bin" ] # Generic
then then
_foamAddPath "$siteDir/bin" _foamAddPath "$siteDir/bin"
fi fi
if [ -d "$siteDir/$WM_PROJECT_VERSION/bin" ] # Version-specific if [ -d "$siteDir/$WM_PROJECT_API/bin" ] # API-specific
then then
_foamAddPath "$siteDir/$WM_PROJECT_VERSION/bin" _foamAddPath "$siteDir/$WM_PROJECT_API/bin"
fi fi
# OpenFOAM executables (user, group, standard) # OpenFOAM executables (user, group, standard)
@ -198,10 +195,13 @@ _foamAddPath "$FOAM_USER_APPBIN:$FOAM_SITE_APPBIN:$FOAM_APPBIN"
# Dummy versions of external libraries. To be found last in LD_LIBRARY_PATH # Dummy versions of external libraries. To be found last in LD_LIBRARY_PATH
_foamAddLib "$FOAM_LIBBIN/dummy" _foamAddLib "$FOAM_LIBBIN/dummy"
# External libraries (allowed to be unset) # External (ThirdParty) libraries. Also allowed to be unset
if [ -n "$FOAM_EXT_LIBBIN" ] if [ -d "$WM_THIRD_PARTY_DIR" ]
then then
_foamAddLib $FOAM_EXT_LIBBIN export FOAM_EXT_LIBBIN="$WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER$WM_PRECISION_OPTION$WM_LABEL_OPTION/lib"
_foamAddLib "$FOAM_EXT_LIBBIN"
else
unset FOAM_EXT_LIBBIN
fi fi
# OpenFOAM libraries (user, group, standard) # OpenFOAM libraries (user, group, standard)

171
etc/config.sh/setup Normal file
View File

@ -0,0 +1,171 @@
#----------------------------------*-sh-*--------------------------------------
# ========= |
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
# \\ / O peration |
# \\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
# \\/ M anipulation |
#------------------------------------------------------------------------------
# License
# This file is part of OpenFOAM, licensed under GNU General Public License
# <http://www.gnu.org/licenses/>.
#
# File
# etc/config.sh/setup
# - sourced by OpenFOAM-*/etc/bashrc
#
# Description
# Finalize setup of OpenFOAM environment for POSIX shell.
#
# Environment
# FOAM_VERBOSE (set/unset)
# - add extra verbosity when sourcing files
# FOAM_CONFIG_NOUSER (set/unset)
# - suppress use of user/group configuration files
#
#------------------------------------------------------------------------------
# [WM_PROJECT_API] - The API level for the project
export WM_PROJECT_API="$($WM_PROJECT_DIR/bin/foamEtcFile -show-api)"
# The installation parent directory
prefixDir="${WM_PROJECT_DIR%/*}"
# Load shell functions
unset WM_SHELL_FUNCTIONS
. "$WM_PROJECT_DIR/etc/config.sh/functions"
# [WM_THIRD_PARTY_DIR] - Location of third-party software components
# \- This may be installed in a directory parallel to the OpenFOAM project
# directory, with the same version name or using the API value.
# It may also not be required at all, in which case a dummy "ThirdParty"
# directory inside of the OpenFOAM project directory.
#
# Note: only accept if the directory exists and contains a "Allwmake" file
export WM_THIRD_PARTY_DIR
unset foundDir
_foamEcho "Locating ThirdParty directory"
for WM_THIRD_PARTY_DIR in \
"$WM_PROJECT_DIR/ThirdParty" \
"$prefixDir/ThirdParty-$WM_PROJECT_VERSION" \
"$prefixDir/ThirdParty-v$WM_PROJECT_API" \
"$prefixDir/ThirdParty-$WM_PROJECT_API" \
"$prefixDir/ThirdParty-common" \
;
do
_foamEcho "... $WM_THIRD_PARTY_DIR"
if [ -d "$WM_THIRD_PARTY_DIR" ]
then
if [ -f "$WM_THIRD_PARTY_DIR/Allwmake" ] || \
[ -d "$WM_THIRD_PARTY_DIR/platforms" ]
then
foundDir=true
break
fi
fi
done
if [ -n "$foundDir" ]
then
_foamEcho "Using $WM_THIRD_PARTY_DIR"
else
# Dummy fallback value
WM_THIRD_PARTY_DIR="$WM_PROJECT_DIR/ThirdParty"
_foamEcho "Dummy $WM_THIRD_PARTY_DIR"
fi
# Done with ThirdParty discovery
# Overrides via <prefs.sh>
# 1. other (system) values
_foamEtc -mode=o prefs.sh
# 2. user or group values (unless disabled)
[ -z "$FOAM_CONFIG_NOUSER" ] && _foamEtc -mode=ug prefs.sh
# Capture and evaluate any command-line parameters
# These can be used to set/unset values, specify additional files etc.
FOAM_SETTINGS="$@"
# Evaluate the command-line parameters, which were saved as FOAM_SETTINGS.
# These can be used to set/unset values, specify additional files etc.
if [ -z "$FOAM_SETTINGS" ]
then
unset FOAM_SETTINGS
else
export FOAM_SETTINGS
_foamEval "$@"
fi
# Clean standard environment variables (PATH, MANPATH, LD_LIBRARY_PATH)
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
export PATH MANPATH LD_LIBRARY_PATH
_foamClean PATH "$foamOldDirs"
_foamClean MANPATH "$foamOldDirs"
_foamClean LD_LIBRARY_PATH "$foamOldDirs"
# Setup for OpenFOAM compilation etc
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
_foamEtc -config settings
# Setup for third-party packages
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
_foamEtc -config mpi
_foamEtc -config paraview -- "$@" # Pass through for evaluation
_foamEtc -config vtk
_foamEtc -config ensight
_foamEtc -config gperftools
## _foamEtc -config ADIOS
## _foamEtc -config ADIOS2
_foamEtc -config CGAL
_foamEtc -config scotch
_foamEtc -config FFTW
if [ -d "$WM_PROJECT_DIR/doc/man1" ]
then
_foamAddMan "$WM_PROJECT_DIR/doc"
fi
# Interactive shell
if /usr/bin/tty -s 2>/dev/null
then
_foamEtc -config aliases
[ "${BASH_VERSINFO:-0}" -ge 4 ] && _foamEtc -config bash_completion
fi
# Clean environment paths again. Only remove duplicates
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
export PATH MANPATH LD_LIBRARY_PATH
_foamClean PATH
_foamClean MANPATH
_foamClean LD_LIBRARY_PATH
# Add trailing ':' for system manpages
if [ -n "$MANPATH" ]
then
MANPATH="${MANPATH}:"
fi
if [ -n "$LD_PRELOAD" ]
then
export LD_PRELOAD
_foamClean LD_PRELOAD
fi
# Cleanup temporary information
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Unload shell functions
. "$WM_PROJECT_DIR/etc/config.sh/functions"
# Variables (done as the last statement for a clean exit code)
unset cleaned foamOldDirs foundDir prefixDir
#------------------------------------------------------------------------------

View File

@ -50,6 +50,7 @@ unset WM_OPTIONS
unset WM_OSTYPE unset WM_OSTYPE
unset WM_PRECISION_OPTION unset WM_PRECISION_OPTION
unset WM_PROJECT unset WM_PROJECT
unset WM_PROJECT_API
unset WM_PROJECT_DIR unset WM_PROJECT_DIR
unset WM_PROJECT_INST_DIR unset WM_PROJECT_INST_DIR
unset WM_PROJECT_SITE unset WM_PROJECT_SITE

150
etc/cshrc
View File

@ -22,10 +22,10 @@
# - $WM_PROJECT_DIR/etc/prefs.csh # - $WM_PROJECT_DIR/etc/prefs.csh
# #
# - User or group values (first file found): # - User or group values (first file found):
# - ~/.OpenFOAM/$WM_PROJECT_VERSION/prefs.csh # - ~/.OpenFOAM/$WM_PROJECT_API/prefs.csh
# - ~/.OpenFOAM/prefs.csh # - ~/.OpenFOAM/prefs.csh
# - $WM_PROJECT_SITE/$WM_PROJECT_VERSION/etc/prefs.csh # - $WM_PROJECT_SITE/$WM_PROJECT_API/etc/prefs.csh
# - $WM_PROJECT_SITE/etc/prefs.csh # - $WM_PROJECT_SITE/prefs.csh
# #
# Environment # Environment
# FOAM_VERBOSE (set/unset) # FOAM_VERBOSE (set/unset)
@ -43,17 +43,22 @@
setenv WM_PROJECT OpenFOAM setenv WM_PROJECT OpenFOAM
setenv WM_PROJECT_VERSION plus setenv WM_PROJECT_VERSION plus
# [FOAM_INST_DIR] - parent directory containing the OpenFOAM installation. # [projectDir] - parent directory containing the OpenFOAM installation.
# \- When this file is located as $WM_PROJECT_DIR/etc/cshrc, the next lines # \- When this file is located as $WM_PROJECT_DIR/etc/cshrc, the next lines
# should work when sourced by CSH or TCSH shells. If this however fails, # should work when sourced by CSH or TCSH shells. If this however fails,
# set one of the fallback values to an appropriate path. # set one of the fallback values to an appropriate path.
# --
set FOAM_INST_DIR=`lsof +p $$ |& \
sed -n -e 's@[^/]*@@' -e 's@/'$WM_PROJECT'[^/]*/etc/cshrc.*@@p'`
# set FOAM_INST_DIR=$HOME/$WM_PROJECT
# set FOAM_INST_DIR=/opt/$WM_PROJECT
# set FOAM_INST_DIR=/usr/local/$WM_PROJECT
# #
# This can be removed if an absolute path is provided for WM_PROJECT_DIR
# later on in this file.
# --
# If the directory naming does not match WM_PROJECT, need to change here
set projectName="$WM_PROJECT"
set projectDir=`lsof +p $$ |& \
sed -n -e 's@^[^/]*@@; s@\(/'"$projectName"'[^/]*\)/etc/cshrc[^/]*@\1@p'`
# set projectDir="$HOME/OpenFOAM/OpenFOAM-$WM_PROJECT_VERSION"
# set projectDir="/opt/OpenFOAM/OpenFOAM-$WM_PROJECT_VERSION"
# set projectDir="/usr/local/OpenFOAM/OpenFOAM-$WM_PROJECT_VERSION"
# END OF (NORMAL) USER EDITABLE PART # END OF (NORMAL) USER EDITABLE PART
################################################################################ ################################################################################
@ -138,10 +143,8 @@ if ( $?FOAM_SITE_LIBBIN ) then
set foamOldDirs="$foamOldDirs $FOAM_SITE_LIBBIN" set foamOldDirs="$foamOldDirs $FOAM_SITE_LIBBIN"
endif endif
# Location of installation and third-party software # [WM_PROJECT_DIR] - Location of this OpenFOAM version
setenv WM_PROJECT_INST_DIR $FOAM_INST_DIR setenv WM_PROJECT_DIR "$projectDir"
setenv WM_PROJECT_DIR $WM_PROJECT_INST_DIR/$WM_PROJECT-$WM_PROJECT_VERSION
setenv WM_THIRD_PARTY_DIR $WM_PROJECT_INST_DIR/ThirdParty-$WM_PROJECT_VERSION
# [WM_PROJECT_USER_DIR] - Location of user files # [WM_PROJECT_USER_DIR] - Location of user files
setenv WM_PROJECT_USER_DIR "$HOME/$WM_PROJECT/$LOGNAME-$WM_PROJECT_VERSION" setenv WM_PROJECT_USER_DIR "$HOME/$WM_PROJECT/$LOGNAME-$WM_PROJECT_VERSION"
@ -157,118 +160,17 @@ else
unsetenv WM_PROJECT_SITE unsetenv WM_PROJECT_SITE
endif endif
# Load shell "functions" (actually aliases)
source $WM_PROJECT_DIR/etc/config.csh/functions
# Overrides via <prefs.csh> # Finalize setup of OpenFOAM environment
# 1. other (system) values if ( -d "$WM_PROJECT_DIR" ) then
_foamEtc -mode=o prefs.csh if ($?FOAM_VERBOSE && $?prompt) echo "source $WM_PROJECT_DIR/etc/config.csh/setup"
source "$WM_PROJECT_DIR/etc/config.csh/setup" "${*}"
# 2. user or group values (unless disabled) else
if (! $?FOAM_CONFIG_NOUSER ) then echo "Error: did not locate installation path for $WM_PROJECT-$WM_PROJECT_VERSION"
_foamEtc -mode=ug prefs.csh echo "No directory: $WM_PROJECT_DIR"
endif endif
# Evaluate command-line parameters and record settings for later. # Cleanup variables (done as final statement for a clean exit code)
# These can be used to set/unset values, specify additional files etc. unset foamOldDirs projectDir projectName
setenv FOAM_SETTINGS "${*}"
while ( $#argv > 0 )
switch ($argv[1])
case -*:
# Stray option (not meant for us here) -> get out
break
breaksw
case *=:
# name= -> unsetenv name
if ($?FOAM_VERBOSE && $?prompt) echo "unsetenv $argv[1]:s/=//"
eval "unsetenv $argv[1]:s/=//"
breaksw
case *=*:
# name=value -> setenv name value
if ($?FOAM_VERBOSE && $?prompt) echo "setenv $argv[1]:s/=/ /"
eval "setenv $argv[1]:s/=/ /"
breaksw
default:
# Filename: source it
if ( -f "$argv[1]" ) then
if ($?FOAM_VERBOSE && $?prompt) echo "Using: $argv[1]"
source "$argv[1]"
else
_foamEtc -silent "$argv[1]"
endif
breaksw
endsw
shift
end
# Clean standard environment variables (PATH, MANPATH, LD_LIBRARY_PATH)
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Prevent local variables from shadowing setenv variables
unset PATH MANPATH LD_LIBRARY_PATH LD_PRELOAD
if (! $?LD_LIBRARY_PATH ) setenv LD_LIBRARY_PATH
if (! $?MANPATH ) setenv MANPATH
_foamClean PATH "$foamOldDirs"
_foamClean MANPATH "$foamOldDirs"
_foamClean LD_LIBRARY_PATH "$foamOldDirs"
# Setup for OpenFOAM compilation etc
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
_foamEtc -config settings
# Setup for third-party packages
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
_foamEtc -config mpi
_foamEtc -config paraview -- "$FOAM_SETTINGS" # Pass through for evaluation
_foamEtc -config vtk
_foamEtc -config ensight
## _foamEtc -config ADIOS
## _foamEtc -config ADIOS2
_foamEtc -config CGAL
_foamEtc -config FFTW
if ( -d "$WM_PROJECT_DIR/doc/man1" ) then
_foamAddMan "$WM_PROJECT_DIR/doc"
endif
# Interactive shell
if ($?prompt) then
_foamEtc -config aliases
_foamEtc -config tcsh_completion
endif
# Clean environment paths again. Only remove duplicates
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
_foamClean PATH
_foamClean MANPATH
_foamClean LD_LIBRARY_PATH
# Add trailing ':' for system manpages
if ( $?MANPATH ) then
setenv MANPATH "${MANPATH}:"
endif
if ( $?LD_PRELOAD ) then
_foamClean LD_PRELOAD
endif
# Cleanup temporary information
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Unload shell "functions"
unalias _foamClean
unalias _foamEtc
unalias _foamAddPath
unalias _foamAddMan
unalias _foamAddLib
unalias _foamAddLibAuto
# Variables (done as the last statement for a clean exit code)
unset FOAM_INST_DIR # Old variable name (OpenFOAM-v1606) - now unneeded
unset cleaned foamOldDirs
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------

View File

@ -16,7 +16,7 @@ cd ${0%/*} && wmakeCheckPwd "$WM_PROJECT_DIR/src" 2>/dev/null || {
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# Trigger update of version strings as required # Trigger update of version strings as required
wmakePrintBuild -check || wrmo OpenFOAM/global/global.o 2>/dev/null wmakeBuildInfo -check || wrmo OpenFOAM/global/global.o 2>/dev/null
wmakeLnInclude -u OpenFOAM wmakeLnInclude -u OpenFOAM
wmakeLnInclude -u OSspecific/"${WM_OSTYPE:-POSIX}" wmakeLnInclude -u OSspecific/"${WM_OSTYPE:-POSIX}"

View File

@ -81,6 +81,7 @@ void Foam::dynamicCode::checkSecurity
<< " allowSystemOperations 1" << nl << nl << " allowSystemOperations 1" << nl << nl
<< "to the InfoSwitches setting in the system controlDict." << nl << "to the InfoSwitches setting in the system controlDict." << nl
<< "The system controlDict is any of" << nl << nl << "The system controlDict is any of" << nl << nl
<< " ~/.OpenFOAM/" << OPENFOAM << "/controlDict" << nl
<< " ~/.OpenFOAM/controlDict" << nl << " ~/.OpenFOAM/controlDict" << nl
<< " $WM_PROJECT_DIR/etc/controlDict" << nl << endl << " $WM_PROJECT_DIR/etc/controlDict" << nl << endl
<< exit(FatalIOError); << exit(FatalIOError);

View File

@ -119,18 +119,8 @@ Foam::fileNameList searchEtc
bool (*accept)(const Foam::fileName&) bool (*accept)(const Foam::fileName&)
) )
{ {
Foam::fileName version(Foam::getEnv("WM_PROJECT_VERSION")); // Could use foamVersion::api, but this more direct.
const Foam::fileName version(std::to_string(OPENFOAM));
// Fallback when WM_PROJECT_VERSION is unset
if (version.empty())
{
#if OPENFOAM
version.assign(std::to_string(OPENFOAM));
#else
version.assign(foamVersion::version);
#endif
}
Foam::fileNameList list; Foam::fileNameList list;
Foam::fileName dir, candidate; Foam::fileName dir, candidate;

View File

@ -26,8 +26,8 @@ Description
It is important that these are constructed in the appropriate order to It is important that these are constructed in the appropriate order to
avoid the use of unconstructed data in the global namespace. avoid the use of unconstructed data in the global namespace.
This file has the extension .Cver to trigger a Makefile rule that converts This file has a '.Cver' extension to trigger a Makefile rule to replace
'VERSION\_STRING' and 'BUILD\_STRING' into the appropriate strings. 'BUILD', 'VERSION' tags with the corresponding strings.
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
@ -48,14 +48,14 @@ const int Foam::foamVersion::api
// Value of PATCH generated by the build-script // Value of PATCH generated by the build-script
const std::string Foam::foamVersion::patch const std::string Foam::foamVersion::patch
( (
"" "@PATCH@"
); );
// Value of the BUILD generated by the build-script // Value of the BUILD generated by the build-script
const std::string Foam::foamVersion::build const std::string Foam::foamVersion::build
( (
"BUILD_STRING" "@BUILD@"
); );
@ -78,7 +78,7 @@ const std::string Foam::foamVersion::buildArch
// Only required for compatibility // Only required for compatibility
const std::string Foam::foamVersion::version const std::string Foam::foamVersion::version
( (
"VERSION_STRING" "@VERSION@"
); );

View File

@ -127,6 +127,7 @@ bool Foam::functionObjects::systemCall::read(const dictionary& dict)
<< " allowSystemOperations 1" << nl << nl << " allowSystemOperations 1" << nl << nl
<< "to the InfoSwitches setting in the system controlDict." << nl << "to the InfoSwitches setting in the system controlDict." << nl
<< "The system controlDict is any of" << nl << nl << "The system controlDict is any of" << nl << nl
<< " ~/.OpenFOAM/" << OPENFOAM << "/controlDict" << nl
<< " ~/.OpenFOAM/controlDict" << nl << " ~/.OpenFOAM/controlDict" << nl
<< " $WM_PROJECT_DIR/etc/controlDict" << nl << endl << " $WM_PROJECT_DIR/etc/controlDict" << nl << endl
<< exit(FatalError); << exit(FatalError);

View File

@ -2,11 +2,9 @@
SUFFIXES += .Cver SUFFIXES += .Cver
# Update version strings in C++ file and in $WM_PROJECT_DIR/.build file # Update strings in C++ file and in META-INFO files
Cvertoo = \ Cvertoo = \
sed -e 's!VERSION_STRING!$(shell wmakePrintBuild -major)!' \ wmakeBuildInfo -update -filter $< > $(@D)/$(<F).C; \
-e 's!BUILD_STRING!$(shell wmakePrintBuild -update)!' \
$< > $(@D)/$(<F).C; \
$(CC) $(c++FLAGS) -c $(@D)/$(<F).C -o $@ $(CC) $(c++FLAGS) -c $(@D)/$(<F).C -o $@
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------

531
wmake/wmakeBuildInfo Executable file
View File

@ -0,0 +1,531 @@
#!/bin/bash
#------------------------------------------------------------------------------
# ========= |
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
# \\ / O peration |
# \\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
# \\/ 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
# wmakeBuildInfo
#
# Description
# Print the version used when building the project
#
# Environment
# - WM_PROJECT_DIR
# - WM_DIR (unset defaults to WM_PROJECT_DIR/wmake)
#
# Note
# Partial logic is also implemented in the bin/foamEtcFile
# -show-api and -show-patch options.
# Make sure that any changes here are also reflected there.
#
#------------------------------------------------------------------------------
# Locations
rulesFile="${WM_DIR:-$WM_PROJECT_DIR/wmake}/rules/General/general"
metaInfoDir="$WM_PROJECT_DIR/META-INFO"
usage() {
exec 1>&2
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
cat<<USAGE
Usage: ${0##*/} [OPTION]
${0##*/} [-update] -filter FILE
options:
-check Compare make and meta information (exit 0 for no changes)
-diff Display differences between make and meta information
(exit code 0 for no changes)
-dry-run In combination with -update
-update Update meta-info from make information
-filter FILE Filter/replace @API@, @BUILD@ tags in specified file
with corresponding make information
-query Report make-info and meta-info
-query-make Report make-info values (api, branch, build)
-query-meta Report meta-info values (api, branch, build)
-show-api Print api value from wmake/rules, or meta-info and exit
-show-patch Print patch value from meta-info and exit
-help Print the usage
Query/manage status of api,branch,build information.
Default without any arguments is the same as '-query-make'.
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
}
#------------------------------------------------------------------------------
# Parse arguments and options
#------------------------------------------------------------------------------
unset optCheck optDryRun optUpdate optQuery optFilter
while [ "$#" -gt 0 ]
do
case "$1" in
-h | -help*)
usage
;;
-check)
optCheck=true
;;
-diff)
optCheck=verbose
;;
-dry-run)
optDryRun=true
;;
-update)
optUpdate=true
;;
-query)
optQuery="make:meta"
;;
-query-make | -query-meta)
optQuery="$optQuery:${1##*-}"
;;
-show-api)
optQuery="api"
;;
-show-patch)
optQuery="patch"
;;
-filter)
optFilter=true
shift # Stop here, a file name follows
break
;;
*)
die "unknown option/argument: '$1'"
;;
esac
shift
done
#------------------------------------------------------------------------------
if [ "$optFilter" = true ]
then
[ -f "$1" ] || {
echo "Error in ${0##*/}: file not found '$1'" 1>&2
exit 2
}
# Disable other methods that generate output to stdout
unset optCheck optQuery
else
[ "$#" -eq 0 ] || die "Unexpected option/arguments $@"
# Nothing specified? Default to -query-make
if [ -z "$optCheck$optUpdate$optQuery" ]
then
optQuery="make"
fi
fi
#------------------------------------------------------------------------------
# Variables
declare -A makeInfo
declare -A metaInfo
#
# Populate makeInfo array
#
# - api : from rules/General/general
# - patch : cached value from previous make
# - branch : from git
# - build : from git
#
# Failure modes:
# - No api information (can't find file etc).
# -> FATAL: should never happen.
#
# - No git installed or no git repo
# -> branch and build are populated as empty strings
#
# - Working on detached head.
# -> branch has value "HEAD" instead of something more readable.
#
getMakeInfo()
{
local api patch build branch
makeInfo=()
# (api) from WM_DIR/rules/General/general
# - extract WM_VERSION = OPENFOAM=<digits>
api="$(sed -ne '/^ *#/!{ /WM_VERSION.*OPENFOAM=/{ s@^.*OPENFOAM= *\([0-9][0-9]*\).*@\1@p; q }}' $rulesFile 2>/dev/null)"
if [ -d "$metaInfoDir" ]
then
# (patch) from build-info - not from api-info
patch="$(sed -ne 's@^patch *= *\([0-9][0-9]*\).*@\1@p' $metaInfoDir/build-info 2>/dev/null)"
fi
# Build info from git
build="$(git --git-dir=$WM_PROJECT_DIR/.git log -1 --date='format:%y%m%d' --format='%h-%ad' 2>/dev/null)"
# Branch info from git
if [ -n "$build" ]
then
branch="$(git --git-dir=$WM_PROJECT_DIR/.git rev-parse --abbrev-ref HEAD 2>/dev/null)"
fi
makeInfo[api]="$api"
makeInfo[patch]="${patch:-0}" # default is 0
makeInfo[branch]="$branch"
makeInfo[build]="$build"
makeInfo[cached]=true
}
#
# Populate metaInfo array
#
# - api : from META-INFO/api-info
# - patch : from META-INFO/api-info
# - branch : from META-INFO/build-info
# - build : from META-INFO/build-info
#
# Failure modes:
# - Directory, file or entry not found.
# -> corresponding entries are empty strings
#
getMetaInfo()
{
local api patch build branch
metaInfo=()
if [ -d "$metaInfoDir" ]
then
# (api, patch) from api-info
# (branch, build) from build-info
api="$(sed -ne 's@^api *= *\([0-9][0-9]*\).*@\1@p' $metaInfoDir/api-info 2>/dev/null)"
patch="$(sed -ne 's@^patch *= *\([0-9][0-9]*\).*@\1@p' $metaInfoDir/api-info 2>/dev/null)"
branch="$(sed -ne 's@^branch *= *\([^ ]*\).*@\1@p' $metaInfoDir/build-info 2>/dev/null)"
build="$(sed -ne 's@^build *= *\([^ ]*\).*@\1@p' $metaInfoDir/build-info 2>/dev/null)"
fi
metaInfo[api]="$api"
metaInfo[patch]="${patch:-0}" # default is 0
metaInfo[branch]="$branch"
metaInfo[build]="$build"
metaInfo[cached]=true
}
#
# 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()
{
[ -n "${makeInfo[cached]}" ] || getMakeInfo
# Local copy
local api="${makeInfo[api]}"
if [ -z "$api" ]
then
[ -n "${metaInfo[cached]}" ] || getMetaInfo
api="${metaInfo[api]}"
fi
if [ -n "$api" ]
then
echo "$api"
else
return 1
fi
}
# Get patch from meta-info / api-info
#
# Failure modes:
# - No patch information (can't find file etc).
#
getPatchLevel()
{
[ -n "${metaInfo[cached]}" ] || getMetaInfo
# Local copy
local value="${metaInfo[patch]}"
if [ -n "$value" ]
then
echo "$value"
else
return 1
fi
}
# Report make info
reportMakeInfo()
{
local key
[ -n "${makeInfo[cached]}" ] || getMakeInfo
[ -n "${metaInfo[cached]}" ] || getMetaInfo
local patch="${metaInfo[patch]}" # <- From meta-info only
makeInfo[patch]="${patch:=0}" # Extra safety
echo "make"
for key in api patch branch build
do
echo " $key = ${makeInfo[$key]}"
done
}
# Report meta info
reportMetaInfo()
{
local key
[ -n "${metaInfo[cached]}" ] || getMetaInfo
local patch="${metaInfo[patch]}" # <- From meta-info only
metaInfo[patch]="${patch:=0}" # Extra safety
echo "meta"
for key in api patch branch build
do
echo " $key = ${metaInfo[$key]}"
done
}
# Test make vs meta info.
# Return 0 for no differences, 1 otherwise
# $1 == verbose, print as diff. Silent otherwise
checkDiff()
{
local verbose="$1"
local key diff
[ -n "${makeInfo[cached]}" ] || getMakeInfo
[ -n "${metaInfo[cached]}" ] || getMetaInfo
for key in api patch branch build
do
if [ "${makeInfo[$key]}" != "${metaInfo[$key]}" ]
then
diff="$diff $key"
fi
done
if [ "$verbose" = verbose ] && [ -n "$diff" ]
then
echo "Differences"
for key in $diff
do
echo "$key:"
echo " make ${makeInfo[$key]}"
echo " meta ${metaInfo[$key]}"
done
fi
test -z "$diff"
}
#
# Update metaInfo (on disk) based on the makeInfo
#
performUpdate()
{
[ -n "${makeInfo[cached]}" ] || getMakeInfo
[ -n "${metaInfo[cached]}" ] || getMetaInfo
# Local copies of the make info
local api="${makeInfo[api]}"
local branch="${makeInfo[branch]}"
local build="${makeInfo[build]}"
local patch="${makeInfo[patch]}"
# If any of the make-info are empty (bad),
# use the meta-info to avoid spurious changes
[ -n "$api" ] || api="${metaInfo[api]}"
[ -n "$branch" ] || branch="${metaInfo[branch]}"
[ -n "$build" ] || build="${metaInfo[build]}"
local outputFile
# build-info
outputFile="$metaInfoDir/build-info"
if [ "$branch" != "${metaInfo[branch]}" ] || \
[ "$build" != "${metaInfo[build]}" ] || \
[ "$patch" != "${metaInfo[patch]}" ]
then
patch="${metaInfo[patch]}" # <- From meta-info only
: "${patch:=0}" # Extra safety
if [ -n "$optDryRun" ]
then
echo "dry-run (update) ${outputFile##*/} branch=${branch}" 1>&2
echo "dry-run (update) ${outputFile##*/} build=${build}" 1>&2
echo "dry-run (update) ${outputFile##*/} patch=${patch}" 1>&2
else
echo "branch=${branch}" >| "$outputFile"
echo "build=${build}" >> "$outputFile"
echo "patch=${patch}" >> "$outputFile"
fi
fi
# api-info
outputFile="$metaInfoDir/api-info"
if [ "$api" != "${metaInfo[api]}" ]
then
patch="${metaInfo[patch]}" # <- From meta-info only
: "${patch:=0}" # Extra safety
if [ -n "$optDryRun" ]
then
echo "dry-run (update) ${outputFile##*/} api=${api}" 1>&2
echo "dry-run (update) ${outputFile##*/} patch=${patch}" 1>&2
else
echo "api=${api}" >| "$outputFile"
echo "patch=${patch}" >> "$outputFile"
fi
fi
return 0
}
#
# Update metaInfo (on disk) based on the makeInfo
# This is the
#
performFiltering()
{
local input="$1"
[ -f "$input" ] || {
echo "Error in ${0##*/}: file not found '$1'" 1>&2
exit 2
}
[ -n "${makeInfo[cached]}" ] || getMakeInfo
[ -n "${metaInfo[cached]}" ] || getMetaInfo
# Local copies of the make info
local api="${makeInfo[api]}"
local branch="${makeInfo[branch]}"
local build="${makeInfo[build]}"
local patch="${metaInfo[patch]}" # <- From meta-info only
: "${patch:=0}" # Extra safety
# If any of the make-info are empty (bad),
# conjure up something from the meta-info
# api is not normally needed (available directly from -Ddefine)
# but we may wish to filter other types of files
if [ -z "$api" ]
then
api="${metaInfo[api]}"
api="${api:-0}" # integer value
fi
# branch/build could be missing for non-git
if [ -z "$branch" ]
then
branch="${metaInfo[branch]}"
branch="${branch:-unknown}"
fi
if [ -z "$build" ]
then
build="${metaInfo[build]}"
build="nogit${build:+-$build}"
fi
sed \
-e 's!@API@!'"${api}"'!g' \
-e 's!@PATCH@!'"${patch:-0}"'!g' \
-e 's!@BRANCH@!'"${branch}"'!g' \
-e 's!@BUILD@!'"${build}"'!g' \
-e 's!@VERSION@!'"${WM_PROJECT_VERSION}"'!g' \
"$input"
return 0
}
#------------------------------------------------------------------------------
# Dispatching
if [ -n "$optCheck" ]
then
checkDiff $optCheck
exit $?
elif [ "$optQuery" = api ]
then
# Show API and exit
getApi
exit $?
elif [ "$optQuery" = patch ]
then
# Show patch level and exit
getPatchLevel
exit $?
else
# Other queries
case "$optQuery" in (*make*) reportMakeInfo ;; esac
case "$optQuery" in (*meta*) reportMetaInfo ;; esac
fi
[ -n "$optUpdate" ] && performUpdate
if [ -n "$optFilter" ]
then
# Perform filter on file
performFiltering "$1"
fi
exit 0 # clean exit
#------------------------------------------------------------------------------

View File

@ -61,6 +61,17 @@ die()
} }
#------------------------------------------------------------------------------
cat << WARN_OBSOLETE 1>&2
###############################################################################
## The wmakePrintBuild utility is OBSOLETE (Dec-2018). ##
## The wmakeBuildInfo utility is to be used instead. ##
###############################################################################
WARN_OBSOLETE
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# Parse arguments and options # Parse arguments and options
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------