Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sentry-native: conan v2 support #15512

Merged
merged 2 commits into from
Feb 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions recipes/sentry-native/all/CMakeLists.txt

This file was deleted.

9 changes: 0 additions & 9 deletions recipes/sentry-native/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,3 @@ sources:
"0.4.13":
url: "https://github.com/getsentry/sentry-native/releases/download/0.4.13/sentry-native.zip"
sha256: "85e0e15d7fb51388d967ab09e7ee1b95f82330a469a93c65d964ea1afd5e6127"
"0.2.6":
url: "https://github.com/getsentry/sentry-native/releases/download/0.2.6/sentry-native-0.2.6.zip"
sha256: "0d93bd77f70a64f3681d4928dfca6b327374218a84d33ee31489114d8e4716c0"
patches:
"0.2.6":
- patch_file: "patches/0.2.6-0001-remove-sentry-handler-dependency.patch"
base_path: "source_subfolder"
- patch_file: "patches/0.2.6-0002-set-cmake-cxx-standard-14.patch"
base_path: "source_subfolder"
140 changes: 76 additions & 64 deletions recipes/sentry-native/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
from conans import ConanFile, CMake, tools
from conans.errors import ConanInvalidConfiguration
import functools
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.apple import is_apple_os
from conan.tools.build import check_min_cppstd
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.env import VirtualBuildEnv
from conan.tools.files import copy, get, rm, rmdir
from conan.tools.gnu import PkgConfigDeps
from conan.tools.scm import Version
import os

required_conan_version = ">=1.43.0"
required_conan_version = ">=1.55.0"


class SentryNativeConan(ConanFile):
Expand All @@ -18,6 +24,7 @@ class SentryNativeConan(ConanFile):
license = "MIT"
topics = ("breakpad", "crashpad", "error-reporting", "crash-reporting")

package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
Expand All @@ -40,26 +47,20 @@ class SentryNativeConan(ConanFile):
"performance": False,
}

generators = "cmake", "cmake_find_package", "cmake_find_package_multi", "pkg_config"

@property
def _source_subfolder(self):
return "source_subfolder"
def _min_cppstd(self):
return "14"

@property
def _minimum_compilers_version(self):
return {
"Visual Studio": "15",
"msvc": "191",
"gcc": "5",
"clang": "3.4",
"apple-clang": "5.1",
}

def export_sources(self):
self.copy("CMakeLists.txt")
for patch in self.conan_data.get("patches", {}).get(self.version, []):
self.copy(patch["patch_file"])

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC
Expand All @@ -85,89 +86,100 @@ def config_options(self):

def configure(self):
if self.options.shared:
del self.options.fPIC
self.options.rm_safe("fPIC")
if self.options.backend != "crashpad":
del self.options.with_crashpad
self.options.rm_safe("with_crashpad")
if self.options.backend != "breakpad":
del self.options.with_breakpad
self.options.rm_safe("with_breakpad")

def layout(self):
cmake_layout(self, src_folder="src")

def requirements(self):
if self.options.transport == "curl":
self.requires("libcurl/7.80.0")
self.requires("libcurl/7.87.0")
if self.options.backend == "crashpad":
if self.options.with_crashpad == "sentry":
self.requires("sentry-crashpad/{}".format(self.version))
self.requires(f"sentry-crashpad/{self.version}")
if self.options.with_crashpad == "google":
self.requires("crashpad/cci.20210507")
self.requires("crashpad/cci.20220219")
elif self.options.backend == "breakpad":
if self.options.with_breakpad == "sentry":
self.requires("sentry-breakpad/{}".format(self.version))
self.requires(f"sentry-breakpad/{self.version}")
if self.options.with_breakpad == "google":
self.requires("breakpad/cci.20210521")
if self.options.qt:
self.requires("qt/5.15.3")
self.requires("openssl/1.1.1n")
if tools.Version(self.version) < "0.4.5":
raise ConanInvalidConfiguration("Qt integration available from version 0.4.5")
if self.options.get_safe("qt"):
self.requires("qt/5.15.8")
self.requires("openssl/1.1.1t")

