From e0b3869075eb6dd4d2d515f80056e2eeb1128fae Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Thu, 22 May 2025 10:22:16 +0200 Subject: feat(btb)!: Introducing libBTB, better API. also: - The Codebase has been improved. - Error codes are now string messages. Signed-off-by: Amlal El Mahrouss --- BTBKit/IManifestBuilder.h | 33 +++++++++++++++++++++++++++++++++ BTBKit/Includes.h | 17 +++++++++++++++++ BTBKit/JSONManifestBuilder.h | 31 +++++++++++++++++++++++++++++++ BTBKit/Macros.h | 34 ++++++++++++++++++++++++++++++++++ GNUmakefile | 23 +++++++++++++++++++++++ cli/CommandLine.cc | 4 ++-- compile_flags.txt | 2 +- lib/IManifestBuilder.h | 31 ------------------------------- lib/Includes.h | 17 ----------------- lib/JSONManifestBuilder.h | 31 ------------------------------- lib/Macros.h | 34 ---------------------------------- makefile | 23 ----------------------- osx-dylib.json | 10 ++++++++++ osx.json | 10 ++++++++++ posix.json | 2 +- src/IManifestBuilder.cc | 2 +- src/JSONManifestBuilder.cc | 5 ++--- win64.json | 2 +- 18 files changed, 166 insertions(+), 145 deletions(-) create mode 100644 BTBKit/IManifestBuilder.h create mode 100644 BTBKit/Includes.h create mode 100644 BTBKit/JSONManifestBuilder.h create mode 100644 BTBKit/Macros.h create mode 100644 GNUmakefile delete mode 100644 lib/IManifestBuilder.h delete mode 100644 lib/Includes.h delete mode 100644 lib/JSONManifestBuilder.h delete mode 100644 lib/Macros.h delete mode 100644 makefile create mode 100644 osx-dylib.json create mode 100644 osx.json diff --git a/BTBKit/IManifestBuilder.h b/BTBKit/IManifestBuilder.h new file mode 100644 index 0000000..41c62df --- /dev/null +++ b/BTBKit/IManifestBuilder.h @@ -0,0 +1,33 @@ +// ============================================================= // +// btb +// Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. +// ============================================================= // + +#pragma once + +#include +#include + +#define BTB_MANIFEST_BUILDER : public BTB::IManifestBuilder + +namespace BTB { +/// @brief Builder interface class. +/// @note This class is meant to be used as an interface. +class IManifestBuilder { + public: + explicit IManifestBuilder() = default; + virtual ~IManifestBuilder() = default; + + IManifestBuilder& operator=(const IManifestBuilder&) = default; + IManifestBuilder(const IManifestBuilder&) = default; + + /// @brief Builds a target using the implemented laguage. + /// @param arg_sz filename size + /// @param arg_val filename path. + /// @retval true succeeded. + /// @retval false failed. + virtual bool buildTarget(int arg_sz, const char* arg_val, const bool dry_run = false) = 0; + + virtual const char* buildSystem() = 0; +}; +} // namespace BTB \ No newline at end of file diff --git a/BTBKit/Includes.h b/BTBKit/Includes.h new file mode 100644 index 0000000..3695d53 --- /dev/null +++ b/BTBKit/Includes.h @@ -0,0 +1,17 @@ +// ============================================================= // +// btb +// Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. +// ============================================================= // + +#ifndef BTB_INCLUDES_H +#define BTB_INCLUDES_H + +#include +#include +#include +#include +#include +#include +#include + +#endif // BTB_INCLUDES_H diff --git a/BTBKit/JSONManifestBuilder.h b/BTBKit/JSONManifestBuilder.h new file mode 100644 index 0000000..6654a9b --- /dev/null +++ b/BTBKit/JSONManifestBuilder.h @@ -0,0 +1,31 @@ +// ============================================================= // +// btb +// Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. +// ============================================================= // + +#pragma once + +#include +#include + +namespace BTB { +/// @brief JSON builder +class JSONManifestBuilder final BTB_MANIFEST_BUILDER { + 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 build succeeded. + /// @retval false failed to build. + virtual bool buildTarget(int arg_sz, const char* arg_val, const bool dry_run = false) override; + + virtual const char* buildSystem() override; +}; +} // namespace BTB \ No newline at end of file diff --git a/BTBKit/Macros.h b/BTBKit/Macros.h new file mode 100644 index 0000000..9d51a2f --- /dev/null +++ b/BTBKit/Macros.h @@ -0,0 +1,34 @@ +// ============================================================= // +// btb +// Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. +// ============================================================= // + +#pragma once + +extern "C" { +#include +} + +#include + +#define LIKELY(ARG) (ARG) ? assert(false) : ((void) 0) +#define UNLIKELY(ARG) LIKELY(!(ARG)) + +#define LIBBTB_VERSION "1.1.0" + +#define LIBBTB_VERSION_BCD 0x0110 + +#define LIBBTB_VERSION_MAJOR 1 +#define LIBBTB_VERSION_MINOR 1 +#define LIBBTB_VERSION_PATCH 0 + +#define LIBBTB_UNUSED(X) ((void) X) + +namespace BTB::Logger { +/// @brief replacement for std::cout for BTB logging. +inline std::ostream& info() noexcept { + auto& out = std::cout; + out << rang::fg::red << "btb: " << rang::style::reset; + return out; +} +} // namespace BTB::Logger diff --git a/GNUmakefile b/GNUmakefile new file mode 100644 index 0000000..f3c888f --- /dev/null +++ b/GNUmakefile @@ -0,0 +1,23 @@ +SUDO=sudo +GCC=g++ +GCC_MINGW=x86_64-w64-mingw32-g++ +CXXFLAGS=-I./ -I./vendor +CXXSTD= -std=c++20 +SRC=$(wildcard cli/*.cc) $(wildcard src/*.cc) +OUT=btb +CP=cp + +.PHONY: build-btb +build-btb: + $(SUDO) $(GCC) $(CXXFLAGS) $(SRC) $(CXXSTD) -o $(OUT) + $(SUDO) $(CP) $(OUT) /usr/local/bin + +.PHONY: build-btb-windows +build-btb-windows: + $(GCC_MINGW) $(CXXFLAGS) $(SRC) -o $(OUT).exe + +.PHONY: help +help: + @echo "=> help: Show this help message." + @echo "=> build-btb-windows: Build BTB for Windows." + @echo "=> build-btb: Build BTB for POSIX." diff --git a/cli/CommandLine.cc b/cli/CommandLine.cc index 419f146..300db6f 100644 --- a/cli/CommandLine.cc +++ b/cli/CommandLine.cc @@ -4,8 +4,8 @@ // Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. // ============================================================= // -#include -#include +#include +#include static bool kFailed = false; static bool kDryRun = false; diff --git a/compile_flags.txt b/compile_flags.txt index 32eb651..3edd1b0 100644 --- a/compile_flags.txt +++ b/compile_flags.txt @@ -1,3 +1,3 @@ -std=c++20 --Ilib +-I./ -Ivendor \ No newline at end of file diff --git a/lib/IManifestBuilder.h b/lib/IManifestBuilder.h deleted file mode 100644 index ed3c30f..0000000 --- a/lib/IManifestBuilder.h +++ /dev/null @@ -1,31 +0,0 @@ -// ============================================================= // -// btb -// Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. -// ============================================================= // - -#pragma once - -#include -#include - -namespace BTB { -/// @brief Builder interface class. -/// @note This class is meant to be used as an interface. -class IManifestBuilder { - public: - explicit IManifestBuilder() = default; - virtual ~IManifestBuilder() = default; - - IManifestBuilder& operator=(const IManifestBuilder&) = default; - IManifestBuilder(const IManifestBuilder&) = default; - - /// @brief Builds a target using the implemented laguage. - /// @param arg_sz filename size - /// @param arg_val filename path. - /// @retval true succeeded. - /// @retval false failed. - virtual bool buildTarget(int arg_sz, const char* arg_val, const bool dry_run = false) = 0; - - virtual const char* buildSystem() = 0; -}; -} // namespace BTB \ No newline at end of file diff --git a/lib/Includes.h b/lib/Includes.h deleted file mode 100644 index 3695d53..0000000 --- a/lib/Includes.h +++ /dev/null @@ -1,17 +0,0 @@ -// ============================================================= // -// btb -// Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. -// ============================================================= // - -#ifndef BTB_INCLUDES_H -#define BTB_INCLUDES_H - -#include -#include -#include -#include -#include -#include -#include - -#endif // BTB_INCLUDES_H diff --git a/lib/JSONManifestBuilder.h b/lib/JSONManifestBuilder.h deleted file mode 100644 index 93c86e9..0000000 --- a/lib/JSONManifestBuilder.h +++ /dev/null @@ -1,31 +0,0 @@ -// ============================================================= // -// btb -// Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. -// ============================================================= // - -#pragma once - -#include -#include - -namespace BTB { -/// @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 build succeeded. - /// @retval false failed to build. - virtual bool buildTarget(int arg_sz, const char* arg_val, const bool dry_run = false) override; - - virtual const char* buildSystem() override; -}; -} // namespace BTB \ No newline at end of file diff --git a/lib/Macros.h b/lib/Macros.h deleted file mode 100644 index 9d51a2f..0000000 --- a/lib/Macros.h +++ /dev/null @@ -1,34 +0,0 @@ -// ============================================================= // -// btb -// Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. -// ============================================================= // - -#pragma once - -extern "C" { -#include -} - -#include - -#define LIKELY(ARG) (ARG) ? assert(false) : ((void) 0) -#define UNLIKELY(ARG) LIKELY(!(ARG)) - -#define LIBBTB_VERSION "1.1.0" - -#define LIBBTB_VERSION_BCD 0x0110 - -#define LIBBTB_VERSION_MAJOR 1 -#define LIBBTB_VERSION_MINOR 1 -#define LIBBTB_VERSION_PATCH 0 - -#define LIBBTB_UNUSED(X) ((void) X) - -namespace BTB::Logger { -/// @brief replacement for std::cout for BTB logging. -inline std::ostream& info() noexcept { - auto& out = std::cout; - out << rang::fg::red << "btb: " << rang::style::reset; - return out; -} -} // namespace BTB::Logger diff --git a/makefile b/makefile deleted file mode 100644 index 8884c33..0000000 --- a/makefile +++ /dev/null @@ -1,23 +0,0 @@ -SUDO=sudo -GCC=g++ -GCC_MINGW=x86_64-w64-mingw32-g++ -CXXFLAGS=-I./lib -I./vendor -CXXSTD= -std=c++20 -SRC=$(wildcard cli/*.cc) $(wildcard src/*.cc) -OUT=btb -CP=cp - -.PHONY: build-btb -build-btb: - $(SUDO) $(GCC) $(CXXFLAGS) $(SRC) $(CXXSTD) -o $(OUT) - $(SUDO) $(CP) $(OUT) /usr/local/bin - -.PHONY: build-btb-windows -build-btb-windows: - $(GCC_MINGW) $(CXXFLAGS) $(SRC) -o $(OUT).exe - -.PHONY: help -help: - @echo "=> help: Show this help message." - @echo "=> build-btb-windows: Build BTB for Windows." - @echo "=> build-btb: Build BTB for POSIX." diff --git a/osx-dylib.json b/osx-dylib.json new file mode 100644 index 0000000..80917d2 --- /dev/null +++ b/osx-dylib.json @@ -0,0 +1,10 @@ +{ + "compiler_path": "g++", + "compiler_std": "c++20", + "headers_path": ["./", "vendor"], + "sources_path": ["src/*.cc"], + "output_name": "libBTB.dylib", + "compiler_flags": ["-fPIC", "-shared"], + "cpp_macros": ["BTB_POSIX", "BTB_OSX"], + "run_after_build": false +} diff --git a/osx.json b/osx.json new file mode 100644 index 0000000..20d513d --- /dev/null +++ b/osx.json @@ -0,0 +1,10 @@ +{ + "compiler_path": "g++", + "compiler_std": "c++20", + "headers_path": ["./", "vendor"], + "sources_path": ["src/*.cc", "cli/*.cc"], + "output_name": "btb", + "compiler_flags": ["-fPIC"], + "cpp_macros": ["BTB_POSIX", "BTB_OSX"], + "run_after_build": false +} diff --git a/posix.json b/posix.json index 7e4343b..e53cc14 100644 --- a/posix.json +++ b/posix.json @@ -1,7 +1,7 @@ { "compiler_path": "g++", "compiler_std": "c++20", - "headers_path": ["lib", "vendor"], + "headers_path": ["./", "vendor"], "sources_path": ["src/*.cc", "cli/*.cc"], "output_name": "btb", "compiler_flags": ["-fPIC"], diff --git a/src/IManifestBuilder.cc b/src/IManifestBuilder.cc index e3cfc6b..b3f4de8 100644 --- a/src/IManifestBuilder.cc +++ b/src/IManifestBuilder.cc @@ -3,4 +3,4 @@ // Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. // ============================================================= // -#include +#include diff --git a/src/JSONManifestBuilder.cc b/src/JSONManifestBuilder.cc index f70450d..46a8518 100644 --- a/src/JSONManifestBuilder.cc +++ b/src/JSONManifestBuilder.cc @@ -3,8 +3,7 @@ // Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. // ============================================================= // -#include -#include +#include using String = std::string; using JSON = nlohmann::json; @@ -91,7 +90,7 @@ bool JSONManifestBuilder::buildTarget(int arg_sz, const char* arg_val, const boo auto ret_exec = std::system(command.c_str()); if (ret_exec > 0) { - BTB::Logger::info() << "error: exec exit with code: " << ret_exec << "" << std::endl; + BTB::Logger::info() << "error: exit with message: " << std::strerror(ret_exec) << "" << std::endl; return false; } diff --git a/win64.json b/win64.json index 2dd9527..a4a2ecc 100644 --- a/win64.json +++ b/win64.json @@ -1,7 +1,7 @@ { "compiler_path": "x86_64-w64-mingw32-g++.exe", "compiler_std": "c++20", - "headers_path": ["lib", "vendor"], + "headers_path": ["./", "vendor"], "sources_path": ["src/*.cc", "cli/*.cc"], "output_name": "btb.exe", "compiler_flags": ["-fPIC"], -- cgit v1.2.3