Skip to content

Commit 421f4fa

Browse files
dvirtzuilianries
andauthored
(#13973) polymorphic_value: conan v2 support
* polymorphic_value: conan v2 support done as part of @prince-chrismc's webinar * apply review suggestions * work around self.info being already cleared see conan-io/conan#12210 * use conan.tools.build.can_run * Revert "work around self.info being already cleared" This reverts commit 84f85e4. * Apply suggestions from code review Co-authored-by: Uilian Ries <[email protected]> * align test package to templates Co-authored-by: Uilian Ries <[email protected]>
1 parent 2b248ac commit 421f4fa

File tree

5 files changed

+72
-27
lines changed

5 files changed

+72
-27
lines changed
Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1-
from conans import ConanFile, tools
2-
from conans.errors import ConanInvalidConfiguration
1+
import os
32

4-
required_conan_version = ">=1.43.0"
3+
from conan import ConanFile
4+
from conan.errors import ConanInvalidConfiguration
5+
from conan.tools.build import check_min_cppstd
6+
from conan.tools.files import copy, get
7+
from conan.tools.layout import basic_layout
8+
from conan.tools.scm import Version
9+
10+
required_conan_version = ">=1.50.0"
511

612

713
class PolymorphictValueConan(ConanFile):
@@ -14,10 +20,6 @@ class PolymorphictValueConan(ConanFile):
1420
settings = "os", "arch", "compiler", "build_type"
1521
no_copy_source = True
1622

17-
@property
18-
def _source_subfolder(self):
19-
return "source_subfolder"
20-
2123
@property
2224
def _minimum_cpp_standard(self):
2325
return 17
@@ -32,16 +34,16 @@ def _minimum_compilers_version(self):
3234
}
3335

3436
def validate(self):
35-
if self.settings.compiler.get_safe("cppstd"):
36-
tools.check_min_cppstd(self, self._minimum_cpp_standard)
37+
if self.settings.get_safe("compiler.cppstd"):
38+
check_min_cppstd(self, self._minimum_cpp_standard)
3739
min_version = self._minimum_compilers_version.get(
3840
str(self.settings.compiler))
3941
if not min_version:
40-
self.output.warn("{} recipe lacks information about the {} "
41-
"compiler support.".format(
42-
self.name, self.settings.compiler))
42+
self.output.warning("{} recipe lacks information about the {} "
43+
"compiler support.".format(
44+
self.name, self.settings.compiler))
4345
else:
44-
if tools.Version(self.settings.compiler.version) < min_version:
46+
if Version(self.settings.compiler.version) < min_version:
4547
raise ConanInvalidConfiguration(
4648
"{} requires C++{} support. "
4749
"The current compiler {} {} does not support it.".format(
@@ -50,20 +52,24 @@ def validate(self):
5052
self.settings.compiler.version))
5153

5254
def package_id(self):
53-
self.info.header_only()
55+
self.info.clear()
56+
57+
def layout(self):
58+
basic_layout(self, src_folder="src")
5459

5560
def source(self):
56-
tools.get(**self.conan_data["sources"][self.version],
57-
strip_root=True, destination=self._source_subfolder)
61+
get(self, **self.conan_data["sources"][self.version], strip_root=True)
5862

5963
def package(self):
60-
self.copy(pattern="polymorphic_value.*", dst="include",
61-
src=self._source_subfolder)
62-
self.copy("*LICENSE*", dst="licenses", keep_path=False)
64+
copy(self, "polymorphic_value.*", self.source_folder,
65+
os.path.join(self.package_folder, "include"))
66+
copy(self, "*LICENSE*", self.source_folder,
67+
os.path.join(self.package_folder, "licenses"), keep_path=False)
6368

6469
def package_info(self):
6570
self.cpp_info.set_property("cmake_file_name", "polymorphic_value")
66-
self.cpp_info.set_property("cmake_target_name", "polymorphic_value::polymorphic_value")
71+
self.cpp_info.set_property(
72+
"cmake_target_name", "polymorphic_value::polymorphic_value")
6773

6874
self.cpp_info.names["cmake_find_package"] = "polymorphic_value"
6975
self.cpp_info.names["cmake_find_package_multi"] = "polymorphic_value"

recipes/polymorphic_value/all/test_package/CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
cmake_minimum_required(VERSION 3.12)
22
project(test_package CXX)
33

4-
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
5-
conan_basic_setup(TARGETS)
6-
74
find_package(polymorphic_value REQUIRED CONFIG)
85

96
add_executable(${PROJECT_NAME} test_package.cpp)
Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,27 @@
1-
from conans import ConanFile, CMake, tools
21
import os
32

3+
from conan import ConanFile
4+
from conan.tools.build import can_run
5+
from conan.tools.cmake import CMake, cmake_layout
6+
47

58
class TestPackageConan(ConanFile):
69
settings = "os", "arch", "compiler", "build_type"
7-
generators = "cmake", "cmake_find_package_multi"
10+
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv"
11+
test_type = "explicit"
12+
13+
def requirements(self):
14+
self.requires(self.tested_reference_str)
15+
16+
def layout(self):
17+
cmake_layout(self)
818

919
def build(self):
1020
cmake = CMake(self)
1121
cmake.configure()
1222
cmake.build()
1323

1424
def test(self):
15-
if not tools.cross_building(self):
16-
self.run(os.path.join("bin", "test_package"), run_environment=True)
25+
if can_run(self):
26+
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
27+
self.run(bin_path, env="conanrun")
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
cmake_minimum_required(VERSION 3.12)
2+
project(test_package CXX)
3+
4+
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
5+
conan_basic_setup(TARGETS)
6+
7+
find_package(polymorphic_value REQUIRED CONFIG)
8+
9+
add_executable(${PROJECT_NAME} ../test_package/test_package.cpp)
10+
target_link_libraries(${PROJECT_NAME} PRIVATE polymorphic_value::polymorphic_value)
11+
target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_20)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import os
2+
3+
from conan.tools.build import cross_building
4+
from conans import CMake, ConanFile
5+
6+
7+
# legacy validation with Conan 1.x
8+
class TestPackageV1Conan(ConanFile):
9+
settings = "os", "arch", "compiler", "build_type"
10+
generators = "cmake", "cmake_find_package_multi"
11+
12+
def build(self):
13+
cmake = CMake(self)
14+
cmake.configure()
15+
cmake.build()
16+
17+
def test(self):
18+
if not cross_building(self):
19+
bin_path = os.path.join("bin", "test_package")
20+
self.run(bin_path, run_environment=True)

0 commit comments

Comments
 (0)