Commit 5eebe505 authored by Mark Olesen's avatar Mark Olesen
Browse files

ENH: reduce dependencies for foamVersion.H

- have printBuildInfo output to std::ostream
- removed extraneous include "stdFoam.H"

ENH: revert to pre-processor defines for hard-coded paths (#1712)

- redundant information, but more robust at run-time without relying
  on initialization order
parent bee23c79
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2018-2019 OpenCFD Ltd. Copyright (C) 2018-2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
...@@ -51,9 +51,8 @@ void testExtraction(const std::string& str) ...@@ -51,9 +51,8 @@ void testExtraction(const std::string& str)
int main() int main()
{ {
Info Info<< "\nVersion information (function)" << nl;
<< "\nVersion information (function)" << nl; foamVersion::printBuildInfo(Info().stdStream());
foamVersion::printBuildInfo();
Info Info
<< "\nVersion information (macros)" << nl << "\nVersion information (macros)" << nl
......
...@@ -8,6 +8,6 @@ namespace Foam ...@@ -8,6 +8,6 @@ namespace Foam
void printTest() void printTest()
{ {
Info<< nl; Info<< nl;
foamVersion::printBuildInfo(); foamVersion::printBuildInfo(Info().stdStream());
} }
} }
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2015-2019 OpenCFD Ltd. Copyright (C) 2015-2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
...@@ -828,9 +828,9 @@ Foam::argList::argList ...@@ -828,9 +828,9 @@ Foam::argList::argList
++argi; ++argi;
if (argi >= args_.size()) if (argi >= args_.size())
{ {
foamVersion::printBuildInfo(false); foamVersion::printBuildInfo(Info().stdStream(), false);
Info<<nl Info<< nl
<<"Error: option '-" << optName <<"Error: option '-" << optName
<< "' requires an argument" << nl << nl << "' requires an argument" << nl << nl
<< "See '" << executable_ << " -help' for usage" << "See '" << executable_ << " -help' for usage"
...@@ -997,7 +997,7 @@ void Foam::argList::parse ...@@ -997,7 +997,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))
{ {
foamVersion::printBuildInfo(false); foamVersion::printBuildInfo(Info().stdStream(), 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
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2018 OpenCFD Ltd. Copyright (C) 2018-2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
...@@ -41,7 +41,7 @@ static inline int apiYear() ...@@ -41,7 +41,7 @@ static inline int apiYear()
return 2000 + (foamVersion::api / 100); return 2000 + (foamVersion::api / 100);
} }
// manpage Footer // Footer for manpage
static inline void printManFooter() static inline void printManFooter()
{ {
Info<< ".SH \"SEE ALSO\"" << nl Info<< ".SH \"SEE ALSO\"" << nl
...@@ -428,7 +428,7 @@ void Foam::argList::printUsage(bool full) const ...@@ -428,7 +428,7 @@ void Foam::argList::printUsage(bool full) const
printNotes(); printNotes();
Info<< nl; Info<< nl;
foamVersion::printBuildInfo(true); foamVersion::printBuildInfo(Info().stdStream(), true);
Info<< endl; Info<< endl;
} }
......
...@@ -30,6 +30,24 @@ License ...@@ -30,6 +30,24 @@ License
#include "foamVersion.H" #include "foamVersion.H"
#include "OSspecific.H" #include "OSspecific.H"
#ifdef FULLDEBUG
#ifndef FOAM_RESOURCE_USER_CONFIG_DIRNAME
# warning FOAM_RESOURCE_USER_CONFIG_DIRNAME undefined (was this intentional?)
#endif
#ifndef FOAM_RESOURCE_SITE_ENVNAME
# warning FOAM_RESOURCE_SITE_ENVNAME undefined (was this intentional?)
#endif
#ifndef FOAM_RESOURCE_SITE_FALLBACK_ENVNAME
# warning FOAM_RESOURCE_SITE_FALLBACK_ENVNAME undefined (was this intentional?)
#endif
#endif
// Always use these names
#undef FOAM_PROJECT_ENVNAME
#define FOAM_PROJECT_ENVNAME "WM_PROJECT_DIR"
// * * * * * * * * * * * * * * Static Functions * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Functions * * * * * * * * * * * * * * //
// //
...@@ -70,8 +88,8 @@ static inline void errorMandatoryNotFound ...@@ -70,8 +88,8 @@ static inline void errorMandatoryNotFound
// setup at all. // setup at all.
std::cerr std::cerr
<< "--> FOAM FATAL ERROR :\n " << "--> FOAM FATAL ERROR :\n"
"Could not find mandatory etc entry (mode=" " Could not find mandatory etc entry (mode="
<< locationToString(location) << ")\n '" << locationToString(location) << ")\n '"
<< name << "'\n" << name << "'\n"
<< std::endl; << std::endl;
...@@ -96,9 +114,6 @@ static inline bool userResourceDir(Foam::fileName& queried) ...@@ -96,9 +114,6 @@ static inline bool userResourceDir(Foam::fileName& queried)
// But we would have worse problems elsewhere if that were the case. // But we would have worse problems elsewhere if that were the case.
return true; return true;
} }
#elif defined FULLDEBUG
#warning FOAM_RESOURCE_USER_CONFIG_DIRNAME \
is undefined (was this intentional?)
#endif #endif
return false; return false;
...@@ -120,38 +135,30 @@ static inline bool groupResourceDir(Foam::fileName& queried) ...@@ -120,38 +135,30 @@ static inline bool groupResourceDir(Foam::fileName& queried)
{ {
#ifdef FOAM_RESOURCE_SITE_ENVNAME #ifdef FOAM_RESOURCE_SITE_ENVNAME
queried = Foam::getEnv(FOAM_RESOURCE_SITE_ENVNAME)/"etc"; queried = Foam::getEnv(FOAM_RESOURCE_SITE_ENVNAME)/"etc";
if (queried.size() > 3) if (queried.size() > 4)
{ {
return Foam::isDir(queried); return Foam::isDir(queried);
} }
#elif defined FULLDEBUG
#warning FOAM_RESOURCE_SITE_ENVNAME \
is undefined (was this intentional?)
#endif #endif
// Fallback when WM_PROJECT_SITE is unset // Fallback when WM_PROJECT_SITE is unset
#ifdef FOAM_RESOURCE_SITE_FALLBACK_ENVNAME #ifdef FOAM_RESOURCE_SITE_FALLBACK_ENVNAME
queried = Foam::getEnv(FOAM_RESOURCE_SITE_FALLBACK_ENVNAME)/"site/etc"; queried = Foam::getEnv(FOAM_RESOURCE_SITE_FALLBACK_ENVNAME)/"site/etc";
if (queried.size() > 8 && Foam::isDir(queried)) if (queried.size() > 9 && Foam::isDir(queried))
{ {
return true; return true;
} }
#elif defined FULLDEBUG
#warning FOAM_RESOURCE_SITE_FALLBACK_ENVNAME \
is undefined (was this intentional?)
#endif #endif
// Compile-time paths // Compile-time paths
queried = Foam::foamVersion::configuredProjectDir(); #ifdef FOAM_CONFIGURED_PROJECT_DIR
if (queried.size()) queried = FOAM_CONFIGURED_PROJECT_DIR "/site/etc";
if (queried.size() > 9 && Foam::isDir(queried))
{ {
queried /= "site/etc"; return true;
if (Foam::isDir(queried))
{
return true;
}
} }
#endif
queried.clear(); queried.clear();
return false; return false;
...@@ -171,32 +178,29 @@ static inline bool groupResourceDir(Foam::fileName& queried) ...@@ -171,32 +178,29 @@ static inline bool groupResourceDir(Foam::fileName& queried)
// - FOAM_CONFIGURED_PROJECT_DIR/"etc" // - FOAM_CONFIGURED_PROJECT_DIR/"etc"
static inline bool projectResourceDir(Foam::fileName& queried) static inline bool projectResourceDir(Foam::fileName& queried)
{ {
queried = Foam::getEnv("WM_PROJECT_DIR")/"etc"; queried = Foam::getEnv(FOAM_PROJECT_ENVNAME)/"etc";
if (queried.size() > 3 && Foam::isDir(queried)) if (queried.size() > 4 && Foam::isDir(queried))
{ {
return true; return true;
} }
// Compile-time paths // Compile-time paths
queried = Foam::foamVersion::configuredEtcDir(); #ifdef FOAM_CONFIGURED_PROJECT_ETC
if (queried.size()) queried = FOAM_CONFIGURED_PROJECT_ETC;
if (Foam::isDir(queried))
{ {
if (Foam::isDir(queried)) return true;
{
return true;
}
} }
#endif
queried = Foam::foamVersion::configuredProjectDir(); #ifdef FOAM_CONFIGURED_PROJECT_DIR
if (queried.size()) queried = FOAM_CONFIGURED_PROJECT_DIR "/etc";
if (queried.size() > 4 && Foam::isDir(queried))
{ {
queried /= "etc"; return true;
if (Foam::isDir(queried))
{
return true;
}
} }
#endif
queried.clear(); queried.clear();
return false; return false;
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2018-2019 OpenCFD Ltd. Copyright (C) 2018-2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
...@@ -37,28 +37,28 @@ bool Foam::foamVersion::patched() ...@@ -37,28 +37,28 @@ bool Foam::foamVersion::patched()
// Patch-level, when defined (non-zero) and not some @TOKEN@ rubbish // Patch-level, when defined (non-zero) and not some @TOKEN@ rubbish
return return
( (
foamVersion::patch.size() && foamVersion::patch[0] != '@' (foamVersion::patch.size() && foamVersion::patch[0] != '@')
&& (foamVersion::patch.size() > 1 || foamVersion::patch[0] != '0') && (foamVersion::patch.size() > 1 || foamVersion::patch[0] != '0')
); );
} }
void Foam::foamVersion::printBuildInfo(const bool full) void Foam::foamVersion::printBuildInfo(std::ostream& os, const bool full)
{ {
Info<< "Using: OpenFOAM-" << foamVersion::version.c_str() os << "Using: OpenFOAM-" << foamVersion::version
<< " (" << foamVersion::api << ") - visit www.openfoam.com\n" << " (" << foamVersion::api << ") - visit www.openfoam.com\n"
<< "Build: " << foamVersion::build.c_str(); << "Build: " << foamVersion::build;
if (foamVersion::patched()) if (foamVersion::patched())
{ {
// Patch-level, when defined // Patch-level, when defined
Info<< " (patch=" << foamVersion::patch.c_str() << ')'; os << " (patch=" << foamVersion::patch << ')';
} }
Info<< nl; os << '\n';
if (full) if (full)
{ {
Info<< "Arch: " << foamVersion::buildArch.c_str() << nl; os << "Arch: " << foamVersion::buildArch << '\n';
} }
} }
......
...@@ -54,7 +54,7 @@ SourceFiles ...@@ -54,7 +54,7 @@ SourceFiles
#ifndef foamVersion_H #ifndef foamVersion_H
#define foamVersion_H #define foamVersion_H
#include "stdFoam.H" #include <iostream>
#include <string> #include <string>
//- The directory name for user-resources within the HOME directory //- The directory name for user-resources within the HOME directory
...@@ -113,7 +113,7 @@ namespace Foam ...@@ -113,7 +113,7 @@ namespace Foam
//- Extract scalar size (in bytes) from "scalar=" tag in string //- Extract scalar size (in bytes) from "scalar=" tag in string
unsigned scalarByteSize(const std::string& str); unsigned scalarByteSize(const std::string& str);
//- Print information about version, build, arch to Info //- Print information about version, build, arch to output stream
// //
// Eg, // Eg,
// \code // \code
...@@ -122,8 +122,9 @@ namespace Foam ...@@ -122,8 +122,9 @@ namespace Foam
// Arch: <ARCH_INFO> // Arch: <ARCH_INFO>
// \endcode // \endcode
// //
// \param os the output stream
// \param full includes Arch information // \param full includes Arch information
void printBuildInfo(const bool full=true); void printBuildInfo(std::ostream& os, const bool full=true);
//- Compile-time definition of the OpenFOAM project directory //- Compile-time definition of the OpenFOAM project directory
//- or empty if not defined. //- or empty if not defined.
......
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