From 26813ffe1f94b9915ba0ef2e1b57731c37cc7a1f Mon Sep 17 00:00:00 2001 From: Amlal Date: Sat, 13 Jul 2024 22:38:38 +0200 Subject: [IMP] btb and new revision of zpt-core library. Signed-off-by: Amlal --- src/compile_flags.txt | 2 + src/manifest_builder.cxx | 101 ++++++++++++++++++++++++++--------------------- 2 files changed, 59 insertions(+), 44 deletions(-) create mode 100644 src/compile_flags.txt (limited to 'src') diff --git a/src/compile_flags.txt b/src/compile_flags.txt new file mode 100644 index 0000000..f6d73f3 --- /dev/null +++ b/src/compile_flags.txt @@ -0,0 +1,2 @@ +-std=c++20 +-I../inc diff --git a/src/manifest_builder.cxx b/src/manifest_builder.cxx index ec60028..a18dc72 100644 --- a/src/manifest_builder.cxx +++ b/src/manifest_builder.cxx @@ -5,67 +5,80 @@ // Created by Amlal on 6/20/24. // -#include +#include +#include +#include #include #include - #include -#include - using json = nlohmann::json; -int ManifestBuilder::buildJson(int argc, const char * argv[]) +bool ManifestBuilder::buildJson(int arg_sz, const char* arg_val) { - std::cout << "buildme: "; - std::string path; + std::cout << "buildme: "; + std::string path; + + if (arg_sz < 0) + { + std::cout << "no files provided.\n"; + return false; + } + else + { + path = arg_val; + } + + try + { + std::ifstream json_obj(path); + + if (!json_obj.good()) + { + std::cout << "buildme: no files provided.\n"; + perror("buildme"); + + return false; + } + + json buildme = json::parse(json_obj); - if (argc == 1) - { - std::cout << "no files, defaulting to build.json\n"; - path = "./build.json"; - } - else - { - path = argv[1]; - } + std::string compiler = buildme["compiler_path"].get(); + std::cout << "choose toolchain: " << compiler << std::endl; - try - { - std::ifstream fJson(path); - json buildme = json::parse(fJson); + json headerSearchPath = buildme["headers_path"]; + std::cout << "buildme: search path: " << headerSearchPath.dump() << std::endl; - std::string compiler = buildme["compiler_path"].get(); - std::cout << "choose toolchain: " << compiler << std::endl; + json sourceFiles = buildme["sources_path"]; + std::cout << "buildme: source files: " << sourceFiles.dump() << std::endl; - json headerSearchPath = buildme["headers_path"]; - std::cout << "search path: " << headerSearchPath.dump() << std::endl; + std::string cmdLine = compiler + " "; - json sourceFiles = buildme["sources_path"]; - std::cout << "source files: " << sourceFiles.dump() << std::endl; + for (auto& sources : sourceFiles) + { + cmdLine += sources.get() + " "; + } - std::string cmdLine = compiler + " "; + for (auto& headers : headerSearchPath) + { + cmdLine += "-include=" + headers.get() + " "; + } - for (auto sources : sourceFiles) - { - cmdLine += sources.get() + " "; - } + cmdLine += "-std=" + buildme["compiler_std"].get() + " "; - for (auto sources : sourceFiles) - { - cmdLine += "-include=" + sources.get() + " "; - } + cmdLine += "-o " + buildme["output_name"].get(); - cmdLine += "-std=" + buildme["compiler_std"].get() + " "; + std::cout << "buildme: running: '" << cmdLine << "'" << std::endl; - std::cout << "running: " << cmdLine << std::endl; + std::system(cmdLine.c_str()); + } + catch (std::runtime_error& err) + { + perror("buildme"); + std::cout << "buildme: error: " << err.what() << std::endl; - std::system(cmdLine.c_str()); - } - catch (...) - { - return 1; - } + return false; + } - return 0; + return true; } -- cgit v1.2.3