Skip to content

Commit 31c5fa8

Browse files
committed
Options
PullRequest: truffleruby/637
2 parents fd86e60 + 81a2bac commit 31c5fa8

File tree

8 files changed

+140
-13
lines changed

8 files changed

+140
-13
lines changed

doc/user/compatibility.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,16 @@ so, but this isn't always the case. For example `RubyVM` is not available.
113113

114114
#### Command line switches
115115

116-
`-y`, `--yydebug`, `--dump=` are ignored with a warning as they are internal
117-
development tools.
116+
`-y`, `--yydebug`, `--dump=`, `--debug-frozen-string-literal` are ignored with
117+
a warning as they are unsupported development tools.
118118

119119
Programs passed in `-e` arguments with magic-comments must have an encoding that
120120
is UTF-8 or a subset of UTF-8, as the JVM has already decoded arguments by the
121121
time we get them.
122122

123+
`--jit` options and the `jit` feature are not supported because TruffleRuby
124+
uses Graal as a JIT.
125+
123126
#### Setting the process title doesn't always work
124127

125128
Setting the process title (via `$0` or `Process.setproctitle` in Ruby) is done

doc/user/options.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,11 @@ MRI has some extra Ruby switches which are aren't normally listed in help output
5151
but are documented in the Ruby manual page.
5252

5353
```
54+
-Xdirectory cd to directory before executing your script (same as -C)
5455
-U set the internal encoding to UTF-8
55-
-KEeSsUuNnAa sets the source and external encoding
56+
-K[EeSsUuNnAa] sets the source and external encoding
5657
--encoding=external[:internal]
5758
the same as --external-encoding=external and optionally --internal-encoding=internal
58-
-y, --ydebug debug the parser
59-
-Xdirectory the same as -Cdirectory
60-
--dump=insns print disassembled instructions
6159
```
6260

