From 8dcfd50b9603691feb678b97770f922f4ad123a5 Mon Sep 17 00:00:00 2001 From: Fabio Niephaus Date: Mon, 1 Aug 2022 09:05:01 +0200 Subject: [PATCH 1/2] Add `--silent` option to silence the build output. --- .../native-image/BuildOutput.md | 1 + substratevm/CHANGELOG.md | 1 + .../com/oracle/svm/core/SubstrateOptions.java | 4 ++++ .../hosted/NativeImageSystemIOWrappers.java | 19 +++++++++++++++++++ .../oracle/svm/hosted/ProgressReporter.java | 6 +++++- 5 files changed, 30 insertions(+), 1 deletion(-) diff --git a/docs/reference-manual/native-image/BuildOutput.md b/docs/reference-manual/native-image/BuildOutput.md index 7eeca685269d..3023fe4582d4 100644 --- a/docs/reference-manual/native-image/BuildOutput.md +++ b/docs/reference-manual/native-image/BuildOutput.md @@ -220,6 +220,7 @@ Run `native-image --expert-options-all | grep "BuildOutput"` to see all build ou -H:±BuildOutputLinks Show links in build output. Default: + (enabled). -H:±BuildOutputPrefix Prefix build output with ':'. Default: - (disabled). -H:±BuildOutputProgress Report progress in build output. Default: + (enabled). +-H:±BuildOutputSilent Silence build output. Default: - (disabled). ``` ### Related Documentation diff --git a/substratevm/CHANGELOG.md b/substratevm/CHANGELOG.md index f323725f7f66..9386f44a96b4 100644 --- a/substratevm/CHANGELOG.md +++ b/substratevm/CHANGELOG.md @@ -6,6 +6,7 @@ This changelog summarizes major changes to GraalVM Native Image. * (GR-35721) Remove old build output style and the `-H:±BuildOutputUseNewStyle` option. * (GR-39390) (GR-39649) (GR-40033) Red Hat added support for the JFR events `JavaMonitorEnter`, `JavaMonitorWait`, and `ThreadSleep`. * (GR-39497) Add `-H:BuildOutputJSONFile=` option for [JSON build output](https://github.com/oracle/graal/edit/master/docs/reference-manual/native-image/BuildOutput.md#machine-readable-build-output). Please feel free to provide feedback so that we can stabilize the schema/API. +* (GR-40170) Add `--silent` option to silence the build output. ## Version 22.2.0 * (GR-20653) Re-enable the usage of all CPU features for JIT compilation on AMD64. diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateOptions.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateOptions.java index e9e01263c084..9ab719155ed3 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateOptions.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateOptions.java @@ -408,6 +408,10 @@ public Boolean getValue(OptionValues values) { /* * Build output options. */ + @APIOption(name = "--silent")// + @Option(help = "Silence build output", type = OptionType.User)// + public static final HostedOptionKey BuildOutputSilent = new HostedOptionKey<>(false); + @Option(help = "Prefix build output with ':'", type = OptionType.User)// public static final HostedOptionKey BuildOutputPrefix = new HostedOptionKey<>(false); diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageSystemIOWrappers.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageSystemIOWrappers.java index d6a204f1353a..77e2a7f80744 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageSystemIOWrappers.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageSystemIOWrappers.java @@ -25,6 +25,7 @@ package com.oracle.svm.hosted; +import java.io.OutputStream; import java.io.PrintStream; import java.util.Objects; @@ -57,6 +58,10 @@ public static NativeImageSystemIOWrappers singleton() { return NativeImageSystemClassLoader.singleton().systemIOWrappers; } + public static NativeImageSystemIOWrappers disabled() { + return new NativeImageSystemIOWrappersDisabled(); + } + public PrintStream getOut() { return outWrapper.delegate; } @@ -103,4 +108,18 @@ private void maybeInformProgressReporterOnce() { } } } + + private static class NativeImageSystemIOWrappersDisabled extends NativeImageSystemIOWrappers { + private static final PrintStream NULL_PRINT_STREAM = new PrintStream(OutputStream.nullOutputStream()); + + @Override + public PrintStream getOut() { + return NULL_PRINT_STREAM; + } + + @Override + public PrintStream getErr() { + return NULL_PRINT_STREAM; + } + } } diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ProgressReporter.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ProgressReporter.java index 453a8627582e..a851bb4fe2cd 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ProgressReporter.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ProgressReporter.java @@ -174,7 +174,11 @@ public static ProgressReporter singleton() { } public ProgressReporter(OptionValues options) { - builderIO = NativeImageSystemIOWrappers.singleton(); + if (SubstrateOptions.BuildOutputSilent.getValue(options)) { + builderIO = NativeImageSystemIOWrappers.disabled(); + } else { + builderIO = NativeImageSystemIOWrappers.singleton(); + } if (SubstrateOptions.BuildOutputJSONFile.hasBeenSet(options)) { jsonHelper = new ProgressReporterJsonHelper(SubstrateOptions.BuildOutputJSONFile.getValue(options)); From 38c58a26f760caf0a6fe115bb78f58bfb5a1edbc Mon Sep 17 00:00:00 2001 From: Fabio Niephaus Date: Mon, 1 Aug 2022 09:23:18 +0200 Subject: [PATCH 2/2] Silence build output of fallback builds. --- .../src/com/oracle/svm/core/SubstrateOptions.java | 2 +- .../src/com/oracle/svm/driver/NativeImage.java | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateOptions.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateOptions.java index 9ab719155ed3..d125b205cf10 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateOptions.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateOptions.java @@ -408,7 +408,7 @@ public Boolean getValue(OptionValues values) { /* * Build output options. */ - @APIOption(name = "--silent")// + @APIOption(name = "silent")// @Option(help = "Silence build output", type = OptionType.User)// public static final HostedOptionKey BuildOutputSilent = new HostedOptionKey<>(false); diff --git a/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/NativeImage.java b/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/NativeImage.java index 61cb8de51fbb..0cdde5f7c50b 100644 --- a/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/NativeImage.java +++ b/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/NativeImage.java @@ -630,6 +630,7 @@ private ArrayList createFallbackBuildArgs() { buildArgs.add(fallbackExecutorJavaArg); } + buildArgs.add(oH + "+" + SubstrateOptions.BuildOutputSilent.getName()); buildArgs.add(oH + "+" + SubstrateOptions.ParseRuntimeOptions.getName()); Path imagePathPath; try { @@ -1407,6 +1408,7 @@ protected static void build(BuildConfiguration config, Function