Skip to content

Commit

Permalink
Merge pull request #10 from Ultimaker/CURA-11482_sentry
Browse files Browse the repository at this point in the history
CURA 11482 sentry
  • Loading branch information
wawanbreton authored Jan 17, 2024
2 parents 73e0a37 + 5ad448f commit ad84618
Show file tree
Hide file tree
Showing 12 changed files with 288 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/conan-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,5 @@ jobs:
- name: Export changed recipes
run: |
mkdir runner_scripts
wget https://raw.githubusercontent.com/Ultimaker/cura-workflows/CURA-10831/runner_scripts/upload_conan_recipes.py -O runner_scripts/upload_conan_recipes.py
wget https://raw.githubusercontent.com/Ultimaker/cura-workflows/main/runner_scripts/upload_conan_recipes.py -O runner_scripts/upload_conan_recipes.py
python runner_scripts/upload_conan_recipes.py --user ultimaker --branch ${{ github.ref_name }} --remote cura ${{ env.GIT_DIFF_FILTERED }}
13 changes: 13 additions & 0 deletions recipes/clipper/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
sources:
"6.4.2":
url: "https://sourceforge.net/projects/polyclipping/files/clipper_ver6.4.2.zip"
sha256: "a14320d82194807c4480ce59c98aa71cd4175a5156645c4e2b3edd330b930627"
"4.10.0":
url: "https://sourceforge.net/projects/polyclipping/files/Older%20versions/clipper_ver4.10.0.zip"
sha256: "4530e01006d02507a41f7eeaefa758c8067a94a7a0d6e0381fadfa40bc0cf248"
patches:
"6.4.2":
- patch_file: "patches/0001-include-install-directory-6.x.patch"
- patch_file: "patches/0002-build-debug-symbols-on-windows-6.x.patch"
"4.10.0":
- patch_file: "patches/0001-include-install-directory-4.x.patch"
101 changes: 101 additions & 0 deletions recipes/clipper/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
from io import StringIO

from conan import ConanFile
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, rmdir
from conan.errors import ConanInvalidConfiguration
from conans.tools import which
import os

required_conan_version = ">=1.54.0"


class ClipperConan(ConanFile):
name = "clipper"
description = "Clipper is an open source freeware polygon clipping library"
license = "BSL-1.0"
topics = ("clipping", "polygon")
url = "https://github.com/conan-io/conan-center-index"
homepage = "http://www.angusj.com/delphi/clipper.php"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
"enable_sentry": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
"enable_sentry": False,
}

def export_sources(self):
export_conandata_patches(self)

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def configure(self):
if self.options.shared:
self.options.rm_safe("fPIC")

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

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

def generate(self):
tc = CMakeToolchain(self)
# Export symbols for msvc shared
tc.variables["CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS"] = True
# To install relocatable shared libs on Macos
tc.cache_variables["CMAKE_POLICY_DEFAULT_CMP0042"] = "NEW"
tc.generate()

def build(self):
apply_conandata_patches(self)
cmake = CMake(self)
cmake.configure(build_script_folder=os.path.join(self.source_folder, "cpp"))
cmake.build()

if self.options.get_safe("enable_sentry", False):
# Upload debug symbols to sentry
sentry_project = self.conf.get("user.curaengine:sentry_project", "", check_type=str)
sentry_org = self.conf.get("user.curaengine:sentry_org", "", check_type=str)
if sentry_project == "" or sentry_org == "":
raise ConanInvalidConfiguration("sentry_project or sentry_org is not set")

if which("sentry-cli") is None:
self.output.warn("sentry-cli is not installed, skipping uploading debug symbols")
else:
if self.settings.os == "Linux":
self.output.info("Stripping debug symbols from binary")
ext = ".so" if self.options.shared else ".a"
self.run(f"objcopy --only-keep-debug --compress-debug-sections=zlib libpolyclipping{ext} libpolyclipping.debug")
self.run(f"objcopy --strip-debug --strip-unneeded libpolyclipping{ext}")
self.run(f"objcopy --add-gnu-debuglink=libpolyclipping.debug libpolyclipping{ext}")

build_source_dir = self.build_path.parent.parent.as_posix()
self.output.info("Uploading debug symbols to sentry")
self.run(f"sentry-cli debug-files upload --include-sources -o {sentry_org} -p {sentry_project} {build_source_dir}")

