summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAmlal EL Mahrouss <amlalelmahrouss@icloud.com>2024-10-08 19:07:32 +0200
committerAmlal EL Mahrouss <amlalelmahrouss@icloud.com>2024-10-08 19:07:32 +0200
commit518a6da50bfb86e938b2bbf850e3740fa824e832 (patch)
tree98612164a291377083e59c14c5d4e60776e484f7
parentc48b12c8c5513e8ec808a40da8f79bb1f1368531 (diff)
IMP: Working on TOML support for the build system.
Signed-off-by: Amlal EL Mahrouss <amlalelmahrouss@icloud.com>
-rw-r--r--build.json16
-rw-r--r--cli/AppMain.cxx34
-rw-r--r--src/TOMLManifestBuilder.cxx12
-rw-r--r--tests/example.json18
-rw-r--r--tests/example.toml1
5 files changed, 55 insertions, 26 deletions
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 <iostream>
#include <thread>
-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"]
+