summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2026-01-06 11:12:50 +0100
committerEugen Wissner <belka@caraus.de>2026-01-06 11:12:50 +0100
commitdd97107aa81e1137c80602c044b3805bf4ffda56 (patch)
tree5b7d3449bfc6963a0f33ee5cb6827faa8424e763
parent8f0a4b9f36046b41a66db599e4e925386c48d049 (diff)
downloadkatja-dd97107aa81e1137c80602c044b3805bf4ffda56.tar.gz
Switch to using modules in the library
-rw-r--r--CMakeLists.txt13
-rw-r--r--cli/component.cpp4
-rw-r--r--cli/main.cpp11
-rw-r--r--cli/page.cpp7
-rw-r--r--include/katja/database.hpp39
-rw-r--r--include/katja/repository.hpp32
-rw-r--r--include/katja/sbo.hpp44
-rw-r--r--katja/database.cpp139
-rw-r--r--katja/repository.cpp59
-rw-r--r--katja/sbo.cpp135
-rw-r--r--tests/database.cpp2
-rw-r--r--tests/repository.cpp2
12 files changed, 221 insertions, 266 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f01ca92..980c023 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -2,7 +2,7 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
-cmake_minimum_required(VERSION 3.30)
+cmake_minimum_required(VERSION 4.0.0)
project(Katja LANGUAGES CXX)
include(CTest)
@@ -12,14 +12,11 @@ option(KATJA_BUILD_TUI "Build text user interface" ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
-set(CMAKE_CXX_STANDARD 20)
-set(CMAKE_CXX_MODULE_STD 1)
+set(CMAKE_CXX_STANDARD 23)
-add_library(katja
- katja/database.cpp include/katja/database.hpp
- katja/sbo.cpp include/katja/sbo.hpp
- katja/repository.cpp include/katja/repository.hpp
-)
+add_library(katja)
+target_sources(katja PUBLIC FILE_SET all_my_modules TYPE CXX_MODULES FILES
+ katja/database.cpp katja/repository.cpp katja/sbo.cpp)
include_directories(include ${Boost_INCLUDE_DIR})
if(KATJA_BUILD_TUI)
diff --git a/cli/component.cpp b/cli/component.cpp
index b33be7a..6735077 100644
--- a/cli/component.cpp
+++ b/cli/component.cpp
@@ -12,9 +12,9 @@ module;
#include <ftxui/component/component.hpp>
#include <ftxui/dom/elements.hpp>
-#include "katja/repository.hpp"
+import katja.repository;
-export module component;
+export module katja.component;
export namespace katja
{
diff --git a/cli/main.cpp b/cli/main.cpp
index d0bf8b7..5502800 100644
--- a/cli/main.cpp
+++ b/cli/main.cpp
@@ -3,17 +3,20 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
+module;
+
#include <filesystem>
+#include <memory>
#include <ftxui/component/screen_interactive.hpp>
#include <ftxui/dom/elements.hpp>
#include <ftxui/component/component.hpp>
#include <toml.hpp>
-#include "katja/sbo.hpp"
-#include "katja/database.hpp"
-
-import page;
+import katja.database;
+import katja.repository;
+import katja.sbo;
+import katja.page;
int main(int argc, const char **argv)
{
diff --git a/cli/page.cpp b/cli/page.cpp
index 617ee07..44b7e73 100644
--- a/cli/page.cpp
+++ b/cli/page.cpp
@@ -9,11 +9,12 @@ module;
#include <ftxui/component/component.hpp>
-#include "katja/repository.hpp"
+import katja.database;
+import katja.repository;
-export module page;
+export module katja.page;
-import component;
+import katja.component;
export namespace katja
{
diff --git a/include/katja/database.hpp b/include/katja/database.hpp
deleted file mode 100644
index ca85ab1..0000000
--- a/include/katja/database.hpp
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at https://mozilla.org/MPL/2.0/.
- */
-#pragma once
-
-#include <string>
-#include <map>
-
-namespace katja
-{
- constexpr const char *database = "/var/lib/pkgtools/packages";
-
- class database_package
- {
- database_package(std::string&& name, std::string&& version,
- std::string&& architecture, std::string&& build_tag);
-
- static database_package create_database_package(const std::string& fullname);
-
- public:
- const std::string name;
- const std::string version;
- const std::string architecture;
- const std::string build_tag;
-
- database_package(const std::string& fullname);
-
- bool operator<(const database_package& that) const;
- bool operator>(const database_package& that) const;
-
- std::string to_string() const;
- };
-
- using package_database = std::multimap<std::string, database_package>;
-
- package_database read_installed_database();
-}
diff --git a/include/katja/repository.hpp b/include/katja/repository.hpp
deleted file mode 100644
index cde9ca0..0000000
--- a/include/katja/repository.hpp
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at https://mozilla.org/MPL/2.0/.
- */
-#pragma once
-
-#include <string>
-#include <vector>
-
-#include "katja/database.hpp"
-
-namespace katja
-{
- struct package_identifier
- {
- const std::string name;
- const std::string version;
- const std::string architecture;
- const std::string data;
-
- std::string to_string() const;
- };
-
- class repository
- {
- public:
- virtual std::vector<package_identifier> get_updates(const package_database& database) = 0;
- virtual std::vector<package_identifier> search_names(const std::string& architecture,
- const std::string& needle) = 0;
- };
-}
diff --git a/include/katja/sbo.hpp b/include/katja/sbo.hpp
deleted file mode 100644
index ba46509..0000000
--- a/include/katja/sbo.hpp
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at https://mozilla.org/MPL/2.0/.
- */
-#pragma once
-
-#include <string>
-#include <vector>
-#include <filesystem>
-#include <optional>
-
-#include "katja/repository.hpp"
-
-namespace katja
-{
- struct info_file
- {
- const std::string program_name;
- const std::string version;
- const std::string homepage;
- const std::string email;
- const std::string maintainer;
-
- info_file(const std::string& program_name, const std::string& version,
- const std::string homepage, const std::string& email, const std::string& maintainer);
-
- package_identifier identifier_for(const std::string& architecture);
- };
-
- class sbo_repository final : public repository
- {
- std::map<std::string, std::filesystem::path> info_paths;
-
- public:
- sbo_repository(const std::filesystem::path& repository_path);
-
- std::vector<package_identifier> get_updates(const package_database& database) override;
- std::vector<package_identifier> search_names(const std::string& architecture,
- const std::string& needle) override;
- };
-
- std::optional<info_file> read_slackbuild_info(const std::filesystem::path& info_filepath);
-}
diff --git a/katja/database.cpp b/katja/database.cpp
index 4f4b5b8..23cb6ca 100644
--- a/katja/database.cpp
+++ b/katja/database.cpp
@@ -3,84 +3,101 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
-#include "katja/database.hpp"
+module;
+#include <string>
+#include <map>
#include <filesystem>
-namespace katja
+export module katja.database;
+
+export namespace katja
{
- database_package database_package::create_database_package(const std::string& fullname)
- {
- std::string::const_reverse_iterator begin_iterator = std::crbegin(fullname);
- std::string::const_reverse_iterator end_iterator = begin_iterator;
- int minus_counter = 0;
+ constexpr const char *database = "/var/lib/pkgtools/packages";
- std::string build_tag;
- std::string architecture;
- std::string version;
+ class database_package
+ {
+ database_package(std::string&& name, std::string&& version,
+ std::string&& architecture, std::string&& build_tag)
+ : name(name), version(version), architecture(architecture), build_tag(build_tag)
+ {
+ }
- for (; begin_iterator != std::crend(fullname) && minus_counter < 3; ++begin_iterator)
+ static database_package create_database_package(const std::string& fullname)
{
- if (*begin_iterator == '-')
+ std::string::const_reverse_iterator begin_iterator = std::crbegin(fullname);
+ std::string::const_reverse_iterator end_iterator = begin_iterator;
+ int minus_counter = 0;
+
+ std::string build_tag;
+ std::string architecture;
+ std::string version;
+
+ for (; begin_iterator != std::crend(fullname) && minus_counter < 3; ++begin_iterator)
{
- if (minus_counter == 0)
- {
- build_tag = std::string(begin_iterator.base(), end_iterator.base());
- }
- else if (minus_counter == 1)
+ if (*begin_iterator == '-')
{
- architecture = std::string(begin_iterator.base(), end_iterator.base());
+ if (minus_counter == 0)
+ {
+ build_tag = std::string(begin_iterator.base(), end_iterator.base());
+ }
+ else if (minus_counter == 1)
+ {
+ architecture = std::string(begin_iterator.base(), end_iterator.base());
+ }
+ else if (minus_counter == 2)
+ {
+ version = std::string(begin_iterator.base(), end_iterator.base());
+ }
+ end_iterator = begin_iterator + 1;
+ ++minus_counter;
}
- else if (minus_counter == 2)
- {
- version = std::string(begin_iterator.base(), end_iterator.base());
- }
- end_iterator = begin_iterator + 1;
- ++minus_counter;
}
+ return database_package(std::string(fullname.cbegin(), end_iterator.base()),
+ std::move(version), std::move(architecture), std::move(build_tag));
}
- return database_package(std::string(fullname.cbegin(), end_iterator.base()),
- std::move(version), std::move(architecture), std::move(build_tag));
- }
- database_package::database_package(std::string&& name, std::string&& version,
- std::string&& architecture, std::string&& build_tag)
- : name(name), version(version), architecture(architecture), build_tag(build_tag)
- {
- }
+ public:
+ const std::string name;
+ const std::string version;
+ const std::string architecture;
+ const std::string build_tag;
- database_package::database_package(const std::string& fullname)
- : database_package(create_database_package(fullname))
- {
- }
+ database_package(const std::string& fullname)
+ : database_package(create_database_package(fullname))
+ {
+ }
- bool database_package::operator<(const database_package& that) const
- {
- return this->name < that.name;
- }
+ bool operator<(const database_package& that) const
+ {
+ return this->name < that.name;
+ }
- bool database_package::operator>(const database_package& that) const
- {
- return this->name > that.name;
- }
+ bool operator>(const database_package& that) const
+ {
+ return this->name > that.name;
+ }
- std::string database_package::to_string() const
- {
- std::string package_string;
- const std::size_t total_size = this->name.size() + this->version.size()
- + this->architecture.size() + this->build_tag.size() + 3;
-
- package_string.reserve(total_size);
- package_string.append(this->name);
- package_string.push_back('-');
- package_string.append(this->version);
- package_string.push_back('-');
- package_string.append(this->architecture);
- package_string.push_back('-');
- package_string.append(this->build_tag);
-
- return package_string;
- }
+ std::string to_string() const
+ {
+ std::string package_string;
+ const std::size_t total_size = this->name.size() + this->version.size()
+ + this->architecture.size() + this->build_tag.size() + 3;
+
+ package_string.reserve(total_size);
+ package_string.append(this->name);
+ package_string.push_back('-');
+ package_string.append(this->version);
+ package_string.push_back('-');
+ package_string.append(this->architecture);
+ package_string.push_back('-');
+ package_string.append(this->build_tag);
+
+ return package_string;
+ }
+ };
+
+ using package_database = std::multimap<std::string, database_package>;
package_database read_installed_database()
{
diff --git a/katja/repository.cpp b/katja/repository.cpp
index 270ffec..38d5411 100644
--- a/katja/repository.cpp
+++ b/katja/repository.cpp
@@ -3,25 +3,48 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
-#include "katja/repository.hpp"
+module;
-namespace katja
+#include <string>
+#include <vector>
+
+export module katja.repository;
+
+import katja.database;
+
+export namespace katja
{
- std::string package_identifier::to_string() const
+ struct package_identifier
+ {
+ const std::string name;
+ const std::string version;
+ const std::string architecture;
+ const std::string data;
+
+ std::string to_string() const
+ {
+ std::string identifier;
+ const std::size_t total_size = this->name.size() + this->version.size()
+ + this->architecture.size() + this->data.size() + 3;
+
+ identifier.reserve(total_size);
+ identifier.append(this->name);
+ identifier.push_back(';');
+ identifier.append(this->version);
+ identifier.push_back(';');
+ identifier.append(this->architecture);
+ identifier.push_back(';');
+ identifier.append(this->data);
+
+ return identifier;
+ }
+ };
+
+ class repository
{
- std::string identifier;
- const std::size_t total_size = this->name.size() + this->version.size()
- + this->architecture.size() + this->data.size() + 3;
-
- identifier.reserve(total_size);
- identifier.append(this->name);
- identifier.push_back(';');
- identifier.append(this->version);
- identifier.push_back(';');
- identifier.append(this->architecture);
- identifier.push_back(';');
- identifier.append(this->data);
-
- return identifier;
- }
+ public:
+ virtual std::vector<package_identifier> get_updates(const package_database& database) = 0;
+ virtual std::vector<package_identifier> search_names(const std::string& architecture,
+ const std::string& needle) = 0;
+ };
}
diff --git a/katja/sbo.cpp b/katja/sbo.cpp
index b53d8ee..f84d030 100644
--- a/katja/sbo.cpp
+++ b/katja/sbo.cpp
@@ -3,15 +3,62 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
+module;
+
#include <fstream>
+#include <string>
+#include <vector>
+#include <filesystem>
+#include <optional>
+#include <map>
#include <boost/algorithm/string.hpp>
-#include "katja/sbo.hpp"
+export module katja.sbo;
+
+import katja.database;
+import katja.repository;
namespace katja
{
static
+ bool trim_info_line(std::string& info_value)
+ {
+ if (boost::algorithm::ends_with(info_value, "\""))
+ {
+ info_value.pop_back();
+ return false;
+ }
+ else if (boost::algorithm::ends_with(info_value, "\\"))
+ {
+ info_value.pop_back();
+ return true;
+ }
+ return false;
+ }
+
+ export struct info_file
+ {
+ const std::string program_name;
+ const std::string version;
+ const std::string homepage;
+ const std::string email;
+ const std::string maintainer;
+
+ info_file(const std::string& program_name, const std::string& version,
+ const std::string homepage, const std::string& email, const std::string& maintainer)
+ : program_name(program_name), version(version), homepage(homepage), email(email), maintainer(maintainer)
+ {
+ }
+
+ package_identifier identifier_for(const std::string& architecture)
+ {
+ return package_identifier{ this->program_name, this->version, architecture, "SBo" };
+ }
+ };
+ export std::optional<info_file> read_slackbuild_info(const std::filesystem::path& info_filepath);
+
+ static
void search_for_slackbuilds(std::map<std::string, std::filesystem::path>& info_files,
const std::filesystem::path& directory)
{
@@ -50,76 +97,58 @@ namespace katja
}
}
}
+}
- info_file::info_file(const std::string& program_name, const std::string& version,
- const std::string homepage, const std::string& email, const std::string& maintainer)
- : program_name(program_name), version(version), homepage(homepage), email(email), maintainer(maintainer)
- {
- }
-
- package_identifier info_file::identifier_for(const std::string& architecture)
- {
- return package_identifier{ this->program_name, this->version, architecture, "SBo" };
- }
-
- sbo_repository::sbo_repository(const std::filesystem::path& repository_path)
+export namespace katja
+{
+ class sbo_repository final : public repository
{
- search_for_slackbuilds(this->info_paths, repository_path);
- }
+ std::map<std::string, std::filesystem::path> info_paths;
- std::vector<package_identifier> sbo_repository::get_updates(const package_database& database)
- {
- std::vector<package_identifier> identifiers;
+ public:
+ sbo_repository(const std::filesystem::path& repository_path)
+ {
+ search_for_slackbuilds(this->info_paths, repository_path);
+ }
- for (const auto& [package_name, package] : database)
+ std::vector<package_identifier> get_updates(const package_database& database) override
{
- auto looked_up_info_path = this->info_paths.find(package_name);
+ std::vector<package_identifier> identifiers;
- if (looked_up_info_path != this->info_paths.cend())
+ for (const auto& [package_name, package] : database)
{
- auto slackbuild_info = read_slackbuild_info(looked_up_info_path->second);
+ auto looked_up_info_path = this->info_paths.find(package_name);
- if (slackbuild_info.has_value() && slackbuild_info.value().version != package.version)
+ if (looked_up_info_path != this->info_paths.cend())
{
- identifiers.push_back(slackbuild_info->identifier_for(package.architecture));
+ auto slackbuild_info = read_slackbuild_info(looked_up_info_path->second);
+
+ if (slackbuild_info.has_value() && slackbuild_info.value().version != package.version)
+ {
+ identifiers.push_back(slackbuild_info->identifier_for(package.architecture));
+ }
}
}
+ return identifiers;
}
- return identifiers;
- }
-
- std::vector<package_identifier> sbo_repository::search_names(const std::string& architecture,
- const std::string& needle)
- {
- std::vector<package_identifier> identifiers;
- for (const auto& [package_name, info_path] : this->info_paths)
+ std::vector<package_identifier> search_names(const std::string& architecture,
+ const std::string& needle) override
{
- if (package_name.find(needle) != std::string::npos)
+ std::vector<package_identifier> identifiers;
+
+ for (const auto& [package_name, info_path] : this->info_paths)
{
- auto slackbuild_info = read_slackbuild_info(info_path);
+ if (package_name.find(needle) != std::string::npos)
+ {
+ auto slackbuild_info = read_slackbuild_info(info_path);
- identifiers.push_back(slackbuild_info->identifier_for(architecture));
+ identifiers.push_back(slackbuild_info->identifier_for(architecture));
+ }
}
+ return identifiers;
}
- return identifiers;
- }
-
- static
- bool trim_info_line(std::string& info_value)
- {
- if (boost::algorithm::ends_with(info_value, "\""))
- {
- info_value.pop_back();
- return false;
- }
- else if (boost::algorithm::ends_with(info_value, "\\"))
- {
- info_value.pop_back();
- return true;
- }
- return false;
- }
+ };
std::optional<info_file> read_slackbuild_info(const std::filesystem::path& info_filepath)
{
diff --git a/tests/database.cpp b/tests/database.cpp
index d2651c8..ed764c8 100644
--- a/tests/database.cpp
+++ b/tests/database.cpp
@@ -6,7 +6,7 @@
#define BOOST_TEST_MODULE database tests
#include <boost/test/unit_test.hpp>
-#include "katja/database.hpp"
+import katja.database;
BOOST_AUTO_TEST_CASE(generate_package_identifier)
{
diff --git a/tests/repository.cpp b/tests/repository.cpp
index bb1d6c7..f025ef2 100644
--- a/tests/repository.cpp
+++ b/tests/repository.cpp
@@ -6,7 +6,7 @@
#define BOOST_TEST_MODULE repository tests
#include <boost/test/unit_test.hpp>
-#include "katja/repository.hpp"
+import katja.repository;
BOOST_AUTO_TEST_CASE(construct_valid_database_package)
{