diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/compile_flags.txt | 2 | ||||
| -rw-r--r-- | src/manifest_builder.cxx | 101 |
2 files changed, 59 insertions, 44 deletions
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 <sstream> +#include <cstdio> +#include <json.hxx> +#include <cstdlib> #include <iostream> #include <fstream> - #include <manifest_builder.hxx> -#include <json.hxx> - 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::string>(); + 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::string>(); - 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>() + " "; + } - std::string cmdLine = compiler + " "; + for (auto& headers : headerSearchPath) + { + cmdLine += "-include=" + headers.get<std::string>() + " "; + } - for (auto sources : sourceFiles) - { - cmdLine += sources.get<std::string>() + " "; - } + cmdLine += "-std=" + buildme["compiler_std"].get<std::string>() + " "; - for (auto sources : sourceFiles) - { - cmdLine += "-include=" + sources.get<std::string>() + " "; - } + cmdLine += "-o " + buildme["output_name"].get<std::string>(); - cmdLine += "-std=" + buildme["compiler_std"].get<std::string>() + " "; + 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; } |
