Skip to content

Commit

Permalink
Update Conanfile and test_package for Savitar
Browse files Browse the repository at this point in the history
The Conanfile for Savitar was expanded, refactored, and updated to use Conan's improved layout(), build(), and package() capabilities.
Importantly, the required Conan version was updated, the recipe and related tests were updated to support recent compilers, and overall code organization and standards were improved.
The legacy Conan code was also removed to improve readability and maintainability of the script. The test_package was updated to follow these changes.

Contributes to CURA-10951
  • Loading branch information
jellespijker committed Aug 29, 2023
1 parent d5c1c3f commit 7bbdb6e
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 40 deletions.
97 changes: 66 additions & 31 deletions conanfile.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
from os import path


from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.cmake import CMakeToolchain, CMakeDeps, CMake, cmake_layout
from conan.tools.files import AutoPackager
from conan.tools.env import VirtualBuildEnv
from conan.tools.files import AutoPackager, copy
from conan.tools.build import check_min_cppstd
from conan import ConanFile
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"

required_conan_version = ">=1.56.0"


class SavitarConan(ConanFile):
Expand All @@ -18,9 +26,6 @@ class SavitarConan(ConanFile):
exports = "LICENSE*"
generators = "CMakeDeps", "VirtualBuildEnv", "VirtualRunEnv"

python_requires = "umbase/[>=0.1.7]@ultimaker/stable"
python_requires_extend = "umbase.UMBaseConanfile"

options = {
"shared": [True, False],
"fPIC": [True, False],
Expand All @@ -31,55 +36,85 @@ class SavitarConan(ConanFile):
"fPIC": True,
"enable_testing": False
}
scm = {
"type": "git",
"subfolder": ".",
"url": "auto",
"revision": "auto"
}

def set_version(self):
if self.version is None:
self.version = self._umdefault_version()
self.version = "5.3.0-alpha"

def build_requirements(self):
if self.options.enable_testing:
for req in self._um_data()["build_requirements_testing"]:
self.test_requires(req)

@property
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, "src"), path.join(self.export_sources_folder, "src"))
copy(self, "*", path.join(self.recipe_folder, "include"), path.join(self.export_sources_folder, "include"))

def layout(self):
cmake_layout(self)
self.cpp.package.libs = ["Savitar"]

if self.settings.get_safe("build_type", "Release") == "Debug":
self.cpp.package.defines = ["SAVITAR_DEBUG"]

def requirements(self):
self.requires("standardprojectsettings/[>=0.1.0]@ultimaker/stable")
for req in self._um_data()["requirements"]:
self.requires(req)
self.requires("pugixml/1.12.1", transitive_headers=True)

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")
if self.options.enable_testing:
self.test_requires("gtest/1.12.1")

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["pugixml"].shared = self.options.shared

def validate(self):
if self.settings.compiler.get_safe("cppstd"):
check_min_cppstd(self, 17)
if self.options.shared:
self.options.rm_safe("fPIC")

def generate(self):
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["ENABLE_TESTING"] = self.options.enable_testing
tc.generate()

def layout(self):
cmake_layout(self)
self.cpp.package.libs = ["Savitar"]
tc = CMakeDeps(self)
tc.generate()

if self.settings.build_type == "Debug":
self.cpp.package.defines = ["SAVITAR_DEBUG"]
tc = VirtualBuildEnv(self)
tc.generate(scope="build")

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def package(self):
copy(self, pattern="LICENSE*", dst="licenses", src=self.source_folder)
packager = AutoPackager(self)
packager.run()
21 changes: 12 additions & 9 deletions test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import CMakeToolchain, CMakeDeps, CMake
from conan.tools.env import VirtualRunEnv
from conans import tools
from conan.tools.files import copy


class SavitarTestConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "VirtualRunEnv"
test_type = "explicit"

def requirements(self):
self.requires(self.tested_reference_str)

def generate(self):
cmake = CMakeDeps(self)
Expand All @@ -15,23 +20,21 @@ def generate(self):
venv = VirtualRunEnv(self)
venv.generate()

tc = CMakeToolchain(self, generator = "Ninja")
if self.settings.compiler == "Visual Studio":
tc.blocks["generic_system"].values["generator_platform"] = None
tc.blocks["generic_system"].values["toolset"] = None
tc = CMakeToolchain(self)
tc.generate()

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):
cmake = CMake(self)
cmake.configure()
cmake.build()

def imports(self):
if self.settings.os == "Windows" and not tools.cross_building(self, skip_x64_x86 = True):
self.copy("*.dll", dst=".", src="@bindirs")

def test(self):
if not tools.cross_building(self):
if can_run(self):
ext = ".exe" if self.settings.os == "Windows" else ""
prefix_path = "" if self.settings.os == "Windows" else "./"
self.run(f"{prefix_path}test{ext}", env = "conanrun")

0 comments on commit 7bbdb6e

Please sign in to comment.