ENH: isolate version information in foamVersion names instead of globals

- For compatibility, access to the old global names is provided via
  macros
        #define FOAMversion     foamVersion::version
        #define FOAMbuild       foamVersion::build
        #define FOAMbuildArch   foamVersion::buildArch

- this isolation makes it easier to provide additional scoped methods
  for dealing with version related information.  Eg, printBuildInfo()
This commit is contained in:
Mark Olesen
2018-11-22 11:50:24 +01:00
parent 0cae54b3e1
commit 083e9e9665
15 changed files with 156 additions and 89 deletions

View File

@ -1,3 +1,3 @@
Test-foamVersionString.C Test-foamVersion.C
EXE = $(FOAM_USER_APPBIN)/Test-foamVersionString EXE = $(FOAM_USER_APPBIN)/Test-foamVersion

View File

@ -1,2 +1,2 @@
/* EXE_INC = -I$(LIB_SRC)/cfdTools/include */ /* EXE_INC = */
/* EXE_LIBS = -lfiniteVolume */ /* EXE_LIBS = */

View File

@ -0,0 +1,62 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
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
Test-foamVersion
Description
Print the OpenFOAM version information.
\*---------------------------------------------------------------------------*/
#include <iostream>
#include "foamVersion.H"
using namespace Foam;
int main()
{
std::cout
<< "\nVersion information (macros)\n"
<< "version " << Foam::FOAMversion << '\n'
<< "build " << Foam::FOAMbuild << '\n'
<< "buildArch " << Foam::FOAMbuildArch << '\n';
std::cout
<< "\nVersion information (namespace)\n"
<< "version " << foamVersion::version << '\n'
<< "build " << foamVersion::build << '\n'
<< "buildArch " << foamVersion::buildArch << '\n';
std::cout
<< "\nVerify memory addesses are identical:\n"
<< "macro " << long(&(Foam::FOAMversion)) << '\n'
<< "namespace " << long(&(foamVersion::version)) << '\n';
std::cout
<< "\nEnd\n";
return 0;
}
// ************************************************************************* //

View File

@ -8,7 +8,7 @@ int USERD_get_reader_release
Info<< "Entering: USERD_get_reader_release" << endl; Info<< "Entering: USERD_get_reader_release" << endl;
#endif #endif
strncpy(release_number, Foam::FOAMbuild, Z_MAX_USERD_NAME); strncpy(release_number, foamVersion::build, Z_MAX_USERD_NAME);
#ifdef ENSIGHTDEBUG #ifdef ENSIGHTDEBUG
Info<< "Leaving: USERD_get_reader_release" << endl; Info<< "Leaving: USERD_get_reader_release" << endl;

View File

@ -9,6 +9,7 @@ global/profiling/profilingInformation.C
global/profiling/profilingSysInfo.C global/profiling/profilingSysInfo.C
global/profiling/profilingTrigger.C global/profiling/profilingTrigger.C
global/etcFiles/etcFiles.C global/etcFiles/etcFiles.C
global/version/foamVersion.C
fileOps = global/fileOperations fileOps = global/fileOperations
$(fileOps)/fileOperation/fileOperation.C $(fileOps)/fileOperation/fileOperation.C

View File

