Skip to content

Commit c29188b

Browse files
committed
[GR-17457] Add --log-process-args and set various CLI commands in RbConfig to avoid extra ruby -run subprocesses
PullRequest: truffleruby/2852
2 parents efb3952 + 79ba1c6 commit c29188b

File tree

6 files changed

+30
-5
lines changed

6 files changed

+30
-5
lines changed

lib/cext/ABI_version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
9
1+
10

lib/truffle/rbconfig.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ module RbConfig
5555

5656
arch = "#{host_cpu}-#{host_os}"
5757
libs = ''
58+
rmdir = Truffle::Platform.linux? ? 'rmdir --ignore-fail-on-non-empty' : 'rmdir'
5859

5960
prefix = ruby_home
6061
graalvm_home = TruffleRuby.graalvm_home
@@ -134,6 +135,7 @@ module RbConfig
134135
'configure_args' => ' ',
135136
'CC' => cc,
136137
'CCDLFLAGS' => '-fPIC',
138+
'CP' => 'cp',
137139
'CXX' => cxx,
138140
'COUTFLAG' => '-o ',
139141
'cppflags' => cppflags,
@@ -154,6 +156,7 @@ module RbConfig
154156
'host' => host,
155157
'host_os' => host_os_full,
156158
'includedir' => "#{prefix}/lib/cext", # the parent dir of rubyhdrdir
159+
'INSTALL' => '/usr/bin/install -c',
157160
'LDFLAGS' => ldflags,
158161
'libdirname' => 'libdir',
159162
'LIBEXT' => 'a',
@@ -167,6 +170,8 @@ module RbConfig
167170
'LIBRUBY_SO' => "cext/libtruffleruby.#{Truffle::Platform::SOEXT}",
168171
'LIBS' => libs,
169172
'libtruffleruby' => libtruffleruby,
173+
'MAKEDIRS' => 'mkdir -p',
174+
'MKDIR_P' => 'mkdir -p',
170175
'NULLCMD' => ':',
171176
'OBJEXT' => 'o',
172177
'optflags' => optflags,
@@ -175,6 +180,9 @@ module RbConfig
175180
'prefix' => prefix,
176181
'RANLIB' => ranlib,
177182
'RM' => 'rm -f',
183+
'RMALL' => 'rm -fr',
184+
'RMDIR' => rmdir,
185+
'RMDIRS' => "#{rmdir} -p",
178186
'RPATHFLAG' => ' -Wl,-rpath,%1$-s',
179187
'RUBY_BASE_NAME' => ruby_base_name,
180188
'ruby_install_name' => ruby_install_name,

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)