From 6132d2c6a751ebffc29f950ca3755a05595dd99e Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Wed, 19 Nov 2025 09:18:08 +0100 Subject: feat: new documented codebase and improvements. Signed-off-by: Amlal El Mahrouss --- dev/BuildKit/Defines.h | 8 +++- dev/BuildKit/IManifestBuilder.h | 24 +++++++---- dev/BuildKit/Imports.h | 4 ++ dev/BuildKit/JSONManifestBuilder.h | 18 ++++++--- dev/BuildKit/TOMLManifestBuilder.h | 18 ++++++--- dev/cli/App.cc | 83 -------------------------------------- dev/cli/AppMain.cc | 83 ++++++++++++++++++++++++++++++++++++++ dev/src/JSONManifestBuilder.cc | 8 +++- dev/src/TOMLManifestBuilder.cc | 17 +++++--- 9 files changed, 151 insertions(+), 112 deletions(-) delete mode 100644 dev/cli/App.cc create mode 100644 dev/cli/AppMain.cc (limited to 'dev') diff --git a/dev/BuildKit/Defines.h b/dev/BuildKit/Defines.h index 4774c85..1c88ceb 100644 --- a/dev/BuildKit/Defines.h +++ b/dev/BuildKit/Defines.h @@ -7,12 +7,16 @@ #include +/// =========================================================== /// +/// @brief Defines file +/// =========================================================== /// + #define LIKELY(ARG) ((ARG) ? assert(false) : ((void) 0)) #define UNLIKELY(ARG) LIKELY(!(ARG)) -#define LIBNEBUILD_VERSION "v0.0.1-libNeBuild" +#define LIBNEBUILD_VERSION "v0.0.7-buildkit" -#define LIBNEBUILD_VERSION_BCD 0x0001 +#define LIBNEBUILD_VERSION_BCD 0x0007 #define LIBNEBUILD_VERSION_MAJOR 1 #define LIBNEBUILD_VERSION_MINOR 1 diff --git a/dev/BuildKit/IManifestBuilder.h b/dev/BuildKit/IManifestBuilder.h index 8f9b2cf..abb389f 100644 --- a/dev/BuildKit/IManifestBuilder.h +++ b/dev/BuildKit/IManifestBuilder.h @@ -7,11 +7,13 @@ #include -#define NEBUILD_MANIFEST_BUILDER : public NeBuild::IManifestBuilder +#define NEBUILD_MANIFEST_BUILDER : public ::NeBuild::IManifestBuilder namespace NeBuild { +/// =========================================================== /// /// @brief Builder interface class. /// @note This class is meant to be used as an interface. +/// =========================================================== /// class IManifestBuilder { public: IManifestBuilder() = default; @@ -20,12 +22,18 @@ class IManifestBuilder { IManifestBuilder& operator=(const IManifestBuilder&) = default; IManifestBuilder(const IManifestBuilder&) = default; - /// @brief Builds a target using the implemented laguage. - /// @param arg_sz filename size - /// @param arg_val filename path. - /// @retval true succeeded. - /// @retval false failed. - virtual bool BuildTarget(const std::string& arg, const bool dry_run = false) = 0; - virtual const char* BuildSystem() = 0; + /// =========================================================== /// + /// @brief Builds a TOML target from a file. + /// @param arg_sz filename size (must be 1 or greater). + /// @param arg_val filename path (must be a valid language file). + /// @retval true building has succeeded. + /// @retval false fail to build, see error message. + /// =========================================================== /// + virtual bool BuildTarget(const std::string& arg, const bool dry_run = false) = 0; + + /// =========================================================== /// + /// @brief Returns the build system name. + /// =========================================================== /// + virtual const char* BuildSystem() = 0; }; } // namespace NeBuild \ No newline at end of file diff --git a/dev/BuildKit/Imports.h b/dev/BuildKit/Imports.h index e22c933..33e1e31 100644 --- a/dev/BuildKit/Imports.h +++ b/dev/BuildKit/Imports.h @@ -6,6 +6,10 @@ #ifndef NEBUILD_INCLUDES_H #define NEBUILD_INCLUDES_H +/// =========================================================== /// +/// @brief Imports file +/// =========================================================== /// + #include #include #include diff --git a/dev/BuildKit/JSONManifestBuilder.h b/dev/BuildKit/JSONManifestBuilder.h index 81643e3..438bdab 100644 --- a/dev/BuildKit/JSONManifestBuilder.h +++ b/dev/BuildKit/JSONManifestBuilder.h @@ -22,12 +22,18 @@ class JSONManifestBuilder final NEBUILD_MANIFEST_BUILDER { JSONManifestBuilder(const JSONManifestBuilder&) = default; public: - /// @brief Builds a JSON target. - /// @param arg_sz filename size - /// @param arg_val filename path. - /// @retval true build succeeded. - /// @retval false failed to build. - bool BuildTarget(const std::string& arg_val, const bool dry_run = false) override; + /// =========================================================== /// + /// @brief Builds a JSON target from a JSON file. + /// @param arg_sz filename size (must be 1 or greater). + /// @param arg_val filename path (must be a valid JSON file). + /// @retval true building has succeeded. + /// @retval false fail to build, see error message. + /// =========================================================== /// + bool BuildTarget(const std::string& arg_val, const bool dry_run = false) override; + + /// =========================================================== /// + /// @brief Returns the build system name. + /// =========================================================== /// const char* BuildSystem() override; }; } // namespace NeBuild \ No newline at end of file diff --git a/dev/BuildKit/TOMLManifestBuilder.h b/dev/BuildKit/TOMLManifestBuilder.h index 6baa9f5..7c508fc 100644 --- a/dev/BuildKit/TOMLManifestBuilder.h +++ b/dev/BuildKit/TOMLManifestBuilder.h @@ -22,12 +22,18 @@ class TOMLManifestBuilder final NEBUILD_MANIFEST_BUILDER { TOMLManifestBuilder(const TOMLManifestBuilder&) = default; public: - /// @brief Builds a TOML target. - /// @param arg_sz filename size - /// @param arg_val filename path. - /// @retval true build succeeded. - /// @retval false failed to build. - bool BuildTarget(const std::string& arg_val, const bool dry_run = false) override; + /// =========================================================== /// + /// @brief Builds a TOML target from a TOML file. + /// @param arg_sz filename size (must be 1 or greater). + /// @param arg_val filename path (must be a valid TOML file). + /// @retval true building has succeeded. + /// @retval false fail to build, see error message. + /// =========================================================== /// + bool BuildTarget(const std::string& arg_val, const bool dry_run = false) override; + + /// =========================================================== /// + /// @brief Returns the build system name. + /// =========================================================== /// const char* BuildSystem() override; }; } // namespace NeBuild \ No newline at end of file diff --git a/dev/cli/App.cc b/dev/cli/App.cc deleted file mode 100644 index d78ad69..0000000 --- a/dev/cli/App.cc +++ /dev/null @@ -1,83 +0,0 @@ - -// ============================================================= // -// nebuild -// Copyright (C) 2024-2025, Amlal El Mahrouss, licensed under BSD-3 license. -// ============================================================= // - -#include -#include - -static bool kFailed = false; -static bool kDryRun = false; - -int main(int argc, char** argv) { - if (argc <= 1) return EXIT_FAILURE; - - for (size_t index = 1; index < argc; ++index) { - std::string index_path = argv[index]; - - if (index_path == "-v" || index_path == "--version") { - NeBuild::Logger::info() << "NeKernel Build Tool.\n"; - NeBuild::Logger::info() - << "Bugs or issues? Check out: https://github.com/nekernel-org/nebuild/issues\n"; - - return EXIT_SUCCESS; - } else if (index_path == "--dry-run" || index_path == "-n") { - kDryRun = true; - continue; - } else if (index_path == "-h" || index_path == "--help") { - NeBuild::Logger::info() << "usage: nebuild \n"; - - return EXIT_SUCCESS; - } - - if (index_path.starts_with("-")) { - NeBuild::Logger::info() << "error: unknown option '" << index_path << "'\n"; - - return EXIT_FAILURE; - } - - std::thread job_build_thread( - [](std::string index_path) -> void { - NeBuild::IManifestBuilder* builder = nullptr; - - const auto kJsonExtension = ".json"; - - if (index_path.ends_with(kJsonExtension)) { - builder = new NeBuild::JSONManifestBuilder(); - - if (!builder) { - kFailed = true; - return; - } - } else { - const auto kTomlExtension = ".toml"; - builder = new NeBuild::TOMLManifestBuilder(); - - if (index_path.ends_with(kTomlExtension)) { - goto end; - } else { - NeBuild::Logger::info() - << "error: file '" << index_path << "' is not a JSON file!" << std::endl; - kFailed = true; - return; - } - } - - end: - NeBuild::Logger::info() << "building manifest: " << index_path << std::endl; - - if (builder && !builder->BuildTarget(index_path, kDryRun)) { - kFailed = true; - } - - delete builder; - builder = nullptr; - }, - index_path); - - job_build_thread.join(); - } - - return kFailed ? EXIT_FAILURE : EXIT_SUCCESS; -} diff --git a/dev/cli/AppMain.cc b/dev/cli/AppMain.cc new file mode 100644 index 0000000..53cbdf3 --- /dev/null +++ b/dev/cli/AppMain.cc @@ -0,0 +1,83 @@ + +// ============================================================= // +// nebuild +// Copyright (C) 2024-2025, Amlal El Mahrouss, licensed under BSD-3 license. +// ============================================================= // + +#include +#include + +static bool kFailed = false; +static bool kDryRun = false; + +int main(int argc, char** argv) { + if (argc <= 1) return EXIT_FAILURE; + + for (size_t index = 1; index < argc; ++index) { + std::string index_path = argv[index]; + + if (index_path == "-v" || index_path == "--version") { + NeBuild::Logger::info() << "NeKernel Build.\n"; + NeBuild::Logger::info() + << "Bugs or issues? Check out: https://github.com/nekernel-org/nebuild/issues\n"; + + return EXIT_SUCCESS; + } else if (index_path == "--dry-run" || index_path == "-n") { + kDryRun = true; + continue; + } else if (index_path == "-h" || index_path == "--help") { + NeBuild::Logger::info() << "usage: nebuild \n"; + + return EXIT_SUCCESS; + } + + if (index_path.starts_with("-")) { + NeBuild::Logger::info() << "error: unknown option '" << index_path << "'\n"; + + return EXIT_FAILURE; + } + + std::thread job_build_thread( + [](std::string index_path) -> void { + NeBuild::IManifestBuilder* builder = nullptr; + + const auto kJsonExtension = ".json"; + + if (index_path.ends_with(kJsonExtension)) { + builder = new NeBuild::JSONManifestBuilder(); + + if (!builder) { + kFailed = true; + return; + } + } else { + const auto kTomlExtension = ".toml"; + builder = new NeBuild::TOMLManifestBuilder(); + + if (index_path.ends_with(kTomlExtension)) { + goto end; + } else { + NeBuild::Logger::info() + << "error: file '" << index_path << "' is not a manifest file!" << std::endl; + kFailed = true; + return; + } + } + + end: + NeBuild::Logger::info() << "building manifest: " << index_path << std::endl; + + if (builder && !builder->BuildTarget(index_path, kDryRun)) { + kFailed = true; + } + + delete builder; + builder = nullptr; + }, + index_path); + + job_build_thread.join(); + } + + return kFailed ? EXIT_FAILURE : EXIT_SUCCESS; +} diff --git a/dev/src/JSONManifestBuilder.cc b/dev/src/JSONManifestBuilder.cc index dba5b37..8eaf20a 100644 --- a/dev/src/JSONManifestBuilder.cc +++ b/dev/src/JSONManifestBuilder.cc @@ -10,11 +10,13 @@ namespace FS = std::filesystem; using namespace NeBuild; +/// =========================================================== /// /// @brief Builds a JSON target from a JSON file. /// @param arg_sz filename size (must be 1 or greater). /// @param arg_val filename path (must be a valid JSON file). /// @retval true building has succeeded. /// @retval false fail to build, see error message. +/// =========================================================== /// bool JSONManifestBuilder::BuildTarget(const std::string& argv_val, const bool dry_run) { std::string path; @@ -84,7 +86,6 @@ bool JSONManifestBuilder::BuildTarget(const std::string& argv_val, const bool dr auto target = json_obj["output_name"].get(); NeBuild::Logger::info() << "output path: " << target << "\n"; - NeBuild::Logger::info() << "command: " << command << "\n"; auto ret_exec = std::system(command.c_str()); @@ -94,13 +95,16 @@ bool JSONManifestBuilder::BuildTarget(const std::string& argv_val, const bool dr return false; } } catch (std::runtime_error& err) { - NeBuild::Logger::info() << "error: " << err.what() << std::endl; + NeBuild::Logger::info() << "error: exit with message: " << err.what() << "" << std::endl; return false; } return true; } +/// =========================================================== /// +/// @brief Returns the build system name. +/// =========================================================== /// const char* JSONManifestBuilder::BuildSystem() { return "NeBuild (JSON)"; } diff --git a/dev/src/TOMLManifestBuilder.cc b/dev/src/TOMLManifestBuilder.cc index 53034e8..f264ade 100644 --- a/dev/src/TOMLManifestBuilder.cc +++ b/dev/src/TOMLManifestBuilder.cc @@ -9,11 +9,13 @@ namespace FS = std::filesystem; using namespace NeBuild; +/// =========================================================== /// /// @brief Builds a TOML target from a TOML file. /// @param arg_sz filename size (must be 1 or greater). /// @param arg_val filename path (must be a valid TOML file). /// @retval true building has succeeded. /// @retval false fail to build, see error message. +/// =========================================================== /// bool TOMLManifestBuilder::BuildTarget(const std::string& argv_val, const bool dry_run) { std::string path; @@ -77,15 +79,17 @@ bool TOMLManifestBuilder::BuildTarget(const std::string& argv_val, const bool dr } } - if (toml_file["compiler_std"].is_string()) - command += "-std=" + toml_file["compiler_std"].as_string()->get() + " "; + if (!toml_file["compiler_std"].is_string()) return false; + + command += "-std=" + toml_file["compiler_std"].as_string()->get() + " "; + + if (toml_file["output_name"].as_string() == nullptr) return false; command += "-o " + toml_file["output_name"].as_string()->get(); auto target = toml_file["output_name"].as_string()->get(); - NeBuild::Logger::info() << "output path: " << target << "\n"; - NeBuild::Logger::info() << "command: " << command << "\n"; + NeBuild::Logger::info() << "output: " << target << "\n"; auto ret_exec = std::system(command.c_str()); @@ -95,13 +99,16 @@ bool TOMLManifestBuilder::BuildTarget(const std::string& argv_val, const bool dr return false; } } catch (std::runtime_error& err) { - NeBuild::Logger::info() << "error: " << err.what() << std::endl; + NeBuild::Logger::info() << "error: exit with message: " << err.what() << "" << std::endl; return false; } return true; } +/// =========================================================== /// +/// @brief Returns the build system name. +/// =========================================================== /// const char* TOMLManifestBuilder::BuildSystem() { return "NeBuild (TOML)"; } -- cgit v1.2.3