Skip to content

Commit

Permalink
(#18672) kcov: migrate to Conan v2
Browse files Browse the repository at this point in the history
* kcov: migrate to Conan v2

* kcov: bump deps

* kcov: bump versions, fixes

* kcov: ignore Bfd dependency

* kcov: bump to v42

* kcov: use conan_deps.cmake to avoid patching

* kcov: fix macOS build

* kcov: armv8 is not supported

* kcov: fix another missing include in macOS system headers

* Update recipes/kcov/all/conandata.yml

* Update recipes/kcov/all/test_package/conanfile.py

* Update recipes/kcov/all/test_package/conanfile.py

---------

Co-authored-by: Uilian Ries <[email protected]>
  • Loading branch information
valgur and uilianries authored Jun 17, 2024
1 parent 7646d1d commit 789662c
Show file tree
Hide file tree
Showing 9 changed files with 183 additions and 54 deletions.
7 changes: 0 additions & 7 deletions recipes/kcov/all/CMakeLists.txt

This file was deleted.

34 changes: 34 additions & 0 deletions recipes/kcov/all/conan_deps.cmake
Original file line number Diff line number Diff line change
@@ -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()
14 changes: 11 additions & 3 deletions recipes/kcov/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
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"
"38":
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"
113 changes: 74 additions & 39 deletions recipes/kcov/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -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 = []
20 changes: 20 additions & 0 deletions recipes/kcov/all/patches/0003-fix-missing-include.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Use updated includes from master to fix a missing <cassert> and <sys/types.h>
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 <set>
#include <signal.h>
#include <spawn.h>
+#include <sys/errno.h>
+// clang-format off
+// sys/ptrace.h needs sys/types.h, so make sure clang-format doesn't change the order
+#include <sys/types.h>
#include <sys/ptrace.h>
+// clang-format on
+#include <cassert>
+#include <iostream>
#include <unistd.h>
#include <unordered_map>
#include <utils.hh>
18 changes: 18 additions & 0 deletions recipes/kcov/all/patches/0004-fix-libdwarf-prefix.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FIXME: update libdwarf instead

--- src/parsers/macho-parser.cc
+++ src/parsers/macho-parser.cc
@@ -6,11 +6,11 @@
*/
#include <capabilities.hh>
#include <configuration.hh>
-#include <dwarf.h>
+#include <libdwarf/dwarf.h>
#include <fcntl.h>
#include <file-parser.hh>
#include <filter.hh>
-#include <libdwarf.h>
+#include <libdwarf/libdwarf.h>
#include <mach-o/fat.h>
#include <mach-o/loader.h>
#include <map>
20 changes: 15 additions & 5 deletions recipes/kcov/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -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")
9 changes: 9 additions & 0 deletions recipes/kcov/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 2 additions & 0 deletions recipes/kcov/config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
versions:
"42":
folder: all
"40":
folder: all
"38":
Expand Down

0 comments on commit 789662c

Please sign in to comment.