1
0
mirror of https://github.com/ohwgiles/laminar.git synced 2026-10-08 11:53:00 +00:00

Minor modernizations

resolves #235
This commit is contained in:
Oliver Giles
2026-05-28 19:44:38 +12:00
parent 3392b899b2
commit b1ae75e259
16 changed files with 41 additions and 72 deletions

View File

@@ -1,5 +1,5 @@
### ###
### Copyright 2015-2024 Oliver Giles ### Copyright 2015-2026 Oliver Giles
### ###
### This file is part of Laminar ### This file is part of Laminar
### ###
@@ -16,7 +16,7 @@
### You should have received a copy of the GNU General Public License ### You should have received a copy of the GNU General Public License
### along with Laminar. If not, see <http://www.gnu.org/licenses/> ### along with Laminar. If not, see <http://www.gnu.org/licenses/>
### ###
cmake_minimum_required(VERSION 3.6) cmake_minimum_required(VERSION 3.18)
project(laminar) project(laminar)
if (${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD") if (${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD")
@@ -57,7 +57,7 @@ if (LLVM_LINKER_IS_LLD)
endif() endif()
set(CMAKE_INCLUDE_CURRENT_DIR ON) 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 "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wno-unused-parameter -Wno-sign-compare")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Werror -DDEBUG") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Werror -DDEBUG")
@@ -160,8 +160,8 @@ include_directories(${Threads_INCLUDE_DIRS})
## Server ## Server
add_executable(laminard ${LAMINARD_CORE_SOURCES} src/main.cpp ${COMPRESSED_BINS}) 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 target_link_libraries(laminard CapnProto::capnp-rpc CapnProto::capnp CapnProto::kj-http CapnProto::kj-async
CapnProto::kj Threads::Threads SQLite::SQLite3 ZLIB::ZLIB) CapnProto::kj Threads::Threads SQLite3::SQLite3 ZLIB::ZLIB)
if (${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD") if (${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD")
pkg_check_modules(INOTIFY REQUIRED libinotify) pkg_check_modules(INOTIFY REQUIRED libinotify)
@@ -191,7 +191,8 @@ if(BUILD_TESTS)
find_package(GTest REQUIRED) find_package(GTest REQUIRED)
include_directories(${GTEST_INCLUDE_DIRS} src) 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) 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() endif()
set(BASH_COMPLETIONS_DIR /usr/share/bash-completion/completions CACHE PATH "Path to bash completions directory") set(BASH_COMPLETIONS_DIR /usr/share/bash-completion/completions CACHE PATH "Path to bash completions directory")

View File