def validate(self):
if self.settings.compiler.cppstd:
tools.check_min_cppstd(self, 14)
if self.settings.compiler.get_safe("cppstd"):
check_min_cppstd(self, self._min_cppstd)

minimum_version = self._minimum_compilers_version.get(str(self.settings.compiler), False)
if not minimum_version:
self.output.warn("Compiler is unknown. Assuming it supports C++14.")
elif tools.Version(self.settings.compiler.version) < minimum_version:
raise ConanInvalidConfiguration("Build requires support for C++14. Minimum version for {} is {}"
.format(str(self.settings.compiler), minimum_version))
if self.options.backend == "inproc" and self.settings.os == "Windows" and tools.Version(self.version) < "0.4":
raise ConanInvalidConfiguration("The in-process backend is not supported on Windows")
if minimum_version and Version(self.settings.compiler.version) < minimum_version:
raise ConanInvalidConfiguration(
f"{self.ref} requires C++{self._min_cppstd}, which your compiler doesn't support."
)
if self.options.transport == "winhttp" and self.settings.os != "Windows":
raise ConanInvalidConfiguration("The winhttp transport is only supported on Windows")
if tools.Version(self.version) >= "0.4.7" and self.settings.compiler == "apple-clang" and tools.Version(self.settings.compiler.version) < "10.0":
if self.settings.compiler == "apple-clang" and Version(self.settings.compiler.version) < "10.0":
raise ConanInvalidConfiguration("apple-clang < 10.0 not supported")
if self.options.backend == "crashpad" and tools.Version(self.version) < "0.4.7" and self.settings.os == "Macos" and self.settings.arch == "armv8":
if self.options.backend == "crashpad" and self.settings.os == "Macos" and self.settings.arch == "armv8":
raise ConanInvalidConfiguration("This version doesn't support ARM compilation")

if self.options.performance:
if tools.Version(self.version) < "0.4.14" or tools.Version(self.version) > "0.4.15":
if Version(self.version) < "0.4.14" or Version(self.version) > "0.4.15":
raise ConanInvalidConfiguration("Performance monitoring is only valid in 0.4.14 and 0.4.15")

def _cmake_new_enough(self, required_version):
try:
import re
from io import StringIO
output = StringIO()
self.run("cmake --version", output)
m = re.search(r"cmake version (\d+\.\d+\.\d+)", output.getvalue())
return Version(m.group(1)) >= required_version
except:
return False

def build_requirements(self):
if tools.Version(self.version) >= "0.4.0" and self.settings.os == "Windows":
self.build_requires("cmake/3.22.0")
if self.settings.os == "Windows" and not self._cmake_new_enough("3.16.4"):
self.tool_requires("cmake/3.25.2")
if self.options.backend == "breakpad":
self.build_requires("pkgconf/1.7.4")
if not self.conf.get("tools.gnu:pkg_config", check_type=str):
self.tool_requires("pkgconf/1.9.3")

def source(self):
tools.get(**self.conan_data["sources"][self.version], destination=self._source_subfolder)
get(self, **self.conan_data["sources"][self.version])

def generate(self):
VirtualBuildEnv(self).generate()
tc = CMakeToolchain(self)
tc.variables["SENTRY_BACKEND"] = self.options.backend
tc.variables["SENTRY_CRASHPAD_SYSTEM"] = True
tc.variables["SENTRY_BREAKPAD_SYSTEM"] = True
tc.variables["SENTRY_ENABLE_INSTALL"] = True
tc.variables["SENTRY_TRANSPORT"] = self.options.transport
tc.variables["SENTRY_PIC"] = self.options.get_safe("fPIC", True)
tc.variables["SENTRY_INTEGRATION_QT"] = self.options.qt
tc.variables["SENTRY_PERFORMANCE_MONITORING"] = self.options.performance
tc.generate()
CMakeDeps(self).generate()
if self.options.backend == "breakpad":
PkgConfigDeps(self).generate()

