ENH: improve consistency in version handling for foamEtcFile (issue #1010)

- Prefer the $WM_PROJECT_VERSION from the environment, since this
  is consistent with the foamEtcFile script, and matches better to
  user expectations.
This commit is contained in:
Mark Olesen
2018-11-22 12:00:50 +01:00
parent 083e9e9665
commit 85ffe4c648
6 changed files with 86 additions and 109 deletions

View File

@ -109,17 +109,17 @@
#+begin_src C++ #+begin_src C++
//- Search for \em name //- Search for \em name
// in the following hierarchy: // in the following hierarchy:
// -# personal settings: // -# user settings
// - ~/.OpenFOAM/\<VERSION\>/ // - ~/.OpenFOAM/\<VERSION\>/
// <em>for version-specific files</em> // <em>for version-specific files</em>
// - ~/.OpenFOAM/ // - ~/.OpenFOAM/
// <em>for version-independent files</em> // <em>for version-independent files</em>
// -# site-wide settings: // -# group settings
// - $WM_PROJECT_INST_DIR/site/\<VERSION\> // - $WM_PROJECT_INST_DIR/site/\<VERSION\>
// <em>for version-specific files</em> // <em>for version-specific files</em>
// - $WM_PROJECT_INST_DIR/site/ // - $WM_PROJECT_INST_DIR/site/
// <em>for version-independent files</em> // <em>for version-independent files</em>
// -# shipped settings: // -# other (shipped) settings
// - $WM_PROJECT_DIR/etc/ // - $WM_PROJECT_DIR/etc/
// //
// \return the full path name or fileName() if the name cannot be found // \return the full path name or fileName() if the name cannot be found

View File

@ -3,7 +3,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) 2015-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2015-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.
@ -25,27 +25,12 @@ Class
Foam::functionEntries::includeEtcEntry Foam::functionEntries::includeEtcEntry
Description Description
A dictionary directive for including a file found using the findEtcFile() A dictionary directive for including a file found using the
mechanism. Foam::findEtcFile() mechanism.
Specify an etc file to include when reading dictionaries, expects a Specify an etc file to include when reading dictionaries, expects a
single string to follow. single string to follow.
Searches for files from user/group/shipped directories.
The search scheme allows for version-specific and
version-independent files using the following hierarchy:
- \b user settings:
- ~/.OpenFOAM/\<VERSION\>
- ~/.OpenFOAM/
- \b group (site) settings (when $WM_PROJECT_SITE is set):
- $WM_PROJECT_SITE/\<VERSION\>
- $WM_PROJECT_SITE
- \b group (site) settings (when $WM_PROJECT_SITE is not set):
- $WM_PROJECT_INST_DIR/site/\<VERSION\>
- $WM_PROJECT_INST_DIR/site/
- \b other (shipped) settings:
- $WM_PROJECT_DIR/etc/
An example of the \c \#includeEtc directive: An example of the \c \#includeEtc directive:
\verbatim \verbatim
#includeEtc "etcFile" #includeEtc "etcFile"

View File

@ -28,20 +28,9 @@ Description
Specify a functionObject dictionary file to include, expects the Specify a functionObject dictionary file to include, expects the
functionObject name to follow with option arguments (without quotes). functionObject name to follow with option arguments (without quotes).
Searches for functionObject dictionary file in user/group/shipped Uses functionObjectList::readFunctionObject() method to search
directories allowing for version-specific and version-independent files within user/group/other "caseDicts/postProcessing" directories
using the following hierarchy: as per Foam::functionObjectList::findDict() and Foam::findEtcFiles()
- \b user settings:
- ~/.OpenFOAM/\<VERSION\>/caseDicts/postProcessing
- ~/.OpenFOAM/caseDicts/postProcessing
- \b group (site) settings (when $WM_PROJECT_SITE is set):
- $WM_PROJECT_SITE/\<VERSION\>/caseDicts/postProcessing
- $WM_PROJECT_SITE/caseDicts/postProcessing
- \b group (site) settings (when $WM_PROJECT_SITE is not set):
- $WM_PROJECT_INST_DIR/site/\<VERSION\>/caseDicts/postProcessing
- $WM_PROJECT_INST_DIR/site/caseDicts/postProcessing
- \b other (project) settings:
- $WM_PROJECT_DIR/etc/caseDicts/postProcessing
The optional field arguments included in the name are inserted in 'field' or The optional field arguments included in the name are inserted in 'field' or
'fields' entries in the functionObject dictionary and included in the name 'fields' entries in the functionObject dictionary and included in the name

View File

