Skip to content
This repository has been archived by the owner on Apr 29, 2024. It is now read-only.

Commit

Permalink
Merge pull request #258 from storm-devs/feature/build-watermarking
Browse files Browse the repository at this point in the history
[meta,diagnostics,engine] Add basic watermarking
  • Loading branch information
espkk authored Nov 17, 2021
2 parents d97c499 + 897ec89 commit 13f0f97
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 12 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}
)
Expand Down
42 changes: 31 additions & 11 deletions conanfile.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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]
}
Expand Down Expand Up @@ -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")

Expand All @@ -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)
4 changes: 4 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion src/apps/ENGINE/src/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "file_service.h"
#include "s_debug.h"
#include "storm/fs.h"
#include "watermark.hpp"

#include <spdlog/sinks/basic_file_sink.h>
#include <spdlog/spdlog.h>
Expand Down Expand Up @@ -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
{
Expand All @@ -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();
Expand Down
9 changes: 9 additions & 0 deletions src/libs/diagnostics/include/watermark.hpp
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions src/libs/diagnostics/src/LifecycleDiagnosticsService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "storm/fs.h"
#include "vfile_service.h"
#include "spdlog_sinks/syncable_sink.hpp"
#include "watermark.hpp"

#ifdef _UNICODE
#include <tchar.h>
Expand Down Expand Up @@ -162,6 +163,7 @@ LifecycleDiagnosticsService::Guard LifecycleDiagnosticsService::initialize(const
// TODO: make this crossplatform
auto *options = sentry_options_new();
sentry_options_set_dsn(options, "https://[email protected]/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());
Expand Down

0 comments on commit 13f0f97

Please sign in to comment.