Skip to content

Commit 9795ca5

Browse files
committed
track warnings in Native Image build and list their count at the very end of the build
1 parent d8ab154 commit 9795ca5

File tree

4 files changed

+30
-0
lines changed

4 files changed

+30
-0
lines changed

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateOptions.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1711,4 +1711,8 @@ private static void validateEnableFallbackCompilation(HostedOptionKey<Boolean> o
17111711
public static boolean canEnableFallbackCompilation() {
17121712
return !EnableFallbackCompilation.getValue() && !useEconomyCompilerConfig();
17131713
}
1714+
1715+
@Option(help = "Passes the numbers of warnings that occurred in the driver phase to the builder.", type = OptionType.Debug, stability = OptionStability.STABLE) //
1716+
public static final HostedOptionKey<Integer> DriverWarningsCount = new HostedOptionKey<>(0);
1717+
17141718
}

substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/NativeImage.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1492,6 +1492,8 @@ private int completeImageBuild() {
14921492
// allow native access for all modules on the image builder module path
14931493
var enableNativeAccessModules = getModulesFromPath(imageBuilderModulePath).keySet();
14941494
imageBuilderJavaArgs.add("--enable-native-access=" + String.join(",", enableNativeAccessModules));
1495+
// pass the number of warnings to the builder process
1496+
imageBuilderArgs.add(oH(SubstrateOptions.DriverWarningsCount)+LogUtils.getWarningsCount());
14951497

14961498
boolean useColorfulOutput = configureBuildOutput();
14971499

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ProgressReporter.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
import java.util.stream.Stream;
5555

5656
import com.oracle.svm.core.RuntimeAssertionsSupport;
57+
import com.oracle.svm.util.LogUtils;
5758
import org.graalvm.nativeimage.ImageSingletons;
5859
import org.graalvm.nativeimage.hosted.Feature;
5960
import org.graalvm.nativeimage.impl.ImageSingletonsSupport;
@@ -795,6 +796,7 @@ public void printEpilog(Optional<String> optionalImageName, Optional<NativeImage
795796
l().a(outcomePrefix(buildOutcome)).a(" generating '").bold().a(imageName).reset().a("' ")
796797
.a(buildOutcome.successful() ? "in" : "after").a(" ").a(timeStats).a(".").println();
797798

799+
printWarningMessages();
798800
printErrorMessage(optionalUnhandledThrowable, parsedHostedOptions);
799801
}
800802

@@ -806,6 +808,17 @@ private static String outcomePrefix(NativeImageGeneratorRunner.BuildOutcome buil
806808
};
807809
}
808810

811+
private void printWarningMessages() {
812+
int warningsCount = LogUtils.getWarningsCount() + SubstrateOptions.DriverWarningsCount.getValue();
813+
if (warningsCount == 0) {
814+
return;
815+
}
816+
817+
l().println();
818+
l().yellowBold().a("The build process encountered ").a(warningsCount).a(warningsCount == 1 ? " warning." : " warnings.").reset().println();
819+
l().println();
820+
}
821+
809822
private void printErrorMessage(Optional<Throwable> optionalUnhandledThrowable, OptionValues parsedHostedOptions) {
810823
if (optionalUnhandledThrowable.isEmpty()) {
811824
return;

substratevm/src/com.oracle.svm.util/src/com/oracle/svm/util/LogUtils.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@
2929

3030
// Checkstyle: Allow raw info or warning printing - begin
3131
public class LogUtils {
32+
/**
33+
* Number of warnings seen during image build. Note this is limited to the current process, i.e. there is a split
34+
* between Driver and Builder.
35+
*/
36+
private static int warningsCount = 0;
37+
3238
/**
3339
* Print an info message.
3440
*/
@@ -66,6 +72,7 @@ public static void prefixInfo(String prefix, String format, Object... args) {
6672
*/
6773
public static void warning(String message) {
6874
System.out.println("Warning: " + message);
75+
warningsCount++;
6976
}
7077

7178
/**
@@ -87,4 +94,8 @@ public static void warning(String format, Object... args) {
8794
public static void warningDeprecatedEnvironmentVariable(String environmentVariableName) {
8895
warning("The " + environmentVariableName + " environment variable is deprecated and might be removed in a future release. Please refer to the GraalVM release notes.");
8996
}
97+
98+
public static int getWarningsCount() {
99+
return warningsCount;
100+
}
90101
}

0 commit comments

Comments
 (0)