From 20252df698106283d15ddf7d53f4e0dd9462666d Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Thu, 17 Jul 2025 07:32:30 +0100 Subject: refactor! Lots of breaking changes to the codebase. feat: Rename ‘btb‘ to ‘nebuild‘ to match nekernel.org's naming scheme. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Amlal El Mahrouss --- .github/workflows/c-cpp.yml | 2 +- .gitignore | 2 +- BTBKit/IManifestBuilder.h | 32 ----- BTBKit/Includes.h | 17 --- BTBKit/JSONManifestBuilder.h | 30 ---- BTBKit/Macros.h | 34 ----- GNUmakefile | 14 +- ReadMe.md | 4 +- cli/CommandLine.cc | 77 ---------- compile_flags.txt | 2 +- dev/BuildKit/IManifestBuilder.h | 32 +++++ dev/BuildKit/Includes.h | 17 +++ dev/BuildKit/JSONManifestBuilder.h | 30 ++++ dev/BuildKit/Macros.h | 34 +++++ dev/cli/CommandLine.cc | 77 ++++++++++ dev/examples/example_01_hello_world/hello_world.cc | 7 + dev/examples/example_01_hello_world/posix.json | 10 ++ dev/examples/example_01_hello_world/win64.json | 10 ++ dev/examples/example_02_libbtb/README.md | 7 + dev/examples/example_02_libbtb/libbtb.cc | 15 ++ dev/examples/example_02_libbtb/posix.json | 20 +++ dev/examples/example_02_libbtb/win64.json | 19 +++ dev/src/IManifestBuilder.cc | 6 + dev/src/JSONManifestBuilder.cc | 153 ++++++++++++++++++++ examples/example_01_hello_world/hello_world.cc | 7 - examples/example_01_hello_world/posix.json | 10 -- examples/example_01_hello_world/win64.json | 10 -- examples/example_02_libbtb/README.md | 7 - examples/example_02_libbtb/libbtb.cc | 15 -- examples/example_02_libbtb/posix.json | 20 --- examples/example_02_libbtb/win64.json | 19 --- osx-dylib.json | 6 +- osx.json | 6 +- posix.json | 6 +- src/IManifestBuilder.cc | 6 - src/JSONManifestBuilder.cc | 157 --------------------- win64.json | 6 +- 37 files changed, 461 insertions(+), 465 deletions(-) delete mode 100644 BTBKit/IManifestBuilder.h delete mode 100644 BTBKit/Includes.h delete mode 100644 BTBKit/JSONManifestBuilder.h delete mode 100644 BTBKit/Macros.h delete mode 100644 cli/CommandLine.cc create mode 100644 dev/BuildKit/IManifestBuilder.h create mode 100644 dev/BuildKit/Includes.h create mode 100644 dev/BuildKit/JSONManifestBuilder.h create mode 100644 dev/BuildKit/Macros.h create mode 100644 dev/cli/CommandLine.cc create mode 100644 dev/examples/example_01_hello_world/hello_world.cc create mode 100644 dev/examples/example_01_hello_world/posix.json create mode 100644 dev/examples/example_01_hello_world/win64.json create mode 100644 dev/examples/example_02_libbtb/README.md create mode 100644 dev/examples/example_02_libbtb/libbtb.cc create mode 100644 dev/examples/example_02_libbtb/posix.json create mode 100644 dev/examples/example_02_libbtb/win64.json create mode 100644 dev/src/IManifestBuilder.cc create mode 100644 dev/src/JSONManifestBuilder.cc delete mode 100644 examples/example_01_hello_world/hello_world.cc delete mode 100644 examples/example_01_hello_world/posix.json delete mode 100644 examples/example_01_hello_world/win64.json delete mode 100644 examples/example_02_libbtb/README.md delete mode 100644 examples/example_02_libbtb/libbtb.cc delete mode 100644 examples/example_02_libbtb/posix.json delete mode 100644 examples/example_02_libbtb/win64.json delete mode 100644 src/IManifestBuilder.cc delete mode 100644 src/JSONManifestBuilder.cc diff --git a/.github/workflows/c-cpp.yml b/.github/workflows/c-cpp.yml index 6f7b609..f3f03e1 100644 --- a/.github/workflows/c-cpp.yml +++ b/.github/workflows/c-cpp.yml @@ -16,4 +16,4 @@ jobs: - name: Install Packages run: sudo apt update && sudo apt install build-essential - name: Build BTB - run: make build-btb \ No newline at end of file + run: make build-nebuild \ No newline at end of file diff --git a/.gitignore b/.gitignore index 1511910..16285f7 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,7 @@ syntax: glob html/ latex/ -btb +nebuild .cmake/ .qtc_clangd/ diff --git a/BTBKit/IManifestBuilder.h b/BTBKit/IManifestBuilder.h deleted file mode 100644 index e11d431..0000000 --- a/BTBKit/IManifestBuilder.h +++ /dev/null @@ -1,32 +0,0 @@ -// ============================================================= // -// 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: - 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 deleted file mode 100644 index 3695d53..0000000 --- a/BTBKit/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/BTBKit/JSONManifestBuilder.h b/BTBKit/JSONManifestBuilder.h deleted file mode 100644 index f5d874c..0000000 --- a/BTBKit/JSONManifestBuilder.h +++ /dev/null @@ -1,30 +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 BTB_MANIFEST_BUILDER { - public: - JSONManifestBuilder() = default; - ~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. - bool buildTarget(int arg_sz, const char* arg_val, const bool dry_run = false) override; - const char* buildSystem() override; -}; -} // namespace BTB \ No newline at end of file diff --git a/BTBKit/Macros.h b/BTBKit/Macros.h deleted file mode 100644 index c2d6194..0000000 --- a/BTBKit/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 "v0.0.1-libBTB" - -#define LIBBTB_VERSION_BCD 0x0001 - -#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 index f3c888f..a008b1e 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -4,20 +4,20 @@ GCC_MINGW=x86_64-w64-mingw32-g++ CXXFLAGS=-I./ -I./vendor CXXSTD= -std=c++20 SRC=$(wildcard cli/*.cc) $(wildcard src/*.cc) -OUT=btb +OUT=nebuild CP=cp -.PHONY: build-btb -build-btb: +.PHONY: build-nebuild +build-nebuild: $(SUDO) $(GCC) $(CXXFLAGS) $(SRC) $(CXXSTD) -o $(OUT) $(SUDO) $(CP) $(OUT) /usr/local/bin -.PHONY: build-btb-windows -build-btb-windows: +.PHONY: build-nebuild-windows +build-nebuild-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." + @echo "=> build-nebuild-windows: Build BTB for Windows." + @echo "=> build-nebuild: Build BTB for POSIX." diff --git a/ReadMe.md b/ReadMe.md index 46363f3..d3430be 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -10,10 +10,10 @@ ## Guide (GNU Make): -- Run make `build-btb-core` and `build-btb`. +- Run make `build-nebuild-core` and `build-nebuild`. ## Guide (NeBuild): -- Run `btb` and pass the path to the manifest file. +- Run `nebuild` and pass the path to the manifest file. ###### Copyright (C) 2024-2025, Amlal El Mahrouss and NeKernel.org Authors, all rights reserved. diff --git a/cli/CommandLine.cc b/cli/CommandLine.cc deleted file mode 100644 index 300db6f..0000000 --- a/cli/CommandLine.cc +++ /dev/null @@ -1,77 +0,0 @@ - -// ============================================================= // -// btb -// Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. -// ============================================================= // - -#include -#include - -static bool kFailed = false; -static bool kDryRun = false; - -int main(int argc, char** argv) { - if (argc <= 1) return EXIT_FAILURE; - - for (size_t index = 1; index < argc; ++index) { - std::string index_path = argv[index]; - - if (index_path == "-v" || index_path == "--version") { - BTB::Logger::info() << "Brought to you by Amlal El Mahrouss for the NeKernel project.\n"; - BTB::Logger::info() << "© 2024-2025 Amlal El Mahrouss, all rights reserved.\n"; - - BTB::Logger::info() - << "Bugs, issues? Check out: https://github.com/nekernel-org/btb/issues\n"; - - return EXIT_SUCCESS; - } else if (index_path == "--dry-run") { - kDryRun = true; - continue; - } else if (index_path == "-h" || index_path == "--help") { - BTB::Logger::info() << "Usage: btb \n"; - - return EXIT_SUCCESS; - } - - if (index_path.starts_with("-")) { - BTB::Logger::info() << "error: unknown option '" << index_path << "'\n"; - - return EXIT_FAILURE; - } - - std::thread job_build_thread( - [](std::string index_path) -> void { - BTB::IManifestBuilder* builder = nullptr; - - const auto kJsonExtension = ".json"; - - if (index_path.ends_with(kJsonExtension)) { - builder = new BTB::JSONManifestBuilder(); - - if (!builder) { - kFailed = true; - return; - } - } else { - BTB::Logger::info() << "error: file '" << index_path << "' is not a JSON file!" - << std::endl; - kFailed = true; - return; - } - - BTB::Logger::info() << "building manifest: " << index_path << std::endl; - - if (builder && !builder->buildTarget(index_path.size(), index_path.c_str(), kDryRun)) { - kFailed = true; - } - - delete builder; - builder = nullptr; - }, - index_path); - - job_build_thread.join(); - } - - return kFailed ? EXIT_FAILURE : EXIT_SUCCESS; -} diff --git a/compile_flags.txt b/compile_flags.txt index 3edd1b0..bb1d0d2 100644 --- a/compile_flags.txt +++ b/compile_flags.txt @@ -1,3 +1,3 @@ -std=c++20 --I./ +-Idev/ -Ivendor \ No newline at end of file diff --git a/dev/BuildKit/IManifestBuilder.h b/dev/BuildKit/IManifestBuilder.h new file mode 100644 index 0000000..1c160c4 --- /dev/null +++ b/dev/BuildKit/IManifestBuilder.h @@ -0,0 +1,32 @@ +// ============================================================= // +// nebuild +// 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: + 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/dev/BuildKit/Includes.h b/dev/BuildKit/Includes.h new file mode 100644 index 0000000..e321483 --- /dev/null +++ b/dev/BuildKit/Includes.h @@ -0,0 +1,17 @@ +// ============================================================= // +// nebuild +// 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/dev/BuildKit/JSONManifestBuilder.h b/dev/BuildKit/JSONManifestBuilder.h new file mode 100644 index 0000000..a4fe66b --- /dev/null +++ b/dev/BuildKit/JSONManifestBuilder.h @@ -0,0 +1,30 @@ +// ============================================================= // +// nebuild +// 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: + JSONManifestBuilder() = default; + ~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. + bool buildTarget(int arg_sz, const char* arg_val, const bool dry_run = false) override; + const char* buildSystem() override; +}; +} // namespace BTB \ No newline at end of file diff --git a/dev/BuildKit/Macros.h b/dev/BuildKit/Macros.h new file mode 100644 index 0000000..1b1613d --- /dev/null +++ b/dev/BuildKit/Macros.h @@ -0,0 +1,34 @@ +// ============================================================= // +// nebuild +// 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 "v0.0.1-libBTB" + +#define LIBBTB_VERSION_BCD 0x0001 + +#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 << "nebuild: " << rang::style::reset; + return out; +} +} // namespace BTB::Logger diff --git a/dev/cli/CommandLine.cc b/dev/cli/CommandLine.cc new file mode 100644 index 0000000..e199e61 --- /dev/null +++ b/dev/cli/CommandLine.cc @@ -0,0 +1,77 @@ + +// ============================================================= // +// nebuild +// Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. +// ============================================================= // + +#include +#include + +static bool kFailed = false; +static bool kDryRun = false; + +int main(int argc, char** argv) { + if (argc <= 1) return EXIT_FAILURE; + + for (size_t index = 1; index < argc; ++index) { + std::string index_path = argv[index]; + + if (index_path == "-v" || index_path == "--version") { + BTB::Logger::info() << "Brought to you by Amlal El Mahrouss for the NeKernel project.\n"; + BTB::Logger::info() << "© 2024-2025 Amlal El Mahrouss, all rights reserved.\n"; + + BTB::Logger::info() + << "Bugs, issues? Check out: https://github.com/nekernel-org/nebuild/issues\n"; + + return EXIT_SUCCESS; + } else if (index_path == "--dry-run") { + kDryRun = true; + continue; + } else if (index_path == "-h" || index_path == "--help") { + BTB::Logger::info() << "Usage: nebuild \n"; + + return EXIT_SUCCESS; + } + + if (index_path.starts_with("-")) { + BTB::Logger::info() << "error: unknown option '" << index_path << "'\n"; + + return EXIT_FAILURE; + } + + std::thread job_build_thread( + [](std::string index_path) -> void { + BTB::IManifestBuilder* builder = nullptr; + + const auto kJsonExtension = ".json"; + + if (index_path.ends_with(kJsonExtension)) { + builder = new BTB::JSONManifestBuilder(); + + if (!builder) { + kFailed = true; + return; + } + } else { + BTB::Logger::info() << "error: file '" << index_path << "' is not a JSON file!" + << std::endl; + kFailed = true; + return; + } + + BTB::Logger::info() << "building manifest: " << index_path << std::endl; + + if (builder && !builder->buildTarget(index_path.size(), index_path.c_str(), kDryRun)) { + kFailed = true; + } + + delete builder; + builder = nullptr; + }, + index_path); + + job_build_thread.join(); + } + + return kFailed ? EXIT_FAILURE : EXIT_SUCCESS; +} diff --git a/dev/examples/example_01_hello_world/hello_world.cc b/dev/examples/example_01_hello_world/hello_world.cc new file mode 100644 index 0000000..ae47ce8 --- /dev/null +++ b/dev/examples/example_01_hello_world/hello_world.cc @@ -0,0 +1,7 @@ +#include +#include + +int main(int argc, char** argv) { + std::cout << "hello, world!\n"; + return 0; +} diff --git a/dev/examples/example_01_hello_world/posix.json b/dev/examples/example_01_hello_world/posix.json new file mode 100644 index 0000000..c3c8151 --- /dev/null +++ b/dev/examples/example_01_hello_world/posix.json @@ -0,0 +1,10 @@ +{ + "compiler_path": "g++", + "compiler_std": "c++20", + "headers_path": ["lib"], + "sources_path": ["hello_world.cc"], + "output_name": "hello_world.elf", + "compiler_flags": ["-fPIC"], + "cpp_macros": ["FOO_MACRO"], + "run_after_build": true +} diff --git a/dev/examples/example_01_hello_world/win64.json b/dev/examples/example_01_hello_world/win64.json new file mode 100644 index 0000000..4af5bdd --- /dev/null +++ b/dev/examples/example_01_hello_world/win64.json @@ -0,0 +1,10 @@ +{ + "compiler_path": "x86_64-w64-mingw32-g++", + "compiler_std": "c++20", + "headers_path": ["lib"], + "sources_path": ["hello_world.cc"], + "output_name": "hello_world.elf", + "compiler_flags": ["-fPIC"], + "cpp_macros": ["FOO_MACRO"], + "run_after_build": true +} diff --git a/dev/examples/example_02_libbtb/README.md b/dev/examples/example_02_libbtb/README.md new file mode 100644 index 0000000..26ccb72 --- /dev/null +++ b/dev/examples/example_02_libbtb/README.md @@ -0,0 +1,7 @@ +# Notice for Deployment. + +In order to use libBTB, it shall live on the same directory, +
+or within a directory recognized in the `$LD_LIBRARY_PATH` or `$DYLD_LIBRARY_PATH` variable. + +## Thanks in advance. \ No newline at end of file diff --git a/dev/examples/example_02_libbtb/libbtb.cc b/dev/examples/example_02_libbtb/libbtb.cc new file mode 100644 index 0000000..0b4d7c4 --- /dev/null +++ b/dev/examples/example_02_libbtb/libbtb.cc @@ -0,0 +1,15 @@ +#include +#include + +#ifndef _WIN32 +static auto kPath = "./posix.json"; +#else +static auto kPath = ".\win64.json"; +#endif + +int main(int argc, char** argv) { + auto builder = new BTB::JSONManifestBuilder(); + if (!builder) return EXIT_FAILURE; + + return builder->buildTarget(strlen(kPath), kPath); +} diff --git a/dev/examples/example_02_libbtb/posix.json b/dev/examples/example_02_libbtb/posix.json new file mode 100644 index 0000000..871712e --- /dev/null +++ b/dev/examples/example_02_libbtb/posix.json @@ -0,0 +1,20 @@ +{ + "compiler_path": "g++", + "compiler_std": "c++20", + "headers_path": [ + "../../", + "../../vendor" + ], + "sources_path": [ + "libbtb.cc" + ], + "output_name": "libbtb.elf", + "compiler_flags": [ + "-L/usr/local/lib", + "-lBTB" + ], + "cpp_macros": [ + "FOO_MACRO" + ], + "run_after_build": true +} \ No newline at end of file diff --git a/dev/examples/example_02_libbtb/win64.json b/dev/examples/example_02_libbtb/win64.json new file mode 100644 index 0000000..658ee0f --- /dev/null +++ b/dev/examples/example_02_libbtb/win64.json @@ -0,0 +1,19 @@ +{ + "compiler_path": "x86_64-w64-mingw32-g++", + "compiler_std": "c++20", + "headers_path": [ + "../../", + "../../vendor" + ], + "sources_path": [ + "libbtb.cc" + ], + "output_name": "libbtb.exe", + "compiler_flags": [ + "-lBTB" + ], + "cpp_macros": [ + "FOO_MACRO" + ], + "run_after_build": true +} \ No newline at end of file diff --git a/dev/src/IManifestBuilder.cc b/dev/src/IManifestBuilder.cc new file mode 100644 index 0000000..1397dd4 --- /dev/null +++ b/dev/src/IManifestBuilder.cc @@ -0,0 +1,6 @@ +// ============================================================= // +// nebuild +// Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. +// ============================================================= // + +#include diff --git a/dev/src/JSONManifestBuilder.cc b/dev/src/JSONManifestBuilder.cc new file mode 100644 index 0000000..e93bcb7 --- /dev/null +++ b/dev/src/JSONManifestBuilder.cc @@ -0,0 +1,153 @@ +// ============================================================= // +// nebuild +// Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. +// ============================================================= // + +#include + +using String = std::string; +using JSON = nlohmann::json; + +namespace FS = std::filesystem; + +using namespace BTB; + +/// @brief Builds a JSON target from a JSON file. +/// @param arg_sz filename size (must be 1 or greater). +/// @param arg_val filename path (must be a valid JSON file). +/// @retval true building has succeeded. +/// @retval false fail to build, see error message. +bool JSONManifestBuilder::buildTarget(int arg_sz, const char* arg_val, const bool dry_run) { + String path; + + if (!arg_val || arg_sz < 0) { + BTB::Logger::info() << "nebuild: error: file path is empty" << std::endl; + return false; + } else { + path += arg_val; + + if (!FS::exists(path)) { + BTB::Logger::info() << "nebuild: error: file '" << path << "' does not exist" << std::endl; + return false; + } + } + + try { + std::ifstream json(path); + + if (!json.good()) { + BTB::Logger::info() << "nebuild: error: file '" << path << "' is not a valid JSON" << std::endl; + return false; + } + + JSON json_obj = JSON::parse(json); + + String compiler = json_obj["compiler_path"].get(); + + JSON header_search_path = json_obj["headers_path"]; + JSON sources_files = json_obj["sources_path"]; + + String command = compiler + " "; + + for (auto& sources : sources_files) { + command += sources.get() + " "; + } + + for (auto& headers : header_search_path) { + command += "-I" + headers.get() + " "; + } + + JSON macros_list = json_obj["cpp_macros"]; + + for (auto& macro : macros_list) { + command += "-D" + macro.get() + " "; + } + + JSON compiler_flags = json_obj["compiler_flags"]; + + for (auto& flag : compiler_flags) { + command += flag.get() + " "; + } + + if (json_obj["compiler_std"].is_string()) + command += "-std=" + json_obj["compiler_std"].get() + " "; + + command += "-o " + json_obj["output_name"].get(); + + auto target = json_obj["output_name"].get(); + + BTB::Logger::info() << "output path: " << target << "\n"; + BTB::Logger::info() << "command: " << command << "\n"; + + try { + if (json_obj["dry_run"].get()) return true; + } catch (...) { + } + + if (dry_run) { + return true; + } + + auto ret_exec = std::system(command.c_str()); + + if (ret_exec > 0) { + BTB::Logger::info() << "error: exit with message: " << std::strerror(ret_exec) << "" << std::endl; + return false; + } + + try { + if (json_obj["run_after_build"].get()) { + if (target.ends_with(".so")) { + BTB::Logger::info() << "error: can't open dynamic library, it mayn't have an entrypoint" + << std::endl; + + return true; + } else if (target.ends_with(".dylib") || target.ends_with(".dll")) { + std::ifstream file = std::ifstream(target); + std::stringstream ss; + + ss << file.rdbuf(); + + if (ss.str()[0] == 'O' && ss.str()[1] == 'p' && ss.str()[2] == 'e' && ss.str()[3] == 'n') + BTB::Logger::info() + << "error: can't open PEF dynamic library, it mayn't contain an entrypoint" + << std::endl; + else if (ss.str()[0] == 'n' && ss.str()[1] == 'e' && ss.str()[2] == 'p' && + ss.str()[3] == 'O') + BTB::Logger::info() + << "error: can't open FEP dynamic library, it mayn't contain an entrypoint" + << std::endl; + else if (ss.str()[0] == 'M' && ss.str()[1] == 'Z') + BTB::Logger::info() + << "error: can't open MZ dynamic library, it mayn't contain an entrypoint" + << std::endl; + else if (ss.str()[0] == 0x7F && ss.str()[1] == 'E') { + BTB::Logger::info() + << "error: can't open ELF dynamic library, it mayn't contain an entrypoint" + << std::endl; + } + + return true; + } + +#if defined(BTB_WINDOWS) + std::system((".\\" + target).c_str()); +#else + std::system(("./" + target).c_str()); +#endif + } + } catch (...) { + return true; + } + } catch (std::runtime_error& err) { + BTB::Logger::info() << "error: " << err.what() << std::endl; + + return false; + } + + return true; +} + +const char* JSONManifestBuilder::buildSystem() { + return "json"; +} diff --git a/examples/example_01_hello_world/hello_world.cc b/examples/example_01_hello_world/hello_world.cc deleted file mode 100644 index ae47ce8..0000000 --- a/examples/example_01_hello_world/hello_world.cc +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include - -int main(int argc, char** argv) { - std::cout << "hello, world!\n"; - return 0; -} diff --git a/examples/example_01_hello_world/posix.json b/examples/example_01_hello_world/posix.json deleted file mode 100644 index c3c8151..0000000 --- a/examples/example_01_hello_world/posix.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "compiler_path": "g++", - "compiler_std": "c++20", - "headers_path": ["lib"], - "sources_path": ["hello_world.cc"], - "output_name": "hello_world.elf", - "compiler_flags": ["-fPIC"], - "cpp_macros": ["FOO_MACRO"], - "run_after_build": true -} diff --git a/examples/example_01_hello_world/win64.json b/examples/example_01_hello_world/win64.json deleted file mode 100644 index 4af5bdd..0000000 --- a/examples/example_01_hello_world/win64.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "compiler_path": "x86_64-w64-mingw32-g++", - "compiler_std": "c++20", - "headers_path": ["lib"], - "sources_path": ["hello_world.cc"], - "output_name": "hello_world.elf", - "compiler_flags": ["-fPIC"], - "cpp_macros": ["FOO_MACRO"], - "run_after_build": true -} diff --git a/examples/example_02_libbtb/README.md b/examples/example_02_libbtb/README.md deleted file mode 100644 index 26ccb72..0000000 --- a/examples/example_02_libbtb/README.md +++ /dev/null @@ -1,7 +0,0 @@ -# Notice for Deployment. - -In order to use libBTB, it shall live on the same directory, -
-or within a directory recognized in the `$LD_LIBRARY_PATH` or `$DYLD_LIBRARY_PATH` variable. - -## Thanks in advance. \ No newline at end of file diff --git a/examples/example_02_libbtb/libbtb.cc b/examples/example_02_libbtb/libbtb.cc deleted file mode 100644 index 21e3e17..0000000 --- a/examples/example_02_libbtb/libbtb.cc +++ /dev/null @@ -1,15 +0,0 @@ -#include -#include - -#ifndef _WIN32 -static auto kPath = "./posix.json"; -#else -static auto kPath = ".\win64.json"; -#endif - -int main(int argc, char** argv) { - auto builder = new BTB::JSONManifestBuilder(); - if (!builder) return EXIT_FAILURE; - - return builder->buildTarget(strlen(kPath), kPath); -} diff --git a/examples/example_02_libbtb/posix.json b/examples/example_02_libbtb/posix.json deleted file mode 100644 index 871712e..0000000 --- a/examples/example_02_libbtb/posix.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "compiler_path": "g++", - "compiler_std": "c++20", - "headers_path": [ - "../../", - "../../vendor" - ], - "sources_path": [ - "libbtb.cc" - ], - "output_name": "libbtb.elf", - "compiler_flags": [ - "-L/usr/local/lib", - "-lBTB" - ], - "cpp_macros": [ - "FOO_MACRO" - ], - "run_after_build": true -} \ No newline at end of file diff --git a/examples/example_02_libbtb/win64.json b/examples/example_02_libbtb/win64.json deleted file mode 100644 index 658ee0f..0000000 --- a/examples/example_02_libbtb/win64.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "compiler_path": "x86_64-w64-mingw32-g++", - "compiler_std": "c++20", - "headers_path": [ - "../../", - "../../vendor" - ], - "sources_path": [ - "libbtb.cc" - ], - "output_name": "libbtb.exe", - "compiler_flags": [ - "-lBTB" - ], - "cpp_macros": [ - "FOO_MACRO" - ], - "run_after_build": true -} \ No newline at end of file diff --git a/osx-dylib.json b/osx-dylib.json index 80917d2..3c49abb 100644 --- a/osx-dylib.json +++ b/osx-dylib.json @@ -1,10 +1,10 @@ { "compiler_path": "g++", "compiler_std": "c++20", - "headers_path": ["./", "vendor"], - "sources_path": ["src/*.cc"], + "headers_path": ["dev", "vendor"], + "sources_path": ["dev/src/*.cc"], "output_name": "libBTB.dylib", "compiler_flags": ["-fPIC", "-shared"], - "cpp_macros": ["BTB_POSIX", "BTB_OSX"], + "cpp_macros": ["BTB_DYLIB", "BTB_OSX"], "run_after_build": false } diff --git a/osx.json b/osx.json index 20d513d..b4a860c 100644 --- a/osx.json +++ b/osx.json @@ -1,9 +1,9 @@ { "compiler_path": "g++", "compiler_std": "c++20", - "headers_path": ["./", "vendor"], - "sources_path": ["src/*.cc", "cli/*.cc"], - "output_name": "btb", + "headers_path": ["dev", "vendor"], + "sources_path": ["dev/src/*.cc", "dev/cli/*.cc"], + "output_name": "nebuild", "compiler_flags": ["-fPIC"], "cpp_macros": ["BTB_POSIX", "BTB_OSX"], "run_after_build": false diff --git a/posix.json b/posix.json index e53cc14..540c877 100644 --- a/posix.json +++ b/posix.json @@ -1,9 +1,9 @@ { "compiler_path": "g++", "compiler_std": "c++20", - "headers_path": ["./", "vendor"], - "sources_path": ["src/*.cc", "cli/*.cc"], - "output_name": "btb", + "headers_path": ["dev/", "vendor"], + "sources_path": ["dev/src/*.cc", "dev/cli/*.cc"], + "output_name": "nebuild", "compiler_flags": ["-fPIC"], "cpp_macros": ["BTB_POSIX"], "run_after_build": false diff --git a/src/IManifestBuilder.cc b/src/IManifestBuilder.cc deleted file mode 100644 index b3f4de8..0000000 --- a/src/IManifestBuilder.cc +++ /dev/null @@ -1,6 +0,0 @@ -// ============================================================= // -// btb -// Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. -// ============================================================= // - -#include diff --git a/src/JSONManifestBuilder.cc b/src/JSONManifestBuilder.cc deleted file mode 100644 index 50850f5..0000000 --- a/src/JSONManifestBuilder.cc +++ /dev/null @@ -1,157 +0,0 @@ -// ============================================================= // -// btb -// Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. -// ============================================================= // - -#include - -using String = std::string; -using JSON = nlohmann::json; -namespace FS = std::filesystem; - -using namespace BTB; - -/// @brief Builds a JSON target from a JSON file. -/// @param arg_sz filename size (must be 1 or greater). -/// @param arg_val filename path (must be a valid JSON file). -/// @retval true building has succeeded. -/// @retval false fail to build, see error message. -bool JSONManifestBuilder::buildTarget(int arg_sz, const char* arg_val, const bool dry_run) { - String path; - - if (!arg_val) { - BTB::Logger::info() << "btb: error: file path is empty" << std::endl; - return false; - } - - if (arg_sz < 0) { - BTB::Logger::info() << "btb: error: file path is empty" << std::endl; - return false; - } else { - path = arg_val; - - if (!FS::exists(path)) { - BTB::Logger::info() << "btb: error: file '" << path << "' does not exist" << std::endl; - return false; - } - } - - try { - std::ifstream json(path); - - if (!json.good()) { - BTB::Logger::info() << "btb: error: file '" << path << "' is not a valid JSON" << std::endl; - return false; - } - - JSON json_obj = JSON::parse(json); - - String compiler = json_obj["compiler_path"].get(); - - JSON header_search_path = json_obj["headers_path"]; - JSON sources_files = json_obj["sources_path"]; - - String command = compiler + " "; - - for (auto& sources : sources_files) { - command += sources.get() + " "; - } - - for (auto& headers : header_search_path) { - command += "-I" + headers.get() + " "; - } - - JSON macros_list = json_obj["cpp_macros"]; - - for (auto& macro : macros_list) { - command += "-D" + macro.get() + " "; - } - - JSON compiler_flags = json_obj["compiler_flags"]; - - for (auto& flag : compiler_flags) { - command += flag.get() + " "; - } - - if (json_obj["compiler_std"].is_string()) - command += "-std=" + json_obj["compiler_std"].get() + " "; - - command += "-o " + json_obj["output_name"].get(); - - auto target = json_obj["output_name"].get(); - - BTB::Logger::info() << "output path: " << target << "\n"; - BTB::Logger::info() << "command: " << command << "\n"; - - try { - if (json_obj["dry_run"].get()) return true; - } catch (...) { - } - - if (dry_run) { - return true; - } - - auto ret_exec = std::system(command.c_str()); - - if (ret_exec > 0) { - BTB::Logger::info() << "error: exit with message: " << std::strerror(ret_exec) << "" << std::endl; - return false; - } - - try { - if (json_obj["run_after_build"].get()) { - if (target.ends_with(".so")) { - BTB::Logger::info() << "error: can't open dynamic library, it mayn't have an entrypoint" - << std::endl; - - return true; - } else if (target.ends_with(".dylib") || target.ends_with(".dll")) { - std::ifstream 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] == '!') - BTB::Logger::info() - << "error: can't open PEF dynamic library, 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') - BTB::Logger::info() - << "error: can't open FEP dynamic library, it mayn't contain an entrypoint" - << std::endl; - else if (ss.str()[0] == 'M' && ss.str()[1] == 'Z') - BTB::Logger::info() - << "error: can't open MZ dynamic library, it mayn't contain an entrypoint" - << std::endl; - else if (ss.str()[0] == 0x7F && ss.str()[1] == 'E') { - BTB::Logger::info() - << "error: can't open ELF dynamic library, it mayn't contain an entrypoint" - << std::endl; - } - - return true; - } - -#if defined(BTB_WINDOWS) - std::system((".\\" + target).c_str()); -#else - std::system(("./" + target).c_str()); -#endif - } - } catch (...) { - return true; - } - } catch (std::runtime_error& err) { - BTB::Logger::info() << "error: " << err.what() << std::endl; - - return false; - } - - return true; -} - -const char* JSONManifestBuilder::buildSystem() { - return "json"; -} diff --git a/win64.json b/win64.json index a4a2ecc..65a42be 100644 --- a/win64.json +++ b/win64.json @@ -1,9 +1,9 @@ { "compiler_path": "x86_64-w64-mingw32-g++.exe", "compiler_std": "c++20", - "headers_path": ["./", "vendor"], - "sources_path": ["src/*.cc", "cli/*.cc"], - "output_name": "btb.exe", + "headers_path": ["dev", "vendor"], + "sources_path": ["dev/src/*.cc", "dev/cli/*.cc"], + "output_name": "nebuild.exe", "compiler_flags": ["-fPIC"], "cpp_macros": ["BTB_WINDOWS"], "run_after_build": false -- cgit v1.2.3