6361
## TruffleRuby options
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
require_relative '../spec_helper'
2+
3+
describe "The --enable and --disable flags" do
4+
5+
it "can be used with gems" do
6+
ruby_exe("p defined?(Gem)", options: "--enable=gems").chomp.should == "\"constant\""
7+
ruby_exe("p defined?(Gem)", options: "--disable=gems").chomp.should == "nil"
8+
ruby_exe("p defined?(Gem)", options: "--enable-gems").chomp.should == "\"constant\""
9+
ruby_exe("p defined?(Gem)", options: "--disable-gems").chomp.should == "nil"
10+
end
11+
12+
it "can be used with gem" do
13+
ruby_exe("p defined?(Gem)", options: "--enable=gem").chomp.should == "\"constant\""
14+
ruby_exe("p defined?(Gem)", options: "--disable=gem").chomp.should == "nil"
15+
ruby_exe("p defined?(Gem)", options: "--enable-gem").chomp.should == "\"constant\""
16+
ruby_exe("p defined?(Gem)", options: "--disable-gem").chomp.should == "nil"
17+
end
18+
19+
it "can be used with did_you_mean" do
20+
ruby_exe("p defined?(DidYouMean)", options: "--enable=did_you_mean").chomp.should == "\"constant\""
21+
ruby_exe("p defined?(DidYouMean)", options: "--disable=did_you_mean").chomp.should == "nil"
22+
ruby_exe("p defined?(DidYouMean)", options: "--enable-did_you_mean").chomp.should == "\"constant\""
23+
ruby_exe("p defined?(DidYouMean)", options: "--disable-did_you_mean").chomp.should == "nil"
24+
end
25+
26+
it "can be used with rubyopt" do
27+
ruby_exe("p $VERBOSE", options: "--enable=rubyopt", env: {'RUBYOPT' => '-w'}).chomp.should == "true"
28+
ruby_exe("p $VERBOSE", options: "--disable=rubyopt", env: {'RUBYOPT' => '-w'}).chomp.should == "false"
29+
ruby_exe("p $VERBOSE", options: "--enable-rubyopt", env: {'RUBYOPT' => '-w'}).chomp.should == "true"
30+
ruby_exe("p $VERBOSE", options: "--disable-rubyopt", env: {'RUBYOPT' => '-w'}).chomp.should == "false"
31+
end
32+
33+
it "can be used with frozen-string-literal" do
34+
ruby_exe("p 'foo'.frozen?", options: "--enable=frozen-string-literal").chomp.should == "true"
35+
ruby_exe("p 'foo'.frozen?", options: "--disable=frozen-string-literal").chomp.should == "false"
36+
ruby_exe("p 'foo'.frozen?", options: "--enable-frozen-string-literal").chomp.should == "true"
37+
ruby_exe("p 'foo'.frozen?", options: "--disable-frozen-string-literal").chomp.should == "false"
38+
end
39+
40+
ruby_version_is "2.6" do
41+
it "can be used with jit" do
42+
ruby_exe("p RubyVM::MJIT.enabled?", options: "--enable=jit").chomp.should == "true"
43+
ruby_exe("p RubyVM::MJIT.enabled?", options: "--disable=jit").chomp.should == "false"
44+
ruby_exe("p RubyVM::MJIT.enabled?", options: "--enable-jit").chomp.should == "true"
45+
ruby_exe("p RubyVM::MJIT.enabled?", options: "--disable-jit").chomp.should == "false"
46+
end
47+
end
48+
49+
it "can be used with all" do
50+
e = "p [defined?(Gem), defined?(DidYouMean), $VERBOSE, 'foo'.frozen?]"
51+
env = {'RUBYOPT' => '-w'}
52+
ruby_exe(e, options: "--enable=all", env: env).chomp.should == "[\"constant\", \"constant\", true, true]"
53+
ruby_exe(e, options: "--enable-all", env: env).chomp.should == "[\"constant\", \"constant\", true, true]"
54+
ruby_exe(e, options: "--disable=all", env: env).chomp.should == "[nil, nil, false, false]"
55+
ruby_exe(e, options: "--disable-all", env: env).chomp.should == "[nil, nil, false, false]"
56+
end
57+
58+
it "prints a warning for unknown features" do
59+
ruby_exe("p 14", options: "--enable=ruby-spec-feature-does-not-exist 2>&1").chomp.should include('warning: unknown argument for --enable')
60+
ruby_exe("p 14", options: "--disable=ruby-spec-feature-does-not-exist 2>&1").chomp.should include('warning: unknown argument for --disable')
61+
ruby_exe("p 14", options: "--enable-ruby-spec-feature-does-not-exist 2>&1").chomp.should include('warning: unknown argument for --enable')
62+
ruby_exe("p 14", options: "--disable-ruby-spec-feature-does-not-exist 2>&1").chomp.should include('warning: unknown argument for --disable')
63+
end
64+
65+
end
66+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
fails:The --enable and --disable flags can be used with jit
2+
slow:The --enable and --disable flags can be used with gems
3+
slow:The --enable and --disable flags can be used with gem
4+
slow:The --enable and --disable flags can be used with did_you_mean
5+
slow:The --enable and --disable flags can be used with rubyopt
6+
slow:The --enable and --disable flags can be used with frozen-string-literal
7+
slow:The --enable and --disable flags prints a warning for unknown features
8+
slow:The --enable and --disable flags can be used with all

spec/tags/truffle/launcher_tags.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,7 @@ slow:The launcher sets the log level using --log.ruby.level=
5959
fails(GR-13956):The launcher prints help containing runtime options
6060
slow:The launcher logs options if --options.log is set
6161
slow:The launcher sets the log level using --log.level=
62+
slow:The launcher ignores --jit option with a warning
63+
slow:The launcher ignores --jit-... options with a warning and a hint to look at Graal options
64+
slow:The launcher ignores --jit... options with a warning and a hint to look at Graal documentation
65+
slow:The launcher warns on ignored options

