Skip to content

Commit

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

* coz: use is_apple_os()

* coz: update

* coz: fix test_package

* coz: static build is not supported, mark as shared-library

* coz: drop test_v1_package
  • Loading branch information
valgur authored Dec 26, 2023
1 parent 6abbea2 commit b198cd5
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 51 deletions.
7 changes: 0 additions & 7 deletions recipes/coz/all/CMakeLists.txt

This file was deleted.

79 changes: 47 additions & 32 deletions recipes/coz/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,61 +1,76 @@
import os
from conans import ConanFile, CMake, tools
from conans.errors import ConanInvalidConfiguration

required_conan_version = ">=1.33.0"
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.apple import is_apple_os
from conan.tools.build import check_min_cppstd
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.files import get, rmdir
from conan.tools.microsoft import is_msvc
from conan.tools.scm import Version

required_conan_version = ">=1.53.0"


class CozConan(ConanFile):
name = "coz"
description = """Causal profiler, uses performance experiments
to predict the effect of optimizations"""
description = "Causal profiler, uses performance experiments to predict the effect of optimizations"
license = "BSD-2-Clause"
url = "https://github.com/conan-io/conan-center-index"
homepage = "http://coz-profiler.org"
license = "BSD-2-Clause"
topics = ("conan", "coz", "profiler", "causal")
topics = ("profiler", "causal")

package_type = "shared-library"
settings = "os", "arch", "compiler", "build_type"

requires = "libelfin/0.3"
exports_sources = "CMakeLists.txt"
generators = "cmake", "cmake_find_package"
def layout(self):
cmake_layout(self, src_folder="src")

def package_id(self):
del self.info.settings.compiler
del self.info.settings.build_type

_source_subfolder = "source_subfolder"
def requirements(self):
self.requires("libelfin/0.3")

def validate(self):
compiler = self.settings.compiler
compiler_version = tools.Version(self.settings.compiler.version)
if self.settings.os == "Macos" or compiler == "Visual Studio" or (
compiler == "gcc" and compiler_version < "5.0"):
raise ConanInvalidConfiguration(
"coz doesn't support compiler: {} on OS: {}.".format(
self.settings.compiler, self.settings.os))
if self.settings.compiler.cppstd:
tools.check_min_cppstd(self, "11")
check_min_cppstd(self, 11)
compiler_version = Version(self.settings.compiler.version)
if self.settings.compiler == "gcc" and compiler_version < "5.0":
raise ConanInvalidConfiguration("coz requires GCC >= 5.0")
if is_apple_os(self) or is_msvc(self):
raise ConanInvalidConfiguration(f"coz doesn't support {self.settings.os}.")

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

_cmake = None

def _configure_cmake(self):
if self._cmake:
return self._cmake
self._cmake = CMake(self)
self._cmake.configure()
return self._cmake
def generate(self):
tc = CMakeToolchain(self)
tc.generate()
deps = CMakeDeps(self)
deps.generate()

def build(self):
cmake = self._configure_cmake()
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, "lib", "cmake"))
rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))

def package_info(self):
# https://github.com/plasma-umass/coz/#cmake
self.cpp_info.set_property("cmake_file_name", "coz-profiler")
self.cpp_info.set_property("cmake_target_name", "coz::coz")

self.cpp_info.libs = ["coz"]
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.system_libs = ["m", "dl", "pthread", "rt"]

# TODO: to remove in conan v2 once cmake_find_package_* generators removed
self.cpp_info.filenames["cmake_find_package"] = "coz-profiler"
self.cpp_info.filenames["cmake_find_package_multi"] = "coz-profiler"
self.cpp_info.names["cmake_find_package"] = "coz"
Expand Down
7 changes: 3 additions & 4 deletions recipes/coz/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
cmake_minimum_required(VERSION 3.1)
cmake_minimum_required(VERSION 3.15)
project(test_package C)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
find_package(coz-profiler REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.c)
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
target_link_libraries(${PROJECT_NAME} PRIVATE coz::coz)
37 changes: 29 additions & 8 deletions recipes/coz/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,40 @@
from conans import ConanFile, CMake, tools
import os

from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import cmake_layout, CMake
from conan.tools.files import chdir


class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake"
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv"
test_type = "explicit"

def requirements(self):
self.requires(self.tested_reference_str)

def layout(self):
cmake_layout(self)

def build(self):
cmake = CMake(self, build_type="RelWithDebInfo") # To work properly Coz tool requires debug information https://github.com/plasma-umass/coz
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if tools.cross_building(self.settings):
if self.settings.build_type not in ["Debug", "RelWithDebInfo"]:
self.output.info(f"Skipping coz test because {self.settings.build_type} "
"build type does not contain debug information")
return
bin_path = os.path.join("bin", "test_package")
self.run("coz run --- " + bin_path, run_environment=True)
print(open("profile.coz").read())
if self.settings.os == "Linux":
perf_even_paranoid = int(open("/proc/sys/kernel/perf_event_paranoid").read())
is_root = os.geteuid() == 0
if perf_even_paranoid > 2 and not is_root:
self.output.info("Skipping coz test because /proc/sys/kernel/perf_event_paranoid value "
f"must be <= 2 (currently {perf_even_paranoid}) and not running as root")
return
if can_run(self):
with chdir(self, self.cpp.build.bindir):
self.run("coz run --- ./test_package", env="conanrun")
print(open("profile.coz").read())

0 comments on commit b198cd5

Please sign in to comment.