diff --git a/.conan/build.py b/.conan/build.py new file mode 100644 index 00000000..4d612d99 --- /dev/null +++ b/.conan/build.py @@ -0,0 +1,52 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import os +import re +import platform +from cpt.packager import ConanMultiPackager + + +def get_version(): + with open("CMakeLists.txt") as cmake: + content = cmake.read() + match = re.search(r'project\(uvw VERSION (.*)\)', content) + if match: + return match.group(1) + return os.getenv("TRAVIS_BRANCH", "master") + +def get_username(): + return os.getenv("CONAN_USERNAME", "skypjack") + + +def get_reference(): + version = get_version() + username = get_username() + return "uvw/{}@{}/stable".format(version, username) + + +def get_upload(): + username = get_username() + url = "https://api.bintray.com/conan/{}/conan".format(username) + default_upload = url if os.getenv("TRAVIS_TAG") else False + return os.getenv("CONAN_UPLOAD", default_upload) + + +def upload_when_stable(): + return os.getenv("CONAN_UPLOAD_ONLY_WHEN_STABLE", "1").lower() not in ["0", "false", "no"] + + +if __name__ == "__main__": + test_folder = os.path.join(".conan", "test_package") + builder = ConanMultiPackager(reference=get_reference(), + username=get_username(), + upload=get_upload(), + remotes="https://api.bintray.com/conan/bincrafters/public-conan", + test_folder=test_folder, + stable_branch_pattern=r'v?\d+\.\d+\.\d+.*', + upload_only_when_stable=upload_when_stable()) + if platform.system() == "Linux": + builder.add(settings={"compiler": "gcc", "compiler.version": "8", + "arch": "x86_64", "build_type": "Release"}, + options={}, env_vars={}, build_requires={}) + builder.run() diff --git a/.conan/test_package/CMakeLists.txt b/.conan/test_package/CMakeLists.txt new file mode 100644 index 00000000..17242138 --- /dev/null +++ b/.conan/test_package/CMakeLists.txt @@ -0,0 +1,10 @@ +project(test_package) +cmake_minimum_required(VERSION 2.8) + +set(CMAKE_VERBOSE_MAKEFILE TRUE) + +include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) +conan_basic_setup(TARGETS) + +add_executable(${PROJECT_NAME} test_package.cpp) +target_link_libraries(${PROJECT_NAME} CONAN_PKG::uvw) \ No newline at end of file diff --git a/.conan/test_package/conanfile.py b/.conan/test_package/conanfile.py new file mode 100644 index 00000000..1bffca9d --- /dev/null +++ b/.conan/test_package/conanfile.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import os +from conans import ConanFile, CMake + + + +class TestPackageConan(ConanFile): + settings = "os", "compiler", "build_type", "arch" + generators = "cmake" + + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() + + def test(self): + test_package = os.path.join("bin", "test_package") + self.run(test_package, 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..8f08f9bd --- /dev/null +++ b/.conan/test_package/test_package.cpp @@ -0,0 +1,48 @@ +#include +#include +#include +#include + +void listen(uvw::Loop &loop) { + std::shared_ptr tcp = loop.resource(); + + tcp->once([](const uvw::ListenEvent &, uvw::TcpHandle &srv) { + std::shared_ptr client = srv.loop().resource(); + + client->on([ptr = srv.shared_from_this()](const uvw::CloseEvent &, uvw::TcpHandle &) { ptr->close(); }); + client->on([](const uvw::EndEvent &, uvw::TcpHandle &client) { client.close(); }); + + srv.accept(*client); + client->read(); + }); + + tcp->bind("127.0.0.1", 4242); + tcp->listen(); +} + +void conn(uvw::Loop &loop) { + auto tcp = loop.resource(); + + tcp->on([](const uvw::ErrorEvent &, uvw::TcpHandle &) { /* handle errors */ }); + + tcp->once([](const uvw::ConnectEvent &, uvw::TcpHandle &tcp) { + auto dataWrite = std::unique_ptr(new char[2]{ 'b', 'c' }); + tcp.write(std::move(dataWrite), 2); + tcp.close(); + }); + + tcp->connect(std::string{"127.0.0.1"}, 4242); +} + +int main() { + std::cout << "Getting UVW loop ...\n"; + auto loop = uvw::Loop::getDefault(); + std::cout << "Staring UVW listener ...\n"; + listen(*loop); + std::cout << "Connecting ...\n"; + conn(*loop); + loop->run(); + std::cout << "Done!\n"; + + return EXIT_SUCCESS; +} \ No newline at end of file diff --git a/.gitignore b/.gitignore index a89dd341..d250cfa3 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ *.user TODO + +.conan/test_package/build \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index c36a9d78..cd7467c4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -36,7 +36,20 @@ matrix: - pip install --user cpp-coveralls after_success: - coveralls --gcov gcov-6 --gcov-options '\-lp' --root ${TRAVIS_BUILD_DIR} --build-root ${TRAVIS_BUILD_DIR}/build --extension cpp --extension hpp --exclude deps --include src - + - os: linux + dist: xenial + sudo: true + language: python + python: "3.7" + services: + - docker + env: + - CONAN_GCC_VERSIONS=8 + - CONAN_DOCKER_IMAGE=conanio/gcc8 + install: + - pip install conan_package_tools + script: + - python .conan/build.py notifications: email: diff --git a/CMakeLists.txt b/CMakeLists.txt index 0ae9f36a..a6464026 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,7 +16,7 @@ endif() # Project configuration # -project(uvw VERSION 1.11.2) +project(uvw VERSION 1.11.3) if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Debug) diff --git a/README.md b/README.md index da588082..0d76e1e2 100644 --- a/README.md +++ b/README.md @@ -6,10 +6,12 @@ [![Build Status](https://travis-ci.org/skypjack/uvw.svg?branch=master)](https://travis-ci.org/skypjack/uvw) [![Build status](https://ci.appveyor.com/api/projects/status/m5ndm8gnu8isg2to?svg=true)](https://ci.appveyor.com/project/skypjack/uvw) [![Coverage Status](https://coveralls.io/repos/github/skypjack/uvw/badge.svg?branch=master)](https://coveralls.io/github/skypjack/uvw?branch=master) +[![Download](https://api.bintray.com/packages/skypjack/conan/uvw/images/download.svg)](https://bintray.com/skypjack/conan/uvw/_latestVersion) [![Gitter chat](https://badges.gitter.im/skypjack/uvw.png)](https://gitter.im/skypjack/uvw) [![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=W2HF9FESD5LJY&lc=IT&item_name=Michele%20Caini¤cy_code=EUR&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted) [![Patreon](https://c5.patreon.com/external/logo/become_a_patron_button.png)](https://www.patreon.com/bePatron?u=11330786) + diff --git a/conanfile.py b/conanfile.py new file mode 100644 index 00000000..4a7bea36 --- /dev/null +++ b/conanfile.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +from conans import ConanFile + + +class UVMConan(ConanFile): + name = "uvw" + description = "Header-only, event based, tiny and easy to use libuv wrapper in modern C++" + homepage = "https://github.com/skypjack/uvw" + url = homepage + license = "MIT" + author = "Michele Caini " + exports = "LICENSE" + exports_sources = "src/*" + no_copy_source = True + requires = "libuv/1.23.2@bincrafters/stable" + + def package(self): + self.copy(pattern="LICENSE", dst="licenses") + self.copy(pattern="*.hpp", dst="include", src="src") + + def package_id(self): + self.info.header_only()