mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
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:
@ -64,6 +64,11 @@ int main(int argc, char *argv[])
|
||||
"list",
|
||||
"List directories or files to be checked"
|
||||
);
|
||||
argList::addBoolOption
|
||||
(
|
||||
"list-all",
|
||||
"List all directories (including non-existence ones)"
|
||||
);
|
||||
argList::addArgument("file...");
|
||||
|
||||
argList::addNote
|
||||
@ -77,9 +82,15 @@ int main(int argc, char *argv[])
|
||||
// First handle no parameters
|
||||
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);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -871,8 +871,14 @@ void Foam::argList::parse
|
||||
if (Pstream::master() && bannerEnabled())
|
||||
{
|
||||
IOobject::writeBanner(Info, true)
|
||||
<< "Build : " << foamVersion::build.c_str()
|
||||
<< " (OPENFOAM=" << OPENFOAM;
|
||||
<< "Build : ";
|
||||
|
||||
if (foamVersion::build.size())
|
||||
{
|
||||
Info<< foamVersion::build.c_str() << ' ';
|
||||
}
|
||||
|
||||
Info<< "OPENFOAM=" << foamVersion::api;
|
||||
|
||||
if (foamVersion::patched())
|
||||
{
|
||||
@ -880,7 +886,7 @@ void Foam::argList::parse
|
||||
Info<< " patch=" << foamVersion::patch.c_str();
|
||||
}
|
||||
|
||||
Info<< ')' << nl
|
||||
Info<< nl
|
||||
<< "Arch : " << foamVersion::buildArch << nl
|
||||
<< "Exec : " << commandLine_.c_str() << nl
|
||||
<< "Date : " << dateString.c_str() << nl
|
||||
|
||||
@ -95,6 +95,7 @@ static inline bool groupResourceDir(Foam::fileName& queried)
|
||||
is undefined (was this intentional?)
|
||||
#endif
|
||||
|
||||
queried.clear();
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -108,7 +109,13 @@ static inline bool groupResourceDir(Foam::fileName& queried)
|
||||
static inline bool projectResourceDir(Foam::fileName& queried)
|
||||
{
|
||||
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&)
|
||||
)
|
||||
{
|
||||
// Could use foamVersion::api, but this more direct.
|
||||
const Foam::fileName version(std::to_string(OPENFOAM));
|
||||
// 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;
|
||||
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
|
||||
(
|
||||
const fileName& name,
|
||||
|
||||
@ -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.
|
||||
// Uses search hierarchy as per findEtcFiles().
|
||||
//
|
||||
@ -51,8 +59,8 @@ namespace Foam
|
||||
// an empty list if the name cannot be found.
|
||||
fileNameList findEtcDirs
|
||||
(
|
||||
const fileName& name=fileName::null, //!< the file to search for
|
||||
const bool findFirst=false //!< stop when the first file has been found
|
||||
const fileName& name, //!< The directory to search for
|
||||
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.
|
||||
fileNameList findEtcFiles
|
||||
(
|
||||
const fileName& name, //!< the file to search for
|
||||
const bool mandatory=false, //!< abort if the file cannot be found
|
||||
const bool findFirst=false //!< stop when the first file has been found
|
||||
const fileName& name, //!< The file to search for
|
||||
const bool mandatory=false, //!< Abort if the file cannot be 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.
|
||||
fileName findEtcFile
|
||||
(
|
||||
const fileName& name, //!< the file to search for
|
||||
const bool mandatory=false //!< abort if the file cannot be found
|
||||
const fileName& name, //!< The file to search for
|
||||
const bool mandatory=false //!< Abort if the file cannot be found
|
||||
);
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user