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