diff --git a/recipes/coz/all/CMakeLists.txt b/recipes/coz/all/CMakeLists.txt deleted file mode 100644 index bd3083b512cb9..0000000000000 --- a/recipes/coz/all/CMakeLists.txt +++ /dev/null @@ -1,7 +0,0 @@ -cmake_minimum_required(VERSION 3.1) -project(cmake_wrapper) - -include(conanbuildinfo.cmake) -conan_basic_setup() - -add_subdirectory(source_subfolder) diff --git a/recipes/coz/all/conanfile.py b/recipes/coz/all/conanfile.py index 525f92fcfbd9c..b3da8b64ac09e 100644 --- a/recipes/coz/all/conanfile.py +++ b/recipes/coz/all/conanfile.py @@ -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" diff --git a/recipes/coz/all/test_package/CMakeLists.txt b/recipes/coz/all/test_package/CMakeLists.txt index 7b9b613cbb24a..d7ea7e2a51ab7 100644 --- a/recipes/coz/all/test_package/CMakeLists.txt +++ b/recipes/coz/all/test_package/CMakeLists.txt @@ -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) diff --git a/recipes/coz/all/test_package/conanfile.py b/recipes/coz/all/test_package/conanfile.py index ad479949b486f..fe45f480669f3 100644 --- a/recipes/coz/all/test_package/conanfile.py +++ b/recipes/coz/all/test_package/conanfile.py @@ -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())