From 61d9e8699687342c2e32c32c8d4eb71760d5d290 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 26 Jun 2021 17:33:24 +0200 Subject: Use fork/exec instead of popen. Add Path class --- backend/BackendUtils.cpp | 51 +++++++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 24 deletions(-) (limited to 'backend/BackendUtils.cpp') diff --git a/backend/BackendUtils.cpp b/backend/BackendUtils.cpp index 158cd12..befd7ed 100644 --- a/backend/BackendUtils.cpp +++ b/backend/BackendUtils.cpp @@ -6,9 +6,9 @@ using namespace std; using namespace sibs; -static const char *cCompilerPath = nullptr; -static const char *cppCompilerPath = nullptr; -static const char *linkerPath = nullptr; +static std::vector cCompilerPath; +static std::vector cppCompilerPath; +static std::vector linkerPath; namespace backend { @@ -108,7 +108,6 @@ namespace backend #endif projectConfPath += TINYDIR_STRING("project.conf"); - auto projectConfFileType = getFileType(projectConfPath.c_str()); if(!sibsConfig.isTest() && getFileType(projectConfPath.c_str()) == FileType::REGULAR) { backend::Ninja *subProject = new backend::Ninja(); @@ -131,82 +130,82 @@ namespace backend }); } - string BackendUtils::getCompilerCExecutable(Compiler compiler) + std::vector BackendUtils::getCompilerCExecutable(Compiler compiler) { - if(cCompilerPath) + if(!cCompilerPath.empty()) return cCompilerPath; char *cc = std::getenv("CC"); if(cc) { - cCompilerPath = cc; + cCompilerPath = { toFileString(cc) }; return cCompilerPath; } switch(compiler) { case Compiler::GCC: - cCompilerPath = "ccache cc"; + cCompilerPath = { TINYDIR_STRING("ccache"), TINYDIR_STRING("cc") }; break; case Compiler::MINGW_W64: - cCompilerPath = "x86_64-w64-mingw32-cc"; + cCompilerPath = { TINYDIR_STRING("x86_64-w64-mingw32-cc") }; break; case Compiler::MSVC: - cCompilerPath = "cl.exe"; + cCompilerPath = { TINYDIR_STRING("cl.exe") }; break; } return cCompilerPath; } - string BackendUtils::getCompilerCppExecutable(Compiler compiler) + std::vector BackendUtils::getCompilerCppExecutable(Compiler compiler) { - if(cppCompilerPath) + if(!cppCompilerPath.empty()) return cppCompilerPath; char *cxx = std::getenv("CXX"); if(cxx) { - cppCompilerPath = cxx; + cppCompilerPath = { toFileString(cxx) }; return cppCompilerPath; } switch(compiler) { case Compiler::GCC: - cppCompilerPath = "ccache c++"; + cppCompilerPath = { TINYDIR_STRING("ccache"), TINYDIR_STRING("c++") }; break; case Compiler::MINGW_W64: - cppCompilerPath = "x86_64-w64-mingw32-c++"; + cppCompilerPath = { TINYDIR_STRING("x86_64-w64-mingw32-c++") }; break; case Compiler::MSVC: - cppCompilerPath = "cl.exe"; + cppCompilerPath = { TINYDIR_STRING("cl.exe") }; break; } return cppCompilerPath; } - string BackendUtils::getCompilerLinker(Compiler compiler) + std::vector BackendUtils::getCompilerLinker(Compiler compiler) { - if(linkerPath) + if(!linkerPath.empty()) return linkerPath; char *ar = std::getenv("AR"); if(ar) { - linkerPath = ar; + linkerPath = { toFileString(ar) }; return linkerPath; } switch(compiler) { case Compiler::GCC: - linkerPath = "ar"; + linkerPath = { TINYDIR_STRING("ar") }; break; case Compiler::MINGW_W64: - linkerPath = "x86_64-w64-mingw32-ar"; + linkerPath = { TINYDIR_STRING("x86_64-w64-mingw32-ar") }; break; case Compiler::MSVC: - linkerPath = "lib.exe"; + linkerPath = { TINYDIR_STRING("lib.exe") }; break; } return linkerPath; @@ -215,7 +214,9 @@ namespace backend RuntimeCompilerType BackendUtils::getCCompilerType(Compiler compiler) { RuntimeCompilerType cCompilerType = RuntimeCompilerType::NONE; - Result cCompilerVersion = exec(toFileString(getCompilerCExecutable(compiler)) + TINYDIR_STRING(" --version")); + std::vector args = getCompilerCExecutable(compiler); + args.push_back(TINYDIR_STRING("--version")); + Result cCompilerVersion = exec(args); if(cCompilerVersion && cCompilerVersion.unwrap().exitCode == 0) { if(cCompilerVersion.unwrap().execStdout.find("Emscripten") != string::npos) @@ -231,7 +232,9 @@ namespace backend RuntimeCompilerType BackendUtils::getCppCompilerType(Compiler compiler) { RuntimeCompilerType cppCompilerType = RuntimeCompilerType::NONE; - Result cppCompilerVersion = exec(toFileString(getCompilerCppExecutable(compiler)) + TINYDIR_STRING(" --version")); + std::vector args = getCompilerCppExecutable(compiler); + args.push_back(TINYDIR_STRING("--version")); + Result cppCompilerVersion = exec(args); if(cppCompilerVersion && cppCompilerVersion.unwrap().exitCode == 0) { if(cppCompilerVersion.unwrap().execStdout.find("Emscripten") != string::npos) -- cgit v1.2.3