From bef508dedc1a55513c46ed5e8f80433dc16c9a82 Mon Sep 17 00:00:00 2001
From: Mark Olesen <Mark.Olesen@esi-group.com>
Date: Thu, 10 Jan 2019 12:21:19 +0100
Subject: [PATCH] ENH: make use of FOAM_API for environment as well (issue
 #1158)

- was WM_PROJECT_API in the environment and FOAM_API in dictionaries.

  Make these both consistently FOAM_API.
  This is a non-breaking change, since the value of WM_PROJECT_API
  (added in 1812) and/or FOAM_API is purely informative.
  For the current correct values, always use

    * foamEtcFile -show-api
    * wmakeBuildInfo -show-api
---
 bin/foamLog                  |  6 +++---
 bin/foamNewCase              |  8 ++++----
 bin/foamUpdateCaseFileHeader |  6 +++---
 bin/mpirunDebug              |  8 ++++----
 bin/tools/change-sitedir.sh  |  4 ++--
 etc/bashrc                   |  6 +++---
 etc/config.csh/settings      |  8 ++++----
 etc/config.csh/setup         | 10 +++++-----
 etc/config.sh/settings       |  8 ++++----
 etc/config.sh/setup          | 10 +++++-----
 etc/cshrc                    |  6 +++---
 wmake/wmakeScheduler         | 28 ++++++++++++++++------------
 wmake/wmakeSchedulerUptime   | 28 ++++++++++++++++------------
 13 files changed, 72 insertions(+), 64 deletions(-)

diff --git a/bin/foamLog b/bin/foamLog
index 26038323094..cd68971205e 100755
--- a/bin/foamLog
+++ b/bin/foamLog
@@ -29,7 +29,7 @@
 #     Extract data for each time-step from a log file for graphing.
 #
 # Environment
-#     WM_PROJECT_API
+#     FOAM_API
 #     WM_PROJECT_DIR
 #     WM_PROJECT_SITE
 #
@@ -90,9 +90,9 @@ cat <<HELP
 
     The database ($Script.db) will taken from these locations:
         .
-        $userDir/$WM_PROJECT_API/
+        $userDir/$FOAM_API/
         $userDir/
-        $groupDir/$WM_PROJECT_API/etc/
+        $groupDir/$FOAM_API/etc/
         $groupDir/etc/
         $WM_PROJECT_DIR/etc/
         $toolsDir
diff --git a/bin/foamNewCase b/bin/foamNewCase
index 9565606a1b4..ca9c2c1b1b8 100755
--- a/bin/foamNewCase
+++ b/bin/foamNewCase
@@ -4,7 +4,7 @@
 # \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
 #  \\    /   O peration     |
 #   \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
-#    \\/     M anipulation  | Copyright (C) 2018 OpenCFD Ltd.
+#    \\/     M anipulation  | Copyright (C) 2018-2019 OpenCFD Ltd.
 #-------------------------------------------------------------------------------
 # License
 #     This file is part of OpenFOAM.
@@ -30,14 +30,14 @@
 #     - requires rsync
 #
 # Environment
-#     WM_PROJECT_API
+#     FOAM_API
 #     WM_PROJECT_DIR
 #     WM_PROJECT_SITE
 #
 #------------------------------------------------------------------------------
 groupDir="${WM_PROJECT_SITE:-${WM_PROJECT_DIR:-<unknown>}/site}"
 userDir="$HOME/.OpenFOAM"
-projectApi="${WM_PROJECT_API:-unknown}"
+projectApi="${FOAM_API:-unknown}"
 
 templateDir="appTemplates"
 
@@ -52,7 +52,7 @@ options:
   -app NAME         specify the application to use
   -case DIR         specify alternative case directory, default is the cwd
   -list             list the applications available
-  -with-api=NUM     specify alternative api to use (default: \$WM_PROJECT_API)
+  -with-api=NUM     specify alternative api to use (default: \$FOAM_API)
   -version VER      [obsolete]
   -help             Print the usage
 
diff --git a/bin/foamUpdateCaseFileHeader b/bin/foamUpdateCaseFileHeader
index 11f110a045d..c77fa4305c4 100755
--- a/bin/foamUpdateCaseFileHeader
+++ b/bin/foamUpdateCaseFileHeader
@@ -4,7 +4,7 @@
 # \\      /  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.
+#    \\/     M anipulation  | Copyright (C) 2018-2019 OpenCFD Ltd.
 #------------------------------------------------------------------------------
 # License
 #     This file is part of OpenFOAM.
@@ -74,9 +74,9 @@ do
     esac
 done
 
-# Constant width for version - default to WM_PROJECT_API
+# Constant width for version - default to FOAM_API
 
-: ${version:=$WM_PROJECT_API}
+: ${version:=$FOAM_API}
 : ${version:=$WM_PROJECT_VERSION}
 
 version=$(printf %-36s ${version:-OPENFOAM})
diff --git a/bin/mpirunDebug b/bin/mpirunDebug
index 61d2f212d85..d672bf14ea6 100755
--- a/bin/mpirunDebug
+++ b/bin/mpirunDebug
@@ -196,13 +196,13 @@ sourceFoam=false    # Fallback command
 
 # Same as foamEtcFile -mode=uo bashrc
 #
-# check ~/.$WM_PROJECT/$WM_PROJECT_API/
+# check ~/.$WM_PROJECT/$FOAM_API/
 # check ~/.$WM_PROJECT/
-# check <installedProject>/etc/
-if [ -n "$WM_PROJECT" ]
+# check projectDir/etc/
+if [ -n "$WM_PROJECT_DIR" ]
 then
     for i in \
-        "$HOME/.$WM_PROJECT/$WM_PROJECT_API" \
+        "$HOME/.$WM_PROJECT/$FOAM_API" \
         "$HOME/.$WM_PROJECT" \
         "$WM_PROJECT_DIR/etc" \
         ;
diff --git a/bin/tools/change-sitedir.sh b/bin/tools/change-sitedir.sh
index f66504a2255..da982408830 100644
--- a/bin/tools/change-sitedir.sh
+++ b/bin/tools/change-sitedir.sh
@@ -2,7 +2,7 @@
 # =========                 |
 # \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
 #  \\    /   O peration     |
-#   \\  /    A nd           | Copyright (C) 2017-2018 OpenCFD Ltd.
+#   \\  /    A nd           | Copyright (C) 2017-2019 OpenCFD Ltd.
 #    \\/     M anipulation  |
 #------------------------------------------------------------------------------
 # License
@@ -46,7 +46,7 @@
 #
 #   corresponds to the standard site location:
 #
-#     $WM_PROJECT_DIR/site{/$WM_PROJECT_API/platforms/$WM_OPTIONS}
+#     $WM_PROJECT_DIR/site{/$FOAM_API/platforms/$WM_OPTIONS}
 #
 #------------------------------------------------------------------------------
 
diff --git a/etc/bashrc b/etc/bashrc
index b38f5f5b141..ba82317ff62 100644
--- a/etc/bashrc
+++ b/etc/bashrc
@@ -3,7 +3,7 @@
 # \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
 #  \\    /   O peration     |
 #   \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
-#    \\/     M anipulation  | Copyright (C) 2016-2018 OpenCFD Ltd.
+#    \\/     M anipulation  | Copyright (C) 2016-2019 OpenCFD Ltd.
 #------------------------------------------------------------------------------
 # License
 #     This file is part of OpenFOAM, licensed under GNU General Public License
@@ -22,9 +22,9 @@
 #         -  $WM_PROJECT_DIR/etc/prefs.sh
 #
 #       - User or group values (first file found):
-#         -  ~/.OpenFOAM/$WM_PROJECT_API/prefs.sh
+#         -  ~/.OpenFOAM/$FOAM_API/prefs.sh
 #         -  ~/.OpenFOAM/prefs.sh
-#         -  $WM_PROJECT_SITE/$WM_PROJECT_API/etc/prefs.sh
+#         -  $WM_PROJECT_SITE/$FOAM_API/etc/prefs.sh
 #         -  $WM_PROJECT_SITE/etc/prefs.sh
 #
 # Environment
diff --git a/etc/config.csh/settings b/etc/config.csh/settings
index ac09ece5bd3..0fdf93f8d1d 100644
--- a/etc/config.csh/settings
+++ b/etc/config.csh/settings
@@ -3,7 +3,7 @@
 # \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
 #  \\    /   O peration     |
 #   \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
-#    \\/     M anipulation  | Copyright (C) 2016-2018 OpenCFD Ltd.
+#    \\/     M anipulation  | Copyright (C) 2016-2019 OpenCFD Ltd.
 #------------------------------------------------------------------------------
 # License
 #     This file is part of OpenFOAM, licensed under GNU General Public License
@@ -183,11 +183,11 @@ endif
 setenv PATH "${WM_PROJECT_DIR}/bin:${PATH}"
 
 # Prepend site-specific scripts to path - only if they exist
-if ( -d "$siteDir/bin" ) then                   # Generic
+if ( -d "$siteDir/bin" ) then               # Generic
     _foamAddPath "$siteDir/bin"
 endif
-if ( -d "$siteDir/$WM_PROJECT_API/bin" ) then   # API-specific
-    _foamAddPath "$siteDir/$WM_PROJECT_API/bin"
+if ( -d "$siteDir/$FOAM_API/bin" ) then     # API-specific
+    _foamAddPath "$siteDir/$FOAM_API/bin"
 endif
 
 # OpenFOAM executables (user, group, standard)
diff --git a/etc/config.csh/setup b/etc/config.csh/setup
index a1152d8a74d..9b06d1818ed 100644
--- a/etc/config.csh/setup
+++ b/etc/config.csh/setup
@@ -2,7 +2,7 @@
 # =========                 |
 # \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
 #  \\    /   O peration     |
-#   \\  /    A nd           | Copyright (C) 2018 OpenCFD Ltd.
+#   \\  /    A nd           | Copyright (C) 2018-2019 OpenCFD Ltd.
 #    \\/     M anipulation  |
 #------------------------------------------------------------------------------
 # License
@@ -24,8 +24,8 @@
 #
 #------------------------------------------------------------------------------
 
-# [WM_PROJECT_API] - The API level for the project
-setenv WM_PROJECT_API `$WM_PROJECT_DIR/bin/foamEtcFile -show-api`
+# [FOAM_API] - The API level for the project
+setenv FOAM_API `$WM_PROJECT_DIR/bin/foamEtcFile -show-api`
 
 # The installation parent directory
 set prefixDir="${WM_PROJECT_DIR:h}"
@@ -51,8 +51,8 @@ _foamEcho "Locating ThirdParty directory"
 foreach foamDir (\
     "$WM_PROJECT_DIR/ThirdParty" \
     "$prefixDir/ThirdParty-$WM_PROJECT_VERSION" \
-    "$prefixDir/ThirdParty-v$WM_PROJECT_API" \
-    "$prefixDir/ThirdParty-$WM_PROJECT_API" \
+    "$prefixDir/ThirdParty-v$FOAM_API" \
+    "$prefixDir/ThirdParty-$FOAM_API" \
     "$prefixDir/ThirdParty-common" \
 )
     _foamEcho "... $foamDir"
diff --git a/etc/config.sh/settings b/etc/config.sh/settings
index c0ea5654aa7..31a4d2138c9 100644
--- a/etc/config.sh/settings
+++ b/etc/config.sh/settings
@@ -3,7 +3,7 @@
 # \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
 #  \\    /   O peration     |
 #   \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
-#    \\/     M anipulation  | Copyright (C) 2016-2018 OpenCFD Ltd.
+#    \\/     M anipulation  | Copyright (C) 2016-2019 OpenCFD Ltd.
 #------------------------------------------------------------------------------
 # License
 #     This file is part of OpenFOAM, licensed under GNU General Public License
@@ -180,13 +180,13 @@ fi
 export PATH="$WM_PROJECT_DIR/bin:$PATH"
 
 # Prepend site-specific scripts to path - only if they exist
-if [ -d "$siteDir/bin" ]                        # Generic
+if [ -d "$siteDir/bin" ]                # Generic
 then
     _foamAddPath "$siteDir/bin"
 fi
-if [ -d "$siteDir/$WM_PROJECT_API/bin" ]        # API-specific
+if [ -d "$siteDir/$FOAM_API/bin" ]      # API-specific
 then
-    _foamAddPath "$siteDir/$WM_PROJECT_API/bin"
+    _foamAddPath "$siteDir/$FOAM_API/bin"
 fi
 
 # OpenFOAM executables (user, group, standard)
diff --git a/etc/config.sh/setup b/etc/config.sh/setup
index 40ab0012f72..c963a9107d2 100644
--- a/etc/config.sh/setup
+++ b/etc/config.sh/setup
@@ -24,8 +24,8 @@
 #
 #------------------------------------------------------------------------------
 
-# [WM_PROJECT_API] - The API level for the project
-export WM_PROJECT_API="$($WM_PROJECT_DIR/bin/foamEtcFile -show-api)"
+# [FOAM_API] - The API level for the project
+export FOAM_API="$($WM_PROJECT_DIR/bin/foamEtcFile -show-api)"
 
 # The installation parent directory
 prefixDir="${WM_PROJECT_DIR%/*}"
@@ -51,9 +51,9 @@ _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-$FOAM_API" \
+    "$prefixDir/ThirdParty-v$FOAM_API" \
+    "$prefixDir/ThirdParty-$FOAM_API" \
     "$prefixDir/ThirdParty-common" \
     ;
 do
diff --git a/etc/cshrc b/etc/cshrc
index 8da66078bf3..a37a0906547 100644
--- a/etc/cshrc
+++ b/etc/cshrc
@@ -3,7 +3,7 @@
 # \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
 #  \\    /   O peration     |
 #   \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
-#    \\/     M anipulation  | Copyright (C) 2016-2018 OpenCFD Ltd.
+#    \\/     M anipulation  | Copyright (C) 2016-2019 OpenCFD Ltd.
 #------------------------------------------------------------------------------
 # License
 #     This file is part of OpenFOAM, licensed under GNU General Public License
@@ -22,9 +22,9 @@
 #         -  $WM_PROJECT_DIR/etc/prefs.csh
 #
 #       - User or group values (first file found):
-#         -  ~/.OpenFOAM/$WM_PROJECT_API/prefs.csh
+#         -  ~/.OpenFOAM/$FOAM_API/prefs.csh
 #         -  ~/.OpenFOAM/prefs.csh
-#         -  $WM_PROJECT_SITE/$WM_PROJECT_API/etc/prefs.csh
+#         -  $WM_PROJECT_SITE/$FOAM_API/etc/prefs.csh
 #         -  $WM_PROJECT_SITE/prefs.csh
 #
 # Environment
diff --git a/wmake/wmakeScheduler b/wmake/wmakeScheduler
index 08b05d5d526..0a92eaa0d84 100755
--- a/wmake/wmakeScheduler
+++ b/wmake/wmakeScheduler
@@ -4,7 +4,7 @@
 # \\      /  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.
+#    \\/     M anipulation  | Copyright (C) 2018-2019 OpenCFD Ltd.
 #-------------------------------------------------------------------------------
 # License
 #     This file is part of OpenFOAM.
@@ -44,20 +44,24 @@
 #     Sources the relevant cshrc/bashrc if not set.
 #
 # Environment
+#     - FOAM_API
 #     - WM_PROJECT_DIR
-#     - WM_PROJECT
-#     - WM_PROJECT_API
+#     - WM_PROJECT  (defaults to OpenFOAM)
 #
 #-------------------------------------------------------------------------------
-Script=${0##*/}
+Script="${0##*/}"
 
-# csh sets HOST, bash sets HOSTNAME
-: ${HOST:=$HOSTNAME}
+# Default project
+[ -n "$WM_PROJECT" ] || WM_PROJECT=OpenFOAM
 
 lockDir="$HOME/.$WM_PROJECT/.wmake"
 
+# csh sets HOST, bash sets HOSTNAME
+[ -n "$HOST" ] || HOST="$HOSTNAME"
+
 # Fallback - 1 core on current host
-: ${WM_HOSTS:=$HOST:1}
+[ -n "$WM_HOSTS" ] || WM_HOSTS="${HOST}:1"
+
 
 # Count the total number of slots available and exit
 if [ "$1" = "-count" ]
@@ -90,13 +94,13 @@ esac
 
 # Same as foamEtcFile -mode=uo bashrc
 #
-# Check ~/.$WM_PROJECT/$WM_PROJECT_API/
+# Check ~/.$WM_PROJECT/$FOAM_API/
 # Check ~/.$WM_PROJECT/
 # Check projectDir/etc/
-if [ -n "$WM_PROJECT" ]
+if [ -n "$WM_PROJECT_DIR" ]
 then
     for i in \
-        "$HOME/.$WM_PROJECT/$WM_PROJECT_API" \
+        "$HOME/.$WM_PROJECT/$FOAM_API" \
         "$HOME/.$WM_PROJECT" \
         "$WM_PROJECT_DIR/etc" \
         ;
@@ -114,11 +118,11 @@ fi
 # Use FOAM_SETTINGS to pass command-line settings
 case "$sourceFoam" in
 */bashrc)
-    sourceFoam='[ -n "$WM_PROJECT" ] || '". $sourceFoam $FOAM_SETTINGS"
+    sourceFoam='[ -n "$WM_PROJECT_DIR" ] || '". $sourceFoam $FOAM_SETTINGS"
     ;;
 
 */cshrc)
