From b1ae75e259d73b3b2be5334d62098389d37135da Mon Sep 17 00:00:00 2001 From: Oliver Giles Date: Thu, 28 May 2026 19:44:38 +1200 Subject: [PATCH] Minor modernizations resolves #235 --- CMakeLists.txt | 13 +++++++------ README.md | 2 +- src/conf.h | 7 ++----- src/context.h | 7 ++----- src/database.h | 6 ++---- src/http.h | 6 ++---- src/laminar.h | 7 +++---- src/leader.h | 6 ++---- src/log.h | 7 ++----- src/monitorscope.h | 7 ++----- src/resources.h | 6 ++---- src/rpc.h | 6 ++---- src/run.h | 15 +++++---------- src/server.cpp | 10 ++++------ src/server.h | 6 ++---- test/eventsource.h | 2 +- 16 files changed, 41 insertions(+), 72 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 81fe1e3..57629e7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ ### -### Copyright 2015-2024 Oliver Giles +### Copyright 2015-2026 Oliver Giles ### ### This file is part of Laminar ### @@ -16,7 +16,7 @@ ### You should have received a copy of the GNU General Public License ### along with Laminar. If not, see ### -cmake_minimum_required(VERSION 3.6) +cmake_minimum_required(VERSION 3.18) project(laminar) if (${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD") @@ -57,7 +57,7 @@ if (LLVM_LINKER_IS_LLD) endif() set(CMAKE_INCLUDE_CURRENT_DIR ON) -set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wno-unused-parameter -Wno-sign-compare") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Werror -DDEBUG") @@ -160,8 +160,8 @@ include_directories(${Threads_INCLUDE_DIRS}) ## Server add_executable(laminard ${LAMINARD_CORE_SOURCES} src/main.cpp ${COMPRESSED_BINS}) -target_link_libraries(laminard CapnProto::capnp-rpc CapnProto::capnp CapnProto::kj-http CapnProto::kj-async - CapnProto::kj Threads::Threads SQLite::SQLite3 ZLIB::ZLIB) +target_link_libraries(laminard CapnProto::capnp-rpc CapnProto::capnp CapnProto::kj-http CapnProto::kj-async + CapnProto::kj Threads::Threads SQLite3::SQLite3 ZLIB::ZLIB) if (${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD") pkg_check_modules(INOTIFY REQUIRED libinotify) @@ -191,7 +191,8 @@ if(BUILD_TESTS) find_package(GTest REQUIRED) include_directories(${GTEST_INCLUDE_DIRS} src) add_executable(laminar-tests ${LAMINARD_CORE_SOURCES} ${COMPRESSED_BINS} test/main.cpp test/laminar-functional.cpp test/unit-conf.cpp test/unit-database.cpp) - target_link_libraries(laminar-tests ${GTEST_LIBRARIES} capnp-rpc capnp kj-http kj-async kj pthread sqlite3 z) + target_link_libraries(laminar-tests ${GTEST_LIBRARIES} CapnProto::capnp-rpc CapnProto::capnp CapnProto::kj-http CapnProto::kj-async CapnProto::kj + Threads::Threads SQLite3::SQLite3 ZLIB::ZLIB) endif() set(BASH_COMPLETIONS_DIR /usr/share/bash-completion/completions CACHE PATH "Path to bash completions directory") diff --git a/README.md b/README.md index 685a0e6..1b1a078 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ See [the website](https://laminar.ohwg.net) and the [documentation](https://lami First install development packages for `capnproto (version 0.7.0 or newer)`, `rapidjson`, `sqlite` and `boost` (for the header-only `multi_index_container` library) from your distribution's repository or other source. -On Debian Bookworm, this can be done with: +On Debian 13 (Trixie), this can be done with: ```bash sudo apt install capnproto cmake g++ libboost-dev libcapnp-dev libsqlite3-dev \ diff --git a/src/conf.h b/src/conf.h index bc355a7..7e5c63e 100644 --- a/src/conf.h +++ b/src/conf.h @@ -1,5 +1,5 @@ /// -/// Copyright 2015 Oliver Giles +/// Copyright 2015-2026 Oliver Giles /// /// This file is part of Laminar /// @@ -16,8 +16,7 @@ /// You should have received a copy of the GNU General Public License /// along with Laminar. If not, see /// -#ifndef LAMINAR_CONF_H_ -#define LAMINAR_CONF_H_ +#pragma once #include #include @@ -41,5 +40,3 @@ int StringMap::convert(std::string e); // beginning with '#' StringMap parseConfFile(const char* path); - -#endif // LAMINAR_CONF_H_ diff --git a/src/context.h b/src/context.h index 7ae1b0b..53cc841 100644 --- a/src/context.h +++ b/src/context.h @@ -1,5 +1,5 @@ /// -/// Copyright 2015-2020 Oliver Giles +/// Copyright 2015-2026 Oliver Giles /// /// This file is part of Laminar /// @@ -16,8 +16,7 @@ /// You should have received a copy of the GNU General Public License /// along with Laminar. If not, see /// -#ifndef LAMINAR_CONTEXT_H_ -#define LAMINAR_CONTEXT_H_ +#pragma once #include #include @@ -36,5 +35,3 @@ public: std::set jobPatterns; }; - -#endif // LAMINAR_CONTEXT_H_ diff --git a/src/database.h b/src/database.h index 56ded6a..d84a8be 100644 --- a/src/database.h +++ b/src/database.h @@ -1,5 +1,5 @@ /// -/// Copyright 2015-2018 Oliver Giles +/// Copyright 2015-2026 Oliver Giles /// /// This file is part of Laminar /// @@ -16,8 +16,7 @@ /// You should have received a copy of the GNU General Public License /// along with Laminar. If not, see /// -#ifndef LAMINAR_DATABASE_H_ -#define LAMINAR_DATABASE_H_ +#pragma once #include #include @@ -157,4 +156,3 @@ template<> long Database::Statement::fetchColumn(int col); template<> ulong Database::Statement::fetchColumn(int col); template<> double Database::Statement::fetchColumn(int col); -#endif // LAMINAR_DATABASE_H_ diff --git a/src/http.h b/src/http.h index fc8db5a..df00c14 100644 --- a/src/http.h +++ b/src/http.h @@ -1,5 +1,5 @@ /// -/// Copyright 2019-2020 Oliver Giles +/// Copyright 2019-2026 Oliver Giles /// /// This file is part of Laminar /// @@ -16,8 +16,7 @@ /// You should have received a copy of the GNU General Public License /// along with Laminar. If not, see /// -#ifndef LAMINAR_HTTP_H_ -#define LAMINAR_HTTP_H_ +#pragma once #include #include @@ -66,4 +65,3 @@ private: kj::HttpHeaderId ACCEPT; }; -#endif //LAMINAR_HTTP_H_ diff --git a/src/laminar.h b/src/laminar.h index a983c09..e369c56 100644 --- a/src/laminar.h +++ b/src/laminar.h @@ -1,5 +1,5 @@ /// -/// Copyright 2015-2022 Oliver Giles +/// Copyright 2015-2026 Oliver Giles /// /// This file is part of Laminar /// @@ -16,14 +16,14 @@ /// You should have received a copy of the GNU General Public License /// along with Laminar. If not, see /// -#ifndef LAMINAR_LAMINAR_H_ -#define LAMINAR_LAMINAR_H_ +#pragma once #include "run.h" #include "monitorscope.h" #include "context.h" #include "database.h" +#include #include #include #include @@ -134,4 +134,3 @@ private: kj::Own rpc; }; -#endif // LAMINAR_LAMINAR_H_ diff --git a/src/leader.h b/src/leader.h index 2da6095..1ba3448 100644 --- a/src/leader.h +++ b/src/leader.h @@ -1,5 +1,5 @@ /// -/// Copyright 2019 Oliver Giles +/// Copyright 2019-2026 Oliver Giles /// /// This file is part of Laminar /// @@ -16,8 +16,7 @@ /// You should have received a copy of the GNU General Public License /// along with Laminar. If not, see /// -#ifndef LAMINAR_LEADER_H_ -#define LAMINAR_LEADER_H_ +#pragma once // Main function for the leader process which is responsible for // executing all the scripts which make up a Run. Separating this @@ -33,4 +32,3 @@ int leader_main(void); -#endif // LAMINAR_LEADER_H_ diff --git a/src/log.h b/src/log.h index a0ccff4..c3f546c 100644 --- a/src/log.h +++ b/src/log.h @@ -1,5 +1,5 @@ /// -/// Copyright 2015-2020 Oliver Giles +/// Copyright 2015-2026 Oliver Giles /// /// This file is part of Laminar /// @@ -16,8 +16,7 @@ /// You should have received a copy of the GNU General Public License /// along with Laminar. If not, see /// -#ifndef LAMINAR_LOG_H_ -#define LAMINAR_LOG_H_ +#pragma once #include #include @@ -69,5 +68,3 @@ namespace _ { const char* laminar_version(); -#endif // LAMINAR_LOG_H_ - diff --git a/src/monitorscope.h b/src/monitorscope.h index 987eafe..c46f359 100644 --- a/src/monitorscope.h +++ b/src/monitorscope.h @@ -1,5 +1,5 @@ /// -/// Copyright 2015-2019 Oliver Giles +/// Copyright 2015-2026 Oliver Giles /// /// This file is part of Laminar /// @@ -16,8 +16,7 @@ /// You should have received a copy of the GNU General Public License /// along with Laminar. If not, see /// -#ifndef LAMINAR_MONITORSCOPE_H_ -#define LAMINAR_MONITORSCOPE_H_ +#pragma once #include @@ -59,5 +58,3 @@ struct MonitorScope { bool order_desc; }; -#endif // LAMINAR_MONITORSCOPE_H_ - diff --git a/src/resources.h b/src/resources.h index 1f8f951..edf1923 100644 --- a/src/resources.h +++ b/src/resources.h @@ -1,5 +1,5 @@ /// -/// Copyright 2015-2019 Oliver Giles +/// Copyright 2015-2026 Oliver Giles /// /// This file is part of Laminar /// @@ -16,8 +16,7 @@ /// You should have received a copy of the GNU General Public License /// along with Laminar. If not, see /// -#ifndef LAMINAR_RESOURCES_H_ -#define LAMINAR_RESOURCES_H_ +#pragma once #include #include @@ -47,4 +46,3 @@ private: std::string index_html; }; -#endif // LAMINAR_RESOURCES_H_ diff --git a/src/rpc.h b/src/rpc.h index 0f55d2c..ff60d8d 100644 --- a/src/rpc.h +++ b/src/rpc.h @@ -1,5 +1,5 @@ /// -/// Copyright 2019-2020 Oliver Giles +/// Copyright 2019-2026 Oliver Giles /// /// This file is part of Laminar /// @@ -16,8 +16,7 @@ /// You should have received a copy of the GNU General Public License /// along with Laminar. If not, see /// -#ifndef LAMINAR_RPC_H_ -#define LAMINAR_RPC_H_ +#pragma once #include #include @@ -33,4 +32,3 @@ public: capnp::Capability::Client rpcInterface; }; -#endif //LAMINAR_RPC_H_ diff --git a/src/run.h b/src/run.h index 7e9e67f..d1a0d28 100644 --- a/src/run.h +++ b/src/run.h @@ -1,5 +1,5 @@ /// -/// Copyright 2015-2018 Oliver Giles +/// Copyright 2015-2026 Oliver Giles /// /// This file is part of Laminar /// @@ -16,14 +16,10 @@ /// You should have received a copy of the GNU General Public License /// along with Laminar. If not, see /// -#ifndef LAMINAR_RUN_H_ -#define LAMINAR_RUN_H_ +#pragma once #include -#include -#include #include -#include #include #include #include @@ -109,6 +105,7 @@ private: // be executing thousands of builds at the same time #include #include +#include #include #include #include @@ -125,7 +122,7 @@ struct _run_same { }; // A single Run can be fetched by... -struct _run_index : bmi::indexed_by< +typedef bmi::indexed_by< bmi::hashed_unique, // a combination of their job name and build number @@ -138,8 +135,7 @@ struct _run_index : bmi::indexed_by< bmi::ordered_non_unique>, // or by their job name bmi::ordered_non_unique> - > -{}; + > _run_index; struct RunSet: public boost::multi_index_container< std::shared_ptr, @@ -158,4 +154,3 @@ struct RunSet: public boost::multi_index_container< typename bmi::nth_index::type const& byJobName() const { return get<3>(); } }; -#endif // LAMINAR_RUN_H_ diff --git a/src/server.cpp b/src/server.cpp index 06cbbba..1fd5b22 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -1,5 +1,5 @@ /// -/// Copyright 2015-2021 Oliver Giles +/// Copyright 2015-2026 Oliver Giles /// /// This file is part of Laminar /// @@ -26,7 +26,6 @@ #include #include -#include #include #include #include @@ -149,11 +148,10 @@ void Server::listenHttp(Http &http, kj::StringPtr httpBindAddress) kj::Promise Server::acceptRpcClient(Rpc& rpc, kj::Own&& listener) { kj::ConnectionReceiver& cr = *listener.get(); - return cr.accept().then(kj::mvCapture(kj::mv(listener), - [this, &rpc](kj::Own&& listener, kj::Own&& connection) { + return cr.accept().then([this, &rpc, l = kj::mv(listener)](kj::Own&& connection) mutable { addTask(rpc.accept(kj::mv(connection))); - return acceptRpcClient(rpc, kj::mv(listener)); - })); + return acceptRpcClient(rpc, kj::mv(l)); + }); } // returns a promise which will read a chunk of data from the file descriptor diff --git a/src/server.h b/src/server.h index d0433da..66d5f1c 100644 --- a/src/server.h +++ b/src/server.h @@ -1,5 +1,5 @@ /// -/// Copyright 2015-2020 Oliver Giles +/// Copyright 2015-2026 Oliver Giles /// /// This file is part of Laminar /// @@ -16,8 +16,7 @@ /// You should have received a copy of the GNU General Public License /// along with Laminar. If not, see /// -#ifndef LAMINAR_SERVER_H_ -#define LAMINAR_SERVER_H_ +#pragma once #include #include @@ -72,4 +71,3 @@ private: kj::Maybe> reapWatch; }; -#endif // LAMINAR_SERVER_H_ diff --git a/test/eventsource.h b/test/eventsource.h index c124381..1c66751 100644 --- a/test/eventsource.h +++ b/test/eventsource.h @@ -52,7 +52,7 @@ private: std::vector receivedMessages; kj::Promise waitForMessages(kj::AsyncInputStream* stream, ulong offset) { - return stream->read(buffer.asPtr().begin() + offset, 1, BUFFER_SIZE).then([=](size_t s) { + return stream->read(buffer.asPtr().begin() + offset, 1, BUFFER_SIZE).then([=, this](size_t s) { ulong end = offset + s; buffer.asPtr().begin()[end] = '\0'; if(strcmp(&buffer.asPtr().begin()[end - 2], "\n\n") == 0) {