summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2025-12-12 14:47:04 +0100
committerGitHub <noreply@github.com>2025-12-12 14:47:04 +0100
commit5a89f642daeed42213749d1d855286ef1a3a46e4 (patch)
tree13735af600898d719deb00c47f678cf57cc99f73 /src
parent8633c78d7a0809cf0fcc0ec6350ad5b71bca9faf (diff)
parentfb094b222027aad36ebc294c0b21909dfe20b3f9 (diff)
Merge pull request #22 from nekernel-org/repo-chore
BREAKING: Repository chores.
Diffstat (limited to 'src')
-rw-r--r--src/lib/JSONManifestBuilder.cc38
-rw-r--r--src/lib/TOMLManifestBuilder.cc17
2 files changed, 43 insertions, 12 deletions
diff --git a/src/lib/JSONManifestBuilder.cc b/src/lib/JSONManifestBuilder.cc
index af69176..45c7ce7 100644
--- a/src/lib/JSONManifestBuilder.cc
+++ b/src/lib/JSONManifestBuilder.cc
@@ -8,13 +8,12 @@
#include <fstream>
namespace NeBuild {
-using JSON = nlohmann::json;
namespace FS = std::filesystem;
/// =========================================================== ///
-/// @brief Builds a JSON target from a JSON file.
+/// @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 JSON file).
+/// @param arg_val filename path (must be a valid nlohmann::json file).
/// @retval true building has succeeded.
/// @retval false fail to build, see error message.
/// =========================================================== ///
@@ -38,42 +37,42 @@ bool JSONManifestBuilder::BuildTarget(BuildConfig& config) {
std::ifstream json(path);
if (!json.good()) {
- NeBuild::Logger::info() << "nebuild: error: file '" << path << "' is not a valid JSON"
- << std::endl;
+ NeBuild::Logger::info() << "nebuild: error: file '" << path
+ << "' is not a valid nlohmann::json" << std::endl;
return false;
}
- JSON json_obj = JSON::parse(json);
+ nlohmann::json json_obj = nlohmann::json::parse(json);
std::string compiler = json_obj["compiler_path"].get<std::string>();
std::string command = compiler + " ";
- JSON header_search_path = json_obj["compiler_headers_path"];
+ nlohmann::json header_search_path = json_obj["compiler_headers_path"];
for (auto& headers : header_search_path) {
command += "-I" + headers.get<std::string>() + " ";
}
- JSON headers_path = json_obj["headers_path"];
+ nlohmann::json headers_path = json_obj["headers_path"];
for (auto& headers : headers_path) {
command += "-I" + headers.get<std::string>() + " ";
}
- JSON sources_files = json_obj["sources_path"];
+ nlohmann::json sources_files = json_obj["sources_path"];
for (auto& sources : sources_files) {
command += sources.get<std::string>() + " ";
}
- JSON macros_list = json_obj["cpp_macros"];
+ nlohmann::json macros_list = json_obj["cpp_macros"];
for (auto& macro : macros_list) {
command += "-D" + macro.get<std::string>() + " ";
}
- JSON compiler_flags = json_obj["compiler_flags"];
+ nlohmann::json compiler_flags = json_obj["compiler_flags"];
for (auto& flag : compiler_flags) {
command += flag.get<std::string>() + " ";
@@ -96,6 +95,21 @@ bool JSONManifestBuilder::BuildTarget(BuildConfig& config) {
config.has_failed_ = true;
return false;
}
+
+ if (!config.dry_run_) {
+ auto run_after_build = json_obj["run_after_build"].get<bool>();
+
+ if (run_after_build) {
+ ret_exec = std::system(target.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 (std::runtime_error& err) {
NeBuild::Logger::info() << "error: exit with message: " << err.what() << "" << std::endl;
config.has_failed_ = true;
@@ -109,6 +123,6 @@ bool JSONManifestBuilder::BuildTarget(BuildConfig& config) {
/// @brief Returns the build system name.
/// =========================================================== ///
const std::string_view JSONManifestBuilder::BuildSystem() {
- return "NeBuild (JSON)";
+ return "NeBuild (nlohmann::json)";
}
} // namespace NeBuild \ No newline at end of file
diff --git a/src/lib/TOMLManifestBuilder.cc b/src/lib/TOMLManifestBuilder.cc
index 5b759fc..257c4a3 100644
--- a/src/lib/TOMLManifestBuilder.cc
+++ b/src/lib/TOMLManifestBuilder.cc
@@ -100,6 +100,23 @@ bool TOMLManifestBuilder::BuildTarget(BuildConfig& config) {
config.has_failed_ = true;
return false;
}
+
+ if (!config.dry_run_) {
+ auto run_after_build = toml_file["run_after_build"].as_boolean();
+ if (!run_after_build) return true;
+
+ auto val = run_after_build->get();
+ if (val) {
+ ret_exec = std::system(target.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 (std::runtime_error& err) {
NeBuild::Logger::info() << "error: exit with message: " << err.what() << "" << std::endl;
config.has_failed_ = true;