ruby/engine/EmbeddedHelp.hpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /*********************************************************************************************************************** | ||
| 2 | * OpenStudio(R), Copyright (c) Alliance for Energy Innovation, LLC. | ||
| 3 | * See also https://openstudio.net/license | ||
| 4 | ***********************************************************************************************************************/ | ||
| 5 | |||
| 6 | #ifndef CLI_EMBEDDEDHELP_HPP | ||
| 7 | #define CLI_EMBEDDEDHELP_HPP | ||
| 8 | |||
| 9 | #include <iostream> | ||
| 10 | #if defined __APPLE__ | ||
| 11 | # include <mach-o/dyld.h> /* _NSGetExecutablePath */ | ||
| 12 | # include <limits.h> /* PATH_MAX */ | ||
| 13 | #elif defined _WIN32 | ||
| 14 | # include <windows.h> | ||
| 15 | #endif | ||
| 16 | |||
| 17 | #ifdef SWIG | ||
| 18 | %include <ext-init.hpp> | ||
| 19 | // Ignore the parser extensions that may not be available in all Ruby builds | ||
| 20 | %ignore Init_cparse; | ||
| 21 | %ignore Init_prism; | ||
| 22 | %ignore embedded_help::init_cparse; | ||
| 23 | %ignore embedded_help::init_prism; | ||
| 24 | #else | ||
| 25 | # include <ext-init.hpp> | ||
| 26 | |||
| 27 | // Forward declarations for Ruby 3.2+ parser extensions that may not be available | ||
| 28 | // Use weak linkage to prevent linker errors on systems where these don't exist | ||
| 29 | extern "C" | ||
| 30 | { | ||
| 31 | # if defined(__GNUC__) || defined(__clang__) | ||
| 32 | extern void Init_cparse(void) __attribute__((weak)); | ||
| 33 | extern void Init_prism(void) __attribute__((weak)); | ||
| 34 | # endif | ||
| 35 | } | ||
| 36 | |||
| 37 | #endif | ||
| 38 | |||
| 39 | namespace embedded_help { | ||
| 40 | |||
| 41 | // Stub implementations for Ruby 3.2+ parser extensions that may not be available | ||
| 42 | // These are declared to provide linker symbols even if the extensions don't exist | ||
| 43 | inline void init_cparse() { | ||
| 44 | // This is a no-op - the extension may not be available in all Ruby builds | ||
| 45 | } | ||
| 46 | |||
| 47 | inline void init_prism() { | ||
| 48 | // This is a no-op - the extension may not be available in all Ruby builds | ||
| 49 | } | ||
| 50 | |||
| 51 | ✗ | inline std::string applicationFilePath() { | |
| 52 | #ifdef __APPLE__ | ||
| 53 | char path[PATH_MAX + 1]; | ||
| 54 | uint32_t size = sizeof(path); | ||
| 55 | if (_NSGetExecutablePath(path, &size) == 0) { | ||
| 56 | return {path}; | ||
| 57 | } | ||
| 58 | #elif defined _WIN32 | ||
| 59 | TCHAR szPath[MAX_PATH]; | ||
| 60 | if (!GetModuleFileName(nullptr, szPath, MAX_PATH)) { | ||
| 61 | return std::string(szPath); | ||
| 62 | } | ||
| 63 | #endif | ||
| 64 | ✗ | return {}; | |
| 65 | } | ||
| 66 | |||
| 67 | } // namespace embedded_help | ||
| 68 | |||
| 69 | #endif // CLI_EMBEDDEDHELP_HPP | ||
| 70 |