From 891cf0e5672fb895b2063db976b63bfeee7d9cd5 Mon Sep 17 00:00:00 2001 From: Uilian Ries Date: Tue, 24 Nov 2020 13:59:44 -0300 Subject: [PATCH 1/3] Add Conandata with Development flow Signed-off-by: Uilian Ries --- .../CMakeLists.txt | 7 +++ .../build.bat | 17 ++++++ .../build.sh | 20 +++++++ .../conandata.yml | 4 ++ .../conanfile.py | 54 +++++++++++++++++++ .../test_package/CMakeLists.txt | 14 +++++ .../test_package/conanfile.py | 25 +++++++++ .../test_package/example.cpp | 6 +++ 8 files changed, 147 insertions(+) create mode 100644 features/package_development_flow_conandata/CMakeLists.txt create mode 100644 features/package_development_flow_conandata/build.bat create mode 100755 features/package_development_flow_conandata/build.sh create mode 100644 features/package_development_flow_conandata/conandata.yml create mode 100644 features/package_development_flow_conandata/conanfile.py create mode 100644 features/package_development_flow_conandata/test_package/CMakeLists.txt create mode 100644 features/package_development_flow_conandata/test_package/conanfile.py create mode 100644 features/package_development_flow_conandata/test_package/example.cpp diff --git a/features/package_development_flow_conandata/CMakeLists.txt b/features/package_development_flow_conandata/CMakeLists.txt new file mode 100644 index 00000000..d6b5772b --- /dev/null +++ b/features/package_development_flow_conandata/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 2.8) +project(HelloWorld) + +include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) +conan_basic_setup() + +add_subdirectory("hello") diff --git a/features/package_development_flow_conandata/build.bat b/features/package_development_flow_conandata/build.bat new file mode 100644 index 00000000..e0f7748e --- /dev/null +++ b/features/package_development_flow_conandata/build.bat @@ -0,0 +1,17 @@ +@ECHO ON + +RMDIR /Q /S tmp + +conan source . --source-folder=tmp/source +conan install . --install-folder=tmp/build +conan build . --source-folder=tmp/source --build-folder=tmp/build +conan package . --source-folder=tmp/source --build-folder=tmp/build --package-folder=tmp/package + +REM NOTE: Use --force to prevent ERROR: Package already exists +conan export-pkg . user/testing --source-folder=tmp/source --build-folder=tmp/build --force + +REM You can also test the package that was just exported +conan test test_package Hello/1.0@user/testing + +REM Finally, run a full create, does all of the above + test_package +conan create . user/testing diff --git a/features/package_development_flow_conandata/build.sh b/features/package_development_flow_conandata/build.sh new file mode 100755 index 00000000..49ace031 --- /dev/null +++ b/features/package_development_flow_conandata/build.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +set -e +set -x + +rm -rf tmp + +conan source . --source-folder=tmp/source +conan install . --install-folder=tmp/build +conan build . --source-folder=tmp/source --build-folder=tmp/build +conan package . --source-folder=tmp/source --build-folder=tmp/build --package-folder=tmp/package + +# NOTE: Use --force to prevent ERROR: Package already exists +conan export-pkg . user/testing --source-folder=tmp/source --build-folder=tmp/build --force + +# You can also test the package that was just exported +conan test test_package Hello/1.0@user/testing + +# Finally, run a full create, does all of the above + test_package +conan create . user/testing diff --git a/features/package_development_flow_conandata/conandata.yml b/features/package_development_flow_conandata/conandata.yml new file mode 100644 index 00000000..37336bbb --- /dev/null +++ b/features/package_development_flow_conandata/conandata.yml @@ -0,0 +1,4 @@ +sources: + "1.0": + sha256: 07035d79713b5c1499cc4167701dc997da6ea8fcee170aecd08c68dd176c55d3 + url: https://github.com/conan-io/hello/archive/7160a88d4f4b0a7282b599ad5161e598d7d7993b.zip diff --git a/features/package_development_flow_conandata/conanfile.py b/features/package_development_flow_conandata/conanfile.py new file mode 100644 index 00000000..342f7fdf --- /dev/null +++ b/features/package_development_flow_conandata/conanfile.py @@ -0,0 +1,54 @@ +from conans import ConanFile, CMake, tools +import os + + +class HelloConan(ConanFile): + name = "Hello" + version = "1.0" + license = "" + author = " " + url = "" + description = "" + topics = ("", "", "") + settings = "os", "compiler", "build_type", "arch" + options = {"shared": [True, False]} + default_options = {"shared": False} + exports_sources = "CMakeLists.txt" + generators = "cmake" + + def source(self): + tools.get(**self.conan_data["sources"][self.version]) + os.rename("hello-7160a88d4f4b0a7282b599ad5161e598d7d7993b", "hello") + # 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 + + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() + + # Explicit way: + # self.run('cmake %s/hello %s' + # % (self.source_folder, cmake.command_line)) + # self.run("cmake --build . %s" % cmake.build_config) + + def package(self): + # CMake way: + # cmake = CMake(self) + # cmake.configure() + # cmake.install() + + # Explicit way: + # self.run('cmake %s/hello %s' % (self.source_folder, cmake.command_line)) + # self.run("cmake --build . %s --target install" % cmake.build_config) + + self.copy("*.h", dst="include", src="hello") + self.copy("*hello.lib", dst="lib", keep_path=False) + self.copy("*.dll", dst="bin", keep_path=False) + self.copy("*.so", dst="lib", keep_path=False) + self.copy("*.dylib", dst="lib", keep_path=False) + self.copy("*.a", dst="lib", keep_path=False) + + def package_info(self): + self.cpp_info.libs = ["hello"] diff --git a/features/package_development_flow_conandata/test_package/CMakeLists.txt b/features/package_development_flow_conandata/test_package/CMakeLists.txt new file mode 100644 index 00000000..ad6dc6eb --- /dev/null +++ b/features/package_development_flow_conandata/test_package/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 2.8.12) +project(PackageTest CXX) + +include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) +conan_basic_setup() + +add_executable(example example.cpp) +target_link_libraries(example ${CONAN_LIBS}) + +# 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) diff --git a/features/package_development_flow_conandata/test_package/conanfile.py b/features/package_development_flow_conandata/test_package/conanfile.py new file mode 100644 index 00000000..c8b87833 --- /dev/null +++ b/features/package_development_flow_conandata/test_package/conanfile.py @@ -0,0 +1,25 @@ +import os + +from conans import ConanFile, CMake, tools + + +class HelloTestConan(ConanFile): + settings = "os", "compiler", "build_type", "arch" + generators = "cmake" + + def build(self): + cmake = CMake(self) + # Current dir is "test_package/build/" and CMakeLists.txt is + # in "test_package" + 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 test(self): + if not tools.cross_building(self.settings): + os.chdir("bin") + self.run(".%sexample" % os.sep) diff --git a/features/package_development_flow_conandata/test_package/example.cpp b/features/package_development_flow_conandata/test_package/example.cpp new file mode 100644 index 00000000..4a5549c5 --- /dev/null +++ b/features/package_development_flow_conandata/test_package/example.cpp @@ -0,0 +1,6 @@ +#include +#include "hello.h" + +int main() { + hello(); +} From bdb40b37fa5751fdc13108fc696e5bf79dbd0790 Mon Sep 17 00:00:00 2001 From: Uilian Ries Date: Tue, 24 Nov 2020 14:01:49 -0300 Subject: [PATCH 2/3] Add conandata example in README Signed-off-by: Uilian Ries --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index e772e374..8016516d 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,13 @@ Example how to use Conan commands to develop a package recipe. Documentation: https://docs.conan.io/en/latest/developing_packages/package_dev_flow.html +### [Package development flow with conandata.yml](features/package_development_flow_conandata) + +Example how to use Conan commands to develop a package recipe which requires a conandata.yml. + +Documentation: https://docs.conan.io/en/latest/developing_packages/package_dev_flow.html + https://docs.conan.io/en/latest/reference/config_files/conandata.yml.html + ### [Workspace](features/workspace) Example how to use Conan Workspaces. From 94030d42b5b1511e5afcd3c1fbe7437d1aaf2695 Mon Sep 17 00:00:00 2001 From: Uilian Ries Date: Tue, 24 Nov 2020 14:05:39 -0300 Subject: [PATCH 3/3] Use real test_package as example Signed-off-by: Uilian Ries --- .../test_package/conanfile.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/features/package_development_flow_conandata/test_package/conanfile.py b/features/package_development_flow_conandata/test_package/conanfile.py index c8b87833..cd8770a6 100644 --- a/features/package_development_flow_conandata/test_package/conanfile.py +++ b/features/package_development_flow_conandata/test_package/conanfile.py @@ -21,5 +21,5 @@ def imports(self): def test(self): if not tools.cross_building(self.settings): - os.chdir("bin") - self.run(".%sexample" % os.sep) + bin_path = os.path.join("bin", "example") + self.run(bin_path, run_environment=True)