Permalink
Browse files

Test Conan package

- Validate conan package by simple example
- Build Conan package using Conan package Tools

Signed-off-by: Uilian Ries <uilianries@gmail.com>
  • Loading branch information...
uilianries committed Oct 6, 2018
1 parent bd6c8b0 commit 08012f329f13c19f9d072897cd60d9ff26ee68c8
Showing with 153 additions and 0 deletions.
  1. +89 −0 .conan/build.py
  2. +12 −0 .conan/test_package/CMakeLists.txt
  3. +20 −0 .conan/test_package/conanfile.py
  4. +29 −0 .conan/test_package/test_package.cpp
  5. +2 −0 .gitignore
  6. +1 −0 conanfile.py
View
@@ -0,0 +1,89 @@
#!/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 crte as package's owner
"""
return os.getenv("CONAN_USERNAME", "crte")
@property
def upload(self):
""" Set hanickadot 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.
"""
if os.getenv("CONAN_UPLOAD", None) is not None:
return os.getenv("CONAN_UPLOAD")
printer = Printer(None)
ci_manager = CIManager(printer)
branch = ci_manager.get_branch()
patterns = [r"v?\d+\.\d+-.*", self.stable_branch_pattern]
for pattern in patterns:
prog = re.compile(pattern)
if branch and prog.match(branch):
return "https://api.bintray.com/conan/hanickadot/ctre"
@property
def upload_only_when_stable(self):
""" Force to upload when running over tag branch
"""
return os.getenv("CONAN_UPLOAD_ONLY_WHEN_STABLE", True)
@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"\d+\.\d+")
@property
def reference(self):
""" Read project version from CMake file to create Conan referece
"""
pattern = re.compile(r' version = "(\d+\.\d+)"')
version = None
with open('conanfile.py') as file:
for line in file:
result = pattern.match(line)
if result:
version = result.group(1)
if not version:
raise Exception("Could not find version in conanfile.py")
pattern = re.compile(r' name = "(.*)"')
name = None
with open('conanfile.py') as file:
for line in file:
result = pattern.match(line)
if result:
name = result.group(1)
if not name:
raise Exception("Could not find name in conanfile.py")
return os.getenv("CONAN_REFERENCE", "{}/{}@crte/stable".format(name, version))
if __name__ == "__main__":
settings = BuilderSettings()
builder = ConanMultiPackager(
reference=settings.reference,
username=settings.username,
upload=settings.upload,
upload_only_when_stable=settings.upload_only_when_stable,
stable_branch_pattern=settings.stable_branch_pattern,
test_folder=os.path.join(".conan", "test_package"))
builder.add()
builder.run()
@@ -0,0 +1,12 @@
project(test_package CXX)
cmake_minimum_required(VERSION 3.2.0 FATAL_ERROR)
set(CMAKE_VERBOSE_MAKEFILE TRUE)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 17)
@@ -0,0 +1,20 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from conans import ConanFile, CMake, tools, RunEnvironment
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.exists(os.path.join(self.deps_cpp_info["CTRE"].rootpath, "licenses", "LICENSE"))
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
@@ -0,0 +1,29 @@
#include <cstdlib>
#include <cassert>
#include <string_view>
#include <optional>
#include <ctre.hpp>
struct date { std::string_view year; std::string_view month; std::string_view day; };
constexpr std::optional<date> extract_date(std::string_view s) noexcept {
using namespace ctre::literals;
if (auto [whole, year, month, day] = "^([0-9]{4})/([0-9]{1,2}+)/([0-9]{1,2}+)$"_pcre.match(s); whole
) {
return date{year.to_view(), month.to_view(), day.to_view()};
} else {
return std::nullopt;
}
}
int main() {
assert(extract_date("2018/08/27").has_value());
assert(extract_date("2018/08/27")->year == "2018");
assert(extract_date("2018/08/27")->month == "08");
assert(extract_date("2018/08/27")->day == "27");
return EXIT_SUCCESS;
}
View
@@ -4,3 +4,5 @@ test
result
tests/benchmark-exec/*
!tests/benchmark-exec/*.cpp
*.pyc
.conan/test_package/build
View
@@ -16,6 +16,7 @@ class CtreConan(ConanFile):
no_copy_source = True
def package(self):
self.copy("LICENSE", "licenses")
self.copy("*.hpp")
def package_id(self):

0 comments on commit 08012f3

Please sign in to comment.