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

libbacktrace: conan v2 support #13498

Merged
merged 1 commit into from
Oct 17, 2022
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
2 changes: 0 additions & 2 deletions recipes/libbacktrace/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,4 @@ sources:
patches:
"cci.20210118":
- patch_file: "patches/0001-pointer-arithmetic.patch"
base_path: "source_subfolder"
- patch_file: "patches/0002-msvc-unistd-alternative.patch"
base_path: "source_subfolder"
152 changes: 74 additions & 78 deletions recipes/libbacktrace/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
from conan.tools.files import rename
from conans import AutoToolsBuildEnvironment, ConanFile, tools
from conans.errors import ConanInvalidConfiguration
import contextlib
import functools
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.apple import fix_apple_shared_install_name
from conan.tools.env import Environment, VirtualBuildEnv
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, rename, rm
from conan.tools.gnu import Autotools, AutotoolsToolchain
from conan.tools.layout import basic_layout
from conan.tools.microsoft import is_msvc, unix_path
from conan.tools.scm import Version
import os

required_conan_version = ">=1.33.0"
required_conan_version = ">=1.52.0"


class LibbacktraceConan(ConanFile):
Expand All @@ -25,104 +29,96 @@ class LibbacktraceConan(ConanFile):
"fPIC": True,
}

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

@property
def _is_msvc(self):
return str(self.settings.compiler) in ["Visual Studio", "msvc"]

@property
def _settings_build(self):
return getattr(self, "settings_build", self.settings)

@property
def _user_info_build(self):
return getattr(self, "user_info_build", self.deps_user_info)

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

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

def configure(self):
if self.options.shared:
del self.options.fPIC
del self.settings.compiler.libcxx
del self.settings.compiler.cppstd
try:
del self.options.fPIC
except Exception:
pass
try:
del self.settings.compiler.libcxx
except Exception:
pass
try:
del self.settings.compiler.cppstd
except Exception:
pass

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

def validate(self):
if self._is_msvc and self.options.shared:
if is_msvc(self) and self.info.options.shared:
raise ConanInvalidConfiguration("libbacktrace shared is not supported with Visual Studio")

def build_requirements(self):
if self._settings_build.os == "Windows" and not tools.get_env("CONAN_BASH_PATH"):
self.build_requires("msys2/cci.latest")
if self._is_msvc:
self.build_requires("automake/1.16.4")
if self._settings_build.os == "Windows":
self.win_bash = True
if not self.conf.get("tools.microsoft.bash:path", default=False, check_type=bool):
self.tool_requires("msys2/cci.latest")
if is_msvc(self):
self.tool_requires("automake/1.16.5")

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

@property
def _user_info_build(self):
return getattr(self, "user_info_build", self.deps_user_info)

@contextlib.contextmanager
def _build_context(self):
if self._is_msvc:
with tools.vcvars(self):
env = {
"CC": "{} cl -nologo".format(tools.unix_path(self._user_info_build["automake"].compile)),
"CXX": "{} cl -nologo".format(tools.unix_path(self._user_info_build["automake"].compile)),
"LD": "{} link -nologo".format(tools.unix_path(self._user_info_build["automake"].compile)),
"AR": "{} lib".format(tools.unix_path(self._user_info_build["automake"].ar_lib)),
}
with tools.environment_append(env):
yield
else:
yield

@functools.lru_cache(1)
def _configure_autotools(self):
autotools = AutoToolsBuildEnvironment(self, win_bash=tools.os_info.is_windows)
autotools.libs = []
if (self.settings.compiler == "Visual Studio" and tools.Version(self.settings.compiler.version) >= "12") or \
str(self.settings.compiler) == "msvc":
autotools.flags.append("-FS")
yes_no = lambda v: "yes" if v else "no"
args = [
"--enable-shared={}".format(yes_no(self.options.shared)),
"--enable-static={}".format(yes_no(not self.options.shared)),
]
autotools.configure(args=args, configure_dir=self._source_subfolder)
return autotools

def _patch_sources(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)
# relocatable shared lib on macOS
tools.replace_in_file(os.path.join(self._source_subfolder, "configure"),
"-install_name \\$rpath/",
"-install_name @rpath/")
get(self, **self.conan_data["sources"][self.version],
destination=self.source_folder, strip_root=True)

def generate(self):
env = VirtualBuildEnv(self)
env.generate()

tc = AutotoolsToolchain(self)
if (self.settings.compiler == "Visual Studio" and Version(self.settings.compiler.version) >= "12") or \
(self.settings.compiler == "msvc" and Version(self.settings.compiler.version) >= "180"):
tc.extra_cflags.append("-FS")
tc.generate()

if is_msvc(self):
env = Environment()
compile_wrapper = unix_path(self, self._user_info_build["automake"].compile)
ar_wrapper = unix_path(self, self._user_info_build["automake"].ar_lib)
env.define("CC", f"{compile_wrapper} cl -nologo")
env.define("CXX", f"{compile_wrapper} cl -nologo")
env.define("LD", "link -nologo")
env.define("AR", f"{ar_wrapper} \"lib -nologo\"")
env.define("NM", "dumpbin -symbols")
env.define("OBJDUMP", ":")
env.define("RANLIB", ":")
env.define("STRIP", ":")
env.vars(self).save_script("conanbuild_libbacktrace_msvc")

def build(self):
self._patch_sources()
with self._build_context():
autotools = self._configure_autotools()
autotools.make()
apply_conandata_patches(self)
autotools = Autotools(self)
autotools.configure()
autotools.make()

def package(self):
with self._build_context():
autotools = self._configure_autotools()
autotools.install()
self.copy("LICENSE", src=self._source_subfolder, dst="licenses")
copy(self, "LICENSE", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
autotools = Autotools(self)
# see https://github.com/conan-io/conan/issues/12006
autotools.install(args=[f"DESTDIR={unix_path(self, self.package_folder)}"])
lib_folder = os.path.join(self.package_folder, "lib")
if self._is_msvc:
rm(self, "*.la", lib_folder)
fix_apple_shared_install_name(self)
if is_msvc(self):
rename(self, os.path.join(lib_folder, "libbacktrace.lib"),
os.path.join(lib_folder, "backtrace.lib"))
tools.remove_files_by_mask(lib_folder, "*.la")

def package_info(self):
self.cpp_info.libs = ["backtrace"]
7 changes: 2 additions & 5 deletions recipes/libbacktrace/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
cmake_minimum_required(VERSION 3.1)
project(test_package C)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)
project(test_package LANGUAGES C)

find_package(libbacktrace REQUIRED CONFIG)

add_executable(test_package test_package.c)
target_link_libraries(test_package libbacktrace::libbacktrace)
target_link_libraries(test_package PRIVATE libbacktrace::libbacktrace)
26 changes: 13 additions & 13 deletions recipes/libbacktrace/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
from conans import CMake, ConanFile, 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")
10 changes: 10 additions & 0 deletions recipes/libbacktrace/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
cmake_minimum_required(VERSION 3.1)
project(test_package LANGUAGES C)

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

find_package(libbacktrace REQUIRED CONFIG)

add_executable(test_package ../test_package/test_package.c)
target_link_libraries(test_package PRIVATE libbacktrace::libbacktrace)
17 changes: 17 additions & 0 deletions recipes/libbacktrace/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from conans import CMake, ConanFile, 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)