From 987543d09634c401407ef7e8b5008039cc92e6b2 Mon Sep 17 00:00:00 2001 From: Jelle Spijker Date: Mon, 12 Feb 2024 11:54:32 +0100 Subject: [PATCH] Use Conan v2 Contributes to CURA-11622 --- .github/workflows/conan-package.yml | 97 +++++++++++++++++------------ .gitignore | 8 +++ conandata.yml | 2 +- conanfile.py | 60 +++++++++--------- test_package/conanfile.py | 13 +--- 5 files changed, 102 insertions(+), 78 deletions(-) diff --git a/.github/workflows/conan-package.yml b/.github/workflows/conan-package.yml index 9aa6004..a638e00 100644 --- a/.github/workflows/conan-package.yml +++ b/.github/workflows/conan-package.yml @@ -6,54 +6,73 @@ on: - 'src/**' - 'test_package/**' - 'include/**' - - 'cmake/**' - 'conanfile.py' - 'CMakeLists.txt' - '.github/workflows/conan-package.yml' - '.github/workflows/requirements*' - 'conandata.yml' - - '.gitattributes' branches: - - main - - 'CURA-*' - - 'PP-*' - - '[0-9].[0-9]*' - - '[0-9].[0-9][0-9]*' + - main + - 'CURA-*' + - 'PP-*' + - 'NP-*' + - '[0-9].[0-9]*' + - '[0-9].[0-9][0-9]*' jobs: - conan-recipe-version: - uses: ultimaker/cura-workflows/.github/workflows/conan-recipe-version.yml@main - with: - project_name: pyarcus + # FIXME: Use main once merged + conan-recipe-version: + uses: ultimaker/cura-workflows/.github/workflows/conan-recipe-version.yml@CURA-11622_conan_v2 + with: + project_name: pyarcus - conan-package-export: - needs: [ conan-recipe-version ] - uses: ultimaker/cura-workflows/.github/workflows/conan-recipe-export.yml@main - with: - recipe_id_full: ${{ needs.conan-recipe-version.outputs.recipe_id_full }} - recipe_id_latest: ${{ needs.conan-recipe-version.outputs.recipe_id_latest }} - secrets: inherit + # FIXME: Use main once merged + conan-package-export: + needs: [ conan-recipe-version ] + uses: ultimaker/cura-workflows/.github/workflows/conan-recipe-export.yml@CURA-11622_conan_v2 + with: + recipe_id_name: ${{ needs.conan-recipe-version.outputs.project_name }} + recipe_id_version: ${{ needs.conan-recipe-version.outputs.recipe_semver_full }} + recipe_id_user: ${{ needs.conan-recipe-version.outputs.user }} + recipe_id_channel: ${{ needs.conan-recipe-version.outputs.channel }} + recipe_id_full: ${{ needs.conan-recipe-version.outputs.recipe_id_full }} + secrets: inherit - conan-package-create-macos: - needs: [ conan-recipe-version, conan-package-export ] - if: ${{ (github.event_name == 'push' && (github.ref_name == 'main' || github.ref_name == 'master' || needs.conan-recipe-version.outputs.is_release_branch == 'true')) }} - uses: ultimaker/cura-workflows/.github/workflows/conan-package-create-macos.yml@main - with: - recipe_id_full: ${{ needs.conan-recipe-version.outputs.recipe_id_full }} - secrets: inherit + # FIXME: Use main once merged + conan-package-create-macos: + needs: [ conan-recipe-version, conan-package-export ] + if: ${{ (github.event_name == 'push' && (github.ref_name == 'main' || github.ref_name == 'master' || needs.conan-recipe-version.outputs.is_release_branch == 'true')) }} + uses: ultimaker/cura-workflows/.github/workflows/conan-package-create-macos.yml@CURA-11622_conan_v2 + with: + recipe_id_name: ${{ needs.conan-recipe-version.outputs.project_name }} + recipe_id_version: ${{ needs.conan-recipe-version.outputs.recipe_semver_full }} + recipe_id_user: ${{ needs.conan-recipe-version.outputs.user }} + recipe_id_channel: ${{ needs.conan-recipe-version.outputs.channel }} + recipe_id_full: ${{ needs.conan-recipe-version.outputs.recipe_id_full }} + secrets: inherit - conan-package-create-windows: - needs: [ conan-recipe-version, conan-package-export ] - if: ${{ (github.event_name == 'push' && (github.ref_name == 'main' || github.ref_name == 'master' || needs.conan-recipe-version.outputs.is_release_branch == 'true')) }} - uses: ultimaker/cura-workflows/.github/workflows/conan-package-create-windows.yml@main - with: - recipe_id_full: ${{ needs.conan-recipe-version.outputs.recipe_id_full }} - secrets: inherit + # FIXME: Use main once merged + conan-package-create-windows: + needs: [ conan-recipe-version, conan-package-export ] + if: ${{ (github.event_name == 'push' && (github.ref_name == 'main' || github.ref_name == 'master' || needs.conan-recipe-version.outputs.is_release_branch == 'true')) }} + uses: ultimaker/cura-workflows/.github/workflows/conan-package-create-windows.yml@CURA-11622_conan_v2 + with: + recipe_id_name: ${{ needs.conan-recipe-version.outputs.project_name }} + recipe_id_version: ${{ needs.conan-recipe-version.outputs.recipe_semver_full }} + recipe_id_user: ${{ needs.conan-recipe-version.outputs.user }} + recipe_id_channel: ${{ needs.conan-recipe-version.outputs.channel }} + recipe_id_full: ${{ needs.conan-recipe-version.outputs.recipe_id_full }} + secrets: inherit - conan-package-create-linux: - needs: [ conan-recipe-version, conan-package-export ] - if: ${{ (github.event_name == 'push' && (github.ref_name == 'main' || github.ref_name == 'master' || needs.conan-recipe-version.outputs.is_release_branch == 'true')) }} - uses: ultimaker/cura-workflows/.github/workflows/conan-package-create-linux.yml@main - with: - recipe_id_full: ${{ needs.conan-recipe-version.outputs.recipe_id_full }} - secrets: inherit + # FIXME: Use main once merged + conan-package-create-linux: + needs: [ conan-recipe-version, conan-package-export ] + if: ${{ (github.event_name == 'push' && (github.ref_name == 'main' || github.ref_name == 'master' || needs.conan-recipe-version.outputs.is_release_branch == 'true')) }} + uses: ultimaker/cura-workflows/.github/workflows/conan-package-create-linux.yml@CURA-11622_conan_v2 + with: + recipe_id_name: ${{ needs.conan-recipe-version.outputs.project_name }} + recipe_id_version: ${{ needs.conan-recipe-version.outputs.recipe_semver_full }} + recipe_id_user: ${{ needs.conan-recipe-version.outputs.user }} + recipe_id_channel: ${{ needs.conan-recipe-version.outputs.channel }} + recipe_id_full: ${{ needs.conan-recipe-version.outputs.recipe_id_full }} + secrets: inherit \ No newline at end of file diff --git a/.gitignore b/.gitignore index 1a980b8..02591ba 100644 --- a/.gitignore +++ b/.gitignore @@ -88,3 +88,11 @@ test_package/build/ pyproject.toml build-*/ +/test_package/metadata/ +/test_package/conanbuild.sh +/test_package/conanbuildenv-release-x86_64.sh +/test_package/conanrunenv-release-x86_64.sh +/test_package/conanrun.sh +/test_package/deactivate_conanbuild.sh +/test_package/deactivate_conanrun.sh +/test_package/deactivate_conanrunenv-release-x86_64.sh diff --git a/conandata.yml b/conandata.yml index d9079d7..cea4898 100644 --- a/conandata.yml +++ b/conandata.yml @@ -1,3 +1,3 @@ version: "5.4.0-alpha.0" requirements: - - "arcus/5.3.1" + - "arcus/[>=5.4.0]@ultimaker/cura_11622" diff --git a/conanfile.py b/conanfile.py index aa2c8d8..3789e32 100644 --- a/conanfile.py +++ b/conanfile.py @@ -1,5 +1,5 @@ +import os from pathlib import Path -from os import path from conan import ConanFile from conan.errors import ConanInvalidConfiguration @@ -21,11 +21,11 @@ class ArcusConan(ConanFile): description = "Communication library between internal components for Ultimaker software" topics = ("conan", "python", "binding", "sip", "cura", "protobuf") settings = "os", "compiler", "build_type", "arch" - revision_mode = "scm" exports = "LICENSE*" - generators = "CMakeDeps", "VirtualBuildEnv", "VirtualRunEnv" + generators = "CMakeDeps", "VirtualRunEnv" + package_type = "library" - python_requires = "pyprojecttoolchain/[>=0.1.7]@ultimaker/stable", "sipbuildtool/[>=0.2.4]@ultimaker/stable" + python_requires = "pyprojecttoolchain/[>=0.2.0]@ultimaker/cura_11622", "sipbuildtool/[>=0.3.0]@ultimaker/cura_11622" # FIXME: use stable after merge options = { "shared": [True, False], @@ -42,8 +42,7 @@ class ArcusConan(ConanFile): def set_version(self): if not self.version: - build_meta = "" if self.develop else "+source" - self.version = self.conan_data["version"] + build_meta + self.version = self.conan_data["version"] def export(self): git = Git(self) @@ -65,16 +64,16 @@ def _compilers_minimum_version(self): 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")) + copy(self, "*", os.path.join(self.recipe_folder, "src"), os.path.join(self.export_sources_folder, "src")) + copy(self, "*", os.path.join(self.recipe_folder, "include"), + os.path.join(self.export_sources_folder, "include")) + copy(self, "*", os.path.join(self.recipe_folder, "python"), os.path.join(self.export_sources_folder, "python")) def requirements(self): for req in self.conan_data["requirements"]: self.requires(req) - self.requires("protobuf/3.21.9", transitive_headers=True) - self.requires("cpython/3.10.4") # Maybe place this in build_requirements as well - self.requires("zlib/1.2.12") + self.requires("protobuf/3.21.12", transitive_headers=True) + self.requires("zlib/1.3.1") def validate(self): if self.settings.compiler.cppstd: @@ -88,8 +87,9 @@ def validate(self): ) def build_requirements(self): - self.test_requires("standardprojectsettings/[>=0.1.0]@ultimaker/stable") - self.test_requires("sipbuildtool/[>=0.2.4]@ultimaker/stable") + self.test_requires("standardprojectsettings/[>=0.2.0]@ultimaker/cura_11622") # FIXME: use stable after merge + self.test_requires("sipbuildtool/[>=0.3.0]@ultimaker/cura_11622") # FIXME: use stable after merge + self.test_requires("cpython/3.12.2@ultimaker/cura_11622") # FIXME: use stable after merge def config_options(self): if self.settings.os == "Windows": @@ -113,10 +113,12 @@ 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["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("\\", "/") + tc.cache_variables["CMAKE_POLICY_DEFAULT_CMP0148"] = "OLD" + cpython_conf = self.dependencies["cpython"].conf_info + tc.variables["Python_EXECUTABLE"] = cpython_conf.get("user.cpython:python").replace("\\", "/") + tc.variables["Python_ROOT_DIR"] = cpython_conf.get("user.cpython:python_root").replace("\\", "/") + cpython_options = self.dependencies["cpython"].options + tc.variables["Python_USE_STATIC_LIBS"] = not cpython_options.shared tc.variables["Python_FIND_FRAMEWORK"] = "NEVER" tc.variables["Python_FIND_REGISTRY"] = "NEVER" tc.variables["Python_FIND_IMPLEMENTATIONS"] = "CPython" @@ -138,6 +140,12 @@ def layout(self): if self.settings.os in ["Linux", "FreeBSD", "Macos"]: self.cpp.package.system_libs = ["pthread"] + self.cpp.package.lib = ["pyArcus"] + + self.cpp.package.libdirs = ["lib"] + self.layouts.build.runenv_info.prepend_path("PYTHONPATH", ".") + self.layouts.package.runenv_info.prepend_path("PYTHONPATH", "lib") + def build(self): cmake = CMake(self) cmake.configure() @@ -145,16 +153,12 @@ def build(self): def package(self): 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, 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")) + for ext in ("*.pyi", "*.so", "*.lib", "*.a", "*.pyd", "*.dylib", "*.dll"): + copy(self, ext, src=self.build_folder, + dst=os.path.join(self.package_folder, "lib"), keep_path=False) + + copy(self, "*.h", os.path.join(self.source_folder, "include"), os.path.join(self.package_folder, "include")) def package_info(self): - self.cpp_info.libdirs = [ path.join(self.package_folder, "lib") ] - if self.in_local_cache: - self.runenv_info.append_path("PYTHONPATH", path.join(self.package_folder, "lib")) - else: - self.runenv_info.append_path("PYTHONPATH", self.build_folder) + self.conf_info.define("user.pyarcus:pythonpath", os.path.join(self.package_folder, self.cpp.package.libdirs[0])) diff --git a/test_package/conanfile.py b/test_package/conanfile.py index 6b42a61..9623450 100644 --- a/test_package/conanfile.py +++ b/test_package/conanfile.py @@ -12,7 +12,6 @@ class ArcusTestConan(ConanFile): settings = "os", "compiler", "build_type", "arch" - generators = "VirtualRunEnv" test_type = "explicit" def requirements(self): @@ -23,22 +22,16 @@ def generate(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) + 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 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")) - + copy(self, "*.dll", src=bin_dir, dst=self.build_folder) def test(self): if can_run(self): test_buf = StringIO() - self.run(f"python test.py", env = "conanrun", output = test_buf, run_environment=True) + self.run(f"python test.py", env="conanrun", stdout=test_buf, scope="run") ret_val = test_buf.getvalue() if "True" not in ret_val: raise ConanException("pyArcus wasn't build correctly!")