Skip to content

Commit 0e73061

Browse files
committed
[GR-37283] Set usage syntax for all options
PullRequest: truffleruby/3219
2 parents 128badb + 46f2061 commit 0e73061

File tree

14 files changed

+250
-74
lines changed

14 files changed

+250
-74
lines changed

mx.truffleruby/suite.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
{
88
"name": "regex",
99
"subdir": True,
10-
"version": "7c20b5f30204e2cc13fb75a68eb3e6c73f46f436",
10+
"version": "85c258963b605f95061b37a912a633b1bf1a1c0f",
1111
"urls": [
1212
{"url": "https://github.com/oracle/graal.git", "kind": "git"},
1313
{"url": "https://curio.ssw.jku.at/nexus/content/repositories/snapshots", "kind": "binary"},
@@ -16,7 +16,7 @@
1616
{
1717
"name": "sulong",
1818
"subdir": True,
19-
"version": "7c20b5f30204e2cc13fb75a68eb3e6c73f46f436",
19+
"version": "85c258963b605f95061b37a912a633b1bf1a1c0f",
2020
"urls": [
2121
{"url": "https://github.com/oracle/graal.git", "kind": "git"},
2222
{"url": "https://curio.ssw.jku.at/nexus/content/repositories/snapshots", "kind": "binary"},

spec/truffle/options/parsing_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
end
2323

2424
it "enum values" do
25-
ruby_exe("p Truffle::Boot.get_option('verbose')").should_not == ":NIL\n"
26-
ruby_exe("p Truffle::Boot.get_option('verbose')", options: "--verbose=NIL").should == ":NIL\n"
27-
ruby_exe("p Truffle::Boot.get_option('verbose')", options: "--verbose").should == ":TRUE\n"
25+
ruby_exe("p Truffle::Boot.get_option('verbose')").should_not == ":nil\n"
26+
ruby_exe("p Truffle::Boot.get_option('verbose')", options: "--verbose=nil").should == ":nil\n" # TODO
27+
ruby_exe("p Truffle::Boot.get_option('verbose')", options: "--verbose").should == ":true\n"
2828
end
2929

3030
it "strings" do
@@ -49,7 +49,7 @@
4949
end
5050

5151
it "enum values" do
52-
ruby_exe("14", options: "--verbose=foo", args: "2>&1", exit_status: 1).should.include?("Invalid argument --verbose=foo specified. No enum constant org.truffleruby.shared.options.Verbosity.FOO")
52+
ruby_exe("14", options: "--verbose=foo", args: "2>&1", exit_status: 1).should.include?("ERROR: Invalid argument --verbose=foo specified. Invalid option value 'foo'. Valid options values are: 'nil', 'false', 'true'")
5353
end
5454
end
5555
end

src/main/java/org/truffleruby/language/TruffleBootNodes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ protected Object getOption(Object optionName,
343343
if (value instanceof Boolean || value instanceof Integer) {
344344
return value;
345345
} else if (value instanceof Enum) {
346-
return getSymbol(((Enum<?>) value).name());
346+
return getSymbol(value.toString());
347347
} else if (value instanceof String) {
348348
return makeStringNode.executeMake(value, Encodings.UTF_8, CodeRange.CR_UNKNOWN);
349349
} else if (value instanceof String[]) {

src/main/java/org/truffleruby/language/arguments/ReadCallerDataNode.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,8 @@ protected Object getCallerData() {
5050
getNotOptimizedNode().warn("Unoptimized reading of caller data.");
5151
}
5252

53-
final MaterializedFrame callerFrame = Truffle
54-
.getRuntime()
55-
.getCallerFrame()
56-
.getFrame(FrameAccess.MATERIALIZE)
57-
.materialize();
53+
final MaterializedFrame callerFrame = Truffle.getRuntime()
54+
.iterateFrames(f -> f.getFrame(FrameAccess.MATERIALIZE).materialize(), 1);
5855
if (!CallStackManager.isRubyFrame(callerFrame)) {
5956
throw new RaiseException(
6057
getContext(),

src/main/java/org/truffleruby/options/Options.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.truffleruby.shared.options.OptionsCatalog;
1818
import org.truffleruby.shared.options.Verbosity;
1919
import org.truffleruby.shared.options.Profile;
20+
import org.truffleruby.shared.options.OutputFormat;
2021

2122
import com.oracle.truffle.api.TruffleLanguage.Env;
2223

@@ -27,13 +28,13 @@ public class Options {
2728
public final String[] LOAD_PATHS;
2829
/** --required-libraries=StringArrayOptionType.EMPTY_STRING_ARRAY */
2930
public final String[] REQUIRED_LIBRARIES;
30-
/** --working-directory="" */
31+
/** --working-directory="." */
3132
public final String WORKING_DIRECTORY;
3233
/** --debug=false */
3334
public final boolean DEBUG;
3435
/** --verbose=Verbosity.FALSE */
3536
public final Verbosity VERBOSITY;
36-
/** --source-encoding="" */
37+
/** --source-encoding="UTF-8" */
3738
public final String SOURCE_ENCODING;
3839
/** --internal-encoding="" */
3940
public final String INTERNAL_ENCODING;
@@ -195,8 +196,8 @@ public class Options {
195196
public final boolean REGEXP_INSTRUMENT_MATCH;
196197
/** --regexp-instrument-match-detailed=false */
197198
public final boolean REGEXP_INSTRUMENT_MATCH_DETAILED;
198-
/** --regexp-instrumentation-output-format="text" */
199-
public final String REGEXP_INSTRUMENT_OUTPUT_FORMAT;
199+
/** --regexp-instrumentation-output-format=OutputFormat.TEXT */
200+
public final OutputFormat REGEXP_INSTRUMENT_OUTPUT_FORMAT;
200201
/** --metrics-time-parsing-file=false */
201202
public final boolean METRICS_TIME_PARSING_FILE;
202203
/** --metrics-time-require=false */

src/main/ruby/truffleruby/core/truffle/kernel_operations.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,11 @@ def $LOAD_PATH.resolve_feature_path(file_name)
134134
Truffle::Boot.redo do
135135
$DEBUG = Truffle::Boot.get_option_or_default('debug', false)
136136
$VERBOSE = case Truffle::Boot.get_option_or_default('verbose', false)
137-
when :TRUE
137+
when :true
138138
true
139-
when :FALSE
139+
when :false
140140
false
141-
when :NIL
141+
when :nil
142142
nil
143143
end
144144
end

src/main/ruby/truffleruby/core/truffle/regexp_operations.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ def self.match_stats(joni_matches:)
175175
def self.print_stats
176176
output_format = Truffle::Boot.get_option('regexp-instrumentation-output-format')
177177

178-
if output_format == 'text'
178+
if output_format == :text
179179
puts '--------------------'
180180
puts 'Regular expression statistics'
181181
puts '--------------------'
@@ -204,7 +204,7 @@ def self.print_stats
204204

205205
puts '--------------------'
206206
end
207-
elsif output_format == 'json'
207+
elsif output_format == :json
208208
ret = {}
209209

210210
if Truffle::Boot.get_option('regexp-instrument-creation')

src/main/ruby/truffleruby/post-boot/post-boot.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868

6969
Truffle::Boot.delay do
7070
wd = Truffle::Boot.get_option('working-directory')
71-
Dir.chdir(wd) unless wd.empty?
71+
Dir.chdir(wd) unless wd.empty? || wd == '.'
7272
end
7373

7474
if Truffle::Boot.ruby_home

src/options.yml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,22 +55,22 @@ LANGUAGE_OPTIONS:
5555
USER:
5656
STABLE:
5757
# Options corresponding to MRI options, which are also useful outside the TruffleRuby launcher
58-
LOAD_PATHS: [[load-paths, -I], string-array, [], Load paths]
59-
REQUIRED_LIBRARIES: [[required-libraries, -r], string-array, [], Required libraries]
60-
WORKING_DIRECTORY: [[working-directory, -C], string, '', Interpreter will switch to this directory]
58+
LOAD_PATHS: [[load-paths, -I], string-array, '<path>,<path>,...', Load paths]
59+
REQUIRED_LIBRARIES: [[required-libraries, -r], string-array, '<path>,<path>,...', Required libraries]
60+
WORKING_DIRECTORY: [[working-directory, -C], string, '.', Interpreter will switch to this directory]
6161
DEBUG: [[debug, -d], boolean, false, 'Sets $DEBUG to this value']
6262
VERBOSITY: [[verbose, -v, -w, -W], enum/verbosity, false, 'Sets $VERBOSE to this value']
63-
SOURCE_ENCODING: [[source-encoding, -K], string, '', Source encoding]
64-
INTERNAL_ENCODING: [[internal-encoding, -E, -U], string, '', Internal encoding]
65-
EXTERNAL_ENCODING: [[external-encoding, -E], string, '', External encoding]
63+
SOURCE_ENCODING: [[source-encoding, -K], string, 'UTF-8', Source encoding]
64+
INTERNAL_ENCODING: [[internal-encoding, -E, -U], string, ['', '<nil>'], Internal encoding]
65+
EXTERNAL_ENCODING: [[external-encoding, -E], string, ['', '<locale>'], External encoding]
6666
BACKTRACE_LIMIT: [[backtrace-limit], integer, -1, limit the maximum length of backtrace displayed]
6767

6868
EXPERT:
6969
EXPERIMENTAL:
7070
# Setting home and launcher, useful for embedding
7171
NO_HOME_PROVIDED: [no-home-provided, boolean, false, set to true to explicitly state that no home is provided (silences the warnings)]
72-
LAUNCHER: [launcher, string, '', The location of the TruffleRuby launcher program]
73-
CORE_LOAD_PATH: [core-load-path, string, 'resource:/truffleruby', Location to load the Truffle core library from]
72+
LAUNCHER: [launcher, string, ['', '<set by launcher>'], The location of the TruffleRuby launcher program]
73+
CORE_LOAD_PATH: [core-load-path, string, ['resource:/truffleruby', '<path, default is from cache>'], Location to load the Truffle core library from]
7474

7575
# CRuby features (--enable/disable-FEATURE), also exposed as options so they can be used outside the Ruby launcher
7676
FROZEN_STRING_LITERALS: [frozen-string-literals, boolean, false, Use frozen string literals]
@@ -137,7 +137,7 @@ EXPERT:
137137
LOG_LOAD: [log-load, boolean, false, Log loading files]
138138
LOG_AUTOLOAD: [log-autoload, boolean, false, Log autoloading]
139139
LOG_FEATURE_LOCATION: [log-feature-location, boolean, false, Log the process of finding features]
140-
METRICS_PROFILE_REQUIRE: [metrics-profile-require, enum/profile, none, 'Measure time for searching, parsing, translating and loading files. Valid values are: summary, detail, or none.']
140+
METRICS_PROFILE_REQUIRE: [metrics-profile-require, enum/profile, none, 'Measure time for searching, parsing, translating and loading files.']
141141
CEXTS_LOG_LOAD: [cexts-log-load, boolean, false, Log loading of cexts]
142142
CEXTS_LOG_WARNINGS: [cexts-log-warnings, boolean, false, Log cexts warnings]
143143

@@ -161,8 +161,8 @@ INTERNAL: # Options for debugging the TruffleRuby implementation
161161
SYNTAX_CHECK: [[syntax-check, -c], boolean, false, Do not execute just check syntax]
162162

163163
# Used internally for the launcher to communicate with the RubyContext
164-
ARGV_GLOBAL_VALUES: [argv-global-values, string-array, [], Parsed options from script argv with a value]
165-
ARGV_GLOBAL_FLAGS: [argv-global-flags, string-array, [], Parsed options from script argv acting as flags (no value)]
164+
ARGV_GLOBAL_VALUES: [argv-global-values, string-array, '<key>,<value>,...', Parsed options from script argv with a value]
165+
ARGV_GLOBAL_FLAGS: [argv-global-flags, string-array, '<flag>,<flag>,...', Parsed options from script argv acting as flags (no value)]
166166
BUILDING_CORE_CEXTS: [building-core-cexts, boolean, false, 'Used while building TruffleRuby to build core C extensions']
167167

168168
# Low-level logging of implementation details
@@ -237,7 +237,7 @@ INTERNAL: # Options for debugging the TruffleRuby implementation
237237
REGEXP_INSTRUMENT_CREATION: [regexp-instrument-creation, boolean, false, Enable instrumentation to gather stats on regexp creation]
238238
REGEXP_INSTRUMENT_MATCH: [regexp-instrument-match, boolean, false, Enable instrumentation to gather stats on regexp matching]
239239
REGEXP_INSTRUMENT_MATCH_DETAILED: [regexp-instrument-match-detailed, boolean, false, Enable instrumentation to gather detailed stats on strings matched against a regexp]
240-
REGEXP_INSTRUMENT_OUTPUT_FORMAT: [regexp-instrumentation-output-format, string, 'text', 'Output format for regexp instrumentation (\\\"text\\\" or \\\"json\\\")']
240+
REGEXP_INSTRUMENT_OUTPUT_FORMAT: [regexp-instrumentation-output-format, enum/output_format, text, 'Output format for regexp instrumentation']
241241

242242
# Options for metrics, the output cannot be used directly without processing
243243
METRICS_TIME_PARSING_FILE: [metrics-time-parsing-file, boolean, false, 'Measure time for parsing, translating and executing files, per file']

0 commit comments

Comments
 (0)