@ -48,7 +48,7 @@ Foam::Ostream& Foam::IOobject::writeBanner(Ostream& os, bool noHint)
if (!*paddedVersion) if (!*paddedVersion)
{ {
// Populate: like strncpy but without trailing '\0' // Populate: like strncpy but without trailing '\0'
const char *p = Foam::FOAMversion; const char *p = foamVersion::version;
memset(paddedVersion, ' ', 38); memset(paddedVersion, ' ', 38);
for (int i = 0; *p && i < 38; ++i) for (int i = 0; *p && i < 38; ++i)
@ -130,7 +130,7 @@ bool Foam::IOobject::writeHeader(Ostream& os, const word& type) const
if (os.format() == IOstream::BINARY) if (os.format() == IOstream::BINARY)
{ {
os << " arch " << Foam::FOAMbuildArch << ";\n"; os << " arch " << foamVersion::buildArch << ";\n";
} }
if (!note().empty()) if (!note().empty())

View File

@ -211,7 +211,7 @@ void Foam::decomposedBlockData::writeHeader
/* /*
if (os.format() == IOstream::BINARY) if (os.format() == IOstream::BINARY)
{ {
os << " arch " << Foam::FOAMbuildArch << ";\n"; os << " arch " << foamVersion::buildArch << ";\n";
} }
*/ */

View File

@ -181,24 +181,6 @@ static void printHostsSubscription(const UList<string>& slaveProcs)
Info<< ")" << nl; Info<< ")" << nl;
} }
// Print information about version, build, arch
static void printBuildInfo(const bool full=true)
{
Info<<"Using: OpenFOAM-" << Foam::FOAMversion
<< " (see www.OpenFOAM.com)" << nl
<< "Build: " << Foam::FOAMbuild
#if OPENFOAM
<< " (OPENFOAM=" << OPENFOAM << ')'
#endif
<< nl;
if (full)
{
Info << "Arch: " << Foam::FOAMbuildArch.c_str() << nl;
}
}
} // End namespace Foam } // End namespace Foam
@ -776,7 +758,7 @@ Foam::argList::argList
++argi; ++argi;
if (argi >= args_.size()) if (argi >= args_.size())
{ {
printBuildInfo(false); foamVersion::printBuildInfo(false);
Info<<nl Info<<nl
<<"Error: option '-" << optName <<"Error: option '-" << optName
@ -903,7 +885,7 @@ void Foam::argList::parse
// Print the collected error messages and exit if check fails // Print the collected error messages and exit if check fails
if (!check(checkArgs, checkOpts)) if (!check(checkArgs, checkOpts))
{ {
printBuildInfo(false); foamVersion::printBuildInfo(false);
FatalError.write(Info, false); FatalError.write(Info, false);
Pstream::exit(1); // works for serial and parallel Pstream::exit(1); // works for serial and parallel
@ -918,12 +900,12 @@ void Foam::argList::parse
if (Pstream::master() && bannerEnabled()) if (Pstream::master() && bannerEnabled())
{ {
IOobject::writeBanner(Info, true) IOobject::writeBanner(Info, true)
<< "Build : " << Foam::FOAMbuild << "Build : " << foamVersion::build
#if OPENFOAM #if OPENFOAM
<< " (OPENFOAM=" << OPENFOAM << ')' << " (OPENFOAM=" << OPENFOAM << ')'
#endif #endif
<< nl << nl
<< "Arch : " << Foam::FOAMbuildArch << 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
<< "Time : " << timeString.c_str() << nl << "Time : " << timeString.c_str() << nl
@ -934,7 +916,7 @@ void Foam::argList::parse
jobInfo.add("startDate", dateString); jobInfo.add("startDate", dateString);
jobInfo.add("startTime", timeString); jobInfo.add("startTime", timeString);
jobInfo.add("userName", userName()); jobInfo.add("userName", userName());
jobInfo.add("foamVersion", word(Foam::FOAMversion)); jobInfo.add("foamVersion", word(foamVersion::version));
jobInfo.add("code", executable_); jobInfo.add("code", executable_);
jobInfo.add("argList", commandLine_); jobInfo.add("argList", commandLine_);
jobInfo.add("currentDir", cwd()); jobInfo.add("currentDir", cwd());
@ -943,8 +925,8 @@ void Foam::argList::parse
// Add build information - only use the first word // Add build information - only use the first word
{ {
std::string build(Foam::FOAMbuild); std::string build(foamVersion::build);
std::string::size_type space = build.find(' '); const auto space = build.find(' ');
if (space != std::string::npos) if (space != std::string::npos)
{ {
build.resize(space); build.resize(space);
@ -1004,10 +986,10 @@ void Foam::argList::parse
proci++; proci++;
// Verify that all processors are running the same build // Verify that all processors are running the same build
if (slaveBuild != Foam::FOAMbuild) if (slaveBuild != foamVersion::build)
{ {
FatalErrorIn(executable()) FatalErrorIn(executable())
<< "Master is running version " << Foam::FOAMbuild << "Master is running version " << foamVersion::build
<< "; slave " << proci << " is running version " << "; slave " << proci << " is running version "
<< slaveBuild << slaveBuild
<< exit(FatalError); << exit(FatalError);
@ -1021,7 +1003,7 @@ void Foam::argList::parse
Pstream::commsTypes::scheduled, Pstream::commsTypes::scheduled,
Pstream::masterNo() Pstream::masterNo()
); );
toMaster << string(Foam::FOAMbuild) << hostName() << pid(); toMaster << string(foamVersion::build) << hostName() << pid();
} }
} }
@ -1623,7 +1605,7 @@ void Foam::argList::printUsage(bool full) const
printNotes(); printNotes();
Info<< nl; Info<< nl;
printBuildInfo(); foamVersion::printBuildInfo(true);
Info<< endl; Info<< endl;
} }
@ -1771,7 +1753,12 @@ void Foam::argList::displayDoc(bool source) const
CStringList command(stringOps::splitSpace(docBrowser)); CStringList command(stringOps::splitSpace(docBrowser));
Info<<"OpenFOAM-" << Foam::FOAMversion << " documentation:" << nl Info
<< "OpenFOAM"
#if OPENFOAM
<< ' ' << OPENFOAM
#endif
<< " documentation:" << nl
<< " " << command << nl << endl; << " " << command << nl << endl;
Foam::system(command, true); Foam::system(command, true);

View File

@ -102,7 +102,7 @@ Foam::fileNameList searchEtc
// User resource directories // User resource directories
if (userResourceDir(dir)) if (userResourceDir(dir))
{ {
candidate = dir/Foam::FOAMversion/name; candidate = dir/foamVersion::version/name;
if (accept(candidate)) if (accept(candidate))
{ {
list.append(std::move(candidate)); list.append(std::move(candidate));
@ -126,7 +126,7 @@ Foam::fileNameList searchEtc
// Group resource directories // Group resource directories
if (groupResourceDir(dir)) if (groupResourceDir(dir))
{ {
candidate = dir/Foam::FOAMversion/name; candidate = dir/foamVersion::version/name;
if (accept(candidate)) if (accept(candidate))
{ {
list.append(std::move(candidate)); list.append(std::move(candidate));

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 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011 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.
@ -31,7 +31,6 @@ Description
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "foamVersion.H" #include "foamVersion.H"
#include "endian.H" #include "endian.H"
#include "label.H" #include "label.H"
@ -39,11 +38,11 @@ Description
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
const char* const Foam::FOAMversion = "VERSION_STRING"; const char* const Foam::foamVersion::version = "VERSION_STRING";
const char* const Foam::FOAMbuild = "BUILD_STRING"; const char* const Foam::foamVersion::build = "BUILD_STRING";
// Information about machine endian, label and scalar sizes // Information about machine endian, label and scalar sizes
const std::string Foam::FOAMbuildArch = const std::string Foam::foamVersion::buildArch
( (
#ifdef WM_LITTLE_ENDIAN #ifdef WM_LITTLE_ENDIAN
"LSB" "LSB"

View File

@ -29,7 +29,6 @@ License
#include "Ostream.H" #include "Ostream.H"
#include "OSspecific.H" #include "OSspecific.H"
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
// file-scope function // file-scope function
@ -59,8 +58,8 @@ Foam::Ostream& Foam::profilingSysInfo::write
os.writeEntry("date", Foam::clock::dateTime()); os.writeEntry("date", Foam::clock::dateTime());
// compile-time information // compile-time information
os.writeEntry("version", std::string(FOAMversion)); os.writeEntry("version", std::string(foamVersion::version));
os.writeEntry("build", std::string(FOAMbuild)); os.writeEntry("build", std::string(foamVersion::build));
printEnv(os, "arch", "WM_ARCH"); printEnv(os, "arch", "WM_ARCH");
printEnv(os, "compilerType", "WM_COMPILER_TYPE"); printEnv(os, "compilerType", "WM_COMPILER_TYPE");

View File

@ -1,8 +1,8 @@
/*---------------------------------------------------------------------------*\ /*-------------------------------*- C++ -*-----------------------------------*\
========= | ========= |
\\ / 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 OpenFOAM Foundation \\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -21,27 +21,30 @@ License
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Application
foamVersionString.C
Description
Print the OpenFOAM version strings.
Simultaneously the smallest possible program to use a minimal bit of
the OpenFOAM library
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include <iostream>
#include "foamVersion.H" #include "foamVersion.H"
#include "messageStream.H"
int main() // Static data members are constructed in global.Cver
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
void Foam::foamVersion::printBuildInfo(const bool full)
{ {
std::cout Info<<"Using: OpenFOAM-" << foamVersion::version
<< "version " << Foam::FOAMversion << "\n" << " (see www.OpenFOAM.com)" << nl
<< "build " << Foam::FOAMbuild << "\n"; << "Build: " << foamVersion::build
#if OPENFOAM
<< " (OPENFOAM=" << OPENFOAM << ')'
#endif
<< nl;
return 0; if (full)
{
Info<< "Arch: " << foamVersion::buildArch.c_str() << nl;
}
} }
// ************************************************************************* // // ************************************************************************* //

View File

@ -21,24 +21,11 @@ License
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Global Namespace
Foam::FOAMversion Foam::foamVersion
Description Description
OpenFOAM version number as a static string. Namespace for OpenFOAM version information
Global
Foam::FOAMbuild
Description
OpenFOAM build information as a static string
Global
Foam::FOAMbuildArch
Description
OpenFOAM build architecture information (endian, label/scalar sizes)
as a static string
Note Note
Compile-time version information is conveyed by the \b OPENFOAM define Compile-time version information is conveyed by the \b OPENFOAM define
@ -48,6 +35,7 @@ Note
The OPENFOAM_PLUS define was last used for 1712. The OPENFOAM_PLUS define was last used for 1712.
SourceFiles SourceFiles
foamVersion.C
global.Cver global.Cver
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
@ -65,13 +53,41 @@ SourceFiles
namespace Foam namespace Foam
{ {
extern const char* const FOAMversion; //- Version information
extern const char* const FOAMbuild; namespace foamVersion
extern const std::string FOAMbuildArch; {
//- OpenFOAM version (number or name) as a static c-string.
extern const char* const version;
//- OpenFOAM build information as a static c-string
extern const char* const build;
//- OpenFOAM build architecture information
//- (machine endian, label/scalar sizes) as a static std::string
extern const std::string buildArch;
//- Print information about version, build, arch to Info
//
// \verbatim
// Using: OpenFOAM-<VERSION> (see www.OpenFOAM.com)
// Build: <BUILD> (OPENFOAM=<API_LEVEL>)
// Arch: "<ARCH_INFO>"
// \endverbatim
//
// \param full includes Arch information
void printBuildInfo(const bool full=true);
}
} }
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Compatibility names (1806 and earlier)
#define FOAMversion foamVersion::version
#define FOAMbuild foamVersion::build
#define FOAMbuildArch foamVersion::buildArch
#endif #endif
// ************************************************************************* // // ************************************************************************* //

View File

@ -41,7 +41,7 @@ void Foam::ensightGeoFile::initialize()
#if OPENFOAM #if OPENFOAM
write("Written by OpenFOAM-" STRING_QUOTE(OPENFOAM)); write("Written by OpenFOAM-" STRING_QUOTE(OPENFOAM));
#else #else
write(string("Written by OpenFOAM-" + string(Foam::FOAMversion))); write(string("Written by OpenFOAM-" + string(foamVersion::version)));
#endif #endif
newline(); newline();

View File

@ -106,12 +106,12 @@ void Foam::ensightSetWriter<Type>::write
// Write .mesh file // Write .mesh file
{ {
string desc = string("written by OpenFOAM-") + Foam::FOAMversion; string desc("Written by OpenFOAM-" + string(foamVersion::version));
OFstream os(meshFile); OFstream os(meshFile);
os.setf(ios_base::scientific, ios_base::floatfield); os.setf(ios_base::scientific, ios_base::floatfield);
os.precision(5); os.precision(5);
os << "EnSight Geometry File" << nl os << "Ensight Geometry File" << nl
<< desc.c_str() << nl << desc.c_str() << nl
<< "node id assign" << nl << "node id assign" << nl
<< "element id assign" << nl << "element id assign" << nl
@ -223,11 +223,11 @@ void Foam::ensightSetWriter<Type>::write
// Write .mesh file // Write .mesh file
{ {
string desc = string("written by OpenFOAM-") + Foam::FOAMversion; string desc("Written by OpenFOAM-" + string(foamVersion::version));
OFstream os(meshFile); OFstream os(meshFile);
os.setf(ios_base::scientific, ios_base::floatfield); os.setf(ios_base::scientific, ios_base::floatfield);
os.precision(5); os.precision(5);
os << "EnSight Geometry File" << nl os << "Ensight Geometry File" << nl
<< desc.c_str() << nl << desc.c_str() << nl
<< "node id assign" << nl << "node id assign" << nl
<< "element id assign" << nl; << "element id assign" << nl;