Skip to content

Commit

Permalink
Set sentry environment based on version
Browse files Browse the repository at this point in the history
Contributes to CURA-11364
  • Loading branch information
jellespijker committed Nov 21, 2023
1 parent f397fb5 commit 5ef89b5
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
6 changes: 4 additions & 2 deletions conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
from conan.tools.files import copy, mkdir
from conan.tools.cmake import CMakeToolchain, CMakeDeps, CMake, cmake_layout
from conan.tools.build import check_min_cppstd
from conan.tools.scm import Version
from conan.tools.scm import Version, Git


required_conan_version = ">=1.58.0 <2.0.0"

Expand Down Expand Up @@ -42,7 +43,8 @@ class CuraEngineConan(ConanFile):

def set_version(self):
if not self.version:
self.version = "5.7.0-alpha"
git = Git(self)
self.version = f"5.7.0-alpha+{git.get_commit()[:6]}"

def export_sources(self):
copy(self, "CMakeLists.txt", self.recipe_folder, self.export_sources_folder)
Expand Down
39 changes: 35 additions & 4 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@

#ifdef SENTRY_URL
#include <filesystem>
#include <semver.hpp>
#include <sentry.h>
#include <string>

#include <fmt/format.h>
#include <range/v3/algorithm/contains.hpp>
#include <range/v3/to_container.hpp>
#include <range/v3/view/take_while.hpp>

#include "utils/format/filesystem_path.h"
#endif
Expand Down Expand Up @@ -72,11 +75,39 @@ int main(int argc, char** argv)
#elif defined(__APPLE__) && defined(__MACH__)
const auto config_path = std::filesystem::path(fmt::format("{}/Library/Application Support/cura/.sentry-native", std::getenv("HOME")));
#elif defined(_WIN64)
const auto config_path = std::filesystem::path(fmt::format("{}/cura/.sentry-native", std::getenv("APPDATA")));
const auto config_path = std::filesystem::path(fmt::format("{}\\cura\\.sentry-native", std::getenv("APPDATA")));
#endif
spdlog::info("Sentry config path: {}", config_path);
sentry_options_set_database_path(options, config_path.native().c_str());
sentry_options_set_release(options, fmt::format("curaengine@{}", CURA_ENGINE_VERSION).c_str());
sentry_options_set_database_path(options, static_cast<const char*>(std::filesystem::absolute(config_path).native().c_str()));
constexpr std::string_view cura_engine_version{ CURA_ENGINE_VERSION };
const auto version = semver::from_string(
cura_engine_version
| ranges::views::take_while(
[](const auto& c)
{
return c != '+';
})
| ranges::to<std::string>);
if (ranges::contains(cura_engine_version, '+') || version.prerelease_type == semver::prerelease::alpha)
{
// Not a production build
sentry_options_set_environment(options, "development");
sentry_options_set_release(
options,
fmt::format(
"curaengine@{}.{}.{}-{}.{}",
version.major,
version.minor,
version.patch,
version.prerelease_type == semver::prerelease::alpha ? "alpha" : "beta",
version.prerelease_number)
.c_str());
}
else
{
sentry_options_set_environment(options, "production");
sentry_options_set_release(options, fmt::format("curaengine@{}", version.to_string()).c_str());
}
sentry_init(options);
}
#endif
Expand Down

0 comments on commit 5ef89b5

Please sign in to comment.