Skip to content

Commit 1f80340

Browse files
committed
[GR-51385] Avoid multiple Context#eval when possible in launcher as a workaround for chromeinspector tests
PullRequest: truffleruby/4119
2 parents 2512cc9 + 33b95f4 commit 1f80340

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/launcher/java/org/truffleruby/launcher/RubyLauncher.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -331,13 +331,6 @@ private int runContext(Context.Builder builder, CommandLineOptions config) {
331331
try (Context context = builder.build()) {
332332
Metrics.printTime("before-run");
333333

334-
Value rubyHome = context.eval(source(
335-
// language=ruby
336-
"Truffle::Boot.ruby_home"));
337-
if (rubyHome.isString()) {
338-
this.rubyHome = rubyHome.asString();
339-
}
340-
341334
if (config.executionAction == ExecutionAction.PATH) {
342335
final Source source = source(// language=ruby
343336
"-> name { Truffle::Boot.find_s_file(name) }");
@@ -349,7 +342,7 @@ private int runContext(Context.Builder builder, CommandLineOptions config) {
349342
} else {
350343
getError()
351344
.println("truffleruby: No such file or directory -- " + config.toExecute + " (LoadError)");
352-
return 1;
345+
return ProcessStatus.exitCode(1);
353346
}
354347
}
355348

@@ -368,13 +361,24 @@ private int runContext(Context.Builder builder, CommandLineOptions config) {
368361
final long argv = getNativeArgv();
369362
final String kind = config.executionAction.name();
370363
final int processStatus = context.eval(source).execute(argc, argv, kind, config.toExecute).asInt();
364+
365+
if (ProcessStatus.isSignal(processStatus)) {
366+
// Only fetch the ruby home when necessary, because chromeinspector tests
367+
// currently only work with a single Context#eval.
368+
Value rubyHome = context.eval(source(// language=ruby
369+
"Truffle::Boot.ruby_home"));
370+
if (rubyHome.isString()) {
371+
this.rubyHome = rubyHome.asString();
372+
}
373+
}
374+
371375
Metrics.printTime("after-run");
372376
return processStatus;
373377
} catch (PolyglotException e) {
374378
getError().println(
375379
"truffleruby: an exception escaped out of the interpreter - this is an implementation bug");
376380
e.printStackTrace(System.err);
377-
return 1;
381+
return ProcessStatus.exitCode(1);
378382
}
379383
}
380384

0 commit comments

Comments
 (0)