Skip to contentSkip to conversation

Add cmake error to build failure dialog

PATCH In review Timo Mueller 2 participants 6 messages May 22, 2014

lore
Share & tools
lore
#0 lore raw

cover Add cmake error to build failure dialog

From: Timo Mueller <[email protected]>

Hi,

when problems occured during configuring the project with CMake we showed a messge dialog with a generic 'build failed' method. In parallel the reason for the error was captured in the configuration console. But as the dialog did not contain any note on the existence of this console the user might end up with no hint on what went wrong and how he can fix it.

To help the user fix syntax errors or other errors with CMake the error is captured and added to the message dialog. While complete CMake log is still available in the configuration console, the dialog now contains all information on what went wrong, e.g. CMake Error at CMakeLists.txt:8 (include_directoriesBOGUS):
Unknown CMake command "include_directoriesBOGUS".

01..03: Enable logging the stderr from CMake to a console while capturing it in a string
04: Add the reported CMake error to the configuration error dialog

Best regards,
Timo

Timo Mueller (4):
plugins/cmake: Allow multiple targets when logging process output plugins/cmake: Enable separate capturing of cmake stderr plugins/cmake: Use generic output stream plugins/cmake: Add cmake error message to error dialog

 .../managedbuilder/YoctoCMakeMessages.properties   |  2 +-
 .../managedbuilder/job/ExecuteConfigureJob.java    | 12 +++++---
 .../cmake/managedbuilder/util/SystemProcess.java   | 34 ++++++++++++++++++----
 3 files changed, 38 insertions(+), 10 deletions(-)
Signature · 1 line
1.9.0
#1 lore raw

PATCH 1/4 plugins/cmake: Allow multiple targets when logging process output

From: Timo Mueller <[email protected]>

Until now the stream pipe was connecting one input stream with one output stream. This for example allowed showing the output of a process in an eclipse console. If the output is required elsewhere, e.g. in a message dialog, the only possiblity was to read out the whole console afterwards.

The stream pipe is extended so that we can now write the process output to multiple target while the process is running, e.g. a eclipse console and a byte stream.

---
 .../src/org/yocto/cmake/managedbuilder/util/SystemProcess.java | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
plugins/org.yocto.cmake.managedbuilder/src/org/yocto/cmake/managedbuilder/util/SystemProcess.java +6 -4
index 9ca6e60..764a1f6 100644
@@ -87,12 +87,12 @@ public class SystemProcess {
 
 	private class StreamPipe extends Thread {
 		private InputStream in;
-		private OutputStream out;
+		private OutputStream[] outputs;
 		boolean shutdown = false;
 
-		public StreamPipe(InputStream in, OutputStream out) {
+		public StreamPipe(InputStream in, OutputStream... outputs) {
 			this.in = in;
-			this.out = out;
+			this.outputs = outputs;
 		}
 
 		@Override
@@ -102,7 +102,9 @@ public class SystemProcess {
 
 			try {
 				while(!shutdown && ((length = in.read(buffer)) > -1)) {
-					out.write(buffer, 0, length);
+					for (OutputStream out : outputs) {
+						out.write(buffer, 0, length);
+					}
 				}
 			} catch (IOException e) {
 				e.printStackTrace();
Signature · 1 line
1.9.0
#2 lore raw

PATCH 2/4 plugins/cmake: Enable separate capturing of cmake stderr

From: Timo Mueller <[email protected]>

The error reported by CMake was logged to the console but not used in any error dialog shown to the user so far.

By capturing the error in a separate stream we can use it when reproting the error to the user.

---
 .../cmake/managedbuilder/util/SystemProcess.java   | 24 +++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)
plugins/org.yocto.cmake.managedbuilder/src/org/yocto/cmake/managedbuilder/util/SystemProcess.java +23 -1
index 764a1f6..9fe0ce1 100644
@@ -24,6 +24,7 @@ public class SystemProcess {
 	private ProcessBuilder builder;
 	private Process process;
 	private StreamPipe outputRedirector;
+	private StreamPipe errorRedirector;
 
 	public SystemProcess(LinkedList<String> command) {
 		this(command, null);
@@ -47,7 +48,6 @@ public class SystemProcess {
 		if (workingDirectory != null) {
 			builder.directory(workingDirectory);
 		}
-		builder.redirectErrorStream(true);
 
 		if(additionalEnvironmentVariables != null && !additionalEnvironmentVariables.isEmpty()) {
 			builder.environment().putAll(additionalEnvironmentVariables);
@@ -56,11 +56,21 @@ public class SystemProcess {
 
 	public void start(OutputStream out) throws IOException {
 		if (builder != null) {
+			builder.redirectErrorStream(true);
 			process = builder.start();
 			outputRedirector = redirectOutput(process, out);
 		}
 	}
 
+	public void start(OutputStream out, OutputStream err) throws IOException {
+		if (builder != null) {
+			builder.redirectErrorStream(false);
+			process = builder.start();
+			outputRedirector = redirectOutput(process, out);
+			errorRedirector = redirectError(process, err, out);
+		}
+	}
+
 	public int waitForResultAndStop() throws InterruptedException {
 		if (process == null) {
 			return -1;
@@ -69,6 +79,10 @@ public class SystemProcess {
 		process.waitFor();
 		outputRedirector.interrupt();
 
+		if (!builder.redirectErrorStream()) {
+			errorRedirector.interrupt();
+		}
+
 		return process.exitValue();
 	}
 
@@ -76,6 +90,14 @@ public class SystemProcess {
 		process.destroy();
 	}
 
+	private StreamPipe redirectError(Process process, OutputStream errOut, OutputStream out) {
+		InputStream err = process.getErrorStream();
+		StreamPipe stderrPipe = new StreamPipe(err, errOut, out);
+		stderrPipe.start();
+
+		return stderrPipe;
+	}
+
 	private StreamPipe redirectOutput(Process process, OutputStream out) {
 		InputStream in = process.getInputStream();
 		StreamPipe stdoutPipe = new StreamPipe(in, out);
Signature · 1 line
1.9.0
#3 lore raw

PATCH 3/4 plugins/cmake: Use generic output stream

From: Timo Mueller <[email protected]>

This enables logging the process output to something other than a eclipse console. e.g. a log file or string that can be reused for dialogs and messages.

---
 .../src/org/yocto/cmake/managedbuilder/job/ExecuteConfigureJob.java    | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
plugins/org.yocto.cmake.managedbuilder/src/org/yocto/cmake/managedbuilder/job/ExecuteConfigureJob.java +2 -1
index 354d930..f90a2d7 100644
@@ -11,6 +11,7 @@
 package org.yocto.cmake.managedbuilder.job;
 
 import java.io.IOException;
+import java.io.OutputStream;
 import java.util.Arrays;
 import java.util.HashMap;
 import java.util.LinkedList;
@@ -157,7 +158,7 @@ public class ExecuteConfigureJob extends Job {
 	}
 
 	private IStatus buildProject(IProgressMonitor monitor,
-			IOConsoleOutputStream cos) throws IOException, InterruptedException {
+			OutputStream cos) throws IOException, InterruptedException {
 		monitor.subTask(
 				YoctoCMakeMessages.getString("ExecuteConfigureJob.buildingMakefile")); //$NON-NLS-1$
 		configureProcess.start(cos);
Signature · 1 line
1.9.0
#4 lore raw

PATCH 4/4 plugins/cmake: Add cmake error message to error dialog

From: Timo Mueller <[email protected]>

In case cmake reported an error during project configuration the resulting error dialog showed a generic 'build failed' message. The specific error message which can help the user find the problem was hidden in cmake console.

Along with logging the cmake error to the configure console it is now also captured and added to the error dialog.

[BUGFIX #6313]

---
 .../yocto/cmake/managedbuilder/YoctoCMakeMessages.properties  |  2 +-
 .../yocto/cmake/managedbuilder/job/ExecuteConfigureJob.java   | 11 +++++++----
 2 files changed, 8 insertions(+), 5 deletions(-)
plugins/org.yocto.cmake.managedbuilder/src/org/yocto/cmake/managedbuilder/YoctoCMakeMessages.properties +1 -1
index 55773ac..651ace5 100644
@@ -15,7 +15,7 @@ ExecuteConfigureJob.consoleName=Configure using CMake [{0}]
 ExecuteConfigureJob.buildingMakefile=Building Makefile
 ExecuteConfigureJob.warning.aborted=Build of project has been aborted
 ExecuteConfigureJob.error.couldNotStart=Build of project could not be started
-ExecuteConfigureJob.error.buildFailed=Build of project failed
+ExecuteConfigureJob.error.buildFailed=Build of project failed with the following error:\n{0}
 ExecuteConfigureJob.cmakeWarning.dialogTitle=Unable to run command "cmake"
 ExecuteConfigureJob.cmakeWarning.dialogMessage=Please make sure that cmake is installed properly on this machine.
 
plugins/org.yocto.cmake.managedbuilder/src/org/yocto/cmake/managedbuilder/job/ExecuteConfigureJob.java +7 -4
index f90a2d7..84e8c62 100644
@@ -10,6 +10,7 @@
  *******************************************************************************/
 package org.yocto.cmake.managedbuilder.job;
 
+import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.util.Arrays;
@@ -124,10 +125,11 @@ public class ExecuteConfigureJob extends Job {
 		IOConsoleOutputStream cos =
 				ConsoleUtility.getConsoleOutput(YoctoCMakeMessages.getFormattedString("ExecuteConfigureJob.consoleName", //$NON-NLS-1$
 						project.getName()));
+		ByteArrayOutputStream ces = new ByteArrayOutputStream();
 		monitor.worked(1);
 
 		try {
-			return buildProject(monitor, cos);
+			return buildProject(monitor, cos, ces);
 		} catch (IOException e) {
 			if(e.getMessage().startsWith("Cannot run program \"cmake\"")) { //$NON-NLS-1$
 				Display.getDefault().asyncExec(new Runnable() {
@@ -158,16 +160,17 @@ public class ExecuteConfigureJob extends Job {
 	}
 
 	private IStatus buildProject(IProgressMonitor monitor,
-			OutputStream cos) throws IOException, InterruptedException {
+			OutputStream stdout, OutputStream stderr) throws IOException, InterruptedException {
 		monitor.subTask(
 				YoctoCMakeMessages.getString("ExecuteConfigureJob.buildingMakefile")); //$NON-NLS-1$
-		configureProcess.start(cos);
+		configureProcess.start(stdout, stderr);
 		int exitValue = configureProcess.waitForResultAndStop();
 		monitor.worked(15);
 
 		if (exitValue != 0) {
 			return new Status(Status.ERROR, Activator.PLUGIN_ID,
-					YoctoCMakeMessages.getString("ExecuteConfigureJob.error.buildFailed") + " " + exitValue); //$NON-NLS-1$ //$NON-NLS-2$
+					YoctoCMakeMessages.getFormattedString("ExecuteConfigureJob.error.buildFailed", //$NON-NLS-1$
+															stderr.toString().trim()));
 		}
 
 		return Status.OK_STATUS;
Signature · 1 line
1.9.0
#5 lore raw
In reply to Timo Mueller

Pulled into eclipse-poky-kepler master. Thanks for the contribution! - Jessica

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Timo Mueller
Sent: Thursday, May 22, 2014 2:58 AM
To: [email protected]
Cc: Timo Mueller
Subject: [yocto] [eclipse][PATCH 0/4] Add cmake error to build failure dialog

From: Timo Mueller <[email protected]>

Hi,

when problems occured during configuring the project with CMake we showed a messge dialog with a generic 'build failed' method. In parallel the reason for the error was captured in the configuration console. But as the dialog did not contain any note on the existence of this console the user might end up with no hint on what went wrong and how he can fix it.

To help the user fix syntax errors or other errors with CMake the error is captured and added to the message dialog. While complete CMake log is still available in the configuration console, the dialog now contains all information on what went wrong, e.g. CMake Error at CMakeLists.txt:8 (include_directoriesBOGUS):
Unknown CMake command "include_directoriesBOGUS".

01..03: Enable logging the stderr from CMake to a console while capturing it in a string 04: Add the reported CMake error to the configuration error dialog

Best regards,
Timo

Timo Mueller (4):
plugins/cmake: Allow multiple targets when logging process output plugins/cmake: Enable separate capturing of cmake stderr plugins/cmake: Use generic output stream plugins/cmake: Add cmake error message to error dialog

 .../managedbuilder/YoctoCMakeMessages.properties   |  2 +-
 .../managedbuilder/job/ExecuteConfigureJob.java    | 12 +++++---
 .../cmake/managedbuilder/util/SystemProcess.java   | 34 ++++++++++++++++++----
 3 files changed, 38 insertions(+), 10 deletions(-)

--
1.9.0

--
_______________________________________________
yocto mailing list
[email protected]
https://lists.yoctoproject.org/listinfo/yocto