From 1e16d865ce8f93ded6baec786e822d35af2ec9b0 Mon Sep 17 00:00:00 2001 From: Jelle Spijker Date: Tue, 29 Aug 2023 09:02:29 +0200 Subject: [PATCH 1/7] Update build and test environment in conanfile.py Conan test and build environment configuration has been revised and optimized. The commit includes changes in imports, dependencies, defining build requirements, generating virtual environments etc. Amended to support more strongly typed Conan feature, supporting cross-compilation, improving auto-detection settings for compiler abilities, and improving overall Conanfile structure. This change aims to improve build performance, reduce potential issues and make the project more maintainable. contributes to CURA-10951 --- conanfile.py | 75 ++++++++++++++++++++++++++++++--------- test_package/conanfile.py | 23 +++++++----- 2 files changed, 74 insertions(+), 24 deletions(-) diff --git a/conanfile.py b/conanfile.py index 841ad36..48b2c82 100644 --- a/conanfile.py +++ b/conanfile.py @@ -1,11 +1,17 @@ import os from pathlib import Path +from os import path from conan import ConanFile +from conan.errors import ConanInvalidConfiguration from conan.tools.build import check_min_cppstd from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout +from conan.tools.env import VirtualBuildEnv from conan.tools.files import copy, mkdir +from conan.tools.microsoft import check_min_vs, is_msvc, is_msvc_static_runtime +from conan.tools.scm import Version + required_conan_version = ">=1.50.0" @@ -22,8 +28,7 @@ class PyNest2DConan(ConanFile): exports = "LICENSE*" generators = "CMakeDeps", "VirtualBuildEnv", "VirtualRunEnv" - python_requires = "umbase/[>=0.1.7]@ultimaker/stable", "pyprojecttoolchain/[>=0.1.6]@ultimaker/stable", "sipbuildtool/[>=0.2.3]@ultimaker/stable" - python_requires_extend = "umbase.UMBaseConanfile" + python_requires = "pyprojecttoolchain/[>=0.1.6]@ultimaker/stable", "sipbuildtool/[>=0.2.4]@ultimaker/stable" options = { "shared": [True, False], @@ -45,21 +50,52 @@ class PyNest2DConan(ConanFile): } def set_version(self): - if self.version is None: - self.version = self._umdefault_version() + if not self.version: + self.version = "5.3.0-alpha" + + def _min_cppstd(self): + return 17 + + @property + def _compilers_minimum_version(self): + return { + "gcc": "9", + "clang": "9", + "apple-clang": "9", + "msvc": "192", + "visual_studio": "14", + } + + def export_sources(self): + copy(self, "CMakeLists.txt", self.recipe_folder, self.export_sources_folder) + copy(self, "*", path.join(self.recipe_folder, "python"), path.join(self.export_sources_folder, "python")) def requirements(self): - self.requires("standardprojectsettings/[>=0.1.0]@ultimaker/stable") # required for the CMake build modules - self.requires("sipbuildtool/[>=0.2.3]@ultimaker/stable") # required for the CMake build modules - for req in self._um_data()["requirements"]: - self.requires(req) + self.requires("nest2d/5.2.2") + self.requires("cpython/3.10.4") + + def validate(self): + if self.settings.compiler.cppstd: + check_min_cppstd(self, self._min_cppstd) + check_min_vs(self, 192) # TODO: remove in Conan 2.0 + if not is_msvc(self): + minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), False) + if minimum_version and Version(self.settings.compiler.version) < minimum_version: + raise ConanInvalidConfiguration( + f"{self.ref} requires C++{self._min_cppstd}, which your compiler does not support." + ) + + def build_requirements(self): + self.test_requires("standardprojectsettings/[>=0.1.0]@ultimaker/stable") + self.test_requires("sipbuildtool/[>=0.2.4]@ultimaker/stable") def config_options(self): - if self.options.shared and self.settings.compiler == "Visual Studio": + if self.settings.os == "Windows": del self.options.fPIC def configure(self): - self.options["nest2d"].shared = self.options.shared + if self.options.shared: + self.options.rm_safe("fPIC") self.options["cpython"].shared = True def validate(self): @@ -68,12 +104,15 @@ def validate(self): def generate(self): pp = self.python_requires["pyprojecttoolchain"].module.PyProjectToolchain(self) - pp.blocks["tool_sip_project"].values["sip_files_dir"] = Path("python").as_posix() - mkdir(self, self.build_path) # FIXME: bad, this should not be necessary + pp.blocks["tool_sip_project"].values["sip_files_dir"] = str(Path("python").as_posix()) + # mkdir(self, self.build_path) # FIXME: bad, this should not be necessary pp.blocks.remove("extra_sources") pp.generate() tc = CMakeToolchain(self) + if is_msvc(self): + tc.variables["USE_MSVC_RUNTIME_LIBRARY_DLL"] = not is_msvc_static_runtime(self) + tc.cache_variables["CMAKE_POLICY_DEFAULT_CMP0077"] = "NEW" tc.variables["Python_EXECUTABLE"] = self.deps_user_info["cpython"].python.replace("\\", "/") tc.variables["Python_USE_STATIC_LIBS"] = not self.options["cpython"].shared tc.variables["Python_ROOT_DIR"] = self.deps_cpp_info["cpython"].rootpath.replace("\\", "/") @@ -84,6 +123,9 @@ def generate(self): tc.variables["Python_SITEARCH"] = "site-packages" tc.generate() + vb = VirtualBuildEnv(self) + vb.generate(scope="build") + # Generate the Source code from SIP sip = self.python_requires["sipbuildtool"].module.SipBuildTool(self) sip.configure() @@ -101,11 +143,12 @@ def build(self): cmake.build() def package(self): - for ext in (".pyi", ".so", ".lib", ".a", ".pyd"): - copy(self, f"pynest2d{ext}", self.build_folder, self.package_path.joinpath("lib"), keep_path = False) + copy(self, pattern="LICENSE*", dst="licenses", src=self.source_folder) + for ext in ("*.pyi", "*.so", "*.lib", "*.a", "*.pyd"): + copy(self, ext, src = self.build_folder, dst = path.join(self.package_folder, "lib"), keep_path = False) - for ext in (".dll", ".so", ".dylib"): - copy(self, f"pynest2d{ext}", self.build_folder, self.package_path.joinpath("bin"), keep_path = False) + for ext in ("*.dll", "*.so", "*.dylib"): + copy(self, ext, src = self.build_folder, dst = path.join(self.package_folder, "bin"), keep_path = False) def package_info(self): self.cpp_info.libdirs = [ os.path.join(self.package_folder, "lib")] diff --git a/test_package/conanfile.py b/test_package/conanfile.py index ee1c3f1..23992bd 100644 --- a/test_package/conanfile.py +++ b/test_package/conanfile.py @@ -4,29 +4,36 @@ from conan import ConanFile from conan.tools.env import VirtualRunEnv -from conan.tools.build import cross_building +from conan.tools.build import can_run from conan.errors import ConanException +from conan.tools.files import copy class PyNest2DTestConan(ConanFile): settings = "os", "compiler", "build_type", "arch" generators = "VirtualRunEnv" + test_type = "explicit" + + def requirements(self): + self.requires(self.tested_reference_str) def generate(self): venv = VirtualRunEnv(self) venv.generate() + cpp_info = self.dependencies[self.tested_reference_str].cpp_info + copy(self, "*.pyd", src = cpp_info.libdirs[0], dst =self.build_folder) + + for dep in self.dependencies.values(): + for bin_dir in dep.cpp_info.bindirs: + copy(self, "*.dll", src = bin_dir, dst = self.build_folder) + def build(self): - if not cross_building(self): + if can_run(self): shutil.copy(Path(self.source_folder).joinpath("test.py"), Path(self.build_folder).joinpath("test.py")) - def imports(self): - if self.settings.os == "Windows" and not cross_building(self): - self.copy("*.dll", dst=".", src="@bindirs") - self.copy("*.pyd", dst=".", src="@libdirs") - def test(self): - if not cross_building(self, skip_x64_x86 = True): + if can_run(self): test_buf = StringIO() self.run(f"python test.py", env = "conanrun", output = test_buf) if "True" not in test_buf.getvalue(): From 96fb8a4765669d650698328d9b77dc0a920f17d3 Mon Sep 17 00:00:00 2001 From: Jelle Spijker Date: Tue, 29 Aug 2023 09:05:21 +0200 Subject: [PATCH 2/7] no longer a use for conandata requirements are specified in conanfile.py directly contributes to CURA-10951 --- conandata.yml | 20 -------------------- 1 file changed, 20 deletions(-) delete mode 100644 conandata.yml diff --git a/conandata.yml b/conandata.yml deleted file mode 100644 index a98105a..0000000 --- a/conandata.yml +++ /dev/null @@ -1,20 +0,0 @@ -"5.3.0-alpha": - requirements: - - "nest2d/5.2.2" - - "cpython/3.10.4" -"5.2.2": - requirements: - - "nest2d/5.2.2" - - "cpython/3.10.4" -"5.2.0": - requirements: - - "nest2d/5.2.0" - - "cpython/3.10.4" -"5.2.0-alpha": - requirements: - - "nest2d/(latest)@ultimaker/testing" - - "cpython/3.10.4" -"5.1.0": - requirements: - - "libnest2d/5.1.0" - - "cpython/3.10.4" From e8ea70d5c90f35a3c1c32791fa36eb0cc753cd11 Mon Sep 17 00:00:00 2001 From: Jelle Spijker Date: Tue, 29 Aug 2023 09:06:43 +0200 Subject: [PATCH 3/7] bump up minimum versions contributes to CURA-10951 --- conanfile.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/conanfile.py b/conanfile.py index 48b2c82..fb3f93f 100644 --- a/conanfile.py +++ b/conanfile.py @@ -13,7 +13,7 @@ from conan.tools.scm import Version -required_conan_version = ">=1.50.0" +required_conan_version = ">=1.56.0" class PyNest2DConan(ConanFile): @@ -28,7 +28,7 @@ class PyNest2DConan(ConanFile): exports = "LICENSE*" generators = "CMakeDeps", "VirtualBuildEnv", "VirtualRunEnv" - python_requires = "pyprojecttoolchain/[>=0.1.6]@ultimaker/stable", "sipbuildtool/[>=0.2.4]@ultimaker/stable" + python_requires = "pyprojecttoolchain/[>=0.1.7]@ultimaker/stable", "sipbuildtool/[>=0.2.4]@ultimaker/stable" options = { "shared": [True, False], From 64b2dd7f51b4f2b6caa3e91a462863ab4a0d97be Mon Sep 17 00:00:00 2001 From: Jelle Spijker Date: Tue, 29 Aug 2023 09:08:35 +0200 Subject: [PATCH 4/7] removed duplicate validate method contributes to CURA-10951 --- conanfile.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/conanfile.py b/conanfile.py index fb3f93f..e0f1fe8 100644 --- a/conanfile.py +++ b/conanfile.py @@ -98,10 +98,6 @@ def configure(self): self.options.rm_safe("fPIC") self.options["cpython"].shared = True - def validate(self): - if self.settings.compiler.get_safe("cppstd"): - check_min_cppstd(self, 17) - def generate(self): pp = self.python_requires["pyprojecttoolchain"].module.PyProjectToolchain(self) pp.blocks["tool_sip_project"].values["sip_files_dir"] = str(Path("python").as_posix()) From 51227ebe4f54b1dcffaa964d68417195d5eaabd4 Mon Sep 17 00:00:00 2001 From: Jelle Spijker Date: Tue, 29 Aug 2023 09:12:37 +0200 Subject: [PATCH 5/7] removed redundant scm atrribute no longer used in conan 2.0 contributes to CURA-10951 --- conanfile.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/conanfile.py b/conanfile.py index e0f1fe8..ac749c0 100644 --- a/conanfile.py +++ b/conanfile.py @@ -42,12 +42,6 @@ class PyNest2DConan(ConanFile): "py_build_requires": '"sip >=6, <7", "setuptools>=40.8.0", "wheel"', "py_build_backend": "sipbuild.api", } - scm = { - "type": "git", - "subfolder": ".", - "url": "auto", - "revision": "auto" - } def set_version(self): if not self.version: From 87ab45a580a1ded06640196e380522a363835ef7 Mon Sep 17 00:00:00 2001 From: Jelle Spijker Date: Tue, 29 Aug 2023 09:24:27 +0200 Subject: [PATCH 6/7] make min_cppstd a property contributes to CURA-10951 --- conanfile.py | 1 + 1 file changed, 1 insertion(+) diff --git a/conanfile.py b/conanfile.py index ac749c0..a5cd9c4 100644 --- a/conanfile.py +++ b/conanfile.py @@ -47,6 +47,7 @@ def set_version(self): if not self.version: self.version = "5.3.0-alpha" + @property def _min_cppstd(self): return 17 From 44e0191ed007cb526969f824665779beb079f1f8 Mon Sep 17 00:00:00 2001 From: Jelle Spijker Date: Tue, 29 Aug 2023 11:30:24 +0200 Subject: [PATCH 7/7] Use libnest2d from CURA-10951 contributes to CURA-10951 --- conanfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conanfile.py b/conanfile.py index a5cd9c4..8fb8b18 100644 --- a/conanfile.py +++ b/conanfile.py @@ -66,7 +66,7 @@ def export_sources(self): copy(self, "*", path.join(self.recipe_folder, "python"), path.join(self.export_sources_folder, "python")) def requirements(self): - self.requires("nest2d/5.2.2") + self.requires("nest2d/(latest)@ultimaker/cura_10951") self.requires("cpython/3.10.4") def validate(self):