summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2025-12-31 11:17:44 +0100
committerAmlal El Mahrouss <amlal@nekernel.org>2025-12-31 11:19:11 +0100
commit635401b6a71dd7466604f25a1591ba324125d133 (patch)
tree2d51ffac16fcd51504982446f8aaa3dd11babbd1
parentdcb52140c062e5cb7fafe04b292a0f98dd6be97d (diff)
feat: codebase improvements introduce 'b_internal' keyword for SDK code.v0.1.1v0.1.1-develop
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
-rw-r--r--Makefile4
-rw-r--r--include/NeBuildKit/Detail/Config.h29
-rw-r--r--scripts/osx-dylib.json2
-rw-r--r--scripts/posix-dylib.json2
-rw-r--r--src/cli/main.cc11
-rw-r--r--src/lib/JSONManifestBuilder.cc2
-rw-r--r--src/lib/TOMLManifestBuilder.cc2
7 files changed, 35 insertions, 17 deletions
diff --git a/Makefile b/Makefile
index 152a6bd..4ae84d5 100644
--- a/Makefile
+++ b/Makefile
@@ -6,9 +6,9 @@
SUDO=sudo
GCC=clang++
GCC_MINGW=x86_64-w64-mingw32-g++
-CXXFLAGS=-I./include -I./vendor
+CXXFLAGS=-I./include -I./vendor -lNeBuildKit
CXXSTD= -std=c++20
-SRC=$(wildcard src/cli/*.cc) $(wildcard src/lib/*.cc)
+SRC=$(wildcard src/cli/*.cc)
OUT=nebuild
CP=cp
diff --git a/include/NeBuildKit/Detail/Config.h b/include/NeBuildKit/Detail/Config.h
index 22e144f..7bc25fc 100644
--- a/include/NeBuildKit/Detail/Config.h
+++ b/include/NeBuildKit/Detail/Config.h
@@ -13,9 +13,6 @@
#include <cassert>
#include <iostream>
-#define LIKELY(ARG) ((ARG) ? assert(false) : ((void) 0))
-#define UNLIKELY(ARG) LIKELY(!(ARG))
-
#define NEBUILD_VERSION "v0.0.8-buildkit"
#define NEBUILD_VERSION_BCD 0x0007
@@ -28,21 +25,41 @@
#define NEBUILD_UNUSED(X) ((void) X)
+#define b_internal private
+
+#ifdef NEBUILD_INTERNAL_SDK
+#undef b_internal
+#define b_internal public
+#endif
+
namespace NeBuild {
struct BuildConfig final {
- bool has_failed_{false};
- bool dry_run_{false};
- std::string path_{};
+ b_internal:
+ bool has_failed_{false};
+ bool dry_run_{false};
+ std::string path_{};
+ public:
explicit operator bool() { return has_failed_; }
+ bool dry_run() { return dry_run_; }
+ void dry_run(const bool dr) { dry_run_ = dr; }
+
+ bool has_failed() { return has_failed_; }
+ void has_failed(const bool dr) { has_failed_ = dr; }
+
+ const std::string& path() { return path_; }
+ void path(const std::string& pat) { path_ = pat; }
+
BuildConfig() = default;
~BuildConfig() = default;
};
} // namespace NeBuild
+/// \brief Logger namespace.
namespace NeBuild::Logger {
/// @brief replacement for std::cout for NeBuild logging.
+/// @todo change this to spdlog?
inline std::ostream& info() noexcept {
auto& out = std::cout;
out << rang::fg::red << "nebuild: " << rang::style::reset;
diff --git a/scripts/osx-dylib.json b/scripts/osx-dylib.json
index d5b87bc..0426f4e 100644
--- a/scripts/osx-dylib.json
+++ b/scripts/osx-dylib.json
@@ -5,6 +5,6 @@
"sources_path": ["src/lib/*.cc"],
"output_name": "libNeBuildKit.dylib",
"compiler_flags": ["-fPIC", "-shared"],
- "cpp_macros": ["NEBUILD_DYLIB", "NEBUILD_OSX"],
+ "cpp_macros": ["NEBUILD_INTERNAL_SDK", "NEBUILD_OSX"],
"run_after_build": false
}
diff --git a/scripts/posix-dylib.json b/scripts/posix-dylib.json
index 3326b3e..17c37a7 100644
--- a/scripts/posix-dylib.json
+++ b/scripts/posix-dylib.json
@@ -5,6 +5,6 @@
"sources_path": ["src/lib/*.cc"],
"output_name": "libNeBuildKit.so",
"compiler_flags": ["-fPIC", "-shared"],
- "cpp_macros": ["NEBUILD_POSIX", "NEBUILD_DYLIB"],
+ "cpp_macros": ["NEBUILD_POSIX", "NEBUILD_INTERNAL_SDK"],
"run_after_build": false
}
diff --git a/src/cli/main.cc b/src/cli/main.cc
index 5a10d07..61ab3c7 100644
--- a/src/cli/main.cc
+++ b/src/cli/main.cc
@@ -23,7 +23,7 @@ int main(int argc, char** argv) {
NeBuild::Logger::info() << "NeBuild (" << NEBUILD_VERSION << ")\n";
return EXIT_SUCCESS;
} else if (index_path == "-dry-run" || index_path == "-n") {
- config.dry_run_ = true;
+ config.dry_run(true);
continue;
} else if (index_path == "-h" || index_path == "-help") {
NeBuild::Logger::info() << "usage: nebuild <options> <file>.\n";
@@ -41,8 +41,9 @@ int main(int argc, char** argv) {
if (index_path.ends_with(kJsonExtension)) {
builder = std::make_unique<NeBuild::JSONManifestBuilder>();
+ /// report failed build to config.
if (!builder) {
- config.has_failed_ = true;
+ config.has_failed(true);
return;
}
} else {
@@ -52,7 +53,7 @@ int main(int argc, char** argv) {
if (!index_path.ends_with(kTomlExtension)) {
NeBuild::Logger::info() << "error: file '" << index_path << "' is not a manifest file!"
<< std::endl;
- config.has_failed_ = true;
+ config.has_failed(true);
return;
}
}
@@ -68,10 +69,10 @@ int main(int argc, char** argv) {
NeBuild::Logger::info() << "building manifest: " << index_path << std::endl;
- config.path_ = index_path;
+ config.path(index_path);
if (builder && !builder->BuildTarget(config)) {
- config.has_failed_ = true;
+ config.has_failed(true);
}
});
diff --git a/src/lib/JSONManifestBuilder.cc b/src/lib/JSONManifestBuilder.cc
index bda523c..9dce796 100644
--- a/src/lib/JSONManifestBuilder.cc
+++ b/src/lib/JSONManifestBuilder.cc
@@ -95,7 +95,7 @@ bool JSONManifestBuilder::BuildTarget(BuildConfig& config) {
config.has_failed_ = true;
return false;
}
- } catch (std::exception& err) {
+ } catch (const std::exception& err) {
NeBuild::Logger::info() << "error: exit with message: " << err.what() << "" << std::endl;
config.has_failed_ = true;
return false;
diff --git a/src/lib/TOMLManifestBuilder.cc b/src/lib/TOMLManifestBuilder.cc
index 0ed3668..c28b6bd 100644
--- a/src/lib/TOMLManifestBuilder.cc
+++ b/src/lib/TOMLManifestBuilder.cc
@@ -100,7 +100,7 @@ bool TOMLManifestBuilder::BuildTarget(BuildConfig& config) {
config.has_failed_ = true;
return false;
}
- } catch (std::runtime_error& err) {
+ } catch (const std::exception& err) {
NeBuild::Logger::info() << "error: exit with message: " << err.what() << "" << std::endl;
config.has_failed_ = true;
return false;