From d7dcb2695ca2c69b45314cfc261c395e935d355b Mon Sep 17 00:00:00 2001 From: Amlal Date: Fri, 25 Oct 2024 18:44:01 +0200 Subject: IMP: Add a new contract method for those who implements IManifestBuilder. Signed-off-by: Amlal --- BTBKit/IManifestBuilder.h | 9 ++++- BTBKit/Includes.h | 10 +++++ BTBKit/JSONManifestBuilder.h | 9 +++-- BTBKit/Macros.h | 6 +-- cli/CliApp.cc | 91 -------------------------------------------- cli/ManifestBuilder.cc | 87 ++++++++++++++++++++++++++++++++++++++++++ makefile | 10 ++--- src/JSONManifestBuilder.cc | 8 +++- tool-dev.cflags | 1 + tool-dev.config | 2 + tool-dev.creator | 1 + tool-dev.cxxflags | 1 + tool-dev.files | 16 ++++++++ tool-dev.includes | 0 14 files changed, 143 insertions(+), 108 deletions(-) create mode 100644 BTBKit/Includes.h delete mode 100644 cli/CliApp.cc create mode 100644 cli/ManifestBuilder.cc create mode 100644 tool-dev.cflags create mode 100644 tool-dev.config create mode 100644 tool-dev.creator create mode 100644 tool-dev.cxxflags create mode 100644 tool-dev.files create mode 100644 tool-dev.includes 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 + +/// @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 +#include +#include +#include +#include + +#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 +#include /// @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 -#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/CliApp.cc deleted file mode 100644 index f8fd999..0000000 --- a/cli/CliApp.cc +++ /dev/null @@ -1,91 +0,0 @@ -// ============================================================= // -// btb -// Copyright ZKA Web Services. -// ============================================================= // - -#include -#include -#include -#include -#include -#include -#include - -static int cJobIndex = 0; -static bool cFailed = false; - -int main(int argc, char** argv) -{ - cJobIndex = argc - 1; - - for (size_t index = 1; index < argc; ++index) - { - std::string index_path = argv[index]; - - if (index_path == "/Ver" || - index_path == "/Version") - { - std::cout << "Usage: btb \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"; - - return 0; - } - else if (index_path == "/?" || - index_path == "/Help") - { - std::cout << "btb: Build a JSON file: btb .json\n"; - std::cout << "btb: Build a TOML file: btb .toml\n"; - - return 0; - } - - std::thread job_build_thread([](std::string index_path) -> void { - IManifestBuilder* builder = nullptr; - - const auto cJsonExt = ".json"; - - if (index_path.ends_with(cJsonExt)) - { - builder = new JSONManifestBuilder(); - } - else - { - cFailed = true; - return; - } - - std::cout << "btb: building: " << index_path << std::endl; - - if (builder && !builder->Build(index_path.size(), index_path.c_str())) - { - cFailed = true; - } - else if (!builder) - { - cFailed = true; - } - - delete builder; - - --cJobIndex; - }, - index_path); - - job_build_thread.detach(); - } - - // wait for completion of all jobs. - while (cJobIndex) - { - if (cFailed) - { - std::cout << "btb: build failed: " << errno << "." << std::endl; - return EXIT_FAILURE; - } - } - - return cFailed ? EXIT_FAILURE : EXIT_SUCCESS; -} diff --git a/cli/ManifestBuilder.cc b/cli/ManifestBuilder.cc new file mode 100644 index 0000000..2c9c4ad --- /dev/null +++ b/cli/ManifestBuilder.cc @@ -0,0 +1,87 @@ +// ============================================================= // +// btb +// Copyright ZKA Web Services. +// ============================================================= // + +#include +#include + +static int kJobCount = 0; +static bool kFailed = false; + +int main(int argc, char** argv) +{ + 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 == "-v" || + index_path == "--version") + { + std::cout << "Usage: btb \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 Co, all rights reserved.\n"; + + return 0; + } + else if (index_path == "-h" || + index_path == "--help") + { + std::cout << "btb: Build a JSON file: btb .json\n"; + + return 0; + } + + std::thread job_build_thread([](std::string index_path) -> void { + IManifestBuilder* builder = nullptr; + + const auto kJsonExtension = ".json"; + + if (index_path.ends_with(kJsonExtension)) + { + builder = new JSONManifestBuilder(); + } + else + { + kFailed = true; + return; + } + + std::cout << "btb: building: " << index_path << std::endl; + + if (builder && !builder->buildTarget(index_path.size(), index_path.c_str())) + { + kFailed = true; + } + else if (!builder) + { + kFailed = true; + } + + delete builder; + + --kJobCount; + }, index_path); + + job_build_thread.detach(); + } + + // wait for completion of all jobs. + while (kJobCount) + { + if (kFailed) + { + std::cout << "btb: build failed: " << errno << "." << std::endl; + return EXIT_FAILURE; + } + } + + return kFailed ? EXIT_FAILURE : EXIT_SUCCESS; +} diff --git a/makefile b/makefile index d8851f1..adf380b 100644 --- a/makefile +++ b/makefile @@ -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 -#include #include #include @@ -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 -- cgit v1.2.3