def package(self):
copy(self, "License.txt", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
cmake = CMake(self)
cmake.install()
rmdir(self, os.path.join(self.package_folder, "share"))

def package_info(self):
self.cpp_info.set_property("pkg_config_name", "polyclipping")
self.cpp_info.libs = ["polyclipping"]

if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.system_libs.append("m")

# TODO: to remove in conan v2 once cmake_find_package* & pkg_config generators removed.
# Do not use these CMake names in CMakeDeps, it was a mistake,
# clipper doesn't provide CMake config file
self.cpp_info.names["cmake_find_package"] = "polyclipping"
self.cpp_info.names["cmake_find_package_multi"] = "polyclipping"
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
--- a/cpp/CMakeLists.txt
+++ b/cpp/CMakeLists.txt
@@ -10,4 +10,4 @@

# The header name clipper.hpp is too generic, so install in a subdirectory
INSTALL (FILES clipper.hpp DESTINATION include/polyclipping)
-INSTALL (TARGETS polyclipping LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
+INSTALL (TARGETS polyclipping LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt
index 32293cb..9382d3e 100644
--- a/cpp/CMakeLists.txt
+++ b/cpp/CMakeLists.txt
@@ -15,7 +15,7 @@ ADD_LIBRARY(polyclipping clipper.cpp)
CONFIGURE_FILE (polyclipping.pc.cmakein "${PCFILE}" @ONLY)

INSTALL (FILES clipper.hpp DESTINATION "${CMAKE_INSTALL_INCDIR}")
-INSTALL (TARGETS polyclipping LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}")
+INSTALL (TARGETS polyclipping LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
INSTALL (FILES "${PCFILE}" DESTINATION "${CMAKE_INSTALL_PKGCONFIGDIR}")

SET_TARGET_PROPERTIES(polyclipping PROPERTIES VERSION 22.0.0 SOVERSION 22 )
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt
--- a/cpp/CMakeLists.txt
+++ b/cpp/CMakeLists.txt
@@ -19,3 +19,7 @@
INSTALL (FILES "${PCFILE}" DESTINATION "${CMAKE_INSTALL_PKGCONFIGDIR}")

SET_TARGET_PROPERTIES(polyclipping PROPERTIES VERSION 22.0.0 SOVERSION 22 )
+option(ENABLE_SENTRY "Send crash data via Sentry" OFF)
+if(WIN32 AND ENABLE_SENTRY)
+ set_target_properties(polyclipping PROPERTIES LINK_FLAGS "/DEBUG:FULL")
+endif()
\ No newline at end of file
8 changes: 8 additions & 0 deletions recipes/clipper/all/test_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 LANGUAGES CXX)

find_package(clipper REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE clipper::clipper)
target_compile_definitions(${PROJECT_NAME} PRIVATE CLIPPER_MAJOR_VERSION=${CLIPPER_MAJOR_VERSION})
32 changes: 32 additions & 0 deletions recipes/clipper/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
from conan.tools.scm import Version
import os


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

def layout(self):
cmake_layout(self)

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

def generate(self):
tc = CMakeToolchain(self)
tc.variables["CLIPPER_MAJOR_VERSION"] = Version(self.dependencies["clipper"].ref.version).major
tc.generate()

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

def test(self):
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
self.run(bin_path, env="conanrun")
67 changes: 67 additions & 0 deletions recipes/clipper/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#include "polyclipping/clipper.hpp"
#include <iostream>

using namespace ClipperLib;

int main() {

#if CLIPPER_MAJOR_VERSION == 6

//from clipper.hpp ...
//typedef signed long long cInt;
//struct IntPoint {cInt X; cInt Y;};
//typedef std::vector<IntPoint> Path;
//typedef std::vector<Path> Paths;

Paths subj(2), clip(1), solution;

//define outer blue 'subject' polygon
subj[0] <<
IntPoint(180,200) << IntPoint(260,200) <<
IntPoint(260,150) << IntPoint(180,150);

//define subject's inner triangular 'hole' (with reverse orientation)
subj[1] <<
IntPoint(215,160) << IntPoint(230,190) << IntPoint(200,190);

//define orange 'clipping' polygon
clip[0] <<
IntPoint(190,210) << IntPoint(240,210) <<
IntPoint(240,130) << IntPoint(190,130);

//perform intersection ...
Clipper c;
c.AddPaths(subj, ptSubject, true);
c.AddPaths(clip, ptClip, true);
c.Execute(ctIntersection, solution, pftNonZero, pftNonZero);

#else

Polygons subj(2), clip(1), solution;
return 0;

//define outer blue 'subject' polygon
subj[0].push_back(IntPoint(180,200));
subj[0].push_back(IntPoint(260,200));
subj[0].push_back(IntPoint(260,150));
subj[0].push_back(IntPoint(180,150));

//define subject's inner triangular 'hole' (with reverse orientation)
subj[1].push_back(IntPoint(215,160));
subj[1].push_back(IntPoint(230,190));
subj[1].push_back(IntPoint(200,190));

//define orange 'clipping' polygon
clip[0].push_back(IntPoint(190,210));
clip[0].push_back(IntPoint(240,210));
clip[0].push_back(IntPoint(240,130));
clip[0].push_back(IntPoint(190,130));

Clipper c;
c.AddPolygons(subj, ptSubject);
c.AddPolygons(clip, ptClip);
c.Execute(ctIntersection, solution, pftNonZero, pftNonZero);

#endif

}
11 changes: 11 additions & 0 deletions recipes/clipper/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
cmake_minimum_required(VERSION 3.1)
project(test_package LANGUAGES CXX)

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

find_package(polyclipping REQUIRED CONFIG)

add_executable(${PROJECT_NAME} ../test_package/test_package.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE polyclipping::polyclipping)
target_compile_definitions(${PROJECT_NAME} PRIVATE CLIPPER_MAJOR_VERSION=${CLIPPER_MAJOR_VERSION})
18 changes: 18 additions & 0 deletions recipes/clipper/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
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.definitions["CLIPPER_MAJOR_VERSION"] = tools.Version(self.deps_cpp_info["clipper"].version).major
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)
3 changes: 3 additions & 0 deletions recipes/clipper/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"6.4.2":
folder: all

0 comments on commit ad84618

Please sign in to comment.