-    sourceFoam='if ( ! $?WM_PROJECT ) source '"$sourceFoam $FOAM_SETTINGS"
+    sourceFoam='if ( ! $?WM_PROJECT_DIR ) source '"$sourceFoam $FOAM_SETTINGS"
     ;;
 esac
 
diff --git a/wmake/wmakeSchedulerUptime b/wmake/wmakeSchedulerUptime
index ec8d2e72484..2873d35d478 100755
--- a/wmake/wmakeSchedulerUptime
+++ b/wmake/wmakeSchedulerUptime
@@ -4,7 +4,7 @@
 # \\      /  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.
+#    \\/     M anipulation  | Copyright (C) 2018-2019 OpenCFD Ltd.
 #-------------------------------------------------------------------------------
 # License
 #     This file is part of OpenFOAM.
@@ -44,20 +44,24 @@
 #     Sources the relevant cshrc/bashrc if not set.
 #
 # Environment
+#     - FOAM_API
 #     - WM_PROJECT_DIR
-#     - WM_PROJECT
-#     - WM_PROJECT_API
+#     - WM_PROJECT  (defaults to OpenFOAM)
 #
 #-------------------------------------------------------------------------------
-Script=${0##*/}
+Script="${0##*/}"
 
-# csh sets HOST, bash sets HOSTNAME
-: ${HOST:=$HOSTNAME}
+# Default project
+[ -n "$WM_PROJECT" ] || WM_PROJECT=OpenFOAM
 
 lockDir="$HOME/.$WM_PROJECT/.wmake"
 
+# csh sets HOST, bash sets HOSTNAME
+[ -n "$HOST" ] || HOST="$HOSTNAME"
+
 # Fallback - 1 core on current host
-: ${WM_HOSTS:=$HOST:1}
+[ -n "$WM_HOSTS" ] || WM_HOSTS="${HOST}:1"
+
 
 # Count the total number of slots available and exit
 if [ "$1" = "-count" ]
@@ -90,13 +94,13 @@ esac
 
 # Same as foamEtcFile -mode=uo bashrc
 #
-# Check ~/.$WM_PROJECT/$WM_PROJECT_API/
+# Check ~/.$WM_PROJECT/$FOAM_API/
 # Check ~/.$WM_PROJECT/
 # Check projectDir/etc/
-if [ -n "$WM_PROJECT" ]
+if [ -n "$WM_PROJECT_DIR" ]
 then
     for i in \
-        "$HOME/.$WM_PROJECT/$WM_PROJECT_API" \
+        "$HOME/.$WM_PROJECT/$FOAM_API" \
         "$HOME/.$WM_PROJECT" \
         "$WM_PROJECT_DIR/etc" \
         ;
@@ -114,11 +118,11 @@ fi
 # Use FOAM_SETTINGS to pass command-line settings
 case "$sourceFoam" in
 */bashrc)
-    sourceFoam='[ -n "$WM_PROJECT" ] || '". $sourceFoam $FOAM_SETTINGS"
+    sourceFoam='[ -n "$WM_PROJECT_DIR" ] || '". $sourceFoam $FOAM_SETTINGS"
     ;;
 
 */cshrc)
-    sourceFoam='if ( ! $?WM_PROJECT ) source '"$sourceFoam $FOAM_SETTINGS"
+    sourceFoam='if ( ! $?WM_PROJECT_DIR ) source '"$sourceFoam $FOAM_SETTINGS"
     ;;
 esac
 
-- 
GitLab