summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAmlal <amlal@zka.com>2024-09-20 15:50:58 +0200
committerAmlal <amlal@zka.com>2024-09-20 15:50:58 +0200
commite59596db6f3e92098fdc0c3715f0a41cd10a0333 (patch)
treed2d126ce86f452add889df780897a2242de73e0e
parent602a5b177636ed55e950b239eedfc0d3217b97e1 (diff)
Add new contract for buildable manifests.
Signed-off-by: Amlal <amlal@zka.com>
-rw-r--r--cli/AppMain.cxx69
-rw-r--r--cli/BuilderJSON.cxx62
-rw-r--r--inc/IManifestBuilder.hxx19
-rw-r--r--inc/JSONManifestBuilder.hxx22
-rw-r--r--inc/manifest_builder.hxx22
-rw-r--r--makefile2
-rw-r--r--src/IManifestBuilder.cxx1
-rw-r--r--src/JSONManifestBuilder.cxx (renamed from src/ManifestBuilder.cxx)4
8 files changed, 114 insertions, 87 deletions
diff --git a/cli/AppMain.cxx b/cli/AppMain.cxx
new file mode 100644
index 0000000..e52daa3
--- /dev/null
+++ b/cli/AppMain.cxx
@@ -0,0 +1,69 @@
+#include "IManifestBuilder.hxx"
+#include <JSONManifestBuilder.hxx>
+#include <cstdio>
+#include <cstddef>
+#include <string>
+#include <iostream>
+#include <thread>
+
+int cJobIndex = 0;
+bool cFailed = false;
+
+static IManifestBuilder* cBuilder = new JSONManifestBuilder();
+
+int main(int argc, char** argv)
+{
+ cJobIndex = argc - 1;
+
+ for (size_t index = 1; index < argc; ++index)
+ {
+ std::string index_json = argv[index];
+
+ if (index_json == "/Ver" ||
+ index_json == "/Version")
+ {
+ std::cout << "Usage: btb <file>\n";
+ std::cout << "Filename is: " << argv[0] << "\n";
+
+ std::cout << "Check for issues at: www.el-mahrouss-logic.com/btb/issues\n";
+
+ std::cout << "Brought to you by Amlal El Mahrouss.\n";
+ std::cout << "© ZKA Technologies, all rights reserved.\n";
+
+ return 0;
+ }
+ else if (index_json == "/?" ||
+ index_json == "/Help")
+ {
+ std::cout << "btb: Build a JSON file: btb <json_path>.json\n";
+ std::cout << "btb: Build a TOML file: btb <toml_path>.toml\n";
+
+ return 0;
+ }
+
+ std::thread job([](std::string index_json) -> void {
+ std::cout << "btb: Building " << index_json << std::endl;
+
+ if (!cBuilder->Build(index_json.size(), index_json.c_str()))
+ {
+ std::string format = "btb ";
+ format += index_json;
+
+ cFailed = true;
+ }
+
+ --cJobIndex;
+ },
+ index_json);
+
+ job.detach();
+ }
+
+ // wait for completion of all jobs.
+ while (cJobIndex)
+ ;
+
+ delete cBuilder;
+
+ return cFailed ? 1 : 0;
+}
diff --git a/cli/BuilderJSON.cxx b/cli/BuilderJSON.cxx
deleted file mode 100644
index cffbe45..0000000
--- a/cli/BuilderJSON.cxx
+++ /dev/null
@@ -1,62 +0,0 @@
-#include <cstdio>
-#include <manifest_builder.hxx>
-#include <cstddef>
-#include <string>
-#include <iostream>
-#include <thread>
-
-int cJobIndex = 0;
-bool cFailed = false;
-
-int main(int argc, char** argv)
-{
- cJobIndex = argc - 1;
-
- for (size_t index = 1; index < argc; ++index)
- {
- std::string index_json = argv[index];
-
- if (index_json == "/Ver" ||
- index_json == "/Version" ||
- index_json == "/?" ||
- index_json == "/Help")
- {
- std::cout << "btb: 🚀 Basic Tool for Building (JSON support).\n";
- std::cout << "btb: Brought to you by Amlal El Mahrouss.\n";
- std::cout << "btb: © ZKA Technologies, all rights reserved.\n";
-
- if (index_json == "/?" ||
- index_json == "/Help")
- std::cout << "btb: 🆘 run file: btb <json_path>.json\n";
-
- return 0;
- }
-
- std::thread job([](std::string index_json) -> void {
- std::cout << "btb: " << index_json << std::endl;
-
- ManifestBuilder builder;
-
- if (!builder.buildJson(index_json.size(), index_json.c_str()))
- {
- std::string format = "btb ";
- format += index_json;
-
- perror(format.c_str());
-
- cFailed = true;
- }
-
- --cJobIndex;
- },
- index_json);
-
- job.detach();
- }
-
- // wait for completion of all jobs.
- while (cJobIndex)
- ;
-
- return cFailed ? 1 : 0;
-}
diff --git a/inc/IManifestBuilder.hxx b/inc/IManifestBuilder.hxx
new file mode 100644
index 0000000..404f8b2
--- /dev/null
+++ b/inc/IManifestBuilder.hxx
@@ -0,0 +1,19 @@
+#pragma once
+
+/// @brief Builder interface
+class IManifestBuilder
+{
+public:
+ explicit IManifestBuilder() = default;
+ virtual ~IManifestBuilder() = default;
+
+ IManifestBuilder& operator=(const IManifestBuilder&) = default;
+ IManifestBuilder(const IManifestBuilder&) = default;
+
+ /// @brief Builds a target.
+ /// @param arg_sz filename size
+ /// @param arg_val filename path.
+ /// @retval true succeeded.
+ /// @retval false failed.
+ virtual bool Build(int arg_sz, const char* arg_val) = 0;
+};
diff --git a/inc/JSONManifestBuilder.hxx b/inc/JSONManifestBuilder.hxx
new file mode 100644
index 0000000..5e29a96
--- /dev/null
+++ b/inc/JSONManifestBuilder.hxx
@@ -0,0 +1,22 @@
+#pragma once
+
+#include <IManifestBuilder.hxx>
+
+/// @brief JSON builder
+class JSONManifestBuilder final : public IManifestBuilder
+{
+public:
+ explicit JSONManifestBuilder() = default;
+ virtual ~JSONManifestBuilder() override = default;
+
+ JSONManifestBuilder& operator=(const JSONManifestBuilder&) = default;
+ JSONManifestBuilder(const JSONManifestBuilder&) = default;
+
+public:
+ /// @brief Builds a JSON target.
+ /// @param arg_sz filename size
+ /// @param arg_val filename path.
+ /// @retval true succeeded.
+ /// @retval false failed.
+ virtual bool Build(int arg_sz, const char* arg_val) override;
+};
diff --git a/inc/manifest_builder.hxx b/inc/manifest_builder.hxx
deleted file mode 100644
index 5d882ff..0000000
--- a/inc/manifest_builder.hxx
+++ /dev/null
@@ -1,22 +0,0 @@
-#pragma once
-
-class ManifestBuilder;
-
-/// @brief JSON builder
-class ManifestBuilder final
-{
-public:
- explicit ManifestBuilder() = default;
- ~ManifestBuilder() = default;
-
- ManifestBuilder& operator=(const ManifestBuilder&) = default;
- ManifestBuilder(const ManifestBuilder&) = default;
-
-public:
- /// @brief Builds a JSON target.
- /// @param arg_sz filename size
- /// @param arg_val filename path.
- /// @retval true succeeded.
- /// @retval false failed.
- bool buildJson(int arg_sz, const char* arg_val);
-};
diff --git a/makefile b/makefile
index bf257aa..43b8cbb 100644
--- a/makefile
+++ b/makefile
@@ -5,7 +5,7 @@ build-btb-core:
.PHONY: build-btb
build-btb:
- sudo g++ -I./inc $(wildcard cli/*.cxx) -std=c++20 -L/usr/local -lbtb -o btb
+ sudo g++ -I./inc $(wildcard cli/*.cxx) $(wildcard src/*.cxx) -std=c++20 -L/usr/local -lbtb -o btb
sudo cp btb /usr/local/bin
.PHONY: help
diff --git a/src/IManifestBuilder.cxx b/src/IManifestBuilder.cxx
new file mode 100644
index 0000000..c1dbe51
--- /dev/null
+++ b/src/IManifestBuilder.cxx
@@ -0,0 +1 @@
+#include <IManifestBuilder.hxx>
diff --git a/src/ManifestBuilder.cxx b/src/JSONManifestBuilder.cxx
index 70f3475..d456bb7 100644
--- a/src/ManifestBuilder.cxx
+++ b/src/JSONManifestBuilder.cxx
@@ -5,7 +5,7 @@
// Created by Amlal on 6/20/24.
//
-#include <manifest_builder.hxx>
+#include <JSONManifestBuilder.hxx>
#include <json.hxx>
@@ -23,7 +23,7 @@ using json = nlohmann::json;
/// @param arg_val filename path.
/// @retval true succeeded.
/// @retval false failed.
-bool ManifestBuilder::buildJson(int arg_sz, const char* arg_val)
+bool JSONManifestBuilder::Build(int arg_sz, const char* arg_val)
{
std::string path;