Skip to content

Commit

Permalink
coz: migrate to Conan v2
Browse files Browse the repository at this point in the history
  • Loading branch information
valgur committed Jul 19, 2023
1 parent b164b06 commit cea325d
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 52 deletions.
7 changes: 0 additions & 7 deletions recipes/coz/all/CMakeLists.txt

This file was deleted.

77 changes: 45 additions & 32 deletions recipes/coz/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,61 +1,74 @@
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.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 = "application"
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")

_source_subfolder = "source_subfolder"
def package_id(self):
del self.info.settings.compiler
del self.info.settings.build_type

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 = self.settings.compiler
compiler_version = Version(self.settings.compiler.version)
if self.settings.os == "Macos" or is_msvc(self) or (compiler == "gcc" and compiler_version < "5.0"):
raise ConanInvalidConfiguration(f"coz doesn't support compiler: {self.settings.compiler} on OS: {self.settings.os}.")

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

_cmake = None
get(self, **self.conan_data["sources"][self.version], strip_root=True)

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()
tc = CMakeDeps(self)
tc.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.frameworkdirs = []
self.cpp_info.libdirs = []
self.cpp_info.resdirs = []

# 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)
30 changes: 21 additions & 9 deletions recipes/coz/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,31 @@
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


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
# FIXME: To work properly Coz tool requires debug information https://github.com/plasma-umass/coz
# cmake = CMake(self, build_type="RelWithDebInfo")
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if tools.cross_building(self.settings):
return
bin_path = os.path.join("bin", "test_package")
self.run("coz run --- " + bin_path, run_environment=True)
print(open("profile.coz").read())
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindir, "test_package")
self.run(bin_path, env="conanrun")
self.run("coz run --- " + bin_path, env="conanrun")
print(open("profile.coz").read())

Check warning on line 31 in recipes/coz/all/test_package/conanfile.py

View workflow job for this annotation

GitHub Actions / Lint changed test_package/conanfile.py (v2 migration)

Using open without explicitly specifying an encoding
8 changes: 8 additions & 0 deletions recipes/coz/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.15)
project(test_package)

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

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package/
${CMAKE_CURRENT_BINARY_DIR}/test_package/)
19 changes: 19 additions & 0 deletions recipes/coz/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from conans import ConanFile, CMake, tools
import os


class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake", "cmake_find_package_multi"

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

def test(self):
if tools.cross_building(self.settings):
return
bin_path = os.path.join("bin", "test_package")
self.run("coz run --- " + bin_path, run_environment=True)
print(open("profile.coz").read())

0 comments on commit cea325d

Please sign in to comment.