diff options
| author | Amlal <amlal@zka.com> | 2024-09-25 17:35:06 +0200 |
|---|---|---|
| committer | Amlal <amlal@zka.com> | 2024-09-25 17:35:06 +0200 |
| commit | 0ef6bae1a2d7c8ed98103e24fa831f7d9b520ab7 (patch) | |
| tree | d1aff537b31cde0dc7d041893502c7e13ff2c32f | |
| parent | d70fc2f8547b3b5af352ee1d5dab2f5122215215 (diff) | |
WIP: Add initial TOML build support
- Set up basic structure for handling TOML files in the build process
Signed-off-by: Amlal <amlal@zka.com>
| -rw-r--r-- | cli/AppMain.cxx | 49 | ||||
| -rw-r--r-- | inc/IManifestBuilder.hxx | 7 | ||||
| -rw-r--r-- | inc/JSONManifestBuilder.hxx | 5 | ||||
| -rw-r--r-- | inc/Macros.hxx | 5 | ||||
| -rw-r--r-- | inc/TOMLManifestBuilder.hxx | 27 | ||||
| -rw-r--r-- | inc/toml.hxx (renamed from inc/toml.hpp) | 0 | ||||
| -rw-r--r-- | src/IManifestBuilder.cxx | 5 | ||||
| -rw-r--r-- | src/JSONManifestBuilder.cxx | 24 | ||||
| -rw-r--r-- | src/TOMLManifestBuilder.cxx | 19 |
9 files changed, 109 insertions, 32 deletions
diff --git a/cli/AppMain.cxx b/cli/AppMain.cxx index 66c7ade..3eee3d4 100644 --- a/cli/AppMain.cxx +++ b/cli/AppMain.cxx @@ -1,5 +1,6 @@ #include <Macros.hxx> #include <JSONManifestBuilder.hxx> +#include <TOMLManifestBuilder.hxx> #include <cstdio> #include <cstddef> #include <string> @@ -9,19 +10,18 @@ int cJobIndex = 0; bool cFailed = false; -static IManifestBuilder* cBuilder = new JSONManifestBuilder(); +static IManifestBuilder* cBuilder = nullptr; int main(int argc, char** argv) { - LIKELY(cBuilder == nullptr); cJobIndex = argc - 1; for (size_t index = 1; index < argc; ++index) { - std::string index_json = argv[index]; + std::string index_path = argv[index]; - if (index_json == "/Ver" || - index_json == "/Version") + if (index_path == "/Ver" || + index_path == "/Version") { std::cout << "Usage: btb <file>\n"; std::cout << "Check for issues at: www.el-mahrouss-logic.com/btb/issues\n"; @@ -31,8 +31,8 @@ int main(int argc, char** argv) return 0; } - else if (index_json == "/?" || - index_json == "/Help") + else if (index_path == "/?" || + 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"; @@ -40,20 +40,33 @@ int main(int argc, char** argv) return 0; } - std::thread job([](std::string index_json) -> void { - std::cout << "btb: Building " << index_json << std::endl; + std::thread job([](std::string index_path) -> void { + if (index_path.ends_with(".json")) + { + delete cBuilder; + cBuilder = nullptr; - if (!cBuilder->Build(index_json.size(), index_json.c_str())) + if (!cBuilder) + cBuilder = new JSONManifestBuilder(); + } + else if (index_path.ends_with(".toml")) { - std::string format = "btb "; - format += index_json; + delete cBuilder; + cBuilder = nullptr; + + if (!cBuilder) + cBuilder = new TOMLManifestBuilder(); + } + std::cout << "btb: Building: " << index_path << std::endl; + + if (!cBuilder->Build(index_path.size(), index_path.c_str())) + { cFailed = true; } --cJobIndex; - }, - index_json); + }, index_path); job.detach(); } @@ -61,10 +74,14 @@ int main(int argc, char** argv) // wait for completion of all jobs. while (cJobIndex) { - BTB_UNUSED(0); + if (cFailed) + { + std::cout << "btb: Build failed." << std::endl; + return EXIT_FAILURE; + } } delete cBuilder; - return cFailed ? 1 : 0; + return cFailed ? EXIT_FAILURE : EXIT_SUCCESS; } diff --git a/inc/IManifestBuilder.hxx b/inc/IManifestBuilder.hxx index 404f8b2..71f5bf0 100644 --- a/inc/IManifestBuilder.hxx +++ b/inc/IManifestBuilder.hxx @@ -1,6 +1,11 @@ +// ============================================================= // +// btb +// Copyright ZKA Technologies. +// ============================================================= // + #pragma once -/// @brief Builder interface +/// @brief Builder interface class class IManifestBuilder { public: diff --git a/inc/JSONManifestBuilder.hxx b/inc/JSONManifestBuilder.hxx index 5e29a96..8259542 100644 --- a/inc/JSONManifestBuilder.hxx +++ b/inc/JSONManifestBuilder.hxx @@ -1,3 +1,8 @@ +// ============================================================= // +// btb +// Copyright ZKA Technologies. +// ============================================================= // + #pragma once #include <IManifestBuilder.hxx> diff --git a/inc/Macros.hxx b/inc/Macros.hxx index 433aef4..10f6e81 100644 --- a/inc/Macros.hxx +++ b/inc/Macros.hxx @@ -1,3 +1,8 @@ +// ============================================================= // +// btb +// Copyright ZKA Technologies. +// ============================================================= // + #pragma once #include <cassert> diff --git a/inc/TOMLManifestBuilder.hxx b/inc/TOMLManifestBuilder.hxx index e69de29..11406ce 100644 --- a/inc/TOMLManifestBuilder.hxx +++ b/inc/TOMLManifestBuilder.hxx @@ -0,0 +1,27 @@ +// ============================================================= // +// btb +// Copyright ZKA Technologies. +// ============================================================= // + +#pragma once + +#include <IManifestBuilder.hxx> + +/// @brief TOML builder +class TOMLManifestBuilder final : public IManifestBuilder +{ +public: + explicit TOMLManifestBuilder() = default; + virtual ~TOMLManifestBuilder() override = default; + + TOMLManifestBuilder& operator=(const TOMLManifestBuilder&) = default; + TOMLManifestBuilder(const TOMLManifestBuilder&) = default; + +public: + /// @brief Builds a TOML 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; +}; diff --git a/inc/toml.hpp b/inc/toml.hxx index 1bb9d66..1bb9d66 100644 --- a/inc/toml.hpp +++ b/inc/toml.hxx diff --git a/src/IManifestBuilder.cxx b/src/IManifestBuilder.cxx index c1dbe51..7a2f210 100644 --- a/src/IManifestBuilder.cxx +++ b/src/IManifestBuilder.cxx @@ -1 +1,6 @@ +// ============================================================= // +// btb +// Copyright ZKA Technologies. +// ============================================================= // + #include <IManifestBuilder.hxx> diff --git a/src/JSONManifestBuilder.cxx b/src/JSONManifestBuilder.cxx index d456bb7..b9e186d 100644 --- a/src/JSONManifestBuilder.cxx +++ b/src/JSONManifestBuilder.cxx @@ -1,22 +1,16 @@ -// -// main.cpp +// ============================================================= // // btb -// -// Created by Amlal on 6/20/24. -// +// Copyright ZKA Technologies. +// ============================================================= // #include <JSONManifestBuilder.hxx> - #include <json.hxx> - #include <cstdlib> #include <cstdio> - #include <iostream> #include <fstream> -#include <sstream> -using json = nlohmann::json; +using JSON = nlohmann::json; /// @brief Builds a JSON target. /// @param arg_sz filename size @@ -45,12 +39,12 @@ bool JSONManifestBuilder::Build(int arg_sz, const char* arg_val) return false; } - json buildme = json::parse(json_obj); + JSON buildme = JSON::parse(json_obj); std::string compiler = buildme["compiler_path"].get<std::string>(); - json headerSearchPath = buildme["headers_path"]; - json sourceFiles = buildme["sources_path"]; + JSON headerSearchPath = buildme["headers_path"]; + JSON sourceFiles = buildme["sources_path"]; std::string cmdLine = compiler + " "; @@ -64,14 +58,14 @@ bool JSONManifestBuilder::Build(int arg_sz, const char* arg_val) cmdLine += "-I" + headers.get<std::string>() + " "; } - json macrosList = buildme["cpp_macros"]; + JSON macrosList = buildme["cpp_macros"]; for (auto& macro : macrosList) { cmdLine += "-D" + macro.get<std::string>() + " "; } - json compilerFlags = buildme["compiler_flags"]; + JSON compilerFlags = buildme["compiler_flags"]; for (auto& flag : compilerFlags) { diff --git a/src/TOMLManifestBuilder.cxx b/src/TOMLManifestBuilder.cxx index e69de29..724db52 100644 --- a/src/TOMLManifestBuilder.cxx +++ b/src/TOMLManifestBuilder.cxx @@ -0,0 +1,19 @@ +// ============================================================= // +// btb +// Copyright ZKA Technologies. +// ============================================================= // + +#include <TOMLManifestBuilder.hxx> +#include <toml.hxx> +#include <iostream> + +/// @brief Builds a TOML target. +/// @param arg_sz filename size +/// @param arg_val filename path. +/// @retval true succeeded. +/// @retval false failed. +bool TOMLManifestBuilder::Build(int arg_sz, const char* arg_val) +{ + + return false; +} |
