Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CURA-10951_gh_build_curapackage #29

Merged
merged 7 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions conandata.yml

This file was deleted.

88 changes: 61 additions & 27 deletions conanfile.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
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"

required_conan_version = ">=1.56.0"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per your own writeup, which mentions 1.57 and smaller as divergent in behaviour from what we've done for the repo's now, shouldn't this be >=1.58.0 instead?

You wrote:

... because conan <= 1.57 didn't create the build folder before the sip-build was run, ...

(Or maybe you're building this one still in the 'old' way, so we don't have to do that -- I'll look further.)



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

options = {
"shared": [True, False],
Expand All @@ -37,43 +42,68 @@ 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 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, "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/(latest)@ultimaker/cura_10951")
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):
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"] = 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then remove it? ;-)

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("\\", "/")
Expand All @@ -84,6 +114,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 @@ -101,11 +134,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")]
Expand Down
23 changes: 15 additions & 8 deletions test_package/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
Loading