@@ -115,21 +115,42 @@ void ArgParser::addEnvVarToOptions(std::list<std::string> & optionsList, const c
115
115
#include < mach-o/dyld.h>
116
116
#endif
117
117
118
+ #ifndef PATH_MAX
119
+ #define PATH_MAX MAX_PATH
120
+ #endif
121
+
118
122
bool ArgParser::initPlatformDir () {
119
- #ifdef WIN32
120
- char path[MAX_PATH] = " " ;
121
- getCurrentModulePath (path, MAX_PATH);
122
- #else
123
- char path[PATH_MAX] = " " ;
124
123
bool found = false ;
124
+ char path[PATH_MAX] = " " ;
125
125
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
+ }
129
150
130
151
#ifdef __MACH__
131
152
uint32_t sz = PATH_MAX;
132
- if (_NSGetExecutablePath (path, &sz) == 0 ) { // OSX-specific
153
+ if (!found && _NSGetExecutablePath (path, &sz) == 0 ) { // OSX-specific
133
154
logMsg (" initPlatformDir: using _NSGetExecutablePath" );
134
155
string tmpPath (path);
135
156
realpath (tmpPath.c_str (), path);
@@ -139,7 +160,7 @@ bool ArgParser::initPlatformDir() {
139
160
140
161
#ifdef __SUNOS__
141
162
const char * execname = getexecname ();
142
- if (execname) {
163
+ if (!found && execname) {
143
164
logMsg (" initPlatformDir: using getexecname" );
144
165
char * dst = path;
145
166
if (execname[0 ] != ' /' ) {
@@ -165,6 +186,7 @@ bool ArgParser::initPlatformDir() {
165
186
strncpy (path + strlen (path), platformDir.c_str (), platformDir.length ());
166
187
found = true ;
167
188
}
189
+ #endif // WIN32
168
190
169
191
if (!found) { // try via PATH search
170
192
logMsg (" initPlatformDir: trying to find executable on PATH" );
@@ -173,21 +195,8 @@ bool ArgParser::initPlatformDir() {
173
195
found = true ;
174
196
}
175
197
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);
191
200
192
201
logMsg (" Module: %s" , path);
193
202
char *bslash = strrchr (path, FILE_SEP);
0 commit comments