@ -3,7 +3,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 | Copyright (C) 2015-2017 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2015-2018 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -115,8 +115,8 @@ public:
// Static data members // Static data members
//- Default relative path to the directory structure //- Default relative path ("caseDicts/postProcessing") to the
//- containing the functionObject dictionary files //- directory structure containing functionObject dictionary files.
static fileName functionObjectDictPath; static fileName functionObjectDictPath;
@ -189,49 +189,38 @@ public:
//- Find the ID of a given function object by name //- Find the ID of a given function object by name
label findObjectID(const word& name) const; label findObjectID(const word& name) const;
//- Print a list of functionObject configuration files in //- Print a list of functionObject configuration files in the
//- user/group/shipped directories. //- directories located using
// The search scheme allows for version-specific and //- Foam::findEtcDirs("caseDicts/postProcessing")
// version-independent files using the following hierarchy: //
// - \b user settings: // -# \b user settings
// - ~/.OpenFOAM/\<VERSION\>/caseDicts/postProcessing // - ~/.OpenFOAM/$WM_PROJECT_VERSION/"caseDicts/postProcessing"
// - ~/.OpenFOAM/caseDicts/postProcessing // - ~/.OpenFOAM/"caseDicts/postProcessing"
// - \b group (site) settings (when $WM_PROJECT_SITE is set): // -# \b group settings
// - $WM_PROJECT_SITE/\<VERSION\>/caseDicts/postProcessing // - $WM_PROJECT_SITE/$WM_PROJECT_VERSION/"caseDicts/postProcessing"
// - $WM_PROJECT_SITE/caseDicts/postProcessing // - $WM_PROJECT_SITE/"caseDicts/postProcessing"
// - \b group (site) settings (when $WM_PROJECT_SITE is not set): // -# \b other (shipped) settings
// - $WM_PROJECT_INST_DIR/site/\<VERSION\>/caseDicts/postProcessing // - $WM_PROJECT_DIR/etc/"caseDicts/postProcessing"
// - $WM_PROJECT_INST_DIR/site/caseDicts/postProcessing //
// - \b other (shipped) settings: // See further notes in Foam::findEtcFiles()
// - $WM_PROJECT_DIR/etc/caseDicts/postProcessing
static void list(); static void list();
//- Search for functionObject dictionary file in //- Find a functionObject dictionary file in the case
//- user/group/shipped directories. //- \<system\> directory or any directory located using
// The search scheme allows for version-specific and //- Foam::findEtcDirs("caseDicts/postProcessing")
// version-independent files using the following hierarchy:
// - \b user settings:
// - ~/.OpenFOAM/\<VERSION\>/caseDicts/postProcessing
// - ~/.OpenFOAM/caseDicts/postProcessing
// - \b group (site) settings (when $WM_PROJECT_SITE is set):
// - $WM_PROJECT_SITE/\<VERSION\>/caseDicts/postProcessing
// - $WM_PROJECT_SITE/caseDicts/postProcessing
// - \b group (site) settings (when $WM_PROJECT_SITE is not set):
// - $WM_PROJECT_INST_DIR/site/\<VERSION\>/caseDicts/postProcessing
// - $WM_PROJECT_INST_DIR/site/caseDicts/postProcessing
// - \b other (shipped) settings:
// - $WM_PROJECT_DIR/etc/caseDicts/postProcessing
// //
// \return The path of the functionObject dictionary file if found // \return The path of the functionObject dictionary file found
// otherwise an empty path // or an empty path
static fileName findDict(const word& funcName); static fileName findDict(const word& funcName);
//- Read the specified functionObject configuration dictionary parsing //- Read the specified functionObject configuration dictionary parsing
// the optional arguments included in the name 'funcNameArgs0', //- the optional arguments included in the name 'funcNameArgs0',
// inserting 'field' or 'fields' entries as required and merging the //- inserting 'field' or 'fields' entries as required and merging the
// resulting functionObject dictionary into 'functionsDict'. Any //- resulting functionObject dictionary into 'functionsDict'. Any
// fields required to execute the functionObject are added to //- fields required to execute the functionObject are added to
// 'requiredFields' //- 'requiredFields'
//
// Uses functionObjectList::findDict() for searching
static bool readFunctionObject static bool readFunctionObject
( (
const string& funcNameArgs0, const string& funcNameArgs0,

View File

@ -24,8 +24,9 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "etcFiles.H" #include "etcFiles.H"
#include "OSspecific.H"
#include "foamVersion.H" #include "foamVersion.H"
#include "macros.H"
#include "OSspecific.H"
// * * * * * * * * * * * * * * Static Functions * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Functions * * * * * * * * * * * * * * //
@ -64,7 +65,8 @@ static inline bool groupResourceDir(Foam::fileName& queried)
return Foam::isDir(queried); return Foam::isDir(queried);
} }
// When WM_PROJECT_SITE is unset: // Fallback when WM_PROJECT_SITE is unset
queried = Foam::getEnv("WM_PROJECT_INST_DIR")/"site"; queried = Foam::getEnv("WM_PROJECT_INST_DIR")/"site";
return (queried.size() > 4 && Foam::isDir(queried)); return (queried.size() > 4 && Foam::isDir(queried));
@ -96,13 +98,26 @@ Foam::fileNameList searchEtc
bool (*accept)(const Foam::fileName&) bool (*accept)(const Foam::fileName&)
) )
{ {
Foam::fileName version(Foam::getEnv("WM_PROJECT_VERSION"));
// Fallback when WM_PROJECT_VERSION is unset
if (version.empty())
{
#if OPENFOAM
version = STRING_QUOTE(OPENFOAM);
#else
version = foamVersion::version;
#endif
}
Foam::fileNameList list; Foam::fileNameList list;
Foam::fileName dir, candidate; Foam::fileName dir, candidate;
// User resource directories // User resource directories
if (userResourceDir(dir)) if (userResourceDir(dir))
{ {
candidate = dir/foamVersion::version/name; candidate = dir/version/name;
if (accept(candidate)) if (accept(candidate))
{ {
list.append(std::move(candidate)); list.append(std::move(candidate));
@ -126,7 +141,7 @@ Foam::fileNameList searchEtc
// Group resource directories // Group resource directories
if (groupResourceDir(dir)) if (groupResourceDir(dir))
{ {
candidate = dir/foamVersion::version/name; candidate = dir/version/name;
if (accept(candidate)) if (accept(candidate))
{ {
list.append(std::move(candidate)); list.append(std::move(candidate));
@ -177,7 +192,7 @@ Foam::fileNameList Foam::findEtcDirs
( (
name, name,
findFirst, findFirst,
[](const fileName& f){ return isDir(f); } [](const fileName& f){ return Foam::isDir(f); }
); );
} }
@ -198,7 +213,7 @@ Foam::fileNameList Foam::findEtcFiles
( (
name, name,
findFirst, findFirst,
[](const fileName& f){ return isFile(f); } [](const fileName& f){ return Foam::isFile(f); }
); );
} }

View File

@ -3,7 +3,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) 2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 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.
@ -45,45 +45,41 @@ namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
//- Search for directories from user/group/other directories. //- Search for directories from user/group/other directories.
// // Uses search hierarchy as per findEtcFiles().
// \note Uses search hierarchy as per findEtcFiles().
// //
// \return The list of full paths of all the matching directories or // \return The list of full paths of all the matching directories or
// an empty list if the name cannot be found. // an empty list if the name cannot be found.
// Optionally stop search after the first directory has been found.
fileNameList findEtcDirs fileNameList findEtcDirs
( (
const fileName& name = fileName::null, const fileName& name=fileName::null, //!< the file to search for
const bool findFirst = false const bool findFirst=false //!< stop when the first file has been found
); );
//- Search for files from user/group/other directories. //- Search for files from user/group/other directories.
// //
// \note // The search hierarchy corresponds to that of the foamEtcFile script,
// The following search hierarchy is also used by the foamEtcFile shell // which allows for version-specific and version-independent files:
// script, which allows for version-specific and version-independent files: // -# \b user settings
// - \b user settings: // - ~/.OpenFOAM/$WM_PROJECT_VERSION
// - ~/.OpenFOAM/\<VERSION\>
// - ~/.OpenFOAM/ // - ~/.OpenFOAM/
// - \b group settings (when $WM_PROJECT_SITE is set): // -# \b group settings
// - $WM_PROJECT_SITE/\<VERSION\> // - $WM_PROJECT_SITE/$WM_PROJECT_VERSION
// - $WM_PROJECT_SITE // - $WM_PROJECT_SITE/
// - \b group settings (when $WM_PROJECT_SITE is not set): // -# \b other (shipped) settings
// - $WM_PROJECT_INST_DIR/site/\<VERSION\>
// - $WM_PROJECT_INST_DIR/site/
// - \b other (shipped) settings:
// - $WM_PROJECT_DIR/etc/ // - $WM_PROJECT_DIR/etc/
// //
// \note Treatment of empty or undefined variables
// - \b \$WM_PROJECT_VERSION : Use compile-time value of OPENFOAM
// - \b \$WM_PROJECT_SITE : Use $WM_PROJECT_INST_DIR/site
//
// \return The list of full paths of all the matching files or // \return The list of full paths of all the matching files or
// an empty list if the name cannot be found. // an empty list if the name cannot be found.
// Optionally abort if the file cannot be found.
// Optionally stop search after the first file has been found.
fileNameList findEtcFiles fileNameList findEtcFiles
( (
const fileName& name, const fileName& name, //!< the file to search for
const bool mandatory = false, const bool mandatory=false, //!< abort if the file cannot be found
const bool findFirst = false const bool findFirst=false //!< stop when the first file has been found
); );
@ -91,8 +87,11 @@ fileNameList findEtcFiles
// //
// \return The full path name of the first file found in the // \return The full path name of the first file found in the
// search hierarchy or an empty fileName if the name cannot be found. // search hierarchy or an empty fileName if the name cannot be found.
// Optionally abort if the file cannot be found but is mandatory. fileName findEtcFile
fileName findEtcFile(const fileName& name, const bool mandatory=false); (
const fileName& name, //!< the file to search for
const bool mandatory=false //!< abort if the file cannot be found
);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //