From f9ce4f03e3de8538b5e09317dd79d1595e0255ea Mon Sep 17 00:00:00 2001 From: Martin Weber Date: Sat, 26 Jun 2021 19:28:08 +0200 Subject: [PATCH] show markers in problem view instead of printing to build console Change-Id: Ic487adc11153fac206183a3ceb943d05c6d36066 Signed-off-by: Martin Weber --- .../META-INF/MANIFEST.MF | 2 +- .../internal/CMakeBuildConfiguration.java | 40 ++++++++++++++++--- .../internal/CommandDescriptorBuilder.java | 4 +- .../cdt/cmake/core/internal/Messages.java | 1 + .../cmake/core/internal/messages.properties | 1 + 5 files changed, 41 insertions(+), 7 deletions(-) diff --git a/cmake/org.eclipse.cdt.cmake.core/META-INF/MANIFEST.MF b/cmake/org.eclipse.cdt.cmake.core/META-INF/MANIFEST.MF index 140f7e7095d..6f3e05b1f4f 100644 --- a/cmake/org.eclipse.cdt.cmake.core/META-INF/MANIFEST.MF +++ b/cmake/org.eclipse.cdt.cmake.core/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.cdt.cmake.core;singleton:=true -Bundle-Version: 1.4.100.qualifier +Bundle-Version: 1.4.200.qualifier Bundle-Activator: org.eclipse.cdt.cmake.core.internal.Activator Bundle-Vendor: %providerName Require-Bundle: org.eclipse.core.runtime, diff --git a/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeBuildConfiguration.java b/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeBuildConfiguration.java index 4cf4b2ff29d..c06f8fba2e0 100644 --- a/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeBuildConfiguration.java +++ b/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeBuildConfiguration.java @@ -38,6 +38,8 @@ import org.eclipse.cdt.core.CommandLauncherManager; import org.eclipse.cdt.core.ConsoleOutputStream; import org.eclipse.cdt.core.ErrorParserManager; import org.eclipse.cdt.core.IConsoleParser; +import org.eclipse.cdt.core.IMarkerGenerator; +import org.eclipse.cdt.core.ProblemMarkerInfo; import org.eclipse.cdt.core.build.CBuildConfiguration; import org.eclipse.cdt.core.build.IToolChain; import org.eclipse.cdt.core.envvar.EnvironmentVariable; @@ -178,12 +180,23 @@ public class CMakeBuildConfiguration extends CBuildConfiguration { // in order to run builds in a container. Process p = startBuildProcess(command.getArguments(), new IEnvironmentVariable[0], workingDir, errConsole, monitor); + String arg0 = command.getArguments().get(0); if (p == null) { - console.getErrorStream().write(String.format(Messages.CMakeBuildConfiguration_Failure, "")); //$NON-NLS-1$ + // process start failed + String msg = String.format(Messages.CMakeBuildConfiguration_Failure, ""); //$NON-NLS-1$ + addMarker(new ProblemMarkerInfo(srcFolder.getProject(), -1, msg, + IMarkerGenerator.SEVERITY_ERROR_BUILD, null, new org.eclipse.core.runtime.Path(arg0))); return null; } - watchProcess(p, errConsole); + // check cmake exit status + final int exitValue = watchProcess(p, errConsole); + if (exitValue != 0) { + // cmake had errors... + String msg = String.format(Messages.CMakeBuildConfiguration_ExitFailure, arg0, exitValue); + addMarker(srcFolder.getProject(), -1, msg, IMarkerGenerator.SEVERITY_ERROR_BUILD, null); + return null; + } } cmakeListsModified = false; } @@ -227,7 +240,14 @@ public class CMakeBuildConfiguration extends CBuildConfiguration { return null; } - watchProcess(p, new IConsoleParser[] { epm }); + // check exit status + final int exitValue = watchProcess(p, new IConsoleParser[] { epm }); + if (exitValue != 0) { + // had errors... + String msg2 = String.format(Messages.CMakeBuildConfiguration_ExitFailure, command.get(0), + exitValue); + addMarker(project, -1, msg2, IMarkerGenerator.SEVERITY_ERROR_BUILD, null); + } project.refreshLocal(IResource.DEPTH_INFINITE, monitor); @@ -271,11 +291,21 @@ public class CMakeBuildConfiguration extends CBuildConfiguration { Process p = startBuildProcess(command.getArguments(), new IEnvironmentVariable[0], workingDir, console, monitor); if (p == null) { - console.getErrorStream().write(String.format(Messages.CMakeBuildConfiguration_Failure, "")); //$NON-NLS-1$ + // process start failed + String msg = String.format(Messages.CMakeBuildConfiguration_Failure, ""); //$NON-NLS-1$ + addMarker(new ProblemMarkerInfo(project, -1, msg, IMarkerGenerator.SEVERITY_ERROR_BUILD, null, + new org.eclipse.core.runtime.Path(command.getArguments().get(0)))); return; } - watchProcess(p, console); + // check exit status + final int exitValue = watchProcess(p, console); + if (exitValue != 0) { + // had errors... + String msg = String.format(Messages.CMakeBuildConfiguration_ExitFailure, command.getArguments().get(0), + exitValue); + addMarker(project, -1, msg, IMarkerGenerator.SEVERITY_ERROR_BUILD, null); + } outStream.write(Messages.CMakeBuildConfiguration_BuildComplete); diff --git a/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CommandDescriptorBuilder.java b/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CommandDescriptorBuilder.java index ac28e572ced..81702a28391 100644 --- a/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CommandDescriptorBuilder.java +++ b/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CommandDescriptorBuilder.java @@ -166,7 +166,7 @@ class CommandDescriptorBuilder { } /** - * Command-lin arguments and additional environment variables to be used to run a process. + * Command-line arguments and additional environment variables to be used to run a process. * @author Martin Weber */ static final class CommandDescriptor { @@ -185,6 +185,8 @@ class CommandDescriptorBuilder { /** * Gets the command-line arguments for the process. + * + * @return a non-empty list containing at least the name of the command to invoke. */ public List getArguments() { return arguments; diff --git a/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/Messages.java b/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/Messages.java index 5cee4eb0163..03e52d66e9f 100644 --- a/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/Messages.java +++ b/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/Messages.java @@ -20,6 +20,7 @@ public class Messages extends NLS { public static String CMakeBuildConfiguration_BuildComplete; public static String CMakeBuildConfiguration_Cleaning; public static String CMakeBuildConfiguration_Configuring; + public static String CMakeBuildConfiguration_ExitFailure; public static String CMakeBuildConfiguration_NotFound; public static String CMakeBuildConfiguration_ProcCompCmds; public static String CMakeBuildConfiguration_ProcCompJson; diff --git a/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/messages.properties b/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/messages.properties index fef203a3a83..caf58d32a5b 100644 --- a/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/messages.properties +++ b/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/messages.properties @@ -14,6 +14,7 @@ CMakeBuildConfiguration_BuildingComplete=Build complete (%d errors, %d warnings) CMakeBuildConfiguration_BuildComplete=Build complete\n CMakeBuildConfiguration_Configuring=Configuring in: %s\n CMakeBuildConfiguration_Cleaning=Cleaning %s +CMakeBuildConfiguration_ExitFailure=%1$s exited with status %2$d. See CDT build console for details. CMakeBuildConfiguration_NotFound=CMakeFiles not found. Assuming clean. CMakeBuildConfiguration_ProcCompCmds=Processing compile commands %s CMakeBuildConfiguration_ProcCompJson=Processing compile_commands.json