Skip to content

Commit

Permalink
kcov: migrate to Conan v2
Browse files Browse the repository at this point in the history
  • Loading branch information
valgur committed Nov 2, 2023
1 parent ee60d51 commit f20165e
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 55 deletions.
7 changes: 0 additions & 7 deletions recipes/kcov/all/CMakeLists.txt

This file was deleted.

2 changes: 0 additions & 2 deletions recipes/kcov/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,4 @@ patches:
"40": []

Check failure on line 9 in recipes/kcov/all/conandata.yml

View workflow job for this annotation

GitHub Actions / Lint changed files (YAML files)

conandata.yml schema error

Schema outlined in https://github.com/conan-io/conan-center-index/blob/master/docs/adding_packages/conandata_yml_format.md#patches-fields is not followed. Found ugly disallowed JSONesque flow mapping (surround with ' and ' to make text appear literally) in "40": [] ^ (line: 9)
"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"
94 changes: 53 additions & 41 deletions recipes/kcov/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,63 +1,75 @@
import os

from conan import ConanFile
from conans import CMake, tools
from conans.errors import ConanInvalidConfiguration
from conan.errors import ConanInvalidConfiguration
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, rmdir

required_conan_version = ">=1.47.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)

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

def requirements(self):
self.requires("zlib/1.2.13")
self.requires("libiberty/9.1.0")
self.requires("libcurl/[>=7.78 <9]")
self.requires("elfutils/0.186")

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.")

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

def _patch_sources(self):
for patch in self.conan_data["patches"][self.version]:
tools.patch(**patch)
get(self, **self.conan_data["sources"][self.version], strip_root=True)

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 generate(self):
tc = CMakeToolchain(self)
tc.generate()
tc = CMakeDeps(self)
tc.generate()

def build(self):
self._patch_sources()
cmake = self._configure_cmake()
apply_conandata_patches(self)
cmake = CMake(self)
cmake.configure()
cmake.build()

def package(self):
cmake = self._configure_cmake()
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"))
copy(self, "COPYING*", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder)

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.output.info(f"Appending PATH environment variable: {bindir}")
self.env_info.PATH.append(bindir)
self.cpp_info.includedirs = []
14 changes: 9 additions & 5 deletions recipes/kcov/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
from conans import ConanFile, tools
from conan import ConanFile


class KcovTestConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "VirtualBuildEnv"
test_type = "explicit"

def build_requirements(self):
self.tool_requires(self.tested_reference_str)

def test(self):
if not tools.cross_building(self.settings):
self.run("kcov --version", run_environment=True)
self.run("kcov --version")
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)

0 comments on commit f20165e

Please sign in to comment.