From 4189e81f9f61fa20292b74e3ad8957edde363667 Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Wed, 19 Jul 2023 23:22:28 +0300 Subject: [PATCH 1/6] coz: migrate to Conan v2 --- recipes/coz/all/CMakeLists.txt | 7 -- recipes/coz/all/conanfile.py | 77 +++++++++++-------- recipes/coz/all/test_package/CMakeLists.txt | 7 +- recipes/coz/all/test_package/conanfile.py | 30 +++++--- .../coz/all/test_v1_package/CMakeLists.txt | 8 ++ recipes/coz/all/test_v1_package/conanfile.py | 19 +++++ 6 files changed, 96 insertions(+), 52 deletions(-) delete mode 100644 recipes/coz/all/CMakeLists.txt create mode 100644 recipes/coz/all/test_v1_package/CMakeLists.txt create mode 100644 recipes/coz/all/test_v1_package/conanfile.py 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..ec45660675354 100644 --- a/recipes/coz/all/conanfile.py +++ b/recipes/coz/all/conanfile.py @@ -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" 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..2afcd641f61d5 100644 --- a/recipes/coz/all/test_package/conanfile.py +++ b/recipes/coz/all/test_package/conanfile.py @@ -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()) diff --git a/recipes/coz/all/test_v1_package/CMakeLists.txt b/recipes/coz/all/test_v1_package/CMakeLists.txt new file mode 100644 index 0000000000000..91630d79f4abb --- /dev/null +++ b/recipes/coz/all/test_v1_package/CMakeLists.txt @@ -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/) diff --git a/recipes/coz/all/test_v1_package/conanfile.py b/recipes/coz/all/test_v1_package/conanfile.py new file mode 100644 index 0000000000000..df891eb34b9f2 --- /dev/null +++ b/recipes/coz/all/test_v1_package/conanfile.py @@ -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()) From 88848604dbfc984165492401f5ae062dac8670c9 Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Wed, 26 Jul 2023 23:21:11 +0300 Subject: [PATCH 2/6] coz: use is_apple_os() --- recipes/coz/all/conanfile.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/recipes/coz/all/conanfile.py b/recipes/coz/all/conanfile.py index ec45660675354..73fc59635dbf1 100644 --- a/recipes/coz/all/conanfile.py +++ b/recipes/coz/all/conanfile.py @@ -2,6 +2,7 @@ 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 @@ -37,7 +38,7 @@ def validate(self): 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"): + if is_apple_os(self) 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): From 27e37661bbedfd2570a9c15b08ca8e208e556552 Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Wed, 20 Dec 2023 10:15:43 +0200 Subject: [PATCH 3/6] coz: update --- recipes/coz/all/conanfile.py | 28 ++++++++++++++++++----- recipes/coz/all/test_package/conanfile.py | 5 ++-- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/recipes/coz/all/conanfile.py b/recipes/coz/all/conanfile.py index 73fc59635dbf1..5cfa1f8d72911 100644 --- a/recipes/coz/all/conanfile.py +++ b/recipes/coz/all/conanfile.py @@ -20,8 +20,24 @@ class CozConan(ConanFile): homepage = "http://coz-profiler.org" topics = ("profiler", "causal") - package_type = "application" + package_type = "library" settings = "os", "arch", "compiler", "build_type" + options = { + "shared": [True, False], + "fPIC": [True, False], + } + default_options = { + "shared": False, + "fPIC": True, + } + + def config_options(self): + if self.settings.os == "Windows": + del self.options.fPIC + + def configure(self): + if self.options.shared: + self.options.rm_safe("fPIC") def layout(self): cmake_layout(self, src_folder="src") @@ -47,8 +63,8 @@ def source(self): def generate(self): tc = CMakeToolchain(self) tc.generate() - tc = CMakeDeps(self) - tc.generate() + deps = CMakeDeps(self) + deps.generate() def build(self): cmake = CMake(self) @@ -65,9 +81,9 @@ def package_info(self): 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 = [] + 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" diff --git a/recipes/coz/all/test_package/conanfile.py b/recipes/coz/all/test_package/conanfile.py index 2afcd641f61d5..ca67ac5303f2a 100644 --- a/recipes/coz/all/test_package/conanfile.py +++ b/recipes/coz/all/test_package/conanfile.py @@ -17,14 +17,13 @@ def layout(self): cmake_layout(self) def build(self): - # 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 can_run(self): + # Coz requires debug information to work properly + if can_run(self) and self.settings.build_type in ["Debug", "RelWithDebInfo"]: 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") From 51e42d36d9ae37adbbc33d2dcd92789dc4da0956 Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Wed, 20 Dec 2023 10:23:00 +0200 Subject: [PATCH 4/6] coz: fix test_package --- recipes/coz/all/test_package/conanfile.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/recipes/coz/all/test_package/conanfile.py b/recipes/coz/all/test_package/conanfile.py index ca67ac5303f2a..fe45f480669f3 100644 --- a/recipes/coz/all/test_package/conanfile.py +++ b/recipes/coz/all/test_package/conanfile.py @@ -3,6 +3,7 @@ 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): @@ -22,9 +23,18 @@ def build(self): cmake.build() def test(self): - # Coz requires debug information to work properly - if can_run(self) and self.settings.build_type in ["Debug", "RelWithDebInfo"]: - 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()) + 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 + 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()) From 4c2c5167059e903fd9f080903668a837dcffcfeb Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Sat, 23 Dec 2023 15:15:11 +0200 Subject: [PATCH 5/6] coz: static build is not supported, mark as shared-library --- recipes/coz/all/conanfile.py | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/recipes/coz/all/conanfile.py b/recipes/coz/all/conanfile.py index 5cfa1f8d72911..dc2edffc33ea2 100644 --- a/recipes/coz/all/conanfile.py +++ b/recipes/coz/all/conanfile.py @@ -20,24 +20,8 @@ class CozConan(ConanFile): homepage = "http://coz-profiler.org" topics = ("profiler", "causal") - package_type = "library" + package_type = "shared-library" settings = "os", "arch", "compiler", "build_type" - options = { - "shared": [True, False], - "fPIC": [True, False], - } - default_options = { - "shared": False, - "fPIC": True, - } - - def config_options(self): - if self.settings.os == "Windows": - del self.options.fPIC - - def configure(self): - if self.options.shared: - self.options.rm_safe("fPIC") def layout(self): cmake_layout(self, src_folder="src") From 322ac25ec9fa93c31991954a4cd66180a0af4e5d Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Mon, 25 Dec 2023 16:51:44 +0200 Subject: [PATCH 6/6] coz: drop test_v1_package --- recipes/coz/all/conanfile.py | 7 ++++--- .../coz/all/test_v1_package/CMakeLists.txt | 8 -------- recipes/coz/all/test_v1_package/conanfile.py | 19 ------------------- 3 files changed, 4 insertions(+), 30 deletions(-) delete mode 100644 recipes/coz/all/test_v1_package/CMakeLists.txt delete mode 100644 recipes/coz/all/test_v1_package/conanfile.py diff --git a/recipes/coz/all/conanfile.py b/recipes/coz/all/conanfile.py index dc2edffc33ea2..b3da8b64ac09e 100644 --- a/recipes/coz/all/conanfile.py +++ b/recipes/coz/all/conanfile.py @@ -36,10 +36,11 @@ def requirements(self): def validate(self): if self.settings.compiler.cppstd: check_min_cppstd(self, 11) - compiler = self.settings.compiler compiler_version = Version(self.settings.compiler.version) - if is_apple_os(self) 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}.") + 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): get(self, **self.conan_data["sources"][self.version], strip_root=True) diff --git a/recipes/coz/all/test_v1_package/CMakeLists.txt b/recipes/coz/all/test_v1_package/CMakeLists.txt deleted file mode 100644 index 91630d79f4abb..0000000000000 --- a/recipes/coz/all/test_v1_package/CMakeLists.txt +++ /dev/null @@ -1,8 +0,0 @@ -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/) diff --git a/recipes/coz/all/test_v1_package/conanfile.py b/recipes/coz/all/test_v1_package/conanfile.py deleted file mode 100644 index df891eb34b9f2..0000000000000 --- a/recipes/coz/all/test_v1_package/conanfile.py +++ /dev/null @@ -1,19 +0,0 @@ -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())