diff --git a/.clang-format b/.clang-format index fb3cacb..3943f55 100644 --- a/.clang-format +++ b/.clang-format @@ -1,16 +1,29 @@ ---- -BasedOnStyle: Microsoft -AccessModifierOffset: '-4' -AlignAfterOpenBracket: Align -AlignConsecutiveMacros: 'true' -AlignConsecutiveAssignments: 'true' -AlignConsecutiveDeclarations: 'true' -BinPackParameters: 'false' -ColumnLimit: '0' -Language: Cpp -NamespaceIndentation: All +BasedOnStyle: Google +IndentWidth: 2 +TabWidth: 2 +UseTab: Never +ColumnLimit: 100 +DerivePointerAlignment: false PointerAlignment: Left -ReflowComments: 'true' -SortIncludes: 'false' -UseTab: Always -... +AllowShortFunctionsOnASingleLine: Inline +AllowShortIfStatementsOnASingleLine: true +AllowShortLoopsOnASingleLine: true +SortIncludes: true +IncludeBlocks: Preserve +SpaceAfterCStyleCast: true +SpaceBeforeParens: ControlStatements +SpacesInAngles: false +SpacesInContainerLiterals: true +SpacesInParentheses: false +SpacesInSquareBrackets: false +BreakBeforeBraces: Attach +ConstructorInitializerAllOnOneLineOrOnePerLine: true +Cpp11BracedListStyle: true +NamespaceIndentation: Inner +ReflowComments: true +AlignConsecutiveAssignments: true +AlignConsecutiveDeclarations: true +AlignTrailingComments: true +FixNamespaceComments: true +IncludeIsMainRegex: '(Test)?$' +SortUsingDeclarations: true diff --git a/BTBKit/IManifestBuilder.h b/BTBKit/IManifestBuilder.h new file mode 100644 index 0000000..e11d431 --- /dev/null +++ b/BTBKit/IManifestBuilder.h @@ -0,0 +1,32 @@ +// ============================================================= // +// 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/lib/Includes.h b/BTBKit/Includes.h similarity index 93% rename from lib/Includes.h rename to BTBKit/Includes.h index 3f035f3..3695d53 100644 --- a/lib/Includes.h +++ b/BTBKit/Includes.h @@ -6,12 +6,12 @@ #ifndef BTB_INCLUDES_H #define BTB_INCLUDES_H -#include #include -#include +#include +#include #include -#include #include -#include +#include +#include -#endif // BTB_INCLUDES_H +#endif // BTB_INCLUDES_H diff --git a/BTBKit/JSONManifestBuilder.h b/BTBKit/JSONManifestBuilder.h new file mode 100644 index 0000000..f5d874c --- /dev/null +++ b/BTBKit/JSONManifestBuilder.h @@ -0,0 +1,30 @@ +// ============================================================= // +// 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 new file mode 100644 index 0000000..c2d6194 --- /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 "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/makefile b/GNUmakefile similarity index 94% rename from makefile rename to GNUmakefile index 8884c33..f3c888f 100644 --- a/makefile +++ b/GNUmakefile @@ -1,7 +1,7 @@ SUDO=sudo GCC=g++ GCC_MINGW=x86_64-w64-mingw32-g++ -CXXFLAGS=-I./lib -I./vendor +CXXFLAGS=-I./ -I./vendor CXXSTD= -std=c++20 SRC=$(wildcard cli/*.cc) $(wildcard src/*.cc) OUT=btb diff --git a/cli/CommandLine.cc b/cli/CommandLine.cc index 5c522e7..300db6f 100644 --- a/cli/CommandLine.cc +++ b/cli/CommandLine.cc @@ -4,87 +4,74 @@ // Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. // ============================================================= // -#include -#include +#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; +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 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/examples/example_01/example.cc b/examples/example_01/example.cc deleted file mode 100644 index aa2d8b0..0000000 --- a/examples/example_01/example.cc +++ /dev/null @@ -1,8 +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/hello_world.cc b/examples/example_01_hello_world/hello_world.cc new file mode 100644 index 0000000..ae47ce8 --- /dev/null +++ b/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/examples/example_01/posix.json b/examples/example_01_hello_world/posix.json similarity index 69% rename from examples/example_01/posix.json rename to examples/example_01_hello_world/posix.json index 17a6022..c3c8151 100644 --- a/examples/example_01/posix.json +++ b/examples/example_01_hello_world/posix.json @@ -2,8 +2,8 @@ "compiler_path": "g++", "compiler_std": "c++20", "headers_path": ["lib"], - "sources_path": ["example.cc"], - "output_name": "example.elf", + "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/win64.json b/examples/example_01_hello_world/win64.json similarity index 72% rename from examples/example_01/win64.json rename to examples/example_01_hello_world/win64.json index 1712d8b..4af5bdd 100644 --- a/examples/example_01/win64.json +++ b/examples/example_01_hello_world/win64.json @@ -2,8 +2,8 @@ "compiler_path": "x86_64-w64-mingw32-g++", "compiler_std": "c++20", "headers_path": ["lib"], - "sources_path": ["example.cc"], - "output_name": "example.elf", + "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 new file mode 100644 index 0000000..26ccb72 --- /dev/null +++ b/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/examples/example_02_libbtb/libbtb.cc b/examples/example_02_libbtb/libbtb.cc new file mode 100644 index 0000000..f3d45b8 --- /dev/null +++ b/examples/example_02_libbtb/libbtb.cc @@ -0,0 +1,12 @@ +#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(); + return builder->buildTarget(strlen(kPath), kPath); +} diff --git a/examples/example_02_libbtb/posix.json b/examples/example_02_libbtb/posix.json new file mode 100644 index 0000000..871712e --- /dev/null +++ b/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/examples/example_02_libbtb/win64.json b/examples/example_02_libbtb/win64.json new file mode 100644 index 0000000..658ee0f --- /dev/null +++ b/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/lib/IManifestBuilder.h b/lib/IManifestBuilder.h deleted file mode 100644 index a48511c..0000000 --- a/lib/IManifestBuilder.h +++ /dev/null @@ -1,33 +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/JSONManifestBuilder.h b/lib/JSONManifestBuilder.h deleted file mode 100644 index fef5baf..0000000 --- a/lib/JSONManifestBuilder.h +++ /dev/null @@ -1,33 +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 35a44a1..0000000 --- a/lib/Macros.h +++ /dev/null @@ -1,37 +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/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 d268724..46a8518 100644 --- a/src/JSONManifestBuilder.cc +++ b/src/JSONManifestBuilder.cc @@ -3,11 +3,10 @@ // Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. // ============================================================= // -#include -#include +#include using String = std::string; -using JSON = nlohmann::json; +using JSON = nlohmann::json; namespace FS = std::filesystem; using namespace BTB; @@ -17,164 +16,137 @@ using namespace BTB; /// @param arg_val filename path (must be a valid JSON file). /// @retval true succeeded building. /// @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_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: exec exit with code: " << 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; - } +bool JSONManifestBuilder::buildTarget(int arg_sz, const char* arg_val, const bool dry_run) { + String path; + + 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()); + std::system((".\\" + target).c_str()); #else - std::system(("./" + target).c_str()); + 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; + } + } 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"; +const char* JSONManifestBuilder::buildSystem() { + return "json"; } diff --git a/vendor/json_fwd.h b/vendor/json_fwd.h index 29a6036..a1c70f3 100644 --- a/vendor/json_fwd.h +++ b/vendor/json_fwd.h @@ -9,11 +9,11 @@ #ifndef INCLUDE_NLOHMANN_JSON_FWD_HPP_ #define INCLUDE_NLOHMANN_JSON_FWD_HPP_ -#include // int64_t, uint64_t -#include // map -#include // allocator -#include // string -#include // vector +#include // int64_t, uint64_t +#include // map +#include // allocator +#include // string +#include // vector // #include // __ _____ _____ _____ @@ -24,16 +24,16 @@ // SPDX-FileCopyrightText: 2013-2023 Niels Lohmann // SPDX-License-Identifier: MIT - - // This file contains all macro definitions affecting or depending on the ABI #ifndef JSON_SKIP_LIBRARY_VERSION_CHECK - #if defined(NLOHMANN_JSON_VERSION_MAJOR) && defined(NLOHMANN_JSON_VERSION_MINOR) && defined(NLOHMANN_JSON_VERSION_PATCH) - #if NLOHMANN_JSON_VERSION_MAJOR != 3 || NLOHMANN_JSON_VERSION_MINOR != 11 || NLOHMANN_JSON_VERSION_PATCH != 3 - #warning "Already included a different version of the library!" - #endif - #endif +#if defined(NLOHMANN_JSON_VERSION_MAJOR) && defined(NLOHMANN_JSON_VERSION_MINOR) && \ + defined(NLOHMANN_JSON_VERSION_PATCH) +#if NLOHMANN_JSON_VERSION_MAJOR != 3 || NLOHMANN_JSON_VERSION_MINOR != 11 || \ + NLOHMANN_JSON_VERSION_PATCH != 3 +#warning "Already included a different version of the library!" +#endif +#endif #endif #define NLOHMANN_JSON_VERSION_MAJOR 3 // NOLINT(modernize-macro-to-enum) @@ -41,83 +41,72 @@ #define NLOHMANN_JSON_VERSION_PATCH 3 // NOLINT(modernize-macro-to-enum) #ifndef JSON_DIAGNOSTICS - #define JSON_DIAGNOSTICS 0 +#define JSON_DIAGNOSTICS 0 #endif #ifndef JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON - #define JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON 0 +#define JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON 0 #endif #if JSON_DIAGNOSTICS - #define NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS _diag +#define NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS _diag #else - #define NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS +#define NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS #endif #if JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON - #define NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON _ldvcmp +#define NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON _ldvcmp #else - #define NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON +#define NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON #endif #ifndef NLOHMANN_JSON_NAMESPACE_NO_VERSION - #define NLOHMANN_JSON_NAMESPACE_NO_VERSION 0 +#define NLOHMANN_JSON_NAMESPACE_NO_VERSION 0 #endif // Construct the namespace ABI tags component -#define NLOHMANN_JSON_ABI_TAGS_CONCAT_EX(a, b) json_abi ## a ## b -#define NLOHMANN_JSON_ABI_TAGS_CONCAT(a, b) \ - NLOHMANN_JSON_ABI_TAGS_CONCAT_EX(a, b) +#define NLOHMANN_JSON_ABI_TAGS_CONCAT_EX(a, b) json_abi##a##b +#define NLOHMANN_JSON_ABI_TAGS_CONCAT(a, b) NLOHMANN_JSON_ABI_TAGS_CONCAT_EX(a, b) -#define NLOHMANN_JSON_ABI_TAGS \ - NLOHMANN_JSON_ABI_TAGS_CONCAT( \ - NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS, \ - NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON) +#define NLOHMANN_JSON_ABI_TAGS \ + NLOHMANN_JSON_ABI_TAGS_CONCAT(NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS, \ + NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON) // Construct the namespace version component -#define NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT_EX(major, minor, patch) \ - _v ## major ## _ ## minor ## _ ## patch +#define NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT_EX(major, minor, patch) _v##major##_##minor##_##patch #define NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT(major, minor, patch) \ - NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT_EX(major, minor, patch) + NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT_EX(major, minor, patch) #if NLOHMANN_JSON_NAMESPACE_NO_VERSION #define NLOHMANN_JSON_NAMESPACE_VERSION #else -#define NLOHMANN_JSON_NAMESPACE_VERSION \ - NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT(NLOHMANN_JSON_VERSION_MAJOR, \ - NLOHMANN_JSON_VERSION_MINOR, \ - NLOHMANN_JSON_VERSION_PATCH) +#define NLOHMANN_JSON_NAMESPACE_VERSION \ + NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT(NLOHMANN_JSON_VERSION_MAJOR, NLOHMANN_JSON_VERSION_MINOR, \ + NLOHMANN_JSON_VERSION_PATCH) #endif // Combine namespace components -#define NLOHMANN_JSON_NAMESPACE_CONCAT_EX(a, b) a ## b -#define NLOHMANN_JSON_NAMESPACE_CONCAT(a, b) \ - NLOHMANN_JSON_NAMESPACE_CONCAT_EX(a, b) +#define NLOHMANN_JSON_NAMESPACE_CONCAT_EX(a, b) a##b +#define NLOHMANN_JSON_NAMESPACE_CONCAT(a, b) NLOHMANN_JSON_NAMESPACE_CONCAT_EX(a, b) #ifndef NLOHMANN_JSON_NAMESPACE -#define NLOHMANN_JSON_NAMESPACE \ - nlohmann::NLOHMANN_JSON_NAMESPACE_CONCAT( \ - NLOHMANN_JSON_ABI_TAGS, \ - NLOHMANN_JSON_NAMESPACE_VERSION) +#define NLOHMANN_JSON_NAMESPACE \ + nlohmann::NLOHMANN_JSON_NAMESPACE_CONCAT(NLOHMANN_JSON_ABI_TAGS, NLOHMANN_JSON_NAMESPACE_VERSION) #endif #ifndef NLOHMANN_JSON_NAMESPACE_BEGIN -#define NLOHMANN_JSON_NAMESPACE_BEGIN \ - namespace nlohmann \ - { \ - inline namespace NLOHMANN_JSON_NAMESPACE_CONCAT( \ - NLOHMANN_JSON_ABI_TAGS, \ - NLOHMANN_JSON_NAMESPACE_VERSION) \ - { +#define NLOHMANN_JSON_NAMESPACE_BEGIN \ + namespace nlohmann { \ + inline namespace NLOHMANN_JSON_NAMESPACE_CONCAT(NLOHMANN_JSON_ABI_TAGS, \ + NLOHMANN_JSON_NAMESPACE_VERSION) { #endif #ifndef NLOHMANN_JSON_NAMESPACE_END -#define NLOHMANN_JSON_NAMESPACE_END \ - } /* namespace (inline namespace) NOLINT(readability/namespace) */ \ - } // namespace nlohmann +#define NLOHMANN_JSON_NAMESPACE_END \ + } /* namespace (inline namespace) NOLINT(readability/namespace) */ \ + } // namespace nlohmann #endif - /*! @brief namespace for Niels Lohmann @see https://github.com/nlohmann @@ -132,28 +121,26 @@ This serializer ignores the template arguments and uses ADL ([argument-dependent lookup](https://en.cppreference.com/w/cpp/language/adl)) for serialization. */ -template +template struct adl_serializer; /// a class to store JSON values /// @sa https://json.nlohmann.me/api/basic_json/ -template class ObjectType = - std::map, - template class ArrayType = std::vector, - class StringType = std::string, class BooleanType = bool, - class NumberIntegerType = std::int64_t, - class NumberUnsignedType = std::uint64_t, - class NumberFloatType = double, - template class AllocatorType = std::allocator, - template class JSONSerializer = - adl_serializer, - class BinaryType = std::vector, // cppcheck-suppress syntaxError - class CustomBaseClass = void> +template