summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2025-12-12 14:45:09 +0100
committerAmlal El Mahrouss <amlal@nekernel.org>2025-12-12 14:45:09 +0100
commitfb094b222027aad36ebc294c0b21909dfe20b3f9 (patch)
tree13735af600898d719deb00c47f678cf57cc99f73
parent358bcc6a52793dc7043415b242169af9ec78f6b4 (diff)
chore: performance improvements and tweaks.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
-rw-r--r--examples/example_01_hello_world/posix.json2
-rw-r--r--examples/example_01_hello_world/win64.json2
-rw-r--r--examples/example_02_libnebuild/posix.json2
-rw-r--r--examples/example_02_libnebuild/win64.json2
-rw-r--r--examples/example_03_hello_world_toml/posix.toml2
-rw-r--r--examples/example_03_hello_world_toml/win64.toml2
-rw-r--r--include/NeBuildKit/IManifestBuilder.h6
-rw-r--r--include/NeBuildKit/JSONManifestBuilder.h2
-rw-r--r--include/NeBuildKit/TOMLManifestBuilder.h2
-rw-r--r--src/lib/JSONManifestBuilder.cc19
-rw-r--r--src/lib/TOMLManifestBuilder.cc17
11 files changed, 45 insertions, 13 deletions
diff --git a/examples/example_01_hello_world/posix.json b/examples/example_01_hello_world/posix.json
index 09cbef7..197e4a2 100644
--- a/examples/example_01_hello_world/posix.json
+++ b/examples/example_01_hello_world/posix.json
@@ -3,7 +3,7 @@
"compiler_std": "c++20",
"headers_path": ["lib"],
"sources_path": ["hello_world.cc"],
- "output_name": "hello_world.elf",
+ "output_name": "./hello_world.elf",
"compiler_flags": ["-fPIC"],
"cpp_macros": ["FOO_MACRO"],
"run_after_build": true
diff --git a/examples/example_01_hello_world/win64.json b/examples/example_01_hello_world/win64.json
index 4af5bdd..4545228 100644
--- a/examples/example_01_hello_world/win64.json
+++ b/examples/example_01_hello_world/win64.json
@@ -3,7 +3,7 @@
"compiler_std": "c++20",
"headers_path": ["lib"],
"sources_path": ["hello_world.cc"],
- "output_name": "hello_world.elf",
+ "output_name": "./hello_world.elf",
"compiler_flags": ["-fPIC"],
"cpp_macros": ["FOO_MACRO"],
"run_after_build": true
diff --git a/examples/example_02_libnebuild/posix.json b/examples/example_02_libnebuild/posix.json
index 809cb67..d7ef767 100644
--- a/examples/example_02_libnebuild/posix.json
+++ b/examples/example_02_libnebuild/posix.json
@@ -8,7 +8,7 @@
"sources_path": [
"libnebuild.cc"
],
- "output_name": "libnebuild.elf",
+ "output_name": "./libnebuild.elf",
"compiler_flags": [
"-L/usr/lib",
"-lNeBuildKit"
diff --git a/examples/example_02_libnebuild/win64.json b/examples/example_02_libnebuild/win64.json
index dcd1142..094208b 100644
--- a/examples/example_02_libnebuild/win64.json
+++ b/examples/example_02_libnebuild/win64.json
@@ -8,7 +8,7 @@
"sources_path": [
"libbtb.cc"
],
- "output_name": "libbtb.exe",
+ "output_name": "./libbtb.exe",
"compiler_flags": [
"-lNeBuild"
],
diff --git a/examples/example_03_hello_world_toml/posix.toml b/examples/example_03_hello_world_toml/posix.toml
index e8595d4..a384ddb 100644
--- a/examples/example_03_hello_world_toml/posix.toml
+++ b/examples/example_03_hello_world_toml/posix.toml
@@ -2,7 +2,7 @@ compiler_path = "clang++"
compiler_std = "c++20"
headers_path = [ "lib" ]
sources_path = [ "hello_world.cc" ]
-output_name = "hello_world.elf"
+output_name = "./hello_world.elf"
compiler_flags = [ "-fPIC" ]
cpp_macros = [ "FOO_MACRO" ]
run_after_build = true
diff --git a/examples/example_03_hello_world_toml/win64.toml b/examples/example_03_hello_world_toml/win64.toml
index c8001a4..6f30476 100644
--- a/examples/example_03_hello_world_toml/win64.toml
+++ b/examples/example_03_hello_world_toml/win64.toml
@@ -2,7 +2,7 @@ compiler_path = "x86_64-w64-mingw32-g++"
compiler_std = "c++20"
headers_path = [ "lib" ]
sources_path = [ "hello_world.cc" ]
-output_name = "hello_world.elf"
+output_name = "./hello_world.elf"
compiler_flags = [ "-fPIC" ]
cpp_macros = [ "FOO_MACRO" ]
run_after_build = true
diff --git a/include/NeBuildKit/IManifestBuilder.h b/include/NeBuildKit/IManifestBuilder.h
index c42f257..8223506 100644
--- a/include/NeBuildKit/IManifestBuilder.h
+++ b/include/NeBuildKit/IManifestBuilder.h
@@ -8,7 +8,7 @@
#include <NeBuildKit/Detail/Config.h>
#include <string_view>
-#define NEBUILD_MANIFEST_BUILDER : public ::NeBuild::IManifestBuilder
+#define NEBUILD_MANIFEST_BUILDER final : public ::NeBuild::IManifestBuilder
namespace NeBuild {
/// =========================================================== ///
@@ -29,11 +29,11 @@ class IManifestBuilder {
/// @retval true building has succeeded.
/// @retval false fail to build, see error message.
/// =========================================================== ///
- virtual bool BuildTarget(BuildConfig& config) = 0;
+ virtual bool BuildTarget(BuildConfig& config) { return false; }
/// =========================================================== ///
/// @brief Returns the build system name.
/// =========================================================== ///
- virtual const std::string_view BuildSystem() = 0;
+ virtual const std::string_view BuildSystem() { return "(null)"; }
};
} // namespace NeBuild \ No newline at end of file
diff --git a/include/NeBuildKit/JSONManifestBuilder.h b/include/NeBuildKit/JSONManifestBuilder.h
index 9f1afdc..4f3cec5 100644
--- a/include/NeBuildKit/JSONManifestBuilder.h
+++ b/include/NeBuildKit/JSONManifestBuilder.h
@@ -12,7 +12,7 @@
namespace NeBuild {
/// @brief JSON builder
-class JSONManifestBuilder final NEBUILD_MANIFEST_BUILDER {
+class JSONManifestBuilder NEBUILD_MANIFEST_BUILDER {
public:
JSONManifestBuilder() = default;
~JSONManifestBuilder() override = default;
diff --git a/include/NeBuildKit/TOMLManifestBuilder.h b/include/NeBuildKit/TOMLManifestBuilder.h
index 1c6bb1b..b4d61b8 100644
--- a/include/NeBuildKit/TOMLManifestBuilder.h
+++ b/include/NeBuildKit/TOMLManifestBuilder.h
@@ -12,7 +12,7 @@
namespace NeBuild {
/// @brief TOML builder
-class TOMLManifestBuilder final NEBUILD_MANIFEST_BUILDER {
+class TOMLManifestBuilder NEBUILD_MANIFEST_BUILDER {
public:
TOMLManifestBuilder() = default;
~TOMLManifestBuilder() override = default;
diff --git a/src/lib/JSONManifestBuilder.cc b/src/lib/JSONManifestBuilder.cc
index 5bd89c6..45c7ce7 100644
--- a/src/lib/JSONManifestBuilder.cc
+++ b/src/lib/JSONManifestBuilder.cc
@@ -37,8 +37,8 @@ bool JSONManifestBuilder::BuildTarget(BuildConfig& config) {
std::ifstream json(path);
if (!json.good()) {
- NeBuild::Logger::info() << "nebuild: error: file '" << path << "' is not a valid nlohmann::json"
- << std::endl;
+ NeBuild::Logger::info() << "nebuild: error: file '" << path
+ << "' is not a valid nlohmann::json" << std::endl;
return false;
}
@@ -95,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;
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;