Skip to content

Commit ab3a2ae

Browse files
committed
[GR-33644] [GR-33641] Support newlines in Truffle's OptionProcessor.
PullRequest: graal/9736
2 parents 4b94d2d + 267cc95 commit ab3a2ae

File tree

11 files changed

+44
-26
lines changed

11 files changed

+44
-26
lines changed

compiler/src/org.graalvm.compiler.truffle.options/src/org/graalvm/compiler/truffle/options/PolyglotCompilerOptions.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ public ExceptionAction apply(String s) {
178178
try {
179179
return ExceptionAction.valueOf(s);
180180
} catch (IllegalArgumentException e) {
181-
throw new IllegalArgumentException(ExceptionAction.HELP);
181+
throw new IllegalArgumentException(String.format(ExceptionAction.HELP));
182182
}
183183
}
184184
});
@@ -365,10 +365,10 @@ private String indent(int nameLength) {
365365
private static final String EXPANSION_VALUES = "Accepted values are:%n" +
366366
" true - Collect data for the default tier 'truffleTier'.%n" +
367367
" false - No data will be collected.%n" +
368-
"Or one or multiple tiers separated by comma (e.g. truffleTier,lowTier) :%n" +
368+
"Or one or multiple tiers separated by comma (e.g. truffleTier,lowTier):%n" +
369369
" peTier - After partial evaluation without additional phases applied.%n" +
370370
" truffleTier - After partial evaluation with additional phases applied.%n" +
371-
" lowTier - After low tier phases were applied.%n";
371+
" lowTier - After low tier phases were applied.";
372372

373373
@Option(help = "Print a tree of all expanded Java methods with statistics after each compilation. " + EXPANSION_VALUES, category = OptionCategory.INTERNAL)
374374
public static final OptionKey<Set<CompilationTier>> TraceMethodExpansion = new OptionKey<>(Collections.emptySet(), COMPILATION_TIERS_TYPE);
@@ -498,7 +498,7 @@ private String indent(int nameLength) {
498498
"On runtimes which doesn't support it the option has no effect.",
499499
category = OptionCategory.EXPERT)
500500
public static final OptionKey<Integer> EncodedGraphCachePurgeDelay = new OptionKey<>(10_000);
501-
501+
502502
@Option(help = "Forces the frame clearing mechanism to be executed, even if Frame.clear() is not used.",
503503
category = OptionCategory.EXPERT)
504504
public static final OptionKey<Boolean> ForceFrameLivenessAnalysis = new OptionKey<>(false);

docs/getting-started/graalvm-community/get-started-graalvm-community.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ GraalVM's polyglot capabilities make it possible to mix multiple programming lan
1414
Here you will find information about installing GraalVM Community Edition, running basic applications with it, and adding support for accompanying features.
1515
Further, you will learn about the polyglot capabilities of GraalVM and see how to build platform-specific native executables of JVM-based applications.
1616

17-
If you are new to GraaVM, we recommend starting with [Introduction to GraalVM](/docs/introduction/), where you will find information about GraalVM's architecture, distributions available, supported platforms, core and additional features, and much more.
17+
If you are new to GraalVM, we recommend starting with [Introduction to GraalVM](/docs/introduction/), where you will find information about GraalVM's architecture, distributions available, supported platforms, core and additional features, and much more.
1818

1919
If you have GraalVM already installed and have experience using it, you can skip this getting started guide and proceed to the in-depth [Reference Manuals](/reference-manual/).
2020

sdk/mx.sdk/mx_sdk_vm_impl.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2149,8 +2149,9 @@ def _gen_gu_manifest(components, formatter, bundled=False):
21492149
dependencies = sorted(dependencies)
21502150
if dependencies:
21512151
manifest["Require-Bundle"] = ','.join(("org.graalvm." + d for d in dependencies))
2152-
if isinstance(main_component, mx_sdk.GraalVmLanguage):
2153-
_wd_base = join('jre', 'languages') if _src_jdk_version < 9 else 'languages'
2152+
if isinstance(main_component, (mx_sdk.GraalVmLanguage, mx_sdk.GraalVmTool)):
2153+
_component_type_base = 'languages' if isinstance(main_component, mx_sdk.GraalVmLanguage) else 'tools'
2154+
_wd_base = join('jre', _component_type_base) if _src_jdk_version < 9 else _component_type_base
21542155
manifest["x-GraalVM-Working-Directories"] = join(_wd_base, main_component.dir_name)
21552156

21562157
post_install_msg = None

sdk/src/org.graalvm.launcher/src/org/graalvm/launcher/Launcher.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -973,9 +973,12 @@ private static String wrap(String s) {
973973

974974
private void printOption(String option, String description, int indentStart, int optionWidth) {
975975
String indent = spaces(indentStart);
976-
String desc = wrap(description != null ? description : "");
976+
String desc = description != null ? description : "";
977977
String nl = System.lineSeparator();
978978
String[] descLines = desc.split(nl);
979+
for (int i = 0; i < descLines.length; i++) {
980+
descLines[i] = wrap(descLines[i]);
981+
}
979982
if (option.length() >= optionWidth && description != null) {
980983
out.println(indent + option + nl + indent + spaces(optionWidth) + descLines[0]);
981984
} else {

sdk/src/org.graalvm.options/src/org/graalvm/options/OptionDescriptor.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -96,7 +96,7 @@ public boolean isDeprecated() {
9696
}
9797

9898
/**
99-
* Returns the deprecation reason and the recommended fix.
99+
* Returns the deprecation reason and the recommended fix. For newlines, use <code>%n</code>.
100100
*
101101
* @since 20.1.0
102102
*/
@@ -133,7 +133,8 @@ public OptionStability getStability() {
133133
}
134134

135135
/**
136-
* Returns a human-readable description on how to use the option.
136+
* Returns a human-readable description on how to use the option. For newlines, use
137+
* <code>%n</code>.
137138
*
138139
* @since 19.0
139140
*/

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/substitute/AnnotationSubstitutionProcessor.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -819,11 +819,13 @@ private static boolean isIncluded(TargetElement targetElementAnnotation, Class<?
819819

820820
private static <T> void register(Map<T, T> substitutions, T annotated, T original, T target) {
821821
if (annotated != null) {
822-
guarantee(!substitutions.containsKey(annotated) || substitutions.get(annotated) == original || substitutions.get(annotated) == target, "Already registered: %s", annotated);
822+
guarantee(!substitutions.containsKey(annotated) || substitutions.get(annotated) == original || substitutions.get(annotated) == target,
823+
"Substition: %s conflicts with previously registered: %s", annotated, substitutions.get(annotated));
823824
substitutions.put(annotated, target);
824825
}
825826
if (original != null) {
826-
guarantee(!substitutions.containsKey(original) || substitutions.get(original) == original || substitutions.get(original) == target, "Already registered: %s", original);
827+
guarantee(!substitutions.containsKey(original) || substitutions.get(original) == original || substitutions.get(original) == target,
828+
"Substition: %s conflicts with previously registered: %s", original, substitutions.get(original));
827829
substitutions.put(original, target);
828830
}
829831
}

truffle/src/com.oracle.truffle.api.instrumentation/src/com/oracle/truffle/api/instrumentation/TruffleInstrument.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ protected OptionDescriptors getOptionDescriptors() {
232232
* }
233233
*
234234
* &#64;Registration(...)
235-
* class MyInstrument extends TruffleInstruement {
235+
* class MyInstrument extends TruffleInstrument {
236236
*
237237
* static final OptionDescriptors CONTEXT_OPTIONS = new MyContextOptionDescriptors();
238238
*

truffle/src/com.oracle.truffle.api.interop/src/com/oracle/truffle/api/interop/InteropLibrary.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,9 @@
105105
* The interop protocol only allows <i>interop values</i> to be used as receivers, return values or
106106
* parameters of messages. Allowed Java types of interop values are:
107107
* <ul>
108-
* <li>{@link TruffleObject}: Any subclass of {@link TruffleObject} is interpreted depending on the
109-
* interop messages it {@link ExportLibrary exports}. Truffle objects are expected but not required
110-
* to export interop library messages.
108+
* <li>{@link TruffleObject}: Any object that implements the {@link TruffleObject} interface is
109+
* interpreted according to the interop messages it {@link ExportLibrary exports}. Truffle objects
110+
* are expected but not required to export interop library messages.
111111
* <li>{@link String} and {@link Character} are interpreted as {@link #isString(Object) string}
112112
* value.
113113
* <li>{@link Boolean} is interpreted as {@link #isBoolean(Object) boolean} value.

truffle/src/com.oracle.truffle.api.library/src/com/oracle/truffle/api/library/ExportLibrary.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@
295295
*
296296
* <pre>
297297
* &#64;ExportLibrary(value = ArrayLibrary.class, delegateTo = "delegate")
298-
* &#64;ExportLibrary(ReflectionLibrary.class, delegateTo = "delegate")
298+
* &#64;ExportLibrary(value = ReflectionLibrary.class, delegateTo = "delegate")
299299
* final class ArrayFullWrapper {
300300
*
301301
* final Object delegate;

truffle/src/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/option/OptionProcessorTest.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ public void testTestLang() {
8686
descriptor1 = descriptor = descriptors.get("optiontestlang1.StringOption1");
8787
assertNotNull(descriptor);
8888
assertTrue(descriptor.isDeprecated());
89+
assertEquals(String.format("Deprecation message%nwith newline"), descriptor.getDeprecationMessage());
8990
assertFalse(descriptor.isOptionMap());
9091
assertSame(OptionCategory.USER, descriptor.getCategory());
9192
assertSame(OptionStability.EXPERIMENTAL, descriptor.getStability());
@@ -94,7 +95,7 @@ public void testTestLang() {
9495

9596
descriptor2 = descriptor = descriptors.get("optiontestlang1.StringOption2");
9697
assertNotNull(descriptor);
97-
assertEquals("StringOption2 help", descriptor.getHelp());
98+
assertEquals(String.format("StringOption2 help%nwith newline"), descriptor.getHelp());
9899
assertFalse(descriptor.isDeprecated());
99100
assertFalse(descriptor.isOptionMap());
100101
assertSame(OptionCategory.EXPERT, descriptor.getCategory());
@@ -166,14 +167,15 @@ public void testOptionsInstrument() {
166167
descriptor1 = descriptor = descriptors.get("optiontestinstr1.StringOption1");
167168
assertNotNull(descriptor);
168169
assertTrue(descriptor.isDeprecated());
170+
assertEquals(String.format("Deprecation message%nwith newline"), descriptor.getDeprecationMessage());
169171
assertFalse(descriptor.isOptionMap());
170172
assertSame(OptionCategory.USER, descriptor.getCategory());
171173
assertEquals("StringOption1 help", descriptor.getHelp());
172174
assertSame(OptionTestInstrument1.StringOption1, descriptor.getKey());
173175

174176
descriptor2 = descriptor = descriptors.get("optiontestinstr1.StringOption2");
175177
assertNotNull(descriptor);
176-
assertEquals("StringOption2 help", descriptor.getHelp());
178+
assertEquals(String.format("StringOption2 help%nwith newline"), descriptor.getHelp());
177179
assertFalse(descriptor.isDeprecated());
178180
assertFalse(descriptor.isOptionMap());
179181
assertSame(OptionCategory.EXPERT, descriptor.getCategory());
@@ -357,10 +359,10 @@ public enum EnumValue {
357359
@Registration(id = "optiontestlang1", version = "1.0", name = "optiontestlang1")
358360
public static class OptionTestLang1 extends TruffleLanguage<Env> {
359361

360-
@Option(help = "StringOption1 help", deprecated = true, category = OptionCategory.USER) //
362+
@Option(help = "StringOption1 help", deprecated = true, deprecationMessage = "Deprecation message%nwith newline", category = OptionCategory.USER) //
361363
static final OptionKey<String> StringOption1 = new OptionKey<>("defaultValue");
362364

363-
@Option(help = "StringOption2 help", deprecated = false, category = OptionCategory.EXPERT, stability = OptionStability.EXPERIMENTAL) //
365+
@Option(help = "StringOption2 help%nwith newline", deprecated = false, category = OptionCategory.EXPERT, stability = OptionStability.EXPERIMENTAL) //
364366
public static final OptionKey<String> StringOption2 = new OptionKey<>("defaultValue");
365367

366368
// The variable name differs from the option name on purpose, to test they can be different
@@ -397,10 +399,10 @@ public static Env getCurrentContext() {
397399
@TruffleInstrument.Registration(id = "optiontestinstr1", services = OptionValues.class)
398400
public static class OptionTestInstrument1 extends TruffleInstrument {
399401

400-
@Option(help = "StringOption1 help", deprecated = true, category = OptionCategory.USER, stability = OptionStability.STABLE) //
402+
@Option(help = "StringOption1 help", deprecated = true, deprecationMessage = "Deprecation message%nwith newline", category = OptionCategory.USER, stability = OptionStability.STABLE) //
401403
public static final OptionKey<String> StringOption1 = new OptionKey<>("defaultValue");
402404

403-
@Option(help = "StringOption2 help", deprecated = false, category = OptionCategory.EXPERT) //
405+
@Option(help = "StringOption2 help%nwith newline", deprecated = false, category = OptionCategory.EXPERT) //
404406
public static final OptionKey<String> StringOption2 = new OptionKey<>("defaultValue");
405407

406408
@Option(help = "Instrument user-defined thresholds", deprecated = false, category = OptionCategory.EXPERT) //

0 commit comments

Comments
 (0)