Skip to content

Commit c71f9a3

Browse files
committed
General work option compatibility
1 parent 1fde8ec commit c71f9a3

File tree

6 files changed

+65
-11
lines changed

6 files changed

+65
-11
lines changed

doc/user/compatibility.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ 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 internal 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

doc/user/options.md

Lines changed: 1 addition & 3 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
5556
-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: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
end
9+
10+
it "can be used with gem" do
11+
ruby_exe("p defined?(Gem)", options: "--enable=gem").chomp.should == "\"constant\""
12+
ruby_exe("p defined?(Gem)", options: "--disable=gem").chomp.should == "nil"
13+
end
14+
15+
it "can be used with did_you_mean" do
16+
ruby_exe("p defined?(DidYouMean)", options: "--enable=did_you_mean").chomp.should == "\"constant\""
17+
ruby_exe("p defined?(DidYouMean)", options: "--disable=did_you_mean").chomp.should == "nil"
18+
end
19+
20+
it "can be used with rubyopt" do
21+
ruby_exe("p $VERBOSE", options: "--enable=rubyopt", env: {'RUBYOPT' => '-w'}).chomp.should == "true"
22+
ruby_exe("p $VERBOSE", options: "--disable=rubyopt", env: {'RUBYOPT' => '-w'}).chomp.should == "false"
23+
end
24+
25+
it "can be used with frozen-string-literal" do
26+
ruby_exe("p 'foo'.frozen?", options: "--enable=frozen-string-literal").chomp.should == "true"
27+
ruby_exe("p 'foo'.frozen?", options: "--disable=frozen-string-literal").chomp.should == "false"
28+
end
29+
30+
ruby_version_is "2.6" do
31+
it "can be used with jit" do
32+
ruby_exe("p RubyVM::MJIT.enabled?", options: "--enable=jit").chomp.should == "true"
33+
ruby_exe("p RubyVM::MJIT.enabled?", options: "--disable=jit").chomp.should == "false"
34+
end
35+
end
36+
37+
it "prints a warning for unknown features" do
38+
ruby_exe("p 14", options: "--enable=ruby-spec-feature-does-not-exist 2>&1").chomp.should include('warning: unknown argument for --enable')
39+
ruby_exe("p 14", options: "--disable=ruby-spec-feature-does-not-exist 2>&1").chomp.should include('warning: unknown argument for --disable')
40+
end
41+
42+
end
43+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
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

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ 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",
166168
"--jit",

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

Lines changed: 10 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,12 @@ 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;
467467
} else if (argument.equals("--jit") || argument.startsWith("--jit-")) {
468468
LOGGER.warning("JIT options are not supported - see the Graal documentation instead");
469469
break FOR;
@@ -511,6 +511,10 @@ private void disallowedInRubyOpts(CharSequence option) throws CommandLineExcepti
511511
}
512512
}
513513

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

0 commit comments

Comments
 (0)