From 2b4849a2fae0a38ee646eda53511de38604bb9c8 Mon Sep 17 00:00:00 2001 From: Dominik Schmidt Date: Tue, 26 Aug 2014 18:07:42 +0200 Subject: [PATCH] Add crash reporter using libcrashreporter-qt --- .gitmodules | 3 + CMakeLists.txt | 6 ++ config.h.in | 1 + src/3rdparty/libcrashreporter-qt | 1 + src/CMakeLists.txt | 5 ++ src/crashreporter/CMakeLists.txt | 45 ++++++++++++ src/crashreporter/CrashReporterConfig.h.in | 12 ++++ src/crashreporter/main.cpp | 84 ++++++++++++++++++++++ src/crashreporter/resources.qrc | 5 ++ src/gui/CMakeLists.txt | 9 +++ src/gui/main.cpp | 10 +++ 11 files changed, 181 insertions(+) create mode 160000 src/3rdparty/libcrashreporter-qt create mode 100644 src/crashreporter/CMakeLists.txt create mode 100644 src/crashreporter/CrashReporterConfig.h.in create mode 100644 src/crashreporter/main.cpp create mode 100644 src/crashreporter/resources.qrc diff --git a/.gitmodules b/.gitmodules index ffec18175..ba3b7388b 100644 --- a/.gitmodules +++ b/.gitmodules @@ -7,3 +7,6 @@ [submodule "binary"] path = binary url = git://github.com/owncloud/owncloud-client-binary.git +[submodule "src/3rdparty/libcrashreporter-qt"] + path = src/3rdparty/libcrashreporter-qt + url = git://github.com/dschmidt/libcrashreporter-qt.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 00a5afce3..56c749a7e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -94,6 +94,12 @@ if(OWNCLOUD_5XX_NO_BLACKLIST) add_definitions(-DOWNCLOUD_5XX_NO_BLACKLIST=1) endif() +option(WITH_CRASHREPORTER "Build the crash reporter" ON) +IF( CMAKE_SYSTEM_PROCESSOR MATCHES "arm" OR NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/3rdparty/libcrashreporter-qt/CMakeLists.txt") + message(STATUS "Build of crashreporter disabled.") + SET(WITH_CRASHREPORTER OFF) +ENDIF() + #### find libs #find_package(Qt4 4.7.0 COMPONENTS QtCore QtGui QtXml QtNetwork QtTest QtWebkit REQUIRED ) #if( UNIX AND NOT APPLE ) # Fdo notifications diff --git a/config.h.in b/config.h.in index d739a212a..56c776800 100644 --- a/config.h.in +++ b/config.h.in @@ -3,6 +3,7 @@ #cmakedefine USE_INOTIFY 1 #cmakedefine WITH_QTKEYCHAIN 1 +#cmakedefine WITH_CRASHREPORTER #cmakedefine GIT_SHA1 "@GIT_SHA1@" #cmakedefine APPLICATION_DOMAIN @APPLICATION_DOMAIN@ diff --git a/src/3rdparty/libcrashreporter-qt b/src/3rdparty/libcrashreporter-qt new file mode 160000 index 000000000..9bac9c15b --- /dev/null +++ b/src/3rdparty/libcrashreporter-qt @@ -0,0 +1 @@ +Subproject commit 9bac9c15b474ab03d0ba80d89ff126ce20a9dff8 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 094d08372..ff039b1a7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -7,6 +7,11 @@ add_subdirectory(libsync) if (NOT BUILD_LIBRARIES_ONLY) add_subdirectory(gui) add_subdirectory(cmd) + + if (WITH_CRASHREPORTER) + add_subdirectory(3rdparty/libcrashreporter-qt) + add_subdirectory(crashreporter) + endif() endif(NOT BUILD_LIBRARIES_ONLY) find_program(KRAZY2_EXECUTABLE krazy2) diff --git a/src/crashreporter/CMakeLists.txt b/src/crashreporter/CMakeLists.txt new file mode 100644 index 000000000..c96fcb507 --- /dev/null +++ b/src/crashreporter/CMakeLists.txt @@ -0,0 +1,45 @@ +PROJECT( CrashReporter ) +cmake_policy(SET CMP0017 NEW) + +list(APPEND crashreporter_SOURCES main.cpp) +list(APPEND crashreporter_RC resources.qrc) + +qt_wrap_ui( crashreporter_UI_HEADERS ${crashreporter_UI} ) +qt_add_resources( crashreporter_RC_RCC ${crashreporter_RC} ) + + +# TODO: differentiate release channel +# if(BUILD_RELEASE) +# set(CRASHREPORTER_RELEASE_CHANNEL "release") +# else() + set(CRASHREPORTER_RELEASE_CHANNEL "nightly") +# endif() + +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/CrashReporterConfig.h.in + ${CMAKE_CURRENT_BINARY_DIR}/CrashReporterConfig.h) + + +include_directories(${CMAKE_CURRENT_BINARY_DIR}) +# ../../libtomahawk +# ../../thirdparty/libcrashreporter-qt/src +#) + +add_executable( owncloud_crash_reporter WIN32 + ${crashreporter_SOURCES} + ${crashreporter_HEADERS_MOC} + ${crashreporter_UI_HEADERS} + ${crashreporter_RC_RCC} +) + + +target_link_libraries(owncloud_crash_reporter + crashreporter-gui + ${QT_LIBRARIES} +) + +#TODO: don't use automoc :-( +set_target_properties(owncloud_crash_reporter PROPERTIES AUTOMOC ON) +set_target_properties(owncloud_crash_reporter PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${BIN_OUTPUT_DIRECTORY} ) +install(TARGETS owncloud_crash_reporter RUNTIME DESTINATION ${LIBEXEC_INSTALL_DIR}) + +qt5_use_modules(owncloud_crash_reporter Widgets Network) diff --git a/src/crashreporter/CrashReporterConfig.h.in b/src/crashreporter/CrashReporterConfig.h.in new file mode 100644 index 000000000..a20095172 --- /dev/null +++ b/src/crashreporter/CrashReporterConfig.h.in @@ -0,0 +1,12 @@ +#ifndef CRASHREPORTERCONFIG_H +#define CRASHREPORTERCONFIG_H + +#define CRASHREPORTER_BUILD_ID "@CMAKE_DATESTAMP_YEAR@@CMAKE_DATESTAMP_MONTH@@CMAKE_DATESTAMP_DAY@000000" + +#define CRASHREPORTER_RELEASE_CHANNEL "@CRASHREPORTER_RELEASE_CHANNEL@" + +#define CRASHREPORTER_PRODUCT_NAME "ownCloud Client" + +#define CRASHREPORTER_VERSION_STRING "@MIRALL_VERSION_STRING@" + +#endif // CRASHREPORTERCONFIG_H diff --git a/src/crashreporter/main.cpp b/src/crashreporter/main.cpp new file mode 100644 index 000000000..84a4cde3e --- /dev/null +++ b/src/crashreporter/main.cpp @@ -0,0 +1,84 @@ +/* + * Copyright (C) by Dominik Schmidt + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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. + */ + +#include "../3rdparty/libcrashreporter-qt/src/libcrashreporter-gui/CrashReporter.h" + +#include "CrashReporterConfig.h" + +#include +#include + +int main( int argc, char* argv[] ) +{ + QApplication app( argc, argv ); + + if ( app.arguments().size() != 2 ) + { + qDebug() << "You need to pass the .dmp file path as only argument"; + return 1; + } + + // TODO: install socorro .... + CrashReporter reporter( QUrl( "http://crash-reports.tomahawk-player.org/submit" ), app.arguments() ); + + reporter.setLogo(QPixmap(":/owncloud-icon.png")); + reporter.setWindowTitle(CRASHREPORTER_PRODUCT_NAME); + reporter.setText("

