From 518a6da50bfb86e938b2bbf850e3740fa824e832 Mon Sep 17 00:00:00 2001 From: Amlal EL Mahrouss Date: Tue, 8 Oct 2024 19:07:32 +0200 Subject: IMP: Working on TOML support for the build system. Signed-off-by: Amlal EL Mahrouss --- build.json | 16 ++++++++++++++++ cli/AppMain.cxx | 34 +++++++++++++--------------------- src/TOMLManifestBuilder.cxx | 12 ++++++++++++ tests/example.json | 18 +++++++++++++----- tests/example.toml | 1 + 5 files changed, 55 insertions(+), 26 deletions(-) create mode 100644 build.json diff --git a/build.json b/build.json new file mode 100644 index 0000000..532125f --- /dev/null +++ b/build.json @@ -0,0 +1,16 @@ +{ + "compiler_path": "g++", + "compiler_std": "c++20", + "headers_path": [ + "inc" + ], + "sources_path": [ + "src/*.cxx", + "cli/*.cxx" + ], + "output_name": "btb", + "compiler_flags": [ + "-fPIC" + ], + "run_after_build": false +} \ No newline at end of file diff --git a/cli/AppMain.cxx b/cli/AppMain.cxx index 975ada5..0546aab 100644 --- a/cli/AppMain.cxx +++ b/cli/AppMain.cxx @@ -7,10 +7,8 @@ #include #include -int cJobIndex = 0; -bool cFailed = false; - -static IManifestBuilder* cBuilder = nullptr; +static int cJobIndex = 0; +static bool cFailed = false; int main(int argc, char** argv) { @@ -40,22 +38,16 @@ int main(int argc, char** argv) return 0; } - std::thread job([](std::string index_path) -> void { + std::thread job_build_thread([](std::string index_path) -> void { + IManifestBuilder* builder = nullptr; + if (index_path.ends_with(".json")) { - delete cBuilder; - cBuilder = nullptr; - - if (!cBuilder) - cBuilder = new JSONManifestBuilder(); + builder = new JSONManifestBuilder(); } else if (index_path.ends_with(".toml")) { - delete cBuilder; - cBuilder = nullptr; - - if (!cBuilder) - cBuilder = new TOMLManifestBuilder(); + builder = new TOMLManifestBuilder(); } else { @@ -65,16 +57,18 @@ int main(int argc, char** argv) std::cout << "btb: Building: " << index_path << std::endl; - if (!cBuilder->Build(index_path.size(), index_path.c_str())) + if (builder && !builder->Build(index_path.size(), index_path.c_str())) { cFailed = true; } + delete builder; + --cJobIndex; }, - index_path); + index_path); - job.detach(); + job_build_thread.detach(); } // wait for completion of all jobs. @@ -82,12 +76,10 @@ int main(int argc, char** argv) { if (cFailed) { - std::cout << "btb: Build failed." << std::endl; + std::cout << "btb: build failed: " << errno << "." << std::endl; return EXIT_FAILURE; } } - delete cBuilder; - return cFailed ? EXIT_FAILURE : EXIT_SUCCESS; } diff --git a/src/TOMLManifestBuilder.cxx b/src/TOMLManifestBuilder.cxx index 724db52..51b29d1 100644 --- a/src/TOMLManifestBuilder.cxx +++ b/src/TOMLManifestBuilder.cxx @@ -14,6 +14,18 @@ /// @retval false failed. bool TOMLManifestBuilder::Build(int arg_sz, const char* arg_val) { + toml::table tbl; + + try + { + tbl = toml::parse_file(arg_val); + std::cout << tbl << "\n"; + } + catch (const toml::parse_error& err) + { + std::cerr << "btb: error:" << err << "\n"; + return false; + } return false; } diff --git a/tests/example.json b/tests/example.json index 32b21dc..805e5c1 100644 --- a/tests/example.json +++ b/tests/example.json @@ -1,10 +1,18 @@ { "compiler_path": "g++", "compiler_std": "c++20", - "headers_path": ["inc"], - "sources_path": ["example.cxx"], + "headers_path": [ + "inc" + ], + "sources_path": [ + "example.cxx" + ], "output_name": "example.elf", - "compiler_flags": ["-fPIC"], - "cpp_macros": ["FOO_MACRO"], + "compiler_flags": [ + "-fPIC" + ], + "cpp_macros": [ + "FOO_MACRO" + ], "run_after_build": true -} +} \ No newline at end of file diff --git a/tests/example.toml b/tests/example.toml index bc7e047..64e38d2 100644 --- a/tests/example.toml +++ b/tests/example.toml @@ -2,3 +2,4 @@ output_name = "example.elf" [Sources] source_file = ["*.cxx"] + -- cgit v1.2.3