Skip to content

Commit 0ae6b31

Browse files
committed
Add --log-process-args to log the arguments whenever a truffleruby process is created
1 parent f6e8e5e commit 0ae6b31

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

src/launcher/java/org/truffleruby/launcher/CommandLineOptions.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ public class CommandLineOptions {
4848
boolean showVersion = false;
4949
boolean showCopyright = false;
5050
ShowHelp showHelp = ShowHelp.NONE;
51+
/** All command-line arguments passed to truffleruby */
52+
final String[] initialArguments;
53+
boolean logProcessArguments = false;
5154
/** Read the RUBYOPT and TRUFFLERUBYOPT environment variables */
5255
boolean readRubyOptEnv = true;
5356
/** What should be done after context is created */
@@ -58,11 +61,13 @@ public class CommandLineOptions {
5861
String toExecute = "";
5962

6063
private final Map<String, String> options;
64+
/** Application arguments */
6165
private String[] arguments;
6266
private final List<String> unknownArguments;
6367
private Boolean gemOrBundle = null;
6468

65-
public CommandLineOptions() {
69+
public CommandLineOptions(List<String> initialArguments) {
70+
this.initialArguments = initialArguments.toArray(EMPTY_STRING_ARRAY);
6671
this.options = new HashMap<>();
6772
this.arguments = EMPTY_STRING_ARRAY;
6873
this.unknownArguments = new ArrayList<>();

src/launcher/java/org/truffleruby/launcher/CommandLineParser.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,9 @@ private void processArgument() throws CommandLineException {
425425
String feature = grabValue(getArgumentError("missing argument for " + argument), false);
426426
config.getUnknownArguments().add(argument + "=" + feature);
427427
break FOR;
428+
} else if (argument.equals("--log-process-args") || argument.equals("--log-process-args=true")) {
429+
config.logProcessArguments = true;
430+
break FOR;
428431
} else if (argument.equals("--yydebug")) {
429432
disallowedInRubyOpts(argument);
430433
warnInternalDebugTool(argument);

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ protected List<String> preprocessArguments(List<String> args, Map<String, String
7474
// TruffleRuby is never distributed without the GraalVM compiler, so this warning is not necessary
7575
polyglotOptions.put("engine.WarnInterpreterOnly", "false");
7676

77-
config = new CommandLineOptions();
77+
config = new CommandLineOptions(args);
7878

7979
try {
8080
config.executionAction = ExecutionAction.UNSET;
@@ -249,6 +249,15 @@ private int runContext(Context.Builder builder, CommandLineOptions config) {
249249
}
250250
}
251251

252+
if (config.logProcessArguments) {
253+
Value logInfo = context.eval(
254+
"ruby",
255+
// language=ruby
256+
"-> message { Truffle::Debug.log_info(message) }");
257+
String message = "new process: truffleruby " + String.join(" ", config.initialArguments);
258+
logInfo.executeVoid(message);
259+
}
260+
252261
final Source source = Source.newBuilder(
253262
TruffleRuby.LANGUAGE_ID,
254263
// language=ruby

src/main/java/org/truffleruby/debug/TruffleDebugNodes.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,12 +360,12 @@ public abstract static class LogInfoNode extends CoreMethodArrayArgumentsNode {
360360
@Specialization
361361
protected Object logInfo(Object value,
362362
@Cached ToJavaStringNode toJavaStringNode) {
363-
config(toJavaStringNode.executeToJavaString(value));
363+
info(toJavaStringNode.executeToJavaString(value));
364364
return nil;
365365
}
366366

367367
@TruffleBoundary
368-
static void config(String message) {
368+
static void info(String message) {
369369
RubyLanguage.LOGGER.info(message);
370370
}
371371

0 commit comments

Comments
 (0)