Skip to content

Commit

Permalink
Merge pull request #6 from Ultimaker/CURA-10951_gh_build_curapackage
Browse files Browse the repository at this point in the history
CURA-10951_gh_build_curapackage
  • Loading branch information
rburema authored Sep 8, 2023
2 parents 437150b + a9712b5 commit 07f0127
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 64 deletions.
19 changes: 0 additions & 19 deletions conandata.yml

This file was deleted.

106 changes: 70 additions & 36 deletions conanfile.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
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.files import copy

from conan.tools.cmake import CMakeToolchain, CMakeDeps, CMake, cmake_layout
from conan.tools.env import VirtualBuildEnv
from conan.tools.files import copy, AutoPackager
from conan.tools.microsoft import check_min_vs, is_msvc, is_msvc_static_runtime
from conan.tools.scm import Version

required_conan_version = ">=1.52.0"
required_conan_version = ">=1.56.0"


class ArcusConan(ConanFile):
Expand All @@ -23,8 +25,7 @@ class ArcusConan(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.7]@ultimaker/stable", "sipbuildtool/[>=0.2.4]@ultimaker/stable"

options = {
"shared": [True, False],
Expand All @@ -38,46 +39,75 @@ class ArcusConan(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 self.version is None:
self.version = self._umdefault_version()
if not self.version:
self.version = "5.3.0-alpha"

@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"))
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("protobuf/3.21.9", transitive_headers=True)
self.requires("arcus/(latest)@ultimaker/cura_10475")
self.requires("cpython/3.10.4") # Maybe place this in build_requirements as well
self.requires("zlib/1.2.12")

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["protobuf"].shared = True
if self.options.shared:
self.options.rm_safe("fPIC")
self.options["cpython"].shared = True
self.options["arcus"].shared = True

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

def generate(self):
# Generate the pyproject.toml
pp = self.python_requires["pyprojecttoolchain"].module.PyProjectToolchain(self)
pp.blocks["tool_sip_project"].values["sip_files_dir"] = Path("python").as_posix()
pp.blocks["tool_sip_project"].values["sip_files_dir"] = str(Path("python").as_posix())
pp.blocks["tool_sip_bindings"].values["name"] = "pyArcus"
pp.blocks["tool_sip_metadata"].values["name"] = "pyArcus"
pp.blocks["extra_sources"].values["headers"] = ["PythonMessage.h"]
pp.blocks["extra_sources"].values["sources"] = [Path("src", "PythonMessage.cpp").as_posix()]
pp.blocks["extra_sources"].values["sources"] = [str(Path("src", "PythonMessage.cpp").as_posix())]
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("\\", "/")
Expand All @@ -88,6 +118,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()
Expand All @@ -105,16 +138,17 @@ def build(self):
cmake.build()

def package(self):
for ext in (".pyi", ".so", ".lib", ".a", ".pyd"):
copy(self, f"pyArcus{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"pyArcus{ext}", self.build_folder, self.package_path.joinpath("bin"), keep_path = False)
copy(self, "*.h", self.source_path.joinpath("include"), self.package_path.joinpath("include"))
for ext in ("*.dll", "*.so", "*.dylib"):
copy(self, ext, src = self.build_folder, dst = path.join(self.package_folder, "bin"), keep_path = False)
copy(self, "*.h", path.join(self.source_folder, "include"), path.join(self.package_folder, "include"))

def package_info(self):
self.cpp_info.libdirs = [ os.path.join(self.package_folder, "lib")]
self.cpp_info.libdirs = [ path.join(self.package_folder, "lib")]
if self.in_local_cache:
self.runenv_info.append_path("PYTHONPATH", os.path.join(self.package_folder, "lib"))
self.runenv_info.append_path("PYTHONPATH", path.join(self.package_folder, "lib"))
else:
self.runenv_info.append_path("PYTHONPATH", self.build_folder)
25 changes: 16 additions & 9 deletions test_package/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,39 @@
from pathlib import Path

from conan import ConanFile
from conan.tools.build import cross_building
from conan.tools.files import copy
from conan.tools.build import can_run
from conan.tools.env import VirtualRunEnv
from conan.errors import ConanException
from conan.tools.files import copy


class ArcusTestConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "VirtualRunEnv"
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"))
shutil.copy(Path(self.source_folder).joinpath("test.proto"), Path(self.build_folder).joinpath("test.proto"))

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):
if can_run(self):
test_buf = StringIO()
self.run(f"python test.py", env = "conanrun", output = test_buf, run_environment=True)
ret_val = test_buf.getvalue()
Expand Down

0 comments on commit 07f0127

Please sign in to comment.