From 8937ac77e65bec5bd8af8d337420d091c271538e Mon Sep 17 00:00:00 2001 From: tastytea Date: Wed, 8 Jan 2020 22:45:46 +0100 Subject: [PATCH 01/15] Fix markup. --- README.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.adoc b/README.adoc index c5a856d..74980a2 100644 --- a/README.adoc +++ b/README.adoc @@ -18,7 +18,7 @@ link:{uri-mastodon-cpp}[mastodon-cpp]. We aim to create a library that is comfortable, yet minimal. All API endpoints -from Mastodon and Pleroma are stored in `enum class`es, to counteract typos and +from Mastodon and Pleroma are stored in ``enum class``es, to counteract typos and make your life easier. The network-facing code is built on link:{uri-curl}[libcurl], a mature and stable library that is available on virtually every operating system. The library does not parse the responses From 8482f51aff11ec550fbd3d21fd96663d08f19fbe Mon Sep 17 00:00:00 2001 From: tastytea Date: Wed, 8 Jan 2020 22:47:40 +0100 Subject: [PATCH 02/15] Fix curl URI. --- README.adoc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.adoc b/README.adoc index 74980a2..921ec56 100644 --- a/README.adoc +++ b/README.adoc @@ -12,7 +12,7 @@ :uri-catch: https://github.com/catchorg/Catch2 :uri-dpkg: https://packages.qa.debian.org/dpkg :uri-rpm-build: http://www.rpm.org -:uri-curl: https://curl.haxx.se/ +:uri-libcurl: https://curl.haxx.se/libcurl/ *{project}* is a C++ wrapper for the Mastodon API. It replaces link:{uri-mastodon-cpp}[mastodon-cpp]. @@ -20,7 +20,7 @@ link:{uri-mastodon-cpp}[mastodon-cpp]. We aim to create a library that is comfortable, yet minimal. All API endpoints from Mastodon and Pleroma are stored in ``enum class``es, to counteract typos and make your life easier. The network-facing code is built on -link:{uri-curl}[libcurl], a mature and stable library that is available on +link:{uri-libcurl}[libcurl], a mature and stable library that is available on virtually every operating system. The library does not parse the responses itself, but returns to you the raw data, because we know everyone has their favorite JSON library and we don't want to impose our choice on you! @@ -84,7 +84,7 @@ link:{uri-reference}/examples.html[More examples] are included in the reference. * Tested OS: Linux * C++ compiler (tested: link:{uri-gcc}[GCC] 7/8/9, link:{uri-lang}[clang] 6/7) * link:{uri-cmake}[CMake] (at least: 3.9) -* link:{uri-curl}[curl] (at least: 7.32) +* link:{uri-libcurl}[libcurl] (at least: 7.32) * Optional ** Documentation: link:{uri-doxygen}[Doxygen] (tested: 1.8) ** Tests: link:{uri-catch}[Catch] (tested: 2.5 / 1.2) From e4a5b8e9cea7016cf188372e8f04ae0cafe33d1e Mon Sep 17 00:00:00 2001 From: tastytea Date: Thu, 9 Jan 2020 11:23:15 +0100 Subject: [PATCH 03/15] Move set_proxy() to Instance. --- include/connection.hpp | 7 ------- include/instance.hpp | 24 ++++++++++++++++++++++++ src/connection.cpp | 14 +++++++------- 3 files changed, 31 insertions(+), 14 deletions(-) diff --git a/include/connection.hpp b/include/connection.hpp index e2735b8..b32acea 100644 --- a/include/connection.hpp +++ b/include/connection.hpp @@ -99,13 +99,6 @@ public: return get(endpoint, {}); } - /*! @copydoc CURLWrapper::set_proxy(string_view) - * - * Sets also the proxy for the Instance you used to initialize this - * Connection. - */ - void set_proxy(string_view proxy); - /*! * @brief Copy new stream contents and delete the “original”. * diff --git a/include/instance.hpp b/include/instance.hpp index 28f8f27..5af177c 100644 --- a/include/instance.hpp +++ b/include/instance.hpp @@ -95,11 +95,35 @@ public: [[nodiscard]] uint64_t get_max_chars(); + /*! @copydoc CURLWrapper::set_proxy(string_view) + * + * Sets also the proxy for all Connection%s that are initialized with this + * Instance afterwards. + */ + void set_proxy(const string_view proxy) + { + _proxy = proxy; + CURLWrapper::set_proxy(proxy); + } + + /*! + * @brief Returns the proxy string that was previously set. + * + * Does not return the proxy if it was set from an environment variable. + * + * @since 0.1.0 + */ + string_view get_proxy() const + { + return _proxy; + } + private: const string _hostname; const string _baseuri; string _access_token; uint64_t _max_chars; + string _proxy; }; } // namespace mastodonpp diff --git a/src/connection.cpp b/src/connection.cpp index 3aaa236..0deaed8 100644 --- a/src/connection.cpp +++ b/src/connection.cpp @@ -24,7 +24,13 @@ using std::holds_alternative; Connection::Connection(Instance &instance) : _instance{instance} , _baseuri{instance.get_baseuri()} -{} +{ + auto proxy{_instance.get_proxy()}; + if (!proxy.empty()) + { + CURLWrapper::set_proxy(proxy); + } +} answer_type Connection::get(const endpoint_variant &endpoint, const parametermap ¶meters) @@ -42,12 +48,6 @@ answer_type Connection::get(const endpoint_variant &endpoint, return make_request(http_method::GET, uri, parameters); } -void Connection::set_proxy(const string_view proxy) -{ - CURLWrapper::set_proxy(proxy); - _instance.set_proxy(proxy); -} - string Connection::get_new_stream_contents() { buffer_mutex.lock(); From 839e29b37ba4c36579e6a73ff150115e8177bd86 Mon Sep 17 00:00:00 2001 From: tastytea Date: Thu, 9 Jan 2020 11:23:30 +0100 Subject: [PATCH 04/15] Expand section about thread safety in documentation. --- include/mastodonpp.hpp | 8 ++++++++ src/curl_wrapper.cpp | 1 + 2 files changed, 9 insertions(+) diff --git a/include/mastodonpp.hpp b/include/mastodonpp.hpp index fec3ecf..11bde31 100644 --- a/include/mastodonpp.hpp +++ b/include/mastodonpp.hpp @@ -88,6 +88,14 @@ * (https://curl.haxx.se/libcurl/c/curl_global_cleanup.html) is called. Both * are not thread safe. * + * Do not make 2 requests with the same @link mastodonpp::Connection Connection + * @endlink at the same time. You can create as many @link + * mastodonpp::Connection Connection@endlink%s as you want from one @link + * mastodonpp::Instance Instance@endlink. + * + * If you are using libcurl with OpenSSL before 1.1.0, please read + * [libcurl-thread(3)](https://curl.haxx.se/libcurl/c/threadsafe.html). + * * @example example01_instance_info.cpp * @example example02_streaming.cpp */ diff --git a/src/curl_wrapper.cpp b/src/curl_wrapper.cpp index 490af70..930e840 100644 --- a/src/curl_wrapper.cpp +++ b/src/curl_wrapper.cpp @@ -36,6 +36,7 @@ using std::atomic; using std::uint8_t; using std::uint16_t; +// No one will ever need more than 65535 connections. 😉 static atomic curlwrapper_instances{0}; CURLWrapper::CURLWrapper() From ec41063488c9c043c7eb859254542d7b2a1a9f2d Mon Sep 17 00:00:00 2001 From: tastytea Date: Thu, 9 Jan 2020 12:24:29 +0100 Subject: [PATCH 05/15] Add get_new_events(). A more comfortable way to consume stream events. --- examples/example02_streaming.cpp | 8 ++++++-- include/connection.hpp | 34 ++++++++++++++++++++++++++++++++ src/connection.cpp | 29 +++++++++++++++++++++++++++ 3 files changed, 69 insertions(+), 2 deletions(-) diff --git a/examples/example02_streaming.cpp b/examples/example02_streaming.cpp index 0f95343..389b16b 100644 --- a/examples/example02_streaming.cpp +++ b/examples/example02_streaming.cpp @@ -65,9 +65,13 @@ int main(int argc, char *argv[]) // Print new events every 2 seconds, for 10 seconds. for (auto counter{0}; counter < 5; ++counter) { - cout << "----------------------------------------" << endl; sleep_for(2s); - cout << connection.get_new_stream_contents() << endl; + for (const auto &event : connection.get_new_events()) + { + // Print typo of event and the beginning of the data. + cout << event.type << ": " + << event.data.substr(0, 70) << " …" << endl; + } } // Cancel the stream, … diff --git a/include/connection.hpp b/include/connection.hpp index b32acea..6885931 100644 --- a/include/connection.hpp +++ b/include/connection.hpp @@ -25,6 +25,7 @@ #include #include #include +#include namespace mastodonpp { @@ -32,6 +33,7 @@ namespace mastodonpp using std::string; using std::string_view; using std::variant; +using std::vector; /*! * @brief An endpoint. Either API::endpoint_type or `std::string_view`. @@ -40,6 +42,29 @@ using std::variant; */ using endpoint_variant = variant; +/*! + * @brief A stream event. + * + * @since 0.1.0 + * + * @headerfile connection.hpp mastodonpp/connection.hpp + */ +struct event_type +{ + /*! + * @brief The type of the event. + * + * Can be: “update”, “notification”, “delete” or “filters_changed”. For + * more information consult [the Mastodon documentation] + * (https://docs.joinmastodon.org/methods/timelines/streaming/ + * #event-types-a-idevent-typesa). + */ + string type; + + //! The payload. + string data; +}; + /*! * @brief Represents a connection to an instance. Used for requests. * @@ -106,10 +131,19 @@ public: * that you are calling this function mid-transfer. You have to check the * data integrity yourself. * + * Using get_new_events() instead is recommended. + * * @since 0.1.0 */ string get_new_stream_contents(); + /*! + * @brief Get new stream events. + * + * @since 0.1.0 + */ + vector get_new_events(); + private: Instance &_instance; const string_view _baseuri; diff --git a/src/connection.cpp b/src/connection.cpp index 0deaed8..4046d6c 100644 --- a/src/connection.cpp +++ b/src/connection.cpp @@ -58,4 +58,33 @@ string Connection::get_new_stream_contents() return buffer_copy; } +vector Connection::get_new_events() +{ + buffer_mutex.lock(); + auto &buffer{get_buffer()}; + vector events; + + size_t pos{0}; + while ((pos = buffer.find("event: ")) != string::npos) + { + const auto endpos{buffer.find("\n\n", pos)}; + if (endpos == string::npos) + { + break; + } + + event_type event; + pos += 7; // Length of "event: ". + event.type = buffer.substr(pos, buffer.find('\n', pos) - pos); + pos = buffer.find("data: ") + 6; + event.data = buffer.substr(pos, endpos - pos); + events.push_back(event); + + buffer.erase(0, endpos); + } + + buffer_mutex.unlock(); + return events; +} + } // namespace mastodonpp From bf82525c5ee85671ba470a9129f875425a0aa4a3 Mon Sep 17 00:00:00 2001 From: tastytea Date: Thu, 9 Jan 2020 13:12:50 +0100 Subject: [PATCH 06/15] Add baseurl to uri if endpoint is string_view. --- src/connection.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/connection.cpp b/src/connection.cpp index 4046d6c..662c333 100644 --- a/src/connection.cpp +++ b/src/connection.cpp @@ -42,7 +42,7 @@ answer_type Connection::get(const endpoint_variant &endpoint, return string(_baseuri) += API{std::get(endpoint)}.to_string_view(); } - return string(std::get(endpoint)); + return string(_baseuri) += std::get(endpoint); }()}; return make_request(http_method::GET, uri, parameters); From bb6b00114e805d56267eda2e0554d7c35489cefd Mon Sep 17 00:00:00 2001 From: tastytea Date: Thu, 9 Jan 2020 13:13:49 +0100 Subject: [PATCH 07/15] Clear buffers before making a request. --- src/curl_wrapper.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/curl_wrapper.cpp b/src/curl_wrapper.cpp index 930e840..f675cca 100644 --- a/src/curl_wrapper.cpp +++ b/src/curl_wrapper.cpp @@ -84,6 +84,8 @@ answer_type CURLWrapper::make_request(const http_method &method, string uri, const parametermap ¶meters) { _stream_cancelled = false; + _curl_buffer_headers.clear(); + _curl_buffer_body.clear(); CURLcode code; switch (method) From 447fc05dbe96136712d43c2e745e1978f2af213b Mon Sep 17 00:00:00 2001 From: tastytea Date: Thu, 9 Jan 2020 13:56:20 +0100 Subject: [PATCH 08/15] Add get_header() to answer_type. --- include/answer.hpp | 9 +++++++++ src/answer.cpp | 25 +++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/include/answer.hpp b/include/answer.hpp index 2eb05aa..56a8324 100644 --- a/include/answer.hpp +++ b/include/answer.hpp @@ -99,6 +99,15 @@ struct answer_type */ friend std::ostream &operator <<(std::ostream &out, const answer_type &answer); + + /*! + * @brief Returns the value of a header field. + * + * Case insensitive, only ASCII. + * + * @since 0.1.0 + */ + string_view get_header(string_view field) const; }; } // namespace mastodonpp diff --git a/src/answer.cpp b/src/answer.cpp index 8006f90..8cc9236 100644 --- a/src/answer.cpp +++ b/src/answer.cpp @@ -16,9 +16,15 @@ #include "answer.hpp" +#include +#include + namespace mastodonpp { +using std::search; +using std::tolower; + answer_type::operator bool() const { return (curl_error_code == 0 && http_status == 200); @@ -35,4 +41,23 @@ std::ostream &operator <<(std::ostream &out, const answer_type &answer) return out; } +string_view answer_type::get_header(const string_view field) const +{ + const string_view searchstring{string(field) += ':'}; + auto it{search(headers.begin(), headers.end(), + searchstring.begin(), searchstring.end(), + [](unsigned char a, unsigned char b) + { return tolower(a) == tolower(b); })}; + + if (it != headers.end()) + { + auto pos{static_cast(it - headers.begin())}; + pos = headers.find(':', pos) + 2; + const auto endpos{headers.find('\n', pos)}; + return headers.substr(pos, endpos - pos); + } + + return {}; +} + } // namespace mastodonpp From 913130b57d07a5e5e4e5be5bfc31185f9c576e8f Mon Sep 17 00:00:00 2001 From: tastytea Date: Thu, 9 Jan 2020 15:16:04 +0100 Subject: [PATCH 09/15] =?UTF-8?q?Escape=20keyword=20=E2=80=9CAPI=E2=80=9D?= =?UTF-8?q?=20in=20documentation.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/curl_wrapper.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/curl_wrapper.hpp b/include/curl_wrapper.hpp index 1ff1d07..fc3bf3f 100644 --- a/include/curl_wrapper.hpp +++ b/include/curl_wrapper.hpp @@ -53,7 +53,7 @@ enum class http_method }; /*! - * @brief std::map of parameters for API calls. + * @brief std::map of parameters for %API calls. * * Example: * @code From 7ba967a36cead5cb79c6ef7911873cf5eae2775d Mon Sep 17 00:00:00 2001 From: tastytea Date: Thu, 9 Jan 2020 15:54:52 +0100 Subject: [PATCH 10/15] Fix answer_type::get_header(). The previous implementation returned a reference to an out-of-scope string. --- include/answer.hpp | 4 +++- src/answer.cpp | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/include/answer.hpp b/include/answer.hpp index 56a8324..b0cafdf 100644 --- a/include/answer.hpp +++ b/include/answer.hpp @@ -103,7 +103,9 @@ struct answer_type /*! * @brief Returns the value of a header field. * - * Case insensitive, only ASCII. + * Is only valid for as long as the answer_type is in scope. + * + * @param field Case insensitive, only ASCII. * * @since 0.1.0 */ diff --git a/src/answer.cpp b/src/answer.cpp index 8cc9236..0db9176 100644 --- a/src/answer.cpp +++ b/src/answer.cpp @@ -54,7 +54,7 @@ string_view answer_type::get_header(const string_view field) const auto pos{static_cast(it - headers.begin())}; pos = headers.find(':', pos) + 2; const auto endpos{headers.find('\n', pos)}; - return headers.substr(pos, endpos - pos); + return string_view(&headers[pos], endpos - pos); } return {}; From 3f161e866ff1c77593b76574c0e00b62cd8b9454 Mon Sep 17 00:00:00 2001 From: tastytea Date: Thu, 9 Jan 2020 16:18:47 +0100 Subject: [PATCH 11/15] Add packages.cmake, to create DEB and RPM packages. --- CMakeLists.txt | 2 +- README.adoc | 4 ++-- cmake/packages.cmake | 55 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 cmake/packages.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index f634f80..20ffaf9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,4 +48,4 @@ if(WITH_EXAMPLES) add_subdirectory(examples) endif() -# include(cmake/packages.cmake) +include(cmake/packages.cmake) diff --git a/README.adoc b/README.adoc index 921ec56..cadfe1a 100644 --- a/README.adoc +++ b/README.adoc @@ -88,8 +88,8 @@ link:{uri-reference}/examples.html[More examples] are included in the reference. * Optional ** Documentation: link:{uri-doxygen}[Doxygen] (tested: 1.8) ** Tests: link:{uri-catch}[Catch] (tested: 2.5 / 1.2) -// ** DEB package: link:{uri-dpkg}[dpkg] (tested: 1.18) -// ** RPM package: link:{uri-rpm-build}[rpm-build] (tested: 4.11) + ** DEB package: link:{uri-dpkg}[dpkg] (tested: 1.18) + ** RPM package: link:{uri-rpm-build}[rpm-build] (tested: 4.11) ==== Get sourcecode diff --git a/cmake/packages.cmake b/cmake/packages.cmake new file mode 100644 index 0000000..464b04b --- /dev/null +++ b/cmake/packages.cmake @@ -0,0 +1,55 @@ +set(CPACK_PACKAGE_NAME ${PROJECT_NAME}) +set(CPACK_PACKAGE_VERSION_MAJOR ${${PROJECT_NAME}_VERSION_MAJOR}) +set(CPACK_PACKAGE_VERSION_MINOR ${${PROJECT_NAME}_VERSION_MINOR}) +set(CPACK_PACKAGE_VERSION_PATCH ${${PROJECT_NAME}_VERSION_PATCH}) +set(CPACK_PACKAGE_VERSION ${${PROJECT_NAME}_VERSION}) +set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "${PROJECT_DESCRIPTION}") +set(CPACK_PACKAGE_CONTACT "tastytea ") +set(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE") +set(CPACK_RESOURCE_FILE_README "${PROJECT_SOURCE_DIR}/README.adoc") + +execute_process(COMMAND uname -m + OUTPUT_VARIABLE CPACK_PACKAGE_ARCHITECTURE OUTPUT_STRIP_TRAILING_WHITESPACE) +set(CPACK_PACKAGE_FILE_NAME + "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}_${CPACK_PACKAGE_ARCHITECTURE}") +set(CPACK_GENERATOR "TGZ") + +if(WITH_DEB) + set(CPACK_PACKAGE_NAME "lib${PROJECT_NAME}") + set(CPACK_GENERATOR "DEB") + set(CPACK_DEBIAN_PACKAGE_HOMEPAGE + "https://schlomp.space/tastytea/${PROJECT_NAME}") + set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON) + + execute_process(COMMAND dpkg --print-architecture + OUTPUT_VARIABLE CPACK_DEBIAN_PACKAGE_ARCHITECTURE + OUTPUT_STRIP_TRAILING_WHITESPACE) + execute_process(COMMAND lsb_release --codename --short + OUTPUT_VARIABLE DEBIAN_CODENAME + OUTPUT_STRIP_TRAILING_WHITESPACE) + set(CPACK_PACKAGE_FILE_NAME + "${CPACK_PACKAGE_NAME}_${CPACK_PACKAGE_VERSION}-0_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}_${DEBIAN_CODENAME}") +endif() + +if(WITH_RPM) + set(CPACK_PACKAGE_NAME "lib${PROJECT_NAME}") + set(CPACK_GENERATOR "RPM") + set(CPACK_RPM_PACKAGE_LICENSE "AGPL-3") + set(CPACK_RPM_PACKAGE_URL "https://schlomp.space/tastytea/${PROJECT_NAME}") + set(CPACK_RPM_PACKAGE_REQUIRES "libcurl >= 7.32") + + set(CPACK_PACKAGE_FILE_NAME + "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-0.${CPACK_PACKAGE_ARCHITECTURE}") + execute_process(COMMAND lsb_release --id --short + OUTPUT_VARIABLE OS + OUTPUT_STRIP_TRAILING_WHITESPACE) + if("${OS}" STREQUAL "CentOS") + execute_process(COMMAND rpm -E %{rhel} + OUTPUT_VARIABLE OS_RELEASE + OUTPUT_STRIP_TRAILING_WHITESPACE) + set(CPACK_PACKAGE_FILE_NAME + "${CPACK_PACKAGE_FILE_NAME}.centos${OS_RELEASE}") + endif() +endif() + +include(CPack) From 10ca8e96efd498e1c0c76c0835756c7403bd79b8 Mon Sep 17 00:00:00 2001 From: tastytea Date: Thu, 9 Jan 2020 16:33:25 +0100 Subject: [PATCH 12/15] CI: Build packages for Debian buster and Ubuntu bionic. --- .drone.yml | 115 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 114 insertions(+), 1 deletion(-) diff --git a/.drone.yml b/.drone.yml index af71b07..4e62c21 100644 --- a/.drone.yml +++ b/.drone.yml @@ -1,6 +1,6 @@ # -*- fill-column: 1000 -*- kind: pipeline -name: build x86_64 +name: Build x86_64 volumes: - name: debian-package-cache @@ -83,3 +83,116 @@ steps: from_secret: email_password when: status: [ changed, failure ] + +--- +kind: pipeline +name: Packages x86_64 + + +volumes: +- name: debian-package-cache + host: + path: /var/cache/debian-package-cache +- name: centos-package-cache + host: + path: /var/cache/centos-package-cache + +trigger: + event: + - tag + +steps: +- name: Debian buster + image: debian:buster-slim + pull: always + environment: + CXX: g++-8 + CXXFLAGS: -pipe -O2 + DEBIAN_FRONTEND: noninteractive + LANG: C.utf8 + commands: + - rm /etc/apt/apt.conf.d/docker-clean + - alias apt-get='rm -f /var/cache/apt/archives/lock && apt-get' + - apt-get update -q + - apt-get install -qq build-essential cmake lsb-release + - apt-get install -qq libcurl4-openssl-dev + - rm -rf build && mkdir -p build && cd build + - cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX=/usr -WITH_DEB=YES .. + - make VERBOSE=1 + - make install DESTDIR=install + - make package + - cp -v libmastodon-cpp_${DRONE_TAG}-0_amd64_buster.deb .. + volumes: + - name: debian-package-cache + path: /var/cache/apt/archives + +- name: Ubuntu bionic + image: ubuntu:bionic + pull: always + environment: + CXX: g++-7 + CXXFLAGS: -pipe -O2 + DEBIAN_FRONTEND: noninteractive + LANG: C.utf8 + commands: + - rm /etc/apt/apt.conf.d/docker-clean + - alias apt-get='rm -f /var/cache/apt/archives/lock && apt-get' + - apt-get update -q + - apt-get install -qq build-essential cmake lsb-release + - apt-get install -qq libcurl4-openssl-dev + - rm -rf build && mkdir -p build && cd build + - cmake -G "Unix Makefiles" -SCMAKE_INSTALL_PREFIX=/usr -WITH_DEB=YES .. + - make VERBOSE=1 + - make install DESTDIR=install + - make package + - cp -v libmastodon-cpp_${DRONE_TAG}-0_amd64_bionic.deb .. + volumes: + - name: debian-package-cache + path: /var/cache/apt/archives + +- name: CentOS 8 + image: centos:8 + pull: always + environment: + CXX: g++ + CXXFLAGS: -pipe -O2 + LANG: C.utf8 + commands: + - sed -i 's/keepcache=0/keepcache=1/' /etc/yum.conf + - yum install -qy gcc-c++ cmake rpm-build redhat-lsb-core + - yum install -qy libcurl-devel + - rm -rf build && mkdir -p build && cd build + - cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX=/usr -WITH_RPM=YES .. + - make + - make install DESTDIR=install + - make package + - cp -v libmastodonpp-${DRONE_TAG}-0.x86_64.centos8.rpm .. + +- name: gitea_release + image: plugins/gitea-release + pull: always + settings: + base_url: https://schlomp.space + api_key: + from_secret: gitea_token + title: ${DRONE_TAG} + prerelease: true + files: + - libmastodonpp_${DRONE_TAG}-0_buster_amd64.deb + - libmastodonpp_${DRONE_TAG}-0_bionic_amd64.deb + - libmastodonpp-${DRONE_TAG}-0.x86_64.centos8.rpm + checksum: + - sha512 + +- name: notification + image: drillster/drone-email + pull: always + settings: + host: cryptoparty-celle.de + from: drone@tzend.de + username: + from_secret: email_username + password: + from_secret: email_password + when: + status: [ changed, failure ] From 7228bf8e6c11544aaecbaf9ae9078ad336f0dc46 Mon Sep 17 00:00:00 2001 From: tastytea Date: Thu, 9 Jan 2020 18:16:04 +0100 Subject: [PATCH 13/15] Enable cmake switches for packages. --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 20ffaf9..146ff24 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,8 +20,8 @@ list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") # Project build options. option(WITH_TESTS "Compile tests." NO) option(WITH_EXAMPLES "Compile examples." NO) -# option(WITH_DEB "Prepare for the building of .deb packages." NO) -# option(WITH_RPM "Prepare for the building of .rpm packages." NO) +option(WITH_DEB "Prepare for the building of .deb packages." NO) +option(WITH_RPM "Prepare for the building of .rpm packages." NO) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) From b630ef3b2e93c25f942041bf60cde0dddd26f35a Mon Sep 17 00:00:00 2001 From: tastytea Date: Thu, 9 Jan 2020 18:31:01 +0100 Subject: [PATCH 14/15] CI: Fix cmake arguments. --- .drone.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.drone.yml b/.drone.yml index 4e62c21..7b5a0c7 100644 --- a/.drone.yml +++ b/.drone.yml @@ -117,8 +117,8 @@ steps: - apt-get install -qq build-essential cmake lsb-release - apt-get install -qq libcurl4-openssl-dev - rm -rf build && mkdir -p build && cd build - - cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX=/usr -WITH_DEB=YES .. - - make VERBOSE=1 + - cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX=/usr -DWITH_DEB=YES .. + - make - make install DESTDIR=install - make package - cp -v libmastodon-cpp_${DRONE_TAG}-0_amd64_buster.deb .. @@ -141,8 +141,8 @@ steps: - apt-get install -qq build-essential cmake lsb-release - apt-get install -qq libcurl4-openssl-dev - rm -rf build && mkdir -p build && cd build - - cmake -G "Unix Makefiles" -SCMAKE_INSTALL_PREFIX=/usr -WITH_DEB=YES .. - - make VERBOSE=1 + - cmake -G "Unix Makefiles" -SCMAKE_INSTALL_PREFIX=/usr -DWITH_DEB=YES .. + - make - make install DESTDIR=install - make package - cp -v libmastodon-cpp_${DRONE_TAG}-0_amd64_bionic.deb .. @@ -162,7 +162,7 @@ steps: - yum install -qy gcc-c++ cmake rpm-build redhat-lsb-core - yum install -qy libcurl-devel - rm -rf build && mkdir -p build && cd build - - cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX=/usr -WITH_RPM=YES .. + - cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX=/usr -DWITH_RPM=YES .. - make - make install DESTDIR=install - make package From 20e3dc5e095449fff1c782366b2b1408d5e825fd Mon Sep 17 00:00:00 2001 From: tastytea Date: Thu, 9 Jan 2020 18:31:14 +0100 Subject: [PATCH 15/15] Fix RPM conflicts with pkg-config and cmake. --- cmake/packages.cmake | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cmake/packages.cmake b/cmake/packages.cmake index 464b04b..f14d273 100644 --- a/cmake/packages.cmake +++ b/cmake/packages.cmake @@ -1,3 +1,5 @@ +include(GNUInstallDirs) + set(CPACK_PACKAGE_NAME ${PROJECT_NAME}) set(CPACK_PACKAGE_VERSION_MAJOR ${${PROJECT_NAME}_VERSION_MAJOR}) set(CPACK_PACKAGE_VERSION_MINOR ${${PROJECT_NAME}_VERSION_MINOR}) @@ -37,6 +39,9 @@ if(WITH_RPM) set(CPACK_RPM_PACKAGE_LICENSE "AGPL-3") set(CPACK_RPM_PACKAGE_URL "https://schlomp.space/tastytea/${PROJECT_NAME}") set(CPACK_RPM_PACKAGE_REQUIRES "libcurl >= 7.32") + list(APPEND CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION + "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/cmake" + "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/pkgconfig") set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-0.${CPACK_PACKAGE_ARCHITECTURE}")