openfoam/applications/utilities/miscellaneous/foamHasLibrary/foamHasLibrary.C
Mark Olesen 5a121119e6 ENH: add -verbose support into argList
- similar to -dry-run handling, can be interrogated from argList,
  which makes it simpler to add into utilities.

- support multiple uses of -dry-run and -verbose to increase the
  level. For example, could have

    someApplication -verbose -verbose

 and inside of the application:

    if (args.verbose() > 2) ...

BUG: error with empty distributed roots specification (fixes #2196)

- previously used the size of distributed roots to transmit if the
  case was running in distributed mode, but this behaves rather poorly
  with bad input. Specifically, the following questionable setup:

      distributed true;
      roots ( /*none*/ );

  Now transmit the ParRunControl distributed() value instead,
  and also emit a gentle warning for the user:

      WARNING: running distributed but did not specify roots!
2021-11-09 15:44:54 +01:00

154 lines
3.9 KiB
C

/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2020-2021 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/>.
Application
foamHasLibrary
Group
grpMiscUtilities
Description
Test if given libraries can be loaded.
Usage
\b foamHasLibrary [OPTION] lib...
Options:
- \par -or
Success if any of the libraries can be loaded.
Does not short-circuit.
- \par -detail
Additional detail (meaning may change).
- \par -verbose
Additional verbosity
Note
No normal output.
\*---------------------------------------------------------------------------*/
#include "argList.H"
#include "profiling.H"
using namespace Foam;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
int main(int argc, char *argv[])
{
argList::addNote("Test if given libraries can be loaded");
profiling::disable(); // No profiling output
argList::noBanner();
argList::noParallel();
argList::removeOption("case");
argList::removeOption("noFunctionObjects");
argList::addBoolOption
(
"or",
"Success if any of the libraries can be loaded\n"
"(does not short-circuit)"
);
argList::addBoolOption
(
"detail",
"Additional detail"
);
argList::addVerboseOption
(
"Additional verbosity"
);
argList::addArgument("lib...");
argList::noMandatoryArgs(); // Arguments are optional
argList args(argc, argv, false, true);
// Force dlOpen of FOAM_DLOPEN_LIBS (principally for Windows applications)
#include "foamDlOpenLibs.H"
const bool testOr = args.found("or");
const bool detail = args.found("detail");
label ngood = 0;
label nbad = 0;
dlLibraryTable& libs = args.libs();
wordHashSet loaded;
for (int argi = 1; argi < args.size(); ++argi)
{
const auto libName = args.get<fileName>(argi); // with validate
if (libName.empty())
{
continue;
}
// InfoErr << "Check " << libName << nl;
// Could have libs.findLibrary(...)
// if we really expect many duplicates
const void* ptr = libs.open(libName, false);
if (!ptr)
{
++nbad;
}
else
{
++ngood;
if (args.verbose())
{
const word addr(Foam::name(ptr));
if (loaded.insert(addr))
{
InfoErr << "Can load " << libName << nl;
}
else
{
InfoErr << "Already loaded " << libName << nl;
}
}
}
}
if (detail)
{
InfoErr << libs.info();
}
return (nbad == 0 || (testOr && ngood > 0)) ? 0 : 1;
}
// ************************************************************************* //