Skip to content

Commit

Permalink
Use Conan v2
Browse files Browse the repository at this point in the history
Contributes to CURA-11079
  • Loading branch information
jellespijker committed Feb 12, 2024
1 parent 6220aaa commit f2fbfb4
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 78 deletions.
42 changes: 13 additions & 29 deletions .github/workflows/conan-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ on:
branches:
- main
- 'CURA-*'
- 'PP-*'
- 'NP-*'

permissions:
contents: read
Expand All @@ -30,9 +32,10 @@ jobs:
with:
PATTERNS: |
recipes/**/*.*
# FIXME: use main once merged
- name: Sync pip requirements
run: wget https://raw.githubusercontent.com/Ultimaker/cura-workflows/main/.github/workflows/requirements-runner.txt -O .github/workflows/requirements-runner.txt
run: wget https://raw.githubusercontent.com/Ultimaker/cura-workflows/CURA-11622_conan_v2/.github/workflows/requirements-runner.txt -O .github/workflows/requirements-runner.txt

- name: Setup Python and pip
uses: actions/setup-python@v4
Expand All @@ -44,38 +47,19 @@ jobs:
- name: Install Python requirements and Create default Conan profile
run: pip install -r .github/workflows/requirements-runner.txt

- name: Setup pipeline caches
run: |
mkdir -p /home/runner/.conan/downloads
mkdir -p /home/runner/.conan/data
- name: Create default Conan profile
run: conan profile new default --detect
run: conan profile detect -f

# FIXME: use runner.os/runner.arch after merge: conan config install https://github.com/Ultimaker/conan-config.git -a "-b runner/runner.os/runner.arch"
- name: Get Conan configuration
run: |
conan config install https://github.com/Ultimaker/conan-config.git
conan config install https://github.com/Ultimaker/conan-config.git -a "-b runner/${{ runner.os }}/${{ runner.arch }}"
- name: Cache Conan packages
uses: actions/cache@v3
with:
path: /home/runner/.conan/data
key: ${{ runner.os }}-conan-data-${{ github.run_id }}
restore-keys: |
${{ runner.os }}-conan-data-
- name: Cache Conan downloads
uses: actions/cache@v3
with:
path: /home/runner/.conan/downloads
key: ${{ runner.os }}-conan-downloads-${{ github.run_id }}
restore-keys: |
${{ runner.os }}-conan-downloads-
conan config install https://github.com/Ultimaker/conan-config.git -a "-b CURA-11622_conan_v2"
conan remote login -p ${{ secrets.CONAN_PASS }} cura-conan-v2 ${{ secrets.CONAN_USER }}
#conan remote disable cura-private
# TODO: Change to main once merged
# TODO: Change to main once merged
- name: Export changed recipes
run: |
mkdir runner_scripts
wget https://raw.githubusercontent.com/Ultimaker/cura-workflows/main/runner_scripts/upload_conan_recipes.py -O runner_scripts/upload_conan_recipes.py
python runner_scripts/upload_conan_recipes.py --user ultimaker --branch ${{ github.ref_name }} --remote cura ${{ env.GIT_DIFF_FILTERED }}
wget https://raw.githubusercontent.com/Ultimaker/cura-workflows/CURA-11622_conan_v2/runner_scripts/upload_conan_recipes.py -O runner_scripts/upload_conan_recipes.py
python runner_scripts/upload_conan_recipes.py --user ultimaker --branch ${{ github.ref_name }} --remote cura-conan-v2 ${{ env.GIT_DIFF_FILTERED }}
5 changes: 2 additions & 3 deletions recipes/clipper/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from io import StringIO
import os
from shutil import which

from conan import ConanFile
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, rmdir
from conan.errors import ConanInvalidConfiguration
from conans.tools import which
import os

required_conan_version = ">=1.54.0"

Expand Down
40 changes: 23 additions & 17 deletions recipes/pyprojecttoolchain/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
from conan.tools.gnu.autotoolstoolchain import AutotoolsToolchain
from conan.tools.files import save
from conan.errors import ConanInvalidConfiguration
from conan.tools._check_build_profile import check_using_build_profile
from conans.tools import Version
from conan.tools.scm import Version
from conan.tools import CppInfo


class BuildSystemBlock(Block):
Expand Down Expand Up @@ -55,8 +55,8 @@ def context(self):

mod_version = Version(self._conanfile.version)
pypi_version = f"{mod_version.major}.{mod_version.minor}.{mod_version.patch}"
if mod_version.prerelease != "":
split_prerelease = mod_version.prerelease.split(".")
if mod_version.pre != "":
split_prerelease = str(mod_version.pre).split(".")
if len(split_prerelease) > 1:
pypi_version += f"{split_prerelease[0][0]}{split_prerelease[1]}"
else:
Expand Down Expand Up @@ -89,10 +89,11 @@ def context(self):

