diff --git a/recipes/kcov/all/CMakeLists.txt b/recipes/kcov/all/CMakeLists.txt deleted file mode 100644 index a69305eb3971f..0000000000000 --- a/recipes/kcov/all/CMakeLists.txt +++ /dev/null @@ -1,7 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12) -project(cmake_wrapper) - -include(conanbuildinfo.cmake) -conan_basic_setup() - -add_subdirectory(source_subfolder) diff --git a/recipes/kcov/all/conan_deps.cmake b/recipes/kcov/all/conan_deps.cmake new file mode 100644 index 0000000000000..47c0823a35eb3 --- /dev/null +++ b/recipes/kcov/all/conan_deps.cmake @@ -0,0 +1,34 @@ +# Wrapper for find_package() that also adds upper-case variables and allows only Conan packages +macro(custom_find_package name) + find_package(${name} ${ARGN} CONFIG + # Allow only Conan packages + NO_DEFAULT_PATH + PATHS ${CMAKE_PREFIX_PATH} + ) + string(TOUPPER ${name} name_upper) + set(${name_upper}_FOUND TRUE) + set(${name_upper}_VERSION_STRING ${${name}_VERSION_STRING}) + set(${name_upper}_INCLUDE_DIRS ${${name}_INCLUDE_DIRS}) + set(${name_upper}_INCLUDE_DIR ${${name}_INCLUDE_DIR}) + set(${name_upper}_LIBRARIES ${${name}_LIBRARIES}) + set(${name_upper}_DEFINITIONS ${${name}_DEFINITIONS}) + unset(name_upper) +endmacro() + +custom_find_package(Bfd) +custom_find_package(ZLIB REQUIRED) +custom_find_package(CURL REQUIRED) + +if(APPLE) + custom_find_package(Dwarfutils REQUIRED) + set(dwarfutils_FOUND TRUE) +else() + custom_find_package(ElfUtils REQUIRED) + set(Elfutils_FOUND TRUE) + # ElfUtils also provides LibElf + set(LibElf_FOUND TRUE) + set(LIBELF_FOUND TRUE) + set(LIBELF_INCLUDE_DIRS ${ElfUtils_INCLUDE_DIRS}) + set(LIBELF_LIBRARIES ${ElfUtils_LIBRARIES}) + set(LIBELF_DEFINITIONS ${ElfUtils_DEFINITIONS}) +endif() diff --git a/recipes/kcov/all/conandata.yml b/recipes/kcov/all/conandata.yml index b98fb5f6098f5..972457056a28e 100644 --- a/recipes/kcov/all/conandata.yml +++ b/recipes/kcov/all/conandata.yml @@ -1,4 +1,7 @@ sources: + "42": + url: "https://github.com/SimonKagstrom/kcov/archive/refs/tags/v42.tar.gz" + sha256: "2c47d75397af248bc387f60cdd79180763e1f88f3dd71c94bb52478f8e74a1f8" "40": url: "https://github.com/SimonKagstrom/kcov/archive/refs/tags/v40.tar.gz" sha256: "6b1c11b066d57426d61375a31c3816f1fcd2610b447050c86d9920e22d5200b3" @@ -6,9 +9,14 @@ sources: url: "https://github.com/SimonKagstrom/kcov/archive/38.tar.gz" sha256: "b37af60d81a9b1e3b140f9473bdcb7975af12040feb24cc666f9bb2bb0be68b4" patches: - "40": [] + "42": + - patch_file: "patches/0003-fix-missing-include.patch" + patch_description: "Add a missing includes on macOS" + patch_type: "backport" + patch_source: "https://github.com/SimonKagstrom/kcov/commit/4efe5e4a4ac4e7b6d99fc869d826aa74ff716ebf" + - patch_file: "patches/0004-fix-libdwarf-prefix.patch" + patch_description: "Adjust libdwarf include to match CCI includedirs" + patch_type: "conan" "38": - patch_file: "patches/0001-fix-SOLIB-path.patch" - base_path: "source_subfolder" - patch_file: "patches/0002-fix-missing-libssl-dependency.patch" - base_path: "source_subfolder" diff --git a/recipes/kcov/all/conanfile.py b/recipes/kcov/all/conanfile.py index 563b33b2f010e..ccb250afff541 100644 --- a/recipes/kcov/all/conanfile.py +++ b/recipes/kcov/all/conanfile.py @@ -1,63 +1,98 @@ import os + from conan import ConanFile -from conans import CMake, tools -from conans.errors import ConanInvalidConfiguration +from conan.errors import ConanInvalidConfiguration +from conan.tools.apple import is_apple_os +from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout +from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, rmdir, rm +from conan.tools.scm import Version + +required_conan_version = ">=1.53.0" + class KcovConan(ConanFile): name = "kcov" + description = ( + "Code coverage tool for compiled programs, Python and Bash which uses " + "debugging information to collect and report data without special compilation options" + ) license = "GPL-2.0" - url = "https://github.com/conan-io/conan-center-index/" + url = "https://github.com/conan-io/conan-center-index" homepage = "http://simonkagstrom.github.io/kcov/index.html" - description = "Code coverage tool for compiled programs, Python and Bash\ - which uses debugging information to collect and report data without\ - special compilation options" topics = ("coverage", "linux", "debug") - settings = "os", "compiler", "build_type", "arch" - exports_sources = "CMakeLists.txt", "patches/**" - requires = ["zlib/1.2.12", - "libiberty/9.1.0", - "libcurl/7.83.1", - "elfutils/0.180"] - generators = "cmake" - _cmake = None - _source_subfolder = "source_subfolder" - _build_subfolder = "build_subfolder" - - def configure(self): + + package_type = "application" + settings = "os", "arch", "compiler", "build_type" + + def export_sources(self): + export_conandata_patches(self) + copy(self, "conan_deps.cmake", self.recipe_folder, os.path.join(self.export_sources_folder, "src")) + + def layout(self): + cmake_layout(self, src_folder="src") + + def requirements(self): + self.requires("zlib/[>=1.2.11 <2]") + self.requires("libcurl/[>=7.78 <9]") + self.requires("openssl/[>=1.1 <4]") + if is_apple_os(self): + self.requires("libdwarf/0.8.0") + else: + self.requires("elfutils/0.190") + + def package_id(self): + del self.info.settings.compiler + del self.info.settings.build_type + + def validate(self): if self.settings.os == "Windows": - raise ConanInvalidConfiguration( - "kcov can not be built on windows.") + raise ConanInvalidConfiguration("kcov can not be built on windows.") + if is_apple_os(self): + if Version(self.version) < 42: + # MachO support was added in v42 + raise ConanInvalidConfiguration(f"{self.ref} does not support {self.settings.os}.") + if self.settings.arch == "armv8": + # https://github.com/SimonKagstrom/kcov/blob/v42/cmake/TargetArch.cmake + raise ConanInvalidConfiguration(f"{self.ref} does not support {self.settings.arch}.") def source(self): - tools.get(**self.conan_data["sources"][self.version]) - extracted_dir = self.name + "-" + self.version - os.rename(extracted_dir, self._source_subfolder) + get(self, **self.conan_data["sources"][self.version], strip_root=True) - def _patch_sources(self): - for patch in self.conan_data["patches"][self.version]: - tools.patch(**patch) + def generate(self): + tc = CMakeToolchain(self) + tc.variables["CMAKE_PROJECT_kcov_INCLUDE"] = "conan_deps.cmake" + tc.generate() + deps = CMakeDeps(self) + # Match Find*.cmake module names used by the project + deps.set_property("libbfd", "cmake_file_name", "Bfd") + deps.set_property("libdwarf", "cmake_file_name", "Dwarfutils") + deps.set_property("elfutils", "cmake_file_name", "ElfUtils") + deps.set_property("libcrpcut", "cmake_file_name", "LibCRPCUT") + deps.generate() - def _configure_cmake(self): - if self._cmake is not None: - return self._cmake - self._cmake = CMake(self) - self._cmake.configure(build_folder=self._build_subfolder) - return self._cmake + def _patch_sources(self): + apply_conandata_patches(self) + # Disable project Find*.cmake modules just in case + rm(self, "Find*.cmake", os.path.join(self.source_folder, "cmake")) def build(self): self._patch_sources() - cmake = self._configure_cmake() + cmake = CMake(self) + cmake.configure() cmake.build() def package(self): - cmake = self._configure_cmake() + copy(self, "COPYING*", self.source_folder, os.path.join(self.package_folder, "licenses")) + cmake = CMake(self) cmake.install() - tools.rmdir(os.path.join(self.package_folder, "share")) - self.copy("COPYING*", dst="licenses", src=self._source_subfolder) + rmdir(self, os.path.join(self.package_folder, "share")) def package_info(self): + self.cpp_info.includedirs = [] + self.cpp_info.frameworkdirs = [] + self.cpp_info.libdirs = [] + self.cpp_info.resdirs = [] + + # TODO: to remove in conan v2 bindir = os.path.join(self.package_folder, "bin") - self.output.info("Appending PATH environment variable: {}" - .format(bindir)) self.env_info.PATH.append(bindir) - self.cpp_info.includedirs = [] diff --git a/recipes/kcov/all/patches/0003-fix-missing-include.patch b/recipes/kcov/all/patches/0003-fix-missing-include.patch new file mode 100644 index 0000000000000..49167148ac3b4 --- /dev/null +++ b/recipes/kcov/all/patches/0003-fix-missing-include.patch @@ -0,0 +1,20 @@ +Use updated includes from master to fix a missing and +https://github.com/SimonKagstrom/kcov/blob/1d036f7799f95fed025c5fa0665c19df38632ab4/src/engines/mach-engine.cc + +--- src/engines/mach-engine.cc ++++ src/engines/mach-engine.cc +@@ -26,7 +26,14 @@ + #include + #include + #include ++#include ++// clang-format off ++// sys/ptrace.h needs sys/types.h, so make sure clang-format doesn't change the order ++#include + #include ++// clang-format on ++#include ++#include + #include + #include + #include diff --git a/recipes/kcov/all/patches/0004-fix-libdwarf-prefix.patch b/recipes/kcov/all/patches/0004-fix-libdwarf-prefix.patch new file mode 100644 index 0000000000000..3c5509fce924d --- /dev/null +++ b/recipes/kcov/all/patches/0004-fix-libdwarf-prefix.patch @@ -0,0 +1,18 @@ +FIXME: update libdwarf instead + +--- src/parsers/macho-parser.cc ++++ src/parsers/macho-parser.cc +@@ -6,11 +6,11 @@ + */ + #include + #include +-#include ++#include + #include + #include + #include +-#include ++#include + #include + #include + #include diff --git a/recipes/kcov/all/test_package/conanfile.py b/recipes/kcov/all/test_package/conanfile.py index ea5ad0c50ed3e..9808e9680a682 100644 --- a/recipes/kcov/all/test_package/conanfile.py +++ b/recipes/kcov/all/test_package/conanfile.py @@ -1,9 +1,19 @@ -from conans import ConanFile, tools +from conan import ConanFile +from conan.tools.cmake import cmake_layout +from conan.tools.build import can_run -class KcovTestConan(ConanFile): - settings = "os", "compiler", "build_type", "arch" +class TestPackageConan(ConanFile): + settings = "os", "arch", "compiler", "build_type" + generators = "VirtualRunEnv" + test_type = "explicit" + + def requirements(self): + self.requires(self.tested_reference_str) + + def layout(self): + cmake_layout(self) def test(self): - if not tools.cross_building(self.settings): - self.run("kcov --version", run_environment=True) + if can_run(self): + self.run("kcov --version", env="conanrun") diff --git a/recipes/kcov/all/test_v1_package/conanfile.py b/recipes/kcov/all/test_v1_package/conanfile.py new file mode 100644 index 0000000000000..ea5ad0c50ed3e --- /dev/null +++ b/recipes/kcov/all/test_v1_package/conanfile.py @@ -0,0 +1,9 @@ +from conans import ConanFile, tools + + +class KcovTestConan(ConanFile): + settings = "os", "compiler", "build_type", "arch" + + def test(self): + if not tools.cross_building(self.settings): + self.run("kcov --version", run_environment=True) diff --git a/recipes/kcov/config.yml b/recipes/kcov/config.yml index b36ca0e497b00..97b2691d28e3b 100644 --- a/recipes/kcov/config.yml +++ b/recipes/kcov/config.yml @@ -1,4 +1,6 @@ versions: + "42": + folder: all "40": folder: all "38":