Skip to content

Commit f406677

Browse files
AiyionPrimebingmann
andcommitted
stacktrace: add version 1.0.0
Co-authored-by: Timo Bingmann <[email protected]>
1 parent 36b98c4 commit f406677

File tree

5 files changed

+131
-0
lines changed

5 files changed

+131
-0
lines changed

recipes/stacktrace/all/conanfile.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import os
2+
3+
from conan import ConanFile
4+
from conan.errors import ConanInvalidConfiguration
5+
from conan.tools.build import check_min_cppstd
6+
from conan.tools.files import copy, download
7+
8+
required_conan_version = ">=2.0"
9+
10+
11+
class PackageConan(ConanFile):
12+
name = "stacktrace"
13+
description = "Print stack backtrace programmatically with demangled function names"
14+
license = "WTFPL"
15+
url = "https://github.com/conan-io/conan-center-index"
16+
homepage = "https://panthema.net/2008/0901-stacktrace-demangled/"
17+
topics = ("stacktrace", "backtrace", "backtrace_symbols", "demangle", "header-only")
18+
package_type = "header-library"
19+
settings = "os", "arch", "compiler", "build_type"
20+
no_copy_source = True
21+
22+
def source(self):
23+
download(
24+
self,
25+
url="https://panthema.net/2008/0901-stacktrace-demangled/stacktrace.h",
26+
filename="stacktrace.h",
27+
sha256="f850b0b859595f26121ccc9c8b9a82d9ed9acfe35fdea01554b257e95301310b",
28+
)
29+
30+
def export_sources(self):
31+
copy(self, "stacktrace.h", self.recipe_folder, self.export_sources_folder)
32+
33+
def package_id(self):
34+
self.info.clear()
35+
36+
def validate(self):
37+
check_min_cppstd(self, 98)
38+
if str(self.settings.compiler) not in ["gcc", "clang"]:
39+
raise ConanInvalidConfiguration(
40+
f"{self.ref} does only demangle gcc and clang properly."
41+
)
42+
if self.settings.os == "Windows":
43+
raise ConanInvalidConfiguration(f"{self.ref} might not compile on Windows.")
44+
45+
def build(self):
46+
pass
47+
48+
def package(self):
49+
copy(
50+
self,
51+
"stacktrace.h",
52+
self.source_folder,
53+
os.path.join(self.package_folder, "include"),
54+
)
55+
56+
def package_info(self):
57+
self.cpp_info.bindirs = []
58+
self.cpp_info.libdirs = []
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
cmake_minimum_required(VERSION 3.15)
2+
project(test_package LANGUAGES CXX)
3+
4+
find_package(stacktrace REQUIRED CONFIG)
5+
6+
add_executable(${PROJECT_NAME} test_package.cpp)
7+
target_link_libraries(${PROJECT_NAME} PRIVATE stacktrace::stacktrace)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from conan import ConanFile
2+
from conan.tools.build import can_run
3+
from conan.tools.cmake import cmake_layout, CMake
4+
import os
5+
6+
7+
class TestPackageConan(ConanFile):
8+
settings = "os", "arch", "compiler", "build_type"
9+
generators = "CMakeDeps", "CMakeToolchain"
10+
11+
def layout(self):
12+
cmake_layout(self)
13+
14+
def requirements(self):
15+
self.requires(self.tested_reference_str)
16+
17+
def build(self):
18+
cmake = CMake(self)
19+
cmake.configure()
20+
cmake.build()
21+
22+
def test(self):
23+
if can_run(self):
24+
bin_path = os.path.join(self.cpp.build.bindir, "test_package")
25+
self.run(bin_path, env="conanrun")
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include "stacktrace.h"
2+
#include <map>
3+
4+
namespace Nu {
5+
6+
template<typename Type>
7+
struct Alpha {
8+
struct Beta {
9+
void func() {
10+
print_stacktrace();
11+
}
12+
void func(Type) {
13+
print_stacktrace();
14+
}
15+
};
16+
};
17+
18+
struct Gamma {
19+
template <int N>
20+
void unroll(double d) {
21+
unroll<N-1>(d);
22+
}
23+
};
24+
25+
template<>
26+
void Gamma::unroll<0>(double) {
27+
print_stacktrace();
28+
}
29+
30+
} // namespace Nu
31+
32+
int main(void) {
33+
Nu::Alpha<int>::Beta().func(42);
34+
Nu::Alpha<char*>::Beta().func("42");
35+
Nu::Alpha< Nu::Alpha< std::map<int, double> > >::Beta().func();
36+
Nu::Gamma().unroll<5>(42.0);
37+
return EXIT_SUCCESS;
38+
}

recipes/stacktrace/config.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
versions:
2+
"1.0.0":
3+
folder: all

0 commit comments

Comments
 (0)