summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAmlal EL Mahrouss <amlalelmahrouss@icloud.com>2024-08-03 22:32:46 +0200
committerAmlal EL Mahrouss <amlalelmahrouss@icloud.com>2024-08-03 22:32:46 +0200
commit65835ae45b44c6abf762961a1fd8c1489e2b9a78 (patch)
tree241b090120b4d3b37d94de67ea1db344d2ae94a9
parente631e5c0ceda0301a49a879178ba93c5141dccff (diff)
[IMP] Version 1.01: New CLI and new library.
Signed-off-by: Amlal EL Mahrouss <amlalelmahrouss@icloud.com>
-rw-r--r--.vscode/c_cpp_properties.json21
-rw-r--r--btbuild/main.cxx53
-rw-r--r--cli/compile_flags.txt (renamed from btbuild/compile_flags.txt)0
-rw-r--r--cli/tool.cxx58
-rw-r--r--inc/manifest_builder.hxx17
-rw-r--r--makefile14
-rw-r--r--src/compile_flags.txt2
-rw-r--r--src/manifest_builder.cxx47
-rw-r--r--tests/example.json5
9 files changed, 148 insertions, 69 deletions
diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json
new file mode 100644
index 0000000..4f571dc
--- /dev/null
+++ b/.vscode/c_cpp_properties.json
@@ -0,0 +1,21 @@
+{
+ "configurations": [
+ {
+ "name": "Win32",
+ "includePath": [
+ "${workspaceFolder}/**"
+ ],
+ "defines": [
+ "_DEBUG",
+ "UNICODE",
+ "_UNICODE"
+ ],
+ "windowsSdkVersion": "10.0.22621.0",
+ "compilerPath": "cl.exe",
+ "cStandard": "c17",
+ "cppStandard": "c++20",
+ "intelliSenseMode": "windows-msvc-x64"
+ }
+ ],
+ "version": 4
+} \ No newline at end of file
diff --git a/btbuild/main.cxx b/btbuild/main.cxx
deleted file mode 100644
index 5e771cb..0000000
--- a/btbuild/main.cxx
+++ /dev/null
@@ -1,53 +0,0 @@
-#include <cstdio>
-#include <manifest_builder.hxx>
-#include <cstddef>
-#include <string>
-#include <iostream>
-#include <thread>
-
-int job_index = 0;
-
-
-int main(int argc, char** argv)
-{
- job_index = argc-1;
-
- for (size_t index = 1; index < argc; ++index)
- {
- std::string index_json = argv[index];
-
- if (index_json == "-v" ||
- index_json == "--version")
- {
- std::cout << "btb(uild): version 1.00\n";
- std::cout << "btb(uild): brought to you by Amlal El Mahrouss.\n";
- return 0;
- }
-
- std::thread job([] (std::string index_json) -> void {
- std::cout << "building: " << 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());
- }
-
- --job_index;
- }, index_json);
-
- job.detach();
- }
-
- // wait for completion of all jobs.
- while (job_index)
- {
-
- }
-
- return 0;
-}
diff --git a/btbuild/compile_flags.txt b/cli/compile_flags.txt
index f6d73f3..f6d73f3 100644
--- a/btbuild/compile_flags.txt
+++ b/cli/compile_flags.txt
diff --git a/cli/tool.cxx b/cli/tool.cxx
new file mode 100644
index 0000000..348d388
--- /dev/null
+++ b/cli/tool.cxx
@@ -0,0 +1,58 @@
+#include <cstdio>
+#include <manifest_builder.hxx>
+#include <cstddef>
+#include <string>
+#include <iostream>
+#include <thread>
+
+int job_index = 0;
+
+int main(int argc, char** argv)
+{
+ job_index = 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: 🚀 Version 1.01.\n";
+ std::cout << "btb: Brought to you by Amlal El Mahrouss.\n";
+ std::cout << "btb: © ZKA Technologies, all rights reserved.\n";
+
+ std::cout << "btb: 🆘 run file: btb <json_path>.json\n";
+
+ return 0;
+ }
+
+ std::thread job([](std::string index_json) -> void {
+ std::cout << "building: " << 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());
+ }
+
+ --job_index;
+ },
+ index_json);
+
+ job.detach();
+ }
+
+ // wait for completion of all jobs.
+ while (job_index)
+ {
+ }
+
+ return 0;
+}
diff --git a/inc/manifest_builder.hxx b/inc/manifest_builder.hxx
index f66a7a8..5d882ff 100644
--- a/inc/manifest_builder.hxx
+++ b/inc/manifest_builder.hxx
@@ -2,16 +2,21 @@
class ManifestBuilder;
+/// @brief JSON builder
class ManifestBuilder final
{
public:
- explicit ManifestBuilder() = default;
- ~ManifestBuilder() = default;
+ explicit ManifestBuilder() = default;
+ ~ManifestBuilder() = default;
- ManifestBuilder& operator=(const ManifestBuilder&) = default;
- ManifestBuilder(const ManifestBuilder&) = default;
+ ManifestBuilder& operator=(const ManifestBuilder&) = default;
+ ManifestBuilder(const ManifestBuilder&) = default;
public:
- bool buildJson(int arg_sz, const char * arg_val);
-
+ /// @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 8efbff2..fb0700b 100644
--- a/makefile
+++ b/makefile
@@ -1,11 +1,11 @@
-.PHONY: build-zpt-core
-build-zpt-core:
- g++ -I./inc $(wildcard src/*.cxx) -std=c++20 -fPIC -shared -o libzpt-core.so
- cp libzpt-core.so /usr/lib
+.PHONY: build-btb-core
+build-btb-core:
+ g++ -I./inc $(wildcard src/*.cxx) -std=c++20 -fPIC -shared -o libbtb.so
+ cp libbtb.so /usr/lib
-.PHONY: build-btbuild
-build-btbuild:
- g++ -I./inc $(wildcard btbuild/*.cxx) -lzpt-core -o btb
+.PHONY: build-btb
+build-btb:
+ g++ -I./inc $(wildcard cli/*.cxx) -lbtb -o btb
cp btb /usr/bin
.PHONY: help
diff --git a/src/compile_flags.txt b/src/compile_flags.txt
index f6d73f3..6790690 100644
--- a/src/compile_flags.txt
+++ b/src/compile_flags.txt
@@ -1,2 +1,4 @@
-std=c++20
-I../inc
+-fPIC
+-shared \ No newline at end of file
diff --git a/src/manifest_builder.cxx b/src/manifest_builder.cxx
index 7a6ee2a..efdb409 100644
--- a/src/manifest_builder.cxx
+++ b/src/manifest_builder.cxx
@@ -14,6 +14,11 @@
using json = nlohmann::json;
+/// @brief Builds a JSON target.
+/// @param arg_sz filename size
+/// @param arg_val filename path.
+/// @retval true succeeded.
+/// @retval false failed.
bool ManifestBuilder::buildJson(int arg_sz, const char* arg_val)
{
std::string path;
@@ -41,7 +46,7 @@ bool ManifestBuilder::buildJson(int arg_sz, const char* arg_val)
std::string compiler = buildme["compiler_path"].get<std::string>();
json headerSearchPath = buildme["headers_path"];
- json sourceFiles = buildme["sources_path"];
+ json sourceFiles = buildme["sources_path"];
std::string cmdLine = compiler + " ";
@@ -73,6 +78,46 @@ bool ManifestBuilder::buildJson(int arg_sz, const char* arg_val)
cmdLine += "-o " + buildme["output_name"].get<std::string>();
std::system(cmdLine.c_str());
+
+ try
+ {
+ if (buildme["run_after_build"].get<bool>())
+ {
+ auto target = buildme["output_name"].get<std::string>();
+
+ if (target.ends_with(".so") ||
+ target.ends_with(".dll"))
+ {
+ std::cout << "buildme: error: can't open DLL/SO, it mayn't contain an entrypoint." << std::endl;
+ return true;
+ }
+ else if (target.ends_with(".lib"))
+ {
+ auto file = std::ifstream(target);
+ std::stringstream ss;
+ ss << file.rdbuf();
+
+ if (ss.str()[0] == 'J' &&
+ ss.str()[1] == 'o' &&
+ ss.str()[2] == 'y' &&
+ ss.str()[3] == '!')
+ std::cout << "buildme: error: can't open PEF LIB, it mayn't contain an entrypoint." << std::endl;
+ else if (ss.str()[0] == '!' &&
+ ss.str()[1] == 'y' &&
+ ss.str()[2] == 'o' &&
+ ss.str()[3] == 'J')
+ std::cout << "buildme: error: can't open FEP LIB, it mayn't contain an entrypoint." << std::endl;
+
+ return true;
+ }
+
+ std::system(("./" + target).c_str());
+ }
+ }
+ catch (...)
+ {
+ // ignore...
+ }
}
catch (std::runtime_error& err)
{
diff --git a/tests/example.json b/tests/example.json
index 6a14d63..32b21dc 100644
--- a/tests/example.json
+++ b/tests/example.json
@@ -2,8 +2,9 @@
"compiler_path": "g++",
"compiler_std": "c++20",
"headers_path": ["inc"],
- "sources_path": ["tests/example.cxx"],
+ "sources_path": ["example.cxx"],
"output_name": "example.elf",
"compiler_flags": ["-fPIC"],
- "cpp_macros": ["FOO_MACRO"]
+ "cpp_macros": ["FOO_MACRO"],
+ "run_after_build": true
}