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

Add libbacktrace/1.0 #4431

Merged
merged 20 commits into from
Feb 9, 2021
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
4 changes: 4 additions & 0 deletions recipes/libbacktrace/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
"cci.20210118":
url: "https://github.com/ianlancetaylor/libbacktrace/archive/dedbe13fda00253fe5d4f2fb812c909729ed5937.tar.gz"
sha256: "dc8c167f48f3de5ae318c528b26b72f300edb6e33744e55394674fd4b7cdd21d"
69 changes: 69 additions & 0 deletions recipes/libbacktrace/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import glob
import os

from conans import AutoToolsBuildEnvironment, ConanFile, tools
from conans.errors import ConanInvalidConfiguration


class LibbacktraceConan(ConanFile):
name = "libbacktrace"
description = "A C library that may be linked into a C/C++ program to produce symbolic backtraces."
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/ianlancetaylor/libbacktrace"
license = "BSD-3-Clause"
topics = ("conan", "backtrace", "stack-trace")

settings = "os", "arch", "compiler", "build_type"
options = {"shared": [True, False], "fPIC": [True, False]}
default_options = {"shared": False, "fPIC": True}

build_requires = "autoconf/2.69", "libtool/2.4.6"

__autotools = None
_source_subfolder = "source_subfolder"

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

def configure(self):
if self.settings.compiler == "Visual Studio":
raise ConanInvalidConfiguration("libsafec doesn't support {}/{}".format(
self.settings.compiler, self.settings.compiler.version))
if self.options.shared:
del self.options.fPIC
del self.settings.compiler.libcxx
del self.settings.compiler.cppstd

def source(self):
tools.get(**self.conan_data["sources"][self.version])
extracted_dir = glob.glob("libbacktrace-*")[0]
os.rename(extracted_dir, self._source_subfolder)

@property
def _autotools(self):
if self.__autotools is None:
self.__autotools = AutoToolsBuildEnvironment(self)
return self.__autotools

def _autotools_configure(self):
if self.options.shared:
args = ["--enable-shared", "--disable-static"]
else:
args = ["--disable-shared", "--enable-static"]
self._autotools.configure(args=args)

def build(self):
with tools.chdir(self._source_subfolder):
self.run("autoreconf -fiv", run_environment=True)
self._autotools_configure()
self._autotools.make()

def package(self):
with tools.chdir(self._source_subfolder):
self._autotools.install()
self.copy("LICENSE", src=self._source_subfolder, dst="licenses")
tools.remove_files_by_mask(os.path.join(self.package_folder, "lib"), "*.la")

def package_info(self):
self.cpp_info.libs = ["backtrace"]
8 changes: 8 additions & 0 deletions recipes/libbacktrace/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 C)

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

add_executable(test_package test_package.c)
target_link_libraries(test_package ${CONAN_LIBS})
19 changes: 19 additions & 0 deletions recipes/libbacktrace/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import os

from conans import CMake, ConanFile, tools


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

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

def test(self):
if tools.cross_building(self.settings):
return
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
36 changes: 36 additions & 0 deletions recipes/libbacktrace/all/test_package/test_package.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include <backtrace-supported.h>
#include <backtrace.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

void
error_callback(void* data, const char* msg, int errnum)
{
fprintf(stderr, "%s", msg);
if (errnum > 0)
fprintf(stderr, ": %s", strerror(errnum));
fprintf(stderr, "\n");
exit(EXIT_FAILURE);
}

int
simple_callback(void* data, uintptr_t pc)
{
printf(" 0x%016lx\n", pc);
return 1;
}

int
main(int argc, char** argv)
{
void* state;

state = backtrace_create_state(argv[0], BACKTRACE_SUPPORTS_THREADS, error_callback, NULL);
printf("Top stack frame:\n");
backtrace_simple(state, 0, simple_callback, error_callback, NULL);
printf("Done\n");

return 0;
}
3 changes: 3 additions & 0 deletions recipes/libbacktrace/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"cci.20210118":
folder: all