From 8c94b76b83403e3ac32d960e364a706044b90aad Mon Sep 17 00:00:00 2001 From: Dimitre Date: Sat, 24 Aug 2024 00:41:43 -0300 Subject: [PATCH] getPlatformString (#509) --- commandLine/src/defines.h | 4 +-- commandLine/src/main.cpp | 4 +-- commandLine/src/utils/Utils.cpp | 60 +++++++++++++++++++++++++++++++++ commandLine/src/utils/Utils.h | 4 +++ 4 files changed, 68 insertions(+), 4 deletions(-) diff --git a/commandLine/src/defines.h b/commandLine/src/defines.h index dd9cba31..ac1f9c0a 100644 --- a/commandLine/src/defines.h +++ b/commandLine/src/defines.h @@ -1,5 +1,5 @@ #define OFPROJECTGENERATOR_MAJOR_VERSION 0 -#define OFPROJECTGENERATOR_MINOR_VERSION 71 +#define OFPROJECTGENERATOR_MINOR_VERSION 72 #define OFPROJECTGENERATOR_PATCH_VERSION 0 -#define PG_VERSION "0.71.0" +#define PG_VERSION "0.72.0" diff --git a/commandLine/src/main.cpp b/commandLine/src/main.cpp index e5bef02a..ce69d536 100644 --- a/commandLine/src/main.cpp +++ b/commandLine/src/main.cpp @@ -413,8 +413,8 @@ int main(int argc, char ** argv) { bRecursive = false; bHelpRequested = false; bListTemplates = false; - // FIXME! problem. - targets.emplace_back(platformsToString[ofGetTargetPlatform()]); + targets.emplace_back(getPlatformString()); + startTime = 0; nProjectsUpdated = 0; nProjectsCreated = 0; diff --git a/commandLine/src/utils/Utils.cpp b/commandLine/src/utils/Utils.cpp index a86b47f1..03394d86 100644 --- a/commandLine/src/utils/Utils.cpp +++ b/commandLine/src/utils/Utils.cpp @@ -38,6 +38,66 @@ using std::unique_ptr; +std::string execute_popen(const char* cmd) { + std::array buffer; + std::string result; + +#ifdef _WIN32 + auto pipe = _popen(cmd, "r"); +#else + auto pipe = popen(cmd, "r"); +#endif + + if (!pipe) throw std::runtime_error("popen() failed!"); + + while (!feof(pipe)) { + if (fgets(buffer.data(), buffer.size(), pipe) != nullptr) + result += buffer.data(); + } + +#ifdef _WIN32 + auto rc = _pclose(pipe); +#else + auto rc = pclose(pipe); +#endif + + + if (rc == EXIT_SUCCESS) { // == 0 + + } else if (rc == EXIT_FAILURE) { // EXIT_FAILURE is not used by all programs, maybe needs some adaptation. + + } + // trim last line break + result.pop_back(); + return result; +} + +std::string getPlatformString() { +#ifdef __linux__ + string arch = execute_popen("uname -m"); + if ( + arch == "armv6l" || + arch == "armv7l" || + arch == "aarch64" + ) { + return "linux" + arch; + } + else { + return "linux64"; + } +#elif defined(__WIN32__) + #if defined(__MINGW32__) || defined(__MINGW64__) + return "msys2"; + #else + return "vs"; + #endif +#elif defined(__APPLE_CC__) + return "osx"; +#else + return {}; +#endif +} + string generateUUID(const string & input){ return uuidxx::uuid::Generate().ToString(false); } diff --git a/commandLine/src/utils/Utils.h b/commandLine/src/utils/Utils.h index 5ef50ac7..b76e875b 100644 --- a/commandLine/src/utils/Utils.h +++ b/commandLine/src/utils/Utils.h @@ -14,6 +14,10 @@ #include "baseProject.h" struct LibraryBinary; +std::string execute_popen(const char* cmd); + +std::string getPlatformString(); + namespace fs = of::filesystem; using std::string; using std::vector;