Sorry! " CRASHREPORTER_PRODUCT_NAME " crashed. Please tell us about it! " CRASHREPORTER_PRODUCT_NAME " has created an error report for you that can help improve the stability in the future. You can now send this report directly to the " CRASHREPORTER_PRODUCT_NAME " developers.

"); + + reporter.setReportData( "BuildID", CRASHREPORTER_BUILD_ID ); + reporter.setReportData( "ProductName", CRASHREPORTER_PRODUCT_NAME ); + reporter.setReportData( "Version", CRASHREPORTER_VERSION_STRING ); + reporter.setReportData( "ReleaseChannel", CRASHREPORTER_RELEASE_CHANNEL); + + //reporter.setReportData( "timestamp", QByteArray::number( QDateTime::currentDateTime().toTime_t() ) ); + + + // add parameters + + // << Pair("InstallTime", "1357622062") + // << Pair("Theme", "classic/1.0") + // << Pair("Version", "30") + // << Pair("id", "{ec8030f7-c20a-464f-9b0e-13a3a9e97384}") + // << Pair("Vendor", "Mozilla") + // << Pair("EMCheckCompatibility", "true") + // << Pair("Throttleable", "0") + // << Pair("URL", "http://code.google.com/p/crashme/") + // << Pair("version", "20.0a1") + // << Pair("CrashTime", "1357770042") + // << Pair("submitted_timestamp", "2013-01-09T22:21:18.646733+00:00") + // << Pair("buildid", "20130107030932") + // << Pair("timestamp", "1357770078.646789") + // << Pair("Notes", "OpenGL: NVIDIA Corporation -- GeForce 8600M GT/PCIe/SSE2 -- 3.3.0 NVIDIA 313.09 -- texture_from_pixmap\r\n") + // << Pair("StartupTime", "1357769913") + // << Pair("FramePoisonSize", "4096") + // << Pair("FramePoisonBase", "7ffffffff0dea000") + // << Pair("Add-ons", "%7B972ce4c6-7e08-4474-a285-3208198ce6fd%7D:20.0a1,crashme%40ted.mielczarek.org:0.4") + // << Pair("SecondsSinceLastCrash", "1831736") + // << Pair("ProductName", "WaterWolf") + // << Pair("legacy_processing", "0") + // << Pair("ProductID", "{ec8030f7-c20a-464f-9b0e-13a3a9e97384}") + + ; + + // TODO: + // send log +// QFile logFile( INSERT_FILE_PATH_HERE ); +// logFile.open( QFile::ReadOnly ); +// reporter.setReportData( "upload_file_miralllog", qCompress( logFile.readAll() ), "application/x-gzip", QFileInfo( INSERT_FILE_PATH_HERE ).fileName().toUtf8()); +// logFile.close(); + + reporter.show(); + + return app.exec(); +} diff --git a/src/crashreporter/resources.qrc b/src/crashreporter/resources.qrc new file mode 100644 index 000000000..830281e77 --- /dev/null +++ b/src/crashreporter/resources.qrc @@ -0,0 +1,5 @@ + + + ../../theme/colored/owncloud-icon-128.png + + diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index 08022a073..9923af809 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -227,6 +227,15 @@ target_link_libraries( ${APPLICATION_EXECUTABLE} ${synclib_NAME} ) target_link_libraries( ${APPLICATION_EXECUTABLE} updater ) target_link_libraries( ${APPLICATION_EXECUTABLE} ${OS_SPECIFIC_LINK_LIBRARIES} ) +if(WITH_CRASHREPORTER) + target_link_libraries( ${APPLICATION_EXECUTABLE} crashreporter-handler) + + if(UNIX AND NOT MAC) + find_package(Threads REQUIRED) + target_link_libraries( ${APPLICATION_EXECUTABLE} ${CMAKE_THREAD_LIBS_INIT}) + endif() +endif() + install(TARGETS ${APPLICATION_EXECUTABLE} RUNTIME DESTINATION bin LIBRARY DESTINATION lib diff --git a/src/gui/main.cpp b/src/gui/main.cpp index 8b7921859..1df5f2a37 100644 --- a/src/gui/main.cpp +++ b/src/gui/main.cpp @@ -28,6 +28,10 @@ #include "updater/updater.h" +#ifdef WITH_CRASHREPORTER + #include "../3rdparty/libcrashreporter-qt/src/libcrashreporter-handler/Handler.h" +#endif + #include #include @@ -51,6 +55,12 @@ int main(int argc, char **argv) Mac::CocoaInitializer cocoaInit; // RIIA #endif Mirall::Application app(argc, argv); + + +#ifdef WITH_CRASHREPORTER + new CrashReporter::Handler( QDir::tempPath(), true, "owncloud_crash_reporter" ); +#endif + #ifndef Q_OS_WIN signal(SIGPIPE, SIG_IGN); #endif