1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Hook up the error parser properly in the build configuration.

So we can have the error partitions that work with double clicking
in the build console.

Change-Id: I357f4efb8fd16232b78b18958c9863071feeebcc
This commit is contained in:
Doug Schaefer 2017-11-03 16:48:20 -04:00
parent ceeac1865a
commit 87cd8401f4
6 changed files with 66 additions and 24 deletions

View file

@ -94,6 +94,7 @@ public class CMakeBuildConfiguration extends CBuildConfiguration {
public IProject[] build(int kind, Map<String, String> args, IConsole console, IProgressMonitor monitor)
throws CoreException {
IProject project = getProject();
try {
String generator = getProperty(CMAKE_GENERATOR);
if (generator == null) {
@ -146,11 +147,13 @@ public class CMakeBuildConfiguration extends CBuildConfiguration {
setBuildEnvironment(processBuilder.environment());
Process process = processBuilder.start();
outStream.write(String.join(" ", command) + '\n'); //$NON-NLS-1$
watchProcess(process, new IConsoleParser[0], console);
watchProcess(process, console);
}
try (ErrorParserManager epm = new ErrorParserManager(project, getBuildDirectoryURI(), this,
getToolChain().getErrorParserIds())) {
epm.setOutputStream(console.getOutputStream());
String buildCommand = getProperty(BUILD_COMMAND);
if (buildCommand == null) {
if (generator.equals("Ninja")) { //$NON-NLS-1$
@ -170,7 +173,7 @@ public class CMakeBuildConfiguration extends CBuildConfiguration {
setBuildEnvironment(processBuilder.environment());
Process process = processBuilder.start();
outStream.write(String.join(" ", command) + '\n'); //$NON-NLS-1$
watchProcess(process, new IConsoleParser[] { epm }, console);
watchProcess(process, new IConsoleParser[] { epm });
}
project.refreshLocal(IResource.DEPTH_INFINITE, monitor);
@ -219,7 +222,7 @@ public class CMakeBuildConfiguration extends CBuildConfiguration {
ProcessBuilder processBuilder = new ProcessBuilder(command).directory(buildDir.toFile());
Process process = processBuilder.start();
outStream.write(String.join(" ", command) + '\n'); //$NON-NLS-1$
watchProcess(process, new IConsoleParser[0], console);
watchProcess(process, console);
project.refreshLocal(IResource.DEPTH_INFINITE, monitor);
} catch (IOException e) {

View file

@ -18,7 +18,6 @@ import java.util.Arrays;
import java.util.List;
import java.util.Map;
import org.eclipse.cdt.core.IConsoleParser;
import org.eclipse.cdt.core.autotools.core.internal.Activator;
import org.eclipse.cdt.core.build.CBuildConfiguration;
import org.eclipse.cdt.core.build.IToolChain;
@ -90,8 +89,9 @@ public class AutotoolsBuildConfiguration extends CBuildConfiguration {
setBuildEnvironment(builder.environment());
try {
// TODO Error parsers
Process process = builder.start();
watchProcess(process, new IConsoleParser[0], console);
watchProcess(process, console);
} catch (IOException e) {
throw new CoreException(Activator.errorStatus("Error executing: " + String.join(" ", command), e)); //$NON-NLS-2$
}

View file

@ -450,10 +450,37 @@ public abstract class CBuildConfiguration extends PlatformObject
return null;
}
@Deprecated
protected int watchProcess(Process process, IConsoleParser[] consoleParsers, IConsole console)
throws CoreException {
if (consoleParsers == null || consoleParsers.length == 0) {
return watchProcess(process, console);
} else {
return watchProcess(process, consoleParsers);
}
}
/**
* @since 6.4
*/
protected int watchProcess(Process process, IConsole console) throws CoreException {
new ReaderThread(process.getInputStream(), console.getOutputStream()).start();
new ReaderThread(process.getErrorStream(), console.getErrorStream()).start();
try {
return process.waitFor();
} catch (InterruptedException e) {
CCorePlugin.log(e);
return -1;
}
}
/**
* @since 6.4
*/
protected int watchProcess(Process process, IConsoleParser[] consoleParsers)
throws CoreException {
new ReaderThread(process.getInputStream(), consoleParsers, console.getOutputStream()).start();
new ReaderThread(process.getErrorStream(), consoleParsers, console.getErrorStream()).start();
new ReaderThread(process.getInputStream(), consoleParsers).start();
new ReaderThread(process.getErrorStream(), consoleParsers).start();
try {
return process.waitFor();
} catch (InterruptedException e) {
@ -463,34 +490,42 @@ public abstract class CBuildConfiguration extends PlatformObject
}
private static class ReaderThread extends Thread {
private final BufferedReader in;
private final PrintStream out;
private final IConsoleParser[] consoleParsers;
private final PrintStream out;
public ReaderThread(InputStream in, IConsoleParser[] consoleParsers, OutputStream out) {
public ReaderThread(InputStream in, IConsoleParser[] consoleParsers) {
this.in = new BufferedReader(new InputStreamReader(in));
this.out = null;
this.consoleParsers = consoleParsers;
this.out = new PrintStream(out);
}
public ReaderThread(InputStream in, OutputStream out) {
this.in = new BufferedReader(new InputStreamReader(in));
this.out = new PrintStream(out);
this.consoleParsers = null;
}
@Override
public void run() {
try {
for (String line = in.readLine(); line != null; line = in.readLine()) {
for (IConsoleParser consoleParser : consoleParsers) {
// Synchronize to avoid interleaving of lines
synchronized (consoleParser) {
consoleParser.processLine(line);
if (consoleParsers != null) {
for (IConsoleParser consoleParser : consoleParsers) {
// Synchronize to avoid interleaving of lines
synchronized (consoleParser) {
consoleParser.processLine(line);
}
}
}
out.println(line);
if (out != null) {
out.println(line);
}
}
} catch (IOException e) {
CCorePlugin.log(e);
}
}
}
private File getScannerInfoCacheFile() {

View file

@ -87,6 +87,7 @@ public class StandardBuildConfiguration extends CBuildConfiguration {
try (ErrorParserManager epm = new ErrorParserManager(project, getBuildDirectoryURI(), this,
getToolChain().getErrorParserIds())) {
epm.setOutputStream(console.getOutputStream());
// run make
console.getOutputStream().write(String.format("%s\n", String.join(" ", command))); //$NON-NLS-1$ //$NON-NLS-2$
ProcessBuilder processBuilder = new ProcessBuilder(command)
@ -94,7 +95,7 @@ public class StandardBuildConfiguration extends CBuildConfiguration {
setBuildEnvironment(processBuilder.environment());
Process process = processBuilder.start();
IConsoleParser[] consoleParsers = new IConsoleParser[] { epm, this };
watchProcess(process, consoleParsers, console);
watchProcess(process, consoleParsers);
}
project.refreshLocal(IResource.DEPTH_INFINITE, monitor);
@ -125,7 +126,7 @@ public class StandardBuildConfiguration extends CBuildConfiguration {
.directory(getBuildDirectory().toFile());
setBuildEnvironment(processBuilder.environment());
Process process = processBuilder.start();
watchProcess(process, new IConsoleParser[0], console);
watchProcess(process, console);
project.refreshLocal(IResource.DEPTH_INFINITE, monitor);
} catch (IOException e) {

View file

@ -391,12 +391,13 @@ public class QtBuildConfiguration extends CBuildConfiguration
outStream.write(msg.toString());
// TODO qmake error parser
watchProcess(process, new IConsoleParser[0], console);
watchProcess(process, console);
doFullBuild = false;
}
try (ErrorParserManager epm = new ErrorParserManager(project, getBuildDirectoryURI(), this,
getToolChain().getErrorParserIds())) {
epm.setOutputStream(console.getOutputStream());
// run make
List<String> command = new ArrayList<>(Arrays.asList(makeCommand));
command.add("all"); //$NON-NLS-1$
@ -404,7 +405,7 @@ public class QtBuildConfiguration extends CBuildConfiguration
setBuildEnvironment(processBuilder.environment());
Process process = processBuilder.start();
outStream.write(String.join(" ", command) + '\n'); //$NON-NLS-1$
watchProcess(process, new IConsoleParser[] { epm }, console);
watchProcess(process, new IConsoleParser[] { epm });
}
getProject().refreshLocal(IResource.DEPTH_INFINITE, monitor);
@ -433,6 +434,7 @@ public class QtBuildConfiguration extends CBuildConfiguration
try (ErrorParserManager epm = new ErrorParserManager(project, getBuildDirectoryURI(), this,
getToolChain().getErrorParserIds())) {
epm.setOutputStream(console.getOutputStream());
// run make
List<String> command = new ArrayList<>(Arrays.asList(makeCommand));
command.add("clean"); //$NON-NLS-1$
@ -440,7 +442,7 @@ public class QtBuildConfiguration extends CBuildConfiguration
setBuildEnvironment(processBuilder.environment());
Process process = processBuilder.start();
outStream.write(String.join(" ", command) + '\n'); //$NON-NLS-1$
watchProcess(process, new IConsoleParser[] { epm }, console);
watchProcess(process, new IConsoleParser[] { epm });
}
project.refreshLocal(IResource.DEPTH_INFINITE, monitor);

View file

@ -741,11 +741,12 @@ public class ArduinoBuildConfiguration extends CBuildConfiguration
try (ErrorParserManager epm = new ErrorParserManager(project, getBuildDirectoryURI(), this,
getToolChain().getErrorParserIds())) {
epm.setOutputStream(console.getOutputStream());
ProcessBuilder processBuilder = new ProcessBuilder().command(getBuildCommand())
.directory(getBuildDirectory().toFile());
setBuildEnvironment(processBuilder.environment());
Process process = processBuilder.start();
if (watchProcess(process, new IConsoleParser[] { epm }, console) == 0) {
if (watchProcess(process, new IConsoleParser[] { epm }) == 0) {
showSizes(console);
}
}
@ -773,7 +774,7 @@ public class ArduinoBuildConfiguration extends CBuildConfiguration
setBuildEnvironment(processBuilder.environment());
Process process = processBuilder.start();
watchProcess(process, new IConsoleParser[0], console);
watchProcess(process, console);
getBuildContainer().refreshLocal(IResource.DEPTH_INFINITE, monitor);
} catch (IOException e) {