diff options
| author | Amlal <amlal.elmahrouss@icloud.com> | 2024-10-25 18:44:01 +0200 |
|---|---|---|
| committer | Amlal <amlal.elmahrouss@icloud.com> | 2024-10-25 18:44:01 +0200 |
| commit | d7dcb2695ca2c69b45314cfc261c395e935d355b (patch) | |
| tree | 32ed6a8aa938944a76eb407ecbc223a2d3a76e32 /cli/ManifestBuilder.cc | |
| parent | b2c3e134b968e75faf6db29536755f0304c63b64 (diff) | |
IMP: Add a new contract method for those who implements IManifestBuilder.
Signed-off-by: Amlal <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'cli/ManifestBuilder.cc')
| -rw-r--r-- | cli/ManifestBuilder.cc | 87 |
1 files changed, 87 insertions, 0 deletions
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 <JSONManifestBuilder.h> +#include <Includes.h> + +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 <file>\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_path>.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; +} |
