diff options
| author | Amlal <amlal.elmahrouss@icloud.com> | 2024-10-25 18:44:01 +0200 |
|---|---|---|
| committer | Amlal <amlal.elmahrouss@icloud.com> | 2024-10-25 18:44:01 +0200 |
| commit | d7dcb2695ca2c69b45314cfc261c395e935d355b (patch) | |
| tree | 32ed6a8aa938944a76eb407ecbc223a2d3a76e32 | |
| parent | b2c3e134b968e75faf6db29536755f0304c63b64 (diff) | |
IMP: Add a new contract method for those who implements IManifestBuilder.
Signed-off-by: Amlal <amlal.elmahrouss@icloud.com>
| -rw-r--r-- | BTBKit/IManifestBuilder.h | 9 | ||||
| -rw-r--r-- | BTBKit/Includes.h | 10 | ||||
| -rw-r--r-- | BTBKit/JSONManifestBuilder.h | 9 | ||||
| -rw-r--r-- | BTBKit/Macros.h | 6 | ||||
| -rw-r--r-- | cli/ManifestBuilder.cc (renamed from cli/CliApp.cc) | 50 | ||||
| -rw-r--r-- | makefile | 10 | ||||
| -rw-r--r-- | src/JSONManifestBuilder.cc | 8 | ||||
| -rw-r--r-- | tool-dev.cflags | 1 | ||||
| -rw-r--r-- | tool-dev.config | 2 | ||||
| -rw-r--r-- | tool-dev.creator | 1 | ||||
| -rw-r--r-- | tool-dev.cxxflags | 1 | ||||
| -rw-r--r-- | tool-dev.files | 16 | ||||
| -rw-r--r-- | tool-dev.includes | 0 |
13 files changed, 79 insertions, 44 deletions
diff --git a/BTBKit/IManifestBuilder.h b/BTBKit/IManifestBuilder.h index 0a821d5..e202a6a 100644 --- a/BTBKit/IManifestBuilder.h +++ b/BTBKit/IManifestBuilder.h @@ -5,7 +5,10 @@ #pragma once -/// @brief Builder interface class +#include <Macros.h> + +/// @brief Builder interface class. +/// @note This class is meant to be used as an interface. class IManifestBuilder { public: @@ -20,5 +23,7 @@ public: /// @param arg_val filename path. /// @retval true succeeded. /// @retval false failed. - virtual bool Build(int arg_sz, const char* arg_val) = 0; + virtual bool buildTarget(int arg_sz, const char* arg_val) = 0; + + virtual const char* buildSystem() = 0; }; diff --git a/BTBKit/Includes.h b/BTBKit/Includes.h new file mode 100644 index 0000000..dcafaa6 --- /dev/null +++ b/BTBKit/Includes.h @@ -0,0 +1,10 @@ +#ifndef BTB_INCLUDES_H +#define BTB_INCLUDES_H + +#include <cstdio> +#include <cstddef> +#include <string> +#include <iostream> +#include <thread> + +#endif // BTB_INCLUDES_H diff --git a/BTBKit/JSONManifestBuilder.h b/BTBKit/JSONManifestBuilder.h index 290d7bb..b300a6a 100644 --- a/BTBKit/JSONManifestBuilder.h +++ b/BTBKit/JSONManifestBuilder.h @@ -6,6 +6,7 @@ #pragma once #include <IManifestBuilder.h> +#include <json.h> /// @brief JSON builder class JSONManifestBuilder final : public IManifestBuilder @@ -21,7 +22,9 @@ 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; + /// @retval true build succeeded. + /// @retval false failed to build. + virtual bool buildTarget(int arg_sz, const char* arg_val) override; + + virtual const char* buildSystem() override; }; diff --git a/BTBKit/Macros.h b/BTBKit/Macros.h index f2d0f87..f29333a 100644 --- a/BTBKit/Macros.h +++ b/BTBKit/Macros.h @@ -7,12 +7,12 @@ #include <cassert> -#define LIKELY(ARG) (ARG) ? assert(false) : (void)0 +#define LIKELY(ARG) (ARG) ? assert(false) : ((void)0) #define UNLIKELY(ARG) LIKELY(!(ARG)) -#define BTBKIT_VERSION "1.0.0" +#define BTBKIT_VERSION "1.2.0" -#define BTBKIT_VERSION_BCD 0x0100 +#define BTBKIT_VERSION_BCD 0x0120 #define BTBKIT_VERSION_MAJOR 1 #define BTBKIT_VERSION_MINOR 0 diff --git a/cli/CliApp.cc b/cli/ManifestBuilder.cc index f8fd999..2c9c4ad 100644 --- a/cli/CliApp.cc +++ b/cli/ManifestBuilder.cc @@ -3,41 +3,38 @@ // Copyright ZKA Web Services. // ============================================================= // -#include <Macros.h> #include <JSONManifestBuilder.h> -#include <cstdio> -#include <cstddef> -#include <string> -#include <iostream> -#include <thread> +#include <Includes.h> -static int cJobIndex = 0; -static bool cFailed = false; +static int kJobCount = 0; +static bool kFailed = false; int main(int argc, char** argv) { - cJobIndex = argc - 1; + if (argc <= 1) + return -1; + + kJobCount = argc - 1; for (size_t index = 1; index < argc; ++index) { std::string index_path = argv[index]; - if (index_path == "/Ver" || - index_path == "/Version") + if (index_path == "-v" || + index_path == "--version") { std::cout << "Usage: btb <file>\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 Web Services, all rights reserved.\n"; + std::cout << "© ZKA Web Services Co, all rights reserved.\n"; return 0; } - else if (index_path == "/?" || - index_path == "/Help") + else if (index_path == "-h" || + index_path == "--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; } @@ -45,47 +42,46 @@ int main(int argc, char** argv) std::thread job_build_thread([](std::string index_path) -> void { IManifestBuilder* builder = nullptr; - const auto cJsonExt = ".json"; + const auto kJsonExtension = ".json"; - if (index_path.ends_with(cJsonExt)) + if (index_path.ends_with(kJsonExtension)) { builder = new JSONManifestBuilder(); } else { - cFailed = true; + kFailed = true; return; } std::cout << "btb: building: " << index_path << std::endl; - if (builder && !builder->Build(index_path.size(), index_path.c_str())) + if (builder && !builder->buildTarget(index_path.size(), index_path.c_str())) { - cFailed = true; + kFailed = true; } else if (!builder) { - cFailed = true; + kFailed = true; } delete builder; - --cJobIndex; - }, - index_path); + --kJobCount; + }, index_path); job_build_thread.detach(); } // wait for completion of all jobs. - while (cJobIndex) + while (kJobCount) { - if (cFailed) + if (kFailed) { std::cout << "btb: build failed: " << errno << "." << std::endl; return EXIT_FAILURE; } } - return cFailed ? EXIT_FAILURE : EXIT_SUCCESS; + return kFailed ? EXIT_FAILURE : EXIT_SUCCESS; } @@ -1,18 +1,14 @@ -.PHONY: build-btb-core -build-btb-core: - sudo g++ -I./BTBKit I./vendor $(wildcard src/*.cxx) -std=c++20 -fPIC -shared -o libbtb.so - sudo cp libbtb.so /usr/local/lib .PHONY: build-btb build-btb: - sudo g++ -I./BTBKit I./vendor $(wildcard cli/*.cxx) $(wildcard src/*.cxx) -std=c++20 -L/usr/local -lbtb -o btb + sudo g++ -I./BTBKit -I./vendor $(wildcard cli/*.cc) $(wildcard src/*.cc) -std=c++20 -L/usr/local -lbtb -o btb sudo cp btb /usr/local/bin .PHONY: build-btb-windows build-btb-windows: - x86_64-w64-mingw32-g++.exe -I./BTBKit -I./vendor $(wildcard cli/*.cxx) $(wildcard src/*.cxx) -std=c++20 -o btb.exe + x86_64-w64-mingw32-g++.exe -I./BTBKit -I./vendor $(wildcard cli/*.cc) $(wildcard src/*.cc) -std=c++20 -o btb.exe .PHONY: help help: - @echo "=> build-btb-core" + @echo "=> build-btb-windows" @echo "=> build-btb" diff --git a/src/JSONManifestBuilder.cc b/src/JSONManifestBuilder.cc index e5db6b8..37cefbc 100644 --- a/src/JSONManifestBuilder.cc +++ b/src/JSONManifestBuilder.cc @@ -4,7 +4,6 @@ // ============================================================= // #include <JSONManifestBuilder.h> -#include <json.h> #include <sstream> #include <iostream> @@ -17,7 +16,7 @@ using JSON = nlohmann::json; /// @param arg_val filename path (must be a valid JSON file). /// @retval true succeeded building. /// @retval false failed to build. -bool JSONManifestBuilder::Build(int arg_sz, const char* arg_val) +bool JSONManifestBuilder::buildTarget(int arg_sz, const char* arg_val) { std::string path; @@ -150,3 +149,8 @@ bool JSONManifestBuilder::Build(int arg_sz, const char* arg_val) return true; } + +const char* JSONManifestBuilder::buildSystem() +{ + return "json"; +} diff --git a/tool-dev.cflags b/tool-dev.cflags new file mode 100644 index 0000000..68d5165 --- /dev/null +++ b/tool-dev.cflags @@ -0,0 +1 @@ +-std=c17
\ No newline at end of file diff --git a/tool-dev.config b/tool-dev.config new file mode 100644 index 0000000..e0284f4 --- /dev/null +++ b/tool-dev.config @@ -0,0 +1,2 @@ +// Add predefined macros for your project here. For example: +// #define THE_ANSWER 42 diff --git a/tool-dev.creator b/tool-dev.creator new file mode 100644 index 0000000..e94cbbd --- /dev/null +++ b/tool-dev.creator @@ -0,0 +1 @@ +[General] diff --git a/tool-dev.cxxflags b/tool-dev.cxxflags new file mode 100644 index 0000000..6435dfc --- /dev/null +++ b/tool-dev.cxxflags @@ -0,0 +1 @@ +-std=c++17
\ No newline at end of file diff --git a/tool-dev.files b/tool-dev.files new file mode 100644 index 0000000..a790a46 --- /dev/null +++ b/tool-dev.files @@ -0,0 +1,16 @@ +BTBKit/IManifestBuilder.h +BTBKit/Includes.h +BTBKit/JSONManifestBuilder.h +BTBKit/Macros.h +ReadMe.md +cli/ManifestBuilder.cc +cli/compile_flags.txt +posix.json +src/IManifestBuilder.cc +src/JSONManifestBuilder.cc +tests/example.cc +tests/posix.json +tests/win64.json +vendor/json.h +vendor/json_fwd.h +win64.json diff --git a/tool-dev.includes b/tool-dev.includes new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tool-dev.includes |
