From 91900a7942c4fc0b911b817cf39587f94a68888b Mon Sep 17 00:00:00 2001 From: Romain LE JEUNE Date: Mon, 13 Feb 2023 20:31:32 +0100 Subject: [PATCH] feat(GODT-2357): Hide DSN_SENTRY and use single setting point for DSN_SENTRY. --- BUILDS.md | 2 +- Makefile | 10 ++++++---- internal/frontend/.gitignore | 2 +- .../bridge-gui/{Version.h.in => BuildConfig.h.in} | 1 + .../frontend/bridge-gui/bridge-gui/CMakeLists.txt | 12 ++---------- .../frontend/bridge-gui/bridge-gui/QMLBackend.cpp | 2 +- internal/frontend/bridge-gui/bridge-gui/QMLBackend.h | 2 +- .../frontend/bridge-gui/bridge-gui/SentryUtils.cpp | 2 +- internal/frontend/bridge-gui/bridge-gui/build.ps1 | 5 +++++ internal/frontend/bridge-gui/bridge-gui/build.sh | 4 ++++ internal/frontend/bridge-gui/bridge-gui/main.cpp | 5 ++--- 11 files changed, 25 insertions(+), 22 deletions(-) rename internal/frontend/bridge-gui/bridge-gui/{Version.h.in => BuildConfig.h.in} (95%) diff --git a/BUILDS.md b/BUILDS.md index 8c07ed6a..8f43485c 100644 --- a/BUILDS.md +++ b/BUILDS.md @@ -11,7 +11,7 @@ * libglvnd and libsecret development files (linux) To enable the sending of crash reports using Sentry please set the -`main.DSNSentry` value with the client key of your sentry project before build. +`DSN_SENTRY` environment variable with the client key of your sentry project before build. Otherwise, the sending of crash reports will be disabled. ## Build diff --git a/Makefile b/Makefile index 63402462..54f9281e 100644 --- a/Makefile +++ b/Makefile @@ -30,9 +30,10 @@ BUILD_FLAGS_GUI:=-tags='${BUILD_TAGS} build_qt' GO_LDFLAGS:=$(addprefix -X github.com/ProtonMail/proton-bridge/v3/internal/constants., Version=${APP_VERSION} Revision=${REVISION} BuildTime=${BUILD_TIME}) GO_LDFLAGS+=-X "github.com/ProtonMail/proton-bridge/v3/internal/constants.FullAppName=${APP_FULL_NAME}" -ifneq "${BUILD_LDFLAGS}" "" - GO_LDFLAGS+=${BUILD_LDFLAGS} +ifneq "${DSN_SENTRY}" "" + GO_LDFLAGS+=-X github.com/ProtonMail/proton-bridge/v3/internal/constants.DSNSentry=${DSN_SENTRY} endif + GO_LDFLAGS_LAUNCHER:=${GO_LDFLAGS} ifeq "${TARGET_OS}" "windows" #GO_LDFLAGS+=-H=windowsgui # Disabled so we can inspect trace logs from the bridge for debugging. @@ -154,7 +155,8 @@ ${EXE_TARGET}: check-build-essentials ${EXE_NAME} BRIDGE_VENDOR="${APP_VENDOR}" \ BRIDGE_APP_VERSION=${APP_VERSION} \ BRIDGE_REVISION=${REVISION} \ - BRIDGE_BUILD_TIME=${BUILD_TIME} \ + BRIDGE_DSN_SENTRY=${DSN_SENTRY} \ + BRIDGE_BUILD_TIME=${BUILD_TIME} \ BRIDGE_GUI_BUILD_CONFIG=Release \ BRIDGE_INSTALL_PATH=${ROOT_DIR}/${DEPLOY_DIR}/${GOOS} \ ./build.sh install @@ -340,7 +342,7 @@ clean-vendor: clean-gui: cd internal/frontend/bridge-gui/ && \ - rm -f Version.h && \ + rm -f BuildConfig.h && \ rm -rf cmake-build-*/ clean-vcpkg: diff --git a/internal/frontend/.gitignore b/internal/frontend/.gitignore index 976250b8..f20600dd 100644 --- a/internal/frontend/.gitignore +++ b/internal/frontend/.gitignore @@ -10,5 +10,5 @@ rcc_cgo_*.go *.qmlc # Generated file -bridge-gui/bridge-gui/Version.h +bridge-gui/bridge-gui/BuildConfig.h bridge-gui/bridge-gui/Resources.rc diff --git a/internal/frontend/bridge-gui/bridge-gui/Version.h.in b/internal/frontend/bridge-gui/bridge-gui/BuildConfig.h.in similarity index 95% rename from internal/frontend/bridge-gui/bridge-gui/Version.h.in rename to internal/frontend/bridge-gui/bridge-gui/BuildConfig.h.in index a9081306..afcc58a5 100644 --- a/internal/frontend/bridge-gui/bridge-gui/Version.h.in +++ b/internal/frontend/bridge-gui/bridge-gui/BuildConfig.h.in @@ -24,5 +24,6 @@ #define PROJECT_VER "@BRIDGE_APP_VERSION@" #define PROJECT_REVISION "@BRIDGE_REVISION@" #define PROJECT_BUILD_TIME "@BRIDGE_BUILD_TIME@" +#define PROJECT_DSN_SENTRY "@BRIDGE_DSN_SENTRY@" #endif // BRIDGE_GUI_VERSION_H diff --git a/internal/frontend/bridge-gui/bridge-gui/CMakeLists.txt b/internal/frontend/bridge-gui/bridge-gui/CMakeLists.txt index e64ff118..cf40a5e8 100644 --- a/internal/frontend/bridge-gui/bridge-gui/CMakeLists.txt +++ b/internal/frontend/bridge-gui/bridge-gui/CMakeLists.txt @@ -85,20 +85,12 @@ message(STATUS "Using Qt ${Qt6_VERSION}") #***************************************************************************************************************************************************** find_package(sentry CONFIG REQUIRED) -set(DSN_SENTRY "https://ea31dfe8574849108fb8ba044fec3620@api.protonmail.ch/core/v4/reports/sentry/7") -set(SENTRY_CONFIG_GENERATED_FILE_DIR ${CMAKE_CURRENT_BINARY_DIR}/sentry-generated) -set(SENTRY_CONFIG_FILE ${SENTRY_CONFIG_GENERATED_FILE_DIR}/project_sentry_config.h) -file(GENERATE OUTPUT ${SENTRY_CONFIG_FILE} CONTENT - "// AUTO GENERATED FILE, DO NOT MODIFY\n#pragma once\nconst char* SentryDNS=\"${DSN_SENTRY}\";\nconst char* SentryProductID=\"bridge-mail@${BRIDGE_APP_VERSION}\";\n" -) - - #***************************************************************************************************************************************************** # Source files and output #***************************************************************************************************************************************************** -configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Version.h.in ${CMAKE_CURRENT_SOURCE_DIR}/Version.h) +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/BuildConfig.h.in ${CMAKE_CURRENT_SOURCE_DIR}/BuildConfig.h) if (NOT TARGET bridgepp) add_subdirectory(../bridgepp bridgepp) @@ -122,7 +114,7 @@ add_executable(bridge-gui EventStreamWorker.cpp EventStreamWorker.h main.cpp Pch.h - Version.h + BuildConfig.h QMLBackend.cpp QMLBackend.h UserList.cpp UserList.h SentryUtils.cpp SentryUtils.h diff --git a/internal/frontend/bridge-gui/bridge-gui/QMLBackend.cpp b/internal/frontend/bridge-gui/bridge-gui/QMLBackend.cpp index 37a7e6c3..01a881c9 100644 --- a/internal/frontend/bridge-gui/bridge-gui/QMLBackend.cpp +++ b/internal/frontend/bridge-gui/bridge-gui/QMLBackend.cpp @@ -18,7 +18,7 @@ #include "QMLBackend.h" #include "EventStreamWorker.h" -#include "Version.h" +#include "BuildConfig.h" #include #include #include diff --git a/internal/frontend/bridge-gui/bridge-gui/QMLBackend.h b/internal/frontend/bridge-gui/bridge-gui/QMLBackend.h index 19b221a2..e9b42c1d 100644 --- a/internal/frontend/bridge-gui/bridge-gui/QMLBackend.h +++ b/internal/frontend/bridge-gui/bridge-gui/QMLBackend.h @@ -21,7 +21,7 @@ #include "MacOS/DockIcon.h" -#include "Version.h" +#include "BuildConfig.h" #include "UserList.h" #include #include diff --git a/internal/frontend/bridge-gui/bridge-gui/SentryUtils.cpp b/internal/frontend/bridge-gui/bridge-gui/SentryUtils.cpp index 6dafef9f..e2470412 100644 --- a/internal/frontend/bridge-gui/bridge-gui/SentryUtils.cpp +++ b/internal/frontend/bridge-gui/bridge-gui/SentryUtils.cpp @@ -16,7 +16,7 @@ // along with Proton Mail Bridge. If not, see . #include "SentryUtils.h" -#include "Version.h" +#include "BuildConfig.h" #include #include diff --git a/internal/frontend/bridge-gui/bridge-gui/build.ps1 b/internal/frontend/bridge-gui/bridge-gui/build.ps1 index 20bd2f49..b11821c3 100644 --- a/internal/frontend/bridge-gui/bridge-gui/build.ps1 +++ b/internal/frontend/bridge-gui/bridge-gui/build.ps1 @@ -76,6 +76,9 @@ function check_exit() { Write-host "Running build for version $bridgeVersion - $buildConfig in $buildDir" $REVISION_HASH = git rev-parse --short=10 HEAD +$bridgeDsnSentry = ($env:BRIDGE_DSN_SENTRY) +$bridgeBuidTime = ($env:BRIDGE_BUILD_TIME) + git submodule update --init --recursive $vcpkgRoot . $vcpkgBootstrap -disableMetrics . $vcpkgExe install sentry-native:x64-windows grpc:x64-windows --clean-after-build @@ -85,6 +88,8 @@ git submodule update --init --recursive $vcpkgRoot -DBRIDGE_VENDOR="$bridgeVendor" ` -DBRIDGE_REVISION=$REVISION_HASH ` -DBRIDGE_APP_VERSION="$bridgeVersion" ` + -DBRIDGE_BUILD_TIME="$bridgeBuidTime" ` + -DBRIDGE_DSN_SENTRY="$bridgeDsnSentry" ` -S . -B $buildDir check_exit "CMake failed" diff --git a/internal/frontend/bridge-gui/bridge-gui/build.sh b/internal/frontend/bridge-gui/bridge-gui/build.sh index c47663d5..832749e2 100755 --- a/internal/frontend/bridge-gui/bridge-gui/build.sh +++ b/internal/frontend/bridge-gui/bridge-gui/build.sh @@ -56,6 +56,8 @@ BUILD_CONFIG=${BRIDGE_GUI_BUILD_CONFIG:-Debug} BUILD_DIR=$(echo "./cmake-build-${BUILD_CONFIG}" | tr '[:upper:]' '[:lower:]') VCPKG_ROOT="${BRIDGE_REPO_ROOT}/extern/vcpkg" BRIDGE_REVISION=$(git rev-parse --short=10 HEAD) +BRIDGE_DSN_SENTRY=${BRIDGE_DSN_SENTRY} +BRIDGE_BUILD_TIME=${BRIDGE_BUILD_TIME} git submodule update --init --recursive ${VCPKG_ROOT} check_exit "Failed to initialize vcpkg as a submodule." @@ -94,6 +96,8 @@ cmake \ -DBRIDGE_APP_FULL_NAME="${BRIDGE_APP_FULL_NAME}" \ -DBRIDGE_VENDOR="${BRIDGE_VENDOR}" \ -DBRIDGE_REVISION="${BRIDGE_REVISION}" \ + -DBRIDGE_DSN_SENTRY="${BRIDGE_DSN_SENTRY}" \ + -DBRIDGE_BRIDGE_TIME="${BRIDGE_BRIDGE_TIME}" \ -DBRIDGE_APP_VERSION="${BRIDGE_APP_VERSION}" "${BRIDGE_CMAKE_MACOS_OPTS}" \ -G Ninja \ -S . \ diff --git a/internal/frontend/bridge-gui/bridge-gui/main.cpp b/internal/frontend/bridge-gui/bridge-gui/main.cpp index 56db1ea1..513d91b6 100644 --- a/internal/frontend/bridge-gui/bridge-gui/main.cpp +++ b/internal/frontend/bridge-gui/bridge-gui/main.cpp @@ -21,7 +21,7 @@ #include "CommandLine.h" #include "QMLBackend.h" #include "SentryUtils.h" -#include "Version.h" +#include "BuildConfig.h" #include #include #include @@ -29,7 +29,6 @@ #include #include #include -#include #ifdef Q_OS_MACOS @@ -293,7 +292,7 @@ void closeBridgeApp() { int main(int argc, char *argv[]) { // Init sentry. sentry_options_t *sentryOptions = sentry_options_new(); - sentry_options_set_dsn(sentryOptions, SentryDNS); + sentry_options_set_dsn(sentryOptions, PROJECT_DSN_SENTRY); { const QString sentryCachePath = sentryCacheDir(); sentry_options_set_database_path(sentryOptions, sentryCachePath.toStdString().c_str());