Commit 083e9e96 authored by Mark Olesen's avatar Mark Olesen
Browse files

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()
parent 0cae54b3
Test-foamVersionString.C
Test-foamVersion.C
EXE = $(FOAM_USER_APPBIN)/Test-foamVersionString
EXE = $(FOAM_USER_APPBIN)/Test-foamVersion
/* EXE_INC = -I$(LIB_SRC)/cfdTools/include */
/* EXE_LIBS = -lfiniteVolume */
/* EXE_INC = */
/* EXE_LIBS = */
/*---------------------------------------------------------------------------*\
========= |
\\ / 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;
}
// ************************************************************************* //
......@@ -8,7 +8,7 @@ int USERD_get_reader_release
Info<< "Entering: USERD_get_reader_release" << endl;
#endif
strncpy(release_number, Foam::FOAMbuild, Z_MAX_USERD_NAME);
strncpy(release_number, foamVersion::build, Z_MAX_USERD_NAME);
#ifdef ENSIGHTDEBUG
Info<< "Leaving: USERD_get_reader_release" << endl;
......
......@@ -9,6 +9,7 @@ global/profiling/profilingInformation.C
global/profiling/profilingSysInfo.C
global/profiling/profilingTrigger.C
global/etcFiles/etcFiles.C
global/version/foamVersion.C
fileOps = global/fileOperations
$(fileOps)/fileOperation/fileOperation.C
......
......@@ -48,7 +48,7 @@ Foam::Ostream& Foam::IOobject::writeBanner(Ostream& os, bool noHint)
if (!*paddedVersion)
{
// Populate: like strncpy but without trailing '\0'
const char *p = Foam::FOAMversion;
const char *p = foamVersion::version;
memset(paddedVersion, ' ', 38);
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)
{
os << " arch " << Foam::FOAMbuildArch << ";\n";
os << " arch " << foamVersion::buildArch << ";\n";
}
if (!note().empty())
......
......@@ -211,7 +211,7 @@ void Foam::decomposedBlockData::writeHeader
/*
if (os.format() == IOstream::BINARY)
{
os << " arch " << Foam::FOAMbuildArch << ";\n";
os << " arch " << foamVersion::buildArch << ";\n";
}
*/
......
......@@ -181,24 +181,6 @@ static void printHostsSubscription(const UList<string>& slaveProcs)
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
......@@ -776,7 +758,7 @@ Foam::argList::argList
++argi;
if (argi >= args_.size())
{
printBuildInfo(false);
foamVersion::printBuildInfo(false);
Info<<nl
<<"Error: option '-" << optName
......@@ -903,7 +885,7 @@ void Foam::argList::parse
// Print the collected error messages and exit if check fails
if (!check(checkArgs, checkOpts))
{
printBuildInfo(false);
foamVersion::printBuildInfo(false);
FatalError.write(Info, false);
Pstream::exit(1); // works for serial and parallel
......@@ -918,12 +900,12 @@ void Foam::argList::parse
if (Pstream::master() && bannerEnabled())
{
IOobject::writeBanner(Info, true)
<< "Build : " << Foam::FOAMbuild
<< "Build : " << foamVersion::build
#if OPENFOAM
<< " (OPENFOAM=" << OPENFOAM << ')'
#endif
<< nl
<< "Arch : " << Foam::FOAMbuildArch << nl
<< "Arch : " << foamVersion::buildArch << nl
<< "Exec : " << commandLine_.c_str() << nl
<< "Date : " << dateString.c_str() << nl
<< "Time : " << timeString.c_str() << nl
......@@ -934,7 +916,7 @@ void Foam::argList::parse
jobInfo.add("startDate", dateString);
jobInfo.add("startTime", timeString);
jobInfo.add("userName", userName());
jobInfo.add("foamVersion", word(Foam::FOAMversion));
jobInfo.add("foamVersion", word(foamVersion::version));
jobInfo.add("code", executable_);
jobInfo.add("argList", commandLine_);
jobInfo.add("currentDir", cwd());
......@@ -943,8 +925,8 @@ void Foam::argList::parse
// Add build information - only use the first word
{
std::string build(Foam::FOAMbuild);
std::string::size_type space = build.find(' ');
std::string build(foamVersion::build);
const auto space = build.find(' ');
if (space != std::string::npos)
{
build.resize(space);
......@@ -1004,10 +986,10 @@ void Foam::argList::parse
proci++;
// Verify that all processors are running the same build
if (slaveBuild != Foam::FOAMbuild)
if (slaveBuild != foamVersion::build)
{
FatalErrorIn(executable())
<< "Master is running version " << Foam::FOAMbuild
<< "Master is running version " << foamVersion::build
<< "; slave " << proci << " is running version "
<< slaveBuild
<< exit(FatalError);
......@@ -1021,7 +1003,7 @@ void Foam::argList::parse
Pstream::commsTypes::scheduled,
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();
Info<< nl;
printBuildInfo();
foamVersion::printBuildInfo(true);
Info<< endl;
}
......@@ -1771,7 +1753,12 @@ void Foam::argList::displayDoc(bool source) const
CStringList command(stringOps::splitSpace(docBrowser));
Info<<"OpenFOAM-" << Foam::FOAMversion << " documentation:" << nl
Info
<< "OpenFOAM"
#if OPENFOAM
<< ' ' << OPENFOAM
#endif
<< " documentation:" << nl
<< " " << command << nl << endl;
Foam::system(command, true);
......
......@@ -102,7 +102,7 @@ Foam::fileNameList searchEtc
// User resource directories
if (userResourceDir(dir))
{
candidate = dir/Foam::FOAMversion/name;
candidate = dir/foamVersion::version/name;
if (accept(candidate))
{
list.append(std::move(candidate));
......@@ -126,7 +126,7 @@ Foam::fileNameList searchEtc
// Group resource directories
if (groupResourceDir(dir))
{
candidate = dir/Foam::FOAMversion/name;
candidate = dir/foamVersion::version/name;
if (accept(candidate))
{
list.append(std::move(candidate));
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -31,7 +31,6 @@ Description
\*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "foamVersion.H"
#include "endian.H"
#include "label.H"
......@@ -39,11 +38,11 @@ Description
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
const char* const Foam::FOAMversion = "VERSION_STRING";
const char* const Foam::FOAMbuild = "BUILD_STRING";
const char* const Foam::foamVersion::version = "VERSION_STRING";
const char* const Foam::foamVersion::build = "BUILD_STRING";
// Information about machine endian, label and scalar sizes
const std::string Foam::FOAMbuildArch =
const std::string Foam::foamVersion::buildArch
(
#ifdef WM_LITTLE_ENDIAN
"LSB"
......
......@@ -29,7 +29,6 @@ License
#include "Ostream.H"
#include "OSspecific.H"
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
// file-scope function
......@@ -59,8 +58,8 @@ Foam::Ostream& Foam::profilingSysInfo::write
os.writeEntry("date", Foam::clock::dateTime());
// compile-time information
os.writeEntry("version", std::string(FOAMversion));
os.writeEntry("build", std::string(FOAMbuild));
os.writeEntry("version", std::string(foamVersion::version));
os.writeEntry("build", std::string(foamVersion::build));
printEnv(os, "arch", "WM_ARCH");
printEnv(os, "compilerType", "WM_COMPILER_TYPE");
......
/*---------------------------------------------------------------------------*\
/*-------------------------------*- C++ -*-----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -21,27 +21,30 @@ License
You should have received a copy of the GNU General Public License
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 "messageStream.H"
int main()
{
std::cout
<< "version " << Foam::FOAMversion << "\n"
<< "build " << Foam::FOAMbuild << "\n";
// Static data members are constructed in global.Cver
return 0;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
void Foam::foamVersion::printBuildInfo(const bool full)
{
Info<<"Using: OpenFOAM-" << foamVersion::version
<< " (see www.OpenFOAM.com)" << nl
<< "Build: " << foamVersion::build
#if OPENFOAM
<< " (OPENFOAM=" << OPENFOAM << ')'
#endif
<< nl;
if (full)
{
Info<< "Arch: " << foamVersion::buildArch.c_str() << nl;
}
}
// ************************************************************************* //
......@@ -21,24 +21,11 @@ License
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Global
Foam::FOAMversion
Namespace
Foam::foamVersion
Description
OpenFOAM version number as a static string.
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
Namespace for OpenFOAM version information
Note
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.
SourceFiles
foamVersion.C
global.Cver
\*---------------------------------------------------------------------------*/
......@@ -65,13 +53,41 @@ SourceFiles
namespace Foam
{
extern const char* const FOAMversion;
extern const char* const FOAMbuild;
extern const std::string FOAMbuildArch;
//- Version information
namespace foamVersion
{
//- 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
// ************************************************************************* //
......@@ -41,7 +41,7 @@ void Foam::ensightGeoFile::initialize()
#if OPENFOAM
write("Written by OpenFOAM-" STRING_QUOTE(OPENFOAM));
#else
write(string("Written by OpenFOAM-" + string(Foam::FOAMversion)));
write(string("Written by OpenFOAM-" + string(foamVersion::version)));
#endif
newline();
......
......@@ -106,12 +106,12 @@ void Foam::ensightSetWriter<Type>::write
// Write .mesh file
{
string desc = string("written by OpenFOAM-") + Foam::FOAMversion;
string desc("Written by OpenFOAM-" + string(foamVersion::version));
OFstream os(meshFile);
os.setf(ios_base::scientific, ios_base::floatfield);
os.precision(5);
os << "EnSight Geometry File" << nl
os << "Ensight Geometry File" << nl
<< desc.c_str() << nl
<< "node id assign" << nl
<< "element id assign" << nl
......@@ -223,11 +223,11 @@ void Foam::ensightSetWriter<Type>::write
// Write .mesh file
{
string desc = string("written by OpenFOAM-") + Foam::FOAMversion;
string desc("Written by OpenFOAM-" + string(foamVersion::version));
OFstream os(meshFile);
os.setf(ios_base::scientific, ios_base::floatfield);
os.precision(5);
os << "EnSight Geometry File" << nl
os << "Ensight Geometry File" << nl
<< desc.c_str() << nl
<< "node id assign" << nl
<< "element id assign" << nl;
......
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