Skip to content

Commit

Permalink
Refactor testing condition in conanfile.py
Browse files Browse the repository at this point in the history
The testing condition repeated across the script was abstracted into a property, _run_tests. This change simplifies the condition check for running tests, and specifically handles a case where the apple-clang compiler version is less or equal to version 14.

Contributes to CURA-10561
  • Loading branch information
jellespijker committed Oct 27, 2023
1 parent 758571c commit 9113cb6
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class DulcificumConan(ConanFile):
"shared": False,
"fPIC": True,
"enable_extensive_warnings": False,
"with_apps": True,
"with_apps": False,
"with_python_bindings": True,
}

Expand All @@ -57,6 +57,12 @@ def _compilers_minimum_version(self):
"visual_studio": "17",
}

@property
def _run_tests(self):
if self.settings.compiler == "apple-clang" and Version(self.settings.compiler.version) <= Version("14"):
return False
return not self.conf.get("tools.build:skip_test", False, check_type = bool)

def export_sources(self):
copy(self, "CMakeLists.txt", self.recipe_folder, self.export_sources_folder)
copy(self, "*", os.path.join(self.recipe_folder, "src"), os.path.join(self.export_sources_folder, "src"))
Expand Down Expand Up @@ -93,7 +99,7 @@ def requirements(self):

def build_requirements(self):
self.test_requires("standardprojectsettings/[>=0.1.0]@ultimaker/stable")
if not self.conf.get("tools.build:skip_test", False, check_type = bool):
if self._run_tests:
self.test_requires("gtest/[>=1.12.1]")

def validate(self):
Expand All @@ -111,7 +117,7 @@ def validate(self):

def generate(self):
tc = CMakeToolchain(self)
tc.variables["ENABLE_TESTS"] = not self.conf.get("tools.build:skip_test", False, check_type = bool)
tc.variables["ENABLE_TESTS"] = self._run_tests
tc.variables["EXTENSIVE_WARNINGS"] = self.options.enable_extensive_warnings
tc.variables["DULCIFICUM_VERSION"] = self.version

Expand Down Expand Up @@ -147,7 +153,7 @@ def generate(self):
copy(self, "*.dll", dep.cpp_info.libdirs[0], self.build_folder)
if len(dep.cpp_info.bindirs) > 0:
copy(self, "*.dll", dep.cpp_info.bindirs[0], self.build_folder)
if not self.conf.get("tools.build:skip_test", False, check_type = bool):
if self._run_tests:
test_path = os.path.join(self.build_folder, "tests")
if not os.path.exists(test_path):
mkdir(self, test_path)
Expand Down

0 comments on commit 9113cb6

Please sign in to comment.