diff options
| author | Nils Maier <maierman@web.de> | 2014-05-29 23:51:48 +0200 |
|---|---|---|
| committer | Nils Maier <maierman@web.de> | 2014-06-10 11:28:34 +0200 |
| commit | 2b02fac2d5f677dc6d099f550fd94fe8dac18bb2 (patch) | |
| tree | 5fc136be71f945d3ee2943a1aa2f28bf0bdaaae1 /src/FeatureConfig.cc | |
| parent | 570bc24fb98d72d1bce9261fdc29139224ec86ec (diff) | |
Improve compiler/platform/libs information in logs
Add and use usedCompilerAndPlatform(). This adds compiler information to
INFO logs and the --version output, and may be helpful when trying to
diagnose/reproduce user-reported problems.
Also make INFO logs include usedLibs() output.
Closes #235
Diffstat (limited to 'src/FeatureConfig.cc')
| -rw-r--r-- | src/FeatureConfig.cc | 142 |
1 files changed, 137 insertions, 5 deletions
diff --git a/src/FeatureConfig.cc b/src/FeatureConfig.cc index 74dafd2b..ff0b6b0d 100644 --- a/src/FeatureConfig.cc +++ b/src/FeatureConfig.cc @@ -34,6 +34,9 @@ /* copyright --> */ #include "FeatureConfig.h" +#include <sstream> +#include <cstring> + #ifdef HAVE_ZLIB # include <zlib.h> #endif // HAVE_ZLIB @@ -61,6 +64,9 @@ #ifdef HAVE_LIBCARES # include <ares.h> #endif // HAVE_LIBCARES +#ifdef HAVE_SYS_UTSNAME_H +# include <sys/utsname.h> +#endif // HAVE_SYS_UTSNAME_H #include "util.h" @@ -112,7 +118,7 @@ const char* strSupportedFeature(int feature) #ifdef ENABLE_BITTORRENT return "BitTorrent"; #else // !ENABLE_BITTORRENT - return 0; + return nullptr; #endif // !ENABLE_BITTORRENT break; @@ -128,7 +134,7 @@ const char* strSupportedFeature(int feature) #ifdef HAVE_ZLIB return "GZip"; #else // !HAVE_ZLIB - return 0; + return nullptr; #endif // !HAVE_ZLIB break; @@ -136,7 +142,7 @@ const char* strSupportedFeature(int feature) #ifdef ENABLE_SSL return "HTTPS"; #else // !ENABLE_SSL - return 0; + return nullptr; #endif // !ENABLE_SSL break; @@ -148,7 +154,7 @@ const char* strSupportedFeature(int feature) #ifdef ENABLE_METALINK return "Metalink"; #else // !ENABLE_METALINK - return 0; + return nullptr; #endif // !ENABLE_METALINK break; @@ -156,7 +162,7 @@ const char* strSupportedFeature(int feature) #ifdef ENABLE_XML_RPC return "XML-RPC"; #else // !ENABLE_XML_RPC - return 0; + return nullptr; #endif // !ENABLE_XML_RPC break; @@ -221,4 +227,130 @@ std::string usedLibs() return res; } +std::string usedCompilerAndPlatform() +{ + std::stringstream rv; +#if defined(__clang_version__) + +#ifdef __apple_build_version__ + rv << "Apple LLVM "; +#else // !__apple_build_version__ + rv << "clang "; +#endif // !__apple_build_version__ + rv << __clang_version__; + +#elif defined(__INTEL_COMPILER) + + rv << "Intel ICC " << __VERSION__; + +#elif defined( __MINGW64_VERSION_STR) + + rv << "mingw-w64 " << __MINGW64_VERSION_STR; +#ifdef __MINGW64_VERSION_STATE + rv << " (" << __MINGW64_VERSION_STATE << ")"; +#endif // __MINGW64_VERSION_STATE + rv << " / gcc " << __VERSION__; + +#elif defined(__GNUG__) + +#ifdef __MINGW32__ + rv << "mingw "; +#ifdef __MINGW32_MAJOR_VERSION + rv << (int)__MINGW32_MAJOR_VERSION; +#endif // __MINGW32_MAJOR_VERSION +#ifdef __MINGW32_MINOR_VERSION + rv << "." << (int)__MINGW32_MINOR_VERSION; +#endif // __MINGW32_MINOR_VERSION + rv << " / "; +#endif // __MINGW32__ + rv << "gcc " << __VERSION__; + +#else // !defined(__GNUG__) + + rv << "Unknown compiler/platform"; + +#endif // !defined(__GNUG__) + + rv << "\n built by " << BUILD; + if(strcmp(BUILD, TARGET)) { + rv << "\n targetting " << TARGET; + } + rv << "\n on " << __DATE__ << " " << __TIME__; + + return rv.str(); +} + +std::string getOperatingSystemInfo() +{ +#ifdef _WIN32 + std::stringstream rv; + rv << "Windows "; + OSVERSIONINFOEX ovi = { + sizeof(OSVERSIONINFOEX) + }; + if(!GetVersionEx((LPOSVERSIONINFO)&ovi)) { + rv << "Unknown"; + return rv.str(); + } + if(ovi.dwMajorVersion < 6) { + rv << "Legcacy, probably XP"; + return rv.str(); + } + switch(ovi.dwMinorVersion) { + case 0: + if(ovi.wProductType == VER_NT_WORKSTATION) { + rv << "Vista"; + } + else { + rv << "Server 2008"; + } + break; + + case 1: + if(ovi.wProductType == VER_NT_WORKSTATION) { + rv << "7"; + } + else { + rv << "Server 2008 R2"; + } + break; + + default: + // Windows above 6.2 does not actually say so. :p + + rv << ovi.dwMajorVersion; + if(ovi.dwMinorVersion) { + rv << "." << ovi.dwMinorVersion; + } + if(ovi.wProductType != VER_NT_WORKSTATION) { + rv << " Server"; + } + break; + } + if(ovi.szCSDVersion[0]) { + rv << " (" << ovi.szCSDVersion << ")"; + } +#ifdef _WIN64 + rv << " (x86_64)"; +#endif // _WIN64 + return rv.str(); +#else //! _WIN32 +#ifdef HAVE_SYS_UTSNAME_H + struct utsname name; + if(!uname(&name)) { + if(!strstr(name.version, name.sysname) || + !strstr(name.version, name.release) || + !strstr(name.version, name.machine)) { + std::stringstream ss; + ss << name.sysname << " " << name.release << " " << name.version << + " " << name.machine; + return ss.str(); + } + return name.version; + } +#endif // HAVE_SYS_UTSNAME_H + return "Unknown system"; +#endif // !_WIN32 +} + } // namespace aria2 |
