ENH: use foamVersion::api internally in etcFiles searching (#1010)

- prefer this to using the OPENFOAM define since this improves the
  internal consistency with the build information.

  The API information could change between builds without the
  etcFiles.C being recompiled whereas the value of
  Foam::foamVersion::api is force updated during the build (triggers
  recompilation of globals.Cver)
This commit is contained in:
Mark Olesen
2018-12-08 17:42:31 +01:00
parent afc373d683
commit 5e4d7386ec
4 changed files with 84 additions and 15 deletions

View File

@ -64,6 +64,11 @@ int main(int argc, char *argv[])
"list", "list",
"List directories or files to be checked" "List directories or files to be checked"
); );
argList::addBoolOption
(
"list-all",
"List all directories (including non-existence ones)"
);
argList::addArgument("file..."); argList::addArgument("file...");
argList::addNote argList::addNote
@ -77,9 +82,15 @@ int main(int argc, char *argv[])
// First handle no parameters // First handle no parameters
if (args.size() == 1) if (args.size() == 1)
{ {
if (args.found("list")) if (args.found("list-all"))
{ {
fileNameList results = findEtcDirs(); fileNameList results = etcDirs(false);
printList(results);
return 0;
}
else if (args.found("list"))
{
fileNameList results = etcDirs();
printList(results); printList(results);
return 0; return 0;
} }

View File

@ -871,8 +871,14 @@ void Foam::argList::parse
if (Pstream::master() && bannerEnabled()) if (Pstream::master() && bannerEnabled())
{ {
IOobject::writeBanner(Info, true) IOobject::writeBanner(Info, true)
<< "Build : " << foamVersion::build.c_str() << "Build : ";
<< " (OPENFOAM=" << OPENFOAM;
if (foamVersion::build.size())
{
Info<< foamVersion::build.c_str() << ' ';
}
Info<< "OPENFOAM=" << foamVersion::api;
if (foamVersion::patched()) if (foamVersion::patched())
{ {
@ -880,7 +886,7 @@ void Foam::argList::parse
Info<< " patch=" << foamVersion::patch.c_str(); Info<< " patch=" << foamVersion::patch.c_str();
} }
Info<< ')' << nl Info<< nl
<< "Arch : " << foamVersion::buildArch << nl << "Arch : " << foamVersion::buildArch << nl
<< "Exec : " << commandLine_.c_str() << nl << "Exec : " << commandLine_.c_str() << nl
<< "Date : " << dateString.c_str() << nl << "Date : " << dateString.c_str() << nl

View File

@ -95,6 +95,7 @@ static inline bool groupResourceDir(Foam::fileName& queried)
is undefined (was this intentional?) is undefined (was this intentional?)
#endif #endif
queried.clear();
return false; return false;
} }
@ -108,7 +109,13 @@ static inline bool groupResourceDir(Foam::fileName& queried)
static inline bool projectResourceDir(Foam::fileName& queried) static inline bool projectResourceDir(Foam::fileName& queried)
{ {
queried = Foam::getEnv("WM_PROJECT_DIR")/"etc"; queried = Foam::getEnv("WM_PROJECT_DIR")/"etc";
return (queried.size() > 3 && Foam::isDir(queried)); if (queried.size() > 3)
{
return Foam::isDir(queried);
}
queried.clear();
return false;
} }
@ -119,8 +126,9 @@ Foam::fileNameList searchEtc
bool (*accept)(const Foam::fileName&) bool (*accept)(const Foam::fileName&)
) )
{ {
// Could use foamVersion::api, but this more direct. // Use foamVersion::api (instead of the OPENFOAM define) to ensure this
const Foam::fileName version(std::to_string(OPENFOAM)); // stays properly synchronized with the build information
const Foam::fileName version(std::to_string(Foam::foamVersion::api));
Foam::fileNameList list; Foam::fileNameList list;
Foam::fileName dir, candidate; Foam::fileName dir, candidate;
@ -192,6 +200,42 @@ Foam::fileNameList searchEtc
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Foam::fileNameList Foam::etcDirs(bool test)
{
// Use foamVersion::api (instead of the OPENFOAM define) to ensure this
// stays properly synchronized with the build information
const Foam::fileName version(std::to_string(Foam::foamVersion::api));
Foam::fileNameList list(5);
Foam::fileName dir;
label nDirs = 0;
// User resource directories
if (userResourceDir(dir) || (!test && dir.size()))
{
list[nDirs++] = dir/version;
list[nDirs++] = dir;
}
// Group (site) resource directories
if (groupResourceDir(dir) || (!test && dir.size()))
{
list[nDirs++] = dir/version;
list[nDirs++] = dir;
}
// Other (project) resource directory
if (projectResourceDir(dir) || (!test && dir.size()))
{
list[nDirs++] = dir;
}
list.resize(nDirs);
return list;
}
Foam::fileNameList Foam::findEtcDirs Foam::fileNameList Foam::findEtcDirs
( (
const fileName& name, const fileName& name,

View File

@ -44,6 +44,14 @@ namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
//- The etc search directories in the normal search order.
//
// \param test false to disable the default test for directory existence.
//
// \return The list of directories
fileNameList etcDirs(bool test=true);
//- Search for directories from user/group/other directories. //- Search for directories from user/group/other directories.
// Uses search hierarchy as per findEtcFiles(). // Uses search hierarchy as per findEtcFiles().
// //
@ -51,8 +59,8 @@ namespace Foam
// an empty list if the name cannot be found. // an empty list if the name cannot be found.
fileNameList findEtcDirs fileNameList findEtcDirs
( (
const fileName& name=fileName::null, //!< the file to search for const fileName& name, //!< The directory to search for
const bool findFirst=false //!< stop when the first file has been found const bool findFirst=false //!< Stop after locating the first directory
); );
@ -76,9 +84,9 @@ fileNameList findEtcDirs
// an empty list if the name cannot be found. // an empty list if the name cannot be found.
fileNameList findEtcFiles fileNameList findEtcFiles
( (
const fileName& name, //!< the file to search for const fileName& name, //!< The file to search for
const bool mandatory=false, //!< abort if the file cannot be found const bool mandatory=false, //!< Abort if the file cannot be found
const bool findFirst=false //!< stop when the first file has been found const bool findFirst=false //!< Stop after locating the first directory
); );
@ -88,8 +96,8 @@ fileNameList findEtcFiles
// search hierarchy or an empty fileName if the name cannot be found. // search hierarchy or an empty fileName if the name cannot be found.
fileName findEtcFile fileName findEtcFile
( (
const fileName& name, //!< the file to search for const fileName& name, //!< The file to search for
const bool mandatory=false //!< abort if the file cannot be found const bool mandatory=false //!< Abort if the file cannot be found
); );