@@ -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. 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 ```bash
sudo apt install capnproto cmake g++ libboost-dev libcapnp-dev libsqlite3-dev \ sudo apt install capnproto cmake g++ libboost-dev libcapnp-dev libsqlite3-dev \

View File

@@ -1,5 +1,5 @@
/// ///
/// Copyright 2015 Oliver Giles /// Copyright 2015-2026 Oliver Giles
/// ///
/// This file is part of Laminar /// This file is part of Laminar
/// ///
@@ -16,8 +16,7 @@
/// You should have received a copy of the GNU General Public License /// You should have received a copy of the GNU General Public License
/// along with Laminar. If not, see <http://www.gnu.org/licenses/> /// along with Laminar. If not, see <http://www.gnu.org/licenses/>
/// ///
#ifndef LAMINAR_CONF_H_ #pragma once
#define LAMINAR_CONF_H_
#include <string> #include <string>
#include <unordered_map> #include <unordered_map>
@@ -41,5 +40,3 @@ int StringMap::convert(std::string e);
// beginning with '#' // beginning with '#'
StringMap parseConfFile(const char* path); StringMap parseConfFile(const char* path);
#endif // LAMINAR_CONF_H_

View File

@@ -1,5 +1,5 @@
/// ///
/// Copyright 2015-2020 Oliver Giles /// Copyright 2015-2026 Oliver Giles
/// ///
/// This file is part of Laminar /// This file is part of Laminar
/// ///
@@ -16,8 +16,7 @@
/// You should have received a copy of the GNU General Public License /// You should have received a copy of the GNU General Public License
/// along with Laminar. If not, see <http://www.gnu.org/licenses/> /// along with Laminar. If not, see <http://www.gnu.org/licenses/>
/// ///
#ifndef LAMINAR_CONTEXT_H_ #pragma once
#define LAMINAR_CONTEXT_H_
#include <string> #include <string>
#include <set> #include <set>
@@ -36,5 +35,3 @@ public:
std::set<std::string> jobPatterns; std::set<std::string> jobPatterns;
}; };
#endif // LAMINAR_CONTEXT_H_

View File

@@ -1,5 +1,5 @@
/// ///
/// Copyright 2015-2018 Oliver Giles /// Copyright 2015-2026 Oliver Giles
/// ///
/// This file is part of Laminar /// This file is part of Laminar
/// ///
@@ -16,8 +16,7 @@
/// You should have received a copy of the GNU General Public License /// You should have received a copy of the GNU General Public License
/// along with Laminar. If not, see <http://www.gnu.org/licenses/> /// along with Laminar. If not, see <http://www.gnu.org/licenses/>
/// ///
#ifndef LAMINAR_DATABASE_H_ #pragma once
#define LAMINAR_DATABASE_H_
#include <string> #include <string>
#include <functional> #include <functional>
@@ -157,4 +156,3 @@ template<> long Database::Statement::fetchColumn(int col);
template<> ulong Database::Statement::fetchColumn(int col); template<> ulong Database::Statement::fetchColumn(int col);
template<> double Database::Statement::fetchColumn(int col); template<> double Database::Statement::fetchColumn(int col);
#endif // LAMINAR_DATABASE_H_

View File

@@ -1,5 +1,5 @@
/// ///
/// Copyright 2019-2020 Oliver Giles /// Copyright 2019-2026 Oliver Giles
/// ///
/// This file is part of Laminar /// This file is part of Laminar
/// ///
@@ -16,8 +16,7 @@
/// You should have received a copy of the GNU General Public License /// You should have received a copy of the GNU General Public License
/// along with Laminar. If not, see <http://www.gnu.org/licenses/> /// along with Laminar. If not, see <http://www.gnu.org/licenses/>
/// ///
#ifndef LAMINAR_HTTP_H_ #pragma once
#define LAMINAR_HTTP_H_
#include <kj/memory.h> #include <kj/memory.h>
#include <kj/compat/http.h> #include <kj/compat/http.h>
@@ -66,4 +65,3 @@ private:
kj::HttpHeaderId ACCEPT; kj::HttpHeaderId ACCEPT;
}; };
#endif //LAMINAR_HTTP_H_

View File

@@ -1,5 +1,5 @@
/// ///
/// Copyright 2015-2022 Oliver Giles /// Copyright 2015-2026 Oliver Giles
/// ///
/// This file is part of Laminar /// This file is part of Laminar
/// ///
@@ -16,14 +16,14 @@
/// You should have received a copy of the GNU General Public License /// You should have received a copy of the GNU General Public License
/// along with Laminar. If not, see <http://www.gnu.org/licenses/> /// along with Laminar. If not, see <http://www.gnu.org/licenses/>
/// ///
#ifndef LAMINAR_LAMINAR_H_ #pragma once
#define LAMINAR_LAMINAR_H_
#include "run.h" #include "run.h"
#include "monitorscope.h" #include "monitorscope.h"
#include "context.h" #include "context.h"
#include "database.h" #include "database.h"
#include <list>
#include <unordered_map> #include <unordered_map>
#include <kj/filesystem.h> #include <kj/filesystem.h>
#include <kj/async-io.h> #include <kj/async-io.h>
@@ -134,4 +134,3 @@ private:
kj::Own<Rpc> rpc; kj::Own<Rpc> rpc;
}; };
#endif // LAMINAR_LAMINAR_H_

View File

@@ -1,5 +1,5 @@
/// ///
/// Copyright 2019 Oliver Giles /// Copyright 2019-2026 Oliver Giles
/// ///
/// This file is part of Laminar /// This file is part of Laminar
/// ///
@@ -16,8 +16,7 @@
/// You should have received a copy of the GNU General Public License /// You should have received a copy of the GNU General Public License
/// along with Laminar. If not, see <http://www.gnu.org/licenses/> /// along with Laminar. If not, see <http://www.gnu.org/licenses/>
/// ///
#ifndef LAMINAR_LEADER_H_ #pragma once
#define LAMINAR_LEADER_H_
// Main function for the leader process which is responsible for // Main function for the leader process which is responsible for
// executing all the scripts which make up a Run. Separating this // executing all the scripts which make up a Run. Separating this
@@ -33,4 +32,3 @@
int leader_main(void); int leader_main(void);
#endif // LAMINAR_LEADER_H_

View File

@@ -1,5 +1,5 @@
/// ///
/// Copyright 2015-2020 Oliver Giles /// Copyright 2015-2026 Oliver Giles
/// ///
/// This file is part of Laminar /// This file is part of Laminar
/// ///
@@ -16,8 +16,7 @@
/// You should have received a copy of the GNU General Public License /// You should have received a copy of the GNU General Public License
/// along with Laminar. If not, see <http://www.gnu.org/licenses/> /// along with Laminar. If not, see <http://www.gnu.org/licenses/>
/// ///
#ifndef LAMINAR_LOG_H_ #pragma once
#define LAMINAR_LOG_H_
#include <kj/debug.h> #include <kj/debug.h>
#include <utility> #include <utility>
@@ -69,5 +68,3 @@ namespace _ {
const char* laminar_version(); const char* laminar_version();
#endif // LAMINAR_LOG_H_

View File

@@ -1,5 +1,5 @@
/// ///
/// Copyright 2015-2019 Oliver Giles /// Copyright 2015-2026 Oliver Giles
/// ///
/// This file is part of Laminar /// This file is part of Laminar
/// ///
@@ -16,8 +16,7 @@
/// You should have received a copy of the GNU General Public License /// You should have received a copy of the GNU General Public License
/// along with Laminar. If not, see <http://www.gnu.org/licenses/> /// along with Laminar. If not, see <http://www.gnu.org/licenses/>
/// ///
#ifndef LAMINAR_MONITORSCOPE_H_ #pragma once
#define LAMINAR_MONITORSCOPE_H_
#include <string> #include <string>
@@ -59,5 +58,3 @@ struct MonitorScope {
bool order_desc; bool order_desc;
}; };
#endif // LAMINAR_MONITORSCOPE_H_

View File

@@ -1,5 +1,5 @@
/// ///
/// Copyright 2015-2019 Oliver Giles /// Copyright 2015-2026 Oliver Giles
/// ///
/// This file is part of Laminar /// This file is part of Laminar
/// ///
@@ -16,8 +16,7 @@
/// You should have received a copy of the GNU General Public License /// You should have received a copy of the GNU General Public License
/// along with Laminar. If not, see <http://www.gnu.org/licenses/> /// along with Laminar. If not, see <http://www.gnu.org/licenses/>
/// ///
#ifndef LAMINAR_RESOURCES_H_ #pragma once
#define LAMINAR_RESOURCES_H_
#include <unordered_map> #include <unordered_map>
#include <utility> #include <utility>
@@ -47,4 +46,3 @@ private:
std::string index_html; std::string index_html;
}; };
#endif // LAMINAR_RESOURCES_H_

View File

@@ -1,5 +1,5 @@
/// ///
/// Copyright 2019-2020 Oliver Giles /// Copyright 2019-2026 Oliver Giles
/// ///
/// This file is part of Laminar /// This file is part of Laminar
/// ///
@@ -16,8 +16,7 @@
/// You should have received a copy of the GNU General Public License /// You should have received a copy of the GNU General Public License
/// along with Laminar. If not, see <http://www.gnu.org/licenses/> /// along with Laminar. If not, see <http://www.gnu.org/licenses/>
/// ///
#ifndef LAMINAR_RPC_H_ #pragma once
#define LAMINAR_RPC_H_
#include <capnp/ez-rpc.h> #include <capnp/ez-rpc.h>
#include <capnp/rpc-twoparty.h> #include <capnp/rpc-twoparty.h>
@@ -33,4 +32,3 @@ public:
capnp::Capability::Client rpcInterface; capnp::Capability::Client rpcInterface;
}; };
#endif //LAMINAR_RPC_H_

View File

@@ -1,5 +1,5 @@
/// ///
/// Copyright 2015-2018 Oliver Giles /// Copyright 2015-2026 Oliver Giles
/// ///
/// This file is part of Laminar /// This file is part of Laminar
/// ///
@@ -16,14 +16,10 @@
/// You should have received a copy of the GNU General Public License /// You should have received a copy of the GNU General Public License
/// along with Laminar. If not, see <http://www.gnu.org/licenses/> /// along with Laminar. If not, see <http://www.gnu.org/licenses/>
/// ///
#ifndef LAMINAR_RUN_H_ #pragma once
#define LAMINAR_RUN_H_
#include <string> #include <string>
#include <queue>
#include <list>
#include <functional> #include <functional>
#include <ostream>
#include <unordered_map> #include <unordered_map>
#include <memory> #include <memory>
#include <kj/async.h> #include <kj/async.h>
@@ -109,6 +105,7 @@ private:
// be executing thousands of builds at the same time // be executing thousands of builds at the same time
#include <boost/multi_index_container.hpp> #include <boost/multi_index_container.hpp>
#include <boost/multi_index/hashed_index.hpp> #include <boost/multi_index/hashed_index.hpp>
#include <boost/multi_index/indexed_by.hpp>
#include <boost/multi_index/member.hpp> #include <boost/multi_index/member.hpp>
#include <boost/multi_index/composite_key.hpp> #include <boost/multi_index/composite_key.hpp>
#include <boost/multi_index/global_fun.hpp> #include <boost/multi_index/global_fun.hpp>
@@ -125,7 +122,7 @@ struct _run_same {
}; };
// A single Run can be fetched by... // A single Run can be fetched by...
struct _run_index : bmi::indexed_by< typedef bmi::indexed_by<
bmi::hashed_unique<bmi::composite_key< bmi::hashed_unique<bmi::composite_key<
std::shared_ptr<Run>, std::shared_ptr<Run>,
// a combination of their job name and build number // a combination of their job name and build number
@@ -138,8 +135,7 @@ struct _run_index : bmi::indexed_by<
bmi::ordered_non_unique<bmi::member<Run, time_t, &Run::startedAt>>, bmi::ordered_non_unique<bmi::member<Run, time_t, &Run::startedAt>>,
// or by their job name // or by their job name
bmi::ordered_non_unique<bmi::member<Run, std::string, &Run::name>> bmi::ordered_non_unique<bmi::member<Run, std::string, &Run::name>>
> > _run_index;
{};
struct RunSet: public boost::multi_index_container< struct RunSet: public boost::multi_index_container<
std::shared_ptr<Run>, std::shared_ptr<Run>,
@@ -158,4 +154,3 @@ struct RunSet: public boost::multi_index_container<
typename bmi::nth_index<RunSet, 3>::type const& byJobName() const { return get<3>(); } typename bmi::nth_index<RunSet, 3>::type const& byJobName() const { return get<3>(); }
}; };
#endif // LAMINAR_RUN_H_

View File

@@ -1,5 +1,5 @@
/// ///
/// Copyright 2015-2021 Oliver Giles /// Copyright 2015-2026 Oliver Giles
/// ///
/// This file is part of Laminar /// This file is part of Laminar
/// ///
@@ -26,7 +26,6 @@
#include <kj/async-unix.h> #include <kj/async-unix.h>
#include <kj/threadlocal.h> #include <kj/threadlocal.h>
#include <signal.h>
#include <sys/eventfd.h> #include <sys/eventfd.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/inotify.h> #include <sys/inotify.h>
@@ -149,11 +148,10 @@ void Server::listenHttp(Http &http, kj::StringPtr httpBindAddress)
kj::Promise<void> Server::acceptRpcClient(Rpc& rpc, kj::Own<kj::ConnectionReceiver>&& listener) { kj::Promise<void> Server::acceptRpcClient(Rpc& rpc, kj::Own<kj::ConnectionReceiver>&& listener) {
kj::ConnectionReceiver& cr = *listener.get(); kj::ConnectionReceiver& cr = *listener.get();
return cr.accept().then(kj::mvCapture(kj::mv(listener), return cr.accept().then([this, &rpc, l = kj::mv(listener)](kj::Own<kj::AsyncIoStream>&& connection) mutable {
[this, &rpc](kj::Own<kj::ConnectionReceiver>&& listener, kj::Own<kj::AsyncIoStream>&& connection) {
addTask(rpc.accept(kj::mv(connection))); 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 // returns a promise which will read a chunk of data from the file descriptor

View File

@@ -1,5 +1,5 @@
/// ///
/// Copyright 2015-2020 Oliver Giles /// Copyright 2015-2026 Oliver Giles
/// ///
/// This file is part of Laminar /// This file is part of Laminar
/// ///
@@ -16,8 +16,7 @@
/// You should have received a copy of the GNU General Public License /// You should have received a copy of the GNU General Public License
/// along with Laminar. If not, see <http://www.gnu.org/licenses/> /// along with Laminar. If not, see <http://www.gnu.org/licenses/>
/// ///
#ifndef LAMINAR_SERVER_H_ #pragma once
#define LAMINAR_SERVER_H_
#include <kj/async-io.h> #include <kj/async-io.h>
#include <kj/compat/http.h> #include <kj/compat/http.h>
@@ -72,4 +71,3 @@ private:
kj::Maybe<kj::Promise<void>> reapWatch; kj::Maybe<kj::Promise<void>> reapWatch;
}; };
#endif // LAMINAR_SERVER_H_

View File

@@ -52,7 +52,7 @@ private:
std::vector<rapidjson::Document> receivedMessages; std::vector<rapidjson::Document> receivedMessages;
kj::Promise<void> waitForMessages(kj::AsyncInputStream* stream, ulong offset) { kj::Promise<void> 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; ulong end = offset + s;
buffer.asPtr().begin()[end] = '\0'; buffer.asPtr().begin()[end] = '\0';
if(strcmp(&buffer.asPtr().begin()[end - 2], "\n\n") == 0) { if(strcmp(&buffer.asPtr().begin()[end - 2], "\n\n") == 0) {