From ba0aea355ec564f106ec56c88fd24f44f8f00aec Mon Sep 17 00:00:00 2001 From: SpaceIm <30052553+SpaceIm@users.noreply.github.com> Date: Sat, 26 Nov 2022 22:24:44 +0100 Subject: [PATCH] (#14250) khrplatform: conan v2 support --- recipes/khrplatform/all/conanfile.py | 38 ++++++++++++------- .../all/test_package/CMakeLists.txt | 5 +-- .../khrplatform/all/test_package/conanfile.py | 21 +++++++--- .../all/test_v1_package/CMakeLists.txt | 8 ++++ .../all/test_v1_package/conanfile.py | 17 +++++++++ 5 files changed, 66 insertions(+), 23 deletions(-) create mode 100644 recipes/khrplatform/all/test_v1_package/CMakeLists.txt create mode 100644 recipes/khrplatform/all/test_v1_package/conanfile.py diff --git a/recipes/khrplatform/all/conanfile.py b/recipes/khrplatform/all/conanfile.py index 4cdbbcb701767..4125f97c39bdb 100644 --- a/recipes/khrplatform/all/conanfile.py +++ b/recipes/khrplatform/all/conanfile.py @@ -1,9 +1,10 @@ +from conan import ConanFile +from conan.tools.files import copy, download, load, save +from conan.tools.layout import basic_layout import os -from conans import ConanFile, tools -from conans.errors import ConanInvalidConfiguration +required_conan_version = ">=1.50.0" -required_conan_version = ">=1.37.0" class KhrplatformConan(ConanFile): name = "khrplatform" @@ -12,20 +13,31 @@ class KhrplatformConan(ConanFile): homepage = "https://www.khronos.org/registry/EGL/" description = "Khronos EGL platform interfaces" topics = ("opengl", "gl", "egl", "khr", "khronos") + settings = "os", "arch", "compiler", "build_type" no_copy_source = True + def layout(self): + basic_layout(self, src_folder="src") + + def package_id(self): + self.info.clear() + def source(self): - tools.download(filename="khrplatform.h", **self.conan_data["sources"][self.version]) + download(self, filename="khrplatform.h", **self.conan_data["sources"][self.version]) - def package(self): - self.copy(pattern="khrplatform.h", dst=os.path.join("include", "KHR")) - license_data = tools.load(os.path.join(self.source_folder, "khrplatform.h")) + def build(self): + pass + + def _extract_license(self): + license_data = load(self, os.path.join(self.source_folder, "khrplatform.h")) begin = license_data.find("/*") + len("/*") end = license_data.find("*/") - license_data = license_data[begin:end] - license_data = license_data.replace("**", "") - tools.save("LICENSE", license_data) - self.copy("LICENSE", dst="licenses") + return license_data[begin:end].replace("**", "") - def package_id(self): - self.info.header_only() + def package(self): + save(self, os.path.join(self.package_folder, "licenses", "LICENSE"), self._extract_license()) + copy(self, "khrplatform.h", src=self.source_folder, dst=os.path.join(self.package_folder, "include", "KHR")) + + def package_info(self): + self.cpp_info.bindirs = [] + self.cpp_info.libdirs = [] diff --git a/recipes/khrplatform/all/test_package/CMakeLists.txt b/recipes/khrplatform/all/test_package/CMakeLists.txt index 5e3eb0ca6b326..34fae3a337730 100644 --- a/recipes/khrplatform/all/test_package/CMakeLists.txt +++ b/recipes/khrplatform/all/test_package/CMakeLists.txt @@ -1,8 +1,5 @@ cmake_minimum_required(VERSION 3.1) -project(test_package C) - -include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) -conan_basic_setup() +project(test_package LANGUAGES C) find_package(khrplatform REQUIRED CONFIG) diff --git a/recipes/khrplatform/all/test_package/conanfile.py b/recipes/khrplatform/all/test_package/conanfile.py index 49a3a66ea5bad..0a6bc68712d90 100644 --- a/recipes/khrplatform/all/test_package/conanfile.py +++ b/recipes/khrplatform/all/test_package/conanfile.py @@ -1,10 +1,19 @@ -from conans import ConanFile, CMake, tools +from conan import ConanFile +from conan.tools.build import can_run +from conan.tools.cmake import CMake, cmake_layout import os class TestPackageConan(ConanFile): - settings = "os", "compiler", "build_type", "arch" - generators = "cmake", "cmake_find_package_multi" + settings = "os", "arch", "compiler", "build_type" + generators = "CMakeToolchain", "CMakeDeps", "VirtualRunEnv" + test_type = "explicit" + + def layout(self): + cmake_layout(self) + + def requirements(self): + self.requires(self.tested_reference_str) def build(self): cmake = CMake(self) @@ -12,6 +21,6 @@ def build(self): cmake.build() def test(self): - if not tools.cross_building(self): - bin_path = os.path.join("bin", "test_package") - self.run(bin_path, run_environment=True) + if can_run(self): + bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package") + self.run(bin_path, env="conanrun") diff --git a/recipes/khrplatform/all/test_v1_package/CMakeLists.txt b/recipes/khrplatform/all/test_v1_package/CMakeLists.txt new file mode 100644 index 0000000000000..0d20897301b68 --- /dev/null +++ b/recipes/khrplatform/all/test_v1_package/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.1) +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/khrplatform/all/test_v1_package/conanfile.py b/recipes/khrplatform/all/test_v1_package/conanfile.py new file mode 100644 index 0000000000000..38f4483872d47 --- /dev/null +++ b/recipes/khrplatform/all/test_v1_package/conanfile.py @@ -0,0 +1,17 @@ +from conans import ConanFile, CMake, tools +import os + + +class TestPackageConan(ConanFile): + settings = "os", "arch", "compiler", "build_type" + generators = "cmake", "cmake_find_package_multi" + + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() + + def test(self): + if not tools.cross_building(self): + bin_path = os.path.join("bin", "test_package") + self.run(bin_path, run_environment=True)