@@ -115,21 +115,42 @@ void ArgParser::addEnvVarToOptions(std::list<std::string> & optionsList, const c
115115#include < mach-o/dyld.h>
116116#endif
117117
118+ #ifndef PATH_MAX
119+ #define PATH_MAX MAX_PATH
120+ #endif
121+
118122bool ArgParser::initPlatformDir () {
119- #ifdef WIN32
120- char path[MAX_PATH] = " " ;
121- getCurrentModulePath (path, MAX_PATH);
122- #else
123- char path[PATH_MAX] = " " ;
124123 bool found = false ;
124+ char path[PATH_MAX] = " " ;
125125
126- // first try via linux /proc/self/exe
127- logMsg (" initPlatformDir: trying /proc/self/exe" );
128- found = readlink (" /proc/self/exe" , path, PATH_MAX) != -1 ;
126+ if (getenv (" JRUBY_HOME" ) != NULL ) {
127+ logMsg (" initPlatformDir: using JRUBY_HOME environment variable" );
128+ char sep[2 ] = { FILE_SEP, NULL };
129+ strncpy (path, getenv (" JRUBY_HOME" ), PATH_MAX - 11 );
130+ strncpy (path + strlen (path), sep, 1 );
131+ strncpy (path + strlen (path), " bin" , 3 );
132+ strncpy (path + strlen (path), sep, 1 );
133+ strncpy (path + strlen (path), " jruby" , 5 );
134+ found = true ;
135+ }
136+
137+ #ifdef WIN32
138+
139+ if (!found) {
140+ getCurrentModulePath (path, PATH_MAX);
141+ }
142+
143+ #else // !WIN32
144+
145+ if (!found) {
146+ // first try via linux /proc/self/exe
147+ logMsg (" initPlatformDir: trying /proc/self/exe" );
148+ found = readlink (" /proc/self/exe" , path, PATH_MAX) != -1 ;
149+ }
129150
130151#ifdef __MACH__
131152 uint32_t sz = PATH_MAX;
132- if (_NSGetExecutablePath (path, &sz) == 0 ) { // OSX-specific
153+ if (!found && _NSGetExecutablePath (path, &sz) == 0 ) { // OSX-specific
133154 logMsg (" initPlatformDir: using _NSGetExecutablePath" );
134155 string tmpPath (path);
135156 realpath (tmpPath.c_str (), path);
@@ -139,7 +160,7 @@ bool ArgParser::initPlatformDir() {
139160
140161#ifdef __SUNOS__
141162 const char * execname = getexecname ();
142- if (execname) {
163+ if (!found && execname) {
143164 logMsg (" initPlatformDir: using getexecname" );
144165 char * dst = path;
145166 if (execname[0 ] != ' /' ) {
@@ -165,6 +186,7 @@ bool ArgParser::initPlatformDir() {
165186 strncpy (path + strlen (path), platformDir.c_str (), platformDir.length ());
166187 found = true ;
167188 }
189+ #endif // WIN32
168190
169191 if (!found) { // try via PATH search
170192 logMsg (" initPlatformDir: trying to find executable on PATH" );
@@ -173,21 +195,8 @@ bool ArgParser::initPlatformDir() {
173195 found = true ;
174196 }
175197
176- if (!found) { // try via JRUBY_HOME
177- if (getenv (" JRUBY_HOME" ) != NULL ) {
178- logMsg (" initPlatformDir: trying JRUBY_HOME environment variable" );
179- strncpy (path, getenv (" JRUBY_HOME" ), PATH_MAX - 11 );
180- strncpy (path + strlen (path), " /bin/jruby" , 10 );
181- found = true ;
182- }
183- }
184-
185- if (!fileExists (path)) {
186- printToConsole (" Could not figure out a proper location for JRuby.\n "
187- " Try `jruby -Xtrace trace.log ...` and view trace.log for details." );
188- return false ;
189- }
190- #endif
198+ // Check if bin/jruby file exists; this logs a message if not found
199+ fileExists (path);
191200
192201 logMsg (" Module: %s" , path);
193202 char *bslash = strrchr (path, FILE_SEP);
0 commit comments