Commit 2d51d4b3 authored by Mark Olesen's avatar Mark Olesen
Browse files

ENH: support silent compat versions.

- can tag the version compatibility with a negative number to suppress
  the warnings but retain some information about which version was
  supported.
parent ad82072d
......@@ -25,6 +25,31 @@ License
#include "dictionary.H"
// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
namespace Foam
{
// Should issue warning if there is +ve versioning (+ve version number)
// and if this version number is not in the future (ie, version > current).
// No warning for 0 (unversioned) or -ve values (silent versioning)
static inline constexpr bool shouldWarnVersion(const int version)
{
return
(
version > 0
&&
(
(OPENFOAM_PLUS > 1700) // Guard against bad #define value
? (OPENFOAM_PLUS > version)
: true
)
);
}
} // End namespace Foam
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::dictionary::const_searcher Foam::dictionary::csearchCompat
......@@ -48,9 +73,8 @@ Foam::dictionary::const_searcher Foam::dictionary::csearchCompat
if (finder.found())
{
if (iter.second)
if (shouldWarnVersion(iter.second))
{
// Emit warning, but only if version (non-zero) was provided
std::cerr
<< "--> FOAM IOWarning :" << nl
<< " Found [v" << iter.second << "] '"
......
......@@ -39,7 +39,11 @@ void Foam::error::warnAboutAge
const int oldVersion
)
{
if (oldVersion < 1000)
if (oldVersion <= 0)
{
// No warning for 0 (unversioned) or -ve values (silent versioning)
}
else if (oldVersion < 1000)
{
// Emit warning
std::cerr
......
......@@ -106,9 +106,9 @@ Foam::argList::initValidTables::initValidTables()
Pstream::addValidParOptions(validParOptions);
}
Foam::argList::initValidTables dummyInitValidTables;
// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
namespace Foam
......@@ -168,6 +168,24 @@ static void printBuildInfo(const bool full=true)
}
}
// Should issue warning if there is +ve versioning (+ve version number)
// and if this version number is not in the future (ie, version > current).
// No warning for 0 (unversioned) or -ve values (silent versioning)
static inline constexpr bool shouldWarnVersion(const int version)
{
return
(
version > 0
&&
(
(OPENFOAM_PLUS > 1700) // Guard against bad #define value
? (OPENFOAM_PLUS > version)
: true
)
);
}
} // End namespace Foam
......@@ -448,19 +466,7 @@ Foam::word Foam::argList::optionCompat(const word& optName)
{
const auto& iter = *fnd;
// Emit warning if there is versioning (non-zero) and it is not
// tagged as future change (ie, ThisVersion > version).
if
(
iter.second
&&
(
(OPENFOAM_PLUS > 1700) // Guard against bad #define value
? (OPENFOAM_PLUS > iter.second)
: true
)
)
if (shouldWarnVersion(iter.second))
{
std::cerr
<< "--> FOAM IOWarning :" << nl
......@@ -498,19 +504,7 @@ int Foam::argList::optionIgnore(const word& optName)
// '-option ARG' or '-option'
const int nskip = (iter.first ? 2 : 1);
// Emit warning if there is versioning (non-zero) and it is not
// tagged as future change (ie, ThisVersion > version).
if
(
iter.second
&&
(
(OPENFOAM_PLUS > 1700) // Guard against bad #define value
? (OPENFOAM_PLUS > iter.second)
: true
)
)
if (shouldWarnVersion(iter.second))
{
std::cerr
<< "--> FOAM IOWarning :" << nl
......@@ -1548,9 +1542,9 @@ void Foam::argList::printCompat() const
Info<< setf(ios_base::left) << setw(34) << "old option"
<< setf(ios_base::left) << setw(32) << "new option"
<< "version" << nl
<< setf(ios_base::left) << setw(34) << "~~~~~~~~~~"
<< setf(ios_base::left) << setw(32) << "~~~~~~~~~~"
<< "~~~~~~~" << nl;
<< setf(ios_base::left) << setw(34) << "=========="
<< setf(ios_base::left) << setw(32) << "=========="
<< "=======" << nl;
for (const word& k : argList::validOptionsCompat.sortedToc())
{
......@@ -1559,15 +1553,19 @@ void Foam::argList::printCompat() const
Info<< " -"
<< setf(ios_base::left) << setw(32) << k
<< " -"
<< setf(ios_base::left) << setw(30) << iter.first;
<< setf(ios_base::left) << setw(30) << iter.first << ' ';
if (iter.second)
if (iter.second > 0)
{
Info<< (iter.second);
}
else if (iter.second < 0)
{
Info<< " " << iter.second;
Info<< (-iter.second);
}
else
{
Info<< " -";
Info<< '-';
}
Info<< nl;
}
......@@ -1588,14 +1586,18 @@ void Foam::argList::printCompat() const
<< setf(ios_base::left) << setw(32) << k;
}
Info<< setf(ios_base::left) << setw(32) << " removed";
if (iter.second)
Info<< setf(ios_base::left) << setw(32) << " removed" << ' ';
if (iter.second > 0)
{
Info<< (iter.second);
}
else if (iter.second < 0)
{
Info<< " " << iter.second;
Info<< (-iter.second);
}
else
{
Info<< " -";
Info<< '-';
}
Info<< nl;
}
......
......@@ -440,7 +440,8 @@ public:
// \param optName the currently used option name
// \param compat alias name and the last OpenFOAM version (YYMM)
// when the alias was not needed.
// Setting a version of 0 suppresses warnings about the alias.
// Setting a zero or negative version suppresses warnings about
// the alias.
static void addOptionCompat
(
const word& optName,
......@@ -451,7 +452,8 @@ public:
//
// \param compat optName and the last OpenFOAM version (YYMM)
// when the option was directly supported.
// Setting a version of 0 suppresses warnings about the alias.
// Setting a zero or negative version suppresses warnings about
// the alias.
// \param expectArg the option is non-bool
static void ignoreOptionCompat
(
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment