From 897ec89f1b9fdd0cc7d81633e34a7df7c3b2ee75 Mon Sep 17 00:00:00 2001 From: espkk Date: Sun, 7 Nov 2021 19:01:18 +0300 Subject: [PATCH] [meta,diagnostics,engine] Add basic watermarking --- CMakeLists.txt | 3 ++ conanfile.py | 42 ++++++++++++++----- src/CMakeLists.txt | 4 ++ src/apps/ENGINE/src/Main.cpp | 4 +- src/libs/diagnostics/include/watermark.hpp | 9 ++++ .../src/LifecycleDiagnosticsService.cpp | 2 + 6 files changed, 52 insertions(+), 12 deletions(-) create mode 100644 src/libs/diagnostics/include/watermark.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index b7c99f0d6..4a32fa666 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,6 +13,8 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Release) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Debug) +set(STORM_WATERMARK_FILE ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/watermark.hpp CACHE FILEPATH "Include file containing build revision, etc." FORCE) + ### Set up third-party dependencies set(ENV{CONAN_REVISIONS_ENABLED} 1) conan_add_remote(NAME bincrafters @@ -29,6 +31,7 @@ conan_cmake_run(CONANFILE conanfile.py BUILD missing OPTIONS output_directory=${CMAKE_RUNTIME_OUTPUT_DIRECTORY} + watermark_file=${STORM_WATERMARK_FILE} crash_reports=${STORM_ENABLE_CRASH_REPORTS} steam=${STORM_ENABLE_STEAM} ) diff --git a/conanfile.py b/conanfile.py index 76bca10f6..291dfbae8 100644 --- a/conanfile.py +++ b/conanfile.py @@ -1,5 +1,6 @@ -from conans import ConanFile +from conans import ConanFile, tools from os import getenv +from random import getrandbits from distutils.dir_util import copy_tree class StormEngine(ConanFile): @@ -8,6 +9,7 @@ class StormEngine(ConanFile): # build options provided by CMakeLists.txt that are used in conanfile.py options = { "output_directory": "ANY", + "watermark_file": "ANY", "crash_reports": [True, False], "steam": [True, False] } @@ -35,18 +37,8 @@ def requirements(self): "sentry-native:transport": "winhttp" } - def __install_bin(self, name): - self.copy(name, dst=self.__dest, src="bin") - - def __intall_lib(self, name): - self.copy(name, dst=self.__dest, src="lib") - - def __install_folder(self, src, dst): - copy_tree(self.recipe_folder + src, self.__dest + dst) - def imports(self): self.__dest = str(self.options.output_directory) + "/" + getenv("CONAN_IMPORT_PATH", "bin") - self.__install_folder("/src/techniques", "/resource/techniques") self.__install_folder("/src/libs/shared_headers/include/shared", "/resource/shared") @@ -61,3 +53,31 @@ def imports(self): if self.options.steam: self.__intall_lib("steam_api64.dll") + + self.__write_watermark(); + + + def __write_watermark(self): + with open(str(self.options.watermark_file), 'w') as f: + f.write("#pragma once\n#define STORM_BUILD_WATERMARK ") + f.write(self.__generate_watermark()) + f.write("\n") + + def __generate_watermark(self): + git = tools.Git() + try: + if git.is_pristine(): + return "%s(%s)" % (git.get_branch(), git.get_revision()) + else: + return "%s(%s)-DIRTY(%032x)" % (git.get_branch(), git.get_revision(), getrandbits(128)) + except: + return "Unknown" + + def __install_bin(self, name): + self.copy(name, dst=self.__dest, src="bin") + + def __intall_lib(self, name): + self.copy(name, dst=self.__dest, src="lib") + + def __install_folder(self, src, dst): + copy_tree(self.recipe_folder + src, self.__dest + dst) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4c3c623df..43953547d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -10,6 +10,10 @@ if(STORM_ENABLE_CRASH_REPORTS) add_definitions(-DSTORM_ENABLE_CRASH_REPORTS=1) endif() +if(STORM_WATERMARK_FILE) + add_definitions(-DSTORM_WATERMARK_FILE="${STORM_WATERMARK_FILE}") +endif() + if (MSVC) # Always generate PDBs add_compile_options(/Zi) diff --git a/src/apps/ENGINE/src/Main.cpp b/src/apps/ENGINE/src/Main.cpp index efa0b2c07..d2da189af 100644 --- a/src/apps/ENGINE/src/Main.cpp +++ b/src/apps/ENGINE/src/Main.cpp @@ -6,6 +6,7 @@ #include "file_service.h" #include "s_debug.h" #include "storm/fs.h" +#include "watermark.hpp" #include #include @@ -101,7 +102,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, #endif if (!lifecycleDiagnosticsGuard) { - spdlog::error("Unable to initialize lifecycle service"); + MessageBoxA(nullptr, "Unable to initialize lifecycle service!", "Warning", MB_ICONWARNING); } else { @@ -113,6 +114,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, // Init logging spdlog::set_default_logger(storm::logging::getOrCreateLogger(defaultLoggerName)); + spdlog::info("Logging system initialized. Running on {}", STORM_BUILD_WATERMARK_STRING); // Init core core.Init(); diff --git a/src/libs/diagnostics/include/watermark.hpp b/src/libs/diagnostics/include/watermark.hpp new file mode 100644 index 000000000..ac7596960 --- /dev/null +++ b/src/libs/diagnostics/include/watermark.hpp @@ -0,0 +1,9 @@ +#pragma once +#ifdef STORM_WATERMARK_FILE +#include STORM_WATERMARK_FILE +#define STORM_STRINGIFY_EXPAND_(x) #x +#define STORM_STRINGIFY_(x) STORM_STRINGIFY_EXPAND_(x) +#define STORM_BUILD_WATERMARK_STRING STORM_STRINGIFY_(STORM_BUILD_WATERMARK) +#else +#error "Watermark file is not present. Check build configuration" +#endif diff --git a/src/libs/diagnostics/src/LifecycleDiagnosticsService.cpp b/src/libs/diagnostics/src/LifecycleDiagnosticsService.cpp index 82ea53e66..0194acfb1 100644 --- a/src/libs/diagnostics/src/LifecycleDiagnosticsService.cpp +++ b/src/libs/diagnostics/src/LifecycleDiagnosticsService.cpp @@ -9,6 +9,7 @@ #include "storm/fs.h" #include "vfile_service.h" #include "spdlog_sinks/syncable_sink.hpp" +#include "watermark.hpp" #ifdef _UNICODE #include @@ -162,6 +163,7 @@ LifecycleDiagnosticsService::Guard LifecycleDiagnosticsService::initialize(const // TODO: make this crossplatform auto *options = sentry_options_new(); sentry_options_set_dsn(options, "https://1798a1bcfb654cbd8ce157b381964525@o572138.ingest.sentry.io/5721165"); + sentry_options_set_release(options, STORM_BUILD_WATERMARK_STRING); sentry_options_set_database_path(options, (fs::GetStashPath() / "sentry-db").c_str()); sentry_options_set_handler_path(options, (getExecutableDir() / "crashpad_handler.exe").c_str()); sentry_options_add_attachment(options, getLogsArchive().c_str());