From a0f8db0c52fd44ff70f4edcf432db4706a081be4 Mon Sep 17 00:00:00 2001 From: Ivan Gagis Date: Thu, 18 May 2023 10:34:30 +0300 Subject: [PATCH] conan: migrate to conan 2 --- .github/workflows/ci.yml | 30 ++++++------ conan/conanfile.py | 78 +++++++++++++++++++++++++++++++ conan/conanfile.py.in | 53 --------------------- conan/test_package/CMakeLists.txt | 17 ++----- conan/test_package/conanfile.py | 33 ++++++------- 5 files changed, 111 insertions(+), 100 deletions(-) create mode 100644 conan/conanfile.py delete mode 100644 conan/conanfile.py.in diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 39d7ded6..7d5c314b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,9 +12,6 @@ env: MYCI_CONAN_REMOTE: https://gagis.hopto.org/conan MYCI_CONAN_USER: cppfw MYCI_CONAN_PASSWORD: ${{ secrets.MYCI_CONAN_PASSWORD }} - CONAN_V2_MODE: 1 - CONAN_REVISIONS_ENABLED: 1 - CONAN_SCM_TO_CONANDATA: 1 jobs: ##### linux ##### linux: @@ -254,26 +251,25 @@ jobs: keys-asc: https://gagis.hopto.org/repo/cppfw/pubkey.gpg install: devscripts equivs myci prorab prorab-extra python3-pip cmake git clang-tidy - name: install conan + run: pip3 --quiet install conan + - name: create default conan profile run: | - pip3 install conan - conan profile new --detect default - conan profile update settings.compiler.libcxx=libstdc++11 default + conan profile detect --name default + sed -i -E "s/compiler.cppstd=.*$/compiler.cppstd=17/g" ~/.conan2/profiles/default - name: git clone uses: myci-actions/checkout@master - name: set PACKAGE_VERSION uses: myci-actions/export-env-var@master with: {name: PACKAGE_VERSION, value: $(myci-deb-version.sh debian/changelog)} if: startsWith(github.ref, 'refs/tags/') - - name: prepare conanfile - run: myci-apply-version.sh --version $PACKAGE_VERSION conan/conanfile.py.in - name: build run: | conan remote add cppfw $MYCI_CONAN_REMOTE - conan create conan $MYCI_CONAN_USER/main --ignore-dirty + conan create conan --user $MYCI_CONAN_USER --channel main --version $PACKAGE_VERSION - name: deploy conan package run: | - conan user --remote cppfw --password $MYCI_CONAN_PASSWORD $MYCI_CONAN_USER - conan upload --remote cppfw --all $PACKAGE_NAME/$PACKAGE_VERSION@$MYCI_CONAN_USER/main + conan remote login --password $MYCI_CONAN_PASSWORD cppfw $MYCI_CONAN_USER + conan upload --check --remote cppfw $PACKAGE_NAME/$PACKAGE_VERSION@$MYCI_CONAN_USER/main if: startsWith(github.ref, 'refs/tags/') ##### conan - macosx ##### conan-macosx: @@ -295,6 +291,10 @@ jobs: brew update - name: install ci tools run: brew install myci prorab prorab-extra conan make + - name: create default conan profile + run: | + conan profile detect --name default + sed -i -E "s/compiler.cppstd=.*$/compiler.cppstd=17/g" ~/.conan2/profiles/default - name: set PATH uses: myci-actions/export-env-var@master with: {name: PATH, value: "/usr/local/opt/make/libexec/gnubin:$PATH"} @@ -304,14 +304,12 @@ jobs: uses: myci-actions/export-env-var@master with: {name: PACKAGE_VERSION, value: $(myci-deb-version.sh debian/changelog)} if: startsWith(github.ref, 'refs/tags/') - - name: prepare conanfile - run: myci-apply-version.sh --version $PACKAGE_VERSION conan/conanfile.py.in - name: build run: | conan remote add cppfw $MYCI_CONAN_REMOTE - conan create conan $MYCI_CONAN_USER/main --ignore-dirty + conan create conan --user $MYCI_CONAN_USER --channel main --version $PACKAGE_VERSION - name: deploy conan package run: | - conan user --remote cppfw --password $MYCI_CONAN_PASSWORD $MYCI_CONAN_USER - conan upload --remote cppfw --all $PACKAGE_NAME/$PACKAGE_VERSION@$MYCI_CONAN_USER/main + conan remote login --password $MYCI_CONAN_PASSWORD cppfw $MYCI_CONAN_USER + conan upload --check --remote cppfw $PACKAGE_NAME/$PACKAGE_VERSION@$MYCI_CONAN_USER/main if: startsWith(github.ref, 'refs/tags/') diff --git a/conan/conanfile.py b/conan/conanfile.py new file mode 100644 index 00000000..8c76a82f --- /dev/null +++ b/conan/conanfile.py @@ -0,0 +1,78 @@ +import os +from conan import ConanFile +from conan.tools.scm import Git +from conan.tools.files import load, update_conandata, copy +from conan.tools.layout import basic_layout + +class AggConan(ConanFile): + name = "agg" + license = "MIT" + author = "Maxim Shemanarev " + url = "http://github.com/cppfw/" + name + description = "Anti-grain geometry, vector graphics library in C++" + topics = ("C++", "cross-platform") + settings = "os", "compiler", "build_type", "arch" + package_type = "library" + options = {"shared": [True, False], "fPIC": [True, False]} + default_options = {"shared": False, "fPIC": True} + generators = "AutotoolsDeps" # this will set CXXFLAGS etc. env vars + + def requirements(self): + # self.requires("utki/[>=1.1.202]@cppfw/main", transitive_headers=True) + + def build_requirements(self): + # self.requires("tst/[>=0.3.29]@cppfw/main", visible=False) + + def config_options(self): + if self.settings.os == "Windows": + del self.options.fPIC + + # save commit and remote URL to conandata.yml for packaging + def export(self): + git = Git(self) + scm_url = git.get_remote_url() + # NOTE: Git.get_commit() doesn't work properly, + # it gets latest commit of the folder in which conanfile.py resides. + # So, we use "git rev-parse HEAD" instead as it gets the actual HEAD + # commit regardless of the current working directory within the repo. + scm_commit = git.run("rev-parse HEAD") # get current commit + update_conandata(self, {"sources": {"commit": scm_commit, "url": scm_url}}) + + def source(self): + git = Git(self) + sources = self.conan_data["sources"] + # shallow fetch commit + git.fetch_commit(url=sources["url"], commit=sources['commit']) + # shallow clone submodules + git.run("submodule update --init --remote --depth 1") + + def build(self): + self.run("make lint=off") + self.run("make lint=off test") + + def package(self): + src_dir = os.path.join(self.build_folder, "src") + src_rel_dir = os.path.join(self.build_folder, "src/out/rel") + dst_include_dir = os.path.join(self.package_folder, "include") + dst_lib_dir = os.path.join(self.package_folder, "lib") + dst_bin_dir = os.path.join(self.package_folder, "bin") + + copy(conanfile=self, pattern="*.h", dst=dst_include_dir, src=src_dir, keep_path=True) + copy(conanfile=self, pattern="*.hpp", dst=dst_include_dir, src=src_dir, keep_path=True) + + if self.options.shared: + copy(conanfile=self, pattern="*" + self.name + ".lib", dst=dst_lib_dir, src="", keep_path=False) + copy(conanfile=self, pattern="*.dll", dst=dst_bin_dir, src=src_rel_dir, keep_path=False) + copy(conanfile=self, pattern="*.so", dst=dst_lib_dir, src=src_rel_dir, keep_path=False) + copy(conanfile=self, pattern="*.so.*", dst=dst_lib_dir, src=src_rel_dir, keep_path=False) + copy(conanfile=self, pattern="*.dylib", dst=dst_lib_dir, src=src_rel_dir, keep_path=False) + else: + copy(conanfile=self, pattern="*" + self.name + ".lib", dst=dst_lib_dir, src="", keep_path=False) + copy(conanfile=self, pattern="*.a", dst=dst_lib_dir, src=src_rel_dir, keep_path=False) + + def package_info(self): + self.cpp_info.libs = ["antigrain"] + + def package_id(self): + # change package id only when minor or major version changes, i.e. when ABI breaks + self.info.requires.minor_mode() diff --git a/conan/conanfile.py.in b/conan/conanfile.py.in deleted file mode 100644 index 969143c9..00000000 --- a/conan/conanfile.py.in +++ /dev/null @@ -1,53 +0,0 @@ -from conans import ConanFile, CMake, tools - -class AggConan(ConanFile): - name = "agg" - version = "$(version)" - license = "MIT" - author = "Ivan Gagis " - url = "http://github.com/cppfw/" + name - description = "Anti-grain geometry, vector graphics library in C++" - topics = ("C++", "cross-platform") - settings = "os", "compiler", "build_type", "arch" - options = {"shared": [True, False], "fPIC": [True, False]} - default_options = {"shared": False, "fPIC": True} - generators = "make" - scm = {"type": "git", "url": "auto", "revision": "auto"} - - def config_options(self): - if self.settings.os == "Windows": - del self.options.fPIC - - # we use the 'scm' attribute, so the source() method is not needed -# def source(self): -# self.run("git clone https://github.com/cppfw/" + self.name + ".git") -# self.run("cd " + self.name + " && git checkout " + self.version) - - # This small hack might be useful to guarantee proper /MT /MD linkage - # in MSVC if the packaged project doesn't have variables to set it - # properly -# tools.replace_in_file("hello/CMakeLists.txt", "PROJECT(HelloWorld)", -# '''PROJECT(HelloWorld) -# include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) -# conan_basic_setup()''') - - def build(self): - self.run("CONANBUILDINFO_DIR=$(pwd)/ make") - self.run("CONANBUILDINFO_DIR=$(pwd)/ make test") - - def package(self): - self.copy("*.h", dst="include/agg", src="src/agg/include") - self.copy("*.hpp", dst="include/agg", src="src/agg/include") - self.copy("*" + self.name + ".lib", dst="lib", keep_path=False) - self.copy("*.dll", dst="bin", src="src/build", keep_path=False) - self.copy("*.so", dst="lib", src="src/build", keep_path=False) - self.copy("*.so.*", dst="lib", src="src/build", keep_path=False) - self.copy("*.dylib", dst="lib", src="src/build", keep_path=False) - self.copy("*.a", dst="lib", src="src/build", keep_path=False) - - def package_info(self): - self.cpp_info.libs = ["antigrain"] - - # change package id only when minor or major version changes, i.e. when ABI breaks - def package_id(self): - self.info.requires.minor_mode() diff --git a/conan/test_package/CMakeLists.txt b/conan/test_package/CMakeLists.txt index 80dd84d9..a781ce1e 100644 --- a/conan/test_package/CMakeLists.txt +++ b/conan/test_package/CMakeLists.txt @@ -1,18 +1,9 @@ -cmake_minimum_required(VERSION 3.1) +cmake_minimum_required(VERSION 3.15) project(PackageTest CXX) -include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) -conan_basic_setup() - -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17") - # set(CMAKE_VERBOSE_MAKEFILE on) -add_executable(example example.cpp) -target_link_libraries(example ${CONAN_LIBS}) +find_package(agg CONFIG REQUIRED) -# CTest is a testing tool that can be used to test your project. -# enable_testing() -# add_test(NAME example -# WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/bin -# COMMAND example) +add_executable(example example.cpp) +target_link_libraries(example agg::agg) diff --git a/conan/test_package/conanfile.py b/conan/test_package/conanfile.py index da047e3d..59f573f0 100644 --- a/conan/test_package/conanfile.py +++ b/conan/test_package/conanfile.py @@ -1,25 +1,22 @@ import os -from conans import ConanFile, CMake, tools +from conan import ConanFile, tools +from conan.tools.cmake import CMake, cmake_layout +class TestConan(ConanFile): + settings = "os", "compiler", "build_type", "arch" + generators = "CMakeToolchain", "CMakeDeps" -class UtkiTestConan(ConanFile): - settings = "os", "compiler", "build_type", "arch" - generators = "cmake" + def requirements(self): + self.requires(self.tested_reference_str) - def build(self): - cmake = CMake(self) - # Current dir is "test_package/build/" and CMakeLists.txt is - # in "test_package" - cmake.configure() - cmake.build() + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() - def imports(self): - self.copy("*.dll", dst="bin", src="bin") - self.copy("*.dylib*", dst="bin", src="lib") - self.copy('*.so*', dst='bin', src='lib') + def layout(self): + cmake_layout(self) - def test(self): - if not tools.cross_building(self): - os.chdir("bin") - self.run(".%sexample" % os.sep, run_environment=True) # run_environment sets LD_LIBRARY_PATH etc. to find dependency libs + def test(self): + self.run(".%sexample" % os.sep, env="conanrun") # env sets LD_LIBRARY_PATH etc. to find dependency libs