diff options
| author | Amlal El Mahrouss <amlal@nekernel.org> | 2025-11-16 10:25:44 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal@nekernel.org> | 2025-11-16 10:27:00 +0100 |
| commit | 67f502af0e8194d4dfd9010c297e51b40a85e7fc (patch) | |
| tree | 81a27a594e5cfac79bcb05c6c28fe314d68e613c /dev/src/TOMLManifestBuilder.cc | |
| parent | 1350d6381de4c2b2c56a69f0dc20ce54fab7be8b (diff) | |
feat: wip TOML support for NeBuild TOML files.
fix: JSON: fix broken JSON implementation.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'dev/src/TOMLManifestBuilder.cc')
| -rw-r--r-- | dev/src/TOMLManifestBuilder.cc | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/dev/src/TOMLManifestBuilder.cc b/dev/src/TOMLManifestBuilder.cc new file mode 100644 index 0000000..d975adf --- /dev/null +++ b/dev/src/TOMLManifestBuilder.cc @@ -0,0 +1,98 @@ +// ============================================================= // +// nebuild +// Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. +// ============================================================= // + +#include <BuildKit/TOMLManifestBuilder.h> + +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; + + if (argv_val.empty()) { + NeBuild::Logger::info() << "nebuild: error: file path is empty" << std::endl; + return false; + } else { + path = argv_val; + + if (!FS::exists(path)) { + NeBuild::Logger::info() << "nebuild: error: file '" << path << "' does not exist" + << std::endl; + return false; + } + } + + try { + auto toml_file = toml::parse_file(path); + + 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(); + + for (auto& headers : header_search_path) { + command += "-I" + headers.as_string()->get() + " "; + } + + auto headers_path = *toml_file["headers_path"].as_array(); + + for (auto& headers : headers_path) { + command += "-I" + headers.as_string()->get() + " "; + } + + + auto sources_files = *toml_file["sources_path"].as_array(); + + for (auto& sources : sources_files) { + command += sources.as_string()->get() + " "; + } + + auto macros_list = *toml_file["cpp_macros"].as_array(); + + for (auto& macro : macros_list) { + command += "-D" + macro.as_string()->get() + " "; + } + + auto compiler_flags = *toml_file["compiler_flags"].as_array(); + + for (auto& flag : compiler_flags) { + command += flag.as_string()->get() + " "; + } + + if (toml_file["compiler_std"].is_string()) + command += "-std=" + toml_file["compiler_std"].as_string()->get() + " "; + + 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"; + + 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; + return false; + } + } catch (std::runtime_error& err) { + NeBuild::Logger::info() << "error: " << err.what() << std::endl; + return false; + } + + return true; +} + +const char* TOMLManifestBuilder::BuildSystem() { + return "NeBuild (TOML)"; +} |
