From fe03952bf6dbf32509a9322e34ac1b5c9d0dbe25 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Fri, 27 Feb 2026 22:43:34 +0100 Subject: chore: update NeBuild file structure. Signed-off-by: Amlal El Mahrouss --- CMakeLists.txt | 14 ++-- Makefile | 4 +- install_windows.cmake | 6 +- scripts/osx-dylib.json | 2 +- scripts/posix-dylib.json | 2 +- scripts/win64-dylib.json | 2 +- src/CommandLine/CLI.cpp | 83 +++++++++++++++++++++ src/NeBuildKit/IManifestBuilder.cpp | 6 ++ src/NeBuildKit/JSONManifestBuilder.cpp | 125 +++++++++++++++++++++++++++++++ src/NeBuildKit/TOMLManifestBuilder.cpp | 130 +++++++++++++++++++++++++++++++++ src/cli/CLI.cpp | 83 --------------------- src/lib/IManifestBuilder.cpp | 6 -- src/lib/JSONManifestBuilder.cpp | 125 ------------------------------- src/lib/TOMLManifestBuilder.cpp | 130 --------------------------------- 14 files changed, 359 insertions(+), 359 deletions(-) create mode 100644 src/CommandLine/CLI.cpp create mode 100644 src/NeBuildKit/IManifestBuilder.cpp create mode 100644 src/NeBuildKit/JSONManifestBuilder.cpp create mode 100644 src/NeBuildKit/TOMLManifestBuilder.cpp delete mode 100644 src/cli/CLI.cpp delete mode 100644 src/lib/IManifestBuilder.cpp delete mode 100644 src/lib/JSONManifestBuilder.cpp delete mode 100644 src/lib/TOMLManifestBuilder.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 840cdba..3e65588 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ # // ============================================================= // -# // NeBuild -# // Copyright (C) 2025-2026, Amlal El Mahrouss, licensed under BSD-3 license. +# // NeBuild System. +# // Copyright (C) 2025-2026, Amlal El Mahrouss and Ne.org, licensed under BSD-3 license. # // ============================================================= // # AMLALE: Update the CMake version, which requires a version that was too old. @@ -14,22 +14,22 @@ set(CMAKE_CXX_EXTENSIONS OFF) include_directories(${CMAKE_SOURCE_DIR}/src ${CMAKE_SOURCE_DIR}/vendor) -file(GLOB NEBUILD_CLI_SOURCES "${CMAKE_SOURCE_DIR}/src/cli/*.cc") -file(GLOB NEBUILD_SRC_SOURCES "${CMAKE_SOURCE_DIR}/src/lib/*.cc") +file(GLOB NEBUILD_CLI_SOURCES "${CMAKE_SOURCE_DIR}/src/CommandLine/*.cc") +file(GLOB NEBUILD_SRC_SOURCES "${CMAKE_SOURCE_DIR}/src/NeBuildKit/*.cc") set(NEBUILD_SOURCES ${NEBUILD_CLI_SOURCES} ${NEBUILD_SRC_SOURCES}) add_executable(nebuild ${NEBUILD_SOURCES}) target_include_directories(nebuild PRIVATE ${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/vendor) -option(BUILD_WINDOWS "Produce a Windows executable name (nebuild.exe)" OFF) +option(BUILD_WINDOWS "=> Produce a Windows executable name (nebuild.exe)" OFF) add_custom_target(build-nebuild COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target nebuild COMMENT "=> NeBuild built successfully for POSIX." ) -message(STATUS "Sources: ${NEBUILD_SOURCES}") -message(STATUS "Include Dirs: ${CMAKE_SOURCE_DIR}/src;${CMAKE_SOURCE_DIR}/vendor") +message(STATUS "=> Sources: ${NEBUILD_SOURCES}") +message(STATUS "=> Include Dirs: ${CMAKE_SOURCE_DIR}/src;${CMAKE_SOURCE_DIR}/vendor") include(install_windows.cmake) diff --git a/Makefile b/Makefile index 7c79b23..e003bc0 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ GCC=clang++ GCC_MINGW=x86_64-w64-mingw32-g++ CXXFLAGS=-I./include -L/usr/local/lib -I./vendor -lNeBuildKit CXXSTD= -std=c++20 -SRC=$(wildcard src/cli/*.cpp) +SRC=$(wildcard src/CommandLine/*.cpp) OUT=nebuild CP=cp @@ -24,7 +24,7 @@ build-nebuild-windows: .PHONY: help help: - @echo "=> NEBUILD HELP:" + @echo "=> NeBuild:" @echo "=> help: Show this help message." @echo "=> build-nebuild-windows: Build NeBuild for Windows." @echo "=> build-nebuild: Build NeBuild for POSIX." diff --git a/install_windows.cmake b/install_windows.cmake index b758a73..792b4a9 100644 --- a/install_windows.cmake +++ b/install_windows.cmake @@ -1,6 +1,6 @@ # // ============================================================= // -# // NeBuild -# // Copyright (C) 2025-2026, Amlal El Mahrouss, licensed under BSD-3 license. +# // NeBuild System. +# // Copyright (C) 2025-2026, Amlal El Mahrouss and Ne.org Author, licensed under BSD-3 license. # // ============================================================= // # AMLALE: Update the CMake version, which requires a version that was too old. @@ -16,4 +16,4 @@ if(BUILD_WINDOWS) ) endif() -message(STATUS "To build for Windows-style executable: configure with -DBUILD_WINDOWS=ON") \ No newline at end of file +message(STATUS "To build for Windows-style executable: configure with -DBUILD_WINDOWS=ON") diff --git a/scripts/osx-dylib.json b/scripts/osx-dylib.json index 675a231..448cc00 100644 --- a/scripts/osx-dylib.json +++ b/scripts/osx-dylib.json @@ -2,7 +2,7 @@ "compiler_path": "clang++", "compiler_std": "c++20", "headers_path": ["include", "vendor"], - "sources_path": ["src/lib/*.cpp"], + "sources_path": ["src/NeBuildKit/*.cpp"], "output_name": "libNeBuildKit.dylib", "compiler_flags": ["-fPIC", "-shared"], "cpp_macros": ["NEBUILD_INTERNAL_SDK", "NEBUILD_OSX"], diff --git a/scripts/posix-dylib.json b/scripts/posix-dylib.json index 5d1b9d1..66d9dc4 100644 --- a/scripts/posix-dylib.json +++ b/scripts/posix-dylib.json @@ -2,7 +2,7 @@ "compiler_path": "clang++", "compiler_std": "c++20", "headers_path": ["include/", "vendor"], - "sources_path": ["src/lib/*.cpp"], + "sources_path": ["src/NeBuildKit/*.cpp"], "output_name": "libNeBuildKit.so", "compiler_flags": ["-fPIC", "-shared"], "cpp_macros": ["NEBUILD_POSIX", "NEBUILD_INTERNAL_SDK"], diff --git a/scripts/win64-dylib.json b/scripts/win64-dylib.json index 5a88251..f4f22ee 100644 --- a/scripts/win64-dylib.json +++ b/scripts/win64-dylib.json @@ -2,7 +2,7 @@ "compiler_path": "x86_64-w64-mingw32-g++.exe", "compiler_std": "c++20", "headers_path": ["include", "vendor"], - "sources_path": ["src/lib/*.cpp"], + "sources_path": ["src/NeBuildKit/*.cpp"], "output_name": "libNeBuildKit.dll", "compiler_flags": ["-fPIC", "-shared"], "cpp_macros": ["NEBUILD_WINDOWS", "NEBUILD_INTERNAL_SDK"], diff --git a/src/CommandLine/CLI.cpp b/src/CommandLine/CLI.cpp new file mode 100644 index 0000000..a21c4ad --- /dev/null +++ b/src/CommandLine/CLI.cpp @@ -0,0 +1,83 @@ + +// ============================================================= // +// NeBuild +// FILE: main.cc +// PURPOSE: Main Tool Entrypoint. +// Copyright (C) 2024-2025, Amlal El Mahrouss and NeKernel Authors, licensed under BSD-3 license. +// ============================================================= // + +#include +#include +#include +#include + +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 (" << NEBUILD_VERSION << ")\n"; + return EXIT_SUCCESS; + } else if (index_path == "-dry-run" || index_path == "-n") { + config.dry_run(true); + continue; + } else if (index_path == "-h" || index_path == "-help") { + NeBuild::Logger::info() << "nebuild \n"; + return EXIT_SUCCESS; + } + + auto index_cpy = index; + + std::thread job_build_thread([&index_path, &index, &index_cpy, &argc, &argv, &config]() -> void { + std::unique_ptr builder; + + constexpr auto kJsonExtension = ".json"; + + if (index_path.ends_with(kJsonExtension)) { + builder = std::make_unique(); + + /// report failed build to config. + if (!builder) { + config.has_failed(true); + return; + } + } else { + constexpr auto kTomlExtension = ".toml"; + builder = std::make_unique(); + + 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; + } + } + + std::string next_path; + + 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); + } + + NeBuild::Logger::info() << "building manifest: " << index_path << std::endl; + + config.path(index_path); + + if (builder && !builder->BuildTarget(config)) { + config.has_failed(true); + } + }); + + job_build_thread.join(); + } + + // check for whether config is valid. if so return failure, or success. + return !config ? EXIT_FAILURE : EXIT_SUCCESS; +} diff --git a/src/NeBuildKit/IManifestBuilder.cpp b/src/NeBuildKit/IManifestBuilder.cpp new file mode 100644 index 0000000..2a61ed0 --- /dev/null +++ b/src/NeBuildKit/IManifestBuilder.cpp @@ -0,0 +1,6 @@ +// ============================================================= // +// NeBuild +// Copyright (C) 2024-2025, Amlal El Mahrouss and NeKernel Authors, licensed under BSD-3 license. +// ============================================================= // + +#include diff --git a/src/NeBuildKit/JSONManifestBuilder.cpp b/src/NeBuildKit/JSONManifestBuilder.cpp new file mode 100644 index 0000000..0cc9fd3 --- /dev/null +++ b/src/NeBuildKit/JSONManifestBuilder.cpp @@ -0,0 +1,125 @@ +// ============================================================= // +// NeBuild +// PURPOSE: JSON build support. +// Copyright (C) 2024-2026, Amlal El Mahrouss and NeKernel Authors, licensed under BSD-3 license. +// ============================================================= // + +#include +#include +#include + +namespace NeBuild { + +namespace FS = std::filesystem; + +/// =========================================================== /// +/// @brief Builds a nlohmann::json target from a nlohmann::json file. +/// @param arg_sz filename size (must be 1 or greater). +/// @param arg_val filename path (must be a valid nlohmann::json file). +/// @return bool: whether the build has succeeded or not. +/// =========================================================== /// +bool JSONManifestBuilder::BuildTarget(BuildConfig& config) { + std::string path; + + if (config.path_.empty()) { + NeBuild::Logger::info() << "error: file path is empty" << std::endl; + return false; + } else { + path = config.path_; + + if (!FS::exists(path)) { + NeBuild::Logger::info() << "error: file '" << path << "' does not exist" + << std::endl; + return false; + } + } + + try { + std::ifstream json(path); + + if (!json.good()) { + NeBuild::Logger::info() << "error: file '" << path + << "' is not a valid nlohmann::json" << std::endl; + return false; + } + + nlohmann::json json_obj = nlohmann::json::parse(json); + + try { + nlohmann::json description = json_obj["description"]; + + NeBuild::Logger::info() << "package path: " << path << std::endl; + + if (auto res = description.get(); !res.empty()) + NeBuild::Logger::info() << "description: " << res << std::endl; + } catch (...) {} + + std::string compiler = json_obj["compiler_path"].get(); + + std::string command = compiler + " "; + + nlohmann::json header_search_path = json_obj["compiler_headers_path"]; + + for (auto& headers : header_search_path) { + command += "-I" + headers.get() + " "; + } + + nlohmann::json headers_path = json_obj["headers_path"]; + + for (auto& headers : headers_path) { + command += "-I" + headers.get() + " "; + } + + nlohmann::json sources_files = json_obj["sources_path"]; + + for (auto& sources : sources_files) { + command += sources.get() + " "; + } + + nlohmann::json macros_list = json_obj["cpp_macros"]; + + for (auto& macro : macros_list) { + command += "-D" + macro.get() + " "; + } + + nlohmann::json compiler_flags = json_obj["compiler_flags"]; + + for (auto& flag : compiler_flags) { + command += flag.get() + " "; + } + + if (json_obj["compiler_std"].is_string()) + command += "-std=" + json_obj["compiler_std"].get() + " "; + + command += "-o " + json_obj["output_name"].get(); + + auto target = json_obj["output_name"].get(); + + NeBuild::Logger::info() << "output path: " << target << "\n"; + + auto ret_exec = std::system(command.c_str()); + + if (ret_exec > 0) { + NeBuild::Logger::info() << "error: exit with message: " << std::strerror(ret_exec) << "" + << std::endl; + config.has_failed_ = true; + return false; + } + } catch (const std::exception& err) { + NeBuild::Logger::info() << "error: exit with message: " << err.what() << "" << std::endl; + config.has_failed_ = true; + + return false; + } + + return true; +} + +/// =========================================================== /// +/// @brief Returns the build system name. +/// =========================================================== /// +const std::string_view JSONManifestBuilder::BuildSystem() { + return "NeBuild (nlohmann::json)"; +} + +} // namespace NeBuild diff --git a/src/NeBuildKit/TOMLManifestBuilder.cpp b/src/NeBuildKit/TOMLManifestBuilder.cpp new file mode 100644 index 0000000..cce9384 --- /dev/null +++ b/src/NeBuildKit/TOMLManifestBuilder.cpp @@ -0,0 +1,130 @@ +// ============================================================= // +// NeBuild +// PURPOSE: TOML build support. +// Copyright (C) 2024-2026, Amlal El Mahrouss and NeKernel Authors, licensed under BSD-3 license. +// ============================================================= // + +#include +#include +#include + +namespace NeBuild { + +namespace FS = std::filesystem; + +/// =========================================================== /// +/// @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). +/// @return bool: whether the build has succeeded or not. +/// =========================================================== /// +bool TOMLManifestBuilder::BuildTarget(BuildConfig& config) { + std::string path; + + if (config.path_.empty()) { + NeBuild::Logger::info() << "error: file path is empty" << std::endl; + return false; + } else { + path = config.path_; + + if (!FS::exists(path)) { + NeBuild::Logger::info() << "error: file '" << path << "' does not exist" + << std::endl; + return false; + } + } + + try { + auto toml_file = toml::parse_file(path); + + try { + auto* description = toml_file["description"].as_string(); + + NeBuild::Logger::info() << "package path: " << path << std::endl; + + if (description) NeBuild::Logger::info() << "description: " << description->get() << std::endl; + } catch (...) { + // ... + } + + std::string compiler = toml_file["compiler_path"].as_string()->get(); + + std::string command = compiler + " "; + + auto header_search_path = toml_file["compiler_headers_path"].as_array(); + + if (header_search_path) { + for (auto& headers : *header_search_path) { + command += "-I" + headers.as_string()->get() + " "; + } + } + + auto headers_path = toml_file["headers_path"].as_array(); + + if (headers_path) { + for (auto& headers : *headers_path) { + command += "-I" + headers.as_string()->get() + " "; + } + } + + auto sources_files = toml_file["sources_path"].as_array(); + + if (sources_files) { + for (auto& sources : *sources_files) { + command += sources.as_string()->get() + " "; + } + } + + auto macros_list = toml_file["cpp_macros"].as_array(); + + if (macros_list) { + for (auto& macro : *macros_list) { + command += "-D" + macro.as_string()->get() + " "; + } + } + + auto compiler_flags = toml_file["compiler_flags"].as_array(); + + if (compiler_flags) { + for (auto& flag : *compiler_flags) { + command += flag.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: " << target << "\n"; + + auto ret_exec = std::system(command.c_str()); + + if (ret_exec > 0) { + NeBuild::Logger::info() << "error: exit with message: " << std::strerror(ret_exec) << "" + << std::endl; + config.has_failed_ = true; + return false; + } + } catch (const std::exception& err) { + NeBuild::Logger::info() << "error: exit with message: " << err.what() << "" << std::endl; + config.has_failed_ = true; + return false; + } + + return true; +} + +/// =========================================================== /// +/// @brief Returns the build system name. +/// =========================================================== /// +const std::string_view TOMLManifestBuilder::BuildSystem() { + return "NeBuild (toml++::toml)"; +} + +} // namespace NeBuild diff --git a/src/cli/CLI.cpp b/src/cli/CLI.cpp deleted file mode 100644 index a21c4ad..0000000 --- a/src/cli/CLI.cpp +++ /dev/null @@ -1,83 +0,0 @@ - -// ============================================================= // -// NeBuild -// FILE: main.cc -// PURPOSE: Main Tool Entrypoint. -// Copyright (C) 2024-2025, Amlal El Mahrouss and NeKernel Authors, licensed under BSD-3 license. -// ============================================================= // - -#include -#include -#include -#include - -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 (" << NEBUILD_VERSION << ")\n"; - return EXIT_SUCCESS; - } else if (index_path == "-dry-run" || index_path == "-n") { - config.dry_run(true); - continue; - } else if (index_path == "-h" || index_path == "-help") { - NeBuild::Logger::info() << "nebuild \n"; - return EXIT_SUCCESS; - } - - auto index_cpy = index; - - std::thread job_build_thread([&index_path, &index, &index_cpy, &argc, &argv, &config]() -> void { - std::unique_ptr builder; - - constexpr auto kJsonExtension = ".json"; - - if (index_path.ends_with(kJsonExtension)) { - builder = std::make_unique(); - - /// report failed build to config. - if (!builder) { - config.has_failed(true); - return; - } - } else { - constexpr auto kTomlExtension = ".toml"; - builder = std::make_unique(); - - 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; - } - } - - std::string next_path; - - 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); - } - - NeBuild::Logger::info() << "building manifest: " << index_path << std::endl; - - config.path(index_path); - - if (builder && !builder->BuildTarget(config)) { - config.has_failed(true); - } - }); - - job_build_thread.join(); - } - - // check for whether config is valid. if so return failure, or success. - return !config ? EXIT_FAILURE : EXIT_SUCCESS; -} diff --git a/src/lib/IManifestBuilder.cpp b/src/lib/IManifestBuilder.cpp deleted file mode 100644 index 2a61ed0..0000000 --- a/src/lib/IManifestBuilder.cpp +++ /dev/null @@ -1,6 +0,0 @@ -// ============================================================= // -// NeBuild -// Copyright (C) 2024-2025, Amlal El Mahrouss and NeKernel Authors, licensed under BSD-3 license. -// ============================================================= // - -#include diff --git a/src/lib/JSONManifestBuilder.cpp b/src/lib/JSONManifestBuilder.cpp deleted file mode 100644 index 0cc9fd3..0000000 --- a/src/lib/JSONManifestBuilder.cpp +++ /dev/null @@ -1,125 +0,0 @@ -// ============================================================= // -// NeBuild -// PURPOSE: JSON build support. -// Copyright (C) 2024-2026, Amlal El Mahrouss and NeKernel Authors, licensed under BSD-3 license. -// ============================================================= // - -#include -#include -#include - -namespace NeBuild { - -namespace FS = std::filesystem; - -/// =========================================================== /// -/// @brief Builds a nlohmann::json target from a nlohmann::json file. -/// @param arg_sz filename size (must be 1 or greater). -/// @param arg_val filename path (must be a valid nlohmann::json file). -/// @return bool: whether the build has succeeded or not. -/// =========================================================== /// -bool JSONManifestBuilder::BuildTarget(BuildConfig& config) { - std::string path; - - if (config.path_.empty()) { - NeBuild::Logger::info() << "error: file path is empty" << std::endl; - return false; - } else { - path = config.path_; - - if (!FS::exists(path)) { - NeBuild::Logger::info() << "error: file '" << path << "' does not exist" - << std::endl; - return false; - } - } - - try { - std::ifstream json(path); - - if (!json.good()) { - NeBuild::Logger::info() << "error: file '" << path - << "' is not a valid nlohmann::json" << std::endl; - return false; - } - - nlohmann::json json_obj = nlohmann::json::parse(json); - - try { - nlohmann::json description = json_obj["description"]; - - NeBuild::Logger::info() << "package path: " << path << std::endl; - - if (auto res = description.get(); !res.empty()) - NeBuild::Logger::info() << "description: " << res << std::endl; - } catch (...) {} - - std::string compiler = json_obj["compiler_path"].get(); - - std::string command = compiler + " "; - - nlohmann::json header_search_path = json_obj["compiler_headers_path"]; - - for (auto& headers : header_search_path) { - command += "-I" + headers.get() + " "; - } - - nlohmann::json headers_path = json_obj["headers_path"]; - - for (auto& headers : headers_path) { - command += "-I" + headers.get() + " "; - } - - nlohmann::json sources_files = json_obj["sources_path"]; - - for (auto& sources : sources_files) { - command += sources.get() + " "; - } - - nlohmann::json macros_list = json_obj["cpp_macros"]; - - for (auto& macro : macros_list) { - command += "-D" + macro.get() + " "; - } - - nlohmann::json compiler_flags = json_obj["compiler_flags"]; - - for (auto& flag : compiler_flags) { - command += flag.get() + " "; - } - - if (json_obj["compiler_std"].is_string()) - command += "-std=" + json_obj["compiler_std"].get() + " "; - - command += "-o " + json_obj["output_name"].get(); - - auto target = json_obj["output_name"].get(); - - NeBuild::Logger::info() << "output path: " << target << "\n"; - - auto ret_exec = std::system(command.c_str()); - - if (ret_exec > 0) { - NeBuild::Logger::info() << "error: exit with message: " << std::strerror(ret_exec) << "" - << std::endl; - config.has_failed_ = true; - return false; - } - } catch (const std::exception& err) { - NeBuild::Logger::info() << "error: exit with message: " << err.what() << "" << std::endl; - config.has_failed_ = true; - - return false; - } - - return true; -} - -/// =========================================================== /// -/// @brief Returns the build system name. -/// =========================================================== /// -const std::string_view JSONManifestBuilder::BuildSystem() { - return "NeBuild (nlohmann::json)"; -} - -} // namespace NeBuild diff --git a/src/lib/TOMLManifestBuilder.cpp b/src/lib/TOMLManifestBuilder.cpp deleted file mode 100644 index cce9384..0000000 --- a/src/lib/TOMLManifestBuilder.cpp +++ /dev/null @@ -1,130 +0,0 @@ -// ============================================================= // -// NeBuild -// PURPOSE: TOML build support. -// Copyright (C) 2024-2026, Amlal El Mahrouss and NeKernel Authors, licensed under BSD-3 license. -// ============================================================= // - -#include -#include -#include - -namespace NeBuild { - -namespace FS = std::filesystem; - -/// =========================================================== /// -/// @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). -/// @return bool: whether the build has succeeded or not. -/// =========================================================== /// -bool TOMLManifestBuilder::BuildTarget(BuildConfig& config) { - std::string path; - - if (config.path_.empty()) { - NeBuild::Logger::info() << "error: file path is empty" << std::endl; - return false; - } else { - path = config.path_; - - if (!FS::exists(path)) { - NeBuild::Logger::info() << "error: file '" << path << "' does not exist" - << std::endl; - return false; - } - } - - try { - auto toml_file = toml::parse_file(path); - - try { - auto* description = toml_file["description"].as_string(); - - NeBuild::Logger::info() << "package path: " << path << std::endl; - - if (description) NeBuild::Logger::info() << "description: " << description->get() << std::endl; - } catch (...) { - // ... - } - - std::string compiler = toml_file["compiler_path"].as_string()->get(); - - std::string command = compiler + " "; - - auto header_search_path = toml_file["compiler_headers_path"].as_array(); - - if (header_search_path) { - for (auto& headers : *header_search_path) { - command += "-I" + headers.as_string()->get() + " "; - } - } - - auto headers_path = toml_file["headers_path"].as_array(); - - if (headers_path) { - for (auto& headers : *headers_path) { - command += "-I" + headers.as_string()->get() + " "; - } - } - - auto sources_files = toml_file["sources_path"].as_array(); - - if (sources_files) { - for (auto& sources : *sources_files) { - command += sources.as_string()->get() + " "; - } - } - - auto macros_list = toml_file["cpp_macros"].as_array(); - - if (macros_list) { - for (auto& macro : *macros_list) { - command += "-D" + macro.as_string()->get() + " "; - } - } - - auto compiler_flags = toml_file["compiler_flags"].as_array(); - - if (compiler_flags) { - for (auto& flag : *compiler_flags) { - command += flag.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: " << target << "\n"; - - auto ret_exec = std::system(command.c_str()); - - if (ret_exec > 0) { - NeBuild::Logger::info() << "error: exit with message: " << std::strerror(ret_exec) << "" - << std::endl; - config.has_failed_ = true; - return false; - } - } catch (const std::exception& err) { - NeBuild::Logger::info() << "error: exit with message: " << err.what() << "" << std::endl; - config.has_failed_ = true; - return false; - } - - return true; -} - -/// =========================================================== /// -/// @brief Returns the build system name. -/// =========================================================== /// -const std::string_view TOMLManifestBuilder::BuildSystem() { - return "NeBuild (toml++::toml)"; -} - -} // namespace NeBuild -- cgit v1.2.3