From 0ef6bae1a2d7c8ed98103e24fa831f7d9b520ab7 Mon Sep 17 00:00:00 2001 From: Amlal Date: Wed, 25 Sep 2024 17:35:06 +0200 Subject: WIP: Add initial TOML build support - Set up basic structure for handling TOML files in the build process Signed-off-by: Amlal --- cli/AppMain.cxx | 49 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 16 deletions(-) (limited to 'cli') 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 #include +#include #include #include #include @@ -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 \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\n"; std::cout << "btb: Build a TOML file: btb .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; } -- cgit v1.2.3