spec/truffle/launcher_spec.rb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,4 +300,37 @@ def should_print_full_java_command(options, env: {})
300300
out.should include("[truffle] opt done")
301301
end
302302
end
303+
304+
it "ignores --jit... options with a warning and a hint to look at Graal documentation" do
305+
[
306+
"--jit",
307+
"--jit-warnings",
308+
"--jit-debug",
309+
"--jit-wait",
310+
"--jit-save-temps",
311+
"--jit-verbose",
312+
"--jit-max-cache",
313+
"--jit-min-calls",
314+
].each do |option|
315+
out = ruby_exe("p 14", options: option, args: "2>&1")
316+
$?.success?.should == true
317+
out.should include("JIT options are not supported - see the Graal documentation instead")
318+
out.should include("14")
319+
end
320+
end
321+
322+
it "warns on ignored options" do
323+
[
324+
"-y",
325+
"--yydebug",
326+
"--debug-frozen-string-literal",
327+
"--dump=insns",
328+
].each do |option|
329+
out = ruby_exe("p 14", options: option, args: "2>&1")
330+
$?.success?.should == true
331+
out.should include("[ruby] WARNING the #{option} switch is silently ignored as it is an internal development tool")
332+
out.should include("14")
333+
end
334+
end
335+
303336
end

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,18 @@ protected void collectArguments(Set<String> options) {
161161
"--copyright",
162162
"--enable", "--disable",
163163
"--external-encoding", "--internal-encoding",
164+
"--yydebug",
165+
"--debug-frozen-string-literal",
164166
"--version",
165167
"--help",
166-
"-Xoptions"));
168+
"--jit",
169+
"--jit-warnings",
170+
"--jit-debug",
171+
"--jit-wait",
172+
"--jit-save-temps",
173+
"--jit-verbose",
174+
"--jit-max-cache",
175+
"--jit-min-calls"));
167176
}
168177

169178
@Override

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ private void processArgument() throws CommandLineException {
255255
break FOR;
256256
case 'y':
257257
disallowedInRubyOpts(argument);
258-
LOGGER.warning("the -y switch is silently ignored as it is an internal development tool");
258+
warnInternalDebugTool(argument);
259259
break FOR;
260260
case 'K':
261261
characterIndex++;
@@ -420,7 +420,7 @@ private void processArgument() throws CommandLineException {
420420
throw notImplemented("--debug");
421421
} else if (argument.equals("--yydebug")) {
422422
disallowedInRubyOpts(argument);
423-
LOGGER.warning("the --yydebug switch is silently ignored as it is an internal development tool");
423+
warnInternalDebugTool(argument);
424424
break FOR;
425425
} else if (rubyOpts && argument.equals("--help")) {
426426
disallowedInRubyOpts(argument);
@@ -434,7 +434,8 @@ private void processArgument() throws CommandLineException {
434434
} else if (argument.startsWith("--profile")) {
435435
throw notImplemented("--profile");
436436
} else if (argument.equals("--debug-frozen-string-literal")) {
437-
throw notImplemented("--debug-frozen-string-literal");
437+
warnInternalDebugTool(argument);
438+
break FOR;
438439
} else if (argument.startsWith("--disable")) {
439440
final int len = argument.length();
440441
if (len == "--disable".length()) {
@@ -457,13 +458,14 @@ private void processArgument() throws CommandLineException {
457458
enableDisableFeature(enable, true);
458459
}
459460
break FOR;
460-
} else if (argument.equals("--gemfile")) {
461-
throw notImplemented("--gemfile");
462461
} else if (argument.equals("--verbose")) {
463462
config.setOption(OptionsCatalog.VERBOSITY, Verbosity.TRUE);
464463
break FOR;
465464
} else if (argument.startsWith("--dump=")) {
466-
LOGGER.warning("the --dump= switch is silently ignored as it is an internal development tool");
465+
warnInternalDebugTool(argument);
466+
break FOR;
467+
} else if (argument.equals("--jit") || argument.startsWith("--jit-")) {
468+
LOGGER.warning("JIT options are not supported - see the Graal documentation instead");
467469
break FOR;
468470
} else {
469471
if (argument.equals("--")) {
@@ -509,6 +511,10 @@ private void disallowedInRubyOpts(CharSequence option) throws CommandLineExcepti
509511
}
510512
}
511513

514+
private void warnInternalDebugTool(String option) {
515+
LOGGER.warning("the " + option + " switch is silently ignored as it is an internal development tool");
516+
}
517+
512518
private static void errorMissingEquals(String label) throws CommandLineException {
513519
throw new CommandLineException("missing argument for --" + label + "\n", true);
514520
}

0 commit comments

Comments
 (0)