@functools.lru_cache(1)
def _configure_cmake(self):
def build(self):
cmake = CMake(self)
cmake.definitions["SENTRY_BACKEND"] = self.options.backend
cmake.definitions["SENTRY_CRASHPAD_SYSTEM"] = True
cmake.definitions["SENTRY_BREAKPAD_SYSTEM"] = True
cmake.definitions["SENTRY_ENABLE_INSTALL"] = True
cmake.definitions["SENTRY_TRANSPORT"] = self.options.transport
cmake.definitions["SENTRY_PIC"] = self.options.get_safe("fPIC", True)
cmake.definitions["SENTRY_INTEGRATION_QT"] = self.options.qt
cmake.definitions["SENTRY_PERFORMANCE_MONITORING"] = self.options.performance
cmake.configure()
return cmake

def build(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)
cmake = self._configure_cmake()
cmake.build()

def package(self):
self.copy("LICENSE", dst="licenses", src=self._source_subfolder)
cmake = self._configure_cmake()
copy(self, "LICENSE", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
cmake = CMake(self)
cmake.install()
tools.rmdir(os.path.join(self.package_folder, "lib", "cmake"))
tools.remove_files_by_mask(os.path.join(self.package_folder, "bin"), "*pdb")
rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))
rm(self, "*pdb", os.path.join(self.package_folder, "bin"))

def package_info(self):
self.cpp_info.set_property("cmake_file_name", "sentry")
Expand All @@ -178,12 +190,12 @@ def package_info(self):
self.cpp_info.sharedlinkflags = ["-Wl,-E,--build-id=sha1"]
if self.settings.os in ("FreeBSD", "Linux"):
self.cpp_info.system_libs = ["pthread", "dl"]
elif is_apple_os(self):
self.cpp_info.frameworks = ["CoreGraphics", "CoreText"]
elif self.settings.os == "Android":
self.cpp_info.system_libs = ["dl", "log"]
elif self.settings.os == "Windows":
self.cpp_info.system_libs = ["shlwapi", "dbghelp"]
if tools.Version(self.version) >= "0.4.7":
self.cpp_info.system_libs.append("Version")
self.cpp_info.system_libs = ["shlwapi", "dbghelp", "version"]
if self.options.transport == "winhttp":
self.cpp_info.system_libs.append("winhttp")

Expand Down

This file was deleted.

This file was deleted.

11 changes: 4 additions & 7 deletions recipes/sentry-native/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
cmake_minimum_required(VERSION 3.1)
project(test_package CXX)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)
cmake_minimum_required(VERSION 3.8)
project(test_package LANGUAGES CXX)

find_package(sentry REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} sentry::sentry)
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 14)
target_link_libraries(${PROJECT_NAME} PRIVATE sentry::sentry)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_14)
26 changes: 13 additions & 13 deletions recipes/sentry-native/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
from conans import ConanFile, CMake, tools
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import CMake, cmake_layout
import os


class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "cmake", "cmake_find_package_multi"
generators = "CMakeToolchain", "CMakeDeps", "VirtualRunEnv"
test_type = "explicit"

def build_requirements(self):
if self.settings.os == "Macos" and self.settings.arch == "armv8":
# Workaround for CMake bug with error message:
# Attempting to use @rpath without CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG being
# set. This could be because you are using a Mac OS X version less than 10.5
# or because CMake's platform configuration is corrupt.
# FIXME: Remove once CMake on macOS/M1 CI runners is upgraded.
self.build_requires("cmake/3.22.0")
def layout(self):
cmake_layout(self)

def requirements(self):
self.requires(self.tested_reference_str)

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
self.run(bin_path, env="conanrun")
8 changes: 8 additions & 0 deletions recipes/sentry-native/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.1)
project(test_package)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package
${CMAKE_CURRENT_BINARY_DIR}/test_package)
17 changes: 17 additions & 0 deletions recipes/sentry-native/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from conans import ConanFile, CMake, tools
import os


class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "cmake", "cmake_find_package_multi"

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
2 changes: 0 additions & 2 deletions recipes/sentry-native/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,3 @@ versions:
folder: all
"0.4.13":
folder: all
"0.2.6":
folder: all