diff --git a/.conan/build.py b/.conan/build.py new file mode 100644 index 00000000..1d7e5420 --- /dev/null +++ b/.conan/build.py @@ -0,0 +1,94 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import os +import re +from cpt.packager import ConanMultiPackager +from cpt.ci_manager import CIManager +from cpt.printer import Printer + + +class BuilderSettings(object): + @property + def username(self): + """ Set catchorg as package's owner + """ + return os.getenv("CONAN_USERNAME", "catchorg") + + @property + def login_username(self): + """ Set Bintray login username + """ + return os.getenv("CONAN_LOGIN_USERNAME", "horenmar") + + @property + def upload(self): + """ Set Catch2 repository to be used on upload. + The upload server address could be customized by env var + CONAN_UPLOAD. If not defined, the method will check the branch name. + Only master or CONAN_STABLE_BRANCH_PATTERN will be accepted. + The master branch will be pushed to testing channel, because it does + not match the stable pattern. Otherwise it will upload to stable + channel. + """ + return os.getenv("CONAN_UPLOAD", "https://api.bintray.com/conan/horenmar/Catch2") + + @property + def upload_only_when_stable(self): + """ Force to upload when running over tag branch + """ + return os.getenv("CONAN_UPLOAD_ONLY_WHEN_STABLE", "True").lower() in ["true", "1", "yes"] + + @property + def stable_branch_pattern(self): + """ Only upload the package the branch name is like a tag + """ + return os.getenv("CONAN_STABLE_BRANCH_PATTERN", r"v\d+\.\d+\.\d+") + + @property + def reference(self): + """ Read project version from branch create Conan referece + """ + return os.getenv("CONAN_REFERENCE", "Catch2/{}@{}/{}".format(self._version, self.username, self.channel)) + + @property + def channel(self): + """ Default Conan package channel when not stable + """ + return os.getenv("CONAN_CHANNEL", "testing") + + @property + def _version(self): + """ Get version name from cmake file + """ + pattern = re.compile(r"project\(Catch2 LANGUAGES CXX VERSION (\d+\.\d+\.\d+)\)") + version = "latest" + with open("CMakeLists.txt") as file: + for line in file: + result = pattern.search(line) + if result: + version = result.group(1) + return version + + @property + def _branch(self): + """ Get branch name from CI manager + """ + printer = Printer(None) + ci_manager = CIManager(printer) + return ci_manager.get_branch() + + +if __name__ == "__main__": + settings = BuilderSettings() + builder = ConanMultiPackager( + reference=settings.reference, + channel=settings.channel, + upload=settings.upload, + upload_only_when_stable=settings.upload_only_when_stable, + stable_branch_pattern=settings.stable_branch_pattern, + login_username=settings.login_username, + username=settings.username, + test_folder=os.path.join(".conan", "test_package")) + builder.add() + builder.run() diff --git a/.conan/test_package/CMakeLists.txt b/.conan/test_package/CMakeLists.txt new file mode 100644 index 00000000..db056599 --- /dev/null +++ b/.conan/test_package/CMakeLists.txt @@ -0,0 +1,11 @@ +cmake_minimum_required(VERSION 3.2.0) +project(test_package CXX) + +include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) +conan_basic_setup(TARGETS) + +find_package(Catch2 REQUIRED CONFIG) + +add_executable(${PROJECT_NAME} test_package.cpp) +target_link_libraries(${PROJECT_NAME} CONAN_PKG::Catch2) +set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 11) diff --git a/.conan/test_package/conanfile.py b/.conan/test_package/conanfile.py new file mode 100644 index 00000000..0a0da54a --- /dev/null +++ b/.conan/test_package/conanfile.py @@ -0,0 +1,19 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +from conans import ConanFile, CMake +import os + + +class TestPackageConan(ConanFile): + settings = "os", "compiler", "build_type", "arch" + generators = "cmake" + + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() + + def test(self): + assert os.path.isfile(os.path.join(self.deps_cpp_info["Catch2"].rootpath, "licenses", "LICENSE.txt")) + bin_path = os.path.join("bin", "test_package") + self.run("%s -s" % bin_path, run_environment=True) diff --git a/.conan/test_package/test_package.cpp b/.conan/test_package/test_package.cpp new file mode 100644 index 00000000..cff50de5 --- /dev/null +++ b/.conan/test_package/test_package.cpp @@ -0,0 +1,15 @@ +#define CATCH_CONFIG_MAIN + +#include + +int Factorial( int number ) { + return number <= 1 ? 1 : Factorial( number - 1 ) * number; +} + +TEST_CASE( "Factorial Tests", "[single-file]" ) { + REQUIRE( Factorial(0) == 1 ); + REQUIRE( Factorial(1) == 1 ); + REQUIRE( Factorial(2) == 2 ); + REQUIRE( Factorial(3) == 6 ); + REQUIRE( Factorial(10) == 3628800 ); +} \ No newline at end of file diff --git a/.gitignore b/.gitignore index ffce8e91..f017e9e0 100644 --- a/.gitignore +++ b/.gitignore @@ -27,3 +27,4 @@ Build .vs cmake-build-* benchmark-dir +.conan/test_package/build diff --git a/.travis.yml b/.travis.yml index 1d38d860..ff6af74a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -271,6 +271,19 @@ matrix: packages: ['clang-6.0', 'libstdc++-8-dev'] env: COMPILER='clang++-6.0' CPP17=1 EXAMPLES=1 COVERAGE=1 EXTRAS=1 + # 8/ Conan + - language: python + python: + - "3.7" + dist: xenial + install: + - pip install conan conan-package-tools + env: + - CONAN_GCC_VERSIONS=8 + - CONAN_DOCKER_IMAGE=conanio/gcc8 + script: + - python .conan/build.py + install: - DEPS_DIR="${TRAVIS_BUILD_DIR}/deps" - mkdir -p ${DEPS_DIR} && cd ${DEPS_DIR} diff --git a/conanfile.py b/conanfile.py index b99f314d..a7cebb92 100644 --- a/conanfile.py +++ b/conanfile.py @@ -3,19 +3,15 @@ from conans import ConanFile, CMake class CatchConan(ConanFile): - name = "Catch" - version = "2.4.2" + name = "Catch2" description = "A modern, C++-native, header-only, framework for unit-tests, TDD and BDD" - author = "philsquared" - generators = "cmake" - # Only needed until conan 1.5 is released - settings = "compiler", "arch" - exports_sources = "single_include/*", "CMakeLists.txt", "CMake/catch2.pc.in", "LICENSE.txt" + topics = ("conan", "catch2", "header-only", "unit-test", "tdd", "bdd") url = "https://github.com/catchorg/Catch2" - license = "Boost Software License - Version 1.0. http://www.boost.org/LICENSE_1_0.txt" - - def build(self): - pass + homepage = url + license = "BSL-1.0" + exports = "LICENSE.txt" + exports_sources = ("single_include/*", "CMakeLists.txt", "CMake/*", "contrib/*") + generators = "cmake" def package(self): cmake = CMake(self) diff --git a/test_package/CMakeLists.txt b/test_package/CMakeLists.txt deleted file mode 100644 index 339facbf..00000000 --- a/test_package/CMakeLists.txt +++ /dev/null @@ -1,7 +0,0 @@ -cmake_minimum_required(VERSION 3.0) -project(CatchTest CXX) - -include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) -conan_basic_setup() - -add_executable(${CMAKE_PROJECT_NAME} MainTest.cpp) diff --git a/test_package/MainTest.cpp b/test_package/MainTest.cpp deleted file mode 100644 index 010feba2..00000000 --- a/test_package/MainTest.cpp +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Created by Phil on 22/10/2010. - * Copyright 2010 Two Blue Cubes Ltd - * - * Distributed under the Boost Software License, Version 1.0. (See accompanying - * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - */ -#define CATCH_CONFIG_MAIN -#include - -unsigned int Factorial( unsigned int number ) { - return number > 1 ? Factorial(number-1)*number : 1; -} - -TEST_CASE( "Factorials are computed", "[factorial]" ) { - REQUIRE( Factorial(0) == 1 ); - REQUIRE( Factorial(1) == 1 ); - REQUIRE( Factorial(2) == 2 ); - REQUIRE( Factorial(3) == 6 ); - REQUIRE( Factorial(10) == 3628800 ); -} diff --git a/test_package/conanfile.py b/test_package/conanfile.py deleted file mode 100644 index e63b2ce5..00000000 --- a/test_package/conanfile.py +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env python -from os import getenv -from os import path -from conans import ConanFile -from conans import CMake - - -class CatchConanTest(ConanFile): - generators = "cmake" - settings = "os", "compiler", "arch", "build_type" - username = getenv("CONAN_USERNAME", "philsquared") - channel = getenv("CONAN_CHANNEL", "testing") - requires = "Catch/2.4.2@%s/%s" % (username, channel) - - def build(self): - cmake = CMake(self) - cmake.configure(build_dir="./") - cmake.build() - - def test(self): - self.run(path.join("bin", "CatchTest"))