Repository: conan-io/conan-center-index

Issue:
[package] wiringpi/2.50: Broken in Conan v2
### Description

The wiringpi package is broken in Conan v2.


### Package and Environment Details

* Conan version 2.0.2
* cmake version 3.26.0-rc6


### Conan profile

[settings]
arch=x86_64
build_type=Release
compiler=gcc
compiler.cppstd=gnu17
compiler.libcxx=libstdc++11
compiler.version=11
os=Linux



### Steps to reproduce

conan install .

### Logs

ImportError: cannot import name 'ConanFile' from 'conans'


Discussion:

Resolving patch:
diff --git a/recipes/wiringpi/all/conanfile.py b/recipes/wiringpi/all/conanfile.py
--- a/recipes/wiringpi/all/conanfile.py
+++ b/recipes/wiringpi/all/conanfile.py
@@ -1,7 +1,10 @@
-from conans import ConanFile, CMake, tools
-from conans.errors import ConanInvalidConfiguration
+import os
+from conan import ConanFile
+from conan.errors import ConanInvalidConfiguration
+from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
+from conan.tools.files import get, copy
 
-required_conan_version = ">=1.33.0"
+required_conan_version = ">=1.53.0"
 
 class WiringpiConan(ConanFile):
     name = "wiringpi"
@@ -19,48 +22,41 @@ class WiringpiConan(ConanFile):
                        "fPIC": True,
                        "wpi_extensions": False,
                        "with_devlib": True}
-    exports_sources = ["CMakeLists.txt"]
-    generators = "cmake"
-    _cmake = None
-
-    @property
-    def _source_subfolder(self):
-        return "source_subfolder"
-
-    @property
-    def _build_subfolder(self):
-        return "build_subfolder"
+            
+    def export_sources(self):
+        copy(self, "CMakeLists.txt", self.recipe_folder, self.export_sources_folder)
 
     def configure(self):
         if self.options.shared:
-            del self.options.fPIC
-        del self.settings.compiler.libcxx
-        del self.settings.compiler.cppstd
+            self.options.rm_safe("fPIC")
+        self.settings.rm_safe("compiler.libcxx")
+        self.settings.rm_safe("compiler.cppstd")
 
     def validate(self):
         if self.settings.os != "Linux":
-            raise ConanInvalidConfiguration("{} only works for Linux.".format(self.name))
+            raise ConanInvalidConfiguration(f"{self.ref} only works for Linux")
 
-    def source(self):
-        tools.get(**self.conan_data["sources"][self.version],
-            destination=self._source_subfolder, strip_root=True)
+    def layout(self):
+        cmake_layout(self, src_folder="src")
 
-    def _configure_cmake(self):
-        if self._cmake:
-            return self._cmake
-        self._cmake = CMake(self)
-        self._cmake.definitions["WITH_WPI_EXTENSIONS"] = self.options.wpi_extensions
-        self._cmake.definitions["WITH_DEV_LIB"] = self.options.with_devlib
-        self._cmake.configure(build_folder=self._build_subfolder)
-        return self._cmake
+    def source(self):
+        get(self, **self.conan_data["sources"][self.version], strip_root=True)
+        
+    def generate(self):
+        tc = CMakeToolchain(self)
+        tc.variables["WIRINGPI_SRC_DIR"] = self.source_folder.replace("\\", "/")
+        tc.variables["WIRINGPI_WITH_WPI_EXTENSIONS"] = self.options.wpi_extensions
+        tc.variables["WIRINGPI_WITH_DEV_LIB"] = self.options.with_devlib
+        tc.generate()
 
     def build(self):
-        cmake = self._configure_cmake()
+        cmake = CMake(self)
+        cmake.configure(build_script_folder=os.path.join(self.source_folder, os.pardir))
         cmake.build()
 
     def package(self):
-        self.copy("COPYING*", src=self._source_subfolder, dst="licenses")
-        cmake = self._configure_cmake()
+        copy(self, pattern="COPYING*", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
+        cmake = CMake(self)
         cmake.install()
 
     def package_info(self):


Test patch:
diff --git a/recipes/wiringpi/all/test_package/CMakeLists.txt b/recipes/wiringpi/all/test_package/CMakeLists.txt
--- a/recipes/wiringpi/all/test_package/CMakeLists.txt
+++ b/recipes/wiringpi/all/test_package/CMakeLists.txt
@@ -1,9 +1,6 @@
 cmake_minimum_required(VERSION 3.1)
 project(test_package C)
 
-include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
-conan_basic_setup(TARGETS)
-
 find_package(wiringpi REQUIRED CONFIG)
 
 add_executable(test_package test_package.c)
diff --git a/recipes/wiringpi/all/test_package/conanfile.py b/recipes/wiringpi/all/test_package/conanfile.py
--- a/recipes/wiringpi/all/test_package/conanfile.py
+++ b/recipes/wiringpi/all/test_package/conanfile.py
@@ -1,17 +1,27 @@
 import os
-from conans import ConanFile, CMake, tools
 
+from conan import ConanFile
+from conan.tools.cmake import CMake, cmake_layout
+from conan.tools.build import can_run
 
-class TestConan(ConanFile):
+
+class wiringPiTestConan(ConanFile):
     settings = "os", "compiler", "build_type", "arch"
-    generators = "cmake", "cmake_find_package_multi"
+    generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv"
+    test_type = "explicit"
+
+    def requirements(self):
+        self.requires(self.tested_reference_str)
 
     def build(self):
         cmake = CMake(self)
         cmake.configure()
         cmake.build()
 
+    def layout(self):
+        cmake_layout(self)
+
     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/wiringpi/all/test_v1_package/CMakeLists.txt b/recipes/wiringpi/all/test_v1_package/CMakeLists.txt
new file mode 100644
--- /dev/null
+++ b/recipes/wiringpi/all/test_v1_package/CMakeLists.txt
@@ -0,0 +1,10 @@
+cmake_minimum_required(VERSION 3.1)
+project(test_package C)
+
+include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
+conan_basic_setup(TARGETS)
+
+find_package(wiringpi REQUIRED CONFIG)
+
+add_executable(test_package ../test_package/test_package.c)
+target_link_libraries(test_package wiringpi::wiringpi)
diff --git a/recipes/wiringpi/all/test_v1_package/conanfile.py b/recipes/wiringpi/all/test_v1_package/conanfile.py
new file mode 100644
--- /dev/null
+++ b/recipes/wiringpi/all/test_v1_package/conanfile.py
@@ -0,0 +1,17 @@
+import os
+from conans import ConanFile, CMake, tools
+
+
+class TestConan(ConanFile):
+    settings = "os", "compiler", "build_type", "arch"
+    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)