From 2b02fac2d5f677dc6d099f550fd94fe8dac18bb2 Mon Sep 17 00:00:00 2001 From: Nils Maier Date: Thu, 29 May 2014 23:51:48 +0200 Subject: [PATCH] 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 --- configure.ac | 3 + src/Context.cc | 5 +- src/FeatureConfig.cc | 142 +++++++++++++++++++++++++++++++++++++++++-- src/FeatureConfig.h | 6 ++ src/version_usage.cc | 4 ++ 5 files changed, 154 insertions(+), 6 deletions(-) diff --git a/configure.ac b/configure.ac index 5b394d460..ab3d2888f 100644 --- a/configure.ac +++ b/configure.ac @@ -35,6 +35,8 @@ case "$host" in ;; esac +AC_DEFINE_UNQUOTED([BUILD], ["$build"], [Define build-type]) +AC_DEFINE_UNQUOTED([HOST], ["$host"], [Define build-type]) AC_DEFINE_UNQUOTED([TARGET], ["$target"], [Define target-type]) # Checks for arguments. @@ -654,6 +656,7 @@ AC_CHECK_HEADERS([argz.h \ sys/time.h \ sys/types.h \ sys/uio.h \ + sys/utsname.h \ termios.h \ unistd.h \ utime.h \ diff --git a/src/Context.cc b/src/Context.cc index 25182c471..8de8b577c 100644 --- a/src/Context.cc +++ b/src/Context.cc @@ -174,7 +174,10 @@ Context::Context(bool standalone, A2_LOG_INFO("<<--- --- --- ---"); A2_LOG_INFO(" --- --- --- ---"); A2_LOG_INFO(" --- --- --- --->>"); - A2_LOG_INFO(fmt("%s %s %s", PACKAGE, PACKAGE_VERSION, TARGET)); + A2_LOG_INFO(fmt("%s %s", PACKAGE, PACKAGE_VERSION)); + A2_LOG_INFO(usedCompilerAndPlatform()); + A2_LOG_INFO(getOperatingSystemInfo()); + A2_LOG_INFO(usedLibs()); A2_LOG_INFO(MSG_LOGGING_STARTED); if(op->getAsBool(PREF_DISABLE_IPV6)) { diff --git a/src/FeatureConfig.cc b/src/FeatureConfig.cc index 74dafd2ba..ff0b6b0d7 100644 --- a/src/FeatureConfig.cc +++ b/src/FeatureConfig.cc @@ -34,6 +34,9 @@ /* copyright --> */ #include "FeatureConfig.h" +#include +#include + #ifdef HAVE_ZLIB # include #endif // HAVE_ZLIB @@ -61,6 +64,9 @@ #ifdef HAVE_LIBCARES # include #endif // HAVE_LIBCARES +#ifdef HAVE_SYS_UTSNAME_H +# include +#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 diff --git a/src/FeatureConfig.h b/src/FeatureConfig.h index 6f33871ab..9c0a27989 100644 --- a/src/FeatureConfig.h +++ b/src/FeatureConfig.h @@ -67,6 +67,12 @@ const char* strSupportedFeature(int feature); // aria2. std::string usedLibs(); +// Returns a summary string of the used compiler/platform. +std::string usedCompilerAndPlatform(); + +// Returns the system information about the OS this binary is running on. +std::string getOperatingSystemInfo(); + } // namespace aria2 #endif // D_FEATURE_CONFIG_H diff --git a/src/version_usage.cc b/src/version_usage.cc index 6d9fc3f73..e713f41f9 100644 --- a/src/version_usage.cc +++ b/src/version_usage.cc @@ -72,6 +72,10 @@ void showVersion() { << MessageDigest::getSupportedHashTypeString() << "\n" << _("Libraries") << ": " << usedLibs() << "\n" + << _("Compiler") << ": " + << usedCompilerAndPlatform() << "\n" + << _("System") << ": " + << getOperatingSystemInfo() << "\n" << "\n" << fmt(_("Report bugs to %s"), PACKAGE_BUGREPORT) << "\n" << _("Visit") << " " << PACKAGE_URL << std::endl;