summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2025-12-09 20:35:28 +0100
committerAmlal El Mahrouss <amlal@nekernel.org>2025-12-09 20:35:28 +0100
commit4e6fd1dd8c9762ea6543ec275fe57ca474f23d8f (patch)
tree39ec629f5b80beb10919677fd12d7b258aaa2e14
parent26783733863f62c468a4c8cb2853badd54e30a39 (diff)
chore: codebase modernization and hygiene improvements.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
-rw-r--r--.clang-format2
-rw-r--r--examples/example_02_libnebuild/libnebuild.cc6
-rw-r--r--include/.keep0
-rw-r--r--include/NeBuildKit/Detail/Config.h40
-rw-r--r--include/NeBuildKit/IManifestBuilder.h7
-rw-r--r--include/NeBuildKit/JSONManifestBuilder.h5
-rw-r--r--include/NeBuildKit/TOMLManifestBuilder.h5
-rw-r--r--scripts/osx-dylib.json (renamed from targets/osx-dylib.json)0
-rw-r--r--scripts/osx.json (renamed from targets/osx.json)0
-rw-r--r--scripts/posix-dylib.json (renamed from targets/posix-dylib.json)0
-rw-r--r--scripts/posix.json (renamed from targets/posix.json)0
-rw-r--r--scripts/win64.json (renamed from targets/win64.json)0
-rw-r--r--src/cli/main.cc84
-rw-r--r--src/lib/JSONManifestBuilder.cc11
-rw-r--r--src/lib/TOMLManifestBuilder.cc10
-rw-r--r--vendor/.keep0
-rw-r--r--vendor/toml++/impl/array.inl6
-rw-r--r--vendor/toml++/impl/parser.inl14
-rw-r--r--vendor/toml++/impl/table.inl2
19 files changed, 88 insertions, 104 deletions
diff --git a/.clang-format b/.clang-format
index 3943f55..293ba4e 100644
--- a/.clang-format
+++ b/.clang-format
@@ -26,4 +26,4 @@ AlignConsecutiveDeclarations: true
AlignTrailingComments: true
FixNamespaceComments: true
IncludeIsMainRegex: '(Test)?$'
-SortUsingDeclarations: true
+SortUsingDeclarations: true \ No newline at end of file
diff --git a/examples/example_02_libnebuild/libnebuild.cc b/examples/example_02_libnebuild/libnebuild.cc
index e707f6c..fffb962 100644
--- a/examples/example_02_libnebuild/libnebuild.cc
+++ b/examples/example_02_libnebuild/libnebuild.cc
@@ -2,15 +2,15 @@
int main(int argc, char** argv) {
#ifndef _WIN32
- constexpr auto kPath = "./posix.json";
+ constexpr auto path = "./posix.json";
#else
- constexpr auto kPath = ".\\win64.json";
+ constexpr auto path = ".\\win64.json";
#endif
NeBuild::JSONManifestBuilder builder;
NeBuild::BuildConfig config;
- config.path_ = kPath;
+ config.path_ = path;
config.dry_run_ = false;
return builder.BuildTarget(config);
diff --git a/include/.keep b/include/.keep
deleted file mode 100644
index e69de29..0000000
--- a/include/.keep
+++ /dev/null
diff --git a/include/NeBuildKit/Detail/Config.h b/include/NeBuildKit/Detail/Config.h
index 915bde4..ddf93c1 100644
--- a/include/NeBuildKit/Detail/Config.h
+++ b/include/NeBuildKit/Detail/Config.h
@@ -16,32 +16,30 @@
#define LIKELY(ARG) ((ARG) ? assert(false) : ((void) 0))
#define UNLIKELY(ARG) LIKELY(!(ARG))
-#define LIBNEBUILD_VERSION "v0.0.7-buildkit"
+#define NEBUILD_VERSION "v0.0.8-buildkit"
-#define LIBNEBUILD_VERSION_BCD 0x0007
+#define NEBUILD_VERSION_BCD 0x0007
-#define LIBNEBUILD_VERSION_MAJOR 0
-#define LIBNEBUILD_VERSION_MINOR 0
-#define LIBNEBUILD_VERSION_PATCH 7
+#define NEBUILD_VERSION_MAJOR 0
+#define NEBUILD_VERSION_MINOR 0
+#define NEBUILD_VERSION_PATCH 7
-#define LIBNEBUILD_EXPORT_C extern "C"
+#define NEBUILD_EXPORT_C extern "C"
-#define LIBNEBUILD_UNUSED(X) ((void) X)
+#define NEBUILD_UNUSED(X) ((void) X)
namespace NeBuild {
- struct BuildConfig final {
- bool has_failed_{false};
- bool dry_run_{false};
- std::string path_{};
-
- explicit operator bool() {
- return has_failed_;
- }
-
- BuildConfig() = default;
- ~BuildConfig() {}
- };
-}
+struct BuildConfig final {
+ bool has_failed_{false};
+ bool dry_run_{false};
+ std::string path_{};
+
+ explicit operator bool() { return has_failed_; }
+
+ BuildConfig() = default;
+ ~BuildConfig() = default;
+};
+} // namespace NeBuild
namespace NeBuild::Logger {
/// @brief replacement for std::cout for NeBuild logging.
@@ -51,5 +49,3 @@ inline std::ostream& info() noexcept {
return out;
}
} // namespace NeBuild::Logger
-
-
diff --git a/include/NeBuildKit/IManifestBuilder.h b/include/NeBuildKit/IManifestBuilder.h
index 8131495..c42f257 100644
--- a/include/NeBuildKit/IManifestBuilder.h
+++ b/include/NeBuildKit/IManifestBuilder.h
@@ -6,6 +6,7 @@
#pragma once
#include <NeBuildKit/Detail/Config.h>
+#include <string_view>
#define NEBUILD_MANIFEST_BUILDER : public ::NeBuild::IManifestBuilder
@@ -19,8 +20,8 @@ class IManifestBuilder {
IManifestBuilder() = default;
virtual ~IManifestBuilder() = default;
- IManifestBuilder& operator=(const IManifestBuilder&) = default;
- IManifestBuilder(const IManifestBuilder&) = default;
+ IManifestBuilder& operator=(const IManifestBuilder&) = delete;
+ IManifestBuilder(const IManifestBuilder&) = delete;
/// =========================================================== ///
/// @brief Builds a TOML target from a file.
@@ -33,6 +34,6 @@ class IManifestBuilder {
/// =========================================================== ///
/// @brief Returns the build system name.
/// =========================================================== ///
- virtual const char* BuildSystem() = 0;
+ virtual const std::string_view BuildSystem() = 0;
};
} // namespace NeBuild \ No newline at end of file
diff --git a/include/NeBuildKit/JSONManifestBuilder.h b/include/NeBuildKit/JSONManifestBuilder.h
index 21f5f87..9f1afdc 100644
--- a/include/NeBuildKit/JSONManifestBuilder.h
+++ b/include/NeBuildKit/JSONManifestBuilder.h
@@ -17,9 +17,6 @@ class JSONManifestBuilder final NEBUILD_MANIFEST_BUILDER {
JSONManifestBuilder() = default;
~JSONManifestBuilder() override = default;
- JSONManifestBuilder& operator=(const JSONManifestBuilder&) = default;
- JSONManifestBuilder(const JSONManifestBuilder&) = default;
-
public:
/// =========================================================== ///
/// @brief Builds a JSON target from a JSON file.
@@ -32,6 +29,6 @@ class JSONManifestBuilder final NEBUILD_MANIFEST_BUILDER {
/// =========================================================== ///
/// @brief Returns the build system name.
/// =========================================================== ///
- const char* BuildSystem() override;
+ const std::string_view BuildSystem() override;
};
} // namespace NeBuild \ No newline at end of file
diff --git a/include/NeBuildKit/TOMLManifestBuilder.h b/include/NeBuildKit/TOMLManifestBuilder.h
index 7caf9d6..1c6bb1b 100644
--- a/include/NeBuildKit/TOMLManifestBuilder.h
+++ b/include/NeBuildKit/TOMLManifestBuilder.h
@@ -17,9 +17,6 @@ class TOMLManifestBuilder final NEBUILD_MANIFEST_BUILDER {
TOMLManifestBuilder() = default;
~TOMLManifestBuilder() override = default;
- TOMLManifestBuilder& operator=(const TOMLManifestBuilder&) = default;
- TOMLManifestBuilder(const TOMLManifestBuilder&) = default;
-
public:
/// =========================================================== ///
/// @brief Builds a TOML target from a TOML file.
@@ -32,6 +29,6 @@ class TOMLManifestBuilder final NEBUILD_MANIFEST_BUILDER {
/// =========================================================== ///
/// @brief Returns the build system name.
/// =========================================================== ///
- const char* BuildSystem() override;
+ const std::string_view BuildSystem() override;
};
} // namespace NeBuild \ No newline at end of file
diff --git a/targets/osx-dylib.json b/scripts/osx-dylib.json
index d5b87bc..d5b87bc 100644
--- a/targets/osx-dylib.json
+++ b/scripts/osx-dylib.json
diff --git a/targets/osx.json b/scripts/osx.json
index bdcab49..bdcab49 100644
--- a/targets/osx.json
+++ b/scripts/osx.json
diff --git a/targets/posix-dylib.json b/scripts/posix-dylib.json
index 3326b3e..3326b3e 100644
--- a/targets/posix-dylib.json
+++ b/scripts/posix-dylib.json
diff --git a/targets/posix.json b/scripts/posix.json
index 679296c..679296c 100644
--- a/targets/posix.json
+++ b/scripts/posix.json
diff --git a/targets/win64.json b/scripts/win64.json
index 75c025a..75c025a 100644
--- a/targets/win64.json
+++ b/scripts/win64.json
diff --git a/src/cli/main.cc b/src/cli/main.cc
index e3a17a0..e79cc6e 100644
--- a/src/cli/main.cc
+++ b/src/cli/main.cc
@@ -6,24 +6,24 @@
#include <NeBuildKit/JSONManifestBuilder.h>
#include <NeBuildKit/TOMLManifestBuilder.h>
+#include <memory>
#include <thread>
-static NeBuild::BuildConfig kConfig;
-
int main(int argc, char** argv) {
if (argc <= 1) return EXIT_FAILURE;
+ NeBuild::BuildConfig config;
+
for (size_t index = 1; index < argc; ++index) {
std::string index_path = argv[index];
if (index_path == "-v" || index_path == "-version") {
- NeBuild::Logger::info() << "NeBuild (" << LIBNEBUILD_VERSION << ")\n";
- NeBuild::Logger::info()
- << "Bugs, issues? https://github.com/nekernel-org/nebuild/issues\n";
+ NeBuild::Logger::info() << "NeBuild (" << NEBUILD_VERSION << ")\n";
+ NeBuild::Logger::info() << "Bugs or issues? https://github.com/nekernel-org/nebuild/issues\n";
return EXIT_SUCCESS;
} else if (index_path == "-dry-run" || index_path == "-n") {
- kConfig.dry_run_ = true;
+ config.dry_run_ = true;
continue;
} else if (index_path == "-h" || index_path == "-help") {
NeBuild::Logger::info() << "usage: nebuild <options> <file>.\n";
@@ -33,58 +33,50 @@ int main(int argc, char** argv) {
auto index_cpy = index;
- std::thread job_build_thread(
- [&index_path, &index, &index_cpy, &argv]() -> void {
- NeBuild::IManifestBuilder* builder = nullptr;
+ std::thread job_build_thread([&index_path, &index, &index_cpy, &argc, &argv, &config]() -> void {
+ std::unique_ptr<NeBuild::IManifestBuilder> builder;
- const auto kJsonExtension = ".json";
+ const auto kJsonExtension = ".json";
- if (index_path.ends_with(kJsonExtension)) {
- builder = new NeBuild::JSONManifestBuilder();
+ if (index_path.ends_with(kJsonExtension)) {
+ builder = std::make_unique<NeBuild::JSONManifestBuilder>();
- if (!builder) {
- kConfig.has_failed_ = true;
- return;
- }
- } else {
- const auto kTomlExtension = ".toml";
- builder = new NeBuild::TOMLManifestBuilder();
+ if (!builder) {
+ config.has_failed_ = true;
+ return;
+ }
+ } else {
+ const auto kTomlExtension = ".toml";
+ builder = std::make_unique<NeBuild::TOMLManifestBuilder>();
- if (index_path.ends_with(kTomlExtension)) {
- goto nebuild_build_target;
- } else {
- NeBuild::Logger::info()
- << "error: file '" << index_path << "' is not a manifest file!" << std::endl;
- kConfig.has_failed_ = true;
- return;
- }
- }
+ if (!index_path.ends_with(kTomlExtension)) {
+ NeBuild::Logger::info() << "error: file '" << index_path << "' is not a manifest file!"
+ << std::endl;
+ config.has_failed_ = true;
+ return;
+ }
+ }
- nebuild_build_target:
- std::string next_path;
+ std::string next_path;
- if (argv[index_cpy + 1]) next_path = argv[index_cpy + 1];
+ if ((index_cpy + 1) < argc && argv[index_cpy + 1]) next_path = argv[index_cpy + 1];
- if (next_path == "-build-system") {
- NeBuild::Logger::info() << builder->BuildSystem() << std::endl;
- std::exit(EXIT_SUCCESS);
- }
+ if (next_path == "-build-system") {
+ NeBuild::Logger::info() << builder->BuildSystem() << std::endl;
+ std::exit(EXIT_SUCCESS);
+ }
- NeBuild::Logger::info() << "building manifest: " << index_path << std::endl;
+ NeBuild::Logger::info() << "building manifest: " << index_path << std::endl;
- kConfig.path_ = index_path;
-
- if (builder && !builder->BuildTarget(kConfig)) {
- kConfig.has_failed_ = true;
- }
+ config.path_ = index_path;
- toml_build_done:
- delete builder;
- builder = nullptr;
- });
+ if (builder && !builder->BuildTarget(config)) {
+ config.has_failed_ = true;
+ }
+ });
job_build_thread.join();
}
- return !kConfig ? EXIT_FAILURE : EXIT_SUCCESS;
+ return !config ? EXIT_FAILURE : EXIT_SUCCESS;
}
diff --git a/src/lib/JSONManifestBuilder.cc b/src/lib/JSONManifestBuilder.cc
index c6ff4d8..af69176 100644
--- a/src/lib/JSONManifestBuilder.cc
+++ b/src/lib/JSONManifestBuilder.cc
@@ -7,10 +7,8 @@
#include <json/json.h>
#include <fstream>
-using namespace NeBuild;
-using namespace nlohmann;
-
-using JSON = json;
+namespace NeBuild {
+using JSON = nlohmann::json;
namespace FS = std::filesystem;
/// =========================================================== ///
@@ -95,10 +93,12 @@ bool JSONManifestBuilder::BuildTarget(BuildConfig& config) {
if (ret_exec > 0) {
NeBuild::Logger::info() << "error: exit with message: " << std::strerror(ret_exec) << ""
<< std::endl;
+ config.has_failed_ = true;
return false;
}
} catch (std::runtime_error& err) {
NeBuild::Logger::info() << "error: exit with message: " << err.what() << "" << std::endl;
+ config.has_failed_ = true;
return false;
}
@@ -108,6 +108,7 @@ bool JSONManifestBuilder::BuildTarget(BuildConfig& config) {
/// =========================================================== ///
/// @brief Returns the build system name.
/// =========================================================== ///
-const char* JSONManifestBuilder::BuildSystem() {
+const std::string_view JSONManifestBuilder::BuildSystem() {
return "NeBuild (JSON)";
}
+} // namespace NeBuild \ No newline at end of file
diff --git a/src/lib/TOMLManifestBuilder.cc b/src/lib/TOMLManifestBuilder.cc
index a58b280..5b759fc 100644
--- a/src/lib/TOMLManifestBuilder.cc
+++ b/src/lib/TOMLManifestBuilder.cc
@@ -4,11 +4,10 @@
// ============================================================= //
#include <NeBuildKit/TOMLManifestBuilder.h>
-#include <toml++/toml.hpp>
#include <filesystem>
+#include <toml++/toml.hpp>
-using namespace NeBuild;
-
+namespace NeBuild {
namespace FS = std::filesystem;
/// =========================================================== ///
@@ -98,10 +97,12 @@ bool TOMLManifestBuilder::BuildTarget(BuildConfig& config) {
if (ret_exec > 0) {
NeBuild::Logger::info() << "error: exit with message: " << std::strerror(ret_exec) << ""
<< std::endl;
+ config.has_failed_ = true;
return false;
}
} catch (std::runtime_error& err) {
NeBuild::Logger::info() << "error: exit with message: " << err.what() << "" << std::endl;
+ config.has_failed_ = true;
return false;
}
@@ -111,6 +112,7 @@ bool TOMLManifestBuilder::BuildTarget(BuildConfig& config) {
/// =========================================================== ///
/// @brief Returns the build system name.
/// =========================================================== ///
-const char* TOMLManifestBuilder::BuildSystem() {
+const std::string_view TOMLManifestBuilder::BuildSystem() {
return "NeBuild (TOML)";
}
+} // namespace NeBuild \ No newline at end of file
diff --git a/vendor/.keep b/vendor/.keep
deleted file mode 100644
index e69de29..0000000
--- a/vendor/.keep
+++ /dev/null
diff --git a/vendor/toml++/impl/array.inl b/vendor/toml++/impl/array.inl
index 7ae8ee1..194a21f 100644
--- a/vendor/toml++/impl/array.inl
+++ b/vendor/toml++/impl/array.inl
@@ -207,7 +207,7 @@ TOML_NAMESPACE_START {
}
TOML_EXTERNAL_LINKAGE
- void array::flatten_child(array && child, size_t & dest_index) noexcept {
+ void array::flatten_child(array && child, size_t& dest_index) noexcept {
for (size_t i = 0, e = child.size(); i < e; i++) {
auto type = child.elems_[i]->type();
if (type == node_type::array) {
@@ -219,7 +219,7 @@ TOML_NAMESPACE_START {
}
TOML_EXTERNAL_LINKAGE
- array& array::flatten()& {
+ array& array::flatten() & {
if (elems_.empty()) return *this;
bool requires_flattening = false;
@@ -258,7 +258,7 @@ TOML_NAMESPACE_START {
}
TOML_EXTERNAL_LINKAGE
- array& array::prune(bool recursive)& noexcept {
+ array& array::prune(bool recursive) & noexcept {
if (elems_.empty()) return *this;
for (size_t i = elems_.size(); i-- > 0u;) {
diff --git a/vendor/toml++/impl/parser.inl b/vendor/toml++/impl/parser.inl
index 1530e5a..0ebc31e 100644
--- a/vendor/toml++/impl/parser.inl
+++ b/vendor/toml++/impl/parser.inl
@@ -391,11 +391,11 @@ TOML_ANON_NAMESPACE_START {
};
template <typename Char>
- utf8_reader(std::basic_string_view<Char>,
- std::string_view) -> utf8_reader<std::basic_string_view<Char>>;
+ utf8_reader(std::basic_string_view<Char>, std::string_view)
+ -> utf8_reader<std::basic_string_view<Char>>;
template <typename Char>
- utf8_reader(std::basic_string_view<Char>,
- std::string&&) -> utf8_reader<std::basic_string_view<Char>>;
+ utf8_reader(std::basic_string_view<Char>, std::string&&)
+ -> utf8_reader<std::basic_string_view<Char>>;
template <typename Char>
utf8_reader(std::basic_istream<Char>&, std::string_view) -> utf8_reader<std::basic_istream<Char>>;
template <typename Char>
@@ -3369,10 +3369,8 @@ TOML_ANON_NAMESPACE_START {
TOML_INTERNAL_LINKAGE
parse_result do_parse_file(std::string_view file_path) {
#if TOML_EXCEPTIONS
-#define TOML_PARSE_FILE_ERROR(msg, path) \
- throw parse_error { \
- msg, source_position{}, std::make_shared<const std::string>(std::move(path)) \
- }
+#define TOML_PARSE_FILE_ERROR(msg, path) \
+ throw parse_error{msg, source_position{}, std::make_shared<const std::string>(std::move(path))}
#else
#define TOML_PARSE_FILE_ERROR(msg, path) \
return parse_result { \
diff --git a/vendor/toml++/impl/table.inl b/vendor/toml++/impl/table.inl
index ca7473e..ba76963 100644
--- a/vendor/toml++/impl/table.inl
+++ b/vendor/toml++/impl/table.inl
@@ -198,7 +198,7 @@ TOML_NAMESPACE_START {
}
TOML_EXTERNAL_LINKAGE
- table& table::prune(bool recursive)& noexcept {
+ table& table::prune(bool recursive) & noexcept {
if (map_.empty()) return *this;
for (auto it = map_.begin(); it != map_.end();) {