summaryrefslogtreecommitdiffhomepage
path: root/src/CommandLine/CLI.cpp
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2026-02-27 22:43:34 +0100
committerAmlal El Mahrouss <amlal@nekernel.org>2026-02-27 22:43:34 +0100
commitfe03952bf6dbf32509a9322e34ac1b5c9d0dbe25 (patch)
tree04bb502e93321c08cbc1feb8ec8a9c42bf33896b /src/CommandLine/CLI.cpp
parent8e27a0f610819130a91a4076eaab1ab657ab3c72 (diff)
chore: update NeBuild file structure.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'src/CommandLine/CLI.cpp')
-rw-r--r--src/CommandLine/CLI.cpp83
1 files changed, 83 insertions, 0 deletions
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 <NeBuildKit/JSONManifestBuilder.h>
+#include <NeBuildKit/TOMLManifestBuilder.h>
+#include <memory>
+#include <thread>
+
+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 <options> <file.{json, toml}>\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<NeBuild::IManifestBuilder> builder;
+
+ constexpr auto kJsonExtension = ".json";
+
+ if (index_path.ends_with(kJsonExtension)) {
+ builder = std::make_unique<NeBuild::JSONManifestBuilder>();
+
+ /// report failed build to config.
+ if (!builder) {
+ config.has_failed(true);
+ return;
+ }
+ } else {
+ constexpr auto kTomlExtension = ".toml";
+ builder = std::make_unique<NeBuild::TOMLManifestBuilder>();
+
+ 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;
+}