From 083e9e966520c614d6a7c5c43cc1b96e3a562416 Mon Sep 17 00:00:00 2001 From: Mark Olesen <Mark.Olesen@esi-group.com> Date: Thu, 22 Nov 2018 11:50:24 +0100 Subject: [PATCH] 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() --- applications/test/foamVersion/Make/files | 4 +- applications/test/foamVersion/Make/options | 4 +- .../test/foamVersion/Test-foamVersion.C | 62 +++++++++++++++++++ .../USERD_get_reader_release.H | 2 +- src/OpenFOAM/Make/files | 1 + .../db/IOobject/IOobjectWriteHeader.C | 4 +- .../decomposedBlockData/decomposedBlockData.C | 2 +- src/OpenFOAM/global/argList/argList.C | 47 +++++--------- src/OpenFOAM/global/etcFiles/etcFiles.C | 4 +- src/OpenFOAM/global/global.Cver | 9 ++- .../global/profiling/profilingSysInfo.C | 5 +- .../OpenFOAM/global/version/foamVersion.C | 39 ++++++------ .../global/{ => version}/foamVersion.H | 54 ++++++++++------ src/fileFormats/ensight/file/ensightGeoFile.C | 2 +- .../ensight/ensightSetWriter.C | 8 +-- 15 files changed, 157 insertions(+), 90 deletions(-) create mode 100644 applications/test/foamVersion/Test-foamVersion.C rename applications/test/foamVersion/Test-foamVersionString.C => src/OpenFOAM/global/version/foamVersion.C (62%) rename src/OpenFOAM/global/{ => version}/foamVersion.H (64%) diff --git a/applications/test/foamVersion/Make/files b/applications/test/foamVersion/Make/files index 52262afb8e8..82922e0ca88 100644 --- a/applications/test/foamVersion/Make/files +++ b/applications/test/foamVersion/Make/files @@ -1,3 +1,3 @@ -Test-foamVersionString.C +Test-foamVersion.C -EXE = $(FOAM_USER_APPBIN)/Test-foamVersionString +EXE = $(FOAM_USER_APPBIN)/Test-foamVersion diff --git a/applications/test/foamVersion/Make/options b/applications/test/foamVersion/Make/options index 6a9e9810b3d..18e6fe47afa 100644 --- a/applications/test/foamVersion/Make/options +++ b/applications/test/foamVersion/Make/options @@ -1,2 +1,2 @@ -/* EXE_INC = -I$(LIB_SRC)/cfdTools/include */ -/* EXE_LIBS = -lfiniteVolume */ +/* EXE_INC = */ +/* EXE_LIBS = */ diff --git a/applications/test/foamVersion/Test-foamVersion.C b/applications/test/foamVersion/Test-foamVersion.C new file mode 100644 index 00000000000..8f3e4128fdf --- /dev/null +++ b/applications/test/foamVersion/Test-foamVersion.C @@ -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; +} + +// ************************************************************************* // diff --git a/applications/utilities/postProcessing/graphics/ensightFoamReader/USERD_get_reader_release.H b/applications/utilities/postProcessing/graphics/ensightFoamReader/USERD_get_reader_release.H index 5ebd4425cb7..0cccce10a37 100644 --- a/applications/utilities/postProcessing/graphics/ensightFoamReader/USERD_get_reader_release.H +++ b/applications/utilities/postProcessing/graphics/ensightFoamReader/USERD_get_reader_release.H @@ -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; diff --git a/src/OpenFOAM/Make/files b/src/OpenFOAM/Make/files index a9466aa28d9..84ece4c4b6c 100644 --- a/src/OpenFOAM/Make/files +++ b/src/OpenFOAM/Make/files @@ -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 diff --git a/src/OpenFOAM/db/IOobject/IOobjectWriteHeader.C b/src/OpenFOAM/db/IOobject/IOobjectWriteHeader.C index 441f0b893d0..c970a49e374 100644 --- a/src/OpenFOAM/db/IOobject/IOobjectWriteHeader.C +++ b/src/OpenFOAM/db/IOobject/IOobjectWriteHeader.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()) diff --git a/src/OpenFOAM/db/IOobjects/decomposedBlockData/decomposedBlockData.C b/src/OpenFOAM/db/IOobjects/decomposedBlockData/decomposedBlockData.C index cca72be73ff..92c2c0dd48c 100644 --- a/src/OpenFOAM/db/IOobjects/decomposedBlockData/decomposedBlockData.C +++ b/src/OpenFOAM/db/IOobjects/decomposedBlockData/decomposedBlockData.C @@ -211,7 +211,7 @@ void Foam::decomposedBlockData::writeHeader /* if (os.format() == IOstream::BINARY) { - os << " arch " << Foam::FOAMbuildArch << ";\n"; + os << " arch " << foamVersion::buildArch << ";\n"; } */ diff --git a/src/OpenFOAM/global/argList/argList.C b/src/OpenFOAM/global/argList/argList.C index 245f5d67e5a..6168c68a972 100644 --- a/src/OpenFOAM/global/argList/argList.C +++ b/src/OpenFOAM/global/argList/argList.C @@ -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); diff --git a/src/OpenFOAM/global/etcFiles/etcFiles.C b/src/OpenFOAM/global/etcFiles/etcFiles.C index 448bf64f27b..e174f36f5d8 100644 --- a/src/OpenFOAM/global/etcFiles/etcFiles.C +++ b/src/OpenFOAM/global/etcFiles/etcFiles.C @@ -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)); diff --git a/src/OpenFOAM/global/global.Cver b/src/OpenFOAM/global/global.Cver index 552dc011cca..177f809c552 100644 --- a/src/OpenFOAM/global/global.Cver +++ b/src/OpenFOAM/global/global.Cver @@ -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" diff --git a/src/OpenFOAM/global/profiling/profilingSysInfo.C b/src/OpenFOAM/global/profiling/profilingSysInfo.C index 166f23e813a..125abecc50e 100644 --- a/src/OpenFOAM/global/profiling/profilingSysInfo.C +++ b/src/OpenFOAM/global/profiling/profilingSysInfo.C @@ -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"); diff --git a/applications/test/foamVersion/Test-foamVersionString.C b/src/OpenFOAM/global/version/foamVersion.C similarity index 62% rename from applications/test/foamVersion/Test-foamVersionString.C rename to src/OpenFOAM/global/version/foamVersion.C index d9050004c6d..6356eb357b3 100644 --- a/applications/test/foamVersion/Test-foamVersionString.C +++ b/src/OpenFOAM/global/version/foamVersion.C @@ -1,8 +1,8 @@ -/*---------------------------------------------------------------------------*\ +/*-------------------------------*- 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; + } } + // ************************************************************************* // diff --git a/src/OpenFOAM/global/foamVersion.H b/src/OpenFOAM/global/version/foamVersion.H similarity index 64% rename from src/OpenFOAM/global/foamVersion.H rename to src/OpenFOAM/global/version/foamVersion.H index e85cc06bfa7..099e045ffce 100644 --- a/src/OpenFOAM/global/foamVersion.H +++ b/src/OpenFOAM/global/version/foamVersion.H @@ -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 // ************************************************************************* // diff --git a/src/fileFormats/ensight/file/ensightGeoFile.C b/src/fileFormats/ensight/file/ensightGeoFile.C index c84e91dc1ca..473585b5dbd 100644 --- a/src/fileFormats/ensight/file/ensightGeoFile.C +++ b/src/fileFormats/ensight/file/ensightGeoFile.C @@ -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(); diff --git a/src/fileFormats/sampledSetWriters/ensight/ensightSetWriter.C b/src/fileFormats/sampledSetWriters/ensight/ensightSetWriter.C index 7152b21dbdd..1d88d286dce 100644 --- a/src/fileFormats/sampledSetWriters/ensight/ensightSetWriter.C +++ b/src/fileFormats/sampledSetWriters/ensight/ensightSetWriter.C @@ -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; -- GitLab