From a3ea256d00e5aac45574c7c8b076b60630f73a95 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Thu, 24 Jul 2025 09:15:17 +0100 Subject: feat! refactor! Breaking changes of the NeBuild system. Working on a TOML backend, refactored source code namespace. And add 'toml++' vendor library. See commit details. Signed-off-by: Amlal El Mahrouss --- dev/BuildKit/Defines.h | 30 ++++++++++++ dev/BuildKit/IManifestBuilder.h | 9 ++-- dev/BuildKit/Imports.h | 23 +++++++++ dev/BuildKit/Includes.h | 17 ------- dev/BuildKit/JSONManifestBuilder.h | 6 +-- dev/BuildKit/Macros.h | 34 -------------- dev/BuildKit/TOMLManifestBuilder.h | 33 +++++++++++++ dev/cli/CommandLine.cc | 77 ------------------------------- dev/cli/Tool.cc | 76 ++++++++++++++++++++++++++++++ dev/examples/example_02_libbtb/libbtb.cc | 2 +- dev/examples/example_02_libbtb/posix.json | 2 +- dev/examples/example_02_libbtb/win64.json | 2 +- dev/src/JSONManifestBuilder.cc | 26 +++++------ 13 files changed, 185 insertions(+), 152 deletions(-) create mode 100644 dev/BuildKit/Defines.h create mode 100644 dev/BuildKit/Imports.h delete mode 100644 dev/BuildKit/Includes.h delete mode 100644 dev/BuildKit/Macros.h create mode 100644 dev/BuildKit/TOMLManifestBuilder.h delete mode 100644 dev/cli/CommandLine.cc create mode 100644 dev/cli/Tool.cc (limited to 'dev') diff --git a/dev/BuildKit/Defines.h b/dev/BuildKit/Defines.h new file mode 100644 index 0000000..d408058 --- /dev/null +++ b/dev/BuildKit/Defines.h @@ -0,0 +1,30 @@ +// ============================================================= // +// nebuild +// Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. +// ============================================================= // + +#pragma once + +#include + +#define LIKELY(ARG) ((ARG) ? assert(false) : ((void) 0)) +#define UNLIKELY(ARG) LIKELY(!(ARG)) + +#define LIBNEBUILD_VERSION "v0.0.1-libNeBuild" + +#define LIBNEBUILD_VERSION_BCD 0x0001 + +#define LIBNEBUILD_VERSION_MAJOR 1 +#define LIBNEBUILD_VERSION_MINOR 1 +#define LIBNEBUILD_VERSION_PATCH 0 + +#define LIBNEBUILD_UNUSED(X) ((void) X) + +namespace NeBuild::Logger { +/// @brief replacement for std::cout for NeBuild logging. +inline std::ostream& info() noexcept { + auto& out = std::cout; + out << rang::fg::red << "nebuild: " << rang::style::reset; + return out; +} +} // namespace NeBuild::Logger diff --git a/dev/BuildKit/IManifestBuilder.h b/dev/BuildKit/IManifestBuilder.h index 065bec3..a0e5d85 100644 --- a/dev/BuildKit/IManifestBuilder.h +++ b/dev/BuildKit/IManifestBuilder.h @@ -5,12 +5,11 @@ #pragma once -#include -#include +#include -#define NEBUILD_MANIFEST_BUILDER : public BTB::IManifestBuilder +#define NEBUILD_MANIFEST_BUILDER : public NeBuild::IManifestBuilder -namespace BTB { +namespace NeBuild { /// @brief Builder interface class. /// @note This class is meant to be used as an interface. class IManifestBuilder { @@ -29,4 +28,4 @@ class IManifestBuilder { virtual bool buildTarget(int arg_sz, const char* arg_val, const bool dry_run = false) = 0; virtual const char* buildSystem() = 0; }; -} // namespace BTB \ No newline at end of file +} // namespace NeBuild \ No newline at end of file diff --git a/dev/BuildKit/Imports.h b/dev/BuildKit/Imports.h new file mode 100644 index 0000000..b365dca --- /dev/null +++ b/dev/BuildKit/Imports.h @@ -0,0 +1,23 @@ +// ============================================================= // +// nebuild +// Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. +// ============================================================= // + +#ifndef NEBUILD_INCLUDES_H +#define NEBUILD_INCLUDES_H + +#include +#include +#include +#include +#include +#include +#include + +extern "C" { +#include +} + +#include + +#endif // NEBUILD_INCLUDES_H diff --git a/dev/BuildKit/Includes.h b/dev/BuildKit/Includes.h deleted file mode 100644 index 4cb3043..0000000 --- a/dev/BuildKit/Includes.h +++ /dev/null @@ -1,17 +0,0 @@ -// ============================================================= // -// nebuild -// Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. -// ============================================================= // - -#ifndef NEBUILD_INCLUDES_H -#define NEBUILD_INCLUDES_H - -#include -#include -#include -#include -#include -#include -#include - -#endif // NEBUILD_INCLUDES_H diff --git a/dev/BuildKit/JSONManifestBuilder.h b/dev/BuildKit/JSONManifestBuilder.h index f7c769d..ba34a69 100644 --- a/dev/BuildKit/JSONManifestBuilder.h +++ b/dev/BuildKit/JSONManifestBuilder.h @@ -6,12 +6,12 @@ #pragma once #include -#include +#include /// @file JSONManifestBuilder.h /// @brief JSON manifest builder header file. -namespace BTB { +namespace NeBuild { /// @brief JSON builder class JSONManifestBuilder final NEBUILD_MANIFEST_BUILDER { public: @@ -30,4 +30,4 @@ class JSONManifestBuilder final NEBUILD_MANIFEST_BUILDER { bool buildTarget(int arg_sz, const char* arg_val, const bool dry_run = false) override; const char* buildSystem() override; }; -} // namespace BTB \ No newline at end of file +} // namespace NeBuild \ No newline at end of file diff --git a/dev/BuildKit/Macros.h b/dev/BuildKit/Macros.h deleted file mode 100644 index 98bf891..0000000 --- a/dev/BuildKit/Macros.h +++ /dev/null @@ -1,34 +0,0 @@ -// ============================================================= // -// nebuild -// Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. -// ============================================================= // - -#pragma once - -extern "C" { -#include -} - -#include - -#define LIKELY(ARG) ((ARG) ? assert(false) : ((void) 0)) -#define UNLIKELY(ARG) LIKELY(!(ARG)) - -#define LIBNEBUILD_VERSION "v0.0.1-libNeBuild" - -#define LIBNEBUILD_VERSION_BCD 0x0001 - -#define LIBNEBUILD_VERSION_MAJOR 1 -#define LIBNEBUILD_VERSION_MINOR 1 -#define LIBNEBUILD_VERSION_PATCH 0 - -#define LIBNEBUILD_UNUSED(X) ((void) X) - -namespace BTB::Logger { -/// @brief replacement for std::cout for BTB logging. -inline std::ostream& info() noexcept { - auto& out = std::cout; - out << rang::fg::red << "nebuild: " << rang::style::reset; - return out; -} -} // namespace BTB::Logger diff --git a/dev/BuildKit/TOMLManifestBuilder.h b/dev/BuildKit/TOMLManifestBuilder.h new file mode 100644 index 0000000..5037967 --- /dev/null +++ b/dev/BuildKit/TOMLManifestBuilder.h @@ -0,0 +1,33 @@ +// ============================================================= // +// nebuild +// Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. +// ============================================================= // + +#pragma once + +#include +#include + +/// @file TOMLManifestBuilder.h +/// @brief TOML manifest builder header file. + +namespace NeBuild { +/// @brief TOML builder +class TOMLManifestBuilder final NEBUILD_MANIFEST_BUILDER { + public: + TOMLManifestBuilder() = default; + ~TOMLManifestBuilder() override = default; + + TOMLManifestBuilder& operator=(const TOMLManifestBuilder&) = default; + 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(int arg_sz, const char* arg_val, const bool dry_run = false) override; + const char* buildSystem() override; +}; +} // namespace NeBuild \ No newline at end of file diff --git a/dev/cli/CommandLine.cc b/dev/cli/CommandLine.cc deleted file mode 100644 index e199e61..0000000 --- a/dev/cli/CommandLine.cc +++ /dev/null @@ -1,77 +0,0 @@ - -// ============================================================= // -// nebuild -// Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. -// ============================================================= // - -#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") { - BTB::Logger::info() << "Brought to you by Amlal El Mahrouss for the NeKernel project.\n"; - BTB::Logger::info() << "© 2024-2025 Amlal El Mahrouss, all rights reserved.\n"; - - BTB::Logger::info() - << "Bugs, issues? Check out: https://github.com/nekernel-org/nebuild/issues\n"; - - return EXIT_SUCCESS; - } else if (index_path == "--dry-run") { - kDryRun = true; - continue; - } else if (index_path == "-h" || index_path == "--help") { - BTB::Logger::info() << "Usage: nebuild \n"; - - return EXIT_SUCCESS; - } - - if (index_path.starts_with("-")) { - BTB::Logger::info() << "error: unknown option '" << index_path << "'\n"; - - return EXIT_FAILURE; - } - - std::thread job_build_thread( - [](std::string index_path) -> void { - BTB::IManifestBuilder* builder = nullptr; - - const auto kJsonExtension = ".json"; - - if (index_path.ends_with(kJsonExtension)) { - builder = new BTB::JSONManifestBuilder(); - - if (!builder) { - kFailed = true; - return; - } - } else { - BTB::Logger::info() << "error: file '" << index_path << "' is not a JSON file!" - << std::endl; - kFailed = true; - return; - } - - BTB::Logger::info() << "building manifest: " << index_path << std::endl; - - if (builder && !builder->buildTarget(index_path.size(), index_path.c_str(), kDryRun)) { - kFailed = true; - } - - delete builder; - builder = nullptr; - }, - index_path); - - job_build_thread.join(); - } - - return kFailed ? EXIT_FAILURE : EXIT_SUCCESS; -} diff --git a/dev/cli/Tool.cc b/dev/cli/Tool.cc new file mode 100644 index 0000000..07aa220 --- /dev/null +++ b/dev/cli/Tool.cc @@ -0,0 +1,76 @@ + +// ============================================================= // +// nebuild +// Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. +// ============================================================= // + +#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() << "Brought to you by Amlal El Mahrouss for NeKernel.org.\n"; + NeBuild::Logger::info() << "© 2024-2025 Amlal El Mahrouss, all rights reserved.\n"; + + NeBuild::Logger::info() + << "Bugs, issues? Check out: https://github.com/nekernel-org/nebuild/issues\n"; + + return EXIT_SUCCESS; + } else if (index_path == "--dry-run") { + 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 { + NeBuild::Logger::info() << "error: file '" << index_path << "' is not a JSON file!" + << std::endl; + kFailed = true; + return; + } + + NeBuild::Logger::info() << "building manifest: " << index_path << std::endl; + + if (builder && !builder->buildTarget(index_path.size(), index_path.c_str(), kDryRun)) { + kFailed = true; + } + + delete builder; + builder = nullptr; + }, + index_path); + + job_build_thread.join(); + } + + return kFailed ? EXIT_FAILURE : EXIT_SUCCESS; +} diff --git a/dev/examples/example_02_libbtb/libbtb.cc b/dev/examples/example_02_libbtb/libbtb.cc index 0b4d7c4..e6e489d 100644 --- a/dev/examples/example_02_libbtb/libbtb.cc +++ b/dev/examples/example_02_libbtb/libbtb.cc @@ -8,7 +8,7 @@ static auto kPath = ".\win64.json"; #endif int main(int argc, char** argv) { - auto builder = new BTB::JSONManifestBuilder(); + auto builder = new NeBuild::JSONManifestBuilder(); if (!builder) return EXIT_FAILURE; return builder->buildTarget(strlen(kPath), kPath); diff --git a/dev/examples/example_02_libbtb/posix.json b/dev/examples/example_02_libbtb/posix.json index 871712e..47f08ba 100644 --- a/dev/examples/example_02_libbtb/posix.json +++ b/dev/examples/example_02_libbtb/posix.json @@ -11,7 +11,7 @@ "output_name": "libbtb.elf", "compiler_flags": [ "-L/usr/local/lib", - "-lBTB" + "-lNeBuild" ], "cpp_macros": [ "FOO_MACRO" diff --git a/dev/examples/example_02_libbtb/win64.json b/dev/examples/example_02_libbtb/win64.json index 658ee0f..a873f5d 100644 --- a/dev/examples/example_02_libbtb/win64.json +++ b/dev/examples/example_02_libbtb/win64.json @@ -10,7 +10,7 @@ ], "output_name": "libbtb.exe", "compiler_flags": [ - "-lBTB" + "-lNeBuild" ], "cpp_macros": [ "FOO_MACRO" diff --git a/dev/src/JSONManifestBuilder.cc b/dev/src/JSONManifestBuilder.cc index aa277c7..6b72ff0 100644 --- a/dev/src/JSONManifestBuilder.cc +++ b/dev/src/JSONManifestBuilder.cc @@ -10,7 +10,7 @@ using JSON = nlohmann::json; namespace FS = std::filesystem; -using namespace BTB; +using namespace NeBuild; /// @brief Builds a JSON target from a JSON file. /// @param arg_sz filename size (must be 1 or greater). @@ -21,13 +21,13 @@ bool JSONManifestBuilder::buildTarget(int arg_sz, const char* arg_val, const boo String path; if (!arg_val || arg_sz < 0) { - BTB::Logger::info() << "nebuild: error: file path is empty" << std::endl; + NeBuild::Logger::info() << "nebuild: error: file path is empty" << std::endl; return false; } else { path += arg_val; if (!FS::exists(path)) { - BTB::Logger::info() << "nebuild: error: file '" << path << "' does not exist" << std::endl; + NeBuild::Logger::info() << "nebuild: error: file '" << path << "' does not exist" << std::endl; return false; } } @@ -36,7 +36,7 @@ bool JSONManifestBuilder::buildTarget(int arg_sz, const char* arg_val, const boo std::ifstream json(path); if (!json.good()) { - BTB::Logger::info() << "nebuild: error: file '" << path << "' is not a valid JSON" << std::endl; + NeBuild::Logger::info() << "nebuild: error: file '" << path << "' is not a valid JSON" << std::endl; return false; } @@ -76,8 +76,8 @@ bool JSONManifestBuilder::buildTarget(int arg_sz, const char* arg_val, const boo auto target = json_obj["output_name"].get(); - BTB::Logger::info() << "output path: " << target << "\n"; - BTB::Logger::info() << "command: " << command << "\n"; + NeBuild::Logger::info() << "output path: " << target << "\n"; + NeBuild::Logger::info() << "command: " << command << "\n"; try { if (json_obj["dry_run"].get()) return true; @@ -91,14 +91,14 @@ bool JSONManifestBuilder::buildTarget(int arg_sz, const char* arg_val, const boo auto ret_exec = std::system(command.c_str()); if (ret_exec > 0) { - BTB::Logger::info() << "error: exit with message: " << std::strerror(ret_exec) << "" << std::endl; + NeBuild::Logger::info() << "error: exit with message: " << std::strerror(ret_exec) << "" << std::endl; return false; } try { if (json_obj["run_after_build"].get()) { if (target.ends_with(".so")) { - BTB::Logger::info() << "error: can't open dynamic library, it mayn't have an entrypoint" + NeBuild::Logger::info() << "error: can't open dynamic library, it mayn't have an entrypoint" << std::endl; return true; @@ -109,20 +109,20 @@ bool JSONManifestBuilder::buildTarget(int arg_sz, const char* arg_val, const boo ss << file.rdbuf(); if (ss.str()[0] == 'O' && ss.str()[1] == 'p' && ss.str()[2] == 'e' && ss.str()[3] == 'n') - BTB::Logger::info() + NeBuild::Logger::info() << "error: can't open PEF dynamic library, it mayn't contain an entrypoint" << std::endl; else if (ss.str()[0] == 'n' && ss.str()[1] == 'e' && ss.str()[2] == 'p' && ss.str()[3] == 'O') - BTB::Logger::info() + NeBuild::Logger::info() << "error: can't open FEP dynamic library, it mayn't contain an entrypoint" << std::endl; else if (ss.str()[0] == 'M' && ss.str()[1] == 'Z') - BTB::Logger::info() + NeBuild::Logger::info() << "error: can't open MZ dynamic library, it mayn't contain an entrypoint" << std::endl; else if (ss.str()[0] == 0x7F && ss.str()[1] == 'E') { - BTB::Logger::info() + NeBuild::Logger::info() << "error: can't open ELF dynamic library, it mayn't contain an entrypoint" << std::endl; } @@ -140,7 +140,7 @@ bool JSONManifestBuilder::buildTarget(int arg_sz, const char* arg_val, const boo return true; } } catch (std::runtime_error& err) { - BTB::Logger::info() << "error: " << err.what() << std::endl; + NeBuild::Logger::info() << "error: " << err.what() << std::endl; return false; } -- cgit v1.2.3