if py_lib_dir is None:
try:
py_lib_dir = Path(self._conanfile.deps_cpp_info['cpython'].rootpath, self._conanfile.deps_cpp_info['cpython'].components["python"].bindirs[0], "libs").as_posix()
py_lib = self._conanfile.deps_cpp_info['cpython'].libs[0]
cpython_cpp = self._conanfile.dependencies["cpython"].cpp_info
py_lib_dir = Path(cpython_cpp.components["python"].libdirs[0]).as_posix()
py_lib = cpython_cpp.components["python"].libs[0]
except:
self._conanfile.output.warn(
self._conanfile.output.warning(
"No include directory set for Python.h, either add the options: 'py_include' of add cpython as a Conan dependency!")
else:
py_lib_dir = Path(py_lib_dir).as_posix()
Expand Down Expand Up @@ -128,7 +129,7 @@ def context(self):
try:
python_version = self._conanfile.dependencies["cpython"].ref.version
except:
self._conanfile.output.warn(
self._conanfile.output.warning(
"No minimum required Python version specified, either add the options: 'py_version' of add cpython as a Conan dependency!")

if python_version is not None:
Expand All @@ -137,12 +138,11 @@ def context(self):
if py_include_dir is None:
try:
header_path = "" if self._conanfile.settings.os == "Windows" else f"python{py_version.major}.{py_version.minor}"
py_include_dir = Path(self._conanfile.deps_cpp_info['cpython'].rootpath,
self._conanfile.deps_cpp_info['cpython'].components["python"].includedirs[0],
header_path).as_posix()
cpython_cpp = self._conanfile.dependencies["cpython"].cpp_info
py_include_dir = Path(cpython_cpp.components["python"].includedirs[0], header_path).as_posix()
py_include_dir = f"py-include-dir = \"{py_include_dir}\""
except:
self._conanfile.output.warn(
self._conanfile.output.warning(
"No include directory set for Python.h, either add the options: 'py_include' of add cpython as a Conan dependency!")
else:
py_include_dir = f"py-include-dir = \"{Path(py_include_dir).as_posix()}\""
Expand Down Expand Up @@ -210,13 +210,19 @@ class ToolSipBindingsBlock(Block):

def context(self):
settings = self._conanfile.settings
deps_cpp_info = self._conanfile.deps_cpp_info
aggregated_cpp_info = CppInfo(self._conanfile)
deps = self._conanfile.dependencies.host.topological_sort
deps = [dep for dep in reversed(deps.values())]
for dep in deps:
dep_cppinfo = dep.cpp_info.aggregated_components()
aggregated_cpp_info.merge(dep_cppinfo)

build_type = settings.get_safe("build_type", "Release")
shared = settings.get_safe("shared", True)

libs = deps_cpp_info.libs
libdirs = [Path(d).as_posix() for d in deps_cpp_info.libdirs]
includedirs = [Path(d).as_posix() for d in deps_cpp_info.includedirs]
libs = aggregated_cpp_info.libs
libdirs = [Path(d).as_posix() for d in aggregated_cpp_info.libdirs]
includedirs = [Path(d).as_posix() for d in aggregated_cpp_info.includedirs]
if self._conanfile.cpp.source.includedirs:
includedirs.extend(self._conanfile.cpp.source.includedirs)

Expand All @@ -243,7 +249,6 @@ class PyProjectToolchain(AutotoolsToolchain):

def __init__(self, conanfile: ConanFile, namespace = None):
super().__init__(conanfile, namespace)
check_using_build_profile(self._conanfile)

blocks = [
("build_system", BuildSystemBlock),
Expand Down Expand Up @@ -283,3 +288,4 @@ def generate(self, env = None, scope = "build"):

class PyProjectToolchainPkg(ConanFile):
name = "pyprojecttoolchain"
package_type = "build-scripts"
14 changes: 9 additions & 5 deletions recipes/sipbuildtool/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import os

from conan import ConanFile
from conans import tools
from conan.tools.files import chdir, copy

from conans.client.subsystems import subsystem_path, deduce_subsystem


Expand All @@ -16,29 +17,32 @@ class SipBuildTool(object):
sip.configure()
sip.generate("projectName")
"""

def __init__(self, conanfile: ConanFile):
self._conanfile = conanfile
self._sip_install_executable = "sip-build"

def configure(self, sip_install_executable = None):
def configure(self, sip_install_executable=None):
if sip_install_executable:
self._sip_install_executable = sip_install_executable

def build(self):
with tools.chdir(self._conanfile.source_folder):
with chdir(self, self._conanfile.source_folder):
sip_cmd = self._sip_install_executable
subsystem = deduce_subsystem(self._conanfile, scope = "build")
subsystem = deduce_subsystem(self._conanfile, scope="build")
sip_cmd = subsystem_path(subsystem, sip_cmd)
cmd = '"{}"'.format(sip_cmd)
self._conanfile.output.info(f"Calling:\n > {cmd}")
self._conanfile.run(cmd)


class Pkg(ConanFile):
name = "sipbuildtool"
package_type = "build-scripts"
exports_sources = "SIPMacros.cmake"

def package(self):
self.copy("SIPMacros.cmake", "cmake")
copy(self, pattern="*.cmake", src=self.export_sources_folder, dst=os.path.join(self.package_folder, "cmake"))

def package_info(self):
self.cpp_info.set_property("name", "sip")
Expand Down
Loading

0 comments on commit f2fbfb4

Please sign in to comment.